Mage_Core_Modules - Version 1.7.0.0

Version Notes

1.7.0.0

Download this release

Release Info

Developer Magento Core Team
Extension Mage_Core_Modules
Version 1.7.0.0
Comparing to
See all releases


Code changes from version 1.6.2.0 to 1.7.0.0

Files changed (434) hide show
  1. RELEASE_NOTES.txt +2037 -0
  2. api.php +88 -0
  3. app/Mage.php +91 -14
  4. app/code/core/Mage/Admin/Helper/Data.php +1 -1
  5. app/code/core/Mage/Admin/Model/Acl.php +1 -1
  6. app/code/core/Mage/Admin/Model/Acl/Assert/Ip.php +1 -1
  7. app/code/core/Mage/Admin/Model/Acl/Assert/Time.php +1 -1
  8. app/code/core/Mage/Admin/Model/Acl/Resource.php +1 -1
  9. app/code/core/Mage/Admin/Model/Acl/Role.php +1 -1
  10. app/code/core/Mage/Admin/Model/Acl/Role/Generic.php +1 -1
  11. app/code/core/Mage/Admin/Model/Acl/Role/Group.php +1 -1
  12. app/code/core/Mage/Admin/Model/Acl/Role/Registry.php +1 -1
  13. app/code/core/Mage/Admin/Model/Acl/Role/User.php +1 -1
  14. app/code/core/Mage/Admin/Model/Config.php +4 -1
  15. app/code/core/Mage/Admin/Model/Mysql4/Acl.php +1 -1
  16. app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php +1 -1
  17. app/code/core/Mage/Admin/Model/Mysql4/Acl/Role/Collection.php +1 -1
  18. app/code/core/Mage/Admin/Model/Mysql4/Permissions/Collection.php +1 -1
  19. app/code/core/Mage/Admin/Model/Mysql4/Role.php +1 -1
  20. app/code/core/Mage/Admin/Model/Mysql4/Role/Collection.php +1 -1
  21. app/code/core/Mage/Admin/Model/Mysql4/Roles.php +1 -1
  22. app/code/core/Mage/Admin/Model/Mysql4/Roles/Collection.php +1 -1
  23. app/code/core/Mage/Admin/Model/Mysql4/Roles/User/Collection.php +1 -1
  24. app/code/core/Mage/Admin/Model/Mysql4/Rules.php +1 -1
  25. app/code/core/Mage/Admin/Model/Mysql4/Rules/Collection.php +1 -1
  26. app/code/core/Mage/Admin/Model/Mysql4/User.php +1 -1
  27. app/code/core/Mage/Admin/Model/Mysql4/User/Collection.php +1 -1
  28. app/code/core/Mage/Admin/Model/Observer.php +5 -3
  29. app/code/core/Mage/Admin/Model/Resource/Acl.php +1 -1
  30. app/code/core/Mage/Admin/Model/Resource/Acl/Role.php +1 -1
  31. app/code/core/Mage/Admin/Model/Resource/Acl/Role/Collection.php +1 -1
  32. app/code/core/Mage/Admin/Model/Resource/Permissions/Collection.php +1 -1
  33. app/code/core/Mage/Admin/Model/Resource/Role.php +1 -1
  34. app/code/core/Mage/Admin/Model/Resource/Role/Collection.php +1 -1
  35. app/code/core/Mage/Admin/Model/Resource/Roles.php +1 -1
  36. app/code/core/Mage/Admin/Model/Resource/Roles/Collection.php +1 -1
  37. app/code/core/Mage/Admin/Model/Resource/Roles/User/Collection.php +1 -1
  38. app/code/core/Mage/Admin/Model/Resource/Rules.php +1 -1
  39. app/code/core/Mage/Admin/Model/Resource/Rules/Collection.php +1 -1
  40. app/code/core/Mage/Admin/Model/Resource/User.php +1 -1
  41. app/code/core/Mage/Admin/Model/Resource/User/Collection.php +1 -1
  42. app/code/core/Mage/Admin/Model/Role.php +1 -1
  43. app/code/core/Mage/Admin/Model/Roles.php +52 -10
  44. app/code/core/Mage/Admin/Model/Rules.php +1 -1
  45. app/code/core/Mage/Admin/Model/Session.php +9 -9
  46. app/code/core/Mage/Admin/Model/User.php +8 -4
  47. app/code/core/Mage/Admin/data/admin_setup/data-install-1.6.0.0.php +1 -1
  48. app/code/core/Mage/Admin/etc/config.xml +1 -1
  49. app/code/core/Mage/Admin/sql/admin_setup/install-1.6.0.0.php +7 -7
  50. app/code/core/Mage/Admin/sql/admin_setup/mysql4-install-0.7.0.php +1 -1
  51. app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.0-0.7.1.php +1 -1
  52. app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.1-0.7.2.php +1 -1
  53. app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php +1 -1
  54. app/code/core/Mage/Admin/sql/admin_setup/{mysql4-upgrade-1.6.0.0-1.6.1.0.php → upgrade-1.6.0.0-1.6.1.0.php} +1 -1
  55. app/code/core/Mage/AdminNotification/Helper/Data.php +3 -1
  56. app/code/core/Mage/AdminNotification/Model/Feed.php +1 -1
  57. app/code/core/Mage/AdminNotification/Model/Inbox.php +91 -1
  58. app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox.php +1 -1
  59. app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox/Collection.php +1 -1
  60. app/code/core/Mage/AdminNotification/Model/Observer.php +1 -1
  61. app/code/core/Mage/AdminNotification/Model/Resource/Inbox.php +8 -2
  62. app/code/core/Mage/AdminNotification/Model/Resource/Inbox/Collection.php +1 -1
  63. app/code/core/Mage/AdminNotification/Model/Survey.php +3 -1
  64. app/code/core/Mage/AdminNotification/etc/adminhtml.xml +1 -1
  65. app/code/core/Mage/AdminNotification/etc/config.xml +1 -1
  66. app/code/core/Mage/AdminNotification/etc/system.xml +1 -1
  67. app/code/core/Mage/AdminNotification/sql/adminnotification_setup/install-1.6.0.0.php +1 -1
  68. app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-install-1.0.0.php +1 -1
  69. app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php +1 -1
  70. app/code/core/Mage/Api/Controller/Action.php +1 -1
  71. app/code/core/Mage/Api/Exception.php +1 -1
  72. app/code/core/Mage/Api/Helper/Data.php +16 -2
  73. app/code/core/Mage/Api/Model/Acl.php +1 -1
  74. app/code/core/Mage/Api/Model/Acl/Assert/Ip.php +1 -1
  75. app/code/core/Mage/Api/Model/Acl/Assert/Time.php +1 -1
  76. app/code/core/Mage/Api/Model/Acl/Resource.php +1 -1
  77. app/code/core/Mage/Api/Model/Acl/Role.php +1 -1
  78. app/code/core/Mage/Api/Model/Acl/Role/Generic.php +1 -1
  79. app/code/core/Mage/Api/Model/Acl/Role/Group.php +1 -1
  80. app/code/core/Mage/Api/Model/Acl/Role/Registry.php +1 -1
  81. app/code/core/Mage/Api/Model/Acl/Role/User.php +1 -1
  82. app/code/core/Mage/Api/Model/Config.php +19 -1
  83. app/code/core/Mage/Api/Model/Mysql4/Acl.php +1 -1
  84. app/code/core/Mage/Api/Model/Mysql4/Acl/Role.php +1 -1
  85. app/code/core/Mage/Api/Model/Mysql4/Acl/Role/Collection.php +1 -1
  86. app/code/core/Mage/Api/Model/Mysql4/Permissions/Collection.php +1 -1
  87. app/code/core/Mage/Api/Model/Mysql4/Role.php +1 -1
  88. app/code/core/Mage/Api/Model/Mysql4/Role/Collection.php +1 -1
  89. app/code/core/Mage/Api/Model/Mysql4/Roles.php +1 -1
  90. app/code/core/Mage/Api/Model/Mysql4/Roles/Collection.php +1 -1
  91. app/code/core/Mage/Api/Model/Mysql4/Roles/User/Collection.php +1 -1
  92. app/code/core/Mage/Api/Model/Mysql4/Rules.php +1 -1
  93. app/code/core/Mage/Api/Model/Mysql4/Rules/Collection.php +1 -1
  94. app/code/core/Mage/Api/Model/Mysql4/User.php +1 -1
  95. app/code/core/Mage/Api/Model/Mysql4/User/Collection.php +1 -1
  96. app/code/core/Mage/Api/Model/Resource/Abstract.php +1 -1
  97. app/code/core/Mage/Api/Model/Resource/Acl.php +1 -1
  98. app/code/core/Mage/Api/Model/Resource/Acl/Role.php +1 -1
  99. app/code/core/Mage/Api/Model/Resource/Acl/Role/Collection.php +1 -1
  100. app/code/core/Mage/Api/Model/Resource/Permissions/Collection.php +1 -1
  101. app/code/core/Mage/Api/Model/Resource/Role.php +1 -1
  102. app/code/core/Mage/Api/Model/Resource/Role/Collection.php +1 -1
  103. app/code/core/Mage/Api/Model/Resource/Roles.php +1 -1
  104. app/code/core/Mage/Api/Model/Resource/Roles/Collection.php +1 -1
  105. app/code/core/Mage/Api/Model/Resource/Roles/User/Collection.php +1 -1
  106. app/code/core/Mage/Api/Model/Resource/Rules.php +1 -1
  107. app/code/core/Mage/Api/Model/Resource/Rules/Collection.php +1 -1
  108. app/code/core/Mage/Api/Model/Resource/User.php +1 -1
  109. app/code/core/Mage/Api/Model/Resource/User/Collection.php +1 -1
  110. app/code/core/Mage/Api/Model/Role.php +5 -2
  111. app/code/core/Mage/Api/Model/Roles.php +47 -4
  112. app/code/core/Mage/Api/Model/Rules.php +1 -1
  113. app/code/core/Mage/Api/Model/Server.php +68 -14
  114. app/code/core/Mage/Api/Model/Server/Adapter/Interface.php +1 -1
  115. app/code/core/Mage/Api/Model/Server/Adapter/Soap.php +38 -21
  116. app/code/core/Mage/Api/Model/Server/Adapter/Xmlrpc.php +14 -6
  117. app/code/core/Mage/Api/Model/Server/Handler.php +1 -1
  118. app/code/core/Mage/Api/Model/Server/Handler/Abstract.php +9 -5
  119. app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php +1 -1
  120. app/code/core/Mage/Api/Model/Server/V2/Handler.php +1 -1
  121. app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php +11 -15
  122. app/code/core/Mage/Api/Model/Server/Wsi/Handler.php +5 -8
  123. app/code/core/Mage/Api/Model/Session.php +4 -8
  124. app/code/core/Mage/Api/Model/User.php +8 -1
  125. app/code/core/Mage/Api/Model/Wsdl/Config.php +1 -1
  126. app/code/core/Mage/Api/Model/Wsdl/Config/Base.php +30 -10
  127. app/code/core/Mage/Api/Model/Wsdl/Config/Element.php +1 -1
  128. app/code/core/Mage/Api/controllers/IndexController.php +1 -1
  129. app/code/core/Mage/Api/controllers/SoapController.php +1 -1
  130. app/code/core/Mage/Api/controllers/V2/SoapController.php +1 -1
  131. app/code/core/Mage/Api/controllers/XmlrpcController.php +1 -1
  132. app/code/core/Mage/Api/etc/adminhtml.xml +7 -5
  133. app/code/core/Mage/Api/etc/api.xml +150 -1
  134. app/code/core/Mage/Api/etc/config.xml +2 -1
  135. app/code/core/Mage/Api/etc/system.xml +11 -1
  136. app/code/core/Mage/Api/etc/wsdl2.xml +20 -1
  137. app/code/core/Mage/Api/etc/wsi.xml +1 -1
  138. app/code/core/Mage/Api/sql/api_setup/install-1.6.0.0.php +1 -1
  139. app/code/core/Mage/Api/sql/api_setup/mysql4-install-0.7.0.php +1 -1
  140. app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.7.0-0.7.1.php +1 -1
  141. app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.8.0-0.8.1.php +1 -1
  142. app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php +1 -1
  143. app/code/core/Mage/Api2/Block/Adminhtml/Attribute.php +48 -0
  144. app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Buttons.php +112 -0
  145. app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Edit.php +61 -0
  146. app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Edit/Form.php +58 -0
  147. app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php +107 -0
  148. app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Tab/Resource.php +141 -0
  149. app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Tabs.php +47 -0
  150. app/code/core/Mage/Api2/Block/Adminhtml/Permissions/User/Edit/Tab/Roles.php +203 -0
  151. app/code/core/Mage/Api2/Block/Adminhtml/Roles.php +56 -0
  152. app/code/core/Mage/Api2/Block/Adminhtml/Roles/Buttons.php +146 -0
  153. app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php +149 -0
  154. app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Info.php +131 -0
  155. app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Resources.php +153 -0
  156. app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Users.php +239 -0
  157. app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tabs.php +65 -0
  158. app/code/core/Mage/Api2/Exception.php +50 -0
  159. app/code/core/Mage/Api2/Helper/Data.php +198 -0
  160. app/code/core/Mage/Api2/Model/Acl.php +187 -0
  161. app/code/core/Mage/Api2/Model/Acl/Filter.php +193 -0
  162. app/code/core/Mage/Api2/Model/Acl/Filter/Attribute.php +77 -0
  163. app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/Operation.php +67 -0
  164. app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php +181 -0
  165. app/code/core/Mage/Api2/Model/Acl/Global.php +65 -0
  166. app/code/core/Mage/Api2/Model/Acl/Global/Role.php +185 -0
  167. app/code/core/Mage/Api2/Model/Acl/Global/Rule.php +65 -0
  168. app/code/core/Mage/Api2/Model/Acl/Global/Rule/Permission.php +74 -0
  169. app/code/core/Mage/Api2/Model/Acl/Global/Rule/Privilege.php +77 -0
  170. app/code/core/Mage/Api2/Model/Acl/Global/Rule/ResourcePermission.php +122 -0
  171. app/code/core/Mage/Api2/Model/Acl/Global/Rule/Tree.php +546 -0
  172. app/code/core/Mage/Api2/Model/Acl/PermissionInterface.php +52 -0
  173. app/code/core/Mage/Api2/Model/Auth.php +80 -0
  174. app/code/core/Mage/Api2/Model/Auth/Adapter.php +93 -0
  175. app/code/core/Mage/Api2/Model/Auth/Adapter/Abstract.php +53 -0
  176. app/code/core/Mage/Api2/Model/Auth/Adapter/Oauth.php +78 -0
  177. app/code/core/Mage/Api2/Model/Auth/User.php +61 -0
  178. app/code/core/Mage/Api2/Model/Auth/User/Abstract.php +96 -0
  179. app/code/core/Mage/Api2/Model/Auth/User/Admin.php +106 -0
  180. app/code/core/Mage/Api2/Model/Auth/User/Customer.php +80 -0
  181. app/code/core/Mage/Api2/Model/Auth/User/Guest.php +80 -0
  182. app/code/core/Mage/Api2/Model/Config.php +449 -0
  183. app/code/core/Mage/Api2/Model/Dispatcher.php +162 -0
  184. app/code/core/Mage/Api2/Model/Multicall.php +278 -0
  185. app/code/core/Mage/Api2/Model/Observer.php +86 -0
  186. app/code/core/Mage/Api2/Model/Renderer.php +83 -0
  187. app/code/core/Mage/Api2/Model/Renderer/Interface.php +50 -0
  188. app/code/core/Mage/Api2/Model/Renderer/Json.php +61 -0
  189. app/code/core/Mage/Api2/Model/Renderer/Query.php +62 -0
  190. app/code/core/Mage/Api2/Model/Renderer/Xml.php +162 -0
  191. app/code/core/Mage/Api2/Model/Renderer/Xml/Writer.php +80 -0
  192. app/code/core/Mage/Api2/Model/Request.php +325 -0
  193. app/code/core/Mage/Api2/Model/Request/Internal.php +105 -0
  194. app/code/core/Mage/Api2/Model/Request/Interpreter.php +76 -0
  195. app/code/core/Mage/Api2/Model/Request/Interpreter/Interface.php +43 -0
  196. app/code/core/Mage/Api2/Model/Request/Interpreter/Json.php +57 -0
  197. app/code/core/Mage/Api2/Model/Request/Interpreter/Query.php +77 -0
  198. app/code/core/Mage/Api2/Model/Request/Interpreter/Xml.php +150 -0
  199. app/code/core/Mage/Api2/Model/Resource.php +1082 -0
  200. app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php +87 -0
  201. app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute/Collection.php +57 -0
  202. app/code/core/Mage/Api2/Model/Resource/Acl/Global/Role.php +121 -0
  203. app/code/core/Mage/Api2/Model/Resource/Acl/Global/Role/Collection.php +63 -0
  204. app/code/core/Mage/Api2/Model/Resource/Acl/Global/Rule.php +45 -0
  205. app/code/core/Mage/Api2/Model/Resource/Acl/Global/Rule/Collection.php +57 -0
  206. app/code/core/Mage/Api2/Model/Resource/Setup.php +36 -0
  207. app/code/core/Mage/Api2/Model/Resource/Validator.php +102 -0
  208. app/code/core/Mage/Api2/Model/Resource/Validator/Eav.php +249 -0
  209. app/code/core/Mage/Api2/Model/Resource/Validator/Fields.php +186 -0
  210. app/code/core/Mage/Api2/Model/Response.php +114 -0
  211. app/code/core/Mage/Api2/Model/Route/Abstract.php +99 -0
  212. app/code/core/Mage/Api2/Model/Route/ApiType.php +57 -0
  213. app/code/core/Mage/Api2/Model/Route/Interface.php +45 -0
  214. app/code/core/Mage/Api2/Model/Route/Rest.php +36 -0
  215. app/code/core/Mage/Api2/Model/Router.php +122 -0
  216. app/code/core/Mage/Api2/Model/Server.php +315 -0
  217. app/code/core/Mage/Api2/controllers/Adminhtml/Api2/AttributeController.php +148 -0
  218. app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php +340 -0
  219. app/code/core/Mage/Api2/etc/adminhtml.xml +93 -0
  220. app/code/core/Mage/Api2/etc/config.xml +212 -0
  221. app/code/core/Mage/Api2/sql/api2_setup/install-1.0.0.0.php +183 -0
  222. app/code/core/Mage/Authorizenet/Block/Directpost/Form.php +1 -1
  223. app/code/core/Mage/Authorizenet/Block/Directpost/Iframe.php +1 -1
  224. app/code/core/Mage/Authorizenet/Helper/Data.php +1 -1
  225. app/code/core/Mage/Authorizenet/Model/Directpost.php +1 -1
  226. app/code/core/Mage/Authorizenet/Model/Directpost/Observer.php +1 -1
  227. app/code/core/Mage/Authorizenet/Model/Directpost/Request.php +1 -1
  228. app/code/core/Mage/Authorizenet/Model/Directpost/Response.php +1 -1
  229. app/code/core/Mage/Authorizenet/Model/Directpost/Session.php +1 -1
  230. app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php +1 -1
  231. app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php +1 -1
  232. app/code/core/Mage/Authorizenet/etc/config.xml +1 -1
  233. app/code/core/Mage/Authorizenet/etc/system.xml +3 -1
  234. app/code/core/Mage/Backup/Exception.php +1 -1
  235. app/code/core/Mage/Backup/Helper/Data.php +291 -1
  236. app/code/core/Mage/Backup/Model/Backup.php +72 -24
  237. app/code/core/Mage/Backup/Model/Config/Backend/Cron.php +89 -0
  238. app/code/core/Mage/Backup/Model/Config/Source/Type.php +52 -0
  239. app/code/core/Mage/Backup/Model/Db.php +33 -5
  240. app/code/core/Mage/Backup/Model/Fs/Collection.php +10 -2
  241. app/code/core/Mage/Backup/Model/Mysql4/Db.php +1 -1
  242. app/code/core/Mage/Backup/Model/Observer.php +95 -0
  243. app/code/core/Mage/Backup/Model/Resource/Db.php +31 -18
  244. app/code/core/Mage/Backup/Model/Resource/Helper/Mysql4.php +43 -10
  245. app/code/core/Mage/Backup/etc/adminhtml.xml +6 -1
  246. app/code/core/Mage/Backup/etc/config.xml +10 -1
  247. app/code/core/Mage/Backup/etc/system.xml +95 -0
  248. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php +1 -1
  249. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Checkbox.php +1 -1
  250. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Multi.php +1 -1
  251. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Radio.php +1 -1
  252. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Select.php +1 -1
  253. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php +18 -5
  254. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php +1 -1
  255. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Special.php +1 -1
  256. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle.php +1 -1
  257. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php +26 -2
  258. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search.php +1 -1
  259. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search/Grid.php +1 -1
  260. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.php +1 -1
  261. app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tabs.php +1 -1
  262. app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php +1 -1
  263. app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php +1 -1
  264. app/code/core/Mage/Bundle/Block/Catalog/Product/List/Partof.php +1 -1
  265. app/code/core/Mage/Bundle/Block/Catalog/Product/Price.php +1 -1
  266. app/code/core/Mage/Bundle/Block/Catalog/Product/View.php +1 -1
  267. app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php +6 -3
  268. app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php +8 -3
  269. app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php +1 -1
  270. app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php +1 -1
  271. app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php +1 -1
  272. app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php +1 -1
  273. app/code/core/Mage/Bundle/Block/Checkout/Cart/Item/Renderer.php +1 -1
  274. app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php +1 -1
  275. app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php +14 -7
  276. app/code/core/Mage/Bundle/Helper/Data.php +1 -1
  277. app/code/core/Mage/Bundle/Model/CatalogIndex/Data/Bundle.php +1 -1
  278. app/code/core/Mage/Bundle/Model/Mysql4/Bundle.php +1 -1
  279. app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Price.php +1 -1
  280. app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Stock.php +1 -1
  281. app/code/core/Mage/Bundle/Model/Mysql4/Option.php +1 -1
  282. app/code/core/Mage/Bundle/Model/Mysql4/Option/Collection.php +1 -1
  283. app/code/core/Mage/Bundle/Model/Mysql4/Price/Index.php +1 -1
  284. app/code/core/Mage/Bundle/Model/Mysql4/Selection.php +1 -1
  285. app/code/core/Mage/Bundle/Model/Mysql4/Selection/Collection.php +1 -1
  286. app/code/core/Mage/Bundle/Model/Observer.php +14 -1
  287. app/code/core/Mage/Bundle/Model/Option.php +1 -1
  288. app/code/core/Mage/Bundle/Model/Price/Index.php +1 -1
  289. app/code/core/Mage/Bundle/Model/Product/Attribute/Source/Price/View.php +1 -1
  290. app/code/core/Mage/Bundle/Model/Product/Price.php +140 -82
  291. app/code/core/Mage/Bundle/Model/Product/Type.php +9 -8
  292. app/code/core/Mage/Bundle/Model/Resource/Bundle.php +1 -1
  293. app/code/core/Mage/Bundle/Model/Resource/Indexer/Price.php +155 -22
  294. app/code/core/Mage/Bundle/Model/Resource/Indexer/Stock.php +1 -1
  295. app/code/core/Mage/Bundle/Model/Resource/Option.php +1 -1
  296. app/code/core/Mage/Bundle/Model/Resource/Option/Collection.php +1 -1
  297. app/code/core/Mage/Bundle/Model/Resource/Price/Index.php +1 -1
  298. app/code/core/Mage/Bundle/Model/Resource/Selection.php +1 -1
  299. app/code/core/Mage/Bundle/Model/Resource/Selection/Collection.php +1 -1
  300. app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php +7 -4
  301. app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +17 -14
  302. app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +12 -11
  303. app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +12 -9
  304. app/code/core/Mage/Bundle/Model/Selection.php +1 -1
  305. app/code/core/Mage/Bundle/Model/Source/Option/Selection/Price/Type.php +1 -1
  306. app/code/core/Mage/Bundle/Model/Source/Option/Type.php +1 -1
  307. app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/Product/EditController.php +1 -1
  308. app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/SelectionController.php +1 -1
  309. app/code/core/Mage/Bundle/controllers/Product/EditController.php +1 -1
  310. app/code/core/Mage/Bundle/controllers/SelectionController.php +1 -1
  311. app/code/core/Mage/Bundle/data/bundle_setup/data-install-1.6.0.0.php +1 -1
  312. app/code/core/Mage/Bundle/etc/config.xml +10 -2
  313. app/code/core/Mage/Bundle/sql/bundle_setup/install-1.6.0.0.php +1 -1
  314. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php +1 -1
  315. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-install-0.1.0.php +1 -1
  316. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.0-0.1.1.php +1 -1
  317. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.1-0.1.2.php +1 -1
  318. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.10-0.1.11.php +1 -1
  319. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.11-0.1.12.php +1 -1
  320. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.12-0.1.13.php +1 -1
  321. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.2-0.1.3.php +1 -1
  322. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.3-0.1.4.php +1 -1
  323. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.4-0.1.5.php +1 -1
  324. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.5-0.1.6.php +1 -1
  325. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.6-0.1.7.php +1 -1
  326. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.7-0.1.8.php +1 -1
  327. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.8-0.1.9.php +1 -1
  328. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.9-0.1.10.php +1 -1
  329. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php +1 -1
  330. app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-1.6.0.0-1.6.0.0.1.php +44 -0
  331. app/code/core/Mage/Bundle/sql/bundle_setup/upgrade-1.6.0.0-1.6.0.0.1.php +84 -0
  332. app/code/core/Mage/Captcha/Block/Captcha.php +48 -0
  333. app/code/core/Mage/Captcha/Block/Captcha/Zend.php +89 -0
  334. app/code/core/Mage/Captcha/Helper/Data.php +138 -0
  335. app/code/core/Mage/Captcha/Model/Config/Font.php +49 -0
  336. app/code/core/Mage/Captcha/Model/Config/Form/Abstract.php +61 -0
  337. app/code/core/Mage/Captcha/Model/Config/Form/Backend.php +40 -0
  338. app/code/core/Mage/Captcha/Model/Config/Form/Frontend.php +40 -0
  339. app/code/core/Mage/Captcha/Model/Config/Mode.php +54 -0
  340. app/code/core/Mage/Captcha/Model/Interface.php +60 -0
  341. app/code/core/Mage/Captcha/Model/Observer.php +292 -0
  342. app/code/core/Mage/Captcha/Model/Resource/Log.php +158 -0
  343. app/code/core/Mage/Captcha/Model/Zend.php +504 -0
  344. app/code/core/Mage/Captcha/controllers/Adminhtml/RefreshController.php +50 -0
  345. app/code/core/Mage/Captcha/controllers/RefreshController.php +50 -0
  346. app/code/core/Mage/Captcha/etc/config.xml +271 -0
  347. app/code/core/Mage/Captcha/etc/system.xml +250 -0
  348. app/code/core/Mage/Captcha/sql/captcha_setup/install-1.7.0.0.0.php +51 -0
  349. app/code/core/Mage/Catalog/Block/Breadcrumbs.php +1 -1
  350. app/code/core/Mage/Catalog/Block/Category/View.php +1 -1
  351. app/code/core/Mage/Catalog/Block/Category/Widget/Link.php +1 -1
  352. app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php +19 -1
  353. app/code/core/Mage/Catalog/Block/Layer/Filter/Attribute.php +1 -1
  354. app/code/core/Mage/Catalog/Block/Layer/Filter/Category.php +1 -1
  355. app/code/core/Mage/Catalog/Block/Layer/Filter/Decimal.php +1 -1
  356. app/code/core/Mage/Catalog/Block/Layer/Filter/Price.php +1 -1
  357. app/code/core/Mage/Catalog/Block/Layer/State.php +1 -1
  358. app/code/core/Mage/Catalog/Block/Layer/View.php +11 -1
  359. app/code/core/Mage/Catalog/Block/Navigation.php +1 -1
  360. app/code/core/Mage/Catalog/Block/Product.php +1 -1
  361. app/code/core/Mage/Catalog/Block/Product/Abstract.php +18 -9
  362. app/code/core/Mage/Catalog/Block/Product/Compare/Abstract.php +1 -1
  363. app/code/core/Mage/Catalog/Block/Product/Compare/List.php +1 -1
  364. app/code/core/Mage/Catalog/Block/Product/Compare/Sidebar.php +1 -1
  365. app/code/core/Mage/Catalog/Block/Product/Gallery.php +1 -1
  366. app/code/core/Mage/Catalog/Block/Product/List.php +1 -1
  367. app/code/core/Mage/Catalog/Block/Product/List/Crosssell.php +2 -2
  368. app/code/core/Mage/Catalog/Block/Product/List/Promotion.php +1 -1
  369. app/code/core/Mage/Catalog/Block/Product/List/Random.php +1 -1
  370. app/code/core/Mage/Catalog/Block/Product/List/Related.php +2 -2
  371. app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php +1 -1
  372. app/code/core/Mage/Catalog/Block/Product/List/Upsell.php +2 -2
  373. app/code/core/Mage/Catalog/Block/Product/New.php +11 -4
  374. app/code/core/Mage/Catalog/Block/Product/Price.php +17 -7
  375. app/code/core/Mage/Catalog/Block/Product/Price/Template.php +1 -1
  376. app/code/core/Mage/Catalog/Block/Product/Send.php +1 -1
  377. app/code/core/Mage/Catalog/Block/Product/View.php +28 -16
  378. app/code/core/Mage/Catalog/Block/Product/View/Abstract.php +1 -1
  379. app/code/core/Mage/Catalog/Block/Product/View/Additional.php +1 -1
  380. app/code/core/Mage/Catalog/Block/Product/View/Attributes.php +1 -1
  381. app/code/core/Mage/Catalog/Block/Product/View/Description.php +1 -1
  382. app/code/core/Mage/Catalog/Block/Product/View/Media.php +24 -6
  383. app/code/core/Mage/Catalog/Block/Product/View/Options.php +27 -3
  384. app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php +3 -3
  385. app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php +1 -1
  386. app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Default.php +1 -1
  387. app/code/core/Mage/Catalog/Block/Product/View/Options/Type/File.php +1 -1
  388. app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php +22 -13
  389. app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Text.php +1 -1
  390. app/code/core/Mage/Catalog/Block/Product/View/Price.php +1 -1
  391. app/code/core/Mage/Catalog/Block/Product/View/Tabs.php +1 -1
  392. app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php +72 -42
  393. app/code/core/Mage/Catalog/Block/Product/View/Type/Grouped.php +1 -1
  394. app/code/core/Mage/Catalog/Block/Product/View/Type/Simple.php +1 -1
  395. app/code/core/Mage/Catalog/Block/Product/View/Type/Virtual.php +1 -1
  396. app/code/core/Mage/Catalog/Block/Product/Widget/Link.php +1 -1
  397. app/code/core/Mage/Catalog/Block/Product/Widget/New.php +1 -1
  398. app/code/core/Mage/Catalog/Block/Seo/Sitemap/Abstract.php +1 -1
  399. app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php +1 -1
  400. app/code/core/Mage/Catalog/Block/Seo/Sitemap/Product.php +1 -1
  401. app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Category.php +1 -1
  402. app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php +1 -1
  403. app/code/core/Mage/Catalog/Block/Widget/Link.php +1 -1
  404. app/code/core/Mage/Catalog/Exception.php +1 -1
  405. app/code/core/Mage/Catalog/Helper/Category.php +1 -1
  406. app/code/core/Mage/Catalog/Helper/Category/Flat.php +1 -1
  407. app/code/core/Mage/Catalog/Helper/Data.php +12 -1
  408. app/code/core/Mage/Catalog/Helper/Image.php +171 -30
  409. app/code/core/Mage/Catalog/Helper/Map.php +1 -1
  410. app/code/core/Mage/Catalog/Helper/Output.php +1 -1
  411. app/code/core/Mage/Catalog/Helper/Product.php +47 -20
  412. app/code/core/Mage/Catalog/Helper/Product/Compare.php +1 -1
  413. app/code/core/Mage/Catalog/Helper/Product/Configuration.php +1 -1
  414. app/code/core/Mage/Catalog/Helper/Product/Configuration/Interface.php +1 -1
  415. app/code/core/Mage/Catalog/Helper/Product/Flat.php +1 -1
  416. app/code/core/Mage/Catalog/Helper/Product/Options.php +1 -1
  417. app/code/core/Mage/Catalog/Helper/Product/Url.php +1 -1
  418. app/code/core/Mage/Catalog/Helper/Product/View.php +1 -1
  419. app/code/core/Mage/Catalog/Model/Abstract.php +1 -1
  420. app/code/core/Mage/Catalog/Model/Api/Resource.php +1 -1
  421. app/code/core/Mage/Catalog/Model/Api2/Product.php +94 -0
  422. app/code/core/Mage/Catalog/Model/Api2/Product/Category.php +36 -0
  423. app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest.php +105 -0
  424. app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest/Admin/V1.php +146 -0
  425. app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest/Customer/V1.php +36 -0
  426. app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest/Guest/V1.php +36 -0
  427. app/code/core/Mage/Catalog/Model/Api2/Product/Image.php +36 -0
  428. app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest.php +222 -0
  429. app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest/Admin/V1.php +237 -0
  430. app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest/Customer/V1.php +36 -0
  431. app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest/Guest/V1.php +36 -0
  432. app/code/core/Mage/Catalog/Model/Api2/Product/Image/Validator/Image.php +53 -0
  433. app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php +402 -0
  434. app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Admin/V1.php +42 -0
RELEASE_NOTES.txt CHANGED
@@ -1,3 +1,1414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ==== 1.6.2.0 ====
2
 
3
  === Improvements ===
@@ -30,6 +1441,632 @@ Fixed Exception while products mass update attributes in backend
30
 
31
 
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ==== 1.6.1.0 ====
34
 
35
  === Major Highlights ===
1
+ ==== 1.7.0.0 ====
2
+
3
+ === Major Highlights ===
4
+ Optimized Layered Navigation for pricing
5
+ Added CAPTCHA support for admin and customer users
6
+ Added different base price per customer group
7
+ Added auto generation of coupon codes
8
+ Improved the basic Backup and Rollback functionality
9
+ Added EU VAT ID validation service integration
10
+ Implemented DHL for Europe
11
+ Added REST API
12
+ Mobile theme was redesigned
13
+ Implemented the frontend Cookie Restriction functionality (EU cookie law compliance)
14
+ Added the Cash On Delivery and Bank Transfer payment methods
15
+
16
+ === Improvements ===
17
+ XmlConnect package release v22.1
18
+ Upgraded TinyMCE to v3.4.7
19
+ Added the ability to translate action array parameter nodes in the layout.xml
20
+ Added the support for using custom currency symbols
21
+ Added the functionality for cleaning old cache files by cron tasks
22
+ Refactored rules-based modules
23
+ Improved customer address handling for PayPal Express checkout
24
+ Added the ability to customize a store logo in emails from an admin
25
+ Refactored the escaping functionality used for translations
26
+ Added the ability to turn off/on IP tracking (e.g. 'Placed from IP', displayed on the order-related pages in the backend)
27
+ Provided the logic for disabling ACL resources in configuration files
28
+ Added additional placeholders for extension developers
29
+
30
+ === Changes ===
31
+ Added support for "memcached" PHP extension
32
+ The js/scriptaculous/dragdrop.js library is upgraded to version 1.9.0
33
+ Files in .jpg format are allowed to be used for a favicon
34
+ Added the ability to extend the list of attributes in the SELECT query for categories loaded via Mage_Catalog_Model_Resource_Category_Flat::_loadNodes()
35
+ Added changes to lib/Varien/Http/Adapter/Curl.php to provide interface for setting different cURL options
36
+ Displaying State or Province can be optional for any country
37
+ Added the ability to get Magento type from Mage.php
38
+
39
+ === Fixes ===
40
+ Fixed: Impossible to reset Customer Password via link in Forgot Password email template
41
+ Fixed: Reference to non-existing class Mage_Catalog_Block_Seo_Searchterm
42
+ Fixed: System can't find page by the URL when Payflow Link PayPal payment method used
43
+ Fixed: Grammar issues reported by community
44
+ Fixed: Layout is broken for PDF documents, values are overlapped
45
+ Fixed: Admin Notifications in backend should not appear again after it been removed or marked as read
46
+ Fixed: Reference and contents information is absent in the shipping label for DHL
47
+ Fixed: Include commented rewrite rules to .htaccess
48
+ Fixed: Shopping Cart is cleared after pressing "Enter"
49
+ Fixed: Group Name of "Not Logged IN" Customer Groups is removed automatically after saving
50
+ Fixed: Not possible to assign one picture to two products (Media Storage = Database)
51
+ Fixed: Exception in shop when accessed by Googlebot
52
+ Fixed: SLI for DHL used credentials only from the default configuration scope
53
+ Fixed: Old copyright data and system version exist in page footer
54
+ Fixed: CMS widgets: Required validation for drop-down "Type" and "Design Package/Theme"
55
+ Fixed: On "New Widget Instance" page, drop-down "Type" doesn't have required validation
56
+ Fixed: Auto-redirect to Base URL = Yes with correct behavior may cause problems when secure URL is hardcoded
57
+ Fixed: Enable Qty Increments on global config has higher priority than product config
58
+ Fixed: Short open tag in app/design/adminhtml/default/default/template/currencysymbol/grid.phtml
59
+ Fixed: UPS, FedEx and DHL methods should work if zip code from/to isn't required
60
+ Fixed: No ability to cancel Partial Authorization checkout with Authorize.net in the frontend
61
+ Fixed: Incorrect displaying of the "New User" page
62
+ Fixed: Multiple warnings in system.log after running compilation process
63
+ Fixed: Session is lost while redirecting from secure to unsecure URL
64
+ Fixed: Redirect to base URL should consider full request URI string
65
+ Fixed: Product name with <> processed incorrect during creation order in backend
66
+ Fixed: FedEx SmartPost method doesn't appears in rate request
67
+ Fixed: 3 and 4 digits CVV should be accepted for JCB cards
68
+ Fixed: Google Checkout tax isn't applied to Bundle product
69
+ Fixed: FPT is not considered by Google Checkout
70
+ Fixed: An error occurred during second Customer authorization fail
71
+ Fixed: Property declaration typo in Mage_Bundle_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option
72
+ Fixed: Product is not shown in the Catalog when it is Out of Stock and Display Out of Stock Products = Yes
73
+ Fixed: Impossible download downloadable product (problem with secure link)
74
+ Fixed: Wrong letter case in class names may cause malfunction when Compiler is enabled
75
+ Fixed: Incorrect invoice amount in order with FPT
76
+ Fixed: Attributes not connected to any product of selected category display in layered navigation
77
+ Fixed: No feedback on creating attribute set in IE9 and IE8
78
+ Fixed: Unexpected breaking import process leads to creation phantom data into database
79
+ Fixed: Two of the same FedEx option show instead of one
80
+ Fixed: Notification for Google contains link that cover large area and blocked user work
81
+ Fixed: Possible to create user role with empty name if it starts with "less than" sign
82
+ Fixed: Impossible to use Clear Shopping Cart button in IE7
83
+ Fixed: Impossible create product with one FPT price for all State/Province
84
+ Fixed: 'Interval Division Limit' affects to global displaying of Layered Navigation
85
+ Fixed: Shipping method must be recalculated on Order Review page if Transfer Shipping Options is enabled
86
+ Fixed: Issue with different secure/unsecure URL cause session data lost
87
+ Fixed: Can't save option Country in Store Information Tab
88
+ Fixed: Rule date information has been missed after using Product Rule or Shopping Cart Price Rule
89
+ Fixed: Billing/Shipping address algorithm for PayPal Express checkout works incorrect
90
+ Fixed: Error during quick search
91
+ Fixed: Block "Description" on Catalog Price Rule page has incorrect size
92
+ Fixed: Search doesn't work if Maximum Query Length field is empty
93
+ Fixed: The Tags Product RSS doesn't update information after changing tag
94
+ Fixed: Customer Attributes and Customer Address Attributes validation
95
+ Fixed: Issue with final price calculation for Configurable product with sub products
96
+ Fixed: Blank page after customer registration with enabled compilation
97
+ Fixed: "Place Order" button must be enabled if all required fields passed the validation on PayPal Express Checkout
98
+ Fixed: Products quantity displays incorrect in price ranges after import (rounding problem)
99
+ Fixed: Layout issue in shopping cart on frontend (IE8)
100
+ Fixed: Impossible to assign user to the role if he is assigned to another role
101
+ Fixed: 'Total records found' on Reports -> Tags -> Popular page shows wrong quantity of records
102
+ Fixed: Unable to refresh lifetime statistics
103
+ Fixed: After changing Price Navigation Step calculation from Automatic(eq price range) to Automatic(eq prod count) the category is loaded very slowly
104
+ Fixed: No ability to create Shipping Label (in case with USPS First-Class Mail International Parcel method)
105
+ Fixed: It is impossible to create Shipping Label for FedEx
106
+ Fixed: Redirect Customer to Account Dashboard after Logging is in enabled and doesn't work for Wishlist
107
+ Fixed: No ability to edit values using mass actions for product in IE8, IE9
108
+ Fixed: Wrong message during checkout process in Inline Translate mode
109
+ Fixed: Default country is selected in Shipping Address during Admin order creation
110
+ Fixed: The Static block widget doesn't displayed on the Product View Extra hint for bundle product
111
+ Fixed: Bunch of W3C validation errors on frontend while using inline translate
112
+ Fixed: Product's association to root category is lost after export/import
113
+ Fixed: WYSIWYG Editor: Page is scrolled to the top after inserting variables
114
+ Fixed: Incorrect Backup/Rollback message
115
+ Fixed: FedEx Free shipping doesn't work correctly
116
+ Fixed: Configurable product displaying double price when choosing option
117
+ Fixed: Impossible to configure Admin User Emails for store view scope
118
+ Fixed: Long payment method data is printed improperly in PDF invoice
119
+ Fixed: Impossibility of changing the Rating Value title for store view in existing Rating Value with filled the Rating Value title for store view
120
+ Fixed: Trademark symbol not showing up
121
+ Fixed: Add "Delivery Option" for FedEx Configurations
122
+ Fixed: Saving product takes long time
123
+ Fixed: Notice message disappear after clearing cache
124
+ Fixed: Products qty displays incorrect in price ranges after import (rounding problem)
125
+ Fixed: Images in CSS fail when merging CSS files
126
+ Fixed: Mass action update of any attributes resets multi-select attributes to NULL
127
+ Fixed: Move CSS from Prototype Windows plug-in to the backend skin
128
+ Fixed: DB adapter should check transaction level in case of DDL query
129
+ Fixed: When Payment method additional info contains double quote it is displayed as '&quot;' in invoice PDF
130
+ Fixed: Incorrect Unit Price(Excl. Tax) in the Shopping Cart Grid after changing currency
131
+ Fixed: Incorrect total quantity of records and pagination doesn't work on Reports->Reviews->Products Reviews page
132
+ Fixed: Incorrect title of All Reviews for product page
133
+ Fixed: Invalid message in shopping cart when trying to add products amount more than allowed
134
+ Fixed: Layered Navigation: Icon "Previous" should be appear only on sub-intervals level
135
+ Fixed: Processing error occurred when big numeric value is entered to an browser URL
136
+ Fixed: Issue with credit memo for multiple bundled products (order status is Processing)
137
+ Fixed: Customer group has to be emulated even if customer is sticky assigned to the group
138
+ Fixed: "Customs Value" isn't represented in store base currency
139
+ Fixed: Layered Navigation: After clicking on interval $0.00, should be filtered and displayed products with price 0.00
140
+ Fixed: Absence of redirecting to the grid page after saving Role/User
141
+ Fixed: Incorrect logic of assignment of unique ID in Varien_Data_Collection
142
+ Fixed: Problems with sorting actions
143
+ Fixed: When product is set to be not available for selling checkout is still possible depending on its position in cart
144
+ Fixed: Impossibility of creating new order with "Reorder" button when Out of stock or disabled products had been ordered
145
+ Fixed: "Online Minute Interval" customer configuration option should have global scope
146
+ Fixed: Unable to translate Active/Inactive in promotions grid
147
+ Fixed: Response headers contains 500 error during frontend pages browsing
148
+ Fixed: Add additional button to PayPal Redirect Page
149
+ Fixed: Category Permissions: if "Display Product Price" is set to "No" the page toolbar is absent
150
+ Fixed: Layered navigation options have wrong order in backend
151
+ Fixed: The "Remember Me" check box with the "What's this?" link should be located below the "Forgot Your Password?" link
152
+ Fixed: Warning message is absent, when "Recovery Link Expiration Period" is specified within the correct range
153
+ Fixed: PayPal HSS (Website Payment Pro Hosted Solutions) France doesn't work
154
+ Fixed: Remove email from Billing address section of the PayPal Express Order Review page
155
+ Fixed: It is available enter negative digits in the "Layered Navigation Price Step" (on Category page)
156
+ Fixed: First/Last Name algorithm for PayPal Express checkout
157
+ Fixed: Asterisk isn't imported in Zip/Post Code field
158
+ Fixed: Some strings are not translated in widgets
159
+ Fixed: Session isn't stored between secure and unsecure URLs when they are located in different paths of the same domain (no SID in request)
160
+ Fixed: "USPS First Class International Parcel" will not show up as an option for customers during checkout
161
+ Fixed: UPS, FedEx and DHL methods should work if zip code from / to isn't required
162
+ Fixed: Issue when trying to create an order from the backend without selecting the state/province
163
+ Fixed: HTTP error when uploading images from a MacOS with shockwave flash 11.1.102.55
164
+ Fixed: UPS Configuration "All Methods" should be selected by default
165
+ Fixed: Cannot create a product review through backend
166
+ Fixed: Typos in Role Permission tree
167
+ Fixed: WYSIWYG button layout issue on product page
168
+ Fixed: Require Customer's Billing Address is missing option "For Virtual Quotes Only"
169
+ Fixed: Errors appears on Design Configuration page if transactional email's logo image and/or favicon files were deleted
170
+ Fixed: State/Province value is reset after page reload on some forms
171
+ Fixed: Cannot access backend after switching on and switching off "Use Custom Admin URL"
172
+ Fixed: "Unsubscribe Selected" and "Delete Selected Problems" buttons don't work
173
+ Fixed: After selecting shipping from dropdown system doesn't update order data automatically on PayPal Express Order Review page
174
+ Fixed: Buttons on the backend order page don't have titles
175
+ Fixed: ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION error in Chrome browser
176
+ Fixed: Changes related with Apply and Discount Amount options for sub item, applied after clicking "Save Rule" button
177
+ Fixed: Invalid Timezone error for Asia/Calcutta when changing default country to India
178
+ Fixed: Sorting by position doesn't work for up-sells and related products
179
+ Fixed: Absent validation for "Only X left Threshold" field
180
+ Fixed: Shipping method calculation based on default shipping address instead of 'Same as billing' setting in backend
181
+ Fixed: There is no validation of the field "Handling Fee" that allows number less than zero in UPS shipping method
182
+ Fixed: Product name with "<>" processed incorrect during creation order in backend
183
+ Fixed: Billing Address Line is always blank if "REQUIREBILLING = 1" for PayPal Express
184
+ Fixed: Configuration->Inventory->Qty Increment isn't validated properly
185
+ Fixed: Absent message about not enough quantity for bundle and configurable products
186
+ Fixed: Wrong behavior of split buttons in IE8
187
+ Fixed: Warning message appears after unselecting user in the Role Users grid
188
+ Fixed: Incorrect total weight calculation in external shipping methods for products with decimal Qty Increments
189
+ Fixed: Tax calculation is incorrect if configurable product mixed up with other composite products in the shopping cart for Store Tax != Customer Tax
190
+ Fixed: Products qty displays wrong in layered navigation after changing currency
191
+ Fixed: Billing address fields are editable if "Same as shipping" selected on the PayPal Express order review page
192
+ Fixed: Incorrect location of "Clear All" link
193
+ Fixed: Incorrect price for bundle fixed product with custom option % and catalog price rule applied
194
+ Fixed: Import/Export: Append Complex Data works incorrect for customer's address and product's customs data
195
+ Fixed: Discount changes subtotal when FPT is active
196
+ Fixed: There is no ability to specify backup's name
197
+ Fixed: Multi selections fields for website scope settings are greyed out
198
+ Fixed: Persistent Shopping Cart: After deleting customers via backend, on frontend customer should be logout completely
199
+ Fixed: Incorrect logic during dividing products into multiple boxes for shipping
200
+ Fixed: Polls are not working properly in case with different domains for http and https
201
+ Fixed: "Block Reference" drop-down contains wrong list of options for frontend Apps types with Products
202
+ Fixed: "Wrong store specified" appears on order creation page
203
+ Fixed: Customer can't continue Checkout process after selecting Billing Address
204
+ Fixed: Refresh Statistics gone from Reports Role
205
+ Fixed: USPS shipping label is printed with "SAMPLE - DO NOT MAIL" sign
206
+ Fixed: Shipping methods are not refreshed after Update Order Data is pressed on PayPal Express Order Review page
207
+ Fixed: Product still invisible in frontend after required re-index
208
+ Fixed: JS error on configurable products
209
+ Fixed: Configurable product missing name in error message when exceeding quantity during order
210
+ Fixed: Added Display Product Count on the Layout Navigation
211
+ Fixed: "FedEx Priority Overnight" shipping method isn't calculated correctly
212
+ Fixed: Incorrect product price for Bundle products with fixed prices in the shopping cart
213
+ Fixed: "Ship Bundle Items" for bundle product works incorrect
214
+ Fixed: Impossible to expand settings accordions on the "Design Settings Editor" tab of Theme Customization page under IE7
215
+ Fixed: Impossibility to configure Bundle product with Disabled status and create new order with it in the backend
216
+ Fixed: Customer email isn't saved in Account Information field
217
+ Fixed: Unable to sort products by price
218
+ Fixed: Errors during creating/extracting "tar" archive with symbolic links
219
+ Fixed: Wrong message text in "Manage Coupon" tab on Shopping Cart Price Rule page
220
+ Fixed: 404 page not found error occurs when "Default Store" value is changed for Main Website
221
+ Fixed: Unable to import products if Catalog price rule enabled
222
+ Fixed: Partial Re-index isn't done for product saved in backend
223
+ Fixed: Catalog Price Rule: "Save and Apply" action leads to apply ALL rules, but it have to apply only specified rule
224
+ Fixed: Tax isn't recalculated on PayPal Express
225
+ Fixed: Backup Name field should allow entering only a limited number of characters
226
+ Fixed: In the "Subtotal" row of "Coupons Usage Report" displayed amounts for all Shopping Cart Price Rule in the system
227
+ Fixed: Shipping address isn't passed to Magento from PayPal
228
+ Fixed: Store view isn't changed when customer subscribes for newsletters
229
+ Fixed: Shopping Cart Price Rules are not marked after creating Coupons Usage Report
230
+ Fixed: Change buttons structure in prototype/windows.js to match general adminhtml buttons structure
231
+ Fixed: Wrong error message on Create New Order page in backend
232
+ Fixed: Impossible to configure order of displaying rating values in the frontend
233
+ Fixed: Incoming Message in Admin Part has the superfluous symbol '\'
234
+ Fixed: Numerous issues with promotions on complex products
235
+ Fixed: Recipient Postal-State Mismatch error seen on Shipping Label with FedEx
236
+ Fixed: Text messages "This is a required fields." are displayed in the hidden FTP section
237
+ Fixed: Incorrect popup on Manage Coupon Codes tab in Shopping Cart Price Rule
238
+ Fixed: Layered navigation work incorrect if attribute values defined on Store View level
239
+ Fixed: Checking import file returns blank page
240
+ Fixed: Change the VAT Number format before sending to VAT ID Validation service
241
+ Fixed: Simple products with configured customs options displayed in wishlist incorrectly
242
+ Fixed: Incorrect text message for product for which there is no enough quantity in stock
243
+ Fixed: Setting float Qty Increments is possible, but doesn't work
244
+ Fixed: SQL error during checkout when customers register at checkout and orders a nominal item
245
+ Fixed: Iframe for gateway isn't reloaded on the Payment information tab
246
+ Fixed: Incorrect behavior after placing order from backend in FF9
247
+ Fixed: Catalog price rule skips conditions specified and applies to all products in the catalog
248
+ Fixed: Price rule is applying to individual items in bundle when price is set to Dynamic
249
+ Fixed: Impossible to save payment method configurations on the Default Config scope
250
+ Fixed: "There has been an error processing your request" message is display if not CSV file was selected to import
251
+ Fixed: Wrong reindex product attributes after bundle product save
252
+ Fixed: Add Products button absent during creating order from backend
253
+ Fixed: "All methods" should be selected by default in configuration section "Allowed Methods" for UPS
254
+ Fixed: Redirect to base URL issue
255
+ Fixed: Added Backup sorting by name possibility
256
+ Fixed: Fix grammar mistakes
257
+ Fixed: Notifications are not shown if URL Rewrite used
258
+ Fixed: "Stop Further Rules Processing" option doesn't work
259
+ Fixed: Admin cannot un-assign product from the tag if already approved tag was added to the product by customer
260
+ Fixed: Inaccuracy calculation could be 10% for FedEx International Ground shipping
261
+ Fixed: Incorrect price calculation of configurable product with custom options (resolved conflicts)
262
+ Fixed: Wrong currency displayed in Recently Viewed Product App
263
+ Fixed: Tabs are grayed on admin dashboard
264
+ Fixed: JS validation for product weight attribute doesn't work
265
+ Fixed: Group Price attribute is present as text field using the mass update action
266
+ Fixed: Shopping Cart Price Rule isn't applied to Not Logged In Customers
267
+ Fixed: "Sign up for our newsletter" text appearing twice
268
+ Fixed: Newsletter problem report grid on backend throws Exception
269
+ Fixed: Special price doesn't work for Bundles with Dynamic price
270
+ Fixed: My Orders block disappears in My Account pages when Reorder functionality is disabled
271
+ Fixed: Search doesn't work in Backups grid
272
+ Fixed: Re-index "Catalog URL Rewrites" works extremely slowly
273
+ Fixed: Checkbox state is preserved for "Put store on the maintenance mode while rollback processing"
274
+ Fixed: UPS Configuration All Methods Should Be Selected by Default
275
+ Fixed: Rollback fails if database backup was performed after product import
276
+ Fixed: Incorrect behavior with 10-digit Zip code, after creating new Tax Rate
277
+ Fixed: Configurable attributes that used for create configurable product should not be applied to that product
278
+ Fixed: Default group has to be used if customer selects address without VAT number
279
+ Fixed: No ability to create Shopping Cart Price Rule
280
+ Fixed: Layout issue appears in IE9 on the export grids
281
+ Fixed: Issue when trying to view the order using a specific admin user
282
+ Fixed: System messages are not displayed at CMS pages and appears only when another message will be invoked
283
+ Fixed: On the frontend Search doesn't work properly if search value is 0 (null)
284
+ Fixed: The size of the columns in Backup grid is changed if no records were found
285
+ Fixed: Maintenance flag isn't deleted if rollback fails with not enough permissions error
286
+ Fixed: Customer's group isn't changed if his billing address modified within backend
287
+ Added Add a message and the link in the mini shopping cart, when the cart is empty
288
+ Fixed: On Edit Shipping Address page button "Validate VAT Number" should be hidden
289
+ Fixed: Fatal error when try to ship order with Flat Rate shipping method
290
+ - fixed potentially problematic chaining involved getShippingCarrier method
291
+ Fixed: No ability to open PDF file with Label
292
+ Fixed: Incorrect final price for configurable products if several custom options used
293
+ Fixed: "Length", "Width" and "Height" fields on "Create Packages" pop up are active, when "Documents" type is selected in IE7 and IE9
294
+ Fixed: HTTP 500 error on frontend for bundle fixed with percent options enabled for sub-products
295
+ Fixed: Shipment created on Magento side doesn't send to Google side for Merchant Calculated shipping
296
+ - added check for process only Google Checkout internal methods
297
+ Fixed: PDF files for invoices and credit memos are not displaying Including Tax Price
298
+ Fixed: Default value that was specified in system settings doesn't presented in Code Format drop-down on Manage Coupon Codes tab
299
+ Fixed: Qty wipes out to 0 when no qty column is included on import
300
+ Fixed: Broken controls makeup is observed after resizing window when customer's page is opened on the backend
301
+ Fixed: Values don't fit to "Date Fields Order" drop-downs in "Date & Time Custom Options" on the Catalog page
302
+ Fixed: Processing error appears for products with "Qty Uses Decimals" = No and enabled DHL International
303
+ Fixed: Apply Tax to FPT setting doesn't seem to work for products with Fixed Product Taxes
304
+ Fixed: Apply Coupon Code textbox doesn't fit in the Apply Coupon Code channel on the backend after reducing the browser window
305
+ Fixed: Tax and Shipping amounts aren't showing on the merchant reports for Websites Payments Pro PayFlow Edition
306
+ Fixed: Incorrect error popup on Manage Coupon Codes tab in Shopping Cart Price Rule
307
+ Fixed: No ability to create Shipping Label with New DHL shipping methods
308
+ Fixed: Indexing update on save takes too long for large catalog_product_entity_int tables
309
+ Fixed: VAT ID group validation takes Default configuration on order creation from backend
310
+ Fixed: Pagination isn't shown on My Product Reviews page when items count exceeds the "Show per page" setting
311
+ Fixed: Inline translation missing for customer account information labels
312
+ Fixed: Corrupted text if drag attribute on Manage Attribute Sets page (IE8)
313
+ Fixed: Wrong calculation price of Bundle product with Fixed price, when special price is configured
314
+ Fixed: Error Message isn't displayed during unsuccessful Shipping Label creation
315
+ Fixed: Unverified redirect is possible in Checkout controller
316
+ Fixed: Customer group in not validated again on checkout if Tax Calculation Based on = Shipping Address
317
+ Fixed: "Clear All" link doesn't work
318
+ Fixed: Wrong message appears when products quantity is updated in the Shopping Cart with enabled Qty Increments setting
319
+ Fixed: Created On field on Manage Coupon Codes grid shows incorrect date/time
320
+ Fixed: Incorrect price calculation of configurable product with custom options
321
+ Fixed: Manage Products > Custom options: Should be possible to enter negative price for custom option of 'Date' type
322
+ Fixed: HTTP 500 Internal Server Error on Admin Forgot Password page
323
+ Fixed: CSV/Excel XML export doesn't work on Sales->Invoices if filter by Selected=Yes is used
324
+ Fixed: "Same As Billing Address" check-box doesn't work
325
+ Fixed: Impossible to enter zero in the base price field for customer groups
326
+ Fixed: Group Price attribute position on the Prices tab is incorrect
327
+ Fixed: Add new column to the grid with number of used coupons
328
+ Fixed: Custom options are not stored when downloadable product is duplicated
329
+ Fixed: Broken logic for "Zero Subtotal Checkout" order statuses
330
+ Fixed: Coupon codes generation fails when trying to generate large amount of codes
331
+ Fixed: PayFlow Link: Using "Pay with PayPal" and selected shipping method that is greater than 0 doesn't process order
332
+ Fixed: User have to stay on Add New Rule page if error appears on save shopping cart price rule
333
+ Fixed: "Automatically Invoice All Items" should be inactive, when were selected "New Order Status: Pending" in "Zero Subtotal Checkout" settings
334
+ Fixed: When enormous request in search fields on the front end 414 error appears
335
+ Fixed: JS error on edit Shopping Cart Price Rule Page
336
+ Fixed: Clear Shopping Cart button add selected item to Items Ordered if check box "Add to Order" is selected
337
+ Fixed: "Clear Shopping Cart" button must be located to the left to "Update Shopping Cart" button
338
+ Fixed: Export of Group Price data doesn't work
339
+ Fixed: Incorrect translation messages definitions
340
+ Fixed: Error message isn't displayed if currency exchange rate not found (in case with DHL Int)
341
+ Fixed: User role with partial access can't edit attributes of configurable products
342
+ Fixed: Letter "n" missed in the word "handling"
343
+ Fixed: Buttons don't react for pressing on the "Widget Options" section in Insert Widget window
344
+ Fixed: Regular price displays incorrect
345
+ Fixed: {{base_url}} in (un)secure_url doesn't work since 1.6.1
346
+ Fixed: Product selection field gets cleared out with recently added products from latest page
347
+ Fixed: "Change" button while checkout doesn't work
348
+ Fixed: MySQL BIGINT field type is wrongly casted to integer
349
+ Fixed: Magento Connect Manager proceed with installation of extension if error appears on database backup
350
+ Fixed: "Set product as New from/to Date" works excluding selected dates
351
+ Fixed: Function fireEvent from lib/varien/js.js does not work in IE9
352
+ Fixed: Searching with first and last name has no results
353
+ Fixed: CMS Pages: Error in IE7 when select CMS page
354
+ Fixed: White screen appears instead of 404 Error Page when going to review a product which doesn't exist
355
+ Fixed: "Maximum Package Weight" option works incorrect in case with decimal Qty in shopping Cart
356
+ Fixed: Unable to create tables for new EAV entity via SQL upgrade script
357
+ Fixed: Customer group isn't revalidated on checkout if Enable Automatic Assignment to Customer Group = Yes
358
+ Fixed: Mistake in PayPal Payments Advanced field set title
359
+ Fixed: Zero Subtotal Checkout payment method is used, when it is disabled in settings
360
+ Fixed: Some info lost from address when customer sets this address as default for shipping
361
+ Fixed: Incorrect calculation logic during distribution products between several pieces (in case with DHL)
362
+ Fixed: No ability to get shipping rates from US to another country (in case with DHL)
363
+ Fixed: Incorrect calculation of pieces weight (in case with Bundle Product)
364
+ Fixed: Product Flat Data index causes replication lag on MySQL master/slave model
365
+ Fixed: Exception is shown, when admin user provides filtration of Newsletter problem reports by Subscriber
366
+ Fixed: Typo in JavaScript error message
367
+ Fixed: Unable to do mass action update for products
368
+ Fixed: Error Message isn't displayed if currency exchange rate not found (in case with DHL)
369
+ Fixed: Weight field is absent during Quick simple product creation
370
+ Fixed: correct helper resolving
371
+ Fixed: Shipping methods are shown twice in DHLs shipping quote
372
+ Fixed: Unable to translate shipping and billing forms on the order creation page
373
+ Fixed: Drop-down attribute with layered navigation filter doesn't work with value is set to 0
374
+ Fixed: Free Shipping options don't work (in case with DHL)
375
+ Fixed: Handling Fee doesn't applied Per Package
376
+ Fixed: Free Shipping options works incorrect
377
+ Fixed: WYSIWYG Editor: It's impossible insert Widget to CMS page content
378
+ Fixed: Customer's group is not changed if his billing address modified within backend
379
+ Fixed: Wrong behavior and exception while using invalid image
380
+ Fixed: Uninformative error message during saving two nodes with the same parameter URL Key
381
+ Fixed: Unable to change order addresses in the admin panel
382
+ Fixed: PayPal Express always uses default billing address from customer account
383
+ Fixed: Unable to place order if customer selects Register on checkout
384
+ Fixed: Performance Issue: Most Viewed product reports on large amount of items
385
+ Fixed: In "Customer Addresses" block before and after of State name is located symbols ","
386
+ Fixed: Lightbox 2.5 with IE7 returns JS error on the page
387
+ Fixed: Unable to change customer status (confirmed/not confirmed) when customer logged in
388
+ Fixed: Incorrect notification for empty field during creation catalog price rules
389
+ Fixed: Unable to save product with non-checked multiple select attribute
390
+ Fixed: Package Size setting for DHL
391
+ Fixed: No Input Validation for Catalog Fields
392
+ Fixed: Row Total Calculation in Refund
393
+ Fixed: "Maximum number of price intervals" should be written with capital letters
394
+ Fixed: Divide Order Weight options for DHL
395
+ Fixed: Impossible to create new customer in the backend
396
+ Fixed: Catalog data-upgrade-1.6.0.0.4-1.6.0.0.5.php is extremely slow
397
+ Fixed: Mage_Catalog_Helper_Product::getProduct() doesn't load product by its SKU
398
+ Fixed: Preview Template doesn't work correctly
399
+ Fixed: Some options of Bundle Product disappeared from the Invoice PDF
400
+ Fixed: "Allow Countries" affects on "Country of Manufacture" attribute
401
+ Fixed: Some phrases are not translated
402
+ Fixed: Incorrect Ordered Qty in Order (in case with decimal qty)
403
+ Fixed: Trademark character isn't being displayed properly in the PDF invoice
404
+ Fixed: Can't search transactions by order_id in manager.paypal.com
405
+ Fixed: Inline Translation: Grid headers are displayed incorrect on the Tag Edit page
406
+ Fixed: "Create Extension Package" page becomes broken after compilation
407
+ Fixed: Price including tax isn't displayed for some kinds of bundle products
408
+ Fixed: Layered navigation for prices displays incorrect price ranges in manual mode
409
+ Fixed: Pager works wrong with float page number
410
+ Fixed: Incorrect foreign key for EAV entity tables
411
+ Fixed: Misprint in downloader/lib/Mage/Connect/Command/Install.php
412
+ Fixed: URL Rewrites must be case-sensitive
413
+ Fixed: Unable to install package via uploader if author name contains dash
414
+ Fixed: Invoice subtotals for cases with partial invoice and discount
415
+ Fixed: Catalog URL Rewrites works incorrectly on creating categories
416
+ Fixed: New Oder Status setting, specified for payment method works incorrectly when only virtual products are present in Order
417
+ Fixed: Rounding issue in catalog and product view if price includes tax
418
+ Fixed: Wrong status of catalog event is displayed by editing catalog event
419
+ Fixed: Role Resources are not saved
420
+ Fixed: "Qty for Item's Status to Become Out of Stock" option works incorrect
421
+ Fixed: XML parser works incorrect
422
+ Fixed: Mage_Reports_Model_Mysql4_Product_Index_Abstract must be declared abstract
423
+ Fixed: "Date & Time" and "Time" custom options becomes required when editing product
424
+ Fixed: Unable to cancel an order for an expired Authorize.net authorization
425
+ Fixed: Custom options are not stored when downloadable product is duplicated
426
+ Fixed: "Cannot initialize the indexer process" error during Mass "Reindex Data" Action
427
+ Fixed: Search by new attribute fails, attribute is not shown in layered navigation
428
+ Fixed: Exception when "Price Navigation Step Calculation" set to "Manual" mode and FPT enabled
429
+ Fixed: WPPHS: Cancel URL doesn't work as should be
430
+ Fixed: Error about insufficient permissions is not appears on database backup creation
431
+ Fixed: After rollback admin doesn't redirected to the Log in to Admin Panel page
432
+ Fixed: Database Backup must not include indexer table data
433
+ Fixed: Scheduled Backup creation/failure isn't logged
434
+ Fixed: Deleting backup while it is used by another process
435
+ Fixed: Opening *.tar files causes an error "There are no trailing zero-filled records"
436
+ Fixed: Unable to search by "Time" and "No" in Backups table
437
+ Fixed: Backups are deleted without confirmation
438
+ Fixed: Reports must be excluded from database snapshot backup
439
+ Fixed: There are no products in filtering results, if step calculation in automatic mode
440
+ Fixed: No validation for "Default Price Navigation Step"
441
+ Fixed: "Back" button doesn't work on the Create New Order page
442
+ Fixed: Incorrect logic of Token expiration in Two Step Password Reset flow
443
+ Fixed: Tag <br/> is present in tool-tip for field "Number of results (For the last time placed)" on the Edit Search page
444
+ Fixed: Unnecessary hard code in Magento Extension
445
+ Fixed: Wrong logic in Mage_Core_Model_Resource_Db_Collection_Abstract::join()
446
+ Fixed: Description and Short Description are displayed incorrectly for products added with WYSIWYG
447
+ Fixed: Adding product to the cart from the product review page leads to 404 page
448
+ Fixed: Special symbols in Sort Order field
449
+ Fixed: Text is wrong displayed with enabled Inline translation for Admin on backend
450
+ Fixed: Inline Translation: Unable to translate some customer information
451
+ Fixed: Useless colon on frontend login page
452
+ Fixed: Unable to continue checkout for product with zero price and non-zero shipping price
453
+ Fixed: Import news_from_date field is configured poorly. It is not accepting the data from file
454
+ Fixed: When updating product data through import, attributes that have a value cannot be assigned a new value that is empty
455
+ Fixed: Unable to replace non-complex data for products with empty values during import
456
+ Fixed: "Wrong order ID" exception in PayPal Express module under heavy load
457
+ Fixed: Tax is applying on the order when creating it in the admin panel for a Customer Group with no taxes
458
+ Fixed: Issue with retrieving order statuses for array of states
459
+ Fixed: Wrong calculation product price with custom option type = Field and Fixed price
460
+ Fixed: Back ordered downloadable product is not available even when it is set to be be accessible when order status is Pending
461
+ Fixed: Missing column "position" at table catalog_category_anc_products_index_tmp
462
+ Fixed: Incorrect behavior of "Save in address book" option during admin Order creation for a new customer
463
+ - refactored Mage_Adminhtml_Model_Sales_Order_Create::_prepareCustomer()
464
+ Fixed: Terms and Conditions is named differently on different pages
465
+ Fixed: "Apply" and "Discount Amount" fields appear twice in the Catalog Price Rule
466
+ Fixed: Poll shows incorrect percentage
467
+ Fixed: Added validation ability for admin configuration forms
468
+ Fixed: UPS XML misprint
469
+ Fixed: Misprint in uploading files form
470
+ Fixed: Unnecessary check boxes for gift options
471
+ Fixed: Wrong resource section declaration in Mage_Tag module
472
+ Fixed: "Customers Submitted this Tag" section doesn't update when customer has deleted tag from his account
473
+ Fixed: Correct product in category position
474
+ Fixed: Unable to create folder in Media Storage
475
+ Fixed: Translation with single quotes breaks JavaScript
476
+ Fixed: Out of memory error with hundreds of thousands of coupons attached to a single sales rule
477
+ Fixed: Unable to translate buttons and tabs on the "Manage Category" page
478
+ Fixed: Product Categories Tree doesn't expand in Manage Products page
479
+ Fixed: Incorrect products qty returns to stock after refund for configurable product
480
+ Fixed: Swf Uploader problems with cross domain Flash Player Policy
481
+ Fixed: Unable to translate "Layout Updates" block on create/edit widget page
482
+ Fixed: IE7: "Remember Me" checkbox visible on billing information step
483
+ Fixed: CMS WYSIWYG Editor - widget is inserted as new while editing in IE8
484
+ Fixed: Currency code doesn't correspond to the amount in reports
485
+ Fixed: Mage_Adminhtml_Block_Sales_Order_View_Tab_History::getFullHistory() doesn't use unique keys for each message
486
+ Fixed: Scope labels are shown without translate wrapper
487
+ Fixed: Wrong parameters handling in Core Helper formatDate()
488
+ Fixed: Apostrophe in store name breaks Google Analytics tracking
489
+ Fixed: Customer attribute prefix is not shown on frontend
490
+ Fixed: Incorrect rounding for product with custom options (percent price)
491
+ Fixed: Invoicing only part of products results in wrong totals calculation
492
+ Fixed: Incorrect Row Total Calculation in Refund
493
+ - fixed rounding issues for partial Invoice and Refund
494
+ - refactored delta rounding
495
+ Fixed: Filter by "Allow Countries" not working for Customer Address Form in the backend
496
+ - checking added for set country to be in available list
497
+ Fixed: There are sql-installs with empty string used as defaults for table columns, while column is not null able
498
+ Fixed: Unable to translate "Note" in "Product Stock Options"
499
+ Fixed: Various warning are displayed after creating shipment for 0 items
500
+ Fixed: Invalid content in Content-header in the top of page during scrolling during order creation
501
+ Fixed: "Online invoice" button present in backend when using Zero Subtotal Checkout
502
+ Fixed: String cast type in in_array function
503
+ Fixed: Newsletter template content should not disappear when "Show" / "Hide Editor" button was clicked
504
+ Fixed: Import feature doesn't validate whether super_products_sku is existing or not
505
+ Fixed: Cannot place order with downloadable product and discount code using Paypal Express payment method
506
+ Fixed: Product still out of stock after Stock Status reindex
507
+ Fixed: Save catalog price rule gives trace if full reindex has already started
508
+ Fixed: Reindex requires notification is not shown for Stock Status when stock is updated for several products using Mass Action
509
+ Fixed: Incorrect FedEx's shipping rates (in case with non-US country origin)
510
+ Fixed: After partial reindex MSRP value is not applied (not viewed) in catalog during mass update action
511
+ Fixed: Wrong stock reindex on catalog if partial reindex done after full reindex started
512
+ Fixed: In error message string "already exists." written twice, when trying to save Product Tax Class with the same name
513
+ Fixed: Slow checkout with non-flushed cache
514
+ Fixed: Bundle product total is incorrect in Customization block
515
+ Fixed: Special price isn't considered for bundle dynamic products in "Your Customization" block
516
+ Fixed: Situation when any amount of duplicate reindex process can be running at one time
517
+ Fixed: Error with Advanced Search (in case with Date Attribute)
518
+ Fixed: Product Flat Data index isn't marked as "Reindex Required" after importing products when Flat Catalog is enabled
519
+ Fixed: User can't change root category for the store
520
+ Fixed: JS error causes the overwrite of Title field in PayPal Advanced configuration
521
+ Fixed: Mass action doesn't partially reindex catalog for product name/description
522
+ Fixed: Remove hint about $1 auth amount from informational message text (PayflowLink configuration)
523
+ Fixed: Mass action doesn't partially reindex catalog for product prices
524
+ Fixed: PayPal Payments Advanced works with $0 Auth instead of Full Auth
525
+ Fixed: Impossible to place Order using "Pay with PayPal" button from PayPal Payments Advanced iframe
526
+ Fixed: Mass action doesn't partially reindex catalog search for product if searchable attribute was updated
527
+ Fixed: "Please wait" AJAX screen doesn't appear in the middle of the page
528
+ Fixed: Checkout link on frontend is always referenced as http
529
+ Fixed: GET request is incorrectly formed during category creation
530
+ - adjusted assertion to determine last viewed store
531
+ Fixed: Display of Tier Pricing with Configurable Products
532
+ - added functionality to dynamically update tier prices accordingly to chosen product configuration
533
+ Fixed: Google Analytics e-commerce tracking not working
534
+ Fixed: URL key isn't used when product is saved
535
+ Fixed: Added validation class to 'Qty increments'
536
+ Fixed: Entered from admin customer date 1970 (or less) is saved as 2070 (or less)
537
+ Fixed: cUrl resource must be closed after checking it for errors, not before
538
+ Fixed: Exception while products mass update attributes in backend
539
+ Fixed: No ability to reindex Catalog URL Rewrites, error is shown
540
+ Fixed: Package with Core dependency
541
+ Fixed: Stock Availability isn't updated if 1: Run Price Reindex 2: Update Stock Availability on product with mass action/single product
542
+ Fixed: Blank page instead shopping cart page when compilation and PSC are enabled
543
+ Fixed: Unable to save redirect URL with special characters in search terms
544
+ Fixed: Attribute Set field should have client-side validation and appropriate information message
545
+ Fixed: "Localhost" isn't a valid domain name for installation
546
+ Fixed: Iframe for PayPal Payments Advanced is not loaded
547
+ Fixed: Retain the selected tab on editing CMS page
548
+ Fixed: Payflow Link Express Checkout (pay with PayPal button) payment
549
+ Fixed: Wrong number of reindex options is displayed
550
+ Fixed: Wrong phpDocs for Varien_Db_Select
551
+ Fixed: JavaScript calendar date range
552
+ - fixed JS calendar behavior to use 4-digits year format
553
+ Fixed: Performance issue connected with sales rules on adding product to cart
554
+ Fixed: DHL same error message appears several times
555
+ Fixed: Item Status says "Mixed" when an order has been completed, should say "Shipped"
556
+ Fixed: Product option title is absent in backend order page
557
+ Fixed: Incorrect items number during multi shipping checkout
558
+ Fixed: User name displays differently in the unsuccessful message and in the text field label (log in form)
559
+ Fixed: If one or more indexers have Update Required = Yes and all Status = READY for all indexers than there is no notification for user to do reindex action
560
+ Fixed: No space between Address line 1 and line 2 in Shipping Label (in case with FedEx)
561
+ Fixed: JS works depends on the position attributes of the product
562
+ Fixed: Char set encoding is out-of-date in Settlement reports
563
+ Fixed: Settlement reports can't be downloaded if in merchant's account 'Settlement file' is set to 6.0 version
564
+ Fixed: Unable to login when secure and unsecure URLs are different
565
+ Fixed: Customer session lost when using different domain/subdomain names for secure and unsecure URLs
566
+ Fixed: "Most Viewed" reports ignore Store View switcher
567
+ Fixed: Long FPT name (and product name) doesn't fit into "My cart" block
568
+ Fixed: Paypal IPN post back failure
569
+ Fixed: Customer was unable to receive newsletters when it was created via backend
570
+ Fixed: Wrong Comments History in notification of order creation/cancellation
571
+ Fixed: Non escaped string causes javascript error
572
+ Fixed: Unable to view pictures during product editing
573
+ Fixed: Ampersand is saved incorrect in attribute label
574
+ Fixed: IE8: JS error appears after pressing 'Add new rule' in catalog price rules menu
575
+ Fixed: Exception after sorting newsletter queue
576
+ Fixed: Customer is not able to log in from URL without "www" in some cases
577
+ Fixed: SQL error on category view with enabled and configured FPT
578
+ Fixed: Automatic reindexing based on matched events doesn't change "Status" and "Last Run" columns at process list grid
579
+ Fixed: Performance issue with Magento Compiler + APC results in too many I/O calls
580
+ Fixed: Website Administrator is able to change default values
581
+ Fixed: Some of wishlist blocks and templates still treat the collection of wishlist items as collection of products
582
+ Fixed: Unnecessary comments in "Share Wishlist" email
583
+
584
+
585
+
586
+ ==== 1.7.0.0-rc1 ====
587
+
588
+ === Major Highlights ===
589
+ New Layered Navigation price bucket algorithm
590
+ Added captcha functionality
591
+ Implemented different base prices for customer groups
592
+ Added auto generation of coupon codes
593
+ Backup and Rollback functionality
594
+ VAT ID Validation added
595
+ Implemented DHL for Europe
596
+ Added REST API
597
+
598
+ === Improvements ===
599
+ XmlConnect package release v22.1
600
+ Upgraded TinyMCE to v3.4.7
601
+ Mobile theme was redesigned
602
+ Added ability to translate action array parameter nodes via layout.xml
603
+ Added support for using custom currency symbols
604
+ Added functionality to cleaning old cache files by cron task
605
+ Refactored rules-based modules
606
+ Improved customer address handling using PayPal Express checkout
607
+ Refactored escaping functionality used with translations
608
+ Added ability to customize logo in emails from the admin
609
+ Implemented front-end cookies restriction functionality
610
+ Added ability to turn off/on IP Tracking (e.g. 'Placed from IP') on the Sales pages in back-end (Order, Invoice, Shipment, Credit memo)
611
+ Provided logic to disable ACL resources through configuration files
612
+ Added additional placeholders for extensions developers
613
+
614
+ === Changes ===
615
+ Added "Cash On Delivery" and "Bank Transfer" payment methods
616
+ Support for "memcached" PHP extension was added
617
+ Library js/scriptaculous/dragdrop.js is upgraded to version 1.9.0
618
+ Image file of "jpg" type are allowed for favicon
619
+ Added ability to extend list of attributes to select for categories loaded via Mage_Catalog_Model_Resource_Category_Flat::_loadNodes()
620
+ Added changes to lib/Varien/Http/Adapter/Curl.php to provide interface for setting different cURL options
621
+ Displaying State or Province can be optional for any country
622
+ Added ability to get Magento type from Mage.php
623
+
624
+ === Fixes ===
625
+ Fixed Multiple warnings in system.log after running compilation process
626
+ Fixed Session is lost while redirecting from secure to unsecure URL
627
+ Fixed Redirect to base URL should consider full request URI string
628
+ Fixed Product name with <> processed incorrect during creation order in backend
629
+ Fixed FedEx SmartPost method doesn't appears in rate request
630
+ Fixed 3 and 4 digits CVV should be accepted for JCB cards
631
+ Fixed Google Checkout tax isn't applied to Bundle product
632
+ Fixed FPT is not considered by Google Checkout
633
+ Fixed An error occurred during second Customer authorization fail
634
+ Fixed Property declaration typo in Mage_Bundle_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option
635
+ Fixed Product is not shown in the Catalog when it is Out of Stock and Display Out of Stock Products = Yes
636
+ Fixed Impossible download downloadable product (problem with secure link)
637
+ Fixed Wrong letter case in class names may cause malfunction when Compiler is enabled
638
+ Fixed Incorrect invoice amount in order with FPT
639
+ Fixed Attributes not connected to any product of selected category display in layered navigation
640
+ Fixed No feedback on creating attribute set in IE9 and IE8
641
+ Fixed Unexpected breaking import process leads to creation phantom data into database
642
+ Fixed Two of the same FedEx option show instead of one
643
+ Fixed Notification for Google contains link that cover large area and blocked user work
644
+ Fixed Possible to create user role with empty name if it starts with "less than" sign
645
+ Fixed Impossible to use Clear Shopping Cart button in IE7
646
+ Fixed Impossible create product with one FPT price for all State/Province
647
+ Fixed 'Interval Division Limit' affects to global displaying of Layered Navigation
648
+ Fixed Shipping method must be recalculated on Order Review page if Transfer Shipping Options is enabled
649
+ Fixed Issue with different secure/unsecure URL cause session data lost
650
+ Fixed Can't save option Country in Store Information Tab
651
+ Fixed Rule date information has been missed after using Product Rule or Shopping Cart Price Rule
652
+ Fixed Billing/Shipping address algorithm for PayPal Express checkout works incorrect
653
+ Fixed Error during quick search
654
+ Fixed Block "Description" on Catalog Price Rule page has incorrect size
655
+ Fixed Search doesn't work if Maximum Query Length field is empty
656
+ Fixed The Tags Product RSS doesn't update information after changing tag
657
+ Fixed Customer Attributes and Customer Address Attributes validation
658
+ Fixed Issue with final price calculation for Configurable product with sub products
659
+ Fixed Blank page after customer registration with enabled compilation
660
+ Fixed "Place Order" button must be enabled if all required fields passed the validation on PayPal Express Checkout
661
+ Fixed Products quantity displays incorrect in price ranges after import (rounding problem)
662
+ Fixed Layout issue in shopping cart on Frontend (IE8)
663
+ Fixed Impossible to assign user to the role if he is assigned to another role
664
+ Fixed 'Total records found' on Reports -> Tags -> Popular page shows wrong quantity of records
665
+ Fixed Unable to refresh lifetime statistics
666
+ Fixed After changing Price Navigation Step calculation from Automatic in Continuos the category is loaded very slowly
667
+ Fixed No ability to create Shipping Label (in case with USPS First-Class Mail International Parcel method)
668
+ Fixed It is impossible to create Shipping Label for FedEx
669
+ Fixed Redirect Customer to Account Dashboard after Logging is in enabled and doesn't work for Wishlist
670
+ Fixed No ability to edit values using mass actions for product in IE8, IE9
671
+ Fixed Wrong message during checkout process in Inline Translate mode
672
+ Fixed Default country is selected in Shipping Address during Admin order creation
673
+ Fixed The Static block widget doesn't displayed on the Product View Extra hint for bundle product
674
+ Fixed Bunch of W3C validation errors on frontend while using inline translate
675
+ Fixed Product's association to root category is lost after export/import
676
+ Fixed WYSIWYG Editor: Page is scrolled to the top after inserting variables
677
+ Fixed Incorrect Backup/Rollback message
678
+ Fixed FedEx Free shipping doesn't work correctly
679
+ Fixed Configurable product displaying double price when choosing option
680
+ Fixed Impossible to configure Admin User Emails for store view scope
681
+ Fixed Long payment method data is printed improperly in PDF invoice
682
+ Fixed Impossibility of changing the Rating Value title for store view in existing Rating Value with filled the Rating Value title for store view
683
+ Fixed Trademark symbol not showing up
684
+ Fixed Add "Delivery Option" for FedEx Configurations
685
+ Fixed Saving product takes long time
686
+ Fixed Notice message disappear after clearing cache
687
+ Fixed Products qty displays incorrect in price ranges after import (rounding problem)
688
+ Fixed Images in CSS fail when merging CSS files
689
+ Fixed Mass action update of any attributes resets multiselect attributes to NULL
690
+ Fixed Move CSS from Prototype Windows plug-in to the backend skin
691
+ Fixed DB adapter should check transaction level in case of DDL query
692
+ Fixed When Payment method additional info contains double quote it is displayed as '&quot;' in invoice PDF
693
+ Fixed Incorrect Unit Price(Excl. Tax) in the Shopping Cart Grid after changing currency
694
+ Fixed Incorrect total quantity of records and pagination doesn't work on Reports->Reviews->Products Reviews page
695
+ Fixed Incorrect title of All Reviews for product page
696
+ Fixed Invalid message in shopping cart when trying to add products amount more than allowed
697
+ Fixed Layered Navigation: Icon "Previous" should be appear only on sub-intervals level
698
+ Fixed Processing error occurred when big numeric value is entered to an browser URL
699
+ Fixed Issue with credit memo for multiple bundled products (order status is Processing)
700
+ Fixed Customer group has to be emulated even if customer is sticky assigned to the group
701
+ Fixed "Customs Value" isn't represented in store base currency
702
+ Fixed Layered Navigation: After clicking on interval $0.00, should be filtered and displayed products with price 0.00
703
+ Fixed Absence of redirecting to the grid page after saving Role/User
704
+ Fixed Incorrect logic of assignment of unique ID in Varien_Data_Collection
705
+ Fixed Problems with sorting actions
706
+ Fixed When product is unsaleable checkout is still possible depending on its position in cart
707
+ Fixed Impossibility of creating new order with "Reorder" button when Out of stock or disabled products had been ordered
708
+ Fixed "Online Minute Interval" customer configuration option should have global scope
709
+ Fixed Unable to translate Active/Inactive in promotions grid
710
+ Fixed Response headers contains 500 error during front-end pages browsing
711
+ Fixed Add additional button to PayPal Redirect Page
712
+ Fixed Category Permissions: if "Display Product Price" is set to "No" the page toolbar is absent
713
+ Fixed Layered navigation options have wrong order in back-end
714
+ Fixed The "Remember Me" check box with the "What's this?" link should be located below the "Forgot Your Password?" link
715
+ Fixed Warning message is absent, when "Recovery Link Expiration Period" is specified within the correct range
716
+ Fixed PayPal HSS (Website Payment Pro Hosted Solutions) France doesn't work
717
+ Fixed Remove email from Billing address section of the PayPal Express Order Review page
718
+ Fixed It is available enter negative digits in the "Layered Navigation Price Step" (on Category page)
719
+ Fixed First/Last Name algorithm for PayPal Express checkout
720
+ Fixed Asterisk isn't imported in Zip/Post Code field
721
+ Fixed Some strings are not translated in widgets
722
+ Fixed Session isn't stored between secure and usecure URLs when they are located in different paths of the same domain (no SID in request)
723
+ Fixed "USPS First Class International Parcel" will not show up as an option for customers during checkout
724
+ Fixed UPS, FedEx and DHL methods should work if zip code from / to isn't required
725
+ Fixed Issue when trying to create an order from the back-end without selecting the state/province
726
+ Fixed HTTP error when uploading images from a MacOS with shockwave flash 11.1.102.55
727
+ Fixed UPS Configuration "All Methods" should be selected by default
728
+ Fixed Cannot create a product review through back-end
729
+ Fixed Typos in Role Permission tree
730
+ Fixed WYSIWYG button layout issue on product page
731
+ Fixed Require Customer's Billing Address is missing option "For Virtual Quotes Only"
732
+ Fixed Errors appears on Design Configuration page if transactional email's logo image and/or favicon files were deleted
733
+ Fixed State/Province value is reset after page reload on some forms
734
+ Fixed Cannot access back-end after switching on and switching off "Use Custom Admin URL"
735
+ Fixed "Unsubscribe Selected" and "Delete Selected Problems" buttons don't work
736
+ Fixed After selecting shipping from dropdown system doesn't update order data automatically on PayPal Express Order Review page
737
+ Fixed Buttons on the back-end order page don't have titles
738
+ Fixed ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION error in Chrome browser
739
+ Fixed Changes related with Apply and Discount Amount options for sub item, applied after clicking "Save Rule" button
740
+ Fixed Invalid Timezone error for Asia/Calcutta when changing default country to India
741
+ Fixed Sorting by position doesn't work for up-sells and related products
742
+ Fixed Absent validation for "Only X left Threshold" field
743
+ Fixed Shipping method calculation based on default shipping address instead of 'Same as billing' setting in back-end
744
+ Fixed There is no validation of the field "Handling Fee" that allows number less than zero in UPS shipping method
745
+ Fixed Product name with "<>" processed incorrect during creation order in back-end
746
+ Fixed Billing Address Line is always blank if "REQUIREBILLING = 1" for PayPal Express
747
+ Fixed SQL query for getting record count of archived orders takes too long time
748
+ Fixed Configuration->Inventory->Qty Increment isn't validated properly
749
+ Fixed Absent message about not enough quantity for bundle and configurable products
750
+ Fixed Wrong behaviour of split buttons in IE8
751
+ Fixed Warning message appears after unselecting user in the Role Users grid
752
+ Fixed Incorrect total weight calculation in external shipping methods for products with decimal Qty Increments
753
+ Fixed Tax calculation is incorrect if configurable product mixed up with other composite products in the shopping cart for Store Tax != Customer Tax
754
+ Fixed Products qty displays wrong in layered navigation after changing currency
755
+ Fixed Billing address fields are editable if "Same as shipping" selected on the PayPal Express order review page
756
+ Fixed Incorrect location of "Clear All" link
757
+ Fixed Incorrect price for bundle fixed product with custom option % and catalog price rule applied
758
+ Fixed Import/Export: Append Complex Data works incorrect for customer's address and product's customs data
759
+ Fixed Discount changes subtotal when FPT is active
760
+ Fixed There is no ability to specify backup's name
761
+ Fixed Multi selections fields for website scope settings are greyed out
762
+ Fixed "Credit Memos" is written incorrectly in Role Permission tree and on the Sales -> Archive -> Credit Memos page
763
+ Fixed Persistent Shopping Cart: After deleting customers via Back-end, on front-end customer should be logout completely
764
+ Fixed Incorrect logic during dividing products into multiple boxes for shipping
765
+ Fixed Polls are not working properly in case with different domains for http and https
766
+ Fixed "Block Reference" drop-down contains wrong list of options for front-end Apps types with Products
767
+ Fixed "Wrong store specified" appears on order creation page
768
+ Fixed Customer can't continue Checkout process after selecting Billing Address
769
+ Fixed Refresh Statistics gone from Reports Role
770
+ Fixed USPS shipping label is printed with "SAMPLE - DO NOT MAIL" sign
771
+ Fixed Shipping methods are not refreshed after Update Order Data is pressed on PayPal Express Order Review page
772
+ Fixed Product still invisible in front-end after required reindex
773
+ Fixed JS error on configurable products
774
+ Fixed Configurable product missing name in error message when exceeding quantity during order
775
+ Fixed Added Display Product Count on the Layout Navigation
776
+ Fixed "FedEx Priority Overnight" shipping method isn't calculated correctly
777
+ Fixed Incorrect product price for Bundle products with fixed prices in the shopping cart
778
+ Fixed "Ship Bundle Items" for bundle product works incorrect
779
+ Fixed Impossible to expand settings accordions on the "Design Settings Editor" tab of Theme Customization page under IE7
780
+ Fixed Impossibility to configure Bundle product with Disabled status and create new order with it in the back-end
781
+ Fixed Customer email isn't saved in Account Information field
782
+ Fixed Unable to sort products by price
783
+ Fixed Errors during creating/extracting "tar" archive with symbolic links
784
+ Fixed Wrong message text in "Manage Coupon" tab on Shopping Cart Price Rule page
785
+ Fixed 404 page not found error occurs when "Default Store" value is changed for Main Website
786
+ Fixed Unable to import products if Catalog price rule enabled
787
+ Fixed Partial Reindex isn't done for product saved in back-end
788
+ Fixed Catalog Price Rule: "Save and Apply" action leads to apply ALL rules, but it have to apply only specified rule
789
+ Fixed Tax isn't recalculated on PayPal Express
790
+ Fixed Backup Name field should allow to enter only a limited number of characters
791
+ Fixed In the "Subtotal" row of "Coupons Usage Report" displayed amounts for all Shopping Cart Price Rule in the system
792
+ Fixed Shipping address isn't passed to Magento from PayPal
793
+ Fixed Store view isn't changed when customer subscribes for newsletters
794
+ Fixed Shopping Cart Price Rules are not marked after creating Coupons Usage Report
795
+ Fixed Change buttons structure in prototype/windows.js to match general adminhtml buttons structure
796
+ Fixed Wrong error message on Create New Order page in back-end
797
+ Fixed Impossible to configure order of displaying rating values in the front-end
798
+ Fixed Incoming Message in Admin Part has the superfluous symbol '\'
799
+ Fixed Numerous issues with promotions on complex products
800
+ Fixed Recipient Postal-State Mismatch error seen on Shipping Label with FedEx
801
+ Fixed Text messages "This is a required fields." are displayed in the hidden FTP section
802
+ Fixed Incorrect popup on Manage Coupon Codes tab in Shopping Cart Price Rule
803
+ Fixed Layered navigation work incorrect if attribute values defined on Store View level
804
+ Fixed Checking import file returns blank page
805
+ Fixed Change the VAT Number format before sending to VAT ID Validation service
806
+ Fixed Simple products with configured customs options displayed in wishlist incorrectly
807
+ Fixed Incorrect text message for product for which there is no enough quantity in stock
808
+ Fixed Setting float Qty Increments is possible, but doesn't work
809
+ Fixed SQL error during checkout when customers register at checkout and orders a nominal item
810
+ Fixed Iframe for gateway isn't reloaded on the Payment information tab
811
+ Fixed Incorrect behavior after placing order from back-end in FF9
812
+ Fixed Catalog price rule skips conditions specified and applies to all products in the catalog
813
+ Fixed Price rule is applying to individual items in bundle when price is set to Dynamic
814
+ Fixed Impossible to save payment method configurations on the Default Config scope
815
+ Fixed "There has been an error processing your request" message is display if not CSV file was selected to import
816
+ Fixed Wrong reindex product attributes after bundle product save
817
+ Fixed Add Products button absent during creating order from back-end
818
+ Fixed "All methods" should be selected by default in configuration section "Allowed Methods" for UPS
819
+ Fixed Redirect to base URL issue
820
+ Fixed Added Backup sorting by name possibility
821
+ Fixed Fix grammar mistakes
822
+ Fixed Notifications are not shown if URL Rewrite used
823
+ Fixed "Stop Further Rules Processing" option doesn't work
824
+ Fixed Admin can not unassign product from the tag if already approved tag was added to the product by customer
825
+ Fixed Inaccuracy calculation could be 10% for FedEx International Ground shipping
826
+ Fixed Incorrect price calculation of configurable product with custom options (resolved conflicts)
827
+ Fixed Wrong currency displayed in Recently Viewed Product App
828
+ Fixed Tabs are grayed on admin dashboard
829
+ Fixed JS validation for product weight attribute doesn't work
830
+ Fixed Group Price attribute is present as text field using the mass update action
831
+ Fixed Shopping Cart Price Rule isn't applied to Not Logged In Customers
832
+ Fixed "Sign up for our newsletter" text appearing twice
833
+ Fixed Newsletter problem report grid on back-end throws Exception
834
+ Fixed Special price doesn't work for Bundles with Dynamic price
835
+ Fixed My Orders block disappears in My Account pages when Reorder functionality is disabled
836
+ Fixed Search doesn't work in Backups grid
837
+ Fixed Reindex "Catalog URL Rewrites" works extremely slowly
838
+ Fixed Checkbox state is preserved for "Put store on the maintenance mode while rollback processing"
839
+ Fixed UPS Configuration All Methods Should Be Selected by Default
840
+ Fixed Rollback fails if database backup was performed after product import
841
+ Fixed Incorrect behavior with 10-digit Zip code, after creating new Tax Rate
842
+ Fixed Configurable attributes that used for create configurable product should not be applied to that product
843
+ Fixed Default group has to be used if customer selects address without VAT number
844
+ Fixed No ability to create Shopping Cart Price Rule
845
+ Fixed Layout issue appears in IE9 on the export grids
846
+ Fixed Issue when trying to view the order using a specific admin user
847
+ Fixed System messages are not displayed at CMS pages and appears only when another message will be invoked
848
+ Fixed On the front-end Search doesn't work properly if search value is 0 (null)
849
+ Fixed The size of the columns in Backup grid is changed if no records were found
850
+ Fixed Maintenance flag isn't deleted if rollback fails with not enough permissions error
851
+ Fixed Customer's group isn't changed if his billing address modified within back-end
852
+ Added Add a message and the link in the mini shopping cart, when the cart is empty
853
+ Fixed On Edit Shipping Address page button "Validate VAT Number" should be hidden
854
+ Fixed Fatal error when try to ship order with Flat Rate shipping method
855
+ - fixed potentially problematic chaining involved getShippingCarrier method
856
+ Fixed No ability to open PDF file with Label
857
+ Fixed Incorrect final price for configurable products if several custom options used
858
+ Fixed "Length", "Width" and "Height" fields on "Create Packages" pop up are active, when "Documents" type is selected in IE7 and IE9
859
+ Fixed HTTP 500 error on front-end for bundle fixed with percent options enabled for sub-products
860
+ Fixed Shipment created on Magento side doesn't send to Google side for Merchant Calculated shipping
861
+ - added check for process only Google Checkout internal methods
862
+ Fixed PDF files for invoices and credit memos are not displaying Including Tax Price
863
+ Fixed Default value that was specified in system settings doesn't presented in Code Format drop-down on Manage Coupon Codes tab
864
+ Fixed Qty wipes out to 0 when no qty column is included on import
865
+ Fixed Broken controls makeup is observed after resizing window when customer's page is opened on the back-end
866
+ Fixed Values don't fit to "Date Fields Order" drop-downs in "Date & Time Custom Options" on the Catalog page
867
+ Fixed Processing error appears for products with "Qty Uses Decimals" = No and enabled DHL International
868
+ Fixed Apply Tax to FPT setting doesn't seem to work for products with Fixed Product Taxes
869
+ Fixed Apply Coupon Code textbox doesn't fit in the Apply Coupon Code channel on the back-end after reducing the browser window
870
+ Fixed Tax and Shipping amounts aren't showing on the merchant reports for Websites Payments Pro PayFlow Edition
871
+ Fixed Incorrect error popup on Manage Coupon Codes tab in Shopping Cart Price Rule
872
+ Fixed No ability to create Shipping Label with New DHL shipping methods
873
+ Fixed Indexing update on save takes too long for large catalog_product_entity_int tables
874
+ Fixed VAT ID group validation takes Default configuration on order creation from back-end
875
+ Fixed Pagination isn't shown on My Product Reviews page when items count exceeds the "Show per page" setting
876
+ Fixed Inline translation missing for customer account information labels
877
+ Fixed Corrupted text if drag attribute on Manage Attribute Sets page (IE8)
878
+ Fixed Wrong calculation price of Bundle product with Fixed price, when special price is configured
879
+ Fixed Error Message isn't displayed during unsuccessful Shipping Label creation
880
+ Fixed Unverified redirect is possible in Checkout controller
881
+ Fixed Customer group in not validated again on checkout if Tax Calculation Based on = Shipping Address
882
+ Fixed "Clear All" link doesn't work
883
+ Fixed Wrong message appears when products quantity is updated in the Shopping Cart with enabled Qty Increments setting
884
+ Fixed Created On field on Manage Coupon Codes grid shows incorrect date/time
885
+ Fixed Incorrect price calculation of configurable product with custom options
886
+ Fixed Manage Products > Custom options: Should be possible to enter negative price for custom option of 'Date' type
887
+ Fixed HTTP 500 Internal Server Error on Admin Forgot Password page
888
+ Fixed CSV/Excel XML export doesn't work on Sales->Invoices if filter by Selected=Yes is used
889
+ Fixed "Same As Billing Address" check-box doesn't work
890
+ Fixed Impossible to enter zero in the base price field for customer groups
891
+ Fixed Group Price attribute position on the Prices tab is incorrect
892
+ Fixed Add new column to the grid with number of used coupons
893
+ Fixed Custom options are not stored when downloadable product is duplicated
894
+ Fixed Broken logic for "Zero Subtotal Checkout" order statuses
895
+ Fixed Coupon codes generation fails when trying to generate large amount of codes
896
+ Fixed PayFlow Link: Using "Pay with PayPal" and selected shipping method that is greater than 0 doesn't process order
897
+ Fixed User have to stay on Add New Rule page if error appears on save shopping cart price rule
898
+ Fixed "Automatically Invoice All Items" should be inactive, when were selected "New Order Status: Pending" in "Zero Subtotal Checkout" settings
899
+ Fixed When enormous request in search fields on the front end 414 error appears
900
+ Fixed JS error on edit Shopping Cart Price Rule Page
901
+ Fixed Clear Shopping Cart button add selected item to Items Ordered if check box "Add to Order" is selected
902
+ Fixed "Clear Shopping Cart" button must be located to the left to "Update Shopping Cart" button
903
+ Fixed Export of Group Price data doesn't work
904
+ Fixed Incorrect translation messages definitions
905
+ Fixed Error message isn't displayed if currency exchange rate not found (in case with DHL Int)
906
+ Fixed User role with partial access can't edit attributes of configurable products
907
+ Fixed Letter "n" missed in the word "handling"
908
+ Fixed Buttons don't react for pressing on the "Widget Options" section in Insert Widget window
909
+ Fixed Regular price displays incorrect
910
+ Fixed {{base_url}} in (un)secure_url doesn't work since 1.6.1
911
+ Fixed Product selection field gets cleared out with recently added products from latest page
912
+ Fixed "Change" button while checkout doesn't work
913
+ Fixed MySQL BIGINT field type is wrongly casted to integer
914
+ Fixed Magento Connect Manager proceed with installation of extension if error appears on database backup
915
+ Fixed "Set product as New from/to Date" works excluding selected dates
916
+ Fixed Function fireEvent from lib/varien/js.js does not work in IE9
917
+ Fixed Searching with first and last name has no results
918
+ Fixed CMS Pages: Error in IE7 when select CMS page
919
+ Fixed White screen appears instead of 404 Error Page when going to review a product which doesn't exist
920
+ Fixed "Maximum Package Weight" option works incorrect in case with decimal Qty in shopping Cart
921
+ Fixed Unable to create tables for new EAV entity via SQL upgrade script
922
+ Fixed Customer group isn't revalidated on checkout if Enable Automatic Assignment to Customer Group = Yes
923
+ Fixed Mistake in PayPal Payments Advanced fieldset title
924
+ Fixed Zero Subtotal Checkout payment method is used, when it is disabled in settings
925
+ Fixed Some info lost from address when customer sets this address as default for shipping
926
+ Fixed Incorrect calculation logic during distribution products between several pieces (in case with DHL)
927
+ Fixed No ability to get shipping rates from US to another country (in case with DHL)
928
+ Fixed Incorrect calculation of pieces weight (in case with Bundle Product)
929
+ Fixed Product Flat Data index causes replication lag on MySQL master/slave model
930
+ Fixed Exception is shown, when admin user provides filtration of Newsletter problem reports by Subscriber
931
+ Fixed Typo in JavaScript error message
932
+ Fixed Unable to do mass action update for products
933
+ Fixed Error Message isn't displayed if currency exchange rate not found (in case with DHL)
934
+ Fixed Weight field is absent during Quick simple product creation
935
+ Fixed correct helper resolving
936
+ Fixed Shipping methods are shown twice in DHLs shipping quote
937
+ Fixed Unable to translate shipping and billing forms on the order creation page
938
+ Fixed Drop-down attribute with layered navigation filter doesn't work with value is set to 0
939
+ Fixed Free Shipping options doesn't work (in case with DHL)
940
+ Fixed Handling Fee doesn't applied Per Package
941
+ Fixed Free Shipping options works incorrect
942
+ Fixed WYSIWYG Editor: It's impossible insert Widget to CMS page content
943
+ Fixed Customer's group is not changed if his billing address modified within backend
944
+ Fixed Wrong behaviour and exception while using invalid image
945
+ Fixed Uninformative error message during saving two nodes with the same parameter URL Key
946
+ Fixed Unable to change order addresses in the admin panel
947
+ Fixed PayPal Express always uses default billing address from customer account
948
+ Fixed Unable to place order if customer selects Register on checkout
949
+ Fixed Performance Issue: Most Viewed product reports on large amount of items
950
+ Fixed In "Customer Addresses" block before and after of State name is located symbols ","
951
+ Fixed Lightbox 2.5 with IE7 returns JS error on the page
952
+ Fixed Unable to change customer status (confirmed/not confirmed) when customer logged in
953
+ Fixed Incorrect notification for empty field during creation catalog price rules
954
+ Fixed Unable to save product with non-checked multiple select attribute
955
+ Fixed Package Size setting for DHL
956
+ Fixed No Input Validation for Catalog Fields
957
+ Fixed Row Total Calculation in Refund
958
+ Fixed "Maximum number of price intervals" should be written with capital letters
959
+ Fixed Divide Order Weight options for DHL
960
+ Fixed Impossible to create new customer in the backend
961
+ Fixed Catalog data-upgrade-1.6.0.0.4-1.6.0.0.5.php is exteremly slow
962
+ Fixed Free Shipping options doesn't work (in case with DHL International)
963
+ Fixed Mage_Catalog_Helper_Product::getProduct() doesn't load product by its SKU
964
+ Fixed Preview Template doesn't work correctly
965
+ Fixed Some options of Bundle Product disappeared from the Invoice PDF
966
+ Fixed "Allow Countries" affects on "Country of Manufacture" attribute
967
+ Fixed Some phrases are not translated
968
+ Fixed Incorrect Ordered Qty in Order (in case with decimal qty)
969
+ Fixed Trademark character isn't being displayed properly in the PDF invoice
970
+ Fixed Can't search transactions by order_id in manager.paypal.com
971
+ Fixed Inline Translation: Grid headers are displayed incorrect on the Tag Edit page
972
+ Fixed "Create Extension Package" page becomes broken after compilation
973
+ Fixed Price including tax isn't displayed for some kinds of bundle products
974
+ Fixed Layered navigation for prices displays incorrect price ranges in manual mode
975
+ Fixed Pager works wrong with float page number
976
+ Fixed Incorrect foreign key for EAV entity tables
977
+ Fixed Misprint in downloader/lib/Mage/Connect/Command/Install.php
978
+ Fixed URL Rewrites must be case-sensitive
979
+ Fixed Unable to install package via uploader if author name contains dash
980
+ Fixed Fixed invoice subtotals for cases with partial invoice and discount
981
+ Fixed Catalog URL Rewrites works incorrectly on creating categories
982
+ Fixed New Oder Status setting, specified for payment method works incorrectly when only virtual products are present in Order
983
+ Fixed Rounding issue in catalog and product view if price includes tax
984
+ Fixed Wrong status of catalog event is displayed by editing catalog event
985
+ Fixed Role Resources are not saved
986
+ Fixed "Qty for Item's Status to Become Out of Stock" option works incorrect
987
+ Fixed XML parser works incorrect
988
+ Fixed Mage_Reports_Model_Mysql4_Product_Index_Abstract must be declared abstract
989
+ Fixed "Date & Time" and "Time" custom options becomes required when editing product
990
+ Fixed Unable to cancel an order for an expired Authorize.net auth
991
+ Fixed Custom options are not stored when downloadable product is duplicated
992
+ Fixed "Cannot initialize the indexer process" error during Mass "Reindex Data" Action
993
+ Fixed Search by new attribute fails, attribute is not shown in layered navigation
994
+ Fixed Exception when "Price Navigation Step Calculation" set to "Manual" mode and FPT enabled
995
+ Fixed WPPHS: Cancel URL doesn't work as should be
996
+ Fixed Error about insufficient permissions is not appears on database backup creation
997
+ Fixed After rollback admin doesn't redirected to the Log in to Admin Panel page
998
+ Fixed Database Backup must not include indexer table data
999
+ Fixed Scheduled Backup creation/failure isn't logged
1000
+ Fixed Deleting backup while it is used by another process
1001
+ Fixed Opening *.tar files causes an error "There are no trailing zero-filled records"
1002
+ Fixed Unable to search by "Time" and "No" in Backups table
1003
+ Fixed Backups are deleted without confirmation
1004
+ Fixed Reports must be excluded from database snapshot backup
1005
+ Fixed There are no products in filtering results, if step calculation in automatic mode
1006
+ Fixed No validation for "Default Price Navigation Step"
1007
+ Fixed "Back" button doesn't work on the Create New Order page
1008
+ Fixed Incorrect logic of Token expiration in Two Step Password Reset flow
1009
+ Fixed Tag <br/> is present in tool-tip for field "Number of results (For the last time placed)" on the Edit Search page
1010
+ Fixed Unnecessary hard code in Magento Extension
1011
+ Fixed Wrong logic in Mage_Core_Model_Resource_Db_Collection_Abstract::join()
1012
+ Fixed Description and Short Description are displayed incorrectly for products added with WYSIWYG
1013
+ Fixed Adding product to the cart from the product review page leads to 404 page
1014
+ Fixed Special symbols in Sort Order field
1015
+ Fixed Text is wrong displayed with enabled Inline translation for Admin on back-end
1016
+ Fixed Inline Translation: Unable to translate some customer information
1017
+ Fixed Useless colon on front-end login page
1018
+ Fixed Unable to continue checkout for product with zero price and non-zero shipping price
1019
+ Fixed Import news_from_date field is configured poorly. It is not accepting the data from file
1020
+ Fixed When updating product data through import, attributes that have a value cannot be assigned a new value that is empty
1021
+ Fixed Unable to replace non-complex data for products with empty values during import
1022
+ Fixed "Wrong order ID" exception in PayPal Express module under heavy load
1023
+ Fixed Tax is applying on the order when creating it in the admin panel for a Customer Group with no taxes
1024
+ Fixed Issue with retrieving order statuses for array of states
1025
+ Fixed Wrong calculation product price with custom option type = Field and Fixed price
1026
+ Fixed Back ordered downloadable product is not available even when it is set to be be accessible when order status is Pending
1027
+ Fixed Missing column "position" at table catalog_category_anc_products_index_tmp
1028
+ Fixed Incorrect behavior of "Save in address book" option during admin Order creation for a new customer
1029
+ - refactored Mage_Adminhtml_Model_Sales_Order_Create::_prepareCustomer()
1030
+ Fixed Terms and Conditions is named differently on different pages
1031
+ Fixed "Apply" and "Discount Amount" fields appear twice in the Catalog Price Rule
1032
+ Fixed Poll shows incorrect percentage
1033
+ Fixed Added validation ability for admin configuration forms
1034
+ Fixed UPS XML misprint
1035
+ Fixed Misprint in uploading files form
1036
+ Fixed Unnecessary check boxes for gift options
1037
+ Fixed Wrong resource section declaration in Mage_Tag module
1038
+ Fixed "Customers Submitted this Tag" section doesn't update when customer has deleted tag from his account
1039
+ Fixed Correct product in category position
1040
+ Fixed Unable to create folder in Media Storage
1041
+ Fixed Translation with single quotes breaks JavaScript
1042
+ Fixed Out of memory error with hundreds of thousands of coupons attached to a single sales rule
1043
+ Fixed Unable to translate buttons and tabs on the "Manage Category" page
1044
+ Fixed Product Categories Tree doesn't expand in Manage Products page
1045
+ Fixed Incorrect products qty returns to stock after refund for configurable product
1046
+ Fixed Swf Uploader problems with cross domain Flash Player Policy
1047
+ Fixed Unable to translate "Layout Updates" block on create/edit widget page
1048
+ Fixed IE7: "Remember Me" checkbox visible on billing information step
1049
+ Fixed CMS WYSIWYG Editor - widget is inserted as new while editing in IE8
1050
+ Fixed Currency code doesn't correspond to the amount in reports
1051
+ Fixed Mage_Adminhtml_Block_Sales_Order_View_Tab_History::getFullHistory() doesn't use unique keys for each message
1052
+ Fixed Scope labels are shown without translate wrapper
1053
+ Fixed Wrong parameters handling in Core Helper formatDate()
1054
+ Fixed Apostrophe in store name breaks Google Analytics tracking
1055
+ Fixed Customer attribute prefix is not shown on frontend
1056
+ Fixed Incorrect rounding for product with custom options (percent price)
1057
+ Fixed Invoicing only part of products results in wrong totals calculation
1058
+ Fixed Incorrect Row Total Calculation in Refund
1059
+ - fixed rounding issues for partial Invoice and Refund
1060
+ - refactored delta rounding
1061
+ Fixed Filter by "Allow Countries" not working for Customer Address Form in the Backend
1062
+ - checking added for set country to be in available list
1063
+ Fixed There are sql-installs with empty string used as defaults for table columns, while column is not null able
1064
+ Fixed Unable to translate "Note" in "Product Stock Options"
1065
+ Fixed Various warning are displayed after creating shipment for 0 items
1066
+ Fixed Invalid content in Content-header in the top of page during scrolling during order creation
1067
+ Fixed "Online invoice" button present in backend when using Zero Subtotal Checkout
1068
+ Fixed String cast type in in_array function
1069
+ Fixed Newsletter template content should not disappear when "Show" / "Hide Editor" button was clicked
1070
+ Fixed Import feature doesn't validate whether super_products_sku is existing or not
1071
+ Fixed Cannot place order with downloadable product and discount code using Paypal Express payment method
1072
+ Fixed Product still out of stock after Stock Status reindex
1073
+ Fixed Save catalog price rule gives trace if full reindex has already started
1074
+ Fixed Reindex requires notification is not shown for Stock Status when stock is updated for several products using Mass Action
1075
+ Fixed Incorrect FedEx's shipping rates (in case with non-US country origin)
1076
+ Fixed After partial reindex MSRP value is not applied (not viewed) in catalog during mass update action
1077
+ Fixed Wrong stock reindex on catalog if partial reindex done after full reindex started
1078
+ Fixed In error message string "already exists." written twice, when trying to save Product Tax Class with the same name
1079
+ Fixed Slow checkout with non-flushed cache
1080
+ Fixed Bundle product total is incorrect in Customization block
1081
+ Fixed Special price isn't considered for bundle dynamic products in "Your Customization" block
1082
+ Fixed Situation when any amount of duplicate reindex process can be running at one time
1083
+ Fixed Error with Advanced Search (in case with Date Attribute)
1084
+ Fixed Product Flat Data index isn't marked as "Reindex Required" after importing products when Flat Catalog is enabled
1085
+ Fixed User can't change root category for the store
1086
+ Fixed JS error causes the overwrite of Title field in PayPal Advanced configuration
1087
+ Fixed Mass action doesn't partially reindex catalog for product name/description
1088
+ Fixed Remove hint about $1 auth amount from informational message text (PayflowLink configuration)
1089
+ Fixed Mass action doesn't partially reindex catalog for product prices
1090
+ Fixed PayPal Payments Advanced works with $0 Auth instead of Full Auth
1091
+ Fixed Impossible to place Order using "Pay with PayPal" button from PayPal Payments Advanced iframe
1092
+ Fixed Mass action doesn't partially reindex catalog search for product if searchable attribute was updated
1093
+ Fixed "Please wait" AJAX screen doesn't appear in the middle of the page
1094
+ Fixed Checkout link on frontend is always referenced as http
1095
+ Fixed GET request is incorrectly formed during category creation
1096
+ - adjusted assertion to determine last viewed store
1097
+ Fixed Display of Tier Pricing with Configurable Products
1098
+ - added functionality to dynamically update tier prices accordingly to chosen product configuration
1099
+ Fixed Google Analytics e-commerce tracking not working
1100
+ Fixed URL key isn't used while product save
1101
+ Fixed Added validation class to 'Qty increments'
1102
+ Fixed Entered from admin customer date 1970 (or less) is saved as 2070 (or less)
1103
+ Fixed cUrl resource must be closed after checking it for errors, not before
1104
+ Fixed Exception while products mass update attributes in backend
1105
+ Fixed No ability to reindex Catalog URL Rewrites, error is shown
1106
+ Fixed Package with Core dependency
1107
+ Fixed Stock Availability isn't updated if 1: Run Price Reindex 2: Update Stock Availability on product with mass action/single product
1108
+ Fixed Blank page instead shopping cart page when compilation and PSC are enabled
1109
+ Fixed Unable to save redirect URL with special characters in search terms
1110
+ Fixed Attribute Set field should have client-side validation and appropriate information message
1111
+ Fixed "Localhost" isn't a valid domain name for installation
1112
+ Fixed Iframe for PayPal Payments Advanced is not loaded
1113
+ Fixed Retain the selected tab on editing CMS page
1114
+ Fixed Payflow Link Express Checkout (pay with PayPal button) payment
1115
+ Fixed Wrong number of reindex options is displayed
1116
+ Fixed Wrong phpDocs for Varien_Db_Select
1117
+ Fixed JavaScript calendar date range
1118
+ - fixed JS calendar behavior to use 4-digits year format
1119
+ Fixed Performance issue connected with sales rules on adding product to cart
1120
+ Fixed DHL same error message appears several times
1121
+ Fixed Item Status says "Mixed" when an order has been completed, should say "Shipped"
1122
+ Fixed Product option title is absent in backend order page
1123
+ Fixed Incorrect items number during multi shipping checkout
1124
+ Fixed User name displays differently in the unsuccessful message and in the text field label (log in form)
1125
+ Fixed If one or more indexers have Update Required = Yes and all Status = READY for all indexers than there is no notification for user to do reindex action
1126
+ Fixed No space between Address line 1 and line 2 in Shipping Label (in case with FedEx)
1127
+ Fixed JS works depends on the position attributes of the product
1128
+ Fixed Char set encoding is out-of-date in Settlement reports
1129
+ Fixed Settlement reports can't be downloaded if in merchant's account 'Settlement file' is set to 6.0 version
1130
+ Fixed Unable to login when secure and unsecure URLs are different
1131
+ Fixed Customer session lost when using different domain/subdomain names for secure and unsecure URLs
1132
+ Fixed "Most Viewed" reports ignore Store View switcher
1133
+ Fixed Long FPT name (and product name) doesn't fit into "My cart" block
1134
+ Fixed Paypal IPN post back failure
1135
+ Fixed Customer was unable to receive newsletters when it was created via backend
1136
+ Fixed Wrong Comments History in notification of order creation/cancellation
1137
+ Fixed Non escaped string causes javascript error
1138
+ Fixed Unable to view pictures during product editing
1139
+ Fixed Ampersand is saved incorrect in attribute label
1140
+ Fixed IE8: JS error appears after pressing 'Add new rule' in catalog price rules menu
1141
+ Fixed Exception after sorting newsletter queue
1142
+ Fixed Customer is not able to log in from URL without "www" in some cases
1143
+ Fixed SQL error on category view with enabled and configured FPT
1144
+ Fixed Automatic reindexing based on matched events doesn't change "Status" and "Last Run" columns at process list grid
1145
+ Fixed Performance issue with Magento Compiler + APC results in too many I/O calls
1146
+ Fixed Website Administrator is able to change default values
1147
+ Fixed Some of wishlist blocks and templates still treat the collection of wishlist items as collection of products
1148
+ Fixed Unnecessary comments in "Share Wishlist" email
1149
+
1150
+
1151
+
1152
+ ==== 1.7.0.0-beta1 ====
1153
+
1154
+ === Improvements ===
1155
+ Added ability to translate action array parameter nodes via layout.xml
1156
+ Added support for using custom currency symbols
1157
+ Added functionality to cleaning old cache files by cron task
1158
+ Refactored rules-based modules
1159
+ Improved customer address handling using PayPal Express checkout
1160
+ Refactored escaping functionality used with translations
1161
+ Added ability to customize logo in emails from the admin
1162
+ Implemented front-end cookies restriction functionality
1163
+ Added ability to turn off/on IP Tracking (e.g. 'Placed from IP') on the Sales pages in back-end (Order, Invoice, Shipment, Credit memo)
1164
+ Provided logic to disable ACL resources through configuration files
1165
+
1166
+
1167
+ === Changes ===
1168
+ Support for "memcached" PHP extension was added
1169
+ Library js/scriptaculous/dragdrop.js is upgraded to version 1.9.0
1170
+ Image file of "jpg" type are allowed for favicon
1171
+ Added ability to extend list of attributes to select for categories loaded via Mage_Catalog_Model_Resource_Category_Flat::_loadNodes()
1172
+ Added changes to lib/Varien/Http/Adapter/Curl.php to provide interface for setting different cURL options
1173
+ Displaying State or Province can be optional for any country
1174
+ Added ability to get Magento type from Mage.php
1175
+
1176
+
1177
+ === Fixes ===
1178
+ Fixed Impossibility of changing the Rating Value title for store view in existing Rating Value with filled the Rating Value title for store view
1179
+ Fixed Trademark symbol not showing up
1180
+ Fixed Add "Delivery Option" for FedEx Configurations
1181
+ Fixed Saving product takes long time
1182
+ Fixed Notice message disappear after clearing cache
1183
+ Fixed Products qty displays incorrect in price ranges after import (rounding problem)
1184
+ Fixed User role with partial access can't edit attributes of configurable products
1185
+ Fixed Images in CSS fail when merging CSS files
1186
+ Fixed Mass action update of any attributes resets multiselect attributes to NULL
1187
+ Fixed Move CSS from Prototype Windows plugin to the backend skin
1188
+ Fixed DB adapter should check transaction level in case of DDL query
1189
+ Fixed When Payment method additional info contains double quote it is displayed as '&quot;' in invoice PDF
1190
+ Fixed Incorrect Unit Price(Excl. Tax) in the Shopping Cart Grid after changing currency
1191
+ Fixed Incorrect total quantity of records and pagination doesn't work on Reports->Reviews->Products Reviews page
1192
+ Fixed Incorrect title of All Reviews for product page
1193
+ Fixed Invalid message in shopping cart when trying to add products amount more than allowed
1194
+ Fixed Layered Navigation: Icon "Previous" should be appear only on sub-intervals level
1195
+ Fixed Group Price attribute position on the Prices tab is incorrect
1196
+ Fixed Processing error occurred when big numeric value is entered to an browser URL
1197
+ Fixed Issue with credit memo for multiple bundled products (order status is Processing)
1198
+ Fixed Customer group has to be emulated even if customer is sticky assigned to the group
1199
+ Fixed "Customs Value" isn't represented in store base currency
1200
+ Fixed Layered Navigation: After clicking on interval $0.00, should be filtered and displayed products with price 0.00
1201
+ Fixed Absence of redirecting to the grid page after saving Role/User
1202
+ Fixed Incorrect logic of assignment of unique ID in Varien_Data_Collection
1203
+ Fixed Problems with sorting actions
1204
+ Fixed When product is unsaleable checkout is still possible depending on its position in cart
1205
+ Fixed Impossibility of creating new order with "Reorder" button when Out of stock or disabled products had been ordered
1206
+ Fixed "Online Minute Interval" customer configuration option should have global scope
1207
+ Fixed Unable to translate Active/Inactive in promotions grid
1208
+ Fixed Session is lost while redirecting from secure to unsecure URL
1209
+ Fixed Response headers contains 500 error during front-end pages browsing
1210
+ Fixed Add additional button to PayPal Redirect Page
1211
+ Fixed Category Permissions: if "Display Product Price" is set to "No" the page toolbar is absent
1212
+ Fixed Layered navigation options have wrong order in back-end
1213
+ Fixed The "Remember Me" check box with the "What's this?" link should be located below the "Forgot Your Password?" link
1214
+ Fixed Warning message is absent, when "Recovery Link Expiration Period" is specified within the correct range
1215
+ Fixed After changing Price Navigation Step calculation from Automatic in Continuos the category is loaded very slowly
1216
+ Fixed PayPal HSS (Website Payment Pro Hosted Solutions) France doesn't work
1217
+ Fixed Remove email from Billing address section of the PayPal Express Order Review page
1218
+ Fixed It is available enter negative digits in the "Layered Navigation Price Step" (on Category page)
1219
+ Fixed First/Last Name algorithm for PayPal Express checkout
1220
+ Fixed Asterisk isn't imported in Zip/Post Code field
1221
+ Fixed Some strings are not translated in widgets
1222
+ Fixed Session isn't stored between secure and usecure URLs when they are located in different paths of the same domain (no SID in request)
1223
+ Fixed "USPS First Class International Parcel" will not show up as an option for customers during checkout
1224
+ Fixed UPS, FedEx and DHL methods should work if zip code from / to isn't required
1225
+ Fixed Issue when trying to create an order from the back-end without selecting the state/province
1226
+ Fixed HTTP error when uploading images from a MacOS with shockwave flash 11.1.102.55
1227
+ Fixed UPS Configuration "All Methods" should be selected by default
1228
+ Fixed Cannot create a product review through back-end
1229
+ Fixed Typos in Role Permission tree
1230
+ Fixed WYSIWYG button layout issue on product page
1231
+ Fixed Require Customer's Billing Address is missing option "For Virtual Quotes Only"
1232
+ Fixed Errors appears on Design Configuration page if transactional email's logo image and/or favicon files were deleted
1233
+ Fixed State/Province value is reset after page reload on some forms
1234
+ Fixed Cannot access back-end after switching on and switching off "Use Custom Admin URL"
1235
+ Fixed "Unsubscribe Selected" and "Delete Selected Problems" buttons don't work
1236
+ Fixed After selecting shipping from dropdown system doesn't update order data automatically on PayPal Express Order Review page
1237
+ Fixed Buttons on the back-end order page don't have titles
1238
+ Fixed ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION error in Chrome browser
1239
+ Fixed Changes related with Apply and Discount Amount options for sub item, applied after clicking "Save Rule" button
1240
+ Fixed Invalid Timezone error for Asia/Calcutta when changing default country to India
1241
+ Fixed Sorting by position doesn't work for up-sells and related products
1242
+ Fixed Absent validation for "Only X left Threshold" field
1243
+ Fixed Shipping method calculation based on default shipping address instead of 'Same as billing' setting in back-end
1244
+ Fixed There is no validation of the field "Handling Fee" that allows number less than zero in UPS shipping method
1245
+ Fixed Product name with "<>" processed incorrect during creation order in back-end
1246
+ Fixed Billing Address Line is always blank if "REQUIREBILLING = 1" for PayPal Express
1247
+ Fixed SQL query for getting record count of archived orders takes too long time
1248
+ Fixed Configuration->Inventory->Qty Increment isn't validated properly
1249
+ Fixed Absent message about not enough quantity for bundle and configurable products
1250
+ Fixed Wrong behaviour of split buttons in IE8
1251
+ Fixed Warning message appears after unselecting user in the Role Users grid
1252
+ Fixed Incorrect total weight calculation in external shipping methods for products with decimal Qty Increments
1253
+ Fixed Tax calculation is incorrect if configurable product mixed up with other composite products in the shopping cart for Store Tax != Customer Tax
1254
+ Fixed No validation for "Default Price Navigation Step"
1255
+ Fixed Products qty displays wrong in layered navigation after changing currency
1256
+ Fixed Billing address fields are editable if "Same as shipping" selected on the PayPal Express order review page
1257
+ Fixed Incorrect location of "Clear All" link
1258
+ Fixed Incorrect price for bundle fixed product with custom option % and catalog price rule applied
1259
+ Fixed Import/Export: Append Complex Data works incorrect for customer's address and product's customs data
1260
+ Fixed Discount changes subtotal when FPT is active
1261
+ Fixed There is no ability to specify backup's name
1262
+ Fixed Multi selections fields for website scope settings are greyed out
1263
+ Fixed "Credit Memos" is written incorrectly in Role Permission tree and on the Sales -> Archive -> Credit Memos page
1264
+ Fixed Persistent Shopping Cart: After deleting customers via Back-end, on front-end customer should be logout completely
1265
+ Fixed Incorrect logic during dividing products into multiple boxes for shipping
1266
+ Fixed Polls are not working properly in case with different domains for http and https
1267
+ Fixed "Block Reference" drop-down contains wrong list of options for front-end Apps types with Products
1268
+ Fixed "Wrong store specified" appears on order creation page
1269
+ Fixed Customer can't continue Checkout process after selecting Billing Address
1270
+ Fixed Refresh Statistics gone from Reports Role
1271
+ Fixed USPS shipping label is printed with "SAMPLE - DO NOT MAIL" sign
1272
+ Fixed Shipping methods are not refreshed after Update Order Data is pressed on PayPal Express Order Review page
1273
+ Fixed Product still invisible in front-end after required reindex
1274
+ Fixed JS error on configurable products
1275
+ Fixed Configurable product missing name in error message when exceeding quantity during order
1276
+ Fixed Added Display Product Count on the Layout Navigation
1277
+ Fixed "FedEx Priority Overnight" shipping method isn't calculated correctly
1278
+ Fixed Incorrect product price for Bundle products with fixed prices in the shopping cart
1279
+ Fixed "Ship Bundle Items" for bundle product works incorrect
1280
+ Fixed Impossible to expand settings accordions on the "Design Settings Editor" tab of Theme Customization page under IE7
1281
+ Fixed Impossibility to configure Bundle product with Disabled status and create new order with it in the back-end
1282
+ Fixed Customer email isn't saved in Account Information field
1283
+ Fixed Unable to sort products by price
1284
+ Fixed Errors during creating/extracting "tar" archive with symbolic links
1285
+ Fixed Wrong message text in "Manage Coupon" tab on Shopping Cart Price Rule page
1286
+ Fixed 404 page not found error occurs when "Default Store" value is changed for Main Website
1287
+ Fixed Unable to import products if Catalog price rule enabled
1288
+ Fixed Partial Reindex isn't done for product saved in back-end
1289
+ Fixed Catalog Price Rule: "Save and Apply" action leads to apply ALL rules, but it have to apply only specified rule
1290
+ Fixed Tax isn't recalculated on PayPal Express
1291
+ Fixed CMS Pages: Error in IE7 when select CMS page
1292
+ Fixed Backup Name field should allow to enter only a limited number of characters
1293
+ Fixed In the "Subtotal" row of "Coupons Usage Report" displayed amounts for all Shopping Cart Price Rule in the system
1294
+ Fixed Shipping address isn't passed to Magento from PayPal
1295
+ Fixed Store view isn't changed when customer subscribes for newsletters
1296
+ Fixed Shopping Cart Price Rules are not marked after creating Coupons Usage Report
1297
+ Fixed Change buttons structure in prototype/windows.js to match general adminhtml buttons structure
1298
+ Fixed Wrong error message on Create New Order page in back-end
1299
+ Fixed Impossible to configure order of displaying rating values in the front-end
1300
+ Fixed Incoming Message in Admin Part has the superfluous symbol '\'
1301
+ Fixed Numerous issues with promotions on complex products
1302
+ Fixed Recipient Postal-State Mismatch error seen on Shipping Label with FedEx
1303
+ Fixed Text messages "This is a required fields." are displayed in the hidden FTP section
1304
+ Fixed Incorrect popup on Manage Coupon Codes tab in Shopping Cart Price Rule
1305
+ Fixed Layered navigation work incorrect if attribute values defined on Store View level
1306
+ Fixed Checking import file returns blank page
1307
+ Fixed Change the VAT Number format before sending to VAT ID Validation service
1308
+ Fixed Simple products with configured customs options displayed in wishlist incorrectly
1309
+ Fixed Incorrect text message for product for which there is no enough quantity in stock
1310
+ Fixed Setting float Qty Increments is possible, but doesn't work
1311
+ Fixed SQL error during checkout when customers register at checkout and orders a nominal item
1312
+ Fixed Iframe for gateway isn't reloaded on the Payment information tab
1313
+ Fixed Incorrect behavior after placing order from back-end in FF9
1314
+ Fixed Catalog price rule skips conditions specified and applies to all products in the catalog
1315
+ Fixed Price rule is applying to individual items in bundle when price is set to Dynamic
1316
+ Fixed Impossible to save payment method configurations on the Default Config scope
1317
+ Fixed "There has been an error processing your request" message is display if not CSV file was selected to import
1318
+ Fixed "Maximum Package Weight" option works incorrect in case with decimal Qty in shopping Cart
1319
+ Fixed Wrong reindex product attributes after bundle product save
1320
+ Fixed Add Products button absent during creating order from back-end
1321
+ Fixed "All methods" should be selected by default in configuration section "Allowed Methods" for UPS
1322
+ Fixed Redirect to base URL issue
1323
+ Fixed Added Backup sorting by name possibility
1324
+ Fixed Entered from admin customer date 1970 (or less) is saved as 2070 (or less)
1325
+ Fixed Fix grammar mistakes
1326
+ Fixed Notifications are not shown if URL Rewrite used
1327
+ Fixed "Stop Further Rules Processing" option doesn't work
1328
+ Fixed Admin can not unassign product from the tag if already approved tag was added to the product by customer
1329
+ Fixed Inaccuracy calculation could be 10% for FedEx International Ground shipping
1330
+ Fixed Incorrect price calculation of configurable product with custom options (resolved conflicts)
1331
+ Fixed Wrong currency displayed in Recently Viewed Product App
1332
+ Fixed Tabs are grayed on admin dashboard
1333
+ Fixed JS validation for product weight attribute doesn't work
1334
+ Fixed Group Price attribute is present as text field using the mass update action
1335
+ Fixed Shopping Cart Price Rule isn't applied to Not Logged In Customers
1336
+ Fixed "Sign up for our newsletter" text appearing twice
1337
+ Fixed Newsletter problem report grid on back-end throws Exception
1338
+ Fixed Special price doesn't work for Bundles with Dynamic price
1339
+ Fixed My Orders block disappears in My Account pages when Reorder functionality is disabled
1340
+ Fixed Search doesn't work in Backups grid
1341
+ Fixed Reindex "Catalog URL Rewrites" works extremely slowly
1342
+ Fixed Checkbox state is preserved for "Put store on the maintenance mode while rollback processing"
1343
+ Fixed UPS Configuration All Methods Should Be Selected by Default
1344
+ Fixed Rollback fails if database backup was performed after product import
1345
+ Fixed Incorrect behavior with 10-digit Zip code, after creating new Tax Rate
1346
+ Fixed Configurable attributes that used for create configurable product should not be applied to that product
1347
+ Fixed Default group has to be used if customer selects address without VAT number
1348
+ Fixed No ability to create Shopping Cart Price Rule
1349
+ Fixed Layout issue appears in IE9 on the export grids
1350
+ Fixed Issue when trying to view the order using a specific admin user
1351
+ Fixed System messages are not displayed at CMS pages and appears only when another message will be invoked
1352
+ Fixed On the front-end Search doesn't work properly if search value is 0 (null)
1353
+ Fixed The size of the columns in Backup grid is changed if no records were found
1354
+ Fixed Maintenance flag isn't deleted if rollback fails with not enough permissions error
1355
+ Fixed Customer's group isn't changed if his billing address modified within back-end
1356
+ Added Add a message and the link in the mini shopping cart, when the cart is empty
1357
+ Fixed On Edit Shipping Address page button "Validate VAT Number" should be hidden
1358
+ Fixed Fatal error when try to ship order with Flat Rate shipping method
1359
+ - fixed potentially problematic chaining involved getShippingCarrier method
1360
+ Fixed No ability to open PDF file with Label
1361
+ Fixed Incorrect final price for configurable products if several custom options used
1362
+ Fixed "Length", "Width" and "Height" fields on "Create Packages" pop up are active, when "Documents" type is selected in IE7 and IE9
1363
+ Fixed HTTP 500 error on front-end for bundle fixed with percent options enabled for sub-products
1364
+ Fixed Shipment created on Magento side doesn't send to Google side for Merchant Calculated shipping
1365
+ - added check for process only Google Checkout internal methods
1366
+ Fixed PDF files for invoices and credit memos are not displaying Including Tax Price
1367
+ Fixed Default value that was specified in system settings doesn't presented in Code Format drop-down on Manage Coupon Codes tab
1368
+ Fixed Unable to place order if customer selects Register on checkout
1369
+ Fixed Qty wipes out to 0 when no qty column is included on import
1370
+ Fixed Broken controls makeup is observed after resizing window when customer's page is opened on the back-end
1371
+ Fixed Values don't fit to "Date Fields Order" drop-downs in "Date & Time Custom Options" on the Catalog page
1372
+ Fixed Processing error appears for products with "Qty Uses Decimals" = No and enabled DHL International
1373
+ Fixed Apply Tax to FPT setting doesn't seem to work for products with Fixed Product Taxes
1374
+ Fixed Apply Coupon Code textbox doesn't fit in the Apply Coupon Code channel on the back-end after reducing the browser window
1375
+ Fixed Tax and Shipping amounts aren't showing on the merchant reports for Websites Payments Pro PayFlow Edition
1376
+ Fixed Incorrect error popup on Manage Coupon Codes tab in Shopping Cart Price Rule
1377
+ Fixed No ability to create Shipping Label with New DHL shipping methods
1378
+ Fixed Indexing update on save takes too long for large catalog_product_entity_int tables
1379
+ Fixed VAT ID group validation takes Default configuration on order creation from back-end
1380
+ Fixed Pagination isn't shown on My Product Reviews page when items count exceeds the "Show per page" setting
1381
+ Fixed Inline translation missing for customer account information labels
1382
+ Fixed Corrupted text if drag attribute on Manage Attribute Sets page (IE8)
1383
+ Fixed Wrong calculation price of Bundle product with Fixed price, when special price is configured
1384
+ Fixed Error Message isn't displayed during unsuccessful Shipping Label creation
1385
+ Fixed Unverified redirect is possible in Checkout controller
1386
+ Fixed Customer group in not validated again on checkout if Tax Calculation Based on = Shipping Address
1387
+ Fixed "Clear All" link doesn't work
1388
+ Fixed Wrong message appears when products quantity is updated in the Shopping Cart with enabled Qty Increments setting
1389
+ Fixed Created On field on Manage Coupon Codes grid shows incorrect date/time
1390
+ Fixed Incorrect price calculation of configurable product with custom options
1391
+ Fixed Manage Products > Custom options: Should be possible to enter negative price for custom option of 'Date' type
1392
+ Fixed HTTP 500 Internal Server Error on Admin Forgot Password page
1393
+ Fixed CSV/Excel XML export doesn't work on Sales->Invoices if filter by Selected=Yes is used
1394
+ Fixed "Same As Billing Address" check-box doesn't work
1395
+ Fixed Impossible to enter zero in the base price field for customer groups
1396
+ Fixed Group Price attribute position on the Prices tab is incorrect
1397
+ Fixed Add new column to the grid with number of used coupons
1398
+ Fixed Custom options are not stored when downloadable product is duplicated
1399
+ Fixed Broken logic for "Zero Subtotal Checkout" order statuses
1400
+ Fixed Coupon codes generation fails when trying to generate large amount of codes
1401
+ Fixed PayFlow Link: Using "Pay with PayPal" and selected shipping method that is greater than 0 doesn't process order
1402
+ Fixed "Clear Shopping Cart" button add selected item to Items Ordered if check box "Add to Order" is selected
1403
+ Fixed User have to stay on Add New Rule page if error appears on save shopping cart price rule
1404
+ Fixed "Automatically Invoice All Items" should be inactive, when were selected "New Order Status: Pending" in "Zero Subtotal Checkout" settings
1405
+ Fixed When enormous request in search fields on the front end 414 error appears
1406
+ Fixed JS error on edit Shopping Cart Price Rule Page
1407
+ Fixed "Clear Shopping Cart" button must be located to the left to "Update Shopping Cart" button
1408
+ Fixed Export of Group Price data doesn't work
1409
+
1410
+
1411
+
1412
  ==== 1.6.2.0 ====
1413
 
1414
  === Improvements ===
1441
 
1442
 
1443
 
1444
+ ==== 1.7.0.0-alpha1 ====
1445
+
1446
+ === Major Highlights ===
1447
+ New Layered Navigation price bucket algorithm
1448
+ Added captcha functionality
1449
+ Implemented different base prices for customer groups
1450
+ Added auto generation of coupon codes
1451
+ Backup and Rollback functionality
1452
+ VAT ID Validation added
1453
+ Implemented DHL for Europe
1454
+
1455
+ === Improvements ===
1456
+ XmlConnect package release v22.1
1457
+ Upgraded TinyMCE to v3.4.7
1458
+ Indexers refactoring
1459
+ Theme for iPhone was redesigned
1460
+
1461
+ === Changes ===
1462
+ Implemented localized PayPal settings for Japan
1463
+ Added PayPal Advanced payment method
1464
+
1465
+ === Fixes ===
1466
+ Fixed Incorrect translation messages definitions
1467
+ Fixed Error message isn't displayed if currency exchange rate not found (in case with DHL Int)
1468
+ Fixed Handling Fee doesn't applied Per Package
1469
+ Fixed User role with partial access can't edit attributes of configurable products
1470
+ Fixed Letter "n" missed in the word "handling"
1471
+ Fixed Buttons don't react for pressing on the "Widget Options" section in Insert Widget window
1472
+ Fixed Regular price displays incorrect
1473
+ Fixed {{base_url}} in (un)secure_url doesn't work since 1.6.1
1474
+ Fixed Product selection field gets cleared out with recently added products from latest page
1475
+ Fixed "Change" button while checkout doesn't work
1476
+ Fixed MySQL BIGINT field type is wrongly casted to integer
1477
+ Fixed Magento Connect Manager proceed with installation of extension if error appears on database backup
1478
+ Fixed "Set product as New from/to Date" works excluding selected dates
1479
+ Fixed Function fireEvent from lib/varien/js.js does not work in IE9
1480
+ Fixed Searching with first and last name has no results
1481
+ Fixed CMS Pages: Error in IE7 when select CMS page
1482
+ Fixed White screen appears instead of 404 Error Page when going to review a product which doesn't exist
1483
+ Fixed "Maximum Package Weight" option works incorrect in case with decimal Qty in shopping Cart
1484
+ Fixed Unable to create tables for new EAV entity via SQL upgrade script
1485
+ Fixed Customer group isn't revalidated on checkout if Enable Automatic Assignment to Customer Group = Yes
1486
+ Fixed Mistake in PayPal Payments Advanced fieldset title
1487
+ Fixed Zero Subtotal Checkout payment method is used, when it is disabled in settings
1488
+ Fixed Some info lost from address when customer sets this address as default for shipping
1489
+ Fixed Incorrect calculation logic during distribution products between several pieces (in case with DHL)
1490
+ Fixed No ability to get shipping rates from US to another country (in case with DHL)
1491
+ Fixed Incorrect calculation of pieces weight (in case with Bundle Product)
1492
+ Fixed Product Flat Data index causes replication lag on MySQL master/slave model
1493
+ Fixed Exception is shown, when admin user provides filtration of Newsletter problem reports by Subscriber
1494
+ Fixed Typo in JavaScript error message
1495
+ Fixed Unable to do mass action update for products
1496
+ Fixed Error Message isn't displayed if currency exchange rate not found (in case with DHL)
1497
+ Fixed Weight field is absent during Quick simple product creation
1498
+ Fixed Fixed correct helper resolving
1499
+ Fixed Shipping methods are shown twice in DHLs shipping quote
1500
+ Fixed Unable to translate shipping and billing forms on the order creation page
1501
+ Fixed Drop-down attribute with layered navigation filter doesn't work with value is set to 0
1502
+ Fixed Free Shipping options doesn't work (in case with DHL)
1503
+ Fixed Handling Fee doesn't applied Per Package
1504
+ Fixed Free Shipping options works incorrect
1505
+ Fixed WYSIWYG Editor: It's impossible insert Widget to CMS page content
1506
+ Fixed Customer's group is not changed if his billing address modified within backend
1507
+ Fixed Wrong behaviour and exception while using invalid image
1508
+ Fixed Layered navigation for prices displays incorrect price ranges in manual mode
1509
+ Fixed Uninformative error message during saving two nodes with the same parameter URL Key
1510
+ Fixed Unable to change order addresses in the admin panel
1511
+ Fixed PayPal Express always uses default billing address from customer account
1512
+ Fixed Unable to place order if customer selects Register on checkout
1513
+ Fixed Performance Issue: Most Viewed product reports on large amount of items
1514
+ Fixed In "Customer Addresses" block before and after of State name is located symbols ","
1515
+ Fixed Lightbox 2.5 with IE7 returns JS error on the page
1516
+ Fixed Unable to change customer status (confirmed/not confirmed) when customer logged in
1517
+ Fixed Incorrect notification for empty field during creation catalog price rules
1518
+ Fixed Unable to save product with non-checked multiple select attribute
1519
+ Fixed "Ship Bundle Items" for bundle product works incorrect
1520
+ Fixed Package Size setting for DHL
1521
+ Fixed No Input Validation for Catalog Fields
1522
+ Fixed Row Total Calculation in Refund
1523
+ Fixed "Maximum number of price intervals" should be written with capital letters
1524
+ Fixed Divide Order Weight options for DHL
1525
+ Fixed Incorrect Row Total Calculation in Refund
1526
+ Fixed Impossible to create new customer in the backend
1527
+ Fixed Catalog data-upgrade-1.6.0.0.4-1.6.0.0.5.php is exteremly slow
1528
+ Fixed Free Shipping options doesn't work (in case with DHL International)
1529
+ Fixed Mage_Catalog_Helper_Product::getProduct() doesn't load product by its SKU
1530
+ Fixed Preview Template doesn't work correctly
1531
+ Fixed Some options of Bundle Product disappeared from the Invoice PDF
1532
+ Fixed "Allow Countries" affects on "Country of Manufacture" attribute
1533
+ Fixed Some phrases are not translated
1534
+ Fixed Incorrect Ordered Qty in Order (in case with decimal qty)
1535
+ Fixed Trademark character isn't being displayed properly in the PDF invoice
1536
+ Fixed Can't search transactions by order_id in manager.paypal.com
1537
+ Fixed Inline Translation: Grid headers are displayed incorrect on the Tag Edit page
1538
+ Fixed "Create Extension Package" page becomes broken after compilation
1539
+ Fixed Price including tax isn't displayed for some kinds of bundle products
1540
+ Fixed Layered navigation for prices displays incorrect price ranges in manual mode
1541
+ Fixed Pager works wrong with float page number
1542
+ Fixed Incorrect foreign key for EAV entity tables
1543
+ Fixed Misprint in downloader/lib/Mage/Connect/Command/Install.php
1544
+ Fixed URL Rewrites must be case-sensitive
1545
+ Fixed Unable to install package via uploader if author name contains dash
1546
+ Fixed Fixed invoice subtotals for cases with partial invoice and discount
1547
+ Fixed Catalog URL Rewrites works incorrectly on creating categories
1548
+ Fixed New Oder Status setting, specified for payment method works incorrectly when only virtual products are present in Order
1549
+ Fixed Rounding issue in catalog and product view if price includes tax
1550
+ Fixed Wrong status of catalog event is displayed by editing catalog event
1551
+ Fixed Role Resources are not saved
1552
+ Fixed "Qty for Item's Status to Become Out of Stock" option works incorrect
1553
+ Fixed XML parser works incorrect
1554
+ Fixed Mage_Reports_Model_Mysql4_Product_Index_Abstract must be declared abstract
1555
+ Fixed "Date & Time" and "Time" custom options becomes required when editing product
1556
+ Fixed Unable to cancel an order for an expired Authorize.net auth
1557
+ Fixed Custom options are not stored when downloadable product is duplicated
1558
+ Fixed "Cannot initialize the indexer process" error during Mass "Reindex Data" Action
1559
+ Fixed Search by new attribute fails, attribute is not shown in layered navigation
1560
+ Fixed Exception when "Price Navigation Step Calculation" set to "Manual" mode and FPT enabled
1561
+ Fixed WPPHS: Cancel URL doesn't work as should be
1562
+ Fixed Error about insufficient permissions is not appears on database backup creation
1563
+ Fixed After rollback admin doesn't redirected to the Log in to Admin Panel page
1564
+ Fixed Database Backup must not include indexer table data
1565
+ Fixed Scheduled Backup creation/failure isn't logged
1566
+ Fixed Deleting backup while it is used by another process
1567
+ Fixed Opening *.tar files causes an error "There are no trailing zero-filled records"
1568
+ Fixed Unable to search by "Time" and "No" in Backups table
1569
+ Fixed Backups are deleted without confirmation
1570
+ Fixed Reports must be excluded from database snapshot backup
1571
+ Fixed There are no products in filtering results, if step calculation in automatic mode
1572
+ Fixed No validation for "Default Price Navigation Step"
1573
+ Fixed "Back" button doesn't work on the Create New Order page
1574
+ Fixed Incorrect logic of Token expiration in Two Step Password Reset flow
1575
+ Fixed Tag <br/> is present in tool-tip for field "Number of results (For the last time placed)" on the Edit Search page
1576
+ Fixed Unnecessary hard code in Magento Extension
1577
+ Fixed Wrong logic in Mage_Core_Model_Resource_Db_Collection_Abstract::join()
1578
+ Fixed Description and Short Description are displayed incorrectly for products added with WYSIWYG
1579
+ Fixed Adding product to the cart from the product review page leads to 404 page
1580
+ Fixed Special symbols in Sort Order field
1581
+ Fixed Text is wrong displayed with enabled Inline translation for Admin on back-end
1582
+ Fixed Inline Translation: Unable to translate some customer information
1583
+ Fixed Useless colon on front-end login page
1584
+ Fixed Unable to continue checkout for product with zero price and non-zero shipping price
1585
+ Fixed Import news_from_date field is configured poorly. It is not accepting the data from file
1586
+ Fixed When updating product data through import, attributes that have a value cannot be assigned a new value that is empty
1587
+ Fixed Unable to replace non-complex data for products with empty values during import
1588
+ Fixed "Wrong order ID" exception in PayPal Express module under heavy load
1589
+ Fixed Tax is applying on the order when creating it in the admin panel for a Customer Group with no taxes
1590
+ Fixed Issue with retrieving order statuses for array of states
1591
+ Fixed Wrong calculation product price with custom option type = Field and Fixed price
1592
+ Fixed Back ordered downloadable product is not available even when it is set to be be accessible when order status is Pending
1593
+ Fixed Missing column "position" at table catalog_category_anc_products_index_tmp
1594
+ Fixed Incorrect behavior of "Save in address book" option during admin Order creation for a new customer
1595
+ - refactored Mage_Adminhtml_Model_Sales_Order_Create::_prepareCustomer()
1596
+ Fixed Terms and Conditions is named differently on different pages
1597
+ Fixed "Apply" and "Discount Amount" fields appear twice in the Catalog Price Rule
1598
+ Fixed Poll shows incorrect percentage
1599
+ Fixed Added validation ability for admin configuration forms
1600
+ Fixed UPS XML misprint
1601
+ Fixed Misprint in uploading files form
1602
+ Fixed Unnecessary check boxes for gift options
1603
+ Fixed Wrong resource section declaration in Mage_Tag module
1604
+ Fixed "Customers Submitted this Tag" section doesn't update when customer has deleted tag from his account
1605
+ Fixed Correct product in category position
1606
+ Fixed Unable to create folder in Media Storage
1607
+ Fixed Translation with single quotes breaks JavaScript
1608
+ Fixed Out of memory error with hundreds of thousands of coupons attached to a single sales rule
1609
+ Fixed Unable to translate buttons and tabs on the "Manage Category" page
1610
+ Fixed Product Categories Tree doesn't expand in Manage Products page
1611
+ Fixed Incorrect products qty returns to stock after refund for configurable product
1612
+ Fixed Swf Uploader problems with cross domain Flash Player Policy
1613
+ Fixed Unable to translate "Layout Updates" block on create/edit widget page
1614
+ Fixed IE7: "Remember Me" checkbox visible on billing information step
1615
+ Fixed CMS WYSIWYG Editor - widget is inserted as new while editing in IE8
1616
+ Fixed Currency code doesn't correspond to the amount in reports
1617
+ Fixed Mage_Adminhtml_Block_Sales_Order_View_Tab_History::getFullHistory() doesn't use unique keys for each message
1618
+ Fixed Scope labels are shown without translate wrapper
1619
+ Fixed Wrong parameters handling in Core Helper formatDate()
1620
+ Fixed Apostrophe in store name breaks Google Analytics tracking
1621
+ Fixed Customer attribute prefix is not shown on frontend
1622
+ Fixed Incorrect rounding for product with custom options (percent price)
1623
+ Fixed Invoicing only part of products results in wrong totals calculation
1624
+ Fixed Incorrect Row Total Calculation in Refund
1625
+ - fixed rounding issues for partial Invoice and Refund
1626
+ - refactored delta rounding
1627
+ Fixed Filter by "Allow Countries" not working for Customer Address Form in the Backend
1628
+ - checking added for set country to be in available list
1629
+ Fixed There are sql-installs with empty string used as defaults for table columns, while column is not null able
1630
+ Fixed Unable to translate "Note" in "Product Stock Options"
1631
+ Fixed Various warning are displayed after creating shipment for 0 items
1632
+ Fixed Invalid content in Content-header in the top of page during scrolling during order creation
1633
+ Fixed "Online invoice" button present in backend when using Zero Subtotal Checkout
1634
+ Fixed String cast type in in_array function
1635
+ Fixed Newsletter template content should not disappear when "Show" / "Hide Editor" button was clicked
1636
+ Fixed Import feature doesn't validate whether super_products_sku is existing or not
1637
+ Fixed Cannot place order with downloadable product and discount code using Paypal Express payment method
1638
+ Fixed Product still out of stock after Stock Status reindex
1639
+ Fixed No ability to reindex Catalog URL Rewrites, error is shown
1640
+ Fixed Automatic reindexing based on matched events doesn't change "Status" and "Last Run" columns at process list grid
1641
+ Fixed Save catalog price rule gives trace if full reindex has already started
1642
+ Fixed Reindex requires notification is not shown for Stock Status when stock is updated for several products using Mass Action
1643
+ Fixed Incorrect FedEx's shipping rates (in case with non-US country origin)
1644
+ Fixed After partial reindex MSRP value is not applied (not viewed) in catalog during mass update action
1645
+ Fixed Wrong stock reindex on catalog if partial reindex done after full reindex started
1646
+ Fixed In error message string "already exists." written twice, when trying to save Product Tax Class with the same name
1647
+ Fixed Slow checkout with non-flushed cache
1648
+ Fixed Bundle product total is incorrect in Customization block
1649
+ Fixed Special price isn't considered for bundle dynamic products in "Your Customization" block
1650
+ Fixed Situation when any amount of duplicate reindex process can be running at one time
1651
+ Fixed Error with Advanced Search (in case with Date Attribute)
1652
+ Fixed Product Flat Data index isn't marked as "Reindex Required" after importing products when Flat Catalog is enabled
1653
+ Fixed User can't change root category for the store
1654
+ Fixed JS error causes the overwrite of Title field in PayPal Advanced configuration
1655
+ Fixed Mass action doesn't partially reindex catalog for product name/description
1656
+ Fixed Remove hint about $1 auth amount from informational message text (PayflowLink configuration)
1657
+ Fixed Mass action doesn't partially reindex catalog for product prices
1658
+ Fixed PayPal Payments Advanced works with $0 Auth instead of Full Auth
1659
+ Fixed Impossible to place Order using "Pay with PayPal" button from PayPal Payments Advanced iframe
1660
+ Fixed Mass action doesn't partially reindex catalog search for product if searchable attribute was updated
1661
+ Fixed "Please wait" AJAX screen doesn't appear in the middle of the page
1662
+ Fixed Checkout link on frontend is always referenced as http
1663
+ Fixed GET request is incorrectly formed during category creation
1664
+ - adjusted assertion to determine last viewed store
1665
+ Fixed Display of Tier Pricing with Configurable Products
1666
+ - added functionality to dynamically update tier prices accordingly to chosen product configuration
1667
+ Fixed Google Analytics e-commerce tracking not working
1668
+ Fixed URL key isn't used while product save
1669
+ Fixed Added validation class to 'Qty increments'
1670
+ Fixed Entered from admin customer date 1970 (or less) is saved as 2070 (or less)
1671
+ Fixed cUrl resource must be closed after checking it for errors, not before
1672
+ Fixed Exception while products mass update attributes in backend
1673
+ Fixed No ability to reindex Catalog URL Rewrites, error is shown
1674
+ Fixed Package with Core dependency
1675
+ Fixed Stock Availability isn't updated if 1: Run Price Reindex 2: Update Stock Availability on product with mass action/single product
1676
+ Fixed Blank page instead shopping cart page when compilation and PSC are enabled
1677
+ Fixed Unable to save redirect URL with special characters in search terms
1678
+ Fixed Attribute Set field should have client-side validation and appropriate information message
1679
+ Fixed "Localhost" isn't a valid domain name for installation
1680
+ Fixed Iframe for PayPal Payments Advanced is not loaded
1681
+ Fixed Retain the selected tab on editing CMS page
1682
+ Fixed Payflow Link Express Checkout (pay with PayPal button) payment
1683
+ Fixed Wrong number of reindex options is displayed
1684
+ Fixed Wrong phpDocs for Varien_Db_Select
1685
+ Fixed JavaScript calendar date range
1686
+ - fixed JS calendar behavior to use 4-digits year format
1687
+ Fixed Performance issue connected with sales rules on adding product to cart
1688
+ Fixed DHL same error message appears several times
1689
+ Fixed Item Status says "Mixed" when an order has been completed, should say "Shipped"
1690
+ Fixed Product option title is absent in backend order page
1691
+ Fixed Incorrect items number during multi shipping checkout
1692
+ Fixed User name displays differently in the unsuccessful message and in the text field label (log in form)
1693
+ Fixed If one or more indexers have Update Required = Yes and all Status = READY for all indexers than there is no notification for user to do reindex action
1694
+ Fixed No space between Address line 1 and line 2 in Shipping Label (in case with FedEx)
1695
+ Fixed JS works depends on the position attributes of the product
1696
+ Fixed Char set encoding is out-of-date in Settlement reports
1697
+ Fixed Settlement reports can't be downloaded if in merchant's account 'Settlement file' is set to 6.0 version
1698
+ Fixed Unable to login when secure and unsecure urls are different
1699
+ Fixed Customer session lost when using different domain/subdomain names for secure and unsecure urls
1700
+ Fixed "Most Viewed" reports ignore Store View switcher
1701
+ Fixed Long FPT name (and product name) doesn't fit into "My cart" block
1702
+ Fixed Paypal IPN post back failure
1703
+ Fixed Customer was unable to receive newsletters when it was created via backend
1704
+ Fixed Wrong Comments History in notification of order creation/cancellation
1705
+ Fixed Non escaped string causes javascript error
1706
+ Fixed Unable to view pictures during product editing
1707
+ Fixed Ampersand is saved incorrect in attribute label
1708
+ Fixed IE8: JS error appears after pressing 'Add new rule' in catalog price rules menu
1709
+ Fixed Exception after sorting newsletter queue
1710
+ Fixed Customer is not able to log in from URL without "www" in some cases
1711
+ Fixed SQL error on category view with enabled and configured FPT
1712
+ Fixed Automatic reindexing based on matched events doesn't change "Status" and "Last Run" columns at process list grid
1713
+ Fixed Performance issue with Magento Compiler + APC results in too many I/O calls
1714
+ Fixed Website Administrator is able to change default values
1715
+ Fixed Some of wishlist blocks and templates still treat the collection of wishlist items as collection of products
1716
+ Fixed Unnecessary comments in "Share Wishlist" email
1717
+
1718
+
1719
+
1720
+ ==== 1.6.x-devel-139014 ====
1721
+
1722
+ === Major Highlights ===
1723
+ Implemented different base prices for customer groups
1724
+ Added auto generation of coupon codes
1725
+
1726
+ === Fixes ===
1727
+ Fixed Incorrect translation messages definitions
1728
+ Fixed Error message isn't displayed if currency exchange rate not found (in case with DHL Int)
1729
+ Fixed Handling Fee doesn't applied Per Package
1730
+ Fixed User role with partial access can't edit attributes of configurable products
1731
+ Fixed Letter "n" missed in the word "handling"
1732
+ Fixed Buttons don't react for pressing on the "Widget Options" section in Insert Widget window
1733
+ Fixed Regular price displays incorrect
1734
+ Fixed {{base_url}} in (un)secure_url doesn't work since 1.6.1
1735
+ Fixed Product selection field gets cleared out with recently added products from latest page
1736
+ Fixed "Change" button while checkout doesn't work
1737
+ Fixed MySQL BIGINT field type is wrongly casted to integer
1738
+ Fixed Magento Connect Manager proceed with installation of extension if error appears on database backup
1739
+ Fixed "Set product as New from/to Date" works excluding selected dates
1740
+ Fixed Function fireEvent from lib/varien/js.js does not work in IE9
1741
+ Fixed Searching with first and last name has no results
1742
+ Fixed CMS Pages: Error in IE7 when select CMS page
1743
+ Fixed White screen appears instead of 404 Error Page when going to review a product which doesn't exist
1744
+ Fixed "Maximum Package Weight" option works incorrect in case with decimal Qty in shopping Cart
1745
+
1746
+
1747
+
1748
+ ==== 1.6.x-devel-138051 ====
1749
+ Fixed Unable to create tables for new EAV entity via SQL upgrade script
1750
+ Fixed Customer group isn't revalidated on checkout if Enable Automatic Assignment to Customer Group = Yes
1751
+ Fixed VAT ID validation must not run if added address is outside EU
1752
+ Fixed Mistake in PayPal Payments Advanced fieldset title
1753
+ Fixed Zero Subtotal Checkout payment method is used, when it is disabled in settings
1754
+ Fixed Some info lost from address when customer sets this address as default for shipping
1755
+ Fixed Incorrect calculation logic during distribution products between several pieces (in case with DHL)
1756
+ Fixed No ability to get shipping rates from US to another country (in case with DHL)
1757
+ Fixed Incorrect calculation of pieces weight (in case with Bundle Product)
1758
+ Fixed Divide Order Weight options for new DHL
1759
+ Fixed Product Flat Data index causes replication lag on MySQL master/slave model
1760
+ Fixed Exception is shown, when admin user provides filtration of Newsletter problem reports by Subscriber
1761
+ Fixed Gap in the section background appears on the Login page when CAPTCHA is enabled
1762
+ Fixed Typo in JavaScript error message
1763
+ Fixed Unable to do mass action update for products
1764
+ Fixed Error Message isn't displayed if currency exchange rate not found (in case with DHL)
1765
+ Fixed Weight field is absent during Quick simple product creation
1766
+ Fixed Fixed correct helper resolving
1767
+ Fixed Shipping methods are shown twice in DHLs shipping quote
1768
+ Fixed Unable to translate shipping and billing forms on the order creation page
1769
+ Fixed Drop-down attribute with layered navigation filter doesn't work with value is set to 0
1770
+ Fixed Free Shipping options doesn't work (in case with DHL)
1771
+ Fixed Handling Fee doesn't applied Per Package
1772
+
1773
+
1774
+
1775
+ ==== 1.6.x-devel-136760 ====
1776
+ Fixed Free Shipping options works incorrect
1777
+ Fixed Wrong massage appears if VAT ID is invalid
1778
+ Fixed WYSIWYG Editor: It's impossible insert Widget to CMS page content
1779
+ Fixed After removing VAT Number, customer continues to be assigned to "Valid VAT ID Domestic" group
1780
+ Fixed Customer's group is not changed if his billing address modified within backend
1781
+ Fixed Wrong behaviour and exception while using invalid image
1782
+ Fixed Layered navigation for prices displays incorrect price ranges in manual mode
1783
+ Fixed Uninformative error message during saving two nodes with the same parameter URL Key
1784
+ Fixed Unable to change order addresses in the admin panel
1785
+ Fixed PayPal Express always uses default billing address from customer account
1786
+ Fixed Unable to place order if customer selects Register on checkout
1787
+ Fixed Performance Issue: Most Viewed product reports on large amount of items
1788
+ Fixed In "Customer Addresses" block before and after of State name is located symbols ","
1789
+ Fixed Lightbox 2.5 with IE7 returns JS error on the page
1790
+ Fixed Unable to change customer status (confirmed/not confirmed) when customer logged in
1791
+ Fixed Incorrect notification for empty field during creation catalog price rules
1792
+ Fixed Unable to save product with non-checked multiple select attribute
1793
+ Fixed "Ship Bundle Items" for bundle product works incorrect
1794
+ Fixed Package Size setting for DHL
1795
+ Fixed No Input Validation for Catalog Fields
1796
+ Fixed Row Total Calculation in Refund
1797
+ Fixed "Maximum number of price intervals" should be written with capital letters
1798
+ Fixed Divide Order Weight options for DHL
1799
+
1800
+
1801
+
1802
+ ==== 1.6.x-devel-135464 ====
1803
+ Fixed Incorrect Row Total Calculation in Refund
1804
+ Fixed Impossible to create new customer in the backend
1805
+ Fixed Catalog data-upgrade-1.6.0.0.4-1.6.0.0.5.php is exteremly slow
1806
+ Fixed Free Shipping options doesn't work (in case with DHL International)
1807
+ Fixed Mage_Catalog_Helper_Product::getProduct() doesn't load product by its SKU
1808
+ Fixed Preview Template doesn't work correctly
1809
+ Fixed Some options of Bundle Product disappeared from the Invoice PDF
1810
+ Fixed "Allow Countries" affects on "Country of Manufacture" attribute
1811
+ Fixed Some phrases are not translated
1812
+ Fixed Incorrect Ordered Qty in Order (in case with decimal qty)
1813
+ Fixed Trademark character isn't being displayed properly in the PDF invoice
1814
+ Fixed Can't search transactions by order_id in manager.paypal.com
1815
+ Fixed Inline Translation: Grid headers are displayed incorrect on the Tag Edit page
1816
+ Fixed Scheduled Backup creation/failure isn't logged
1817
+ Fixed "Create Extension Package" page becomes broken after compilation
1818
+ Fixed Price including tax isn't displayed for some kinds of bundle products
1819
+ Fixed Layered navigation for prices displays incorrect price ranges in manual mode
1820
+ Fixed Pager works wrong with float page number
1821
+ Fixed VAT Number for country that isn't selected in "European Union Countries" validated
1822
+ Fixed Incorrect foreign key for EAV entity tables
1823
+ Fixed VAT ID: Warning message about not-valid VAT Number displayed in green frame
1824
+ Fixed Misprint in downloader/lib/Mage/Connect/Command/Install.php
1825
+ Fixed URL Rewrites must be case-sensitive
1826
+ Fixed Incorrect notification when customer's billing address updated with VAT ID within frontend
1827
+ Fixed Unable to install package via uploader if author name contains dash
1828
+ Fixed Fixed invoice subtotals for cases with partial invoice and discount
1829
+ Fixed Incorrect work of "Disable Automatic Group Changes Based on VAT ID Default Value" option
1830
+ Fixed Catalog URL Rewrites works incorrectly on creating categories
1831
+
1832
+
1833
+
1834
+ ==== 1.6.x-devel-134386 ====
1835
+
1836
+ === Major Highlights ===
1837
+ Added VAT ID Validation
1838
+ Implemented DHL for Europe
1839
+
1840
+ === Improvements ===
1841
+ Theme for iPhone was redesigned
1842
+
1843
+ === Fixes ===
1844
+ Fixed New Oder Status setting, specified for payment method works incorrectly when only virtual products are present in Order
1845
+ Fixed Rounding issue in catalog and product view if price includes tax
1846
+ Fixed Wrong status of catalog event is displayed by editing catalog event
1847
+ Fixed Role Resources are not saved
1848
+ Fixed "Qty for Item's Status to Become Out of Stock" option works incorrect
1849
+ Fixed XML parser works incorrect
1850
+ Fixed Mage_Reports_Model_Mysql4_Product_Index_Abstract must be declared abstract
1851
+ Fixed "Date & Time" and "Time" custom options becomes required when editing product
1852
+ Fixed Unable to cancel an order for an expired Authorize.net auth
1853
+ Fixed Custom options are not stored when downloadable product is duplicated
1854
+ Fixed "Cannot initialize the indexer process" error during Mass "Reindex Data" Action
1855
+ Fixed Search by new attribute fails, attribute is not shown in layered navigation
1856
+ Fixed Exception when "Price Navigation Step Calculation" set to "Manual" mode and FPT enabled
1857
+ Fixed WPPHS: Cancel URL doesn't work as should be
1858
+ Fixed Error about insufficient permissions is not appears on database backup creation
1859
+ Fixed After rollback admin doesn't redirected to the Log in to Admin Panel page
1860
+ Fixed Database Backup must not include indexer table data
1861
+ Fixed Scheduled Backup creation/failure isn't logged
1862
+ Fixed Deleting backup while it is used by another process
1863
+ Fixed Opening *.tar files causes an error "There are no trailing zero-filled records"
1864
+ Fixed Unable to search by "Time" and "No" in Backups table
1865
+ Fixed Backups are deleted without confirmation
1866
+ Fixed Reports must be excluded from database snapshot backup
1867
+ Fixed There are no products in filtering results, if step calculation in automatic mode
1868
+ Fixed No validation for "Default Price Navigation Step"
1869
+ Fixed "Back" button doesn't work on the Create New Order page
1870
+ Fixed Incorrect logic of Token expiration in Two Step Password Reset flow
1871
+ Fixed Tag <br/> is present in tool-tip for field "Number of results (For the last time placed)" on the Edit Search page
1872
+ Fixed Impossible to use CAPTCHA that longer than 12 symbols
1873
+ Fixed CAPTCHA with space symbol in it works incorrectly
1874
+ Fixed System backup doesn't complete
1875
+ Fixed Unnecessary hard code in Magento Extension
1876
+ Fixed It's impossible specify form where CAPTCHA could be used
1877
+ Fixed Wrong logic in Mage_Core_Model_Resource_Db_Collection_Abstract::join()
1878
+ Fixed Description and Short Description are displayed incorrectly for products added with WYSIWYG
1879
+ Fixed Adding product to the cart from the product review page leads to 404 page
1880
+ Fixed Special symbols in Sort Order field
1881
+ Fixed Text is wrong displayed with enabled Inline translation for Admin on back-end
1882
+ Fixed Inline Translation: Unable to translate some customer information
1883
+ Fixed Useless colon on front-end login page
1884
+ Fixed Unable to continue checkout for product with zero price and non-zero shipping price
1885
+ Fixed Import news_from_date field is configured poorly. It is not accepting the data from file
1886
+ Fixed When updating product data through import, attributes that have a value cannot be assigned a new value that is empty
1887
+ Fixed Unable to replace non-complex data for products with empty values during import
1888
+ Fixed Customer can't understand is CAPTCHA case sensitive or not
1889
+ Fixed Incorrect CAPTCHA's default configuration values
1890
+ Fixed "Wrong order ID" exception in PayPal Express module under heavy load
1891
+ Fixed Tax is applying on the order when creating it in the admin panel for a Customer Group with no taxes
1892
+ Fixed Issue with retrieving order statuses for array of states
1893
+ Fixed Wrong calculation product price with custom option type = Field and Fixed price
1894
+ Fixed Back ordered downloadable product is not available even when it is set to be be accessible when order status is Pending
1895
+
1896
+
1897
+
1898
+ ==== 1.6.x-devel-133001 ====
1899
+
1900
+ === Major Highlights ===
1901
+ Implemented Backup and Rollback functionality
1902
+
1903
+ === Fixes ===
1904
+ Fixed Full Product Price reindex started instead of partial if prices updated with mass action
1905
+ Fixed Missing column "position" at table catalog_category_anc_products_index_tmp
1906
+ Fixed Incorrect behavior of "Save in address book" option during admin Order creation for a new customer
1907
+ - refactored Mage_Adminhtml_Model_Sales_Order_Create::_prepareCustomer()
1908
+ Fixed Terms and Conditions is named differently on different pages
1909
+ Fixed "Apply" and "Discount Amount" fields appear twice in the Catalog Price Rule
1910
+ Fixed Poll shows incorrect percentage
1911
+ Fixed Added validation ability for admin configuration forms
1912
+ Fixed UPS XML misprint
1913
+ Fixed Misprint in uploading files form
1914
+ Fixed Unnecessary check boxes for gift options
1915
+ Fixed Wrong resource section declaration in Mage_Tag module
1916
+ Fixed "Customers Submitted this Tag" section doesn't update when customer has deleted tag from his account
1917
+ Fixed Correct product in category position
1918
+ Fixed Unable to create folder in Media Storage
1919
+ Fixed Translation with single quotes breaks JavaScript
1920
+ Fixed Out of memory error with hundreds of thousands of coupons attached to a single sales rule
1921
+ Fixed Unable to translate buttons and tabs on the "Manage Category" page
1922
+ Fixed Product Categories Tree doesn't expand in Manage Products page
1923
+ Fixed Incorrect products qty returns to stock after refund for configurable product
1924
+ Fixed Swf Uploader problems with cross domain Flash Player Policy
1925
+ Fixed Unable to translate "Layout Updates" block on create/edit widget page
1926
+ Fixed IE7: "Remember Me" checkbox visible on billing information step
1927
+ Fixed CMS WYSIWYG Editor - widget is inserted as new while editing in IE8
1928
+ Fixed Currency code doesn't correspond to the amount in reports
1929
+ Fixed Mage_Adminhtml_Block_Sales_Order_View_Tab_History::getFullHistory() doesn't use unique keys for each message
1930
+ Fixed Scope labels are shown without translate wrapper
1931
+ Fixed Wrong parameters handling in Core Helper formatDate()
1932
+ Fixed Apostrophe in store name breaks Google Analytics tracking
1933
+ Fixed Customer attribute prefix is not shown on frontend
1934
+ Fixed Incorrect rounding for product with custom options (percent price)
1935
+ Fixed Invoicing only part of products results in wrong totals calculation
1936
+ Fixed Incorrect Row Total Calculation in Refund
1937
+ - fixed rounding issues for partial Invoice and Refund
1938
+ - refactored delta rounding
1939
+ Fixed Filter by "Allow Countries" not working for Customer Address Form in the Backend
1940
+ - checking added for set country to be in available list
1941
+ Fixed There are sql-installs with empty string used as defaults for table columns, while column is not null able
1942
+ Fixed Unable to translate "Note" in "Product Stock Options"
1943
+ Fixed Various warning are displayed after creating shipment for 0 items
1944
+ Fixed Invalid content in Content-header in the top of page during scrolling during order creation
1945
+ Fixed "Online invoice" button present in backend when using Zero Subtotal Checkout
1946
+ Fixed String cast type in in_array function
1947
+ Fixed Newsletter template content should not disappear when "Show" / "Hide Editor" button was clicked
1948
+ Fixed Import feature doesn't validate whether super_products_sku is existing or not
1949
+
1950
+
1951
+
1952
+ ==== 1.6.x-devel-131783 ====
1953
+
1954
+ === Major Highlights ===
1955
+ Implemented new Layered Navigation price bucket algorithm
1956
+ Added captcha functionality
1957
+
1958
+ === Improvements ===
1959
+ XmlConnect package release v22.1
1960
+ Upgraded TinyMCE to v3.4.7
1961
+
1962
+ === Fixes ===
1963
+ Fixed Cannot place order with downloadable product and discount code using Paypal Express payment method
1964
+ Fixed Product still out of stock after Stock Status reindex
1965
+ Fixed No ability to reindex Catalog URL Rewrites, error is shown
1966
+ Fixed Automatic reindexing based on matched events doesn't change "Status" and "Last Run" columns at process list grid
1967
+ Fixed Save catalog price rule gives trace if full reindex has already started
1968
+ Fixed Reindex requires notification is not shown for Stock Status when stock is updated for several products using Mass Action
1969
+ Fixed Incorrect FedEx's shipping rates (in case with non-US country origin)
1970
+ Fixed After partial reindex MSRP value is not applied (not viewed) in catalog during mass update action
1971
+ Fixed Wrong stock reindex on catalog if partial reindex done after full reindex started
1972
+ Fixed In error message string "already exists." written twice, when trying to save Product Tax Class with the same name
1973
+ Fixed Wrong stock reindex on catalog if partial reindex done after full reindex started
1974
+ Fixed Slow checkout with non-flushed cache
1975
+
1976
+
1977
+
1978
+ ==== 1.6.x-devel-130478 ====
1979
+ Fixed Bundle product total is incorrect in Customization block
1980
+ Fixed Special price isn't considered for bundle dynamic products in "Your Customization" block
1981
+ Fixed Situation when any amount of duplicate reindex process can be running at one time
1982
+ Fixed Error with Advanced Search (in case with Date Attribute)
1983
+ Fixed Product Flat Data index isn't marked as "Reindex Required" after importing products when Flat Catalog is enabled
1984
+ Fixed User can't change root category for the store
1985
+ Fixed JS error causes the overwrite of Title field in PayPal Advanced configuration
1986
+ Fixed Mass action doesn't partially reindex catalog for product name/description
1987
+ Fixed Remove hint about $1 auth amount from informational message text (PayflowLink configuration)
1988
+ Fixed Mass action doesn't partially reindex catalog for product prices
1989
+ Fixed PayPal Payments Advanced works with $0 Auth instead of Full Auth
1990
+ Fixed Impossible to place Order using "Pay with PayPal" button from PayPal Payments Advanced iframe
1991
+ Fixed Mass action doesn't partially reindex catalog search for product if searchable attribute was updated
1992
+ Fixed "Please wait" AJAX screen doesn't appear in the middle of the page
1993
+ Fixed Checkout link on frontend is always referenced as http
1994
+ Fixed GET request is incorrectly formed during category creation
1995
+ - adjusted assertion to determine last viewed store
1996
+ Fixed Display of Tier Pricing with Configurable Products
1997
+ - added functionality to dynamically update tier prices accordingly to chosen product configuration
1998
+ Fixed Google Analytics e-commerce tracking not working
1999
+ Fixed URL key isn't used while product save
2000
+ Fixed Added validation class to 'Qty increments'
2001
+ Fixed Entered from admin customer date 1970 (or less) is saved as 2070 (or less)
2002
+ Fixed cUrl resource must be closed after checking it for errors, not before
2003
+ Fixed Exception while products mass update attributes in backend
2004
+ Fixed Impossible to place Order using Pay with PayPal button from PayflowLink iframe, when Payment Action is Sale
2005
+ Fixed No ability to reindex Catalog URL Rewrites, error is shown
2006
+ Fixed Package with Core dependency
2007
+
2008
+
2009
+
2010
+ ==== 1.6.x-devel-129596 ====
2011
+ Fixed Stock Availability isn't updated if 1: Run Price Reindex 2: Update Stock Availability on product with mass action/single product
2012
+ Fixed PayPal Payments Advanced update descriptions
2013
+ Fixed Blank page instead shopping cart page when compilation and PSC are enabled
2014
+ Fixed Unable to save redirect URL with special characters in search terms
2015
+ Fixed Attribute Set field should have client-side validation and appropriate information message
2016
+ Fixed "Localhost" isn't a valid domain name for installation
2017
+ Fixed Iframe for PayPal Payments Advanced is not loaded
2018
+ Fixed Retain the selected tab on editing CMS page
2019
+ Fixed Payflow Link Express Checkout (pay with PayPal button) payment
2020
+ Fixed Wrong number of reindex options is displayed
2021
+ Fixed Wrong phpDocs for Varien_Db_Select
2022
+ Fixed JavaScript calendar date range
2023
+ - fixed JS calendar behavior to use 4-digits year format
2024
+ Fixed Performance issue connected with sales rules on adding product to cart
2025
+ Fixed DHL same error message appears several times
2026
+ Fixed Item Status says "Mixed" when an order has been completed, should say "Shipped"
2027
+ Fixed Product option title is absent in backend order page
2028
+ Fixed Incorrect items number during multi shipping checkout
2029
+ Fixed User name displays differently in the unsuccessful message and in the text field label (log in form)
2030
+ Fixed If one or more indexers have Update Required = Yes and all Status = READY for all indexers than there is no notification for user to do reindex action
2031
+ Fixed No space between Address line 1 and line 2 in Shipping Label (in case with FedEx)
2032
+
2033
+
2034
+
2035
+ ==== 1.6.x-devel-128838 ====
2036
+
2037
+ === Improvements ===
2038
+ Indexers refactoring
2039
+
2040
+ === Changes ===
2041
+ Implemented localized PayPal settings for Japan
2042
+ Added PayPal Payments Advanced
2043
+
2044
+ === Fixes ===
2045
+ Fixed JS works depends on the position attributes of the product
2046
+ Fixed Char set encoding is out-of-date in Settlement reports
2047
+ Fixed Settlement reports can't be downloaded if in merchant's account 'Settlement file' is set to 6.0 version
2048
+ Fixed Unable to login when secure and unsecure urls are different
2049
+ Fixed Customer session lost when using different domain/subdomain names for secure and unsecure urls
2050
+ Fixed "Most Viewed" reports ignore Store View switcher
2051
+ Fixed Long FPT name (and product name) doesn't fit into "My cart" block
2052
+ Fixed Paypal IPN post back failure
2053
+ Fixed Customer was unable to receive newsletters when it was created via backend
2054
+ Fixed Wrong Comments History in notification of order creation/cancellation
2055
+ Fixed Non escaped string causes javascript error
2056
+ Fixed Unable to view pictures during product editing
2057
+ Fixed Ampersand is saved incorrect in attribute label
2058
+ Fixed IE8: JS error appears after pressing 'Add new rule' in catalog price rules menu
2059
+ Fixed Exception after sorting newsletter queue
2060
+ Fixed Customer is not able to log in from URL without "www" in some cases
2061
+ Fixed SQL error on category view with enabled and configured FPT
2062
+ Fixed Automatic reindexing based on matched events doesn't change "Status" and "Last Run" columns at process list grid
2063
+ Fixed Performance issue with Magento Compiler + APC results in too many I/O calls
2064
+ Fixed Website Administrator is able to change default values
2065
+ Fixed Some of wishlist blocks and templates still treat the collection of wishlist items as collection of products
2066
+ Fixed Unnecessary comments in "Share Wishlist" email
2067
+
2068
+
2069
+
2070
  ==== 1.6.1.0 ====
2071
 
2072
  === Major Highlights ===
api.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ if (version_compare(phpversion(), '5.2.0', '<')) {
28
+ echo 'It looks like you have an invalid PHP version. Magento supports PHP 5.2.0 or newer';
29
+ exit;
30
+ }
31
+ error_reporting(E_ALL | E_STRICT);
32
+
33
+ $mageFilename = getcwd() . '/app/Mage.php';
34
+
35
+ if (!file_exists($mageFilename)) {
36
+ echo 'Mage file not found';
37
+ exit;
38
+ }
39
+ require $mageFilename;
40
+
41
+ if (!Mage::isInstalled()) {
42
+ echo 'Application is not installed yet, please complete install wizard first.';
43
+ exit;
44
+ }
45
+
46
+ if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
47
+ Mage::setIsDeveloperMode(true);
48
+ }
49
+
50
+ #ini_set('display_errors', 1);
51
+
52
+ // emulate index.php entry point for correct URLs generation in API
53
+ Mage::register('custom_entry_point', true);
54
+ Mage::$headersSentThrowsException = false;
55
+ Mage::init('admin');
56
+ Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
57
+ Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML, Mage_Core_Model_App_Area::PART_EVENTS);
58
+
59
+ // query parameter "type" is set by .htaccess rewrite rule
60
+ $apiAlias = Mage::app()->getRequest()->getParam('type');
61
+
62
+ // check request could be processed by API2
63
+ if (in_array($apiAlias, Mage_Api2_Model_Server::getApiTypes())) {
64
+ /** @var $server Mage_Api2_Model_Server */
65
+ $server = Mage::getSingleton('api2/server');
66
+
67
+ $server->run();
68
+ } else {
69
+ /* @var $server Mage_Api_Model_Server */
70
+ $server = Mage::getSingleton('api/server');
71
+ $adapterCode = $server->getAdapterCodeByAlias($apiAlias);
72
+
73
+ // if no adapters found in aliases - find it by default, by code
74
+ if (null === $adapterCode) {
75
+ $adapterCode = $apiAlias;
76
+ }
77
+ try {
78
+ $server->initialize($adapterCode);
79
+ $server->run();
80
+
81
+ Mage::app()->getResponse()->sendResponse();
82
+ } catch (Exception $e) {
83
+ Mage::logException($e);
84
+
85
+ echo $e->getMessage();
86
+ exit;
87
+ }
88
+ }
app/Mage.php CHANGED
@@ -33,8 +33,8 @@ Mage::register('original_include_path', get_include_path());
33
  if (defined('COMPILER_INCLUDE_PATH')) {
34
  $appPath = COMPILER_INCLUDE_PATH;
35
  set_include_path($appPath . PS . Mage::registry('original_include_path'));
36
- include_once "Mage_Core_functions.php";
37
- include_once "Varien_Autoload.php";
38
  } else {
39
  /**
40
  * Set include path
@@ -129,6 +129,22 @@ final class Mage
129
  */
130
  static private $_isInstalled;
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  /**
133
  * Gets the current Magento version string
134
  * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
@@ -138,7 +154,8 @@ final class Mage
138
  public static function getVersion()
139
  {
140
  $i = self::getVersionInfo();
141
- return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "") . "-{$i['stability']}{$i['number']}", '.-');
 
142
  }
143
 
144
  /**
@@ -151,14 +168,25 @@ final class Mage
151
  {
152
  return array(
153
  'major' => '1',
154
- 'minor' => '6',
155
- 'revision' => '2',
156
  'patch' => '0',
157
  'stability' => '',
158
  'number' => '',
159
  );
160
  }
161
 
 
 
 
 
 
 
 
 
 
 
 
162
  /**
163
  * Set all my static data to defaults
164
  *
@@ -166,12 +194,14 @@ final class Mage
166
  public static function reset()
167
  {
168
  self::$_registry = array();
 
169
  self::$_app = null;
170
  self::$_config = null;
171
  self::$_events = null;
172
  self::$_objects = null;
173
  self::$_isDownloader = false;
174
  self::$_isDeveloperMode = false;
 
175
  // do not reset $headersSentThrowsException
176
  }
177
 
@@ -343,6 +373,7 @@ final class Mage
343
  * Get base URL path by type
344
  *
345
  * @param string $type
 
346
  * @return string
347
  */
348
  public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
@@ -404,17 +435,16 @@ final class Mage
404
  * Dispatch event
405
  *
406
  * Calls all observer callbacks registered for this event
407
- * and multiobservers matching event name pattern
408
  *
409
  * @param string $name
410
- * @param array $args
411
  * @return Mage_Core_Model_App
412
  */
413
  public static function dispatchEvent($name, array $data = array())
414
  {
415
  Varien_Profiler::start('DISPATCH EVENT:'.$name);
416
  $result = self::app()->dispatchEvent($name, $data);
417
- #$result = self::registry('events')->dispatch($name, $data);
418
  Varien_Profiler::stop('DISPATCH EVENT:'.$name);
419
  return $result;
420
  }
@@ -424,8 +454,8 @@ final class Mage
424
  *
425
  * @link Mage_Core_Model_Config::getModelInstance
426
  * @param string $modelClass
427
- * @param array $arguments
428
- * @return Mage_Core_Model_Abstract
429
  */
430
  public static function getModel($modelClass = '', $arguments = array())
431
  {
@@ -519,7 +549,7 @@ final class Mage
519
  }
520
 
521
  /**
522
- * Retreive resource helper object
523
  *
524
  * @param string $moduleName
525
  * @return Mage_Core_Model_Resource_Helper_Abstract
@@ -554,6 +584,7 @@ final class Mage
554
  *
555
  * @param string $message
556
  * @param string $messageStorage
 
557
  */
558
  public static function throwException($message, $messageStorage = null)
559
  {
@@ -577,7 +608,8 @@ final class Mage
577
  self::$_app = new Mage_Core_Model_App();
578
  self::setRoot();
579
  self::$_events = new Varien_Event_Collection();
580
- self::$_config = new Mage_Core_Model_Config($options);
 
581
 
582
  Varien_Profiler::start('self::app::init');
583
  self::$_app->init($code, $type, $options);
@@ -599,7 +631,8 @@ final class Mage
599
  try {
600
  self::setRoot();
601
  self::$_app = new Mage_Core_Model_App();
602
- self::$_config = new Mage_Core_Model_Config();
 
603
 
604
  if (!empty($modules)) {
605
  self::$_app->initSpecified($code, $type, $options, $modules);
@@ -630,9 +663,19 @@ final class Mage
630
  try {
631
  Varien_Profiler::start('mage');
632
  self::setRoot();
 
 
 
633
  self::$_app = new Mage_Core_Model_App();
 
 
 
 
 
 
634
  self::$_events = new Varien_Event_Collection();
635
- self::$_config = new Mage_Core_Model_Config($options);
 
636
  self::$_app->run(array(
637
  'scope_code' => $code,
638
  'scope_type' => $type,
@@ -663,6 +706,40 @@ final class Mage
663
  }
664
  }
665
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
  /**
667
  * Retrieve application installation flag
668
  *
33
  if (defined('COMPILER_INCLUDE_PATH')) {
34
  $appPath = COMPILER_INCLUDE_PATH;
35
  set_include_path($appPath . PS . Mage::registry('original_include_path'));
36
+ include_once COMPILER_INCLUDE_PATH . DS . "Mage_Core_functions.php";
37
+ include_once COMPILER_INCLUDE_PATH . DS . "Varien_Autoload.php";
38
  } else {
39
  /**
40
  * Set include path
129
  */
130
  static private $_isInstalled;
131
 
132
+ /**
133
+ * Magento edition constants
134
+ */
135
+ const EDITION_COMMUNITY = 'Community';
136
+ const EDITION_ENTERPRISE = 'Enterprise';
137
+ const EDITION_PROFESSIONAL = 'Professional';
138
+ const EDITION_GO = 'Go';
139
+
140
+ /**
141
+ * Current Magento edition.
142
+ *
143
+ * @var string
144
+ * @static
145
+ */
146
+ static private $_currentEdition = self::EDITION_COMMUNITY;
147
+
148
  /**
149
  * Gets the current Magento version string
150
  * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
154
  public static function getVersion()
155
  {
156
  $i = self::getVersionInfo();
157
+ return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "")
158
+ . "-{$i['stability']}{$i['number']}", '.-');
159
  }
160
 
161
  /**
168
  {
169
  return array(
170
  'major' => '1',
171
+ 'minor' => '7',
172
+ 'revision' => '0',
173
  'patch' => '0',
174
  'stability' => '',
175
  'number' => '',
176
  );
177
  }
178
 
179
+ /**
180
+ * Get current Magento edition
181
+ *
182
+ * @static
183
+ * @return string
184
+ */
185
+ public static function getEdition()
186
+ {
187
+ return self::$_currentEdition;
188
+ }
189
+
190
  /**
191
  * Set all my static data to defaults
192
  *
194
  public static function reset()
195
  {
196
  self::$_registry = array();
197
+ self::$_appRoot = null;
198
  self::$_app = null;
199
  self::$_config = null;
200
  self::$_events = null;
201
  self::$_objects = null;
202
  self::$_isDownloader = false;
203
  self::$_isDeveloperMode = false;
204
+ self::$_isInstalled = null;
205
  // do not reset $headersSentThrowsException
206
  }
207
 
373
  * Get base URL path by type
374
  *
375
  * @param string $type
376
+ * @param null|bool $secure
377
  * @return string
378
  */
379
  public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
435
  * Dispatch event
436
  *
437
  * Calls all observer callbacks registered for this event
438
+ * and multiple observers matching event name pattern
439
  *
440
  * @param string $name
441
+ * @param array $data
442
  * @return Mage_Core_Model_App
443
  */
444
  public static function dispatchEvent($name, array $data = array())
445
  {
446
  Varien_Profiler::start('DISPATCH EVENT:'.$name);
447
  $result = self::app()->dispatchEvent($name, $data);
 
448
  Varien_Profiler::stop('DISPATCH EVENT:'.$name);
449
  return $result;
450
  }
454
  *
455
  * @link Mage_Core_Model_Config::getModelInstance
456
  * @param string $modelClass
457
+ * @param array|object $arguments
458
+ * @return Mage_Core_Model_Abstract|false
459
  */
460
  public static function getModel($modelClass = '', $arguments = array())
461
  {
549
  }
550
 
551
  /**
552
+ * Retrieve resource helper object
553
  *
554
  * @param string $moduleName
555
  * @return Mage_Core_Model_Resource_Helper_Abstract
584
  *
585
  * @param string $message
586
  * @param string $messageStorage
587
+ * @throws Mage_Core_Exception
588
  */
589
  public static function throwException($message, $messageStorage = null)
590
  {
608
  self::$_app = new Mage_Core_Model_App();
609
  self::setRoot();
610
  self::$_events = new Varien_Event_Collection();
611
+ self::_setIsInstalled($options);
612
+ self::_setConfigModel($options);
613
 
614
  Varien_Profiler::start('self::app::init');
615
  self::$_app->init($code, $type, $options);
631
  try {
632
  self::setRoot();
633
  self::$_app = new Mage_Core_Model_App();
634
+ self::_setIsInstalled($options);
635
+ self::_setConfigModel($options);
636
 
637
  if (!empty($modules)) {
638
  self::$_app->initSpecified($code, $type, $options, $modules);
663
  try {
664
  Varien_Profiler::start('mage');
665
  self::setRoot();
666
+ if (isset($options['edition'])) {
667
+ self::$_currentEdition = $options['edition'];
668
+ }
669
  self::$_app = new Mage_Core_Model_App();
670
+ if (isset($options['request'])) {
671
+ self::$_app->setRequest($options['request']);
672
+ }
673
+ if (isset($options['response'])) {
674
+ self::$_app->setResponse($options['response']);
675
+ }
676
  self::$_events = new Varien_Event_Collection();
677
+ self::_setIsInstalled($options);
678
+ self::_setConfigModel($options);
679
  self::$_app->run(array(
680
  'scope_code' => $code,
681
  'scope_type' => $type,
706
  }
707
  }
708
 
709
+ /**
710
+ * Set application isInstalled flag based on given options
711
+ *
712
+ * @param array $options
713
+ */
714
+ protected static function _setIsInstalled($options = array())
715
+ {
716
+ if (isset($options['is_installed']) && $options['is_installed']) {
717
+ self::$_isInstalled = true;
718
+ }
719
+ }
720
+
721
+ /**
722
+ * Set application Config model
723
+ *
724
+ * @param array $options
725
+ */
726
+ protected static function _setConfigModel($options = array())
727
+ {
728
+ if (isset($options['config_model']) && class_exists($options['config_model'])) {
729
+ $alternativeConfigModelName = $options['config_model'];
730
+ unset($options['config_model']);
731
+ $alternativeConfigModel = new $alternativeConfigModelName($options);
732
+ } else {
733
+ $alternativeConfigModel = null;
734
+ }
735
+
736
+ if (!is_null($alternativeConfigModel) && ($alternativeConfigModel instanceof Mage_Core_Model_Config)) {
737
+ self::$_config = $alternativeConfigModel;
738
+ } else {
739
+ self::$_config = new Mage_Core_Model_Config($options);
740
+ }
741
+ }
742
+
743
  /**
744
  * Retrieve application installation flag
745
  *
app/code/core/Mage/Admin/Helper/Data.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Assert/Ip.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Assert/Time.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Resource.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Role/Generic.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Role/Group.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Role/Registry.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Acl/Role/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Config.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -114,6 +114,9 @@ class Mage_Admin_Model_Config extends Varien_Simplexml_Config
114
  }
115
 
116
  foreach ($children as $res) {
 
 
 
117
  $this->loadAclResources($acl, $res, $resourceName);
118
  }
119
  return $this;
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
114
  }
115
 
116
  foreach ($children as $res) {
117
+ if (1 == $res->disabled) {
118
+ continue;
119
+ }
120
  $this->loadAclResources($acl, $res, $resourceName);
121
  }
122
  return $this;
app/code/core/Mage/Admin/Model/Mysql4/Acl.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Acl/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Acl/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Permissions/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Roles.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Roles/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Roles/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Rules.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/Rules/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Mysql4/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Observer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -33,6 +33,7 @@
33
  */
34
  class Mage_Admin_Model_Observer
35
  {
 
36
  /**
37
  * Handler for controller_action_predispatch event
38
  *
@@ -51,7 +52,8 @@ class Mage_Admin_Model_Observer
51
  'forgotpassword',
52
  'resetpassword',
53
  'resetpasswordpost',
54
- 'logout'
 
55
  );
56
  if (in_array($requestedActionName, $openActions)) {
57
  $request->setDispatched(true);
@@ -64,7 +66,7 @@ class Mage_Admin_Model_Observer
64
  $postLogin = $request->getPost('login');
65
  $username = isset($postLogin['username']) ? $postLogin['username'] : '';
66
  $password = isset($postLogin['password']) ? $postLogin['password'] : '';
67
- $user = $session->login($username, $password, $request);
68
  $request->setPost('login', null);
69
  }
70
  if (!$request->getParam('forwarded')) {
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
33
  */
34
  class Mage_Admin_Model_Observer
35
  {
36
+ const FLAG_NO_LOGIN = 'no-login';
37
  /**
38
  * Handler for controller_action_predispatch event
39
  *
52
  'forgotpassword',
53
  'resetpassword',
54
  'resetpasswordpost',
55
+ 'logout',
56
+ 'refresh' // captcha refresh
57
  );
58
  if (in_array($requestedActionName, $openActions)) {
59
  $request->setDispatched(true);
66
  $postLogin = $request->getPost('login');
67
  $username = isset($postLogin['username']) ? $postLogin['username'] : '';
68
  $password = isset($postLogin['password']) ? $postLogin['password'] : '';
69
+ $session->login($username, $password, $request);
70
  $request->setPost('login', null);
71
  }
72
  if (!$request->getParam('forwarded')) {
app/code/core/Mage/Admin/Model/Resource/Acl.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Acl/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Acl/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Permissions/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Roles.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Roles/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Roles/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Rules.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/Rules/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Resource/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Roles.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -53,42 +53,86 @@ class Mage_Admin_Model_Roles extends Mage_Core_Model_Abstract
53
  */
54
  protected $_eventPrefix = 'admin_roles';
55
 
 
 
 
56
  protected function _construct()
57
  {
58
  $this->_init('admin/roles');
59
  }
60
 
 
 
 
 
 
61
  public function update()
62
  {
63
  $this->getResource()->update($this);
64
  return $this;
65
  }
66
 
 
 
 
 
 
67
  public function getUsersCollection()
68
  {
69
  return Mage::getResourceModel('admin/roles_user_collection');
70
  }
71
 
 
 
 
 
 
72
  public function getResourcesTree()
73
  {
74
  return $this->_buildResourcesArray(null, null, null, null, true);
75
  }
76
 
 
 
 
 
 
77
  public function getResourcesList()
78
  {
79
  return $this->_buildResourcesArray();
80
  }
81
 
 
 
 
 
 
82
  public function getResourcesList2D()
83
  {
84
  return $this->_buildResourcesArray(null, null, null, true);
85
  }
86
 
 
 
 
 
 
87
  public function getRoleUsers()
88
  {
89
  return $this->getResource()->getRoleUsers($this);
90
  }
91
 
 
 
 
 
 
 
 
 
 
 
 
92
  protected function _buildResourcesArray(Varien_Simplexml_Element $resource = null,
93
  $parentName = null, $level = 0, $represent2Darray = null, $rawNodes = false, $module = 'adminhtml')
94
  {
@@ -99,7 +143,7 @@ class Mage_Admin_Model_Roles extends Mage_Core_Model_Abstract
99
  $level = -1;
100
  } else {
101
  $resourceName = $parentName;
102
- if ($resource->getName() != 'title' && $resource->getName() != 'sort_order' && $resource->getName() != 'children') {
103
  $resourceName = (is_null($parentName) ? '' : $parentName . '/') . $resource->getName();
104
 
105
  //assigning module for its' children nodes
@@ -121,22 +165,20 @@ class Mage_Admin_Model_Roles extends Mage_Core_Model_Abstract
121
  }
122
  }
123
 
 
124
  $children = $resource->children();
125
- if (empty($children)) {
126
- if ($rawNodes) {
127
- return $resource;
128
- } else {
129
- return $result;
130
  }
131
- }
132
- foreach ($children as $child) {
133
  $this->_buildResourcesArray($child, $resourceName, $level + 1, $represent2Darray, $rawNodes, $module);
134
  }
 
135
  if ($rawNodes) {
136
  return $resource;
137
  } else {
138
  return $result;
139
  }
140
  }
141
-
142
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
53
  */
54
  protected $_eventPrefix = 'admin_roles';
55
 
56
+ /**
57
+ * Constructor
58
+ */
59
  protected function _construct()
60
  {
61
  $this->_init('admin/roles');
62
  }
63
 
64
+ /**
65
+ * Update object into database
66
+ *
67
+ * @return Mage_Admin_Model_Roles
68
+ */
69
  public function update()
70
  {
71
  $this->getResource()->update($this);
72
  return $this;
73
  }
74
 
75
+ /**
76
+ * Retrieve users collection
77
+ *
78
+ * @return Mage_Admin_Model_Resource_Roles_User_Collection
79
+ */
80
  public function getUsersCollection()
81
  {
82
  return Mage::getResourceModel('admin/roles_user_collection');
83
  }
84
 
85
+ /**
86
+ * Return tree of acl resources
87
+ *
88
+ * @return array|null|Varien_Simplexml_Element
89
+ */
90
  public function getResourcesTree()
91
  {
92
  return $this->_buildResourcesArray(null, null, null, null, true);
93
  }
94
 
95
+ /**
96
+ * Return list of acl resources
97
+ *
98
+ * @return array|null|Varien_Simplexml_Element
99
+ */
100
  public function getResourcesList()
101
  {
102
  return $this->_buildResourcesArray();
103
  }
104
 
105
+ /**
106
+ * Return list of acl resources in 2D format
107
+ *
108
+ * @return array|null|Varien_Simplexml_Element
109
+ */
110
  public function getResourcesList2D()
111
  {
112
  return $this->_buildResourcesArray(null, null, null, true);
113
  }
114
 
115
+ /**
116
+ * Return users for role
117
+ *
118
+ * @return array|false
119
+ */
120
  public function getRoleUsers()
121
  {
122
  return $this->getResource()->getRoleUsers($this);
123
  }
124
 
125
+ /**
126
+ * Build resources array process
127
+ *
128
+ * @param null|Varien_Simplexml_Element $resource
129
+ * @param null $parentName
130
+ * @param int $level
131
+ * @param null $represent2Darray
132
+ * @param bool $rawNodes
133
+ * @param string $module
134
+ * @return array|null|Varien_Simplexml_Element
135
+ */
136
  protected function _buildResourcesArray(Varien_Simplexml_Element $resource = null,
137
  $parentName = null, $level = 0, $represent2Darray = null, $rawNodes = false, $module = 'adminhtml')
138
  {
143
  $level = -1;
144
  } else {
145
  $resourceName = $parentName;
146
+ if (!in_array($resource->getName(), array('title', 'sort_order', 'children', 'disabled'))) {
147
  $resourceName = (is_null($parentName) ? '' : $parentName . '/') . $resource->getName();
148
 
149
  //assigning module for its' children nodes
165
  }
166
  }
167
 
168
+ //check children and run recursion if they exists
169
  $children = $resource->children();
170
+ foreach ($children as $key => $child) {
171
+ if (1 == $child->disabled) {
172
+ $resource->{$key} = null;
173
+ continue;
 
174
  }
 
 
175
  $this->_buildResourcesArray($child, $resourceName, $level + 1, $represent2Darray, $rawNodes, $module);
176
  }
177
+
178
  if ($rawNodes) {
179
  return $resource;
180
  } else {
181
  return $result;
182
  }
183
  }
 
184
  }
app/code/core/Mage/Admin/Model/Rules.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/Model/Session.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -86,7 +86,7 @@ class Mage_Admin_Model_Session extends Mage_Core_Model_Session_Abstract
86
  }
87
 
88
  try {
89
- /* @var $user Mage_Admin_Model_User */
90
  $user = Mage::getModel('admin/user');
91
  $user->login($username, $password);
92
  if ($user->getId()) {
@@ -98,19 +98,19 @@ class Mage_Admin_Model_Session extends Mage_Core_Model_Session_Abstract
98
  $this->setIsFirstPageAfterLogin(true);
99
  $this->setUser($user);
100
  $this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
101
- if ($requestUri = $this->_getRequestUri($request)) {
 
 
102
  Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user));
103
  header('Location: ' . $requestUri);
104
  exit;
105
  }
 
 
106
  }
107
- else {
108
- Mage::throwException(Mage::helper('adminhtml')->__('Invalid Username or Password.'));
109
- }
110
- }
111
- catch (Mage_Core_Exception $e) {
112
  Mage::dispatchEvent('admin_session_user_login_failed',
113
- array('user_name' => $username, 'exception' => $e));
114
  if ($request && !$request->getParam('messageSent')) {
115
  Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
116
  $request->setParam('messageSent', true);
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
86
  }
87
 
88
  try {
89
+ /** @var $user Mage_Admin_Model_User */
90
  $user = Mage::getModel('admin/user');
91
  $user->login($username, $password);
92
  if ($user->getId()) {
98
  $this->setIsFirstPageAfterLogin(true);
99
  $this->setUser($user);
100
  $this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
101
+
102
+ $requestUri = $this->_getRequestUri($request);
103
+ if ($requestUri) {
104
  Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user));
105
  header('Location: ' . $requestUri);
106
  exit;
107
  }
108
+ } else {
109
+ Mage::throwException(Mage::helper('adminhtml')->__('Invalid User Name or Password.'));
110
  }
111
+ } catch (Mage_Core_Exception $e) {
 
 
 
 
112
  Mage::dispatchEvent('admin_session_user_login_failed',
113
+ array('user_name' => $username, 'exception' => $e));
114
  if ($request && !$request->getParam('messageSent')) {
115
  Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
116
  $request->setParam('messageSent', true);
app/code/core/Mage/Admin/Model/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -61,7 +61,7 @@
61
  class Mage_Admin_Model_User extends Mage_Core_Model_Abstract
62
  {
63
  /**
64
- * Configuration pathes for email templates and identities
65
  */
66
  const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template';
67
  const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity';
@@ -328,6 +328,10 @@ class Mage_Admin_Model_User extends Mage_Core_Model_Abstract
328
  $result = false;
329
 
330
  try {
 
 
 
 
331
  $this->loadByUsername($username);
332
  $sensitive = ($config) ? $username == $this->getUsername() : true;
333
 
@@ -556,7 +560,7 @@ class Mage_Admin_Model_User extends Mage_Core_Model_Abstract
556
  throw Mage::exception('Mage_Core', Mage::helper('adminhtml')->__('Invalid password reset token.'));
557
  }
558
  $this->setRpToken($newResetPasswordLinkToken);
559
- $currentDate = Varien_Date::now(true);
560
  $this->setRpTokenCreatedAt($currentDate);
561
 
562
  return $this;
@@ -578,7 +582,7 @@ class Mage_Admin_Model_User extends Mage_Core_Model_Abstract
578
 
579
  $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod();
580
 
581
- $currentDate = Varien_Date::now(true);
582
  $currentTimestamp = Varien_Date::toTimestamp($currentDate);
583
  $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt);
584
  if ($tokenTimestamp > $currentTimestamp) {
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
61
  class Mage_Admin_Model_User extends Mage_Core_Model_Abstract
62
  {
63
  /**
64
+ * Configuration paths for email templates and identities
65
  */
66
  const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'admin/emails/forgot_email_template';
67
  const XML_PATH_FORGOT_EMAIL_IDENTITY = 'admin/emails/forgot_email_identity';
328
  $result = false;
329
 
330
  try {
331
+ Mage::dispatchEvent('admin_user_authenticate_before', array(
332
+ 'username' => $username,
333
+ 'user' => $this
334
+ ));
335
  $this->loadByUsername($username);
336
  $sensitive = ($config) ? $username == $this->getUsername() : true;
337
 
560
  throw Mage::exception('Mage_Core', Mage::helper('adminhtml')->__('Invalid password reset token.'));
561
  }
562
  $this->setRpToken($newResetPasswordLinkToken);
563
+ $currentDate = Varien_Date::now();
564
  $this->setRpTokenCreatedAt($currentDate);
565
 
566
  return $this;
582
 
583
  $tokenExpirationPeriod = Mage::helper('admin')->getResetPasswordLinkExpirationPeriod();
584
 
585
+ $currentDate = Varien_Date::now();
586
  $currentTimestamp = Varien_Date::toTimestamp($currentDate);
587
  $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt);
588
  if ($tokenTimestamp > $currentTimestamp) {
app/code/core/Mage/Admin/data/admin_setup/data-install-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/etc/config.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Admin
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
21
  *
22
  * @category Mage
23
  * @package Mage_Admin
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
app/code/core/Mage/Admin/sql/admin_setup/install-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -41,8 +41,8 @@ $table = $installer->getConnection()
41
  'primary' => true,
42
  ), 'Assert ID')
43
  ->addColumn('assert_type', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
44
- 'nullable' => false,
45
- 'default' => '',
46
  ), 'Assert Type')
47
  ->addColumn('assert_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
48
  ), 'Assert Data')
@@ -85,8 +85,8 @@ $table = $installer->getConnection()
85
  'default' => '0',
86
  ), 'User ID')
87
  ->addColumn('role_name', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array(
88
- 'nullable' => false,
89
- 'default' => '',
90
  ), 'Role Name')
91
  ->addIndex($installer->getIdxName('admin/role', array('parent_id', 'sort_order')),
92
  array('parent_id', 'sort_order'))
@@ -112,8 +112,8 @@ $table = $installer->getConnection()
112
  'default' => '0',
113
  ), 'Role ID')
114
  ->addColumn('resource_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
115
- 'nullable' => false,
116
- 'default' => '',
117
  ), 'Resource ID')
118
  ->addColumn('privileges', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
119
  'nullable' => true,
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
41
  'primary' => true,
42
  ), 'Assert ID')
43
  ->addColumn('assert_type', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
44
+ 'nullable' => true,
45
+ 'default' => null,
46
  ), 'Assert Type')
47
  ->addColumn('assert_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
48
  ), 'Assert Data')
85
  'default' => '0',
86
  ), 'User ID')
87
  ->addColumn('role_name', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array(
88
+ 'nullable' => true,
89
+ 'default' => null,
90
  ), 'Role Name')
91
  ->addIndex($installer->getIdxName('admin/role', array('parent_id', 'sort_order')),
92
  array('parent_id', 'sort_order'))
112
  'default' => '0',
113
  ), 'Role ID')
114
  ->addColumn('resource_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
115
+ 'nullable' => true,
116
+ 'default' => null,
117
  ), 'Resource ID')
118
  ->addColumn('privileges', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
119
  'nullable' => true,
app/code/core/Mage/Admin/sql/admin_setup/mysql4-install-0.7.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.0-0.7.1.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-0.7.1-0.7.2.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/sql/admin_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Admin/sql/admin_setup/{mysql4-upgrade-1.6.0.0-1.6.1.0.php → upgrade-1.6.0.0-1.6.1.0.php} RENAMED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Admin
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/Helper/Data.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -129,6 +129,8 @@ class Mage_AdminNotification_Helper_Data extends Mage_Core_Helper_Abstract
129
  $this->_popupReadable = true;
130
  }
131
  }
 
 
132
  }
133
  return $this->_popupReadable;
134
  }
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
129
  $this->_popupReadable = true;
130
  }
131
  }
132
+
133
+ $curl->close();
134
  }
135
  return $this->_popupReadable;
136
  }
app/code/core/Mage/AdminNotification/Model/Feed.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/Model/Inbox.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -117,4 +117,94 @@ class Mage_AdminNotification_Model_Inbox extends Mage_Core_Model_Abstract
117
  {
118
  return $this->getResource()->parse($this, $data);
119
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
117
  {
118
  return $this->getResource()->parse($this, $data);
119
  }
120
+
121
+ /**
122
+ * Add new message
123
+ *
124
+ * @param int $severity
125
+ * @param string $title
126
+ * @param string|array $description
127
+ * @param string $url
128
+ * @param bool $isInternal
129
+ * @return Mage_AdminNotification_Model_Inbox
130
+ */
131
+ public function add($severity, $title, $description, $url = '', $isInternal = true)
132
+ {
133
+ if (!$this->getSeverities($severity)) {
134
+ Mage::throwException($this->__('Wrong message type'));
135
+ }
136
+ if (is_array($description)) {
137
+ $description = '<ul><li>' . implode('</li><li>', $description) . '</li></ul>';
138
+ }
139
+ $date = date('Y-m-d H:i:s');
140
+ $this->parse(array(array(
141
+ 'severity' => $severity,
142
+ 'date_added' => $date,
143
+ 'title' => $title,
144
+ 'description' => $description,
145
+ 'url' => $url,
146
+ 'internal' => $isInternal
147
+ )));
148
+ return $this;
149
+ }
150
+
151
+ /**
152
+ * Add critical severity message
153
+ *
154
+ * @param string $title
155
+ * @param string|array $description
156
+ * @param string $url
157
+ * @param bool $isInternal
158
+ * @return Mage_AdminNotification_Model_Inbox
159
+ */
160
+ public function addCritical($title, $description, $url = '', $isInternal = true)
161
+ {
162
+ $this->add(self::SEVERITY_CRITICAL, $title, $description, $url, $isInternal);
163
+ return $this;
164
+ }
165
+
166
+ /**
167
+ * Add major severity message
168
+ *
169
+ * @param string $title
170
+ * @param string|array $description
171
+ * @param string $url
172
+ * @param bool $isInternal
173
+ * @return Mage_AdminNotification_Model_Inbox
174
+ */
175
+ public function addMajor($title, $description, $url = '', $isInternal = true)
176
+ {
177
+ $this->add(self::SEVERITY_MAJOR, $title, $description, $url, $isInternal);
178
+ return $this;
179
+ }
180
+
181
+ /**
182
+ * Add minor severity message
183
+ *
184
+ * @param string $title
185
+ * @param string|array $description
186
+ * @param string $url
187
+ * @param bool $isInternal
188
+ * @return Mage_AdminNotification_Model_Inbox
189
+ */
190
+ public function addMinor($title, $description, $url = '', $isInternal = true)
191
+ {
192
+ $this->add(self::SEVERITY_MINOR, $title, $description, $url, $isInternal);
193
+ return $this;
194
+ }
195
+
196
+ /**
197
+ * Add notice
198
+ *
199
+ * @param string $title
200
+ * @param string|array $description
201
+ * @param string $url
202
+ * @param bool $isInternal
203
+ * @return Mage_AdminNotification_Model_Inbox
204
+ */
205
+ public function addNotice($title, $description, $url = '', $isInternal = true)
206
+ {
207
+ $this->add(self::SEVERITY_NOTICE, $title, $description, $url, $isInternal);
208
+ return $this;
209
+ }
210
  }
app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/Model/Mysql4/Inbox/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/Model/Observer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/Model/Resource/Inbox.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -101,7 +101,13 @@ class Mage_AdminNotification_Model_Resource_Inbox extends Mage_Core_Model_Resour
101
  foreach ($data as $item) {
102
  $select = $adapter->select()
103
  ->from($this->getMainTable())
104
- ->where('url=?', $item['url']);
 
 
 
 
 
 
105
 
106
  if (isset($item['internal'])) {
107
  $row = false;
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
101
  foreach ($data as $item) {
102
  $select = $adapter->select()
103
  ->from($this->getMainTable())
104
+ ->where('title = ?', $item['title']);
105
+
106
+ if (empty($item['url'])) {
107
+ $select->where('url IS NULL');
108
+ } else {
109
+ $select->where('url = ?', $item['url']);
110
+ }
111
 
112
  if (isset($item['internal'])) {
113
  $row = false;
app/code/core/Mage/AdminNotification/Model/Resource/Inbox/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/Model/Survey.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -50,6 +50,8 @@ class Mage_AdminNotification_Model_Survey
50
  $curl->setConfig(array('timeout' => 5))
51
  ->write(Zend_Http_Client::GET, self::getSurveyUrl(), '1.0');
52
  $response = $curl->read();
 
 
53
  if (Zend_Http_Response::extractCode($response) == 200) {
54
  return true;
55
  }
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
50
  $curl->setConfig(array('timeout' => 5))
51
  ->write(Zend_Http_Client::GET, self::getSurveyUrl(), '1.0');
52
  $response = $curl->read();
53
+ $curl->close();
54
+
55
  if (Zend_Http_Response::extractCode($response) == 200) {
56
  return true;
57
  }
app/code/core/Mage/AdminNotification/etc/adminhtml.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_AdminNotification
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
21
  *
22
  * @category Mage
23
  * @package Mage_AdminNotification
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
app/code/core/Mage/AdminNotification/etc/config.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_AdminNotification
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
21
  *
22
  * @category Mage
23
  * @package Mage_AdminNotification
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
app/code/core/Mage/AdminNotification/etc/system.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_AdminNotification
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
21
  *
22
  * @category Mage
23
  * @package Mage_AdminNotification
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
app/code/core/Mage/AdminNotification/sql/adminnotification_setup/install-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-install-1.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/AdminNotification/sql/adminnotification_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_AdminNotification
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Controller/Action.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Exception.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Helper/Data.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -35,6 +35,16 @@ class Mage_Api_Helper_Data extends Mage_Core_Helper_Abstract
35
  {
36
  const XML_PATH_API_WSI = 'api/config/compliance_wsi';
37
 
 
 
 
 
 
 
 
 
 
 
38
  /**
39
  * @return boolean
40
  */
@@ -165,7 +175,11 @@ class Mage_Api_Helper_Data extends Mage_Core_Helper_Abstract
165
 
166
  foreach ($objectKeys as $key) {
167
  if (is_object($obj->$key) && isset($obj->$key->complexObjectArray)) {
168
- $obj->$key = $obj->$key->complexObjectArray;
 
 
 
 
169
  $modifiedKeys[] = $key;
170
  }
171
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
35
  {
36
  const XML_PATH_API_WSI = 'api/config/compliance_wsi';
37
 
38
+ /**
39
+ * Method to find adapter code depending on WS-I compatibility setting
40
+ *
41
+ * @return string
42
+ */
43
+ public function getV2AdapterCode()
44
+ {
45
+ return $this->isComplianceWSI() ? 'soap_wsi' : 'soap_v2';
46
+ }
47
+
48
  /**
49
  * @return boolean
50
  */
175
 
176
  foreach ($objectKeys as $key) {
177
  if (is_object($obj->$key) && isset($obj->$key->complexObjectArray)) {
178
+ if (is_array($obj->$key->complexObjectArray)) {
179
+ $obj->$key = $obj->$key->complexObjectArray;
180
+ } else { // for one element array
181
+ $obj->$key = array($obj->$key->complexObjectArray);
182
+ }
183
  $modifiedKeys[] = $key;
184
  }
185
  }
app/code/core/Mage/Api/Model/Acl.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Assert/Ip.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Assert/Time.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Resource.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Role/Generic.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Role/Group.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Role/Registry.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Acl/Role/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Config.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -71,6 +71,24 @@ class Mage_Api_Model_Config extends Varien_Simplexml_Config
71
  return $this;
72
  }
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  /**
75
  * Retrieve all adapters
76
  *
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
71
  return $this;
72
  }
73
 
74
+ /**
75
+ * Retrieve adapter aliases from config.
76
+ *
77
+ * @return array
78
+ */
79
+ public function getAdapterAliases()
80
+ {
81
+ $aliases = array();
82
+
83
+ foreach ($this->getNode('adapter_aliases')->children() as $alias => $adapter) {
84
+ $aliases[$alias] = array(
85
+ (string) $adapter->suggest_class, // model class name
86
+ (string) $adapter->suggest_method // model method name
87
+ );
88
+ }
89
+ return $aliases;
90
+ }
91
+
92
  /**
93
  * Retrieve all adapters
94
  *
app/code/core/Mage/Api/Model/Mysql4/Acl.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Acl/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Acl/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Permissions/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Roles.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Roles/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Roles/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Rules.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/Rules/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Mysql4/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Acl.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Acl/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Acl/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Permissions/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Role.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Role/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Roles.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Roles/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Roles/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Rules.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/Rules/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Resource/User/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Role.php CHANGED
@@ -20,12 +20,12 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
  /**
28
- * Enter description here ...
29
  *
30
  * @method Mage_Api_Model_Resource_Role _getResource()
31
  * @method Mage_Api_Model_Resource_Role getResource()
@@ -48,6 +48,9 @@
48
  */
49
  class Mage_Api_Model_Role extends Mage_Core_Model_Abstract
50
  {
 
 
 
51
  protected function _construct()
52
  {
53
  $this->_init('api/role');
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
  /**
28
+ * Role item model
29
  *
30
  * @method Mage_Api_Model_Resource_Role _getResource()
31
  * @method Mage_Api_Model_Resource_Role getResource()
48
  */
49
  class Mage_Api_Model_Role extends Mage_Core_Model_Abstract
50
  {
51
+ /**
52
+ * Initialize resource
53
+ */
54
  protected function _construct()
55
  {
56
  $this->_init('api/role');
app/code/core/Mage/Api/Model/Roles.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -41,6 +41,8 @@
41
  * @method Mage_Api_Model_Roles setUserId(int $value)
42
  * @method string getRoleName()
43
  * @method Mage_Api_Model_Roles setRoleName(string $value)
 
 
44
  *
45
  * @category Mage
46
  * @package Mage_Api
@@ -48,6 +50,14 @@
48
  */
49
  class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract
50
  {
 
 
 
 
 
 
 
 
51
  protected function _construct()
52
  {
53
  $this->_init('api/roles');
@@ -84,8 +94,10 @@ class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract
84
  return $this->getResource()->getRoleUsers($this);
85
  }
86
 
87
- protected function _buildResourcesArray(Varien_Simplexml_Element $resource=null, $parentName=null, $level=0, $represent2Darray=null, $rawNodes = false, $module = 'adminhtml')
88
- {
 
 
89
  static $result;
90
 
91
  if (is_null($resource)) {
@@ -94,7 +106,9 @@ class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract
94
  $level = -1;
95
  } else {
96
  $resourceName = $parentName;
97
- if ($resource->getName()!='title' && $resource->getName()!='sort_order' && $resource->getName() != 'children') {
 
 
98
  $resourceName = (is_null($parentName) ? '' : $parentName.'/').$resource->getName();
99
 
100
  //assigning module for its' children nodes
@@ -135,4 +149,33 @@ class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract
135
  }
136
  }
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
41
  * @method Mage_Api_Model_Roles setUserId(int $value)
42
  * @method string getRoleName()
43
  * @method Mage_Api_Model_Roles setRoleName(string $value)
44
+ * @method string getName()
45
+ * @method Mage_Api_Model_Role setName() setName(string $name)
46
  *
47
  * @category Mage
48
  * @package Mage_Api
50
  */
51
  class Mage_Api_Model_Roles extends Mage_Core_Model_Abstract
52
  {
53
+ /**
54
+ * Filters
55
+ *
56
+ * @var array
57
+ */
58
+ protected $_filters;
59
+
60
+
61
  protected function _construct()
62
  {
63
  $this->_init('api/roles');
94
  return $this->getResource()->getRoleUsers($this);
95
  }
96
 
97
+ protected function _buildResourcesArray(
98
+ Varien_Simplexml_Element $resource = null, $parentName = null, $level = 0, $represent2Darray = null,
99
+ $rawNodes = false, $module = 'adminhtml'
100
+ ) {
101
  static $result;
102
 
103
  if (is_null($resource)) {
106
  $level = -1;
107
  } else {
108
  $resourceName = $parentName;
109
+ if ($resource->getName()!='title' && $resource->getName()!='sort_order'
110
+ && $resource->getName() != 'children'
111
+ ) {
112
  $resourceName = (is_null($parentName) ? '' : $parentName.'/').$resource->getName();
113
 
114
  //assigning module for its' children nodes
149
  }
150
  }
151
 
152
+ /**
153
+ * Filter data before save
154
+ *
155
+ * @return Mage_Api_Model_Roles
156
+ */
157
+ protected function _beforeSave()
158
+ {
159
+ $this->filter();
160
+ parent::_beforeSave();
161
+ return $this;
162
+ }
163
+
164
+ /**
165
+ * Filter set data
166
+ *
167
+ * @return Mage_Api_Model_Roles
168
+ */
169
+ public function filter()
170
+ {
171
+ $data = $this->getData();
172
+ if (!$this->_filters || !$data) {
173
+ return $this;
174
+ }
175
+ /** @var $filter Mage_Core_Model_Input_Filter */
176
+ $filter = Mage::getModel('core/input_filter');
177
+ $filter->setFilters($this->_filters);
178
+ $this->setData($filter->filter($data));
179
+ return $this;
180
+ }
181
  }
app/code/core/Mage/Api/Model/Rules.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Server.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -43,35 +43,89 @@ class Mage_Api_Model_Server
43
  /**
44
  * Web service adapter
45
  *
46
- * @var Mage_Api_Model_Server_Adaper_Interface
47
  */
48
  protected $_adapter;
49
 
50
- public function init(Mage_Api_Controller_Action $controller, $adapter='default', $handler='default')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  {
52
- $adapters = Mage::getSingleton('api/config')->getActiveAdapters();
53
- $handlers = Mage::getSingleton('api/config')->getHandlers();
54
- $this->_api = $adapter;
55
- if (isset($adapters[$adapter])) {
56
- $adapterModel = Mage::getModel((string) $adapters[$adapter]->model);
57
- /* @var $adapterModel Mage_Api_Model_Server_Adapter_Interface */
 
 
58
  if (!($adapterModel instanceof Mage_Api_Model_Server_Adapter_Interface)) {
59
  Mage::throwException(Mage::helper('api')->__('Invalid webservice adapter specified.'));
60
  }
61
-
62
  $this->_adapter = $adapterModel;
63
- $this->_adapter->setController($controller);
 
 
 
 
 
 
64
 
65
  if (!isset($handlers->$handler)) {
66
  Mage::throwException(Mage::helper('api')->__('Invalid webservice handler specified.'));
67
  }
68
-
69
  $handlerClassName = Mage::getConfig()->getModelClassName((string) $handlers->$handler->model);
 
70
  $this->_adapter->setHandler($handlerClassName);
71
  } else {
72
  Mage::throwException(Mage::helper('api')->__('Invalid webservice adapter specified.'));
73
  }
74
-
75
  return $this;
76
  }
77
 
@@ -96,7 +150,7 @@ class Mage_Api_Model_Server
96
  /**
97
  * Retrieve web service adapter
98
  *
99
- * @return Mage_Api_Model_Server_Adaper_Interface
100
  */
101
  public function getAdapter()
102
  {
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
43
  /**
44
  * Web service adapter
45
  *
46
+ * @var Mage_Api_Model_Server_Adapter_Interface
47
  */
48
  protected $_adapter;
49
 
50
+ /**
51
+ * Complex retrieve adapter code by calling auxiliary model method
52
+ *
53
+ * @param string $alias Alias name
54
+ * @return string|null Returns NULL if no alias found
55
+ */
56
+ public function getAdapterCodeByAlias($alias)
57
+ {
58
+ /** @var $config Mage_Api_Model_Config */
59
+ $config = Mage::getSingleton('api/config');
60
+ $aliases = $config->getAdapterAliases();
61
+
62
+ if (!isset($aliases[$alias])) {
63
+ return null;
64
+ }
65
+ $object = Mage::getModel($aliases[$alias][0]);
66
+ $method = $aliases[$alias][1];
67
+
68
+ if (!method_exists($object, $method)) {
69
+ Mage::throwException(Mage::helper('api')->__('Can not find webservice adapter.'));
70
+ }
71
+ return $object->$method();
72
+ }
73
+
74
+ /**
75
+ * Initialize server components
76
+ *
77
+ * @param Mage_Api_Controller_Action $controller
78
+ * @param string $adapter Adapter name
79
+ * @param string $handler Handler name
80
+ * @return Mage_Api_Model_Server
81
+ */
82
+ public function init(Mage_Api_Controller_Action $controller, $adapter = 'default', $handler = 'default')
83
+ {
84
+ $this->initialize($adapter, $handler);
85
+
86
+ $this->_adapter->setController($controller);
87
+
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * Initialize server components. Lightweight implementation of init() method
93
+ *
94
+ * @param string $adapterCode Adapter code
95
+ * @param string $handler OPTIONAL Handler name (if not specified, it will be found from config)
96
+ * @return Mage_Api_Model_Server
97
+ */
98
+ public function initialize($adapterCode, $handler = null)
99
  {
100
+ /** @var $helper Mage_Api_Model_Config */
101
+ $helper = Mage::getSingleton('api/config');
102
+ $adapters = $helper->getActiveAdapters();
103
+
104
+ if (isset($adapters[$adapterCode])) {
105
+ /** @var $adapterModel Mage_Api_Model_Server_Adapter_Interface */
106
+ $adapterModel = Mage::getModel((string) $adapters[$adapterCode]->model);
107
+
108
  if (!($adapterModel instanceof Mage_Api_Model_Server_Adapter_Interface)) {
109
  Mage::throwException(Mage::helper('api')->__('Invalid webservice adapter specified.'));
110
  }
 
111
  $this->_adapter = $adapterModel;
112
+ $this->_api = $adapterCode;
113
+
114
+ // get handler code from config if no handler passed as argument
115
+ if (null === $handler && !empty($adapters[$adapterCode]->handler)) {
116
+ $handler = (string) $adapters[$adapterCode]->handler;
117
+ }
118
+ $handlers = $helper->getHandlers();
119
 
120
  if (!isset($handlers->$handler)) {
121
  Mage::throwException(Mage::helper('api')->__('Invalid webservice handler specified.'));
122
  }
 
123
  $handlerClassName = Mage::getConfig()->getModelClassName((string) $handlers->$handler->model);
124
+
125
  $this->_adapter->setHandler($handlerClassName);
126
  } else {
127
  Mage::throwException(Mage::helper('api')->__('Invalid webservice adapter specified.'));
128
  }
 
129
  return $this;
130
  }
131
 
150
  /**
151
  * Retrieve web service adapter
152
  *
153
+ * @return Mage_Api_Model_Server_Adapter_Interface
154
  */
155
  public function getAdapter()
156
  {
app/code/core/Mage/Api/Model/Server/Adapter/Interface.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Server/Adapter/Soap.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -64,7 +64,7 @@ class Mage_Api_Model_Server_Adapter_Soap
64
  return $this->getData('handler');
65
  }
66
 
67
- /**
68
  * Set webservice api controller
69
  *
70
  * @param Mage_Api_Controller_Action $controller
@@ -77,13 +77,22 @@ class Mage_Api_Model_Server_Adapter_Soap
77
  }
78
 
79
  /**
80
- * Retrive webservice api controller
81
  *
82
- * @return Mage_Api_Controller_Action
83
  */
84
  public function getController()
85
  {
86
- return $this->getData('controller');
 
 
 
 
 
 
 
 
 
87
  }
88
 
89
  /**
@@ -94,12 +103,11 @@ class Mage_Api_Model_Server_Adapter_Soap
94
  */
95
  public function run()
96
  {
97
-
98
  $apiConfigCharset = Mage::getStoreConfig("api/config/charset");
99
 
100
  if ($this->getController()->getRequest()->getParam('wsdl') !== null) {
101
  // Generating wsdl content from template
102
- $io = new Varien_Io_File();
103
  $io->open(array('path'=>Mage::getModuleDir('etc', 'Mage_Api')));
104
 
105
  $wsdlContent = $io->read('wsdl.xml');
@@ -112,14 +120,11 @@ class Mage_Api_Model_Server_Adapter_Soap
112
  unset($queryParams['wsdl']);
113
  }
114
 
115
- $wsdlConfig->setUrl(
116
- htmlspecialchars(Mage::getUrl('*/*/*', array('_query'=>$queryParams) ))
117
- );
118
  $wsdlConfig->setName('Magento');
119
  $wsdlConfig->setHandler($this->getHandler());
120
 
121
- $template->setVariables(array('wsdl'=>$wsdlConfig));
122
-
123
 
124
  $this->getController()->getResponse()
125
  ->clearHeaders()
@@ -179,9 +184,9 @@ class Mage_Api_Model_Server_Adapter_Soap
179
  }
180
 
181
  /**
182
- * Check whether Soap extension is loaded
183
  *
184
- * @return boolean
185
  */
186
  protected function _extensionLoaded()
187
  {
@@ -197,16 +202,18 @@ class Mage_Api_Model_Server_Adapter_Soap
197
  protected function getWsdlUrl($params = null, $withAuth = true)
198
  {
199
  $urlModel = Mage::getModel('core/url')
200
- ->setUseSession(false);
201
 
202
- $wsdlUrl = ($params !== null)? $urlModel->getUrl('*/*/*', $params) : $urlModel->getUrl('*/*/*');
 
 
203
 
204
  if( $withAuth ) {
205
  $phpAuthUser = $this->getController()->getRequest()->getServer('PHP_AUTH_USER', false);
206
  $phpAuthPw = $this->getController()->getRequest()->getServer('PHP_AUTH_PW', false);
207
 
208
  if ($phpAuthUser && $phpAuthPw) {
209
- $wsdlUrl = sprintf("http://%s:%s@%s", $phpAuthUser, $phpAuthPw, str_replace('http://', '', $wsdlUrl ) );
210
  }
211
  }
212
 
@@ -222,21 +229,31 @@ class Mage_Api_Model_Server_Adapter_Soap
222
  protected function _instantiateServer()
223
  {
224
  $apiConfigCharset = Mage::getStoreConfig('api/config/charset');
225
- ini_set('soap.wsdl_cache_enabled', '0');
 
 
 
 
 
 
 
226
  $tries = 0;
227
  do {
228
  $retry = false;
229
  try {
230
- $this->_soap = new Zend_Soap_Server($this->getWsdlUrl(array("wsdl" => 1)), array('encoding' => $apiConfigCharset));
 
231
  } catch (SoapFault $e) {
232
- if (false !== strpos($e->getMessage(), "can't import schema from 'http://schemas.xmlsoap.org/soap/encoding/'")) {
 
 
233
  $retry = true;
234
  sleep(1);
235
  } else {
236
  throw $e;
237
  }
238
  $tries++;
239
- }
240
  } while ($retry && $tries < 5);
241
  use_soap_error_handler(false);
242
  $this->_soap
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
64
  return $this->getData('handler');
65
  }
66
 
67
+ /**
68
  * Set webservice api controller
69
  *
70
  * @param Mage_Api_Controller_Action $controller
77
  }
78
 
79
  /**
80
+ * Retrive webservice api controller. If no controller have been set - emulate it by the use of Varien_Object
81
  *
82
+ * @return Mage_Api_Controller_Action|Varien_Object
83
  */
84
  public function getController()
85
  {
86
+ $controller = $this->getData('controller');
87
+
88
+ if (null === $controller) {
89
+ $controller = new Varien_Object(
90
+ array('request' => Mage::app()->getRequest(), 'response' => Mage::app()->getResponse())
91
+ );
92
+
93
+ $this->setData('controller', $controller);
94
+ }
95
+ return $controller;
96
  }
97
 
98
  /**
103
  */
104
  public function run()
105
  {
 
106
  $apiConfigCharset = Mage::getStoreConfig("api/config/charset");
107
 
108
  if ($this->getController()->getRequest()->getParam('wsdl') !== null) {
109
  // Generating wsdl content from template
110
+ $io = new Varien_Io_File();
111
  $io->open(array('path'=>Mage::getModuleDir('etc', 'Mage_Api')));
112
 
113
  $wsdlContent = $io->read('wsdl.xml');
120
  unset($queryParams['wsdl']);
121
  }
122
 
123
+ $wsdlConfig->setUrl(htmlspecialchars(Mage::getUrl('*/*/*', array('_query'=>$queryParams))));
 
 
124
  $wsdlConfig->setName('Magento');
125
  $wsdlConfig->setHandler($this->getHandler());
126
 
127
+ $template->setVariables(array('wsdl' => $wsdlConfig));
 
128
 
129
  $this->getController()->getResponse()
130
  ->clearHeaders()
184
  }
185
 
186
  /**
187
+ * Check whether Soap extension is loaded
188
  *
189
+ * @return boolean
190
  */
191
  protected function _extensionLoaded()
192
  {
202
  protected function getWsdlUrl($params = null, $withAuth = true)
203
  {
204
  $urlModel = Mage::getModel('core/url')
205
+ ->setUseSession(false);
206
 
207
+ $wsdlUrl = $params !== null
208
+ ? $urlModel->getUrl('*/*/*', array('_current' => true, '_query' => $params))
209
+ : $urlModel->getUrl('*/*/*');
210
 
211
  if( $withAuth ) {
212
  $phpAuthUser = $this->getController()->getRequest()->getServer('PHP_AUTH_USER', false);
213
  $phpAuthPw = $this->getController()->getRequest()->getServer('PHP_AUTH_PW', false);
214
 
215
  if ($phpAuthUser && $phpAuthPw) {
216
+ $wsdlUrl = sprintf("http://%s:%s@%s", $phpAuthUser, $phpAuthPw, str_replace('http://', '', $wsdlUrl ));
217
  }
218
  }
219
 
229
  protected function _instantiateServer()
230
  {
231
  $apiConfigCharset = Mage::getStoreConfig('api/config/charset');
232
+ $wsdlCacheEnabled = (bool) Mage::getStoreConfig('api/config/wsdl_cache_enabled');
233
+
234
+ if ($wsdlCacheEnabled) {
235
+ ini_set('soap.wsdl_cache_enabled', '1');
236
+ } else {
237
+ ini_set('soap.wsdl_cache_enabled', '0');
238
+ }
239
+
240
  $tries = 0;
241
  do {
242
  $retry = false;
243
  try {
244
+ $this->_soap = new Zend_Soap_Server($this->getWsdlUrl(array("wsdl" => 1)),
245
+ array('encoding' => $apiConfigCharset));
246
  } catch (SoapFault $e) {
247
+ if (false !== strpos($e->getMessage(),
248
+ "can't import schema from 'http://schemas.xmlsoap.org/soap/encoding/'")
249
+ ) {
250
  $retry = true;
251
  sleep(1);
252
  } else {
253
  throw $e;
254
  }
255
  $tries++;
256
+ }
257
  } while ($retry && $tries < 5);
258
  use_soap_error_handler(false);
259
  $this->_soap
app/code/core/Mage/Api/Model/Server/Adapter/Xmlrpc.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -77,25 +77,33 @@ class Mage_Api_Model_Server_Adapter_Xmlrpc
77
  }
78
 
79
  /**
80
- * Retrive webservice api controller
81
  *
82
- * @return Mage_Api_Controller_Action
83
  */
84
  public function getController()
85
  {
86
- return $this->getData('controller');
 
 
 
 
 
 
 
 
 
87
  }
88
 
89
  /**
90
  * Run webservice
91
  *
92
- * @param Mage_Api_Controller_Action $controller
93
  * @return Mage_Api_Model_Server_Adapter_Xmlrpc
94
  */
95
  public function run()
96
  {
97
  $apiConfigCharset = Mage::getStoreConfig("api/config/charset");
98
-
99
  $this->_xmlRpc = new Zend_XmlRpc_Server();
100
  $this->_xmlRpc->setEncoding($apiConfigCharset)
101
  ->setClass($this->getHandler());
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
77
  }
78
 
79
  /**
80
+ * Retrive webservice api controller. If no controller have been set - emulate it by the use of Varien_Object
81
  *
82
+ * @return Mage_Api_Controller_Action|Varien_Object
83
  */
84
  public function getController()
85
  {
86
+ $controller = $this->getData('controller');
87
+
88
+ if (null === $controller) {
89
+ $controller = new Varien_Object(
90
+ array('request' => Mage::app()->getRequest(), 'response' => Mage::app()->getResponse())
91
+ );
92
+
93
+ $this->setData('controller', $controller);
94
+ }
95
+ return $controller;
96
  }
97
 
98
  /**
99
  * Run webservice
100
  *
 
101
  * @return Mage_Api_Model_Server_Adapter_Xmlrpc
102
  */
103
  public function run()
104
  {
105
  $apiConfigCharset = Mage::getStoreConfig("api/config/charset");
106
+
107
  $this->_xmlRpc = new Zend_XmlRpc_Server();
108
  $this->_xmlRpc->setEncoding($apiConfigCharset)
109
  ->setClass($this->getHandler());
app/code/core/Mage/Api/Model/Server/Handler.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Server/Handler/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -110,7 +110,7 @@ abstract class Mage_Api_Model_Server_Handler_Abstract
110
  /**
111
  * Check session expiration
112
  *
113
- * @return boolean
114
  */
115
  protected function _isSessionExpired ()
116
  {
@@ -210,10 +210,14 @@ abstract class Mage_Api_Model_Server_Handler_Abstract
210
  * @param string $apiKey
211
  * @return string
212
  */
213
- public function login($username, $apiKey)
214
  {
215
- $this->_startSession();
 
 
 
216
  try {
 
217
  $this->_getSession()->login($username, $apiKey);
218
  } catch (Exception $e) {
219
  return $this->_fault('access_denied');
@@ -225,7 +229,7 @@ abstract class Mage_Api_Model_Server_Handler_Abstract
225
  * Call resource functionality
226
  *
227
  * @param string $sessionId
228
- * @param string $resourcePath
229
  * @param array $args
230
  * @return mixed
231
  */
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
110
  /**
111
  * Check session expiration
112
  *
113
+ * @return boolean
114
  */
115
  protected function _isSessionExpired ()
116
  {
210
  * @param string $apiKey
211
  * @return string
212
  */
213
+ public function login($username, $apiKey = null)
214
  {
215
+ if (empty($username) || empty($apiKey)) {
216
+ return $this->_fault('invalid_request_param');
217
+ }
218
+
219
  try {
220
+ $this->_startSession();
221
  $this->_getSession()->login($username, $apiKey);
222
  } catch (Exception $e) {
223
  return $this->_fault('access_denied');
229
  * Call resource functionality
230
  *
231
  * @param string $sessionId
232
+ * @param string $apiPath
233
  * @param array $args
234
  * @return mixed
235
  */
app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Server/V2/Handler.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -77,21 +77,17 @@ class Mage_Api_Model_Server_WSI_Adapter_Soap extends Mage_Api_Model_Server_Adapt
77
  ->clearHeaders()
78
  ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
79
  ->setBody(
80
- preg_replace(
81
- '/(\>\<)/i',
82
- ">\n<",
83
  str_replace(
84
- '<soap:operation soapAction=""></soap:operation>',
85
- "<soap:operation soapAction=\"\" />\n",
86
- str_replace(
87
- '<soap:body use="literal"></soap:body>',
88
- "<soap:body use=\"literal\" />\n",
89
- preg_replace(
90
- '/<\?xml version="([^\"]+)"([^\>]+)>/i',
91
- '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>',
92
- $this->_soap->handle()
93
- )
94
- )
95
  )
96
  )
97
  );
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
77
  ->clearHeaders()
78
  ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
79
  ->setBody(
80
+ str_replace(
81
+ '<soap:operation soapAction=""></soap:operation>',
82
+ "<soap:operation soapAction=\"\" />\n",
83
  str_replace(
84
+ '<soap:body use="literal"></soap:body>',
85
+ "<soap:body use=\"literal\" />\n",
86
+ preg_replace(
87
+ '/<\?xml version="([^\"]+)"([^\>]+)>/i',
88
+ '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>',
89
+ $this->_soap->handle()
90
+ )
 
 
 
 
91
  )
92
  )
93
  );
app/code/core/Mage/Api/Model/Server/Wsi/Handler.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -91,11 +91,8 @@ class Mage_Api_Model_Server_WSI_Handler extends Mage_Api_Model_Server_Handler_Ab
91
  * @param string $apiKey
92
  * @return string
93
  */
94
- public function login($username, $apiKey=null)
95
  {
96
-
97
- /** @todo implement WS-I support check */
98
- //
99
  if (is_object($username)) {
100
  $apiKey = $username->apiKey;
101
  $username = $username->username;
@@ -110,7 +107,7 @@ class Mage_Api_Model_Server_WSI_Handler extends Mage_Api_Model_Server_Handler_Ab
110
  * Return called class and method names
111
  *
112
  * @param String $apiPath
113
- * @return Array
114
  */
115
  protected function _getResourceName($apiPath){
116
 
@@ -139,7 +136,7 @@ class Mage_Api_Model_Server_WSI_Handler extends Mage_Api_Model_Server_Handler_Ab
139
 
140
  /**
141
  * Return an array of parameters for the callable method.
142
- *
143
  * @param String $modelName
144
  * @param String $methodName
145
  * @return Array of ReflectionParameter
@@ -171,7 +168,7 @@ class Mage_Api_Model_Server_WSI_Handler extends Mage_Api_Model_Server_Handler_Ab
171
  if($parameter->isOptional()){
172
  $callArgs[$pName] = $parameter->getDefaultValue();
173
  } else {
174
- Mage::logException(new Exception("Required parameter \"$pName\" is missing.", 0, null));
175
  $this->_fault('invalid_request_param');
176
  }
177
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
91
  * @param string $apiKey
92
  * @return string
93
  */
94
+ public function login($username, $apiKey = null)
95
  {
 
 
 
96
  if (is_object($username)) {
97
  $apiKey = $username->apiKey;
98
  $username = $username->username;
107
  * Return called class and method names
108
  *
109
  * @param String $apiPath
110
+ * @return Array
111
  */
112
  protected function _getResourceName($apiPath){
113
 
136
 
137
  /**
138
  * Return an array of parameters for the callable method.
139
+ *
140
  * @param String $modelName
141
  * @param String $methodName
142
  * @return Array of ReflectionParameter
168
  if($parameter->isOptional()){
169
  $callArgs[$pName] = $parameter->getDefaultValue();
170
  } else {
171
+ Mage::logException(new Exception("Required parameter \"$pName\" is missing.", 0));
172
  $this->_fault('invalid_request_param');
173
  }
174
  }
app/code/core/Mage/Api/Model/Session.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -39,7 +39,7 @@ class Mage_Api_Model_Session extends Mage_Core_Model_Session_Abstract
39
  public function start($sessionName=null)
40
  {
41
  // parent::start($sessionName=null);
42
- $this->_currentSessId = md5(time() . $sessionName);
43
  $this->sessionIds[] = $this->getSessionId();
44
  return $this;
45
  }
@@ -83,10 +83,6 @@ class Mage_Api_Model_Session extends Mage_Core_Model_Session_Abstract
83
 
84
  public function login($username, $apiKey)
85
  {
86
- if (empty($username) || empty($apiKey)) {
87
- return;
88
- }
89
-
90
  $user = Mage::getModel('api/user')
91
  ->setSessid($this->getSessionId())
92
  ->login($username, $apiKey);
@@ -157,7 +153,7 @@ class Mage_Api_Model_Session extends Mage_Core_Model_Session_Abstract
157
  /**
158
  * Check session expiration
159
  *
160
- * @return boolean
161
  */
162
  public function isSessionExpired ($user)
163
  {
@@ -187,7 +183,7 @@ class Mage_Api_Model_Session extends Mage_Core_Model_Session_Abstract
187
  * Renew user by session ID if session not expired
188
  *
189
  * @param string $sessId
190
- * @return boolean
191
  */
192
  protected function _renewBySessId ($sessId)
193
  {
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
39
  public function start($sessionName=null)
40
  {
41
  // parent::start($sessionName=null);
42
+ $this->_currentSessId = md5(time() . uniqid('', true) . $sessionName);
43
  $this->sessionIds[] = $this->getSessionId();
44
  return $this;
45
  }
83
 
84
  public function login($username, $apiKey)
85
  {
 
 
 
 
86
  $user = Mage::getModel('api/user')
87
  ->setSessid($this->getSessionId())
88
  ->login($username, $apiKey);
153
  /**
154
  * Check session expiration
155
  *
156
+ * @return boolean
157
  */
158
  public function isSessionExpired ($user)
159
  {
183
  * Renew user by session ID if session not expired
184
  *
185
  * @param string $sessId
186
+ * @return boolean
187
  */
188
  protected function _renewBySessId ($sessId)
189
  {
app/code/core/Mage/Api/Model/User.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -56,6 +56,13 @@
56
  */
57
  class Mage_Api_Model_User extends Mage_Core_Model_Abstract
58
  {
 
 
 
 
 
 
 
59
  protected function _construct()
60
  {
61
  $this->_init('api/user');
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
56
  */
57
  class Mage_Api_Model_User extends Mage_Core_Model_Abstract
58
  {
59
+ /**
60
+ * Prefix of model events names
61
+ *
62
+ * @var string
63
+ */
64
+ protected $_eventPrefix = 'api_user';
65
+
66
  protected function _construct()
67
  {
68
  $this->_init('api/user');
app/code/core/Mage/Api/Model/Wsdl/Config.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/Model/Wsdl/Config/Base.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -45,6 +45,18 @@ class Mage_Api_Model_Wsdl_Config_Base extends Varien_Simplexml_Config
45
  public function __construct($sourceData=null)
46
  {
47
  $this->_elementClass = 'Mage_Api_Model_Wsdl_Config_Element';
 
 
 
 
 
 
 
 
 
 
 
 
48
  parent::__construct($sourceData);
49
  }
50
 
@@ -78,20 +90,14 @@ class Mage_Api_Model_Wsdl_Config_Base extends Varien_Simplexml_Config
78
  */
79
  public function processFileData($text)
80
  {
 
81
  $template = Mage::getModel('core/email_template_filter');
82
 
83
- if (null === $this->_wsdlVariables) {
84
- $this->_wsdlVariables = new Varien_Object();
85
- $this->_wsdlVariables->setUrl(Mage::getUrl('*/*/*'));
86
- $this->_wsdlVariables->setName('Magento');
87
- $this->_wsdlVariables->setHandler($this->getHandler());
88
- }
89
 
90
  $template->setVariables(array('wsdl'=>$this->_wsdlVariables));
91
 
92
- $text = $template->filter($text);
93
-
94
- return $text;
95
  }
96
 
97
  public function addLoadedFile($file)
@@ -113,4 +119,18 @@ class Mage_Api_Model_Wsdl_Config_Base extends Varien_Simplexml_Config
113
  }
114
  return $this;
115
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
45
  public function __construct($sourceData=null)
46
  {
47
  $this->_elementClass = 'Mage_Api_Model_Wsdl_Config_Element';
48
+
49
+ // remove wsdl parameter from query
50
+ $queryParams = Mage::app()->getRequest()->getQuery();
51
+ unset($queryParams['wsdl']);
52
+
53
+ // set up default WSDL template variables
54
+ $this->_wsdlVariables = new Varien_Object(
55
+ array(
56
+ 'name' => 'Magento',
57
+ 'url' => htmlspecialchars(Mage::getUrl('*/*/*', array('_query' => $queryParams)))
58
+ )
59
+ );
60
  parent::__construct($sourceData);
61
  }
62
 
90
  */
91
  public function processFileData($text)
92
  {
93
+ /** @var $template Mage_Core_Model_Email_Template_Filter */
94
  $template = Mage::getModel('core/email_template_filter');
95
 
96
+ $this->_wsdlVariables->setHandler($this->getHandler());
 
 
 
 
 
97
 
98
  $template->setVariables(array('wsdl'=>$this->_wsdlVariables));
99
 
100
+ return $template->filter($text);
 
 
101
  }
102
 
103
  public function addLoadedFile($file)
119
  }
120
  return $this;
121
  }
122
+
123
+ /**
124
+ * Set variable to be used in WSDL template processing
125
+ *
126
+ * @param string $key Varible key
127
+ * @param string $value Variable value
128
+ * @return Mage_Api_Model_Wsdl_Config_Base
129
+ */
130
+ public function setWsdlVariable($key, $value)
131
+ {
132
+ $this->_wsdlVariables->setData($key, $value);
133
+
134
+ return $this;
135
+ }
136
  }
app/code/core/Mage/Api/Model/Wsdl/Config/Element.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/controllers/IndexController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/controllers/SoapController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/controllers/V2/SoapController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/controllers/XmlrpcController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/etc/adminhtml.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
@@ -37,11 +37,11 @@
37
  <sort_order>0</sort_order>
38
  <children>
39
  <users translate="title">
40
- <title>Users</title>
41
  <sort_order>10</sort_order>
42
  </users>
43
  <roles translate="title">
44
- <title>Roles</title>
45
  <sort_order>20</sort_order>
46
  </roles>
47
  </children>
@@ -67,12 +67,14 @@
67
  <sort_order>25</sort_order>
68
  <children>
69
  <users translate="title">
70
- <title>Users</title>
71
  <action>adminhtml/api_user</action>
 
72
  </users>
73
  <roles translate="title">
74
- <title>Roles</title>
75
  <action>adminhtml/api_role</action>
 
76
  </roles>
77
  </children>
78
  </api>
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
37
  <sort_order>0</sort_order>
38
  <children>
39
  <users translate="title">
40
+ <title>SOAP/XML-RPC - Users</title>
41
  <sort_order>10</sort_order>
42
  </users>
43
  <roles translate="title">
44
+ <title>SOAP/XML-RPC - Roles</title>
45
  <sort_order>20</sort_order>
46
  </roles>
47
  </children>
67
  <sort_order>25</sort_order>
68
  <children>
69
  <users translate="title">
70
+ <title>SOAP/XML-RPC - Users</title>
71
  <action>adminhtml/api_user</action>
72
+ <sort_order>10</sort_order>
73
  </users>
74
  <roles translate="title">
75
+ <title>SOAP/XML-RPC - Roles</title>
76
  <action>adminhtml/api_role</action>
77
+ <sort_order>20</sort_order>
78
  </roles>
79
  </children>
80
  </api>
app/code/core/Mage/Api/etc/api.xml CHANGED
@@ -21,12 +21,18 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <api>
 
 
 
 
 
 
30
  <adapters>
31
  <soap>
32
  <model>api/server_adapter_soap</model>
@@ -139,5 +145,148 @@
139
  </default>
140
  </privilegeSets>
141
  </acl>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  </api>
143
  </config>
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <api>
30
+ <adapter_aliases>
31
+ <v2_soap>
32
+ <suggest_class>Mage_Api_Helper_Data</suggest_class>
33
+ <suggest_method>getV2AdapterCode</suggest_method>
34
+ </v2_soap>
35
+ </adapter_aliases>
36
  <adapters>
37
  <soap>
38
  <model>api/server_adapter_soap</model>
145
  </default>
146
  </privilegeSets>
147
  </acl>
148
+
149
+ <domain_messages>
150
+ <!-- module name -->
151
+ <core>
152
+ <!-- 200 -->
153
+ <success>
154
+ <ok>Request is executed.</ok>
155
+ </success>
156
+ <!-- 201 -->
157
+ <created>
158
+ <created>Request is executed. Created new resource.</created>
159
+ </created>
160
+ <!-- 202 -->
161
+ <processing>
162
+ <processing>Request is carried out.</processing>
163
+ </processing>
164
+ <!-- 400 -->
165
+ <validation>
166
+ <invalid_param>Parameter "%s" is not valid.</invalid_param>
167
+ </validation>
168
+ <!-- 400 -->
169
+ <request_error>
170
+ <!-- Client sent wrong API version -->
171
+ <invalid_api_version>API version "%s" not found.</invalid_api_version>
172
+ </request_error>
173
+ <!-- 401 -->
174
+ <authentication>
175
+ <protect_resource>You must provide an authenticated user for this method.</protect_resource>
176
+ <invalid_token>Token in request is not valid.</invalid_token>
177
+ </authentication>
178
+ <!-- 403 -->
179
+ <forbidden>
180
+ <api_key_invalid>Invalid API key</api_key_invalid>
181
+ </forbidden>
182
+ <!-- 404 -->
183
+ <not_found>
184
+ <item_not_found>Requested item %s not found.</item_not_found>
185
+ <resource_not_found>Requested resource %s not found.</resource_not_found>
186
+ </not_found>
187
+ <!-- 405 -->
188
+ <not_allowed>
189
+ <method_not_allowed>Method "%s" is not allowed.</method_not_allowed>
190
+ </not_allowed>
191
+ <!-- 406 -->
192
+ <not_acceptable>
193
+ <api_version_required>Api version is required.</api_version_required>
194
+ </not_acceptable>
195
+ <!-- 410 -->
196
+ <gone>
197
+ <!-- Message when client trying sent the API version which no longer maintained -->
198
+ <api_deprecated>API version "%s" is deprecated.</api_deprecated>
199
+ <!-- Message when client trying request the resource which no longer maintained -->
200
+ <deprecated>Resource "%s" is deprecated.</deprecated>
201
+ </gone>
202
+
203
+ <!-- 500 -->
204
+ <internal_error>
205
+ <!-- Code error message not found or not exist -->
206
+ <unknown_error>There was unknown error while processing your request.</unknown_error>
207
+ <!-- Internal error when server catch some exception or language error -->
208
+ <internal_error>There was internal error while processing your request.</internal_error>
209
+ <!-- Developer mode message about error -->
210
+ <code_error>Server has internal error. %s: %s</code_error>
211
+ </internal_error>
212
+ <!-- 501 -->
213
+ <not_implemented>
214
+ <resource_not_implemented>This resource is not implemented so far.</resource_not_implemented>
215
+ <method_not_implemented>This method is not implemented so far.</method_not_implemented>
216
+ </not_implemented>
217
+ </core>
218
+ </domain_messages>
219
+
220
+ <!-- Message Domains with relation to HTTP codes -->
221
+ <!-- The priority for domains is the HTTP code -->
222
+ <domain_codes>
223
+ <!-- All success messages except "entry_created", "processing" -->
224
+ <success>
225
+ <http_code>200</http_code>
226
+ <type>notification</type>
227
+ </success>
228
+ <!-- Messages when created new entry -->
229
+ <created>
230
+ <http_code>201</http_code>
231
+ <type>notification</type>
232
+ </created>
233
+ <!-- Processing messages -->
234
+ <processing>
235
+ <http_code>202</http_code>
236
+ <type>notification</type>
237
+ </processing>
238
+
239
+ <!-- Validation messages -->
240
+ <validation>
241
+ <http_code>400</http_code>
242
+ <type>error</type>
243
+ </validation>
244
+ <!-- Messages when the request from a client has an error -->
245
+ <request_error>
246
+ <http_code>400</http_code>
247
+ <type>error</type>
248
+ </request_error>
249
+ <!-- Authentication error messages -->
250
+ <authentication>
251
+ <http_code>401</http_code>
252
+ <type>error</type>
253
+ </authentication>
254
+ <!-- Messages when post request is accepted but cannot performed -->
255
+ <forbidden>
256
+ <http_code>403</http_code>
257
+ <type>error</type>
258
+ </forbidden>
259
+ <!-- Messages when some data not found -->
260
+ <not_found>
261
+ <http_code>404</http_code>
262
+ <type>error</type>
263
+ </not_found>
264
+ <!-- Messages when some method is not allowed -->
265
+ <not_allowed>
266
+ <http_code>405</http_code>
267
+ <type>error</type>
268
+ </not_allowed>
269
+ <!-- Messages when some is not acceptable -->
270
+ <not_acceptable>
271
+ <http_code>406</http_code>
272
+ <type>error</type>
273
+ </not_acceptable>
274
+ <!-- Messages when some resource are gone -->
275
+ <gone>
276
+ <http_code>410</http_code>
277
+ <type>error</type>
278
+ </gone>
279
+ <!-- All messages related with internal errors -->
280
+ <internal_error>
281
+ <http_code>500</http_code>
282
+ <type>error</type>
283
+ </internal_error>
284
+ <!-- Messages when something not implemented -->
285
+ <not_implemented>
286
+ <http_code>501</http_code>
287
+ <type>error</type>
288
+ </not_implemented>
289
+ </domain_codes>
290
+
291
  </api>
292
  </config>
app/code/core/Mage/Api/etc/config.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
@@ -123,6 +123,7 @@
123
  <charset>UTF-8</charset>
124
  <session_timeout>3600</session_timeout>
125
  <compliance_wsi>0</compliance_wsi>
 
126
  </config>
127
  </api>
128
  </default>
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
123
  <charset>UTF-8</charset>
124
  <session_timeout>3600</session_timeout>
125
  <compliance_wsi>0</compliance_wsi>
126
+ <wsdl_cache_enabled>0</wsdl_cache_enabled>
127
  </config>
128
  </api>
129
  </default>
app/code/core/Mage/Api/etc/system.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
@@ -70,6 +70,16 @@
70
  <show_in_website>1</show_in_website>
71
  <show_in_store>1</show_in_store>
72
  </compliance_wsi>
 
 
 
 
 
 
 
 
 
 
73
  </fields>
74
  </config>
75
  </groups>
21
  *
22
  * @category Mage
23
  * @package Mage_Api
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
70
  <show_in_website>1</show_in_website>
71
  <show_in_store>1</show_in_store>
72
  </compliance_wsi>
73
+ <wsdl_cache_enabled translate="label">
74
+ <label>Enable WSDL Cache</label>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>adminhtml/system_config_source_yesno</source_model>
77
+ <backend_model>adminhtml/system_config_backend_store</backend_model>
78
+ <sort_order>40</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>1</show_in_store>
82
+ </wsdl_cache_enabled>
83
  </fields>
84
  </config>
85
  </groups>
app/code/core/Mage/Api/etc/wsdl2.xml CHANGED
@@ -18,6 +18,25 @@
18
  </restriction>
19
  </complexContent>
20
  </complexType>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  <complexType name="filters">
22
  <all>
23
  <element name="filter" type="typens:associativeArray" minOccurs="0" />
@@ -34,7 +53,7 @@
34
  <complexType name="complexFilter">
35
  <all>
36
  <element name="key" type="xsd:string" />
37
- <element name="value" type="typens:associativeEntity" />
38
  </all>
39
  </complexType>
40
  <complexType name="ArrayOfString">
18
  </restriction>
19
  </complexContent>
20
  </complexType>
21
+ <complexType name="associativeMultiEntity">
22
+ <all>
23
+ <element name="key" type="xsd:string" />
24
+ <element name="value" type="typens:ArrayOfString" />
25
+ </all>
26
+ </complexType>
27
+ <complexType name="associativeMultiArray">
28
+ <complexContent>
29
+ <restriction base="soapenc:Array">
30
+ <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:associativeMultiEntity[]" />
31
+ </restriction>
32
+ </complexContent>
33
+ </complexType>
34
+ <complexType name="associativeAnyTypeEntity">
35
+ <all>
36
+ <element name="key" type="xsd:string" />
37
+ <element name="value" type="typens:anyType" />
38
+ </all>
39
+ </complexType>
40
  <complexType name="filters">
41
  <all>
42
  <element name="filter" type="typens:associativeArray" minOccurs="0" />
53
  <complexType name="complexFilter">
54
  <all>
55
  <element name="key" type="xsd:string" />
56
+ <element name="value" type="typens:associativeAnyTypeEntity" />
57
  </all>
58
  </complexType>
59
  <complexType name="ArrayOfString">
app/code/core/Mage/Api/etc/wsi.xml CHANGED
@@ -33,7 +33,7 @@
33
  <xsd:complexType name="complexFilter">
34
  <xsd:sequence>
35
  <xsd:element name="key" type="xsd:string" />
36
- <xsd:element name="value" type="typens:associativeEntity" />
37
  </xsd:sequence>
38
  </xsd:complexType>
39
  <xsd:complexType name="complexFilterArray">
33
  <xsd:complexType name="complexFilter">
34
  <xsd:sequence>
35
  <xsd:element name="key" type="xsd:string" />
36
+ <xsd:element name="value" type="typens:associativeMultiEntity" />
37
  </xsd:sequence>
38
  </xsd:complexType>
39
  <xsd:complexType name="complexFilterArray">
app/code/core/Mage/Api/sql/api_setup/install-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/sql/api_setup/mysql4-install-0.7.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.7.0-0.7.1.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-0.8.0-0.8.1.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api/sql/api_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Api
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Api2/Block/Adminhtml/Attribute.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 attributes grid container block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container
35
+ {
36
+ /**
37
+ * Construct grid container
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+
43
+ $this->_blockGroup = 'api2';
44
+ $this->_controller = 'adminhtml_attribute';
45
+ $this->_headerText = $this->__('REST Attributes');
46
+ $this->_removeButton('add');
47
+ }
48
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Buttons.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Block for rendering buttons
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Attribute_Buttons extends Mage_Adminhtml_Block_Template
35
+ {
36
+ /**
37
+ * Construct
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+ $this->setTemplate('api2/attribute/buttons.phtml');
43
+ }
44
+
45
+ /**
46
+ * Prepare global layout
47
+ *
48
+ * @return Mage_Core_Block_Abstract
49
+ */
50
+ protected function _prepareLayout()
51
+ {
52
+ $buttons = array(
53
+ 'backButton' => array(
54
+ 'label' => $this->__('Back'),
55
+ 'onclick' => sprintf("window.location.href='%s';", $this->getUrl('*/*/')),
56
+ 'class' => 'back'
57
+ ),
58
+ 'saveButton' => array(
59
+ 'label' => $this->__('Save'),
60
+ 'onclick' => 'form.submit(); return false;',
61
+ 'class' => 'save'
62
+ ),
63
+ );
64
+
65
+ foreach ($buttons as $name => $data) {
66
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
67
+ $this->setChild($name, $button);
68
+ }
69
+
70
+ return parent::_prepareLayout();
71
+ }
72
+
73
+ /**
74
+ * Get back button HTML
75
+ *
76
+ * @return string
77
+ */
78
+ public function getBackButtonHtml()
79
+ {
80
+ return $this->getChildHtml('backButton');
81
+ }
82
+
83
+ /**
84
+ * Get reset button HTML
85
+ *
86
+ * @return string
87
+ */
88
+ public function getResetButtonHtml()
89
+ {
90
+ return $this->getChildHtml('resetButton');
91
+ }
92
+
93
+ /**
94
+ * Get save button HTML
95
+ *
96
+ * @return string
97
+ */
98
+ public function getSaveButtonHtml()
99
+ {
100
+ return $this->getChildHtml('saveButton');
101
+ }
102
+
103
+ /**
104
+ * Get block caption
105
+ *
106
+ * @return string
107
+ */
108
+ public function getCaption()
109
+ {
110
+ return $this->__('Edit');
111
+ }
112
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Edit.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Attribute Edit block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Attribute_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
35
+ {
36
+ /**
37
+ * Initialize edit form container
38
+ */
39
+ public function __construct()
40
+ {
41
+ $this->_objectId = 'id';
42
+ $this->_blockGroup = 'api2';
43
+ $this->_controller = 'adminhtml_attribute';
44
+
45
+ parent::__construct();
46
+
47
+ $this->_updateButton('save', 'label', $this->__('Save'))
48
+ ->_removeButton('delete');
49
+ }
50
+
51
+ /**
52
+ * Retrieve text for header element depending on loaded page
53
+ *
54
+ * @return string
55
+ */
56
+ public function getHeaderText()
57
+ {
58
+ $userTypes = Mage_Api2_Model_Auth_User::getUserTypes();
59
+ return $this->__('Edit attribute rules for %s Role', $userTypes[$this->getRequest()->getParam('type')]);
60
+ }
61
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Edit/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Attribute edit form block
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Api2
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_Api2_Block_Adminhtml_Attribute_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
36
+ {
37
+ /**
38
+ * Prepare form before rendering HTML
39
+ *
40
+ * @return Mage_Api2_Block_Adminhtml_Attribute_Edit_Form
41
+ */
42
+ protected function _prepareForm()
43
+ {
44
+ $form = new Varien_Data_Form(array(
45
+ 'id' => 'edit_form',
46
+ 'action' => $this->getData('action'),
47
+ 'method' => 'post'
48
+ ));
49
+
50
+
51
+ $form->setAction($this->getUrl('*/*/save', array('type' => $this->getRequest()->getParam('type'))))
52
+ ->setUseContainer(true);
53
+
54
+ $this->setForm($form);
55
+
56
+ return parent::_prepareForm();
57
+ }
58
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Grid.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 attributes grid block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Attribute_Grid extends Mage_Adminhtml_Block_Widget_Grid
35
+ {
36
+ /**
37
+ * Set grid ID
38
+ *
39
+ * @param array $attributes
40
+ */
41
+ public function __construct($attributes = array())
42
+ {
43
+ parent::__construct($attributes);
44
+ $this->setId('api2_attributes');
45
+ }
46
+
47
+ /**
48
+ * Collection object set up
49
+ */
50
+ protected function _prepareCollection()
51
+ {
52
+ $collection = new Varien_Data_Collection();
53
+
54
+ foreach (Mage_Api2_Model_Auth_User::getUserTypes() as $type => $label) {
55
+ $collection->addItem(
56
+ new Varien_Object(array('user_type_name' => $label, 'user_type_code' => $type))
57
+ );
58
+ }
59
+
60
+ $this->setCollection($collection);
61
+ }
62
+
63
+ /**
64
+ * Prepare grid columns
65
+ *
66
+ * @return Mage_Api2_Block_Adminhtml_Attribute_Grid
67
+ */
68
+ protected function _prepareColumns()
69
+ {
70
+ $this->addColumn('user_type_name', array(
71
+ 'header' => $this->__('User Type'),
72
+ 'index' => 'user_type_name'
73
+ ));
74
+
75
+ return parent::_prepareColumns();
76
+ }
77
+
78
+ /**
79
+ * Disable unnecessary functionality
80
+ *
81
+ * @return Mage_Api2_Block_Adminhtml_Attribute_Grid
82
+ */
83
+ public function _prepareLayout()
84
+ {
85
+ $this->setFilterVisibility(false);
86
+ $this->setPagerVisibility(false);
87
+
88
+ return $this;
89
+ }
90
+
91
+ /**
92
+ * Get row URL
93
+ *
94
+ * @param Varien_Object $row
95
+ * @return string|null
96
+ */
97
+ public function getRowUrl($row)
98
+ {
99
+ /** @var $session Mage_Admin_Model_Session */
100
+ $session = Mage::getSingleton('admin/session');
101
+ if ($session->isAllowed('system/api/attributes/edit')) {
102
+ return $this->getUrl('*/*/edit', array('type' => $row->getUserTypeCode()));
103
+ }
104
+
105
+ return null;
106
+ }
107
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Tab/Resource.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Block for rendering attributes tree list tab
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Model_Acl_Global_Role getRole()
34
+ * @method Mage_Api2_Block_Adminhtml_Attribute_Tab_Resource setRole(Mage_Api2_Model_Acl_Global_Role $role)
35
+ */
36
+ class Mage_Api2_Block_Adminhtml_Attribute_Tab_Resource extends Mage_Adminhtml_Block_Widget_Form
37
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
38
+ {
39
+ /**
40
+ * Tree model
41
+ *
42
+ * @var Mage_Api2_Model_Acl_Global_Rule_Tree
43
+ */
44
+ protected $_treeModel = false;
45
+
46
+ /**
47
+ * Constructor
48
+ */
49
+ public function __construct()
50
+ {
51
+ parent::__construct();
52
+
53
+ $this->setId('api2_attribute_section_resources')
54
+ ->setData('default_dir', Varien_Db_Select::SQL_ASC)
55
+ ->setData('default_sort', 'sort_order')
56
+ ->setData('title', $this->__('Attribute Rules Information'))
57
+ ->setData('use_ajax', true);
58
+
59
+ $this->_treeModel = Mage::getModel(
60
+ 'api2/acl_global_rule_tree',
61
+ array('type' => Mage_Api2_Model_Acl_Global_Rule_Tree::TYPE_ATTRIBUTE));
62
+
63
+ /** @var $permissions Mage_Api2_Model_Acl_Filter_Attribute_ResourcePermission */
64
+ $permissions = Mage::getModel('api2/acl_filter_attribute_resourcePermission');
65
+ $permissions->setFilterValue($this->getRequest()->getParam('type'));
66
+ $this->_treeModel->setResourcesPermissions($permissions->getResourcesPermissions())
67
+ ->setHasEntityOnlyAttributes($permissions->getHasEntityOnlyAttributes());
68
+ }
69
+
70
+ /**
71
+ * Get Json Representation of Resource Tree
72
+ *
73
+ * @return string
74
+ */
75
+ public function getResTreeJson()
76
+ {
77
+ /** @var $helper Mage_Core_Helper_Data */
78
+ $helper = Mage::helper('core');
79
+ return $helper->jsonEncode($this->_treeModel->getTreeResources());
80
+ }
81
+
82
+ /**
83
+ * Check if everything is allowed
84
+ *
85
+ * @return boolean
86
+ */
87
+ public function getEverythingAllowed()
88
+ {
89
+ return $this->_treeModel->getEverythingAllowed();
90
+ }
91
+
92
+ /**
93
+ * Check if tree has entity only attributes
94
+ *
95
+ * @return bool
96
+ */
97
+ public function hasEntityOnlyAttributes()
98
+ {
99
+ return $this->_treeModel->getHasEntityOnlyAttributes();
100
+ }
101
+
102
+ /**
103
+ * Get tab label
104
+ *
105
+ * @return string
106
+ */
107
+ public function getTabLabel()
108
+ {
109
+ return $this->__('ACL Attribute Rules');
110
+ }
111
+
112
+ /**
113
+ * Get tab title
114
+ *
115
+ * @return string
116
+ */
117
+ public function getTabTitle()
118
+ {
119
+ return $this->getTabLabel();
120
+ }
121
+
122
+ /**
123
+ * Whether tab is available
124
+ *
125
+ * @return bool
126
+ */
127
+ public function canShowTab()
128
+ {
129
+ return true;
130
+ }
131
+
132
+ /**
133
+ * Whether tab is hidden
134
+ *
135
+ * @return bool
136
+ */
137
+ public function isHidden()
138
+ {
139
+ return false;
140
+ }
141
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Attribute/Tabs.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Block tabs for attributes edit page
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Attribute_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
35
+ {
36
+ /**
37
+ * Constructor
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+
43
+ $this->setId('api2_attribute_section_main')
44
+ ->setDestElementId('edit_form')
45
+ ->setData('title', $this->__('ACL Attributes Information'));
46
+ }
47
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Permissions/User/Edit/Tab/Roles.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 role list for admin user permissions
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Permissions_User_Edit_Tab_Roles
35
+ extends Mage_Adminhtml_Block_Widget_Grid
36
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
37
+ {
38
+ /**
39
+ * Selected API2 roles for grid
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_selectedRoles;
44
+
45
+ /**
46
+ * Constructor
47
+ * Prepare grid parameters
48
+ */
49
+ public function __construct()
50
+ {
51
+ parent::__construct();
52
+
53
+ $this->setId('api2_roles_section')
54
+ ->setDefaultSort('sort_order')
55
+ ->setDefaultDir(Varien_Db_Select::SQL_ASC)
56
+ ->setTitle($this->__('REST Roles Information'))
57
+ ->setUseAjax(true);
58
+ }
59
+
60
+ /**
61
+ * Prepare grid collection object
62
+ *
63
+ * @return Mage_Api2_Block_Adminhtml_Permissions_User_Edit_Tab_Roles
64
+ */
65
+ protected function _prepareCollection()
66
+ {
67
+ /** @var $collection Mage_Api2_Model_Resource_Acl_Global_Role_Collection */
68
+ $collection = Mage::getResourceModel('api2/acl_global_role_collection');
69
+ $collection->addFieldToFilter('entity_id', array('nin' => Mage_Api2_Model_Acl_Global_Role::getSystemRoles()));
70
+
71
+ $this->setCollection($collection);
72
+
73
+ return parent::_prepareCollection();
74
+ }
75
+
76
+ /**
77
+ * Prepare grid columns
78
+ *
79
+ * @return Mage_Api2_Block_Adminhtml_Permissions_User_Edit_Tab_Roles
80
+ */
81
+ protected function _prepareColumns()
82
+ {
83
+ $this->addColumn('assigned_user_role', array(
84
+ 'header_css_class' => 'a-center',
85
+ 'header' => $this->__('Assigned'),
86
+ 'type' => 'radio',
87
+ 'html_name' => 'api2_roles[]',
88
+ 'values' => $this->_getSelectedRoles(),
89
+ 'align' => 'center',
90
+ 'index' => 'entity_id'
91
+ ));
92
+
93
+ $this->addColumn('role_name', array(
94
+ 'header' => $this->__('Role Name'),
95
+ 'index' => 'role_name'
96
+ ));
97
+
98
+ return parent::_prepareColumns();
99
+ }
100
+
101
+ /**
102
+ * Add custom column filter to collection
103
+ *
104
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
105
+ * @return Mage_Api2_Block_Adminhtml_Permissions_User_Edit_Tab_Roles
106
+ */
107
+ protected function _addColumnFilterToCollection($column)
108
+ {
109
+ if ($column->getId() == 'assigned_user_role') {
110
+ $userRoles = $this->_getSelectedRoles();
111
+ if ($column->getFilter()->getValue()) {
112
+ $this->getCollection()->addFieldToFilter('entity_id', array('in' => $userRoles));
113
+ } elseif (!empty($userRoles)) {
114
+ $this->getCollection()->addFieldToFilter('entity_id', array('nin' => $userRoles));
115
+ } else {
116
+ $this->getCollection();
117
+ }
118
+ } else {
119
+ parent::_addColumnFilterToCollection($column);
120
+ }
121
+
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Get selected API2 roles for grid
127
+ *
128
+ * @return array
129
+ */
130
+ protected function _getSelectedRoles()
131
+ {
132
+ if (null === $this->_selectedRoles) {
133
+ $userRoles = array();
134
+
135
+ /* @var $user Mage_Admin_Model_User */
136
+ $user = Mage::registry('permissions_user');
137
+ if ($user->getId()) {
138
+ /** @var $collection Mage_Api2_Model_Resource_Acl_Global_Role_Collection */
139
+ $collection = Mage::getResourceModel('api2/acl_global_role_collection');
140
+ $collection->addFilterByAdminId($user->getId());
141
+
142
+ $userRoles = $collection->getAllIds();
143
+ }
144
+
145
+ $this->_selectedRoles = $userRoles;
146
+ }
147
+
148
+ return $this->_selectedRoles;
149
+ }
150
+
151
+ /**
152
+ * Prepare label for tab
153
+ *
154
+ * @return string
155
+ */
156
+ public function getTabLabel()
157
+ {
158
+ return $this->__('REST Role');
159
+ }
160
+
161
+ /**
162
+ * Prepare title for tab
163
+ *
164
+ * @return string
165
+ */
166
+ public function getTabTitle()
167
+ {
168
+ return $this->__('REST Role');
169
+ }
170
+
171
+ /**
172
+ * Returns status flag about this tab can be shown or not
173
+ *
174
+ * @return true
175
+ */
176
+ public function canShowTab()
177
+ {
178
+ return true;
179
+ }
180
+
181
+ /**
182
+ * Returns status flag about this tab hidden or not
183
+ *
184
+ * @return true
185
+ */
186
+ public function isHidden()
187
+ {
188
+ return false;
189
+ }
190
+
191
+ /**
192
+ * Get controller action url for grid ajax actions
193
+ *
194
+ * @return string
195
+ */
196
+ public function getGridUrl()
197
+ {
198
+ return $this->getUrl(
199
+ '*/api2_role/rolesGrid',
200
+ array('user_id' => Mage::registry('permissions_user')->getUserId())
201
+ );
202
+ }
203
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Roles.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Roles grid container block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Roles extends Mage_Adminhtml_Block_Widget_Grid_Container
35
+ {
36
+ /**
37
+ * Construct grid container
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+
43
+ $this->_blockGroup = 'api2';
44
+ $this->_controller = 'adminhtml_roles';
45
+ $this->_headerText = Mage::helper('adminhtml')->__('REST Roles');
46
+
47
+ //check allow edit
48
+ /** @var $session Mage_Admin_Model_Session */
49
+ $session = Mage::getSingleton('admin/session');
50
+ if ($session->isAllowed('system/api/roles/add')) {
51
+ $this->_updateButton('add', 'label', $this->__('Add Admin Role'));
52
+ } else {
53
+ $this->_removeButton('add');
54
+ }
55
+ }
56
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Roles/Buttons.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Block for rendering buttons
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Block_Adminhtml_Roles_Buttons setRole(Mage_Api2_Model_Acl_Global_Role $role)
34
+ * @method Mage_Api2_Model_Acl_Global_Role getRole()
35
+ */
36
+ class Mage_Api2_Block_Adminhtml_Roles_Buttons extends Mage_Adminhtml_Block_Template
37
+ {
38
+ /**
39
+ * Construct
40
+ */
41
+ public function __construct()
42
+ {
43
+ parent::__construct();
44
+ $this->setTemplate('api2/role/buttons.phtml');
45
+ }
46
+
47
+ /**
48
+ * Preparing global layout
49
+ *
50
+ * @return Mage_Api2_Block_Adminhtml_Roles_Buttons
51
+ */
52
+ protected function _prepareLayout()
53
+ {
54
+ $buttons = array(
55
+ 'backButton' => array(
56
+ 'label' => Mage::helper('adminhtml')->__('Back'),
57
+ 'onclick' => sprintf("window.location.href='%s';", $this->getUrl('*/*/')),
58
+ 'class' => 'back'
59
+ ),
60
+ 'resetButton' => array(
61
+ 'label' => Mage::helper('adminhtml')->__('Reset'),
62
+ 'onclick' => 'window.location.reload()'
63
+ ),
64
+ 'saveButton' => array(
65
+ 'label' => Mage::helper('adminhtml')->__('Save Role'),
66
+ 'onclick' => 'roleForm.submit(); return false;',
67
+ 'class' => 'save'
68
+ ),
69
+ 'deleteButton' => array(
70
+ 'label' => Mage::helper('adminhtml')->__('Delete Role'),
71
+ 'onclick' => '', //roleId is not set at this moment, so we set script later
72
+ 'class' => 'delete'
73
+ ),
74
+ );
75
+
76
+ foreach ($buttons as $name=>$data) {
77
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
78
+ $this->setChild($name, $button);
79
+ }
80
+
81
+ return parent::_prepareLayout();
82
+ }
83
+
84
+ /**
85
+ * Get back button HTML
86
+ *
87
+ * @return string
88
+ */
89
+ public function getBackButtonHtml()
90
+ {
91
+ return $this->getChildHtml('backButton');
92
+ }
93
+
94
+ /**
95
+ * Get reset button HTML
96
+ *
97
+ * @return string
98
+ */
99
+ public function getResetButtonHtml()
100
+ {
101
+ return $this->getChildHtml('resetButton');
102
+ }
103
+
104
+ /**
105
+ * Get save button HTML
106
+ *
107
+ * @return string
108
+ */
109
+ public function getSaveButtonHtml()
110
+ {
111
+ return $this->getChildHtml('saveButton');
112
+ }
113
+
114
+ /**
115
+ * Get delete button HTML
116
+ *
117
+ * @return string
118
+ */
119
+ public function getDeleteButtonHtml()
120
+ {
121
+ if(!$this->getRole() || !$this->getRole()->getId()
122
+ || Mage_Api2_Model_Acl_Global_Role::isSystemRole($this->getRole())) {
123
+
124
+ return '';
125
+ }
126
+
127
+ $this->getChild('deleteButton')->setData('onclick', sprintf("deleteConfirm('%s', '%s')",
128
+ Mage::helper('adminhtml')->__('Are you sure you want to do this?'),
129
+ $this->getUrl('*/*/delete', array('id' => $this->getRole()->getId()))
130
+ ));
131
+
132
+ return $this->getChildHtml('deleteButton');
133
+ }
134
+
135
+ /**
136
+ * Get block caption
137
+ *
138
+ * @return string
139
+ */
140
+ public function getCaption()
141
+ {
142
+ return $this->getRole() && $this->getRole()->getId()
143
+ ? ($this->__('Edit Role') . " '{$this->escapeHtml($this->getRole()->getRoleName())}'")
144
+ : $this->__('Add New Role');
145
+ }
146
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Roles/Grid.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Roles grid block
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Block_Adminhtml_Roles_Grid extends Mage_Adminhtml_Block_Widget_Grid
35
+ {
36
+ /**
37
+ * Construct grid block
38
+ */
39
+ public function __construct()
40
+ {
41
+ parent::__construct();
42
+ $this->setId('rolesGrid');
43
+ $this->setUseAjax(true);
44
+ $this->setSaveParametersInSession(true);
45
+ $this->setDefaultSort('entity_id')
46
+ ->setDefaultDir(Varien_Db_Select::SQL_DESC);
47
+ }
48
+
49
+ /**
50
+ * Prepare collection
51
+ *
52
+ * @return Mage_Api2_Block_Adminhtml_Roles_Grid
53
+ */
54
+ protected function _prepareCollection()
55
+ {
56
+ /** @var $collection Mage_Api2_Model_Resource_Acl_Global_Role_Collection */
57
+ $collection = Mage::getModel('api2/acl_global_role')->getCollection();
58
+ $this->setCollection($collection);
59
+ parent::_prepareCollection();
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * Prepare columns
65
+ *
66
+ * @return Mage_Api2_Block_Adminhtml_Roles_Grid
67
+ */
68
+ protected function _prepareColumns()
69
+ {
70
+ $this->addColumn('entity_id', array(
71
+ 'header' => Mage::helper('oauth')->__('ID'),
72
+ 'index' => 'entity_id',
73
+ 'align' => 'right',
74
+ 'width' => '50px',
75
+ ));
76
+
77
+ $this->addColumn('role_name', array(
78
+ 'header' => Mage::helper('oauth')->__('Role Name'),
79
+ 'index' => 'role_name',
80
+ 'escape' => true,
81
+ ));
82
+
83
+ $this->addColumn('tole_user_type', array(
84
+ 'header' => Mage::helper('oauth')->__('User Type'),
85
+ 'sortable' => false,
86
+ 'frame_callback' => array($this, 'decorateUserType')
87
+ ));
88
+
89
+ $this->addColumn('created_at', array(
90
+ 'header' => Mage::helper('oauth')->__('Created At'),
91
+ 'index' => 'created_at'
92
+ ));
93
+
94
+ parent::_prepareColumns();
95
+ return $this;
96
+ }
97
+
98
+ /**
99
+ * Get grid URL
100
+ *
101
+ * @return string
102
+ */
103
+ public function getGridUrl()
104
+ {
105
+ return $this->getUrl('*/*/grid', array('_current' => true));
106
+ }
107
+
108
+ /**
109
+ * Get row URL
110
+ *
111
+ * @param Mage_Api2_Model_Acl_Global_Role $row
112
+ * @return string|null
113
+ */
114
+ public function getRowUrl($row)
115
+ {
116
+ /** @var $session Mage_Admin_Model_Session */
117
+ $session = Mage::getSingleton('admin/session');
118
+
119
+ if ($session->isAllowed('system/api/roles/edit')) {
120
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
121
+ }
122
+ return null;
123
+ }
124
+
125
+ /**
126
+ * Decorate 'User Type' column
127
+ *
128
+ * @param string $renderedValue Rendered value
129
+ * @param Mage_Api2_Model_Acl_Global_Role $row
130
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
131
+ * @param bool $isExport
132
+ * @return string
133
+ */
134
+ public function decorateUserType($renderedValue, $row, $column, $isExport)
135
+ {
136
+ switch ($row->getEntityId()) {
137
+ case Mage_Api2_Model_Acl_Global_Role::ROLE_GUEST_ID:
138
+ $userType = Mage::helper('api2')->__('Guest');
139
+ break;
140
+ case Mage_Api2_Model_Acl_Global_Role::ROLE_CUSTOMER_ID:
141
+ $userType = Mage::helper('api2')->__('Customer');
142
+ break;
143
+ default:
144
+ $userType = Mage::helper('api2')->__('Admin');
145
+ break;
146
+ }
147
+ return $userType;
148
+ }
149
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Info.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Block for rendering role info tab
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Api2
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ * @method Mage_Api2_Model_Acl_Global_Role getRole()
35
+ * @method Mage_Api2_Block_Adminhtml_Roles_Tab_Info setRole(Mage_Api2_Model_Acl_Global_Role $role)
36
+ */
37
+ class Mage_Api2_Block_Adminhtml_Roles_Tab_Info extends Mage_Adminhtml_Block_Widget_Form
38
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
39
+ {
40
+ /**
41
+ * Prepare form object
42
+ */
43
+ protected function _prepareForm()
44
+ {
45
+ $form = new Varien_Data_Form();
46
+
47
+ $fieldset = $form->addFieldset('base_fieldset', array(
48
+ 'legend' => Mage::helper('adminhtml')->__('Role Information')
49
+ ));
50
+
51
+ $data = array(
52
+ 'name' => 'role_name',
53
+ 'label' => Mage::helper('adminhtml')->__('Role Name'),
54
+ 'id' => 'role_name',
55
+ 'class' => 'required-entry',
56
+ 'required' => true,
57
+ );
58
+
59
+ if ($this->isHidden()) {
60
+ /** @var $helper Mage_Core_Helper_Data */
61
+ $helper = Mage::helper('core');
62
+
63
+ $data['note'] = Mage::helper('api2')->__(
64
+ '%s role is protected.',
65
+ $helper->escapeHtml($this->getRole()->getRoleName())
66
+ );
67
+ $data['readonly'] = 'readonly';
68
+ }
69
+ $fieldset->addField('role_name', 'text', $data);
70
+
71
+ $fieldset->addField('entity_id', 'hidden',
72
+ array(
73
+ 'name' => 'id',
74
+ )
75
+ );
76
+
77
+ $fieldset->addField('in_role_users', 'hidden',
78
+ array(
79
+ 'name' => 'in_role_users',
80
+ 'id' => 'in_role_userz',
81
+ )
82
+ );
83
+
84
+ $fieldset->addField('in_role_users_old', 'hidden', array('name' => 'in_role_users_old'));
85
+
86
+ if ($this->getRole()) {
87
+ $form->setValues($this->getRole()->getData());
88
+ }
89
+ $this->setForm($form);
90
+ }
91
+
92
+ /**
93
+ * Get tab label
94
+ *
95
+ * @return string
96
+ */
97
+ public function getTabLabel()
98
+ {
99
+ return Mage::helper('api2')->__('Role Info');
100
+ }
101
+
102
+ /**
103
+ * Get tab title
104
+ *
105
+ * @return string
106
+ */
107
+ public function getTabTitle()
108
+ {
109
+ return $this->getTabLabel();
110
+ }
111
+
112
+ /**
113
+ * Whether tab is available
114
+ *
115
+ * @return bool
116
+ */
117
+ public function canShowTab()
118
+ {
119
+ return true;
120
+ }
121
+
122
+ /**
123
+ * Whether tab is hidden
124
+ *
125
+ * @return bool
126
+ */
127
+ public function isHidden()
128
+ {
129
+ return $this->getRole() && Mage_Api2_Model_Acl_Global_Role::isSystemRole($this->getRole());
130
+ }
131
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Resources.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Block for rendering resources list tab
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Model_Acl_Global_Role getRole()
34
+ * @method Mage_Api2_Block_Adminhtml_Roles_Tab_Resources setRole(Mage_Api2_Model_Acl_Global_Role $role)
35
+ */
36
+ class Mage_Api2_Block_Adminhtml_Roles_Tab_Resources extends Mage_Adminhtml_Block_Widget_Form
37
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
38
+ {
39
+ /**
40
+ * Role model
41
+ *
42
+ * @var Mage_Api2_Model_Acl_Global_Role
43
+ */
44
+ protected $_role;
45
+
46
+ /**
47
+ * Tree model
48
+ *
49
+ * @var Mage_Api2_Model_Acl_Global_Rule_Tree
50
+ */
51
+ protected $_treeModel = false;
52
+
53
+ /**
54
+ * Constructor
55
+ */
56
+ public function __construct()
57
+ {
58
+ parent::__construct();
59
+
60
+ $this->setId('api2_role_section_resources')
61
+ ->setData('default_dir', Varien_Db_Select::SQL_ASC)
62
+ ->setData('default_sort', 'sort_order')
63
+ ->setData('title', Mage::helper('api2')->__('Api Rules Information'))
64
+ ->setData('use_ajax', true);
65
+
66
+ $this->_treeModel = Mage::getModel(
67
+ 'api2/acl_global_rule_tree', array('type' => Mage_Api2_Model_Acl_Global_Rule_Tree::TYPE_PRIVILEGE)
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Get Json Representation of Resource Tree
73
+ *
74
+ * @return string
75
+ */
76
+ public function getResTreeJson()
77
+ {
78
+ $this->_prepareTreeModel();
79
+ /** @var $helper Mage_Core_Helper_Data */
80
+ $helper = Mage::helper('core');
81
+ return $helper->jsonEncode($this->_treeModel->getTreeResources());
82
+ }
83
+
84
+ /**
85
+ * Prepare tree model
86
+ *
87
+ * @return Mage_Api2_Block_Adminhtml_Roles_Tab_Resources
88
+ */
89
+ public function _prepareTreeModel()
90
+ {
91
+ $role = $this->getRole();
92
+ if ($role) {
93
+ $permissionModel = $role->getPermissionModel();
94
+ $permissionModel->setFilterValue($role);
95
+ $this->_treeModel->setResourcesPermissions($permissionModel->getResourcesPermissions());
96
+ } else {
97
+ $role = Mage::getModel('api2/acl_global_role');
98
+ }
99
+ $this->_treeModel->setRole($role);
100
+ return $this;
101
+ }
102
+
103
+ /**
104
+ * Check if everything is allowed
105
+ *
106
+ * @return boolean
107
+ */
108
+ public function getEverythingAllowed()
109
+ {
110
+ $this->_prepareTreeModel();
111
+ return $this->_treeModel->getEverythingAllowed();
112
+ }
113
+
114
+ /**
115
+ * Get tab label
116
+ *
117
+ * @return string
118
+ */
119
+ public function getTabLabel()
120
+ {
121
+ return Mage::helper('api2')->__('Role API Resources');
122
+ }
123
+
124
+ /**
125
+ * Get tab title
126
+ *
127
+ * @return string
128
+ */
129
+ public function getTabTitle()
130
+ {
131
+ return $this->getTabLabel();
132
+ }
133
+
134
+ /**
135
+ * Whether tab is available
136
+ *
137
+ * @return bool
138
+ */
139
+ public function canShowTab()
140
+ {
141
+ return true;
142
+ }
143
+
144
+ /**
145
+ * Whether tab is hidden
146
+ *
147
+ * @return bool
148
+ */
149
+ public function isHidden()
150
+ {
151
+ return false;
152
+ }
153
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Users.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Block for rendering users list tab
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Model_Acl_Global_Role getRole()
34
+ * @method Mage_Api2_Block_Adminhtml_Roles_Tab_Users setRole(Mage_Api2_Model_Acl_Global_Role $role)
35
+ * @method Mage_Api2_Block_Adminhtml_Roles_Tab_Users setUsers(array $users)
36
+ * @method Mage_Admin_Model_Resource_User_Collection getCollection()
37
+ */
38
+ class Mage_Api2_Block_Adminhtml_Roles_Tab_Users extends Mage_Adminhtml_Block_Widget_Grid
39
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
40
+ {
41
+ /**
42
+ * Construct grid block
43
+ */
44
+ public function __construct()
45
+ {
46
+ parent::__construct();
47
+ $this->setId('roleUsersGrid');
48
+ $this->setData('use_ajax', true);
49
+ $this->setSaveParametersInSession(true);
50
+ $this->setDefaultSort('user_id')
51
+ ->setDefaultDir(Varien_Db_Select::SQL_DESC);
52
+ $this->setDefaultFilter(array('filter_in_role_users'=>1));
53
+ }
54
+
55
+ /**
56
+ * Prepare collection
57
+ *
58
+ * @return Mage_Api2_Block_Adminhtml_Roles_Tab_Users
59
+ */
60
+ protected function _prepareCollection()
61
+ {
62
+ /** @var $collection Mage_Admin_Model_Resource_User_Collection */
63
+ $collection = Mage::getModel('admin/user')->getCollection();
64
+ $collection->getSelect()->joinLeft(
65
+ array('acl' => $collection->getTable('api2/acl_user')),
66
+ 'acl.admin_id = main_table.user_id',
67
+ 'role_id'
68
+ );
69
+ if ($this->getRole() && $this->getRole()->getId()) {
70
+ $collection->addFilter('acl.role_id', $this->getRole()->getId());
71
+ }
72
+
73
+ $this->setCollection($collection);
74
+ parent::_prepareCollection();
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * Prepare columns
80
+ *
81
+ * @return Mage_Api2_Block_Adminhtml_Roles_Tab_Users
82
+ */
83
+ protected function _prepareColumns()
84
+ {
85
+ $this->addColumn('filter_in_role_users', array(
86
+ 'header_css_class' => 'a-center',
87
+ 'type' => 'checkbox',
88
+ 'name' => 'filter_in_role_users',
89
+ 'values' => $this->getUsers(),
90
+ 'align' => 'center',
91
+ 'index' => 'user_id'
92
+ ));
93
+
94
+ $this->addColumn('user_id', array(
95
+ 'header' => Mage::helper('api2')->__('ID'), 'index' => 'user_id', 'align' => 'right', 'width' => '50px',
96
+ ));
97
+
98
+ $this->addColumn('username', array(
99
+ 'header' => Mage::helper('adminhtml')->__('User Name'), 'align' => 'left', 'index' => 'username'
100
+ ));
101
+
102
+ $this->addColumn('firstname', array(
103
+ 'header' => Mage::helper('adminhtml')->__('First Name'), 'align' => 'left', 'index' => 'firstname'
104
+ ));
105
+
106
+ $this->addColumn('lastname', array(
107
+ 'header' => Mage::helper('adminhtml')->__('Last Name'), 'align' => 'left', 'index' => 'lastname'
108
+ ));
109
+
110
+ return parent::_prepareColumns();
111
+ }
112
+
113
+ /**
114
+ * Get grid URL
115
+ *
116
+ * @return string
117
+ */
118
+ public function getGridUrl()
119
+ {
120
+ return $this->getUrl('*/*/usersGrid', array('_current' => true));
121
+ }
122
+
123
+ /**
124
+ * Get row URL
125
+ *
126
+ * @param Mage_Api2_Model_Acl_Global_Role $row
127
+ * @return string|null
128
+ */
129
+ public function getRowUrl($row)
130
+ {
131
+ return null;
132
+ }
133
+
134
+ /**
135
+ * Get tab label
136
+ *
137
+ * @return string
138
+ */
139
+ public function getTabLabel()
140
+ {
141
+ return Mage::helper('api2')->__('Role Users');
142
+ }
143
+
144
+ /**
145
+ * Get tab title
146
+ *
147
+ * @return string
148
+ */
149
+ public function getTabTitle()
150
+ {
151
+ return $this->getTabLabel();
152
+ }
153
+
154
+ /**
155
+ * Whether tab is available
156
+ *
157
+ * @return bool
158
+ */
159
+ public function canShowTab()
160
+ {
161
+ return !$this->isHidden();
162
+ }
163
+
164
+ /**
165
+ * Whether tab is hidden
166
+ *
167
+ * @return bool
168
+ */
169
+ public function isHidden()
170
+ {
171
+ return $this->getRole() && Mage_Api2_Model_Acl_Global_Role::isSystemRole($this->getRole());
172
+ }
173
+
174
+ /**
175
+ * Render block only when not hidden
176
+ *
177
+ * @return string
178
+ */
179
+ public function _toHtml()
180
+ {
181
+ if (!$this->isHidden()) {
182
+ return parent::_toHtml();
183
+ }
184
+ return '';
185
+ }
186
+
187
+ /**
188
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
189
+ * @return Mage_Api2_Block_Adminhtml_Roles_Tab_Users
190
+ */
191
+ protected function _addColumnFilterToCollection($column)
192
+ {
193
+ if ($column->getId() == 'filter_in_role_users') {
194
+ $inRoleIds = $this->getUsers();
195
+ if (empty($inRoleIds)) {
196
+ $inRoleIds = 0;
197
+ }
198
+
199
+ if ($column->getFilter()->getValue()) {
200
+ $this->getCollection()->addFieldToFilter('user_id', array('in' => $inRoleIds));
201
+ } else {
202
+ if($inRoleIds) {
203
+ $this->getCollection()->addFieldToFilter('user_id', array('nin' => $inRoleIds));
204
+ }
205
+ }
206
+ } else {
207
+ parent::_addColumnFilterToCollection($column);
208
+ }
209
+ return $this;
210
+ }
211
+
212
+ /**
213
+ * Get users
214
+ *
215
+ * @param bool $json
216
+ * @return array|string
217
+ */
218
+ public function getUsers($json = false)
219
+ {
220
+ $users = $this->getData('users');
221
+
222
+ if ($json) {
223
+ if ($users === array()) {
224
+ return '{}';
225
+ }
226
+ $jsonUsers = array();
227
+ foreach($users as $usrId) {
228
+ $jsonUsers[$usrId] = 0;
229
+ }
230
+ /** @var $helper Mage_Core_Helper_Data */
231
+ $helper = Mage::helper('core');
232
+ $result = $helper->jsonEncode((object) $jsonUsers);
233
+ } else {
234
+ $result = array_values($users);
235
+ }
236
+
237
+ return $result;
238
+ }
239
+ }
app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tabs.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Block tabs for role edit page
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Block_Adminhtml_Roles_Tabs setRole(Mage_Api2_Model_Acl_Global_Role $role)
34
+ * @method Mage_Api2_Model_Acl_Global_Role getRole()
35
+ */
36
+ class Mage_Api2_Block_Adminhtml_Roles_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
37
+ {
38
+
39
+ /**
40
+ * Constructor
41
+ */
42
+ public function __construct()
43
+ {
44
+ parent::__construct();
45
+ $this->setId('role_info_tabs');
46
+ $this->setDestElementId('role_edit_form');
47
+ $this->setData('title', Mage::helper('api2')->__('Role Information'));
48
+ }
49
+
50
+ /**
51
+ * Hook before html rendering
52
+ *
53
+ * @return Mage_Api2_Block_Adminhtml_Roles_Tabs
54
+ */
55
+ protected function _beforeToHtml()
56
+ {
57
+ $role = $this->getRole();
58
+ if ($role && Mage_Api2_Model_Acl_Global_Role::isSystemRole($role)) {
59
+ $this->setActiveTab('api2_role_section_resources');
60
+ } else {
61
+ $this->setActiveTab('api2_role_section_info');
62
+ }
63
+ return parent::_beforeToHtml();
64
+ }
65
+ }
app/code/core/Mage/Api2/Exception.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API exception
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Exception extends Exception
35
+ {
36
+ /**
37
+ * Exception constructor
38
+ *
39
+ * @param string $message
40
+ * @param int $code
41
+ */
42
+ public function __construct($message, $code)
43
+ {
44
+ if ($code <= 100 || $code >= 599) {
45
+ throw new Exception(sprintf('Invalid Exception code "%d"', $code));
46
+ }
47
+
48
+ parent::__construct($message, $code);
49
+ }
50
+ }
app/code/core/Mage/Api2/Helper/Data.php ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice API2 data helper
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Helper_Data extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Request interpret adapters
38
+ */
39
+ const XML_PATH_API2_REQUEST_INTERPRETERS = 'global/api2/request/interpreters';
40
+
41
+ /**
42
+ * Response render adapters
43
+ */
44
+ const XML_PATH_API2_RESPONSE_RENDERS = 'global/api2/response/renders';
45
+
46
+ /**#@+
47
+ * Config paths
48
+ */
49
+ const XML_PATH_AUTH_ADAPTERS = 'global/api2/auth_adapters';
50
+ const XML_PATH_USER_TYPES = 'global/api2/user_types';
51
+ /**#@- */
52
+
53
+ /**
54
+ * Compare order to be used in adapters list sort
55
+ *
56
+ * @param int $a
57
+ * @param int $b
58
+ * @return int
59
+ */
60
+ protected static function _compareOrder($a, $b)
61
+ {
62
+ if ($a['order'] == $b['order']) {
63
+ return 0;
64
+ }
65
+ return ($a['order'] < $b['order']) ? -1 : 1;
66
+ }
67
+
68
+ /**
69
+ * Retrieve Auth adapters info from configuration file as array
70
+ *
71
+ * @param bool $enabledOnly
72
+ * @return array
73
+ */
74
+ public function getAuthAdapters($enabledOnly = false)
75
+ {
76
+ $adapters = Mage::getConfig()->getNode(self::XML_PATH_AUTH_ADAPTERS);
77
+
78
+ if (!$adapters) {
79
+ return array();
80
+ }
81
+ $adapters = $adapters->asArray();
82
+
83
+ if ($enabledOnly) {
84
+ foreach ($adapters as $adapter) {
85
+ if (empty($adapter['enabled'])) {
86
+ unset($adapters);
87
+ }
88
+ }
89
+ $adapters = (array) $adapters;
90
+ }
91
+ uasort($adapters, array('Mage_Api2_Helper_Data', '_compareOrder'));
92
+
93
+ return $adapters;
94
+ }
95
+
96
+ /**
97
+ * Retrieve enabled user types in form of user type => user model pairs
98
+ *
99
+ * @return array
100
+ */
101
+ public function getUserTypes()
102
+ {
103
+ $userModels = array();
104
+ $types = Mage::getConfig()->getNode(self::XML_PATH_USER_TYPES);
105
+
106
+ if ($types) {
107
+ foreach ($types->asArray() as $type => $params) {
108
+ if (!empty($params['allowed'])) {
109
+ $userModels[$type] = $params['model'];
110
+ }
111
+ }
112
+ }
113
+ return $userModels;
114
+ }
115
+
116
+ /**
117
+ * Get interpreter type for Request body according to Content-type HTTP header
118
+ *
119
+ * @return array
120
+ */
121
+ public function getRequestInterpreterAdapters()
122
+ {
123
+ return (array) Mage::app()->getConfig()->getNode(self::XML_PATH_API2_REQUEST_INTERPRETERS);
124
+ }
125
+
126
+ /**
127
+ * Get interpreter type for Request body according to Content-type HTTP header
128
+ *
129
+ * @return array
130
+ */
131
+ public function getResponseRenderAdapters()
132
+ {
133
+ return (array) Mage::app()->getConfig()->getNode(self::XML_PATH_API2_RESPONSE_RENDERS);
134
+ }
135
+
136
+ /**
137
+ * Check API type support
138
+ *
139
+ * @param string $type
140
+ * @return bool
141
+ */
142
+ public function isApiTypeSupported($type)
143
+ {
144
+ return in_array($type, Mage_Api2_Model_Server::getApiTypes());
145
+ }
146
+
147
+ /**
148
+ * Get allowed attributes of a rule
149
+ *
150
+ * @param string $userType
151
+ * @param string $resourceId
152
+ * @param string $operation One of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
153
+ * @return array
154
+ */
155
+ public function getAllowedAttributes($userType, $resourceId, $operation)
156
+ {
157
+ /** @var $resource Mage_Api2_Model_Resource_Acl_Filter_Attribute */
158
+ $resource = Mage::getResourceModel('api2/acl_filter_attribute');
159
+
160
+ $attributes = $resource->getAllowedAttributes($userType, $resourceId, $operation);
161
+
162
+ return ($attributes === false || $attributes === null ? array() : explode(',', $attributes));
163
+ }
164
+
165
+ /**
166
+ * Check if ALL attributes are allowed
167
+ *
168
+ * @param string $userType
169
+ * @return bool
170
+ */
171
+ public function isAllAttributesAllowed($userType)
172
+ {
173
+ /** @var $resource Mage_Api2_Model_Resource_Acl_Filter_Attribute */
174
+ $resource = Mage::getResourceModel('api2/acl_filter_attribute');
175
+
176
+ return $resource->isAllAttributesAllowed($userType);
177
+ }
178
+
179
+ /**
180
+ * Get operation type for specified operation
181
+ *
182
+ * @param string $operation One of Mage_Api2_Model_Resource::OPERATION_... constant
183
+ * @return string One of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
184
+ * @throws Exception
185
+ */
186
+ public function getTypeOfOperation($operation)
187
+ {
188
+ if (Mage_Api2_Model_Resource::OPERATION_RETRIEVE === $operation) {
189
+ return Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ;
190
+ } elseif (Mage_Api2_Model_Resource::OPERATION_CREATE === $operation) {
191
+ return Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_WRITE;
192
+ } elseif (Mage_Api2_Model_Resource::OPERATION_UPDATE === $operation) {
193
+ return Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_WRITE;
194
+ } else {
195
+ throw new Exception('Can not determine operation type');
196
+ }
197
+ }
198
+ }
app/code/core/Mage/Api2/Model/Acl.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API User ACL model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl extends Zend_Acl
35
+ {
36
+ /**
37
+ * REST ACL roles collection
38
+ *
39
+ * @var Mage_Api2_Model_Resource_Acl_Global_Role_Collection
40
+ */
41
+ protected $_rolesCollection;
42
+
43
+ /**
44
+ * API2 config model instance
45
+ *
46
+ * @var Mage_Api2_Model_Config
47
+ */
48
+ protected $_config;
49
+
50
+ /**
51
+ * Resource type of request
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_resourceType;
56
+
57
+ /**
58
+ * Operation of request
59
+ *
60
+ * @var string
61
+ */
62
+ protected $_operation;
63
+
64
+ /**
65
+ * Constructor
66
+ *
67
+ * @param array $options
68
+ */
69
+ public function __construct($options)
70
+ {
71
+ if (!isset($options['resource_type']) || empty($options['resource_type'])) {
72
+ throw new Exception("Passed parameter 'resource_type' is wrong.");
73
+ }
74
+ if (!isset($options['operation']) || empty($options['operation'])) {
75
+ throw new Exception("Passed parameter 'operation' is wrong.");
76
+ }
77
+ $this->_resourceType = $options['resource_type'];
78
+ $this->_operation = $options['operation'];
79
+
80
+ $this->_setResources();
81
+ $this->_setRoles();
82
+ $this->_setRules();
83
+ }
84
+
85
+ /**
86
+ * Retrieve REST ACL roles collection
87
+ *
88
+ * @return Mage_Api2_Model_Resource_Acl_Global_Role_Collection
89
+ */
90
+ protected function _getRolesCollection()
91
+ {
92
+ if (null === $this->_rolesCollection) {
93
+ $this->_rolesCollection = Mage::getResourceModel('api2/acl_global_role_collection');
94
+ }
95
+ return $this->_rolesCollection;
96
+ }
97
+
98
+ /**
99
+ * Retrieve API2 config model instance
100
+ *
101
+ * @return Mage_Api2_Model_Config
102
+ */
103
+ protected function _getConfig()
104
+ {
105
+ if (null === $this->_config) {
106
+ $this->_config = Mage::getModel('api2/config');
107
+ }
108
+ return $this->_config;
109
+ }
110
+
111
+ /**
112
+ * Retrieve resources types and set into ACL
113
+ *
114
+ * @return Mage_Api2_Model_Acl
115
+ */
116
+ protected function _setResources()
117
+ {
118
+ foreach ($this->_getConfig()->getResourcesTypes() as $type) {
119
+ $this->addResource($type);
120
+ }
121
+ return $this;
122
+ }
123
+
124
+ /**
125
+ * Retrieve roles from DB and set into ACL
126
+ *
127
+ * @return Mage_Api2_Model_Acl
128
+ */
129
+ protected function _setRoles()
130
+ {
131
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
132
+ foreach ($this->_getRolesCollection() as $role) {
133
+ $this->addRole($role->getId());
134
+ }
135
+ return $this;
136
+ }
137
+
138
+ /**
139
+ * Retrieve rules data from DB and inject it into ACL
140
+ *
141
+ * @return Mage_Api2_Model_Acl
142
+ */
143
+ protected function _setRules()
144
+ {
145
+ /** @var $rulesCollection Mage_Api2_Model_Resource_Acl_Global_Rule_Collection */
146
+ $rulesCollection = Mage::getResourceModel('api2/acl_global_rule_collection');
147
+
148
+ /** @var $rule Mage_Api2_Model_Acl_Global_Rule */
149
+ foreach ($rulesCollection as $rule) {
150
+ if (Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL === $rule->getResourceId()) {
151
+ if (in_array($rule->getRoleId(), Mage_Api2_Model_Acl_Global_Role::getSystemRoles())) {
152
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
153
+ $role = $this->_getRolesCollection()->getItemById($rule->getRoleId());
154
+ $privileges = $this->_getConfig()->getResourceUserPrivileges(
155
+ $this->_resourceType,
156
+ $role->getConfigNodeName()
157
+ );
158
+
159
+ if (!array_key_exists($this->_operation, $privileges)) {
160
+ continue;
161
+ }
162
+ }
163
+
164
+ $this->allow($rule->getRoleId());
165
+ } else {
166
+ $this->allow($rule->getRoleId(), $rule->getResourceId(), $rule->getPrivilege());
167
+ }
168
+ }
169
+ return $this;
170
+ }
171
+
172
+ /**
173
+ * Adds a Role having an identifier unique to the registry
174
+ * OVERRIDE to allow numeric roles identifiers
175
+ *
176
+ * @param int $roleId Role identifier
177
+ * @param Zend_Acl_Role_Interface|string|array $parents
178
+ * @return Zend_Acl Provides a fluent interface
179
+ */
180
+ public function addRole($roleId, $parents = null)
181
+ {
182
+ if (!is_numeric($roleId)) {
183
+ throw new Exception('Invalid role identifier');
184
+ }
185
+ return parent::addRole((string) $roleId);
186
+ }
187
+ }
app/code/core/Mage/Api2/Model/Acl/Filter.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API ACL filter
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Filter
35
+ {
36
+ /**
37
+ * Attributes allowed for use
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_allowedAttributes;
42
+
43
+ /**
44
+ * A list of attributes to be included into output
45
+ *
46
+ * @var array
47
+ */
48
+ protected $_attributesToInclude;
49
+
50
+ /**
51
+ * Associated resource model
52
+ *
53
+ * @var Mage_Api2_Model_Resource
54
+ */
55
+ protected $_resource;
56
+
57
+ /**
58
+ * Object constructor
59
+ *
60
+ * @param Mage_Api2_Model_Resource $resource
61
+ */
62
+ public function __construct(Mage_Api2_Model_Resource $resource)
63
+ {
64
+ $this->_resource = $resource;
65
+ }
66
+
67
+ /**
68
+ * Return only the data which keys are allowed
69
+ *
70
+ * @param array $allowedAttributes List of attributes available to use
71
+ * @param array $data Associative array attribute to value
72
+ * @return array
73
+ */
74
+ protected function _filter(array $allowedAttributes, array $data)
75
+ {
76
+ foreach ($data as $attribute => $value) {
77
+ if (!in_array($attribute, $allowedAttributes)) {
78
+ unset($data[$attribute]);
79
+ }
80
+ }
81
+ return $data;
82
+ }
83
+
84
+ /**
85
+ * Strip attributes in of collection items
86
+ *
87
+ * @param array $items
88
+ * @return array
89
+ */
90
+ public function collectionIn($items)
91
+ {
92
+ foreach ($items as &$data) {
93
+ $data = is_array($data) ? $this->in($data) : array();
94
+ }
95
+ return $items;
96
+ }
97
+
98
+ /**
99
+ * Strip attributes out of collection items
100
+ *
101
+ * @param array $items
102
+ * @return array
103
+ */
104
+ public function collectionOut($items)
105
+ {
106
+ foreach ($items as &$data) {
107
+ $data = $this->out($data);
108
+ }
109
+ return $items;
110
+ }
111
+
112
+ /**
113
+ * Fetch array of allowed attributes for given resource type, operation and user type.
114
+ *
115
+ * @param string $operationType OPTIONAL One of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
116
+ * @return array
117
+ */
118
+ public function getAllowedAttributes($operationType = null)
119
+ {
120
+ if (null === $this->_allowedAttributes) {
121
+ /** @var $helper Mage_Api2_Helper_Data */
122
+ $helper = Mage::helper('api2/data');
123
+
124
+ if (null === $operationType) {
125
+ $operationType = $helper->getTypeOfOperation($this->_resource->getOperation());
126
+ }
127
+ if ($helper->isAllAttributesAllowed($this->_resource->getUserType())) {
128
+ $this->_allowedAttributes = array_keys($this->_resource->getAvailableAttributes(
129
+ $this->_resource->getUserType(), $operationType
130
+ ));
131
+ } else {
132
+ $this->_allowedAttributes = $helper->getAllowedAttributes(
133
+ $this->_resource->getUserType(), $this->_resource->getResourceType(), $operationType
134
+ );
135
+ }
136
+ // force attributes to be no filtered
137
+ foreach ($this->_resource->getForcedAttributes() as $forcedAttr) {
138
+ if (!in_array($forcedAttr, $this->_allowedAttributes)) {
139
+ $this->_allowedAttributes[] = $forcedAttr;
140
+ }
141
+ }
142
+ }
143
+ return $this->_allowedAttributes;
144
+ }
145
+
146
+ /**
147
+ * Retrieve a list of attributes to be included in output based on available and requested attributes
148
+ *
149
+ * @return array
150
+ */
151
+ public function getAttributesToInclude()
152
+ {
153
+ if (null === $this->_attributesToInclude) {
154
+ $allowedAttrs = $this->getAllowedAttributes(Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ);
155
+ $requestedAttrs = $this->_resource->getRequest()->getRequestedAttributes();
156
+
157
+ if ($requestedAttrs) {
158
+ foreach ($allowedAttrs as $allowedAttr) {
159
+ if (in_array($allowedAttr, $requestedAttrs)) {
160
+ $this->_attributesToInclude[] = $allowedAttr;
161
+ }
162
+ }
163
+ } else {
164
+ $this->_attributesToInclude = $allowedAttrs;
165
+ }
166
+ }
167
+ return $this->_attributesToInclude;
168
+ }
169
+
170
+ /**
171
+ * Filter data for write operations
172
+ *
173
+ * @param array $requestData
174
+ * @return array
175
+ */
176
+ public function in(array $requestData)
177
+ {
178
+ $allowedAttributes = $this->getAllowedAttributes(Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_WRITE);
179
+
180
+ return $this->_filter($allowedAttributes, $requestData);
181
+ }
182
+
183
+ /**
184
+ * Filter data before output
185
+ *
186
+ * @param array $retrievedData
187
+ * @return array
188
+ */
189
+ public function out(array $retrievedData)
190
+ {
191
+ return $this->_filter($this->getAttributesToInclude(), $retrievedData);
192
+ }
193
+ }
app/code/core/Mage/Api2/Model/Acl/Filter/Attribute.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 filter ACL attribute model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection getCollection()
34
+ * @method Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection getResourceCollection()
35
+ * @method Mage_Api2_Model_Resource_Acl_Filter_Attribute getResource()
36
+ * @method Mage_Api2_Model_Resource_Acl_Filter_Attribute _getResource()
37
+ * @method string getUserType()
38
+ * @method Mage_Api2_Model_Acl_Filter_Attribute setUserType() setUserType(string $type)
39
+ * @method string getResourceId()
40
+ * @method Mage_Api2_Model_Acl_Filter_Attribute setResourceId() setResourceId(string $resource)
41
+ * @method string getOperation()
42
+ * @method Mage_Api2_Model_Acl_Filter_Attribute setOperation() setOperation(string $operation)
43
+ * @method string getAllowedAttributes()
44
+ * @method Mage_Api2_Model_Acl_Filter_Attribute setAllowedAttributes() setAllowedAttributes(string $attributes)
45
+ */
46
+ class Mage_Api2_Model_Acl_Filter_Attribute extends Mage_Core_Model_Abstract
47
+ {
48
+ /**
49
+ * Permissions model
50
+ *
51
+ * @var Mage_Api2_Model_Acl_Filter_Attribute_ResourcePermission
52
+ */
53
+ protected $_permissionModel;
54
+
55
+ /**
56
+ * Initialize resource model
57
+ *
58
+ * @return void
59
+ */
60
+ protected function _construct()
61
+ {
62
+ $this->_init('api2/acl_filter_attribute');
63
+ }
64
+
65
+ /**
66
+ * Get pairs resources-permissions for current attribute
67
+ *
68
+ * @return Mage_Api2_Model_Acl_Filter_Attribute_ResourcePermission
69
+ */
70
+ public function getPermissionModel()
71
+ {
72
+ if (null == $this->_permissionModel) {
73
+ $this->_permissionModel = Mage::getModel('api2/acl_filter_attribute_resourcePermission');
74
+ }
75
+ return $this->_permissionModel;
76
+ }
77
+ }
app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/Operation.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Operation source model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Filter_Attribute_Operation
35
+ {
36
+ /**
37
+ * Get options paramets
38
+ *
39
+ * @return array
40
+ */
41
+ static public function toOptionArray()
42
+ {
43
+ return array(
44
+ array(
45
+ 'value' => Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ,
46
+ 'label' => Mage::helper('api2')->__('Read')
47
+ ),
48
+ array(
49
+ 'value' => Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_WRITE,
50
+ 'label' => Mage::helper('api2')->__('Write')
51
+ )
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Get options in "key-value" format
57
+ *
58
+ * @return array
59
+ */
60
+ static public function toArray()
61
+ {
62
+ return array(
63
+ Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ => Mage::helper('api2')->__('Read'),
64
+ Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_WRITE => Mage::helper('api2')->__('Write')
65
+ );
66
+ }
67
+ }
app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 filter ACL attribute resources permissions model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Filter_Attribute_ResourcePermission
35
+ implements Mage_Api2_Model_Acl_PermissionInterface
36
+ {
37
+ /**
38
+ * Resources permissions
39
+ *
40
+ * @var array
41
+ */
42
+ protected $_resourcesPermissions;
43
+
44
+ /**
45
+ * Filter item value
46
+ *
47
+ * @var string
48
+ */
49
+ protected $_userType;
50
+
51
+ /**
52
+ * Flag if resource has entity only attributes
53
+ *
54
+ * @var bool
55
+ */
56
+ protected $_hasEntityOnlyAttributes = false;
57
+
58
+ /**
59
+ * Get resources permissions for selected role
60
+ *
61
+ * @return array
62
+ */
63
+ public function getResourcesPermissions()
64
+ {
65
+ if (null === $this->_resourcesPermissions) {
66
+ $rulesPairs = array();
67
+
68
+ if ($this->_userType) {
69
+ $allowedAttributes = array();
70
+
71
+ /** @var $rules Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection */
72
+ $rules = Mage::getResourceModel('api2/acl_filter_attribute_collection');
73
+ $rules->addFilterByUserType($this->_userType);
74
+
75
+ foreach ($rules as $rule) {
76
+ if (Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL === $rule->getResourceId()) {
77
+ $rulesPairs[$rule->getResourceId()] = Mage_Api2_Model_Acl_Global_Rule_Permission::TYPE_ALLOW;
78
+ }
79
+
80
+ /** @var $rule Mage_Api2_Model_Acl_Filter_Attribute */
81
+ if (null !== $rule->getAllowedAttributes()) {
82
+ $allowedAttributes[$rule->getResourceId()][$rule->getOperation()] = explode(
83
+ ',', $rule->getAllowedAttributes()
84
+ );
85
+ }
86
+ }
87
+
88
+ /** @var $config Mage_Api2_Model_Config */
89
+ $config = Mage::getModel('api2/config');
90
+
91
+ /** @var $operationSource Mage_Api2_Model_Acl_Filter_Attribute_Operation */
92
+ $operationSource = Mage::getModel('api2/acl_filter_attribute_operation');
93
+
94
+ foreach ($config->getResourcesTypes() as $resource) {
95
+ $resourceUserPrivileges = $config->getResourceUserPrivileges($resource, $this->_userType);
96
+
97
+ if (!$resourceUserPrivileges) { // skip user without any privileges for resource
98
+ continue;
99
+ }
100
+ $operations = $operationSource->toArray();
101
+
102
+ if (empty($resourceUserPrivileges[Mage_Api2_Model_Resource::OPERATION_CREATE])
103
+ && empty($resourceUserPrivileges[Mage_Api2_Model_Resource::OPERATION_UPDATE])
104
+ ) {
105
+ unset($operations[Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_WRITE]);
106
+ }
107
+ if (empty($resourceUserPrivileges[Mage_Api2_Model_Resource::OPERATION_RETRIEVE])) {
108
+ unset($operations[Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ]);
109
+ }
110
+ if (!$operations) { // skip resource without any operations allowed
111
+ continue;
112
+ }
113
+ try {
114
+ /** @var $resourceModel Mage_Api2_Model_Resource */
115
+ $resourceModel = Mage::getModel($config->getResourceModel($resource));
116
+ if ($resourceModel) {
117
+ $resourceModel->setResourceType($resource)
118
+ ->setUserType($this->_userType);
119
+
120
+ foreach ($operations as $operation => $operationLabel) {
121
+ if (!$this->_hasEntityOnlyAttributes
122
+ && $config->getResourceEntityOnlyAttributes($resource, $this->_userType, $operation)
123
+ ) {
124
+ $this->_hasEntityOnlyAttributes = true;
125
+ }
126
+ $availableAttributes = $resourceModel->getAvailableAttributes(
127
+ $this->_userType,
128
+ $operation
129
+ );
130
+ asort($availableAttributes);
131
+ foreach ($availableAttributes as $attribute => $attributeLabel) {
132
+ $status = isset($allowedAttributes[$resource][$operation])
133
+ && in_array($attribute, $allowedAttributes[$resource][$operation])
134
+ ? Mage_Api2_Model_Acl_Global_Rule_Permission::TYPE_ALLOW
135
+ : Mage_Api2_Model_Acl_Global_Rule_Permission::TYPE_DENY;
136
+
137
+ $rulesPairs[$resource]['operations'][$operation]['attributes'][$attribute] = array(
138
+ 'status' => $status,
139
+ 'title' => $attributeLabel
140
+ );
141
+ }
142
+ }
143
+ }
144
+ } catch (Exception $e) {
145
+ // getModel() throws exception when application is in development mode
146
+ Mage::logException($e);
147
+ }
148
+ }
149
+ }
150
+ $this->_resourcesPermissions = $rulesPairs;
151
+ }
152
+ return $this->_resourcesPermissions;
153
+ }
154
+
155
+ /**
156
+ * Set filter value
157
+ *
158
+ * Set user type
159
+ *
160
+ * @param string $userType
161
+ * @return Mage_Api2_Model_Acl_Filter_Attribute_ResourcePermission
162
+ */
163
+ public function setFilterValue($userType)
164
+ {
165
+ if (!array_key_exists($userType, Mage_Api2_Model_Auth_User::getUserTypes())) {
166
+ throw new Exception('Unknown user type.');
167
+ }
168
+ $this->_userType = $userType;
169
+ return $this;
170
+ }
171
+
172
+ /**
173
+ * Get flag value
174
+ *
175
+ * @return bool
176
+ */
177
+ public function getHasEntityOnlyAttributes()
178
+ {
179
+ return $this->_hasEntityOnlyAttributes;
180
+ }
181
+ }
app/code/core/Mage/Api2/Model/Acl/Global.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API Global ACL model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Global
35
+ {
36
+ /**
37
+ * Check if the operation is allowed on resources of given type type for given user type/role
38
+ *
39
+ * @param Mage_Api2_Model_Auth_User_Abstract $apiUser
40
+ * @param string $resourceType
41
+ * @param string $operation
42
+ * @return boolean
43
+ * @throws Mage_Api2_Exception
44
+ */
45
+ public function isAllowed(Mage_Api2_Model_Auth_User_Abstract $apiUser, $resourceType, $operation)
46
+ {
47
+ // skip user without role, e.g. Customer
48
+ if (null === $apiUser->getRole()) {
49
+ return true;
50
+ }
51
+ /** @var $aclInstance Mage_Api2_Model_Acl */
52
+ $aclInstance = Mage::getSingleton(
53
+ 'api2/acl',
54
+ array('resource_type' => $resourceType, 'operation' => $operation)
55
+ );
56
+
57
+ if (!$aclInstance->hasRole($apiUser->getRole())) {
58
+ throw new Mage_Api2_Exception('Role not found', Mage_Api2_Model_Server::HTTP_UNAUTHORIZED);
59
+ }
60
+ if (!$aclInstance->has($resourceType)) {
61
+ throw new Mage_Api2_Exception('Resource not found', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
62
+ }
63
+ return $aclInstance->isAllowed($apiUser->getRole(), $resourceType, $operation);
64
+ }
65
+ }
app/code/core/Mage/Api2/Model/Acl/Global/Role.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Global ACL Role model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Model_Resource_Acl_Global_Role_Collection getCollection()
34
+ * @method Mage_Api2_Model_Resource_Acl_Global_Role_Collection getResourceCollection()
35
+ * @method Mage_Api2_Model_Resource_Acl_Global_Role getResource()
36
+ * @method Mage_Api2_Model_Resource_Acl_Global_Role _getResource()
37
+ * @method string getCreatedAt()
38
+ * @method Mage_Api2_Model_Acl_Global_Role setCreatedAt() setCreatedAt(string $createdAt)
39
+ * @method string getUpdatedAt()
40
+ * @method Mage_Api2_Model_Acl_Global_Role setUpdatedAt() setUpdatedAt(string $updatedAt)
41
+ * @method string getRoleName()
42
+ * @method Mage_Api2_Model_Acl_Global_Role setRoleName() setRoleName(string $roleName)
43
+ */
44
+ class Mage_Api2_Model_Acl_Global_Role extends Mage_Core_Model_Abstract
45
+ {
46
+ /**#@+
47
+ * System roles identifiers
48
+ */
49
+ const ROLE_GUEST_ID = 1;
50
+ const ROLE_CUSTOMER_ID = 2;
51
+ /**#@-*/
52
+
53
+ /**#@+
54
+ * Config node identifiers
55
+ */
56
+ const ROLE_CONFIG_NODE_NAME_GUEST = 'guest';
57
+ const ROLE_CONFIG_NODE_NAME_CUSTOMER = 'customer';
58
+ const ROLE_CONFIG_NODE_NAME_ADMIN = 'admin';
59
+ /**#@-*/
60
+
61
+ /**
62
+ * Permissions model
63
+ *
64
+ * @var Mage_Api2_Model_Acl_Global_Rule_ResourcePermission
65
+ */
66
+ protected $_permissionModel;
67
+
68
+ /**
69
+ * Initialize resource model
70
+ *
71
+ * @return void
72
+ */
73
+ protected function _construct()
74
+ {
75
+ $this->_init('api2/acl_global_role');
76
+ }
77
+
78
+ /**
79
+ * Before save actions
80
+ *
81
+ * @return Mage_Api2_Model_Acl_Global_Role
82
+ */
83
+ protected function _beforeSave()
84
+ {
85
+ if ($this->isObjectNew() && null === $this->getCreatedAt()) {
86
+ $this->setCreatedAt(Varien_Date::now());
87
+ } else {
88
+ $this->setUpdatedAt(Varien_Date::now());
89
+ }
90
+
91
+ //check and protect guest role
92
+ if (Mage_Api2_Model_Acl_Global_Role::isSystemRole($this)
93
+ && $this->getRoleName() != $this->getOrigData('role_name')) {
94
+
95
+ /** @var $helper Mage_Core_Helper_Data */
96
+ $helper = Mage::helper('core');
97
+
98
+ Mage::throwException(
99
+ Mage::helper('api2')->__('%s role is a special one and can\'t be changed.',
100
+ $helper->escapeHtml($this->getRoleName()))
101
+ );
102
+ }
103
+
104
+ parent::_beforeSave();
105
+ return $this;
106
+ }
107
+
108
+ /**
109
+ * Perform checks before role delete
110
+ *
111
+ * @return Mage_Api2_Model_Acl_Global_Role
112
+ */
113
+ protected function _beforeDelete()
114
+ {
115
+ if (Mage_Api2_Model_Acl_Global_Role::isSystemRole($this)) {
116
+ /** @var $helper Mage_Core_Helper_Data */
117
+ $helper = Mage::helper('core');
118
+
119
+ Mage::throwException(
120
+ Mage::helper('api2')->__('%s role is a special one and can\'t be deleted.',
121
+ $helper->escapeHtml($this->getRoleName()))
122
+ );
123
+ }
124
+
125
+ parent::_beforeDelete();
126
+ return $this;
127
+ }
128
+
129
+ /**
130
+ * Get pairs resources-permissions for current role
131
+ *
132
+ * @return Mage_Api2_Model_Acl_Global_Rule_ResourcePermission
133
+ */
134
+ public function getPermissionModel()
135
+ {
136
+ if (null == $this->_permissionModel) {
137
+ $this->_permissionModel = Mage::getModel('api2/acl_global_rule_resourcePermission');
138
+ }
139
+ return $this->_permissionModel;
140
+ }
141
+
142
+ /**
143
+ * Retrieve system roles
144
+ *
145
+ * @return array
146
+ */
147
+ static public function getSystemRoles()
148
+ {
149
+ return array(
150
+ self::ROLE_GUEST_ID,
151
+ self::ROLE_CUSTOMER_ID
152
+ );
153
+ }
154
+
155
+ /**
156
+ * Get role system belonging
157
+ *
158
+ * @param Mage_Api2_Model_Acl_Global_Role $role
159
+ * @return bool
160
+ */
161
+ public static function isSystemRole($role)
162
+ {
163
+ return in_array($role->getId(), self::getSystemRoles());
164
+ }
165
+
166
+ /**
167
+ * Get config node identifiers
168
+ *
169
+ * @return string
170
+ */
171
+ public function getConfigNodeName()
172
+ {
173
+ switch ($this->getId()) {
174
+ case self::ROLE_GUEST_ID:
175
+ $roleNodeName = self::ROLE_CONFIG_NODE_NAME_GUEST;
176
+ break;
177
+ case self::ROLE_CUSTOMER_ID:
178
+ $roleNodeName = self::ROLE_CONFIG_NODE_NAME_CUSTOMER;
179
+ break;
180
+ default:
181
+ $roleNodeName = self::ROLE_CONFIG_NODE_NAME_ADMIN;
182
+ }
183
+ return $roleNodeName;
184
+ }
185
+ }
app/code/core/Mage/Api2/Model/Acl/Global/Rule.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Global ACL Rule model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method Mage_Api2_Model_Resource_Acl_Global_Rule_Collection getCollection()
34
+ * @method Mage_Api2_Model_Resource_Acl_Global_Rule_Collection getResourceCollection()
35
+ * @method Mage_Api2_Model_Resource_Acl_Global_Rule getResource()
36
+ * @method Mage_Api2_Model_Resource_Acl_Global_Rule _getResource()
37
+ * @method int getRoleId()
38
+ * @method Mage_Api2_Model_Acl_Global_Rule setRoleId() setRoleId(int $roleId)
39
+ * @method string getResourceId()
40
+ * @method Mage_Api2_Model_Acl_Global_Rule setResourceId() setResourceId(string $resource)
41
+ * @method string getPrivilege()
42
+ * @method int getPermission()
43
+ * @method Mage_Api2_Model_Acl_Global_Rule setPermission() setPermission(int $permission)
44
+ * @method string getPrivilege()
45
+ * @method Mage_Api2_Model_Acl_Global_Rule setPrivilege() setPrivilege(string $privilege)
46
+ * @method string getAllowedAttributes()
47
+ * @method Mage_Api2_Model_Acl_Global_Rule setAllowedAttributes() setAllowedAttributes(string $allowedAttributes)
48
+ */
49
+ class Mage_Api2_Model_Acl_Global_Rule extends Mage_Core_Model_Abstract
50
+ {
51
+ /**
52
+ * Root resource ID "all"
53
+ */
54
+ const RESOURCE_ALL = 'all';
55
+
56
+ /**
57
+ * Initialize resource model
58
+ *
59
+ * @return void
60
+ */
61
+ protected function _construct()
62
+ {
63
+ $this->_init('api2/acl_global_rule');
64
+ }
65
+ }
app/code/core/Mage/Api2/Model/Acl/Global/Rule/Permission.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Permission source model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Global_Rule_Permission
35
+ {
36
+ /**#@+
37
+ * Source keys
38
+ */
39
+ const TYPE_ALLOW = 1;
40
+ const TYPE_DENY = 0;
41
+ /**#@-*/
42
+
43
+ /**
44
+ * Get options parameters
45
+ *
46
+ * @return array
47
+ */
48
+ static public function toOptionArray()
49
+ {
50
+ return array(
51
+ array(
52
+ 'value' => self::TYPE_DENY,
53
+ 'label' => Mage::helper('api2')->__('Deny')
54
+ ),
55
+ array(
56
+ 'value' => self::TYPE_ALLOW,
57
+ 'label' => Mage::helper('api2')->__('Allow')
58
+ ),
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Get options in "key-value" format
64
+ *
65
+ * @return array
66
+ */
67
+ static public function toArray()
68
+ {
69
+ return array(
70
+ self::TYPE_DENY => Mage::helper('api2')->__('Deny'),
71
+ self::TYPE_ALLOW => Mage::helper('api2')->__('Allow'),
72
+ );
73
+ }
74
+ }
app/code/core/Mage/Api2/Model/Acl/Global/Rule/Privilege.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Privilege of rule source model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Global_Rule_Privilege
35
+ {
36
+ /**
37
+ * Get options parameters
38
+ *
39
+ * @return array
40
+ */
41
+ static public function toOptionArray()
42
+ {
43
+ return array(
44
+ array(
45
+ 'value' => Mage_Api2_Model_Resource::OPERATION_CREATE,
46
+ 'label' => Mage::helper('api2')->__('Create')
47
+ ),
48
+ array(
49
+ 'value' => Mage_Api2_Model_Resource::OPERATION_RETRIEVE,
50
+ 'label' => Mage::helper('api2')->__('Retrieve')
51
+ ),
52
+ array(
53
+ 'value' => Mage_Api2_Model_Resource::OPERATION_UPDATE,
54
+ 'label' => Mage::helper('api2')->__('Update')
55
+ ),
56
+ array(
57
+ 'value' => Mage_Api2_Model_Resource::OPERATION_DELETE,
58
+ 'label' => Mage::helper('api2')->__('Delete')
59
+ )
60
+ );
61
+ }
62
+
63
+ /**
64
+ * Get options in "key-value" format
65
+ *
66
+ * @return array
67
+ */
68
+ static public function toArray()
69
+ {
70
+ return array(
71
+ Mage_Api2_Model_Resource::OPERATION_CREATE => Mage::helper('api2')->__('Create'),
72
+ Mage_Api2_Model_Resource::OPERATION_RETRIEVE => Mage::helper('api2')->__('Retrieve'),
73
+ Mage_Api2_Model_Resource::OPERATION_UPDATE => Mage::helper('api2')->__('Update'),
74
+ Mage_Api2_Model_Resource::OPERATION_DELETE => Mage::helper('api2')->__('Delete')
75
+ );
76
+ }
77
+ }
app/code/core/Mage/Api2/Model/Acl/Global/Rule/ResourcePermission.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Global ACL role resources permissions model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Global_Rule_ResourcePermission
35
+ implements Mage_Api2_Model_Acl_PermissionInterface
36
+ {
37
+ /**
38
+ * Resources permissions
39
+ *
40
+ * @var array
41
+ */
42
+ protected $_resourcesPermissions;
43
+
44
+ /**
45
+ * Role
46
+ *
47
+ * @var Mage_Api2_Model_Acl_Global_Role
48
+ */
49
+ protected $_role;
50
+
51
+ /**
52
+ * Get resources permissions for selected role
53
+ *
54
+ * @return array
55
+ */
56
+ public function getResourcesPermissions()
57
+ {
58
+ if (null === $this->_resourcesPermissions) {
59
+ $roleConfigNodeName = $this->_role->getConfigNodeName();
60
+ $rulesPairs = array();
61
+ $allowedType = Mage_Api2_Model_Acl_Global_Rule_Permission::TYPE_ALLOW;
62
+
63
+ if ($this->_role) {
64
+ /** @var $rules Mage_Api2_Model_Resource_Acl_Global_Rule_Collection */
65
+ $rules = Mage::getResourceModel('api2/acl_global_rule_collection');
66
+ $rules->addFilterByRoleId($this->_role->getId());
67
+
68
+ /** @var $rule Mage_Api2_Model_Acl_Global_Rule */
69
+ foreach ($rules as $rule) {
70
+ $resourceId = $rule->getResourceId();
71
+ $rulesPairs[$resourceId]['privileges'][$roleConfigNodeName][$rule->getPrivilege()] = $allowedType;
72
+ }
73
+ } else {
74
+ //make resource "all" as default for new item
75
+ $rulesPairs = array(Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL => $allowedType);
76
+ }
77
+
78
+ //set permissions to resources
79
+ /** @var $config Mage_Api2_Model_Config */
80
+ $config = Mage::getModel('api2/config');
81
+ /** @var $privilegeSource Mage_Api2_Model_Acl_Global_Rule_Privilege */
82
+ $privilegeSource = Mage::getModel('api2/acl_global_rule_privilege');
83
+ $privileges = array_keys($privilegeSource->toArray());
84
+
85
+ /** @var $node Varien_Simplexml_Element */
86
+ foreach ($config->getResources() as $resourceType => $node) {
87
+ $resourceId = (string)$resourceType;
88
+ $allowedRoles = (array)$node->privileges;
89
+ $allowedPrivileges = array();
90
+ if (isset($allowedRoles[$roleConfigNodeName])) {
91
+ $allowedPrivileges = $allowedRoles[$roleConfigNodeName];
92
+ }
93
+ foreach ($privileges as $privilege) {
94
+ if (empty($allowedPrivileges[$privilege])
95
+ && isset($rulesPairs[$resourceId][$roleConfigNodeName]['privileges'][$privilege])
96
+ ) {
97
+ unset($rulesPairs[$resourceId][$roleConfigNodeName]['privileges'][$privilege]);
98
+ } elseif (!empty($allowedPrivileges[$privilege])
99
+ && !isset($rulesPairs[$resourceId][$roleConfigNodeName]['privileges'][$privilege])
100
+ ) {
101
+ $deniedType = Mage_Api2_Model_Acl_Global_Rule_Permission::TYPE_DENY;
102
+ $rulesPairs[$resourceId]['privileges'][$roleConfigNodeName][$privilege] = $deniedType;
103
+ }
104
+ }
105
+ }
106
+ $this->_resourcesPermissions = $rulesPairs;
107
+ }
108
+ return $this->_resourcesPermissions;
109
+ }
110
+
111
+ /**
112
+ * Set filter value
113
+ *
114
+ * @param Mage_Api2_Model_Acl_Global_Role $role
115
+ */
116
+ public function setFilterValue($role)
117
+ {
118
+ if ($role && $role->getId()) {
119
+ $this->_role = $role;
120
+ }
121
+ }
122
+ }
app/code/core/Mage/Api2/Model/Acl/Global/Rule/Tree.php ADDED
@@ -0,0 +1,546 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 acl global rule tree
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Acl_Global_Rule_Tree extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**#@+
37
+ * Tree types
38
+ */
39
+ const TYPE_ATTRIBUTE = 'attribute';
40
+ const TYPE_PRIVILEGE = 'privilege';
41
+ /**#@-*/
42
+
43
+ /**#@+
44
+ * Names
45
+ */
46
+ const NAME_CHILDREN = 'children';
47
+ const NAME_PRIVILEGE = 'privilege';
48
+ const NAME_OPERATION = 'operation';
49
+ const NAME_ATTRIBUTE = 'attribute';
50
+ const NAME_RESOURCE = 'resource';
51
+ const NAME_RESOURCE_GROUPS = 'resource_groups';
52
+ const NAME_GROUP = 'group';
53
+ /**#@-*/
54
+
55
+ /**
56
+ * Separator for tree ID
57
+ */
58
+ const ID_SEPARATOR = '-';
59
+
60
+ /**
61
+ * Role
62
+ *
63
+ * @var Mage_Api2_Model_Acl_Global_Role
64
+ */
65
+ protected $_role;
66
+
67
+ /**
68
+ * Resources permissions
69
+ *
70
+ * @var array
71
+ */
72
+ protected $_resourcesPermissions;
73
+
74
+ /**
75
+ * Resources from config model
76
+ *
77
+ * @var Varien_Simplexml_Element
78
+ */
79
+ protected $_resourcesConfig;
80
+
81
+ /**
82
+ * Exist privileges
83
+ *
84
+ * @var array
85
+ */
86
+ protected $_existPrivileges;
87
+
88
+ /**
89
+ * Exist operations
90
+ *
91
+ * @var array
92
+ */
93
+ protected $_existOperations;
94
+
95
+ /**
96
+ * Tree type
97
+ *
98
+ * @var string
99
+ */
100
+ protected $_type;
101
+
102
+ /**
103
+ * Initialized
104
+ *
105
+ * @var bool
106
+ */
107
+ protected $_initialized = false;
108
+
109
+ /**
110
+ * Flag if resource has entity only attributes
111
+ *
112
+ * @var bool
113
+ */
114
+ protected $_hasEntityOnlyAttributes = false;
115
+
116
+ /**
117
+ * Constructor
118
+ *
119
+ * In the constructor should be set tree type: attributes or privileges.
120
+ * Attributes for tree with resources, operations and attributes.
121
+ * Privileges for tree with resources and privileges.
122
+ *
123
+ * @param array $options
124
+ */
125
+ public function __construct($options)
126
+ {
127
+ $this->_type = $options['type'];
128
+
129
+ switch ($this->_type) {
130
+ case self::TYPE_ATTRIBUTE:
131
+ /** @var $operationSource Mage_Api2_Model_Acl_Filter_Attribute_Operation */
132
+ $operationSource = Mage::getModel('api2/acl_filter_attribute_operation');
133
+ $this->_existOperations = $operationSource->toArray();
134
+ break;
135
+
136
+ case self::TYPE_PRIVILEGE:
137
+ /** @var $privilegeSource Mage_Api2_Model_Acl_Global_Rule_Privilege */
138
+ $privilegeSource = Mage::getModel('api2/acl_global_rule_privilege');
139
+ $this->_existPrivileges = $privilegeSource->toArray();
140
+ break;
141
+
142
+ default:
143
+ throw new Exception(sprintf('Unknown tree type "%s".', $this->_type));
144
+ break;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Initialize block
150
+ *
151
+ * @return Mage_Api2_Model_Acl_Global_Rule_Tree
152
+ * @throws Exception
153
+ */
154
+ protected function _init()
155
+ {
156
+ if ($this->_initialized) {
157
+ return $this;
158
+ }
159
+
160
+ /** @var $config Mage_Api2_Model_Config */
161
+ $config = Mage::getModel('api2/config');
162
+ $this->_resourcesConfig = $config->getResourceGroups();
163
+
164
+ if ($this->_type == self::TYPE_ATTRIBUTE && !$this->_existOperations) {
165
+ throw new Exception('Operations is not set');
166
+ }
167
+
168
+ if ($this->_type == self::TYPE_PRIVILEGE && !$this->_existPrivileges) {
169
+ throw new Exception('Privileges is not set.');
170
+ }
171
+
172
+ return $this;
173
+ }
174
+
175
+ /**
176
+ * Convert to array serialized post data from tree grid
177
+ *
178
+ * @return array
179
+ */
180
+ public function getPostResources()
181
+ {
182
+ $isAll = Mage::app()->getRequest()->getParam(Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL);
183
+ $allow = Mage_Api2_Model_Acl_Global_Rule_Permission::TYPE_ALLOW;
184
+ if ($isAll) {
185
+ $resources = array(
186
+ Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL => array(
187
+ null => $allow
188
+ )
189
+ );
190
+ } else {
191
+ $resources = array();
192
+ $checkedResources = explode(',', Mage::app()->getRequest()->getParam('resource'));
193
+ $prefixResource = self::NAME_RESOURCE . self::ID_SEPARATOR;
194
+ switch ($this->_type) {
195
+ case self::TYPE_PRIVILEGE:
196
+ $prefixPrivilege = self::NAME_PRIVILEGE . self::ID_SEPARATOR;
197
+ $nameResource = null;
198
+ foreach ($checkedResources as $i => $item) {
199
+ if (0 === strpos($item, $prefixResource)) {
200
+ $nameResource = substr($item, mb_strlen($prefixResource, 'UTF-8'));
201
+ $resources[$nameResource] = array();
202
+ } elseif (0 === strpos($item, $prefixPrivilege)) {
203
+ $name = substr($item, mb_strlen($prefixPrivilege, 'UTF-8'));
204
+ $namePrivilege = str_replace($nameResource . self::ID_SEPARATOR, '', $name);
205
+ $resources[$nameResource][$namePrivilege] = $allow;
206
+ } else {
207
+ unset($checkedResources[$i]);
208
+ }
209
+ }
210
+ break;
211
+
212
+ case self::TYPE_ATTRIBUTE:
213
+ $prefixOperation = self::NAME_OPERATION . self::ID_SEPARATOR;
214
+ $prefixAttribute = self::NAME_ATTRIBUTE . self::ID_SEPARATOR;
215
+ $nameResource = null;
216
+ foreach ($checkedResources as $i => $item) {
217
+ if (0 === strpos($item, $prefixResource)) {
218
+ $nameResource = substr($item, mb_strlen($prefixResource, 'UTF-8'));
219
+ $resources[$nameResource] = array();
220
+ } elseif (0 === strpos($item, $prefixOperation)) {
221
+ $name = substr($item, mb_strlen($prefixOperation, 'UTF-8'));
222
+ $operationName = str_replace($nameResource . self::ID_SEPARATOR, '', $name);
223
+ $resources[$nameResource][$operationName] = array();
224
+ } elseif (0 === strpos($item, $prefixAttribute)) {
225
+ $name = substr($item, mb_strlen($prefixOperation, 'UTF-8'));
226
+ $attributeName = str_replace(
227
+ $nameResource . self::ID_SEPARATOR . $operationName . self::ID_SEPARATOR,
228
+ '',
229
+ $name
230
+ );
231
+ $resources[$nameResource][$operationName][$attributeName] = $allow;
232
+ } else {
233
+ unset($checkedResources[$i]);
234
+ }
235
+ }
236
+ break;
237
+
238
+ //no default
239
+ }
240
+ }
241
+ return $resources;
242
+ }
243
+
244
+ /**
245
+ * Check if everything is allowed
246
+ *
247
+ * @return boolean
248
+ */
249
+ public function getEverythingAllowed()
250
+ {
251
+ $this->_init();
252
+
253
+ $all = Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL;
254
+ return !empty($this->_resourcesPermissions[$all]);
255
+ }
256
+
257
+ /**
258
+ * Get tree resources
259
+ *
260
+ * @return array
261
+ */
262
+ public function getTreeResources()
263
+ {
264
+ $this->_init();
265
+ $root = $this->_getTreeNode($this->_resourcesConfig, 1);
266
+ return isset($root[self::NAME_CHILDREN]) ? $root[self::NAME_CHILDREN] : array();
267
+ }
268
+
269
+ /**
270
+ * Get tree node
271
+ *
272
+ * @param Varien_Simplexml_Element|array $node
273
+ * @param int $level
274
+ * @return array
275
+ */
276
+ protected function _getTreeNode($node, $level = 0)
277
+ {
278
+ $item = array();
279
+
280
+ $isResource = false;
281
+ $isGroup = false;
282
+ $name = null;
283
+
284
+ if ($level != 0) {
285
+ $name = $node->getName();
286
+ if (!(int) $node->resource) {
287
+ if (self::NAME_RESOURCE_GROUPS != $name) {
288
+ $isGroup = true;
289
+ $item['id'] = self::NAME_GROUP . self::ID_SEPARATOR . $name;
290
+ }
291
+ $item['text'] = (string) $node->title;
292
+ } else {
293
+ $isResource = true;
294
+ $item['id'] = self::NAME_RESOURCE . self::ID_SEPARATOR . $name;
295
+ $item['text'] = $this->__('%s', (string) $node->title);
296
+ }
297
+ $item['checked'] = false;
298
+ $item['sort_order'] = isset($node->sort_order) ? (string) $node->sort_order : 0;
299
+ }
300
+ if (isset($node->children)) {
301
+ $children = $node->children->children();
302
+ } else {
303
+ $children = $node->children();
304
+ }
305
+
306
+ if (empty($children)) {
307
+ /**
308
+ * Node doesn't have any child nodes
309
+ * and it should be skipped
310
+ */
311
+ return $item;
312
+ }
313
+
314
+ $item[self::NAME_CHILDREN] = array();
315
+
316
+ if ($isResource) {
317
+ if (self::TYPE_ATTRIBUTE == $this->_type) {
318
+ if (!$this->_addOperations($item, $node, $name)) {
319
+ return null;
320
+ }
321
+ } elseif (self::TYPE_PRIVILEGE == $this->_type) {
322
+ if (!$this->_addPrivileges($item, $node, $name)) {
323
+ return null;
324
+ }
325
+ }
326
+ }
327
+
328
+ /** @var $child Varien_Simplexml_Element */
329
+ foreach ($children as $child) {
330
+ if ($child->getName() != 'title' && $child->getName() != 'sort_order') {
331
+ if (!(string) $child->title) {
332
+ continue;
333
+ }
334
+
335
+ if ($level != 0) {
336
+ $subNode = $this->_getTreeNode($child, $level + 1);
337
+ if (!$subNode) {
338
+ continue;
339
+ }
340
+ //if sub-node check then check current node
341
+ if (!empty($subNode['checked'])) {
342
+ $item['checked'] = true;
343
+ }
344
+ $item[self::NAME_CHILDREN][] = $subNode;
345
+ } else {
346
+ $item = $this->_getTreeNode($child, $level + 1);
347
+ }
348
+ }
349
+ }
350
+ if (!empty($item[self::NAME_CHILDREN])) {
351
+ usort($item[self::NAME_CHILDREN], array($this, '_sortTree'));
352
+ } elseif ($isGroup) {
353
+ //skip empty group
354
+ return null;
355
+ }
356
+ return $item;
357
+ }
358
+
359
+ /**
360
+ * Add privileges
361
+ *
362
+ * @param array $item Tree node
363
+ * @param Varien_Simplexml_Element $node XML node
364
+ * @param string $name Resource name
365
+ * @return bool
366
+ */
367
+ protected function _addPrivileges(&$item, Varien_Simplexml_Element $node, $name)
368
+ {
369
+ $roleConfigNodeName = $this->getRole()->getConfigNodeName();
370
+ $possibleList = array();
371
+ if (isset($node->privileges)) {
372
+ $possibleRoles = $node->privileges->asArray();
373
+ if (isset($possibleRoles[$roleConfigNodeName])) {
374
+ $possibleList = $possibleRoles[$roleConfigNodeName];
375
+ }
376
+ }
377
+
378
+ if (!$possibleList) {
379
+ return false;
380
+ }
381
+
382
+ $cnt = 0;
383
+ foreach ($this->_existPrivileges as $key => $title) {
384
+ if (empty($possibleList[$key])) {
385
+ continue;
386
+ }
387
+ $checked = !empty($this->_resourcesPermissions[$name]['privileges'][$roleConfigNodeName][$key]);
388
+ $item['checked'] = $checked ? $checked : $item['checked'];
389
+ $subItem = array(
390
+ 'id' => self::NAME_PRIVILEGE . self::ID_SEPARATOR . $name . self::ID_SEPARATOR . $key,
391
+ 'text' => $title,
392
+ 'checked' => $checked,
393
+ 'sort_order' => ++$cnt,
394
+ );
395
+ $item[self::NAME_CHILDREN][] = $subItem;
396
+ }
397
+ return true;
398
+ }
399
+
400
+ /**
401
+ * Add operation
402
+ *
403
+ * @param array $item Tree node
404
+ * @param Varien_Simplexml_Element $node XML node
405
+ * @param string $name Resource name
406
+ * @return bool
407
+ */
408
+ protected function _addOperations(&$item, Varien_Simplexml_Element $node, $name)
409
+ {
410
+ $cnt = 0;
411
+ foreach ($this->_existOperations as $key => $title) {
412
+ $subItem = array(
413
+ 'id' => self::NAME_OPERATION . self::ID_SEPARATOR . $name . self::ID_SEPARATOR . $key,
414
+ 'text' => $title,
415
+ 'checked' => false,
416
+ 'sort_order' => ++$cnt,
417
+ );
418
+
419
+ if (!empty($this->_resourcesPermissions[$name]['operations'][$key]['attributes'])) {
420
+ if (!$this->_addAttribute($subItem, $node, $name, $key)) {
421
+ $cnt--;
422
+ continue;
423
+ }
424
+ } else {
425
+ $cnt--;
426
+ continue;
427
+ }
428
+ if (!empty($subItem['checked'])) {
429
+ $item['checked'] = true;
430
+ }
431
+ $item[self::NAME_CHILDREN][] = $subItem;
432
+ }
433
+ if (!$cnt) {
434
+ return false;
435
+ }
436
+ return true;
437
+ }
438
+
439
+ /**
440
+ * Add privileges
441
+ *
442
+ * @param array $item Tree node
443
+ * @param Varien_Simplexml_Element $node XML node
444
+ * @param string $name Node name
445
+ * @param string $privilege Privilege name
446
+ * @return bool
447
+ */
448
+ protected function _addAttribute(&$item, Varien_Simplexml_Element $node, $name, $privilege)
449
+ {
450
+ $cnt = 0;
451
+ foreach ($this->_resourcesPermissions[$name]['operations'][$privilege]['attributes'] as $key => $attribute) {
452
+ $title = $attribute['title'];
453
+ $status = $attribute['status'];
454
+
455
+ $checked = $status == Mage_Api2_Model_Acl_Global_Rule_Permission::TYPE_ALLOW;
456
+ $item['checked'] = $checked ? $checked : $item['checked'];
457
+ $item[self::NAME_CHILDREN][] = array(
458
+ 'id' => self::NAME_ATTRIBUTE . self::ID_SEPARATOR . $name . self::ID_SEPARATOR . $privilege
459
+ . self::ID_SEPARATOR . $key,
460
+ 'text' => $title,
461
+ 'checked' => $checked,
462
+ 'sort_order' => ++$cnt,
463
+ );
464
+ }
465
+
466
+ return true;
467
+ }
468
+
469
+ /**
470
+ * Compare two nodes of the Resource Tree
471
+ *
472
+ * @param array $a
473
+ * @param array $b
474
+ * @return int
475
+ */
476
+ protected function _sortTree($a, $b)
477
+ {
478
+ return $a['sort_order'] < $b['sort_order'] ? -1 : ($a['sort_order'] > $b['sort_order'] ? 1 : 0);
479
+ }
480
+
481
+ /**
482
+ * Set role
483
+ *
484
+ * @param Mage_Api2_Model_Acl_Global_Role $role
485
+ * @return Mage_Api2_Model_Acl_Global_Rule_Tree
486
+ */
487
+ public function setRole($role)
488
+ {
489
+ $this->_role = $role;
490
+ return $this;
491
+ }
492
+
493
+ /**
494
+ * Get role
495
+ *
496
+ * @return Mage_Api2_Model_Acl_Global_Role
497
+ */
498
+ public function getRole()
499
+ {
500
+ return $this->_role;
501
+ }
502
+
503
+ /**
504
+ * Set resources permissions
505
+ *
506
+ * @param array $resourcesPermissions
507
+ * @return Mage_Api2_Model_Acl_Global_Rule_Tree
508
+ */
509
+ public function setResourcesPermissions($resourcesPermissions)
510
+ {
511
+ $this->_resourcesPermissions = $resourcesPermissions;
512
+ return $this;
513
+ }
514
+
515
+ /**
516
+ * Get resources permissions
517
+ *
518
+ * @return array
519
+ */
520
+ public function getResourcesPermissions()
521
+ {
522
+ return $this->_resourcesPermissions;
523
+ }
524
+
525
+ /**
526
+ * Set has entity only attributes flag
527
+ *
528
+ * @param bool $hasEntityOnlyAttributes
529
+ * @return Mage_Api2_Model_Acl_Global_Rule_Tree
530
+ */
531
+ public function setHasEntityOnlyAttributes($hasEntityOnlyAttributes)
532
+ {
533
+ $this->_hasEntityOnlyAttributes = $hasEntityOnlyAttributes;
534
+ return $this;
535
+ }
536
+
537
+ /**
538
+ * Get has entity only attributes flag
539
+ *
540
+ * @return bool
541
+ */
542
+ public function getHasEntityOnlyAttributes()
543
+ {
544
+ return $this->_hasEntityOnlyAttributes;
545
+ }
546
+ }
app/code/core/Mage/Api2/Model/Acl/PermissionInterface.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 ACL resource permission interface
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ interface Mage_Api2_Model_Acl_PermissionInterface
35
+ {
36
+ /**
37
+ * Get ACL resources permissions
38
+ *
39
+ * Get permissions list with set permissions
40
+ *
41
+ * @return array
42
+ */
43
+ public function getResourcesPermissions();
44
+
45
+ /**
46
+ * Set filter value
47
+ *
48
+ * @param mixed $filterValue
49
+ * @return Mage_Api2_Model_Acl_PermissionInterface
50
+ */
51
+ public function setFilterValue($filterValue);
52
+ }
app/code/core/Mage/Api2/Model/Auth.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API User authentication model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Auth
35
+ {
36
+ /**
37
+ * Use this type if no authentication adapter is applied
38
+ */
39
+ const DEFAULT_USER_TYPE = 'guest';
40
+
41
+ /**
42
+ * Figure out API user type and create user model instance
43
+ *
44
+ * @param Mage_Api2_Model_Request $request
45
+ * @throws Exception
46
+ * @return Mage_Api2_Model_Auth_User_Abstract
47
+ */
48
+ public function authenticate(Mage_Api2_Model_Request $request)
49
+ {
50
+ /** @var $helper Mage_Api2_Helper_Data */
51
+ $helper = Mage::helper('api2/data');
52
+ $userTypes = $helper->getUserTypes();
53
+
54
+ if (!$userTypes) {
55
+ throw new Exception('No allowed user types found');
56
+ }
57
+ /** @var $authAdapter Mage_Api2_Model_Auth_Adapter */
58
+ $authAdapter = Mage::getModel('api2/auth_adapter');
59
+ $userParamsObj = $authAdapter->getUserParams($request);
60
+
61
+ if (!isset($userTypes[$userParamsObj->type])) {
62
+ throw new Mage_Api2_Exception(
63
+ 'Invalid user type or type is not allowed', Mage_Api2_Model_Server::HTTP_UNAUTHORIZED
64
+ );
65
+ }
66
+ /** @var $userModel Mage_Api2_Model_Auth_User_Abstract */
67
+ $userModel = Mage::getModel($userTypes[$userParamsObj->type]);
68
+
69
+ if (!$userModel instanceof Mage_Api2_Model_Auth_User_Abstract) {
70
+ throw new Exception('User model must to extend Mage_Api2_Model_Auth_User_Abstract');
71
+ }
72
+ // check user type consistency
73
+ if ($userModel->getType() != $userParamsObj->type) {
74
+ throw new Exception('User model type does not match appropriate type in config');
75
+ }
76
+ $userModel->setUserId($userParamsObj->id);
77
+
78
+ return $userModel;
79
+ }
80
+ }
app/code/core/Mage/Api2/Model/Auth/Adapter.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API Auth Adapter class
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Auth_Adapter
35
+ {
36
+ /**
37
+ * Adapter models
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_adapters = array();
42
+
43
+ /**
44
+ * Load adapters configuration and create adapters models
45
+ *
46
+ * @return Mage_Api2_Model_Auth_Adapter
47
+ * @throws Exception
48
+ */
49
+ protected function _initAdapters()
50
+ {
51
+ /** @var $helper Mage_Api2_Helper_Data */
52
+ $helper = Mage::helper('api2');
53
+
54
+ foreach ($helper->getAuthAdapters(true) as $adapterKey => $adapterParams) {
55
+ $adapterModel = Mage::getModel($adapterParams['model']);
56
+
57
+ if (!$adapterModel instanceof Mage_Api2_Model_Auth_Adapter_Abstract) {
58
+ throw new Exception('Authentication adapter must to extend Mage_Api2_Model_Auth_Adapter_Abstract');
59
+ }
60
+ $this->_adapters[$adapterKey] = $adapterModel;
61
+ }
62
+ if (!$this->_adapters) {
63
+ throw new Exception('No active authentication adapters found');
64
+ }
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * Process request and figure out an API user type and its identifier
70
+ *
71
+ * Returns stdClass object with two properties: type and id
72
+ *
73
+ * @param Mage_Api2_Model_Request $request
74
+ * @return stdClass
75
+ */
76
+ public function getUserParams(Mage_Api2_Model_Request $request)
77
+ {
78
+ $this->_initAdapters();
79
+
80
+ foreach ($this->_adapters as $adapterModel) {
81
+ /** @var $adapterModel Mage_Api2_Model_Auth_Adapter_Abstract */
82
+ if ($adapterModel->isApplicableToRequest($request)) {
83
+ $userParams = $adapterModel->getUserParams($request);
84
+
85
+ if (null !== $userParams->type) {
86
+ return $userParams;
87
+ }
88
+ throw new Mage_Api2_Exception('Can not determine user type', Mage_Api2_Model_Server::HTTP_UNAUTHORIZED);
89
+ }
90
+ }
91
+ return (object) array('type' => Mage_Api2_Model_Auth::DEFAULT_USER_TYPE, 'id' => null);
92
+ }
93
+ }
app/code/core/Mage/Api2/Model/Auth/Adapter/Abstract.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract class of authentication adapter
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Api2_Model_Auth_Adapter_Abstract
35
+ {
36
+ /**
37
+ * Process request and figure out an API user type and its identifier
38
+ *
39
+ * Returns stdClass object with two properties: type and id
40
+ *
41
+ * @param Mage_Api2_Model_Request $request
42
+ * @return stdClass
43
+ */
44
+ abstract public function getUserParams(Mage_Api2_Model_Request $request);
45
+
46
+ /**
47
+ * Check if request contains authentication info for adapter
48
+ *
49
+ * @param Mage_Api2_Model_Request $request
50
+ * @return boolean
51
+ */
52
+ abstract public function isApplicableToRequest(Mage_Api2_Model_Request $request);
53
+ }
app/code/core/Mage/Api2/Model/Auth/Adapter/Oauth.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * oAuth Authentication adapter
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Auth_Adapter_Oauth extends Mage_Api2_Model_Auth_Adapter_Abstract
35
+ {
36
+ /**
37
+ * Process request and figure out an API user type and its identifier
38
+ *
39
+ * Returns stdClass object with two properties: type and id
40
+ *
41
+ * @param Mage_Api2_Model_Request $request
42
+ * @return stdClass
43
+ */
44
+ public function getUserParams(Mage_Api2_Model_Request $request)
45
+ {
46
+ /** @var $oauthServer Mage_Oauth_Model_Server */
47
+ $oauthServer = Mage::getModel('oauth/server', $request);
48
+ $userParamsObj = (object) array('type' => null, 'id' => null);
49
+
50
+ try {
51
+ $token = $oauthServer->checkAccessRequest();
52
+ $userType = $token->getUserType();
53
+
54
+ if (Mage_Oauth_Model_Token::USER_TYPE_ADMIN == $userType) {
55
+ $userParamsObj->id = $token->getAdminId();
56
+ } else {
57
+ $userParamsObj->id = $token->getCustomerId();
58
+ }
59
+ $userParamsObj->type = $userType;
60
+ } catch (Exception $e) {
61
+ throw new Mage_Api2_Exception($oauthServer->reportProblem($e), Mage_Api2_Model_Server::HTTP_UNAUTHORIZED);
62
+ }
63
+ return $userParamsObj;
64
+ }
65
+
66
+ /**
67
+ * Check if request contains authentication info for adapter
68
+ *
69
+ * @param Mage_Api2_Model_Request $request
70
+ * @return boolean
71
+ */
72
+ public function isApplicableToRequest(Mage_Api2_Model_Request $request)
73
+ {
74
+ $headerValue = $request->getHeader('Authorization');
75
+
76
+ return $headerValue && 'oauth' === strtolower(substr($headerValue, 0, 5));
77
+ }
78
+ }
app/code/core/Mage/Api2/Model/Auth/User.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API auth user
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Auth_User
35
+ {
36
+ /**
37
+ * Get options in "key-value" format
38
+ *
39
+ * @param boolean $asOptionArray OPTIONAL If TRUE - return an options array, plain array - otherwise
40
+ * @return array
41
+ */
42
+ static public function getUserTypes($asOptionArray = false)
43
+ {
44
+ $userTypes = array();
45
+
46
+ /** @var $helper Mage_Api2_Helper_Data */
47
+ $helper = Mage::helper('api2');
48
+
49
+ foreach ($helper->getUserTypes() as $modelPath) {
50
+ /** @var $userModel Mage_Api2_Model_Auth_User_Abstract */
51
+ $userModel = Mage::getModel($modelPath);
52
+
53
+ if ($asOptionArray) {
54
+ $userTypes[] = array('value' => $userModel->getType(), 'label' => $userModel->getLabel());
55
+ } else {
56
+ $userTypes[$userModel->getType()] = $userModel->getLabel();
57
+ }
58
+ }
59
+ return $userTypes;
60
+ }
61
+ }
app/code/core/Mage/Api2/Model/Auth/User/Abstract.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 User Abstract Class
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Api2_Model_Auth_User_Abstract
35
+ {
36
+ /**
37
+ * Customer/Admin identifier
38
+ *
39
+ * @var int
40
+ */
41
+ protected $_userId;
42
+
43
+ /**
44
+ * User Role
45
+ *
46
+ * @var int
47
+ */
48
+ protected $_role;
49
+
50
+ /**
51
+ * Retrieve user human-readable label
52
+ *
53
+ * @return string
54
+ */
55
+ public function getLabel()
56
+ {
57
+ return $this->getType();
58
+ }
59
+
60
+ /**
61
+ * Retrieve user role
62
+ *
63
+ * @return int
64
+ */
65
+ abstract public function getRole();
66
+
67
+ /**
68
+ * Retrieve user type
69
+ *
70
+ * @return string
71
+ */
72
+ abstract public function getType();
73
+
74
+ /**
75
+ * Retrieve user identifier
76
+ *
77
+ * @return int
78
+ */
79
+ public function getUserId()
80
+ {
81
+ return $this->_userId;
82
+ }
83
+
84
+ /**
85
+ * Set user identifier
86
+ *
87
+ * @param int $userId User identifier
88
+ * @return Mage_Api2_Model_Auth_User_Abstract
89
+ */
90
+ public function setUserId($userId)
91
+ {
92
+ $this->_userId = $userId;
93
+
94
+ return $this;
95
+ }
96
+ }
app/code/core/Mage/Api2/Model/Auth/User/Admin.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 User Admin Class
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Auth_User_Admin extends Mage_Api2_Model_Auth_User_Abstract
35
+ {
36
+ /**
37
+ * User type
38
+ */
39
+ const USER_TYPE = 'admin';
40
+
41
+ /**
42
+ * Retrieve user human-readable label
43
+ *
44
+ * @return string
45
+ */
46
+ public function getLabel()
47
+ {
48
+ return Mage::helper('api2')->__('Admin');
49
+ }
50
+
51
+ /**
52
+ * Retrieve user role
53
+ *
54
+ * @return int
55
+ * @throws Exception
56
+ */
57
+ public function getRole()
58
+ {
59
+ if (!$this->_role) {
60
+ if (!$this->getUserId()) {
61
+ throw new Exception('Admin identifier is not set');
62
+ }
63
+
64
+ /** @var $collection Mage_Api2_Model_Resource_Acl_Global_Role_Collection */
65
+ $collection = Mage::getModel('api2/acl_global_role')->getCollection();
66
+ $collection->addFilterByAdminId($this->getUserId());
67
+
68
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
69
+ $role = $collection->getFirstItem();
70
+ if (!$role->getId()) {
71
+ throw new Exception('Admin role not found');
72
+ }
73
+
74
+ $this->setRole($role->getId());
75
+ }
76
+
77
+ return $this->_role;
78
+ }
79
+
80
+ /**
81
+ * Retrieve user type
82
+ *
83
+ * @return string
84
+ */
85
+ public function getType()
86
+ {
87
+ return self::USER_TYPE;
88
+ }
89
+
90
+ /**
91
+ * Set user role
92
+ *
93
+ * @param int $role
94
+ * @return Mage_Api2_Model_Auth_User_Admin
95
+ * @throws Exception
96
+ */
97
+ public function setRole($role)
98
+ {
99
+ if ($this->_role) {
100
+ throw new Exception('Admin role has been already set');
101
+ }
102
+ $this->_role = $role;
103
+
104
+ return $this;
105
+ }
106
+ }
app/code/core/Mage/Api2/Model/Auth/User/Customer.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 User Customer Class
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Auth_User_Customer extends Mage_Api2_Model_Auth_User_Abstract
35
+ {
36
+ /**
37
+ * User type
38
+ */
39
+ const USER_TYPE = 'customer';
40
+
41
+ /**
42
+ * Retrieve user human-readable label
43
+ *
44
+ * @return string
45
+ */
46
+ public function getLabel()
47
+ {
48
+ return Mage::helper('api2')->__('Customer');
49
+ }
50
+
51
+ /**
52
+ * Retrieve user type
53
+ *
54
+ * @return string
55
+ */
56
+ public function getType()
57
+ {
58
+ return self::USER_TYPE;
59
+ }
60
+
61
+ /**
62
+ * Retrieve user role
63
+ *
64
+ * @return int
65
+ */
66
+ public function getRole()
67
+ {
68
+ if (!$this->_role) {
69
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
70
+ $role = Mage::getModel('api2/acl_global_role')->load(Mage_Api2_Model_Acl_Global_Role::ROLE_CUSTOMER_ID);
71
+ if (!$role->getId()) {
72
+ throw new Exception('Customer role not found');
73
+ }
74
+
75
+ $this->_role = Mage_Api2_Model_Acl_Global_Role::ROLE_CUSTOMER_ID;
76
+ }
77
+
78
+ return $this->_role;
79
+ }
80
+ }
app/code/core/Mage/Api2/Model/Auth/User/Guest.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 User Guest Class
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Auth_User_Guest extends Mage_Api2_Model_Auth_User_Abstract
35
+ {
36
+ /**
37
+ * User type
38
+ */
39
+ const USER_TYPE = 'guest';
40
+
41
+ /**
42
+ * Retrieve user human-readable label
43
+ *
44
+ * @return string
45
+ */
46
+ public function getLabel()
47
+ {
48
+ return Mage::helper('api2')->__('Guest');
49
+ }
50
+
51
+ /**
52
+ * Retrieve user type
53
+ *
54
+ * @return string
55
+ */
56
+ public function getType()
57
+ {
58
+ return self::USER_TYPE;
59
+ }
60
+
61
+ /**
62
+ * Retrieve user role
63
+ *
64
+ * @return int
65
+ */
66
+ public function getRole()
67
+ {
68
+ if (!$this->_role) {
69
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
70
+ $role = Mage::getModel('api2/acl_global_role')->load(Mage_Api2_Model_Acl_Global_Role::ROLE_GUEST_ID);
71
+ if (!$role->getId()) {
72
+ throw new Exception('Guest role not found');
73
+ }
74
+
75
+ $this->_role = Mage_Api2_Model_Acl_Global_Role::ROLE_GUEST_ID;
76
+ }
77
+
78
+ return $this->_role;
79
+ }
80
+ }
app/code/core/Mage/Api2/Model/Config.php ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice api2 config model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Config extends Varien_Simplexml_Config
35
+ {
36
+ /**
37
+ * Node name of resource groups
38
+ */
39
+ const NODE_RESOURCE_GROUPS = 'resource_groups';
40
+
41
+ /**
42
+ * Id for config cache
43
+ */
44
+ const CACHE_ID = 'config_api2';
45
+
46
+ /**
47
+ * Tag name for config cache
48
+ */
49
+ const CACHE_TAG = 'CONFIG_API2';
50
+
51
+ /**
52
+ * Is resources added to group
53
+ *
54
+ * @var boolean
55
+ */
56
+ protected $_resourcesGrouped = false;
57
+
58
+ /**
59
+ * Constructor
60
+ * Initializes XML for this configuration
61
+ * Local cache configuration
62
+ *
63
+ * @param string|Varien_Simplexml_Element|null $sourceData
64
+ */
65
+ public function __construct($sourceData = null)
66
+ {
67
+ parent::__construct($sourceData);
68
+
69
+ $canUserCache = Mage::app()->useCache('config');
70
+ if ($canUserCache) {
71
+ $this->setCacheId(self::CACHE_ID)
72
+ ->setCacheTags(array(self::CACHE_TAG))
73
+ ->setCacheChecksum(null)
74
+ ->setCache(Mage::app()->getCache());
75
+
76
+ if ($this->loadCache()) {
77
+ return;
78
+ }
79
+ }
80
+
81
+ // Load data of config files api2.xml
82
+ $config = Mage::getConfig()->loadModulesConfiguration('api2.xml');
83
+ $this->setXml($config->getNode('api2'));
84
+
85
+ if ($canUserCache) {
86
+ $this->saveCache();
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Fetch all routes of the given api type from config files api2.xml
92
+ *
93
+ * @param string $apiType
94
+ * @throws Mage_Api2_Exception
95
+ * @return array
96
+ */
97
+ public function getRoutes($apiType)
98
+ {
99
+ /** @var $helper Mage_Api2_Helper_Data */
100
+ $helper = Mage::helper('api2');
101
+ if (!$helper->isApiTypeSupported($apiType)) {
102
+ throw new Mage_Api2_Exception(sprintf('API type "%s" is not supported', $apiType),
103
+ Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
104
+ }
105
+
106
+ $routes = array();
107
+ foreach ($this->getResources() as $resourceKey => $resource) {
108
+ if (!$resource->routes) {
109
+ continue;
110
+ }
111
+
112
+ /** @var $routes Varien_Simplexml_Element */
113
+ foreach ($resource->routes->children() as $route) {
114
+ $arguments = array(
115
+ Mage_Api2_Model_Route_Abstract::PARAM_ROUTE => (string)$route->route,
116
+ Mage_Api2_Model_Route_Abstract::PARAM_DEFAULTS => array(
117
+ 'model' => (string)$resource->model,
118
+ 'type' => (string)$resourceKey,
119
+ 'action_type' => (string)$route->action_type
120
+ )
121
+ );
122
+
123
+ $routes[] = Mage::getModel('api2/route_' . $apiType, $arguments);
124
+ }
125
+ }
126
+ return $routes;
127
+ }
128
+
129
+ /**
130
+ * Retrieve all resources from config files api2.xml
131
+ *
132
+ * @return Varien_Simplexml_Element
133
+ */
134
+ public function getResources()
135
+ {
136
+ return $this->getNode('resources')->children();
137
+ }
138
+
139
+ /**
140
+ * Retrieve all resources types
141
+ *
142
+ * @return array
143
+ */
144
+ public function getResourcesTypes()
145
+ {
146
+ $list = array();
147
+
148
+ foreach ($this->getResources() as $resourceType => $resourceCfg) {
149
+ $list[] = (string) $resourceType;
150
+ }
151
+ return $list;
152
+ }
153
+
154
+ /**
155
+ * Retrieve all resource groups from config files api2.xml
156
+ *
157
+ * @return Varien_Simplexml_Element|boolean
158
+ */
159
+ public function getResourceGroups()
160
+ {
161
+ $groups = $this->getXpath('//' . self::NODE_RESOURCE_GROUPS);
162
+ if (!$groups) {
163
+ return false;
164
+ }
165
+
166
+ /** @var $groups Varien_Simplexml_Element */
167
+ $groups = $groups[0];
168
+
169
+ if (!$this->_resourcesGrouped) {
170
+ /** @var $node Varien_Simplexml_Element */
171
+ foreach ($this->getResources() as $node) {
172
+ $result = $node->xpath('group');
173
+ if (!$result) {
174
+ continue;
175
+ }
176
+ $groupName = (string) $result[0];
177
+ if ($groupName) {
178
+ $result = $groups->xpath('.//' . $groupName);
179
+ if (!$result) {
180
+ continue;
181
+ }
182
+
183
+ /** @var $group Varien_Simplexml_Element */
184
+ $group = $result[0];
185
+
186
+ if (!isset($group->children)) {
187
+ $children = new Varien_Simplexml_Element('<children />');
188
+ } else {
189
+ $children = $group->children;
190
+ }
191
+ $node->resource = 1;
192
+ $children->appendChild($node);
193
+ $group->appendChild($children);
194
+ }
195
+ }
196
+ }
197
+ return $groups;
198
+ }
199
+
200
+ /**
201
+ * Retrieve resource group from config files api2.xml
202
+ *
203
+ * @param string $name
204
+ * @return Mage_Core_Model_Config_Element|boolean
205
+ */
206
+ public function getResourceGroup($name)
207
+ {
208
+ $group = $this->getResourceGroups()->xpath('.//' . $name);
209
+ if (!$group) {
210
+ return false;
211
+ }
212
+ return $group[0];
213
+ }
214
+
215
+ /**
216
+ * Retrieve resource by type (node)
217
+ *
218
+ * @param string $node
219
+ * @return Varien_Simplexml_Element|boolean
220
+ */
221
+ public function getResource($node)
222
+ {
223
+ return $this->getNode('resources/' . $node);
224
+ }
225
+
226
+ /**
227
+ * Retrieve resource attributes
228
+ *
229
+ * @param string $node
230
+ * @return array
231
+ */
232
+ public function getResourceAttributes($node)
233
+ {
234
+ $attributes = $this->getNode('resources/' . $node . '/attributes');
235
+ return $attributes ? $attributes->asCanonicalArray() : array();
236
+ }
237
+
238
+ /**
239
+ * Get excluded attributes of API resource
240
+ *
241
+ * @param string $resource
242
+ * @param string $userType
243
+ * @param string $operation
244
+ * @return array
245
+ */
246
+ public function getResourceExcludedAttributes($resource, $userType, $operation)
247
+ {
248
+ $node = $this->getNode('resources/' . $resource . '/exclude_attributes/' . $userType . '/' . $operation);
249
+ $exclAttributes = array();
250
+
251
+ if ($node) {
252
+ foreach ($node->children() as $attribute => $status) {
253
+ if ((string) $status) {
254
+ $exclAttributes[] = $attribute;
255
+ }
256
+ }
257
+ }
258
+ return $exclAttributes;
259
+ }
260
+
261
+ /**
262
+ * Get forced attributes of API resource
263
+ *
264
+ * @param string $resource
265
+ * @param string $userType
266
+ * @return array
267
+ */
268
+ public function getResourceForcedAttributes($resource, $userType)
269
+ {
270
+ $node = $this->getNode('resources/' . $resource . '/force_attributes/' . $userType);
271
+ $forcedAttributes = array();
272
+
273
+ if ($node) {
274
+ foreach ($node->children() as $attribute => $status) {
275
+ if ((string) $status) {
276
+ $forcedAttributes[] = $attribute;
277
+ }
278
+ }
279
+ }
280
+ return $forcedAttributes;
281
+ }
282
+
283
+ /**
284
+ * Get included attributes
285
+ *
286
+ * @param string $resource API resource ID
287
+ * @param string $userType API user type
288
+ * @param string $operationType Type of operation: one of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
289
+ * @return array
290
+ */
291
+ public function getResourceIncludedAttributes($resource, $userType, $operationType)
292
+ {
293
+ $node = $this->getNode('resources/' . $resource . '/include_attributes/' . $userType . '/' . $operationType);
294
+ $inclAttributes = array();
295
+
296
+ if ($node) {
297
+ foreach ($node->children() as $attribute => $status) {
298
+ if ((string) $status) {
299
+ $inclAttributes[] = $attribute;
300
+ }
301
+ }
302
+ }
303
+ return $inclAttributes;
304
+ }
305
+
306
+ /**
307
+ * Get entity only attributes
308
+ *
309
+ * @param string $resource API resource ID
310
+ * @param string $userType API user type
311
+ * @param string $operationType Type of operation: one of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
312
+ * @return array
313
+ */
314
+ public function getResourceEntityOnlyAttributes($resource, $userType, $operationType)
315
+ {
316
+ $node = $this->getNode('resources/' . $resource . '/entity_only_attributes/' . $userType . '/' .
317
+ $operationType);
318
+ $entityOnlyAttributes = array();
319
+
320
+ if ($node) {
321
+ foreach ($node->children() as $attribute => $status) {
322
+ if ((string) $status) {
323
+ $entityOnlyAttributes[] = $attribute;
324
+ }
325
+ }
326
+ }
327
+ return $entityOnlyAttributes;
328
+ }
329
+
330
+ /**
331
+ * Retrieve resource working model
332
+ *
333
+ * @param string $node
334
+ * @return string
335
+ */
336
+ public function getResourceWorkingModel($node)
337
+ {
338
+ return (string)$this->getNode('resources/' . $node . '/working_model');
339
+ }
340
+
341
+ /**
342
+ * Get resource allowed versions sorted in reverse order
343
+ *
344
+ * @param string $node
345
+ * @return array
346
+ * @throws Exception
347
+ */
348
+ public function getVersions($node)
349
+ {
350
+ $element = $this->getNode('resources/' . $node . '/versions');
351
+ if (!$element) {
352
+ throw new Exception(
353
+ sprintf('Resource "%s" does not have node <versions> in config.', htmlspecialchars($node))
354
+ );
355
+ }
356
+
357
+ $versions = explode(',', (string)$element);
358
+ if (count(array_filter($versions, 'is_numeric')) != count($versions)) {
359
+ throw new Exception(sprintf('Invalid resource "%s" versions in config.', htmlspecialchars($node)));
360
+ }
361
+
362
+ rsort($versions, SORT_NUMERIC);
363
+
364
+ return $versions;
365
+ }
366
+
367
+ /**
368
+ * Retrieve resource model
369
+ *
370
+ * @param string $node
371
+ * @return string
372
+ */
373
+ public function getResourceModel($node)
374
+ {
375
+ return (string)$this->getNode('resources/' . $node . '/model');
376
+ }
377
+
378
+ /**
379
+ * Retrieve API user privileges for specified resource
380
+ *
381
+ * @param string $resource
382
+ * @param string $userType
383
+ * @return array
384
+ */
385
+ public function getResourceUserPrivileges($resource, $userType)
386
+ {
387
+ $attributes = $this->getNode('resources/' . $resource . '/privileges/' . $userType);
388
+ return $attributes ? $attributes->asCanonicalArray() : array();
389
+ }
390
+
391
+ /**
392
+ * Retrieve resource subresources
393
+ *
394
+ * @param string $node
395
+ * @return array
396
+ */
397
+ public function getResourceSubresources($node)
398
+ {
399
+ $subresources = $this->getNode('resources/' . $node . '/subresources');
400
+ return $subresources ? $subresources->asCanonicalArray() : array();
401
+ }
402
+
403
+ /**
404
+ * Get validation config by validator type
405
+ *
406
+ * @param string $resourceType
407
+ * @param string $validatorType
408
+ * @return array
409
+ */
410
+ public function getValidationConfig($resourceType, $validatorType)
411
+ {
412
+ $config = $this->getNode('resources/' . $resourceType . '/validators/' . $validatorType);
413
+ return $config ? $config->asCanonicalArray() : array();
414
+ }
415
+
416
+ /**
417
+ * Get latest version of resource model. If second arg is specified - use it as a limiter
418
+ *
419
+ * @param string $resourceType Resource type
420
+ * @param int $lowerOrEqualsTo OPTIONAL If specified - return version equal or lower to
421
+ * @return int
422
+ */
423
+ public function getResourceLastVersion($resourceType, $lowerOrEqualsTo = null)
424
+ {
425
+ $availVersions = $this->getVersions($resourceType); // already ordered in reverse order
426
+ $useVersion = reset($availVersions);
427
+
428
+ if (null !== $lowerOrEqualsTo) {
429
+ foreach ($availVersions as $availVersion) {
430
+ if ($availVersion <= $lowerOrEqualsTo) {
431
+ $useVersion = $availVersion;
432
+ break;
433
+ }
434
+ }
435
+ }
436
+ return (int)$useVersion;
437
+ }
438
+
439
+ /**
440
+ * Get route with Mage_Api2_Model_Resource::ACTION_TYPE_ENTITY type
441
+ *
442
+ * @param string $node
443
+ * @return string
444
+ */
445
+ public function getRouteWithEntityTypeAction($node)
446
+ {
447
+ return (string)$this->getNode('resources/' . $node . '/routes/route_entity/route');
448
+ }
449
+ }
app/code/core/Mage/Api2/Model/Dispatcher.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice api2 dispatcher model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Dispatcher
35
+ {
36
+ /**
37
+ * Template for retrieve resource class name
38
+ */
39
+ const RESOURCE_CLASS_TEMPLATE = ':resource_:api_:user_v:version';
40
+
41
+ /**
42
+ * API User object
43
+ *
44
+ * @var Mage_Api2_Model_Auth_User_Abstract
45
+ */
46
+ protected $_apiUser;
47
+
48
+ /**
49
+ * Instantiate resource class, set parameters to the instance, run resource internal dispatch method
50
+ *
51
+ * @param Mage_Api2_Model_Request $request
52
+ * @param Mage_Api2_Model_Response $response
53
+ * @return Mage_Api2_Model_Dispatcher
54
+ * @throws Mage_Api2_Exception
55
+ */
56
+ public function dispatch(Mage_Api2_Model_Request $request, Mage_Api2_Model_Response $response)
57
+ {
58
+ if (!$request->getModel() || !$request->getApiType()) {
59
+ throw new Mage_Api2_Exception(
60
+ 'Request does not contains all necessary data', Mage_Api2_Model_Server::HTTP_BAD_REQUEST
61
+ );
62
+ }
63
+ $model = self::loadResourceModel(
64
+ $request->getModel(),
65
+ $request->getApiType(),
66
+ $this->getApiUser()->getType(),
67
+ $this->getVersion($request->getResourceType(), $request->getVersion())
68
+ );
69
+
70
+ $model->setRequest($request);
71
+ $model->setResponse($response);
72
+ $model->setApiUser($this->getApiUser());
73
+
74
+ $model->dispatch();
75
+
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Pack resource model class path from components and try to load it
81
+ *
82
+ * @param string $apiType API type
83
+ * @param string $userType API User type (e.g. admin, customer, guest)
84
+ * @param int $version Requested version
85
+ * @return Mage_Api2_Model_Resource
86
+ * @throws Mage_Api2_Exception
87
+ */
88
+ public static function loadResourceModel($model, $apiType, $userType, $version)
89
+ {
90
+ $class = strtr(
91
+ self::RESOURCE_CLASS_TEMPLATE,
92
+ array(':resource' => $model, ':api' => $apiType, ':user' => $userType, ':version' => $version)
93
+ );
94
+
95
+ try {
96
+ /** @var $modelObj Mage_Api2_Model_Resource */
97
+ $modelObj = Mage::getModel($class);
98
+ } catch (Exception $e) {
99
+ // getModel() throws exception when in application is in development mode - skip it to next check
100
+ }
101
+ if (empty($modelObj) || !$modelObj instanceof Mage_Api2_Model_Resource) {
102
+ throw new Mage_Api2_Exception('Resource not found', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
103
+ }
104
+ return $modelObj;
105
+ }
106
+
107
+ /**
108
+ * Set API user object
109
+ *
110
+ * @param Mage_Api2_Model_Auth_User_Abstract $apiUser
111
+ * @return Mage_Api2_Model_Dispatcher
112
+ */
113
+ public function setApiUser(Mage_Api2_Model_Auth_User_Abstract $apiUser)
114
+ {
115
+ $this->_apiUser = $apiUser;
116
+
117
+ return $this;
118
+ }
119
+
120
+ /**
121
+ * Get API user object
122
+ *
123
+ * @return Mage_Api2_Model_Auth_User_Abstract
124
+ */
125
+ public function getApiUser()
126
+ {
127
+ if (!$this->_apiUser) {
128
+ throw new Exception('API user is not set.');
129
+ }
130
+
131
+ return $this->_apiUser;
132
+ }
133
+
134
+ /**
135
+ * Get correct version of the resource model
136
+ *
137
+ * @param string $resourceType
138
+ * @param string|bool $requestedVersion
139
+ * @return int
140
+ * @throws Mage_Api2_Exception
141
+ */
142
+ public function getVersion($resourceType, $requestedVersion)
143
+ {
144
+ if (false !== $requestedVersion && !preg_match('/^[1-9]\d*$/', $requestedVersion)) {
145
+ throw new Mage_Api2_Exception(
146
+ sprintf('Invalid version "%s" requested.', htmlspecialchars($requestedVersion)),
147
+ Mage_Api2_Model_Server::HTTP_BAD_REQUEST
148
+ );
149
+ }
150
+ return $this->getConfig()->getResourceLastVersion($resourceType, $requestedVersion);
151
+ }
152
+
153
+ /**
154
+ * Get config
155
+ *
156
+ * @return Mage_Api2_Model_Config
157
+ */
158
+ public function getConfig()
159
+ {
160
+ return Mage::getModel('api2/config');
161
+ }
162
+ }
app/code/core/Mage/Api2/Model/Multicall.php ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 model for multiple internal calls to subresources of specified resource
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Multicall
35
+ {
36
+
37
+ /**
38
+ * @var Mage_Api2_Model_Request
39
+ */
40
+ protected $_parentCallRequest;
41
+
42
+ /**
43
+ * @var string
44
+ */
45
+ protected $_parentResourceId;
46
+
47
+ /**
48
+ * Multicall to subresources of specified resource
49
+ *
50
+ * @param string $parentResourceId
51
+ * @param string $parentResourceName
52
+ * @param Mage_Api2_Model_Request $parentCallRequest
53
+ * @return Mage_Api2_Model_Response
54
+ */
55
+ public function call($parentResourceId, $parentResourceName, Mage_Api2_Model_Request $parentCallRequest)
56
+ {
57
+ $this->_parentResourceId = $parentResourceId;
58
+ $this->_parentCallRequest = $parentCallRequest;
59
+ $subresources = $this->_getDeclaredSubresources($parentResourceName);
60
+ foreach ($subresources as $subresource) {
61
+ $this->_callSubresource($subresource);
62
+ }
63
+
64
+ return $this->_getResponse();
65
+ }
66
+
67
+ /**
68
+ * Make call to specified subresource with data from request
69
+ *
70
+ * @param Mage_Core_Model_Config_Element $subresource
71
+ * @return Mage_Api2_Model_Multicall
72
+ */
73
+ protected function _callSubresource($subresource)
74
+ {
75
+ $bodyParams = $this->_getRequest()->getBodyParams();
76
+ // check if subresource data exists in request
77
+ $requestParamName = (string)$subresource->request_param_name;
78
+ if (!(is_array($bodyParams) && array_key_exists($requestParamName, $bodyParams)
79
+ && is_array($bodyParams[$requestParamName]))
80
+ ) {
81
+ return $this;
82
+ }
83
+ // make internal call
84
+ $subresourceType = (string)$subresource->type;
85
+ $requestData = $bodyParams[$requestParamName];
86
+ switch ($subresourceType) {
87
+ case 'collection':
88
+ foreach ($requestData as $subresourceData) {
89
+ $this->_internalCall($subresource, $subresourceData);
90
+ }
91
+ break;
92
+ case 'instance':
93
+ default:
94
+ $this->_internalCall($subresource, $requestData);
95
+ break;
96
+ }
97
+ return $this;
98
+ }
99
+
100
+ /**
101
+ * Make internal call to specified subresource on with specified data via API2 server
102
+ *
103
+ * @param Mage_Core_Model_Config_Element $subresource
104
+ * @param array $requestData
105
+ * @throws Mage_Api2_Exception
106
+ * @return Mage_Api2_Model_Multicall
107
+ */
108
+ protected function _internalCall($subresource, $requestData)
109
+ {
110
+ try {
111
+ if (!is_array($requestData)) {
112
+ throw new Mage_Api2_Exception('Invalid data format', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
113
+ }
114
+ $subresourceIdKey = (string)$subresource->id_param_name;
115
+ /** @var $server Mage_Api2_Model_Server */
116
+ $server = Mage::getSingleton('api2/server');
117
+
118
+ // create subresource item before linking it to main resource
119
+ if (!array_key_exists($subresourceIdKey, $requestData)) {
120
+ $subresourceCreateResourceName = (string)$subresource->create_resource_name;
121
+ $internalRequest = $this->_prepareRequest($subresourceCreateResourceName, $requestData);
122
+ /** @var $internalCreateResponse Mage_Api2_Model_Response */
123
+ $internalCreateResponse = Mage::getModel('api2/response');
124
+ $server->internalCall($internalRequest, $internalCreateResponse);
125
+ $createdSubresourceInstanceId = $this->_getCreatedResourceId($internalCreateResponse);
126
+ if (empty($createdSubresourceInstanceId)) {
127
+ throw new Mage_Api2_Exception('Error during subresource creation',
128
+ Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
129
+ }
130
+ $requestData[$subresourceIdKey] = $createdSubresourceInstanceId;
131
+ }
132
+
133
+ // link subresource to main resource
134
+ $subresourceName = (string)$subresource->name;
135
+ $parentResourceIdFieldName = (string)$subresource->parent_resource_id_field_name;
136
+ $internalRequest = $this->_prepareRequest($subresourceName, $requestData, $parentResourceIdFieldName);
137
+
138
+ /** @var $internalResponse Mage_Api2_Model_Response */
139
+ $internalResponse = Mage::getModel('api2/response');
140
+ $server->internalCall($internalRequest, $internalResponse);
141
+ } catch (Exception $e) {
142
+ // TODO: implement strict mode
143
+ Mage::logException($e);
144
+ $this->_getResponse()->setException($e);
145
+ // TODO: Refactor partial success idintification process
146
+ $this->_getResponse()->setHttpResponseCode(Mage_Api2_Model_Server::HTTP_CREATED);
147
+ }
148
+
149
+ if (isset($internalCreateResponse)) {
150
+ $this->_aggregateResponse($internalCreateResponse);
151
+ }
152
+ if (isset($internalResponse)) {
153
+ $this->_aggregateResponse($internalResponse);
154
+ }
155
+
156
+ return $this;
157
+ }
158
+
159
+ /**
160
+ * Prepare internal request
161
+ *
162
+ * @param string $subresourceName
163
+ * @param array $data
164
+ * @param string|null $parentResourceIdFieldName
165
+ * @return Mage_Api2_Model_Request_Internal
166
+ */
167
+ protected function _prepareRequest($subresourceName, $data, $parentResourceIdFieldName = null)
168
+ {
169
+ $subresourceUri = $this->_createSubresourceUri($subresourceName, $parentResourceIdFieldName);
170
+ /** @var $internalRequest Mage_Api2_Model_Request_Internal */
171
+ $internalRequest = Mage::getModel('api2/request_internal');
172
+ $internalRequest->setRequestUri($subresourceUri);
173
+ $internalRequest->setBodyParams($data);
174
+ $internalRequest->setMethod('POST');
175
+ return $internalRequest;
176
+ }
177
+
178
+ /**
179
+ * Generate subresource uri
180
+ *
181
+ * @param string $subresourceName
182
+ * @param string $parentResourceIdFieldName
183
+ * @return string
184
+ */
185
+ protected function _createSubresourceUri($subresourceName, $parentResourceIdFieldName = null)
186
+ {
187
+ /** @var $apiTypeRoute Mage_Api2_Model_Route_ApiType */
188
+ $apiTypeRoute = Mage::getModel('api2/route_apiType');
189
+
190
+ $chain = $apiTypeRoute->chain(
191
+ new Zend_Controller_Router_Route($this->_getConfig()->getMainRoute($subresourceName))
192
+ );
193
+ $params = array();
194
+ $params['api_type'] = 'rest';
195
+ if (null !== $parentResourceIdFieldName) {
196
+ $params[$parentResourceIdFieldName] = $this->_parentResourceId;
197
+ }
198
+ $uri = $chain->assemble($params);
199
+
200
+ return '/' . $uri;
201
+ }
202
+
203
+ /**
204
+ * Retrieve list of subresources declared in configuration
205
+ *
206
+ * @param string $parentResourceName
207
+ * @return array
208
+ */
209
+ protected function _getDeclaredSubresources($parentResourceName)
210
+ {
211
+ return $this->_getConfig()->getResourceSubresources($parentResourceName);
212
+ }
213
+
214
+ /**
215
+ * Retrieve API2 config
216
+ *
217
+ * @return Mage_Api2_Model_Config
218
+ */
219
+ protected function _getConfig()
220
+ {
221
+ return Mage::getSingleton('api2/config');
222
+ }
223
+
224
+ /**
225
+ * Retrieve global response
226
+ *
227
+ * @return Mage_Api2_Model_Response
228
+ */
229
+ protected function _getResponse()
230
+ {
231
+ return Mage::getSingleton('api2/response');
232
+ }
233
+
234
+ /**
235
+ * Retrieve parent request
236
+ *
237
+ * @return Mage_Api2_Model_Request
238
+ */
239
+ protected function _getRequest()
240
+ {
241
+ return $this->_parentCallRequest;
242
+ }
243
+
244
+ /**
245
+ * Add internal call response to global response
246
+ *
247
+ * @param Mage_Api2_Model_Response $response
248
+ */
249
+ protected function _aggregateResponse(Mage_Api2_Model_Response $response)
250
+ {
251
+ if ($response->isException()) {
252
+ $errors = $response->getException();
253
+ // @TODO: add subresource prefix to error messages
254
+ foreach ($errors as $error) {
255
+ $this->_getResponse()->setException($error);
256
+ }
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Retrieve created resource id from response
262
+ *
263
+ * @param Mage_Api2_Model_Response $response
264
+ * @return string|int
265
+ */
266
+ protected function _getCreatedResourceId($response)
267
+ {
268
+ $resourceId = 0;
269
+ $headers = $response->getHeaders();
270
+ foreach ($headers as $header) {
271
+ if ($header['name'] == 'Location') {
272
+ list($resourceId) = array_reverse(explode('/', $header['value']));
273
+ break;
274
+ }
275
+ }
276
+ return $resourceId;
277
+ }
278
+ }
app/code/core/Mage/Api2/Model/Observer.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 observer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Observer
35
+ {
36
+ /**
37
+ * Save relation of admin user to API2 role
38
+ *
39
+ * @param Varien_Event_Observer $observer
40
+ * @return void
41
+ */
42
+ public function saveAdminToRoleRelation(Varien_Event_Observer $observer)
43
+ {
44
+ /** @var $user Mage_Admin_Model_User Object */
45
+ $user = $observer->getObject();
46
+
47
+ if ($user->hasData('api2_roles')) {
48
+ $roles = $user->getData('api2_roles');
49
+
50
+ if (!is_array($roles) || !isset($roles[0])) {
51
+ throw new Exception('API2 roles property has wrong data format.');
52
+ }
53
+
54
+ /** @var $resourceModel Mage_Api2_Model_Resource_Acl_Global_Role */
55
+ $resourceModel = Mage::getResourceModel('api2/acl_global_role');
56
+ $resourceModel->saveAdminToRoleRelation($user->getId(), $roles[0]);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * After save attribute if it is not visible on front remove it from Attribute ACL
62
+ *
63
+ * @param Varien_Event_Observer $observer
64
+ * @return Mage_Api2_Model_Observer
65
+ */
66
+ public function catalogAttributeSaveAfter(Varien_Event_Observer $observer)
67
+ {
68
+ /** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
69
+ $attribute = $observer->getEvent()->getAttribute();
70
+ if ($attribute->getIsUserDefined() && $attribute->dataHasChangedFor('is_visible_on_front')
71
+ && !$attribute->getIsVisibleOnFront()) {
72
+ /** @var $collection Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection */
73
+ $collection = Mage::getResourceModel('api2/acl_filter_attribute_collection');
74
+ /** @var $aclFilter Mage_Api2_Model_Acl_Filter_Attribute */
75
+ foreach ($collection as $aclFilter) {
76
+ if ($aclFilter->getResourceId() != Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL) {
77
+ $allowedAttributes = explode(',', $aclFilter->getAllowedAttributes());
78
+ $allowedAttributes = array_diff($allowedAttributes, array($attribute->getAttributeCode()));
79
+ $aclFilter->setAllowedAttributes(implode(',', $allowedAttributes))->save();
80
+ }
81
+ }
82
+ }
83
+
84
+ return $this;
85
+ }
86
+ }
app/code/core/Mage/Api2/Model/Renderer.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice API2 renderer factory model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Api2_Model_Renderer
35
+ {
36
+ /**
37
+ * Get Renderer of given type
38
+ *
39
+ * @param array|string $acceptTypes
40
+ * @throws Mage_Api2_Exception
41
+ * @throws Exception
42
+ * @return Mage_Api2_Model_Renderer_Interface
43
+ */
44
+ public static function factory($acceptTypes)
45
+ {
46
+ /** @var $helper Mage_Api2_Helper_Data */
47
+ $helper = Mage::helper('api2');
48
+ $adapters = $helper->getResponseRenderAdapters();
49
+
50
+ if (!is_array($acceptTypes)) {
51
+ $acceptTypes = array($acceptTypes);
52
+ }
53
+
54
+ $type = null;
55
+ $adapterPath = null;
56
+ foreach ($acceptTypes as $type) {
57
+ foreach ($adapters as $item) {
58
+ $itemType = $item->type;
59
+ if ($type == $itemType
60
+ || $type == current(explode('/', $itemType)) . '/*' || $type == '*/*'
61
+ ) {
62
+ $adapterPath = $item->model;
63
+ break 2;
64
+ }
65
+ }
66
+ }
67
+
68
+ //if server can't respond in any of accepted types it SHOULD send 406(not acceptable)
69
+ if (null === $adapterPath) {
70
+ throw new Mage_Api2_Exception(
71
+ 'Server can not understand Accept HTTP header media type.',
72
+ Mage_Api2_Model_Server::HTTP_NOT_ACCEPTABLE
73
+ );
74
+ }
75
+
76
+ $adapter = Mage::getModel($adapterPath);
77
+ if (!$adapter) {
78
+ throw new Exception(sprintf('Response renderer adapter for content type "%s" not found.', $type));
79
+ }
80
+
81
+ return $adapter;
82
+ }
83
+ }
app/code/core/Mage/Api2/Model/Renderer/Interface.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice API2 renderer adapter interface
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ interface Mage_Api2_Model_Renderer_Interface
35
+ {
36
+ /**
37
+ * Render content in a certain format
38
+ *
39
+ * @param array|object $data
40
+ * @return string
41
+ */
42
+ public function render($data);
43
+
44
+ /**
45
+ * Get MIME type generated by renderer
46
+ *
47
+ * @return string
48
+ */
49
+ public function getMimeType();
50
+ }
app/code/core/Mage/Api2/Model/Renderer/Json.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice API2 renderer of JSON type model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Renderer_Json implements Mage_Api2_Model_Renderer_Interface
35
+ {
36
+ /**
37
+ * Adapter mime type
38
+ */
39
+ const MIME_TYPE = 'application/json';
40
+
41
+ /**
42
+ * Convert Array to JSON
43
+ *
44
+ * @param array|object $data
45
+ * @return string
46
+ */
47
+ public function render($data)
48
+ {
49
+ return Zend_Json::encode($data);
50
+ }
51
+
52
+ /**
53
+ * Get MIME type generated by renderer
54
+ *
55
+ * @return string
56
+ */
57
+ public function getMimeType()
58
+ {
59
+ return self::MIME_TYPE;
60
+ }
61
+ }
app/code/core/Mage/Api2/Model/Renderer/Query.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice API2 renderer of query format model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Renderer_Query implements Mage_Api2_Model_Renderer_Interface
35
+ {
36
+ /**
37
+ * Adapter mime type
38
+ */
39
+ const MIME_TYPE = 'text/plain';
40
+
41
+ /**
42
+ * Convert Array to URL-encoded query string
43
+ *
44
+ * @param array|object $data
45
+ * @return string
46
+ */
47
+ public function render($data)
48
+ {
49
+ $query = http_build_query($data);
50
+ return $query;
51
+ }
52
+
53
+ /**
54
+ * Get MIME type generated by renderer
55
+ *
56
+ * @return string
57
+ */
58
+ public function getMimeType()
59
+ {
60
+ return self::MIME_TYPE;
61
+ }
62
+ }
app/code/core/Mage/Api2/Model/Renderer/Xml.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice API2 renderer of XML type model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Renderer_Xml implements Mage_Api2_Model_Renderer_Interface
35
+ {
36
+ /**
37
+ * Adapter mime type
38
+ */
39
+ const MIME_TYPE = 'application/xml';
40
+
41
+ /**
42
+ * Default name for item of non-associative array
43
+ */
44
+ const ARRAY_NON_ASSOC_ITEM_NAME = 'data_item';
45
+
46
+ /**
47
+ * Chars for replacement in the tag name
48
+ *
49
+ * @var array
50
+ */
51
+ protected $_replacementInTagName = array(
52
+ '!' => '', '"' => '', '#' => '', '$' => '', '%' => '', '&' => '', '\'' => '',
53
+ '(' => '', ')' => '', '*' => '', '+' => '', ',' => '', '/' => '', ';' => '',
54
+ '<' => '', '=' => '', '>' => '', '?' => '', '@' => '', '[' => '', '\\' => '',
55
+ ']' => '', '^' => '', '`' => '', '{' => '', '|' => '', '}' => '', '~' => '',
56
+ ' ' => '_', ':' => '_'
57
+ );
58
+
59
+ /**
60
+ * Chars for replacement in the tag value
61
+ *
62
+ * @var array
63
+ */
64
+ protected $_replacementInTagValue = array(
65
+ '&' => '&amp;' // replace "&" with HTML entity, because by default not replaced
66
+ );
67
+
68
+ /**
69
+ * Protected pattern for check chars in the begin of tag name
70
+ *
71
+ * @var string
72
+ */
73
+ protected $_protectedTagNamePattern = '/^[0-9,.-]/';
74
+
75
+ /**
76
+ * Convert Array to XML
77
+ *
78
+ * @param mixed $data
79
+ * @return string
80
+ */
81
+ public function render($data)
82
+ {
83
+ /* @var $writer Mage_Api2_Model_Renderer_Xml_Writer */
84
+ $writer = Mage::getModel('api2/renderer_xml_writer', array(
85
+ 'config' => new Zend_Config($this->_prepareData($data, true))
86
+ ));
87
+ return $writer->render();
88
+ }
89
+
90
+ /**
91
+ * Prepare convert data
92
+ *
93
+ * @param array|Varien_Object $data
94
+ * @param bool $root
95
+ * @return array
96
+ * @throws Exception
97
+ */
98
+ protected function _prepareData($data, $root = false)
99
+ {
100
+ if (!is_array($data) && !is_object($data)) {
101
+ if ($root) {
102
+ $data = array($data);
103
+ } else {
104
+ throw new Exception('Prepare data must be an object or an array.');
105
+ }
106
+ }
107
+ $data = $data instanceof Varien_Object ? $data->toArray() : (array)$data;
108
+ $isAssoc = !preg_match('/^\d+$/', implode(array_keys($data), ''));
109
+
110
+ $preparedData = array();
111
+ foreach ($data as $key => $value) {
112
+ $value = is_array($value) || is_object($value) ? $this->_prepareData($value) : $this->_prepareValue($value);
113
+ if ($isAssoc) {
114
+ $preparedData[$this->_prepareKey($key)] = $value;
115
+ } else {
116
+ $preparedData[self::ARRAY_NON_ASSOC_ITEM_NAME][] = $value;
117
+ }
118
+ }
119
+ return $preparedData;
120
+ }
121
+
122
+ /**
123
+ * Prepare value
124
+ *
125
+ * @param string $value
126
+ * @return string
127
+ */
128
+ protected function _prepareValue($value)
129
+ {
130
+ return str_replace(
131
+ array_keys($this->_replacementInTagValue),
132
+ array_values($this->_replacementInTagValue),
133
+ $value
134
+ );
135
+ }
136
+
137
+ /**
138
+ * Prepare key and replace unavailable chars
139
+ *
140
+ * @param string $key
141
+ * @return string
142
+ */
143
+ protected function _prepareKey($key)
144
+ {
145
+ $key = str_replace(array_keys($this->_replacementInTagName), array_values($this->_replacementInTagName), $key);
146
+ $key = trim($key, '_');
147
+ if (preg_match($this->_protectedTagNamePattern, $key)) {
148
+ $key = self::ARRAY_NON_ASSOC_ITEM_NAME . '_' . $key;
149
+ }
150
+ return $key;
151
+ }
152
+
153
+ /**
154
+ * Get MIME type generated by renderer
155
+ *
156
+ * @return string
157
+ */
158
+ public function getMimeType()
159
+ {
160
+ return self::MIME_TYPE;
161
+ }
162
+ }
app/code/core/Mage/Api2/Model/Renderer/Xml/Writer.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API XML Renderer Writer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Renderer_Xml_Writer extends Zend_Config_Writer_Xml
35
+ {
36
+ /**
37
+ * Root node in XML output
38
+ */
39
+ const XML_ROOT_NODE = 'magento_api';
40
+
41
+ /**
42
+ * Render a Zend_Config into a XML config string.
43
+ * OVERRIDE to avoid using zend-config string in XML
44
+ *
45
+ * @return string
46
+ */
47
+ public function render()
48
+ {
49
+ $xml = new SimpleXMLElement('<' . self::XML_ROOT_NODE . '/>');
50
+ $extends = $this->_config->getExtends();
51
+ $sectionName = $this->_config->getSectionName();
52
+
53
+ if (is_string($sectionName)) {
54
+ $child = $xml->addChild($sectionName);
55
+
56
+ $this->_addBranch($this->_config, $child, $xml);
57
+ } else {
58
+ foreach ($this->_config as $sectionName => $data) {
59
+ if (!($data instanceof Zend_Config)) {
60
+ $xml->addChild($sectionName, (string) $data);
61
+ } else {
62
+ $child = $xml->addChild($sectionName);
63
+
64
+ if (isset($extends[$sectionName])) {
65
+ $child->addAttribute('zf:extends', $extends[$sectionName], Zend_Config_Xml::XML_NAMESPACE);
66
+ }
67
+
68
+ $this->_addBranch($data, $child, $xml);
69
+ }
70
+ }
71
+ }
72
+
73
+ $dom = dom_import_simplexml($xml)->ownerDocument;
74
+ $dom->formatOutput = true;
75
+
76
+ $xmlString = $dom->saveXML();
77
+
78
+ return $xmlString;
79
+ }
80
+ }
app/code/core/Mage/Api2/Model/Request.php ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API Request model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Request extends Zend_Controller_Request_Http
35
+ {
36
+ /**
37
+ * Character set which must be used in request
38
+ */
39
+ const REQUEST_CHARSET = 'utf-8';
40
+
41
+ /**#@+
42
+ * Name of query ($_GET) parameters to use in navigation and so on
43
+ */
44
+ const QUERY_PARAM_REQ_ATTRS = 'attrs';
45
+ const QUERY_PARAM_PAGE_NUM = 'page';
46
+ const QUERY_PARAM_PAGE_SIZE = 'limit';
47
+ const QUERY_PARAM_ORDER_FIELD = 'order';
48
+ const QUERY_PARAM_ORDER_DIR = 'dir';
49
+ const QUERY_PARAM_FILTER = 'filter';
50
+ /**#@- */
51
+
52
+ /**
53
+ * Interpreter adapter
54
+ *
55
+ * @var Mage_Api2_Model_Request_Interpreter_Interface
56
+ */
57
+ protected $_interpreter;
58
+
59
+ /**
60
+ * Body params
61
+ *
62
+ * @var array
63
+ */
64
+ protected $_bodyParams;
65
+
66
+ /**
67
+ * Constructor
68
+ *
69
+ * If a $uri is passed, the object will attempt to populate itself using
70
+ * that information.
71
+ * Override parent class to allow object instance get via Mage::getSingleton()
72
+ *
73
+ * @param string|Zend_Uri $uri
74
+ */
75
+ public function __construct($uri = null)
76
+ {
77
+ parent::__construct($uri ? $uri : null);
78
+ }
79
+
80
+ /**
81
+ * Get request interpreter
82
+ *
83
+ * @return Mage_Api2_Model_Request_Interpreter_Interface
84
+ */
85
+ protected function _getInterpreter()
86
+ {
87
+ if (null === $this->_interpreter) {
88
+ $this->_interpreter = Mage_Api2_Model_Request_Interpreter::factory($this->getContentType());
89
+ }
90
+ return $this->_interpreter;
91
+ }
92
+
93
+ /**
94
+ * Retrieve accept types understandable by requester in a form of array sorted by quality descending
95
+ *
96
+ * @return array
97
+ */
98
+ public function getAcceptTypes()
99
+ {
100
+ $qualityToTypes = array();
101
+ $orderedTypes = array();
102
+
103
+ foreach (preg_split('/,\s*/', $this->getHeader('Accept')) as $definition) {
104
+ $typeWithQ = explode(';', $definition);
105
+ $mimeType = trim(array_shift($typeWithQ));
106
+
107
+ // check MIME type validity
108
+ if (!preg_match('~^([0-9a-z*+\-]+)(?:/([0-9a-z*+\-\.]+))?$~i', $mimeType)) {
109
+ continue;
110
+ }
111
+ $quality = '1.0'; // default value for quality
112
+
113
+ if ($typeWithQ) {
114
+ $qAndValue = explode('=', $typeWithQ[0]);
115
+
116
+ if (2 == count($qAndValue)) {
117
+ $quality = $qAndValue[1];
118
+ }
119
+ }
120
+ $qualityToTypes[$quality][$mimeType] = true;
121
+ }
122
+ krsort($qualityToTypes);
123
+
124
+ foreach ($qualityToTypes as $typeList) {
125
+ $orderedTypes += $typeList;
126
+ }
127
+ return array_keys($orderedTypes);
128
+ }
129
+
130
+ /**
131
+ * Get api type from Request
132
+ *
133
+ * @return string
134
+ */
135
+ public function getApiType()
136
+ {
137
+ // getParam() is not used to avoid parameter fetch from $_GET or $_POST
138
+ return isset($this->_params['api_type']) ? $this->_params['api_type'] : null;
139
+ }
140
+
141
+ /**
142
+ * Fetch data from HTTP Request body
143
+ *
144
+ * @return array
145
+ */
146
+ public function getBodyParams()
147
+ {
148
+ if (null == $this->_bodyParams) {
149
+ $this->_bodyParams = $this->_getInterpreter()->interpret((string)$this->getRawBody());
150
+ }
151
+ return $this->_bodyParams;
152
+ }
153
+
154
+ /**
155
+ * Get Content-Type of request
156
+ *
157
+ * @return string
158
+ * @throws Mage_Api2_Exception
159
+ */
160
+ public function getContentType()
161
+ {
162
+ $headerValue = $this->getHeader('Content-Type');
163
+
164
+ if (!$headerValue) {
165
+ throw new Mage_Api2_Exception('Content-Type header is empty', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
166
+ }
167
+ if (!preg_match('~^([a-z\d/\-+.]+)(?:; *charset=(.+))?$~Ui', $headerValue, $matches)) {
168
+ throw new Mage_Api2_Exception('Invalid Content-Type header', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
169
+ }
170
+ // request encoding check if it is specified in header
171
+ if (isset($matches[2]) && self::REQUEST_CHARSET != strtolower($matches[2])) {
172
+ throw new Mage_Api2_Exception(
173
+ 'UTF-8 is the only supported charset', Mage_Api2_Model_Server::HTTP_BAD_REQUEST
174
+ );
175
+ }
176
+ return $matches[1];
177
+ }
178
+
179
+ /**
180
+ * Get filter settings passed by API user
181
+ *
182
+ * @return mixed
183
+ */
184
+ public function getFilter()
185
+ {
186
+ return $this->getQuery(self::QUERY_PARAM_FILTER);
187
+ }
188
+
189
+ /**
190
+ * Get resource model class name
191
+ *
192
+ * @return string|null
193
+ */
194
+ public function getModel()
195
+ {
196
+ // getParam() is not used to avoid parameter fetch from $_GET or $_POST
197
+ return isset($this->_params['model']) ? $this->_params['model'] : null;
198
+ }
199
+
200
+ /**
201
+ * Retrieve one of CRUD operation dependent on HTTP method
202
+ *
203
+ * @return string
204
+ * @throws Mage_Api2_Exception
205
+ */
206
+ public function getOperation()
207
+ {
208
+ if (!$this->isGet() && !$this->isPost() && !$this->isPut() && !$this->isDelete()) {
209
+ throw new Mage_Api2_Exception('Invalid request method', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
210
+ }
211
+ // Map HTTP methods to classic CRUD verbs
212
+ $operationByMethod = array(
213
+ 'GET' => Mage_Api2_Model_Resource::OPERATION_RETRIEVE,
214
+ 'POST' => Mage_Api2_Model_Resource::OPERATION_CREATE,
215
+ 'PUT' => Mage_Api2_Model_Resource::OPERATION_UPDATE,
216
+ 'DELETE' => Mage_Api2_Model_Resource::OPERATION_DELETE
217
+ );
218
+
219
+ return $operationByMethod[$this->getMethod()];
220
+ }
221
+
222
+ /**
223
+ * Get sort order direction requested by API user
224
+ *
225
+ * @return mixed
226
+ */
227
+ public function getOrderDirection()
228
+ {
229
+ return $this->getQuery(self::QUERY_PARAM_ORDER_DIR);
230
+ }
231
+
232
+ /**
233
+ * Get sort order field requested by API user
234
+ *
235
+ * @return mixed
236
+ */
237
+ public function getOrderField()
238
+ {
239
+ return $this->getQuery(self::QUERY_PARAM_ORDER_FIELD);
240
+ }
241
+
242
+ /**
243
+ * Retrieve page number requested by API user
244
+ *
245
+ * @return mixed
246
+ */
247
+ public function getPageNumber()
248
+ {
249
+ return $this->getQuery(self::QUERY_PARAM_PAGE_NUM);
250
+ }
251
+
252
+ /**
253
+ * Retrieve page size requested by API user
254
+ *
255
+ * @return mixed
256
+ */
257
+ public function getPageSize()
258
+ {
259
+ return $this->getQuery(self::QUERY_PARAM_PAGE_SIZE);
260
+ }
261
+
262
+ /**
263
+ * Get an array of attribute codes requested by API user
264
+ *
265
+ * @return array
266
+ */
267
+ public function getRequestedAttributes()
268
+ {
269
+ $include = $this->getQuery(self::QUERY_PARAM_REQ_ATTRS, array());
270
+
271
+ //transform comma-separated list
272
+ if (!is_array($include)) {
273
+ $include = explode(',', $include);
274
+ }
275
+ return array_map('trim', $include);
276
+ }
277
+
278
+ /**
279
+ * Retrieve resource type
280
+ *
281
+ * @return string
282
+ */
283
+ public function getResourceType()
284
+ {
285
+ // getParam() is not used to avoid parameter fetch from $_GET or $_POST
286
+ return isset($this->_params['type']) ? $this->_params['type'] : null;
287
+ }
288
+
289
+ /**
290
+ * Get Version header from headers
291
+ *
292
+ * @return string
293
+ */
294
+ public function getVersion()
295
+ {
296
+ return $this->getHeader('Version');
297
+ }
298
+
299
+ /**
300
+ * Retrieve action type
301
+ *
302
+ * @return string|null
303
+ */
304
+ public function getActionType()
305
+ {
306
+ // getParam() is not used to avoid parameter fetch from $_GET or $_POST
307
+ return isset($this->_params['action_type']) ? $this->_params['action_type'] : null;
308
+ }
309
+
310
+ /**
311
+ * It checks if the array in the request body is an associative one.
312
+ * It is required for definition of the dynamic aaction type (multi or single)
313
+ *
314
+ * @return bool
315
+ */
316
+ public function isAssocArrayInRequestBody()
317
+ {
318
+ $params = $this->getBodyParams();
319
+ if (count($params)) {
320
+ $keys = array_keys($params);
321
+ return !is_numeric($keys[0]);
322
+ }
323
+ return false;
324
+ }
325
+ }
app/code/core/Mage/Api2/Model/Request/Internal.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API internal request model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Request_Internal extends Mage_Api2_Model_Request
35
+ {
36
+ /**
37
+ * Request body data
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_bodyParams;
42
+
43
+ /**
44
+ * Request method
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_method;
49
+
50
+ /**
51
+ * Fetch data from HTTP Request body
52
+ *
53
+ * @return array
54
+ */
55
+ public function getBodyParams()
56
+ {
57
+ if ($this->_bodyParams === null) {
58
+ $this->_bodyParams = $this->_getInterpreter()->interpret((string) $this->getRawBody());
59
+ }
60
+ return $this->_bodyParams;
61
+ }
62
+
63
+ /**
64
+ * Set request body data
65
+ *
66
+ * @param array $data
67
+ * @return Mage_Api2_Model_Request
68
+ */
69
+ public function setBodyParams($data)
70
+ {
71
+ $this->_bodyParams = $data;
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * Set HTTP request method for request emulation during internal call
77
+ *
78
+ * @param string $method
79
+ * @return Mage_Api2_Model_Request_Internal
80
+ */
81
+ public function setMethod($method)
82
+ {
83
+ $availableMethod = array('GET', 'POST', 'PUT', 'DELETE');
84
+ if (in_array($method, $availableMethod)) {
85
+ $this->_method = $method;
86
+ } else {
87
+ throw new Mage_Api2_Exception('Invalid method provided', Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
88
+ }
89
+ return $this;
90
+ }
91
+
92
+ /**
93
+ * Override parent method for request emulation during internal call
94
+ *
95
+ * @return string
96
+ */
97
+ public function getMethod()
98
+ {
99
+ $method = $this->_method;
100
+ if (!$method) {
101
+ $method = parent::getMethod();
102
+ }
103
+ return $method;
104
+ }
105
+ }
app/code/core/Mage/Api2/Model/Request/Interpreter.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Request content interpreter factory
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Api2_Model_Request_Interpreter
35
+ {
36
+ /**
37
+ * Request body interpreters factory
38
+ *
39
+ * @param string $type
40
+ * @return Mage_Api2_Model_Request_Interpreter_Interface
41
+ * @throws Exception|Mage_Api2_Exception
42
+ */
43
+ public static function factory($type)
44
+ {
45
+ /** @var $helper Mage_Api2_Helper_Data */
46
+ $helper = Mage::helper('api2/data');
47
+ $adapters = $helper->getRequestInterpreterAdapters();
48
+
49
+ if (empty($adapters) || !is_array($adapters)) {
50
+ throw new Exception('Request interpreter adapters is not set.');
51
+ }
52
+
53
+ $adapterModel = null;
54
+ foreach ($adapters as $item) {
55
+ $itemType = $item->type;
56
+ if ($itemType == $type) {
57
+ $adapterModel = $item->model;
58
+ break;
59
+ }
60
+ }
61
+
62
+ if ($adapterModel === null) {
63
+ throw new Mage_Api2_Exception(
64
+ sprintf('Server can not understand Content-Type HTTP header media type "%s"', $type),
65
+ Mage_Api2_Model_Server::HTTP_BAD_REQUEST
66
+ );
67
+ }
68
+
69
+ $adapter = Mage::getModel($adapterModel);
70
+ if (!$adapter) {
71
+ throw new Exception(sprintf('Request interpreter adapter "%s" not found.', $type));
72
+ }
73
+
74
+ return $adapter;
75
+ }
76
+ }
app/code/core/Mage/Api2/Model/Request/Interpreter/Interface.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Request content interpreter adapter interface
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ interface Mage_Api2_Model_Request_Interpreter_Interface
35
+ {
36
+ /**
37
+ * Parse request body into array of params
38
+ *
39
+ * @param string $body Posted content from request
40
+ * @return array|null Return NULL if content is invalid
41
+ */
42
+ public function interpret($body);
43
+ }
app/code/core/Mage/Api2/Model/Request/Interpreter/Json.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Request content interpreter JSON adapter
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Request_Interpreter_Json implements Mage_Api2_Model_Request_Interpreter_Interface
35
+ {
36
+ /**
37
+ * Parse Request body into array of params
38
+ *
39
+ * @param string $body Posted content from request
40
+ * @return array|null Return NULL if content is invalid
41
+ * @throws Exception|Mage_Api2_Exception
42
+ */
43
+ public function interpret($body)
44
+ {
45
+ if (!is_string($body)) {
46
+ throw new Exception(sprintf('Invalid data type "%s". String expected.', gettype($body)));
47
+ }
48
+
49
+ $decoded = Zend_Json::decode($body);
50
+
51
+ if ($body != 'null' && $decoded === null) {
52
+ throw new Mage_Api2_Exception('Decoding error.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
53
+ }
54
+
55
+ return $decoded;
56
+ }
57
+ }
app/code/core/Mage/Api2/Model/Request/Interpreter/Query.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Request content interpreter query adapter
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Request_Interpreter_Query implements Mage_Api2_Model_Request_Interpreter_Interface
35
+ {
36
+ /**
37
+ * URI validate pattern
38
+ */
39
+ const URI_VALIDATE_PATTERN = "/^(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*'()\[\];\/?:@&=+$,])*$/";
40
+
41
+ /**
42
+ * Parse request body into array of params
43
+ *
44
+ * @param string $body Posted content from request
45
+ * @return array Return always array
46
+ * @throws Exception|Mage_Api2_Exception
47
+ */
48
+ public function interpret($body)
49
+ {
50
+ if (!is_string($body)) {
51
+ throw new Exception(sprintf('Invalid data type "%s". String expected.', gettype($body)));
52
+ }
53
+
54
+ if (!$this->_validateQuery($body)) {
55
+ throw new Mage_Api2_Exception(
56
+ 'Invalid data type. Check Content-Type.',
57
+ Mage_Api2_Model_Server::HTTP_BAD_REQUEST
58
+ );
59
+ }
60
+
61
+ $data = array();
62
+ parse_str($body, $data);
63
+ return $data;
64
+ }
65
+
66
+ /**
67
+ * Returns true if and only if the query string passes validation.
68
+ *
69
+ * @param string $query The query to validate
70
+ * @return boolean
71
+ * @link http://www.faqs.org/rfcs/rfc2396.html
72
+ */
73
+ protected function _validateQuery($query)
74
+ {
75
+ return preg_match(self::URI_VALIDATE_PATTERN, $query);
76
+ }
77
+ }
app/code/core/Mage/Api2/Model/Request/Interpreter/Xml.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Request content interpreter XML adapter
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Request_Interpreter_Xml implements Mage_Api2_Model_Request_Interpreter_Interface
35
+ {
36
+ /**
37
+ * Default name for item of non-associative array
38
+ */
39
+ const ARRAY_NON_ASSOC_ITEM_NAME = 'data_item';
40
+
41
+ /**
42
+ * Load error string.
43
+ *
44
+ * Is null if there was no error while loading
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_loadErrorStr = null;
49
+
50
+ /**
51
+ * Parse Request body into array of params
52
+ *
53
+ * @param string $body Posted content from request
54
+ * @return array
55
+ * @throws Exception|Mage_Api2_Exception
56
+ */
57
+ public function interpret($body)
58
+ {
59
+ if (!is_string($body)) {
60
+ throw new Exception(sprintf('Invalid data type "%s". String expected.', gettype($body)));
61
+ }
62
+ $body = false !== strpos($body, '<?xml') ? $body : '<?xml version="1.0"?>' . PHP_EOL . $body;
63
+
64
+ set_error_handler(array($this, '_loadErrorHandler')); // Warnings and errors are suppressed
65
+ $config = simplexml_load_string($body);
66
+ restore_error_handler();
67
+
68
+ // Check if there was a error while loading file
69
+ if ($this->_loadErrorStr !== null) {
70
+ throw new Mage_Api2_Exception('Decoding error.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
71
+ }
72
+
73
+ $xml = $this->_toArray($config);
74
+ return $xml;
75
+ }
76
+
77
+ /**
78
+ * Returns an associativearray from a SimpleXMLElement.
79
+ *
80
+ * @param SimpleXMLElement $xmlObject Convert a SimpleXMLElement into an array
81
+ * @return array
82
+ */
83
+ protected function _toArray(SimpleXMLElement $xmlObject)
84
+ {
85
+ $config = array();
86
+ // Search for parent node values
87
+ if (count($xmlObject->attributes()) > 0) {
88
+ foreach ($xmlObject->attributes() as $key => $value) {
89
+ $value = (string)$value;
90
+ if (array_key_exists($key, $config)) {
91
+ if (!is_array($config[$key])) {
92
+ $config[$key] = array($config[$key]);
93
+ }
94
+ $config[$key][] = $value;
95
+ } else {
96
+ $config[$key] = $value;
97
+ }
98
+ }
99
+ }
100
+
101
+ // Search for children
102
+ if (count($xmlObject->children()) > 0) {
103
+ foreach ($xmlObject->children() as $key => $value) {
104
+ if (count($value->children()) > 0) {
105
+ $value = $this->_toArray($value);
106
+ } else if (count($value->attributes()) > 0) {
107
+ $attributes = $value->attributes();
108
+ if (isset($attributes['value'])) {
109
+ $value = (string)$attributes['value'];
110
+ } else {
111
+ $value = $this->_toArray($value);
112
+ }
113
+ } else {
114
+ $value = (string) $value;
115
+ }
116
+ if (array_key_exists($key, $config)) {
117
+ if (!is_array($config[$key]) || !array_key_exists(0, $config[$key])) {
118
+ $config[$key] = array($config[$key]);
119
+ }
120
+ $config[$key][] = $value;
121
+ } else {
122
+ if (self::ARRAY_NON_ASSOC_ITEM_NAME != $key) {
123
+ $config[$key] = $value;
124
+ } else {
125
+ $config[] = $value;
126
+ }
127
+ }
128
+ }
129
+ }
130
+
131
+ return $config;
132
+ }
133
+
134
+ /**
135
+ * Handle any errors from load xml
136
+ *
137
+ * @param integer $errno
138
+ * @param string $errstr
139
+ * @param string $errfile
140
+ * @param integer $errline
141
+ */
142
+ protected function _loadErrorHandler($errno, $errstr, $errfile, $errline)
143
+ {
144
+ if ($this->_loadErrorStr === null) {
145
+ $this->_loadErrorStr = $errstr;
146
+ } else {
147
+ $this->_loadErrorStr .= (PHP_EOL . $errstr);
148
+ }
149
+ }
150
+ }
app/code/core/Mage/Api2/Model/Resource.php ADDED
@@ -0,0 +1,1082 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Abstract Resource
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method string _create() _create(array $filteredData) creation of an entity
34
+ * @method void _multiCreate() _multiCreate(array $filteredData) processing and creation of a collection
35
+ * @method array _retrieve() retrieving an entity
36
+ * @method array _retrieveCollection() retrieving a collection
37
+ * @method void _update() _update(array $filteredData) update of an entity
38
+ * @method void _multiUpdate() _multiUpdate(array $filteredData) update of a collection
39
+ * @method void _delete() deletion of an entity
40
+ * @method void _multidelete() _multidelete(array $requestData) deletion of a collection
41
+ */
42
+ abstract class Mage_Api2_Model_Resource
43
+ {
44
+ /**#@+
45
+ * Action types
46
+ */
47
+ const ACTION_TYPE_ENTITY = 'entity';
48
+ const ACTION_TYPE_COLLECTION = 'collection';
49
+ /**#@-*/
50
+
51
+ /**#@+
52
+ * Operations. Resource method names
53
+ */
54
+ const OPERATION_CREATE = 'create';
55
+ const OPERATION_RETRIEVE = 'retrieve';
56
+ const OPERATION_UPDATE = 'update';
57
+ const OPERATION_DELETE = 'delete';
58
+ /**#@-*/
59
+
60
+ /**#@+
61
+ * Common operations for attributes
62
+ */
63
+ const OPERATION_ATTRIBUTE_READ = 'read';
64
+ const OPERATION_ATTRIBUTE_WRITE = 'write';
65
+ /**#@-*/
66
+
67
+ /**#@+
68
+ * Default error messages
69
+ */
70
+ const RESOURCE_NOT_FOUND = 'Resource not found.';
71
+ const RESOURCE_METHOD_NOT_ALLOWED = 'Resource does not support method.';
72
+ const RESOURCE_METHOD_NOT_IMPLEMENTED = 'Resource method not implemented yet.';
73
+ const RESOURCE_INTERNAL_ERROR = 'Resource internal error.';
74
+ const RESOURCE_DATA_PRE_VALIDATION_ERROR = 'Resource data pre-validation error.';
75
+ const RESOURCE_DATA_INVALID = 'Resource data invalid.'; //error while checking data inside method
76
+ const RESOURCE_UNKNOWN_ERROR = 'Resource unknown error.';
77
+ const RESOURCE_REQUEST_DATA_INVALID = 'The request data is invalid.';
78
+ /**#@-*/
79
+
80
+ /**#@+
81
+ * Default collection resources error messages
82
+ */
83
+ const RESOURCE_COLLECTION_PAGING_ERROR = 'Resource collection paging error.';
84
+ const RESOURCE_COLLECTION_PAGING_LIMIT_ERROR = 'The paging limit exceeds the allowed number.';
85
+ const RESOURCE_COLLECTION_ORDERING_ERROR = 'Resource collection ordering error.';
86
+ const RESOURCE_COLLECTION_FILTERING_ERROR = 'Resource collection filtering error.';
87
+ const RESOURCE_COLLECTION_ATTRIBUTES_ERROR = 'Resource collection including additional attributes error.';
88
+ /**#@-*/
89
+
90
+ /**#@+
91
+ * Default success messages
92
+ */
93
+ const RESOURCE_UPDATED_SUCCESSFUL = 'Resource updated successful.';
94
+ /**#@-*/
95
+
96
+ /**#@+
97
+ * Collection page sizes
98
+ */
99
+ const PAGE_SIZE_DEFAULT = 10;
100
+ const PAGE_SIZE_MAX = 100;
101
+ /**#@-*/
102
+
103
+ /**
104
+ * Request
105
+ *
106
+ * @var Mage_Api2_Model_Request
107
+ */
108
+ protected $_request;
109
+
110
+ /**
111
+ * Resource type
112
+ *
113
+ * @var string
114
+ */
115
+ protected $_resourceType;
116
+
117
+ /**
118
+ * Api type
119
+ *
120
+ * @var string
121
+ */
122
+ protected $_apiType;
123
+
124
+ /**
125
+ * API Version
126
+ *
127
+ * @var int
128
+ */
129
+ protected $_version = null;
130
+
131
+ /**
132
+ * Response
133
+ *
134
+ * @var Zend_Controller_Response_Http
135
+ */
136
+ protected $_response;
137
+
138
+ /**
139
+ * Attribute Filter
140
+ *
141
+ * @var Mage_Api2_Model_Acl_Filter
142
+ */
143
+ protected $_filter;
144
+
145
+ /**
146
+ * Renderer
147
+ *
148
+ * @var Mage_Api2_Model_Renderer_Interface
149
+ */
150
+ protected $_renderer;
151
+
152
+ /**
153
+ * Api user
154
+ *
155
+ * @var Mage_Api2_Model_Auth_User_Abstract
156
+ */
157
+ protected $_apiUser;
158
+
159
+ /**
160
+ * User type
161
+ *
162
+ * @var string
163
+ */
164
+ protected $_userType;
165
+
166
+ /**
167
+ * One of Mage_Api2_Model_Resource::ACTION_TYPE_... constant
168
+ *
169
+ * @var string
170
+ */
171
+ protected $_actionType;
172
+
173
+ /**
174
+ * One of Mage_Api2_Model_Resource::OPERATION_... constant
175
+ *
176
+ * @var string
177
+ */
178
+ protected $_operation;
179
+
180
+ /**
181
+ * If TRUE - no rendering will be done and dispatch will return data. Otherwise, by default
182
+ *
183
+ * @var bool
184
+ */
185
+ protected $_returnData = false;
186
+
187
+ /**
188
+ * @var Mage_Api2_Model_Multicall
189
+ */
190
+ protected $_multicall;
191
+
192
+ /**
193
+ * Dispatch
194
+ * To implement the functionality, you must create a method in the parent one.
195
+ *
196
+ * Action type is defined in api2.xml in the routes section and depends on entity (single object)
197
+ * or collection (several objects).
198
+ *
199
+ * HTTP_MULTI_STATUS is used for several status codes in the response
200
+ */
201
+ public function dispatch()
202
+ {
203
+ switch ($this->getActionType() . $this->getOperation()) {
204
+ /* Create */
205
+ case self::ACTION_TYPE_ENTITY . self::OPERATION_CREATE:
206
+ // Creation of objects is possible only when working with collection
207
+ $this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
208
+ break;
209
+ case self::ACTION_TYPE_COLLECTION . self::OPERATION_CREATE:
210
+ // If no of the methods(multi or single) is implemented, request body is not checked
211
+ if (!$this->_checkMethodExist('_create') && !$this->_checkMethodExist('_multiCreate')) {
212
+ $this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
213
+ }
214
+ // If one of the methods(multi or single) is implemented, request body must not be empty
215
+ $requestData = $this->getRequest()->getBodyParams();
216
+ if (empty($requestData)) {
217
+ $this->_critical(self::RESOURCE_REQUEST_DATA_INVALID);
218
+ }
219
+ // The create action has the dynamic type which depends on data in the request body
220
+ if ($this->getRequest()->isAssocArrayInRequestBody()) {
221
+ $this->_errorIfMethodNotExist('_create');
222
+ $filteredData = $this->getFilter()->in($requestData);
223
+ if (empty($filteredData)) {
224
+ $this->_critical(self::RESOURCE_REQUEST_DATA_INVALID);
225
+ }
226
+ $newItemLocation = $this->_create($filteredData);
227
+ $this->getResponse()->setHeader('Location', $newItemLocation);
228
+ } else {
229
+ $this->_errorIfMethodNotExist('_multiCreate');
230
+ $filteredData = $this->getFilter()->collectionIn($requestData);
231
+ $this->_multiCreate($filteredData);
232
+ $this->_render($this->getResponse()->getMessages());
233
+ $this->getResponse()->setHttpResponseCode(Mage_Api2_Model_Server::HTTP_MULTI_STATUS);
234
+ }
235
+ break;
236
+ /* Retrieve */
237
+ case self::ACTION_TYPE_ENTITY . self::OPERATION_RETRIEVE:
238
+ $this->_errorIfMethodNotExist('_retrieve');
239
+ $retrievedData = $this->_retrieve();
240
+ $filteredData = $this->getFilter()->out($retrievedData);
241
+ $this->_render($filteredData);
242
+ break;
243
+ case self::ACTION_TYPE_COLLECTION . self::OPERATION_RETRIEVE:
244
+ $this->_errorIfMethodNotExist('_retrieveCollection');
245
+ $retrievedData = $this->_retrieveCollection();
246
+ $filteredData = $this->getFilter()->collectionOut($retrievedData);
247
+ $this->_render($filteredData);
248
+ break;
249
+ /* Update */
250
+ case self::ACTION_TYPE_ENTITY . self::OPERATION_UPDATE:
251
+ $this->_errorIfMethodNotExist('_update');
252
+ $requestData = $this->getRequest()->getBodyParams();
253
+ if (empty($requestData)) {
254
+ $this->_critical(self::RESOURCE_REQUEST_DATA_INVALID);
255
+ }
256
+ $filteredData = $this->getFilter()->in($requestData);
257
+ if (empty($filteredData)) {
258
+ $this->_critical(self::RESOURCE_REQUEST_DATA_INVALID);
259
+ }
260
+ $this->_update($filteredData);
261
+ break;
262
+ case self::ACTION_TYPE_COLLECTION . self::OPERATION_UPDATE:
263
+ $this->_errorIfMethodNotExist('_multiUpdate');
264
+ $requestData = $this->getRequest()->getBodyParams();
265
+ if (empty($requestData)) {
266
+ $this->_critical(self::RESOURCE_REQUEST_DATA_INVALID);
267
+ }
268
+ $filteredData = $this->getFilter()->collectionIn($requestData);
269
+ $this->_multiUpdate($filteredData);
270
+ $this->_render($this->getResponse()->getMessages());
271
+ $this->getResponse()->setHttpResponseCode(Mage_Api2_Model_Server::HTTP_MULTI_STATUS);
272
+ break;
273
+ /* Delete */
274
+ case self::ACTION_TYPE_ENTITY . self::OPERATION_DELETE:
275
+ $this->_errorIfMethodNotExist('_delete');
276
+ $this->_delete();
277
+ break;
278
+ case self::ACTION_TYPE_COLLECTION . self::OPERATION_DELETE:
279
+ $this->_errorIfMethodNotExist('_multiDelete');
280
+ $requestData = $this->getRequest()->getBodyParams();
281
+ if (empty($requestData)) {
282
+ $this->_critical(self::RESOURCE_REQUEST_DATA_INVALID);
283
+ }
284
+ $this->_multiDelete($requestData);
285
+ $this->getResponse()->setHttpResponseCode(Mage_Api2_Model_Server::HTTP_MULTI_STATUS);
286
+ break;
287
+ default:
288
+ $this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
289
+ break;
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Trigger error for not-implemented operations
295
+ *
296
+ * @param $methodName
297
+ */
298
+ protected function _errorIfMethodNotExist($methodName)
299
+ {
300
+ if (!$this->_checkMethodExist($methodName)) {
301
+ $this->_critical(self::RESOURCE_METHOD_NOT_IMPLEMENTED);
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Check method exist
307
+ *
308
+ * @param $methodName
309
+ * @return bool
310
+ */
311
+ protected function _checkMethodExist($methodName)
312
+ {
313
+ return method_exists($this, $methodName);
314
+ }
315
+
316
+ /**
317
+ * Get request
318
+ *
319
+ * @throws Exception
320
+ * @return Mage_Api2_Model_Request
321
+ */
322
+ public function getRequest()
323
+ {
324
+ if (!$this->_request) {
325
+ throw new Exception('Request is not set.');
326
+ }
327
+ return $this->_request;
328
+ }
329
+
330
+ /**
331
+ * Set request
332
+ *
333
+ * @param Mage_Api2_Model_Request $request
334
+ * @return Mage_Api2_Model_Resource
335
+ */
336
+ public function setRequest(Mage_Api2_Model_Request $request)
337
+ {
338
+ $this->setResourceType($request->getResourceType());
339
+ $this->setApiType($request->getApiType());
340
+ $this->_request = $request;
341
+ return $this;
342
+ }
343
+
344
+ /**
345
+ * Get resource type
346
+ * If not exists get from Request
347
+ *
348
+ * @return string
349
+ */
350
+ public function getResourceType()
351
+ {
352
+ if (!$this->_resourceType) {
353
+ $this->setResourceType($this->getRequest()->getResourceType());
354
+ }
355
+ return $this->_resourceType;
356
+ }
357
+
358
+ /**
359
+ * Set resource type
360
+ *
361
+ * @param string $resourceType
362
+ * @return Mage_Api2_Model_Resource
363
+ */
364
+ public function setResourceType($resourceType)
365
+ {
366
+ $this->_resourceType = $resourceType;
367
+ return $this;
368
+ }
369
+
370
+ /**
371
+ * Get API type
372
+ * If not exists get from Request.
373
+ *
374
+ * @return string
375
+ */
376
+ public function getApiType()
377
+ {
378
+ if (!$this->_apiType) {
379
+ $this->setApiType($this->getRequest()->getApiType());
380
+ }
381
+ return $this->_apiType;
382
+ }
383
+
384
+ /**
385
+ * Set API type
386
+ *
387
+ * @param string $apiType
388
+ * @return Mage_Api2_Model_Resource
389
+ */
390
+ public function setApiType($apiType)
391
+ {
392
+ $this->_apiType = $apiType;
393
+ return $this;
394
+ }
395
+
396
+ /**
397
+ * Determine version from class name
398
+ *
399
+ * @return int
400
+ */
401
+ public function getVersion()
402
+ {
403
+ if (null === $this->_version) {
404
+ if (preg_match('/^.+([1-9]\d*)$/', get_class($this), $matches) ) {
405
+ $this->setVersion($matches[1]);
406
+ } else {
407
+ throw new Exception('Can not determine version from class name');
408
+ }
409
+ }
410
+ return $this->_version;
411
+ }
412
+
413
+ /**
414
+ * Set API version
415
+ *
416
+ * @param int $version
417
+ */
418
+ public function setVersion($version)
419
+ {
420
+ $this->_version = (int)$version;
421
+ }
422
+
423
+ /**
424
+ * Get response
425
+ *
426
+ * @return Mage_Api2_Model_Response
427
+ */
428
+ public function getResponse()
429
+ {
430
+ if (!$this->_response) {
431
+ throw new Exception('Response is not set.');
432
+ }
433
+ return $this->_response;
434
+ }
435
+
436
+ /**
437
+ * Set response
438
+ *
439
+ * @param Mage_Api2_Model_Response $response
440
+ */
441
+ public function setResponse(Mage_Api2_Model_Response $response)
442
+ {
443
+ $this->_response = $response;
444
+ }
445
+
446
+ /**
447
+ * Get filter if not exists create
448
+ *
449
+ * @return Mage_Api2_Model_Acl_Filter
450
+ */
451
+ public function getFilter()
452
+ {
453
+ if (!$this->_filter) {
454
+ /** @var $filter Mage_Api2_Model_Acl_Filter */
455
+ $filter = Mage::getModel('api2/acl_filter', $this);
456
+ $this->setFilter($filter);
457
+ }
458
+ return $this->_filter;
459
+ }
460
+
461
+ /**
462
+ * Set filter
463
+ *
464
+ * @param Mage_Api2_Model_Acl_Filter $filter
465
+ */
466
+ public function setFilter(Mage_Api2_Model_Acl_Filter $filter)
467
+ {
468
+ $this->_filter = $filter;
469
+ }
470
+
471
+ /**
472
+ * Get renderer if not exists create
473
+ *
474
+ * @return Mage_Api2_Model_Renderer_Interface
475
+ */
476
+ public function getRenderer()
477
+ {
478
+ if (!$this->_renderer) {
479
+ $renderer = Mage_Api2_Model_Renderer::factory($this->getRequest()->getAcceptTypes());
480
+ $this->setRenderer($renderer);
481
+ }
482
+
483
+ return $this->_renderer;
484
+ }
485
+
486
+ /**
487
+ * Set renderer
488
+ *
489
+ * @param Mage_Api2_Model_Renderer_Interface $renderer
490
+ */
491
+ public function setRenderer(Mage_Api2_Model_Renderer_Interface $renderer)
492
+ {
493
+ $this->_renderer = $renderer;
494
+ }
495
+
496
+ /**
497
+ * Get user type
498
+ * If not exists get from apiUser
499
+ *
500
+ * @return string
501
+ */
502
+ public function getUserType()
503
+ {
504
+ if (!$this->_userType) {
505
+ $this->setUserType($this->getApiUser()->getType());
506
+ }
507
+ return $this->_userType;
508
+ }
509
+
510
+ /**
511
+ * Set user type
512
+ *
513
+ * @param string $userType
514
+ * @return Mage_Api2_Model_Resource
515
+ */
516
+ public function setUserType($userType)
517
+ {
518
+ $this->_userType = $userType;
519
+ return $this;
520
+ }
521
+
522
+ /**
523
+ * Get API user
524
+ *
525
+ * @throws Exception
526
+ * @return Mage_Api2_Model_Auth_User_Abstract
527
+ */
528
+ public function getApiUser()
529
+ {
530
+ if (!$this->_apiUser) {
531
+ throw new Exception('API user is not set.');
532
+ }
533
+ return $this->_apiUser;
534
+ }
535
+
536
+ /**
537
+ * Set API user
538
+ *
539
+ * @param Mage_Api2_Model_Auth_User_Abstract $apiUser
540
+ * @return Mage_Api2_Model_Resource
541
+ */
542
+ public function setApiUser(Mage_Api2_Model_Auth_User_Abstract $apiUser)
543
+ {
544
+ $this->_apiUser = $apiUser;
545
+ return $this;
546
+ }
547
+
548
+ /**
549
+ * Get action type
550
+ * If not exists get from Request
551
+ *
552
+ * @return string One of Mage_Api2_Model_Resource::ACTION_TYPE_... constant
553
+ */
554
+ public function getActionType()
555
+ {
556
+ if (!$this->_actionType) {
557
+ $this->setActionType($this->getRequest()->getActionType());
558
+ }
559
+ return $this->_actionType;
560
+ }
561
+
562
+ /**
563
+ * Set route type
564
+ *
565
+ * @param string $actionType One of Mage_Api2_Model_Resource::ACTION_TYPE_... constant
566
+ * @return Mage_Api2_Model_Resource
567
+ */
568
+ public function setActionType($actionType)
569
+ {
570
+ $this->_actionType = $actionType;
571
+ return $this;
572
+ }
573
+
574
+ /**
575
+ * Get operation
576
+ * If not exists get from Request
577
+ *
578
+ * @return string One of Mage_Api2_Model_Resource::OPERATION_... constant
579
+ */
580
+ public function getOperation()
581
+ {
582
+ if (!$this->_operation) {
583
+ $this->setOperation($this->getRequest()->getOperation());
584
+ }
585
+ return $this->_operation;
586
+ }
587
+
588
+ /**
589
+ * Set operation
590
+ *
591
+ * @param string $operation One of Mage_Api2_Model_Resource::OPERATION_... constant
592
+ * @return Mage_Api2_Model_Resource
593
+ */
594
+ public function setOperation($operation)
595
+ {
596
+ $this->_operation = $operation;
597
+ return $this;
598
+ }
599
+
600
+ /**
601
+ * Get API2 config
602
+ *
603
+ * @return Mage_Api2_Model_Config
604
+ */
605
+ public function getConfig()
606
+ {
607
+ return Mage::getSingleton('api2/config');
608
+ }
609
+
610
+ /**
611
+ * Get working model
612
+ *
613
+ * @return Mage_Core_Model_Abstract
614
+ */
615
+ public function getWorkingModel()
616
+ {
617
+ return Mage::getModel($this->getConfig()->getResourceWorkingModel($this->getResourceType()));
618
+ }
619
+
620
+ /**
621
+ * Render data using registered Renderer
622
+ *
623
+ * @param mixed $data
624
+ */
625
+ protected function _render($data)
626
+ {
627
+ $this->getResponse()->setMimeType($this->getRenderer()->getMimeType())
628
+ ->setBody($this->getRenderer()->render($data));
629
+ }
630
+
631
+ /**
632
+ * Throw exception, critical error - stop execution
633
+ *
634
+ * @param string $message
635
+ * @param int $code
636
+ * @throws Mage_Api2_Exception
637
+ */
638
+ protected function _critical($message, $code = null)
639
+ {
640
+ if ($code === null) {
641
+ $errors = $this->_getCriticalErrors();
642
+ if (!isset($errors[$message])) {
643
+ throw new Exception(
644
+ sprintf('Invalid error "%s" or error code missed.', $message),
645
+ Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR
646
+ );
647
+ }
648
+ $code = $errors[$message];
649
+ }
650
+ throw new Mage_Api2_Exception($message, $code);
651
+ }
652
+
653
+ /**
654
+ * Retrieve array with critical errors mapped to HTTP codes
655
+ *
656
+ * @return array
657
+ */
658
+ protected function _getCriticalErrors()
659
+ {
660
+ return array(
661
+ '' => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
662
+ self::RESOURCE_NOT_FOUND => Mage_Api2_Model_Server::HTTP_NOT_FOUND,
663
+ self::RESOURCE_METHOD_NOT_ALLOWED => Mage_Api2_Model_Server::HTTP_METHOD_NOT_ALLOWED,
664
+ self::RESOURCE_METHOD_NOT_IMPLEMENTED => Mage_Api2_Model_Server::HTTP_METHOD_NOT_ALLOWED,
665
+ self::RESOURCE_DATA_PRE_VALIDATION_ERROR => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
666
+ self::RESOURCE_INTERNAL_ERROR => Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR,
667
+ self::RESOURCE_UNKNOWN_ERROR => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
668
+ self::RESOURCE_REQUEST_DATA_INVALID => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
669
+ self::RESOURCE_COLLECTION_PAGING_ERROR => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
670
+ self::RESOURCE_COLLECTION_PAGING_LIMIT_ERROR => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
671
+ self::RESOURCE_COLLECTION_ORDERING_ERROR => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
672
+ self::RESOURCE_COLLECTION_FILTERING_ERROR => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
673
+ self::RESOURCE_COLLECTION_ATTRIBUTES_ERROR => Mage_Api2_Model_Server::HTTP_BAD_REQUEST,
674
+ );
675
+ }
676
+
677
+ /**
678
+ * Add non-critical error
679
+ *
680
+ * @param string $message
681
+ * @param int $code
682
+ * @return Mage_Api2_Model_Resource
683
+ */
684
+ protected function _error($message, $code)
685
+ {
686
+ $this->getResponse()->setException(new Mage_Api2_Exception($message, $code));
687
+ return $this;
688
+ }
689
+
690
+ /**
691
+ * Add success message
692
+ *
693
+ * @param string $message
694
+ * @param int $code
695
+ * @param array $params
696
+ * @return Mage_Api2_Model_Resource
697
+ */
698
+ protected function _successMessage($message, $code, $params = array())
699
+ {
700
+ $this->getResponse()->addMessage($message, $code, $params, Mage_Api2_Model_Response::MESSAGE_TYPE_SUCCESS);
701
+ return $this;
702
+ }
703
+
704
+ /**
705
+ * Add error message
706
+ *
707
+ * @param string $message
708
+ * @param int $code
709
+ * @param array $params
710
+ * @return Mage_Api2_Model_Resource
711
+ */
712
+ protected function _errorMessage($message, $code, $params = array())
713
+ {
714
+ $this->getResponse()->addMessage($message, $code, $params, Mage_Api2_Model_Response::MESSAGE_TYPE_ERROR);
715
+ return $this;
716
+ }
717
+
718
+ /**
719
+ * Set navigation parameters and apply filters from URL params
720
+ *
721
+ * @param Varien_Data_Collection_Db $collection
722
+ * @return Mage_Api2_Model_Resource
723
+ */
724
+ final protected function _applyCollectionModifiers(Varien_Data_Collection_Db $collection)
725
+ {
726
+ $pageNumber = $this->getRequest()->getPageNumber();
727
+ if ($pageNumber != abs($pageNumber)) {
728
+ $this->_critical(self::RESOURCE_COLLECTION_PAGING_ERROR);
729
+ }
730
+
731
+ $pageSize = $this->getRequest()->getPageSize();
732
+ if (null == $pageSize) {
733
+ $pageSize = self::PAGE_SIZE_DEFAULT;
734
+ } else {
735
+ if ($pageSize != abs($pageSize) || $pageSize > self::PAGE_SIZE_MAX) {
736
+ $this->_critical(self::RESOURCE_COLLECTION_PAGING_LIMIT_ERROR);
737
+ }
738
+ }
739
+
740
+ $orderField = $this->getRequest()->getOrderField();
741
+
742
+ if (null !== $orderField) {
743
+ $operation = Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ;
744
+ if (!is_string($orderField)
745
+ || !array_key_exists($orderField, $this->getAvailableAttributes($this->getUserType(), $operation))
746
+ ) {
747
+ $this->_critical(self::RESOURCE_COLLECTION_ORDERING_ERROR);
748
+ }
749
+ $collection->setOrder($orderField, $this->getRequest()->getOrderDirection());
750
+ }
751
+ $collection->setCurPage($pageNumber)->setPageSize($pageSize);
752
+
753
+ return $this->_applyFilter($collection);
754
+ }
755
+
756
+ /**
757
+ * Validate filter data and apply it to collection if possible
758
+ *
759
+ * @param Varien_Data_Collection_Db $collection
760
+ * @return Mage_Api2_Model_Resource
761
+ */
762
+ protected function _applyFilter(Varien_Data_Collection_Db $collection)
763
+ {
764
+ $filter = $this->getRequest()->getFilter();
765
+
766
+ if (!$filter) {
767
+ return $this;
768
+ }
769
+ if (!is_array($filter)) {
770
+ $this->_critical(self::RESOURCE_COLLECTION_FILTERING_ERROR);
771
+ }
772
+ if (method_exists($collection, 'addAttributeToFilter')) {
773
+ $methodName = 'addAttributeToFilter';
774
+ } elseif (method_exists($collection, 'addFieldToFilter')) {
775
+ $methodName = 'addFieldToFilter';
776
+ } else {
777
+ return $this;
778
+ }
779
+ $allowedAttributes = $this->getFilter()->getAllowedAttributes(self::OPERATION_ATTRIBUTE_READ);
780
+
781
+ foreach ($filter as $filterEntry) {
782
+ if (!is_array($filterEntry)
783
+ || !array_key_exists('attribute', $filterEntry)
784
+ || !in_array($filterEntry['attribute'], $allowedAttributes)
785
+ ) {
786
+ $this->_critical(self::RESOURCE_COLLECTION_FILTERING_ERROR);
787
+ }
788
+ $attributeCode = $filterEntry['attribute'];
789
+
790
+ unset($filterEntry['attribute']);
791
+
792
+ try {
793
+ $collection->$methodName($attributeCode, $filterEntry);
794
+ } catch(Exception $e) {
795
+ $this->_critical(self::RESOURCE_COLLECTION_FILTERING_ERROR);
796
+ }
797
+ }
798
+ return $this;
799
+ }
800
+
801
+ /**
802
+ * Perform multiple calls to subresources of specified resource
803
+ *
804
+ * @param string $resourceInstanceId
805
+ * @return Mage_Api2_Model_Response
806
+ */
807
+ protected function _multicall($resourceInstanceId)
808
+ {
809
+ if (!$this->_multicall) {
810
+ $this->_multicall = Mage::getModel('api2/multicall');
811
+ }
812
+ $resourceName = $this->getResourceType();
813
+ return $this->_multicall->call($resourceInstanceId, $resourceName, $this->getRequest());
814
+ }
815
+
816
+ /**
817
+ * Create model of specified resource and configure it with current object attributes
818
+ *
819
+ * @param string $resourceId Resource identifier
820
+ * @param array $requestParams Parameters to be set to request
821
+ * @return Mage_Api2_Model_Resource
822
+ */
823
+ protected function _getSubModel($resourceId, array $requestParams)
824
+ {
825
+ $resourceModel = Mage_Api2_Model_Dispatcher::loadResourceModel(
826
+ $this->getConfig()->getResourceModel($resourceId),
827
+ $this->getApiType(),
828
+ $this->getUserType(),
829
+ $this->getVersion()
830
+ );
831
+
832
+ /** @var $request Mage_Api2_Model_Request */
833
+ $request = Mage::getModel('api2/request');
834
+
835
+ $request->setParams($requestParams);
836
+
837
+ $resourceModel
838
+ ->setRequest($request) // request MUST be set first
839
+ ->setApiUser($this->getApiUser())
840
+ ->setApiType($this->getApiType())
841
+ ->setResourceType($resourceId)
842
+ ->setOperation($this->getOperation())
843
+ ->setReturnData(true);
844
+
845
+ return $resourceModel;
846
+ }
847
+
848
+ /**
849
+ * Check ACL permission for specified resource with current other conditions
850
+ *
851
+ * @param string $resourceId Resource identifier
852
+ * @return bool
853
+ * @throws Exception
854
+ */
855
+ protected function _isSubCallAllowed($resourceId)
856
+ {
857
+ /** @var $globalAcl Mage_Api2_Model_Acl_Global */
858
+ $globalAcl = Mage::getSingleton('api2/acl_global');
859
+
860
+ try {
861
+ return $globalAcl->isAllowed($this->getApiUser(), $resourceId, $this->getOperation());
862
+ } catch (Mage_Api2_Exception $e) {
863
+ throw new Exception('Invalid arguments for isAllowed() call');
864
+ }
865
+ }
866
+
867
+ /**
868
+ * Set 'returnData' flag
869
+ *
870
+ * @param boolean $flag
871
+ * @return Mage_Api2_Model_Resource
872
+ */
873
+ public function setReturnData($flag)
874
+ {
875
+ $this->_returnData = $flag;
876
+ return $this;
877
+ }
878
+
879
+ /**
880
+ * Get resource location
881
+ *
882
+ * @param Mage_Core_Model_Abstract $resource
883
+ * @return string URL
884
+ */
885
+ protected function _getLocation($resource)
886
+ {
887
+ /* @var $apiTypeRoute Mage_Api2_Model_Route_ApiType */
888
+ $apiTypeRoute = Mage::getModel('api2/route_apiType');
889
+
890
+ $chain = $apiTypeRoute->chain(
891
+ new Zend_Controller_Router_Route($this->getConfig()->getRouteWithEntityTypeAction($this->getResourceType()))
892
+ );
893
+ $params = array(
894
+ 'api_type' => $this->getRequest()->getApiType(),
895
+ 'id' => $resource->getId()
896
+ );
897
+ $uri = $chain->assemble($params);
898
+
899
+ return '/' . $uri;
900
+ }
901
+
902
+ /**
903
+ * Resource specific method to retrieve attributes' codes. May be overriden in child.
904
+ *
905
+ * @return array
906
+ */
907
+ protected function _getResourceAttributes()
908
+ {
909
+ return array();
910
+ }
911
+
912
+ /**
913
+ * Get available attributes of API resource
914
+ *
915
+ * @param string $userType
916
+ * @param string $operation
917
+ * @return array
918
+ */
919
+ public function getAvailableAttributes($userType, $operation)
920
+ {
921
+ $available = $this->getAvailableAttributesFromConfig();
922
+ $excludedAttrs = $this->getExcludedAttributes($userType, $operation);
923
+ $includedAttrs = $this->getIncludedAttributes($userType, $operation);
924
+ $entityOnlyAttrs = $this->getEntityOnlyAttributes($userType, $operation);
925
+ $resourceAttrs = $this->_getResourceAttributes();
926
+
927
+ // if resource returns not-associative array - attributes' codes only
928
+ if (0 === key($resourceAttrs)) {
929
+ $resourceAttrs = array_combine($resourceAttrs, $resourceAttrs);
930
+ }
931
+ foreach ($resourceAttrs as $attrCode => $attrLabel) {
932
+ if (!isset($available[$attrCode])) {
933
+ $available[$attrCode] = empty($attrLabel) ? $attrCode : $attrLabel;
934
+ }
935
+ }
936
+ foreach (array_keys($available) as $code) {
937
+ if (in_array($code, $excludedAttrs) || ($includedAttrs && !in_array($code, $includedAttrs))) {
938
+ unset($available[$code]);
939
+ }
940
+ if (in_array($code, $entityOnlyAttrs)) {
941
+ $available[$code] .= ' *';
942
+ }
943
+ }
944
+ return $available;
945
+ }
946
+
947
+ /**
948
+ * Get excluded attributes for user type
949
+ *
950
+ * @param string $userType
951
+ * @param string $operation
952
+ * @return array
953
+ */
954
+ public function getExcludedAttributes($userType, $operation)
955
+ {
956
+ return $this->getConfig()->getResourceExcludedAttributes($this->getResourceType(), $userType, $operation);
957
+ }
958
+
959
+ /**
960
+ * Get forced attributes
961
+ *
962
+ * @return array
963
+ */
964
+ public function getForcedAttributes()
965
+ {
966
+ return $this->getConfig()->getResourceForcedAttributes($this->getResourceType(), $this->getUserType());
967
+ }
968
+
969
+ /**
970
+ * Retrieve list of included attributes
971
+ *
972
+ * @param string $userType API user type
973
+ * @param string $operationType Type of operation: one of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
974
+ * @return array
975
+ */
976
+ public function getIncludedAttributes($userType, $operationType)
977
+ {
978
+ return $this->getConfig()->getResourceIncludedAttributes($this->getResourceType(), $userType, $operationType);
979
+ }
980
+
981
+ /**
982
+ * Retrieve list of entity only attributes
983
+ *
984
+ * @param string $userType API user type
985
+ * @param string $operationType Type of operation: one of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
986
+ * @return array
987
+ */
988
+ public function getEntityOnlyAttributes($userType, $operationType)
989
+ {
990
+ return $this->getConfig()->getResourceEntityOnlyAttributes($this->getResourceType(), $userType, $operationType);
991
+ }
992
+
993
+ /**
994
+ * Get available attributes of API resource from configuration file
995
+ *
996
+ * @return array
997
+ */
998
+ public function getAvailableAttributesFromConfig()
999
+ {
1000
+ return $this->getConfig()->getResourceAttributes($this->getResourceType());
1001
+ }
1002
+
1003
+ /**
1004
+ * Get available attributes of API resource from data base
1005
+ *
1006
+ * @return array
1007
+ */
1008
+ public function getDbAttributes()
1009
+ {
1010
+ $available = array();
1011
+ $workModel = $this->getConfig()->getResourceWorkingModel($this->getResourceType());
1012
+
1013
+ if ($workModel) {
1014
+ /* @var $resource Mage_Core_Model_Resource_Db_Abstract */
1015
+ $resource = Mage::getResourceModel($workModel);
1016
+
1017
+ if (method_exists($resource, 'getMainTable')) {
1018
+ $available = array_keys($resource->getReadConnection()->describeTable($resource->getMainTable()));
1019
+ }
1020
+ }
1021
+ return $available;
1022
+ }
1023
+
1024
+ /**
1025
+ * Get EAV attributes of working model
1026
+ *
1027
+ * @param bool $onlyVisible OPTIONAL Show only the attributes which are visible on frontend
1028
+ * @param bool $excludeSystem OPTIONAL Exclude attributes marked as system
1029
+ * @return array
1030
+ */
1031
+ public function getEavAttributes($onlyVisible = false, $excludeSystem = false)
1032
+ {
1033
+ $attributes = array();
1034
+ $model = $this->getConfig()->getResourceWorkingModel($this->getResourceType());
1035
+
1036
+ /** @var $entityType Mage_Eav_Model_Entity_Type */
1037
+ $entityType = Mage::getModel('eav/entity_type')->load($model, 'entity_model');
1038
+
1039
+ /** @var $attribute Mage_Eav_Model_Entity_Attribute */
1040
+ foreach ($entityType->getAttributeCollection() as $attribute) {
1041
+ if ($onlyVisible && !$attribute->getIsVisible()) {
1042
+ continue;
1043
+ }
1044
+ if ($excludeSystem && $attribute->getIsSystem()) {
1045
+ continue;
1046
+ }
1047
+ $attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel();
1048
+ }
1049
+
1050
+ return $attributes;
1051
+ }
1052
+
1053
+ /**
1054
+ * Retrieve current store according to request and API user type
1055
+ *
1056
+ * @return Mage_Core_Model_Store
1057
+ */
1058
+ protected function _getStore()
1059
+ {
1060
+ $store = $this->getRequest()->getParam('store');
1061
+ try {
1062
+ if ($this->getUserType() != Mage_Api2_Model_Auth_User_Admin::USER_TYPE) {
1063
+ // customer or guest role
1064
+ if (!$store) {
1065
+ $store = Mage::app()->getDefaultStoreView();
1066
+ } else {
1067
+ $store = Mage::app()->getStore($store);
1068
+ }
1069
+ } else {
1070
+ // admin role
1071
+ if (is_null($store)) {
1072
+ $store = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID;
1073
+ }
1074
+ $store = Mage::app()->getStore($store);
1075
+ }
1076
+ } catch (Mage_Core_Model_Store_Exception $e) {
1077
+ // store does not exist
1078
+ $this->_critical('Requested store is invalid', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
1079
+ }
1080
+ return $store;
1081
+ }
1082
+ }
app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 filter ACL attribute resource model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Acl_Filter_Attribute extends Mage_Core_Model_Resource_Db_Abstract
35
+ {
36
+ /**
37
+ * Attribute Filter resource ID "all"
38
+ */
39
+ const FILTER_RESOURCE_ALL = 'all';
40
+
41
+ /**
42
+ * Initialize resource model
43
+ *
44
+ * @return void
45
+ */
46
+ protected function _construct()
47
+ {
48
+ $this->_init('api2/acl_attribute', 'entity_id');
49
+ }
50
+
51
+ /**
52
+ * Get allowed attributes
53
+ *
54
+ * @param string $userType
55
+ * @param string $resourceId
56
+ * @param string $operation One of Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_... constant
57
+ * @return string|bool|null
58
+ */
59
+ public function getAllowedAttributes($userType, $resourceId, $operation)
60
+ {
61
+ $select = $this->_getReadAdapter()->select()
62
+ ->from($this->getMainTable(), 'allowed_attributes')
63
+ ->where('user_type = ?', $userType)
64
+ ->where('resource_id = ?', $resourceId)
65
+ ->where('operation = ?', $operation);
66
+
67
+ return $this->getReadConnection()->fetchOne($select);
68
+ }
69
+
70
+ /**
71
+ * Check if ALL attributes allowed
72
+ *
73
+ * @param string $userType
74
+ * @return bool
75
+ */
76
+ public function isAllAttributesAllowed($userType)
77
+ {
78
+ $resourceId = self::FILTER_RESOURCE_ALL;
79
+
80
+ $select = $this->getReadConnection()->select()
81
+ ->from($this->getMainTable(), new Zend_Db_Expr('COUNT(*)'))
82
+ ->where('user_type = ?', $userType)
83
+ ->where('resource_id = ?', $resourceId);
84
+
85
+ return ($this->getReadConnection()->fetchOne($select) == 1);
86
+ }
87
+ }
app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute/Collection.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 filter ACL attribute resource collection model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
35
+ {
36
+ /**
37
+ * Initialize collection model
38
+ *
39
+ * @return void
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('api2/acl_filter_attribute');
44
+ }
45
+
46
+ /**
47
+ * Add filtering by user type
48
+ *
49
+ * @param string $userType
50
+ * @return Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection
51
+ */
52
+ public function addFilterByUserType($userType)
53
+ {
54
+ $this->addFilter('user_type', $userType, 'public');
55
+ return $this;
56
+ }
57
+ }
app/code/core/Mage/Api2/Model/Resource/Acl/Global/Role.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 global ACL role resource model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ * @method int getId
34
+ * @method string getRoleName
35
+ */
36
+ class Mage_Api2_Model_Resource_Acl_Global_Role extends Mage_Core_Model_Resource_Db_Abstract
37
+ {
38
+ /**
39
+ * Initialize resource model
40
+ *
41
+ * @return void
42
+ */
43
+ protected function _construct()
44
+ {
45
+ $this->_init('api2/acl_role', 'entity_id');
46
+ }
47
+
48
+ /**
49
+ * Create/update relation row of admin user to API2 role
50
+ *
51
+ * @param int $adminId Admin user id
52
+ * @param int $roleId API2 role id
53
+ * @return Mage_Api2_Model_Resource_Acl_Global_Role
54
+ */
55
+ public function saveAdminToRoleRelation($adminId, $roleId)
56
+ {
57
+ if (Mage_Api2_Model_Acl_Global_Role::ROLE_GUEST_ID == $roleId
58
+ || Mage_Api2_Model_Acl_Global_Role::ROLE_CUSTOMER_ID == $roleId
59
+ ) {
60
+ Mage::throwException(
61
+ Mage::helper('api2')->__('The role is a special one and not for assigning it to admin users.')
62
+ );
63
+ }
64
+
65
+ $read = $this->_getReadAdapter();
66
+ $select = $read->select()
67
+ ->from($this->getTable('api2/acl_user'), 'admin_id')
68
+ ->where('admin_id = ?', $adminId, Zend_Db::INT_TYPE);
69
+
70
+ $write = $this->_getWriteAdapter();
71
+ $table = $this->getTable('api2/acl_user');
72
+
73
+ if (false === $read->fetchOne($select)) {
74
+ $write->insert($table, array('admin_id' => $adminId, 'role_id' => $roleId));
75
+ } else {
76
+ $write->update($table, array('role_id' => $roleId), array('admin_id = ?' => $adminId));
77
+ }
78
+
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * delete relation row of admin user to API2 role
84
+ *
85
+ * @param int $adminId Admin user id
86
+ * @param int $roleId API2 role id
87
+ * @return Mage_Api2_Model_Resource_Acl_Global_Role
88
+ */
89
+ public function deleteAdminToRoleRelation($adminId, $roleId)
90
+ {
91
+ $write = $this->_getWriteAdapter();
92
+ $table = $this->getTable('api2/acl_user');
93
+
94
+ $where = array(
95
+ 'role_id = ?' => $roleId,
96
+ 'admin_id = ?' => $adminId
97
+ );
98
+
99
+ $write->delete($table, $where);
100
+
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * Get users
106
+ *
107
+ * @param Mage_Api2_Model_Acl_Global_Role $role
108
+ * @return array
109
+ */
110
+ public function getRoleUsers(Mage_Api2_Model_Acl_Global_Role $role)
111
+ {
112
+ $adapter = $this->_getReadAdapter();
113
+ $select = $adapter->select()
114
+ ->from($this->getTable('api2/acl_user'))
115
+ ->where('role_id=?', $role->getId());
116
+
117
+ $users = $adapter->fetchCol($select);
118
+
119
+ return $users;
120
+ }
121
+ }
app/code/core/Mage/Api2/Model/Resource/Acl/Global/Role/Collection.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 global ACL role resource collection model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Acl_Global_Role_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
35
+ {
36
+ /**
37
+ * Initialize collection model
38
+ *
39
+ * @return void
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('api2/acl_global_role');
44
+ }
45
+
46
+ /**
47
+ * Add filter by admin user id and join table with appropriate information
48
+ *
49
+ * @param int $id Admin user id
50
+ * @return Mage_Api2_Model_Resource_Acl_Global_Role_Collection
51
+ */
52
+ public function addFilterByAdminId($id)
53
+ {
54
+ $this->getSelect()
55
+ ->joinInner(
56
+ array('user' => $this->getTable('api2/acl_user')),
57
+ 'main_table.entity_id = user.role_id',
58
+ array('admin_id' => 'user.admin_id'))
59
+ ->where('user.admin_id = ?', $id, Zend_Db::INT_TYPE);
60
+
61
+ return $this;
62
+ }
63
+ }
app/code/core/Mage/Api2/Model/Resource/Acl/Global/Rule.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 global ACL rule resource model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Acl_Global_Rule extends Mage_Core_Model_Resource_Db_Abstract
35
+ {
36
+ /**
37
+ * Initialize resource model
38
+ *
39
+ * @return void
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('api2/acl_rule', 'entity_id');
44
+ }
45
+ }
app/code/core/Mage/Api2/Model/Resource/Acl/Global/Rule/Collection.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Api2 global ACL rule resource collection model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Acl_Global_Rule_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
35
+ {
36
+ /**
37
+ * Initialize collection model
38
+ *
39
+ * @return void
40
+ */
41
+ protected function _construct()
42
+ {
43
+ $this->_init('api2/acl_global_rule');
44
+ }
45
+
46
+ /**
47
+ * Add filtering by role ID
48
+ *
49
+ * @param int $roleId
50
+ * @return Mage_Api2_Model_Resource_Acl_Global_Rule_Collection
51
+ */
52
+ public function addFilterByRoleId($roleId)
53
+ {
54
+ $this->addFilter('role_id', $roleId, 'public');
55
+ return $this;
56
+ }
57
+ }
app/code/core/Mage/Api2/Model/Resource/Setup.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 setup model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
35
+ {
36
+ }
app/code/core/Mage/Api2/Model/Resource/Validator.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Abstarct Validator
29
+ *
30
+ * This is an object to which we encapsulate all business logic of validation and different invariants.
31
+ * But instead of different validators, we group all logic in one class but in different methods.
32
+ *
33
+ * If fails validation, then validation method returns false, and
34
+ * getErrors() will return an array of errors that explain why the
35
+ * validation failed.
36
+ *
37
+ * @category Mage
38
+ * @package Mage_Api2
39
+ * @author Magento Core Team <core@magentocommerce.com>
40
+ */
41
+ abstract class Mage_Api2_Model_Resource_Validator
42
+ {
43
+ /**
44
+ * Array of validation failure errors.
45
+ *
46
+ * @var array
47
+ */
48
+ protected $_errors = array();
49
+
50
+ /**
51
+ * Set an array of errors
52
+ *
53
+ * @param array $data
54
+ * @return Mage_Api2_Model_Resource_Validator
55
+ */
56
+ protected function _setErrors(array $data)
57
+ {
58
+ $this->_errors = array_values($data);
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Add errors
64
+ *
65
+ * @param array $errors
66
+ * @return Mage_Api2_Model_Resource_Validator
67
+ */
68
+ protected function _addErrors($errors)
69
+ {
70
+ foreach ($errors as $error) {
71
+ $this->_addError($error);
72
+ }
73
+ return $this;
74
+ }
75
+
76
+ /**
77
+ * Add error
78
+ *
79
+ * @param string $error
80
+ * @return Mage_Api2_Model_Resource_Validator
81
+ */
82
+ protected function _addError($error)
83
+ {
84
+ $this->_errors[] = $error;
85
+ return $this;
86
+ }
87
+
88
+ /**
89
+ * Returns an array of errors that explain why the most recent isValidData()
90
+ * call returned false. The array keys are validation failure error identifiers,
91
+ * and the array values are the corresponding human-readable error strings.
92
+ *
93
+ * If isValidData() was never called or if the most recent isValidData() call
94
+ * returned true, then this method returns an empty array.
95
+ *
96
+ * @return array
97
+ */
98
+ public function getErrors()
99
+ {
100
+ return $this->_errors;
101
+ }
102
+ }
app/code/core/Mage/Api2/Model/Resource/Validator/Eav.php ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 EAV Validator
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Validator_Eav extends Mage_Api2_Model_Resource_Validator
35
+ {
36
+ /**
37
+ * Config node key of current validator
38
+ */
39
+ const CONFIG_NODE_KEY = 'eav';
40
+
41
+ /**
42
+ * Form path
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_formPath;
47
+
48
+ /**
49
+ * Entity model
50
+ *
51
+ * @var Mage_Core_Model_Abstract
52
+ */
53
+ protected $_entity;
54
+
55
+ /**
56
+ * Form code
57
+ *
58
+ * @var string
59
+ */
60
+ protected $_formCode;
61
+
62
+ /**
63
+ * Eav form model
64
+ *
65
+ * @var Mage_Eav_Model_Form
66
+ */
67
+ protected $_eavForm;
68
+
69
+ /**
70
+ * Construct. Set all depends.
71
+ *
72
+ * Required parameteres for options:
73
+ * - resource
74
+ *
75
+ * @param array $options
76
+ * @throws Exception If passed parameter 'resource' is wrong
77
+ * @throws Exception If config parameter 'formPath' is empty
78
+ * @throws Exception If config parameter 'formCode' is empty
79
+ * @throws Exception If config parameter 'entity' is wrong
80
+ * @throws Exception If entity is not model
81
+ * @throws Exception If eav form is not found
82
+ */
83
+ public function __construct($options)
84
+ {
85
+ if (!isset($options['resource']) || !$options['resource'] instanceof Mage_Api2_Model_Resource) {
86
+ throw new Exception("Passed parameter 'resource' is wrong.");
87
+ }
88
+ $resource = $options['resource'];
89
+ $userType = $resource->getUserType();
90
+
91
+ $validationConfig = $resource->getConfig()->getValidationConfig(
92
+ $resource->getResourceType(), self::CONFIG_NODE_KEY);
93
+
94
+ if (empty($validationConfig[$userType]['form_model'])) {
95
+ throw new Exception("Config parameter 'formPath' is empty.");
96
+ }
97
+ $this->_formPath = $validationConfig[$userType]['form_model'];
98
+
99
+ if (empty($validationConfig[$userType]['form_code'])) {
100
+ throw new Exception("Config parameter 'formCode' is empty.");
101
+ }
102
+ $this->_formCode = $validationConfig[$userType]['form_code'];
103
+
104
+ if (empty($validationConfig[$userType]['entity_model'])) {
105
+ throw new Exception("Config parameter 'entity' is wrong.");
106
+ }
107
+ $this->_entity = Mage::getModel($validationConfig[$userType]['entity_model']);
108
+ if (empty($this->_entity) || !$this->_entity instanceof Mage_Core_Model_Abstract) {
109
+ throw new Exception("Entity is not model.");
110
+ }
111
+
112
+ $this->_eavForm = Mage::getModel($this->_formPath);
113
+ if (empty($this->_eavForm) || !$this->_eavForm instanceof Mage_Eav_Model_Form) {
114
+ throw new Exception("Eav form '{$this->_formPath}' is not found.");
115
+ }
116
+ $this->_eavForm->setEntity($this->_entity)
117
+ ->setFormCode($this->_formCode)
118
+ ->ignoreInvisible(false);
119
+ }
120
+
121
+ /**
122
+ * Validate attribute value for attributes with source models
123
+ *
124
+ * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
125
+ * @param mixed $attrValue
126
+ * @return array|bool
127
+ */
128
+ protected function _validateAttributeWithSource(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $attrValue)
129
+ {
130
+ $errors = array();
131
+
132
+ // validate attributes with source models
133
+ if (null !== $attrValue && $attribute->getSourceModel()) {
134
+ if ('multiselect' !== $attribute->getFrontendInput() && is_array($attrValue)) {
135
+ return array('Invalid value type for ' . $attribute->getAttributeCode());
136
+ }
137
+ $possibleValues = $attribute->getSource()->getAllOptions(false);
138
+
139
+ foreach ((array) $attrValue as $value) {
140
+ if (is_scalar($value)) {
141
+ $value = (string) $value;
142
+ $isValid = false;
143
+ foreach ($possibleValues as $optionData) {
144
+ // comparison without types check is performed only when both values are numeric
145
+ $useStrictMode = !(is_numeric($value) && is_numeric($optionData['value']));
146
+ $isValid = $useStrictMode ? $value === $optionData['value'] : $value == $optionData['value'];
147
+ if ($isValid) {
148
+ break;
149
+ }
150
+ }
151
+ if (!$isValid) {
152
+ $errors[] = 'Invalid value "' . $value . '" for '. $attribute->getAttributeCode();
153
+ }
154
+ } else {
155
+ $errors[] = 'Invalid value type for ' . $attribute->getAttributeCode();
156
+ }
157
+ }
158
+ }
159
+ return $errors ? $errors : true;
160
+ }
161
+
162
+ /**
163
+ * Filter request data.
164
+ *
165
+ * @param array $data
166
+ * @return array Filtered data
167
+ */
168
+ public function filter(array $data)
169
+ {
170
+ return array_intersect_key($this->_eavForm->extractData($this->_eavForm->prepareRequest($data)), $data);
171
+ }
172
+
173
+ /**
174
+ * Validate entity.
175
+ * If the $partial parameter is TRUE, then we validate only those parameters that were passed.
176
+ *
177
+ * If fails validation, then this method returns false, and
178
+ * getErrors() will return an array of errors that explain why the
179
+ * validation failed.
180
+ *
181
+ * @param array $data
182
+ * @param bool $partial
183
+ * @return bool
184
+ */
185
+ public function isValidData(array $data, $partial = false)
186
+ {
187
+ $errors = array();
188
+ foreach ($this->_eavForm->getAttributes() as $attribute) {
189
+ if ($partial && !array_key_exists($attribute->getAttributeCode(), $data)) {
190
+ continue;
191
+ }
192
+ if ($this->_eavForm->ignoreInvisible() && !$attribute->getIsVisible()) {
193
+ continue;
194
+ }
195
+ $attrValue = isset($data[$attribute->getAttributeCode()]) ? $data[$attribute->getAttributeCode()] : null;
196
+
197
+ $result = Mage_Eav_Model_Attribute_Data::factory($attribute, $this->_eavForm->getEntity())
198
+ ->setExtractedData($data)
199
+ ->validateValue($attrValue);
200
+
201
+ if ($result !== true) {
202
+ $errors = array_merge($errors, $result);
203
+ } else {
204
+ $result = $this->_validateAttributeWithSource($attribute, $attrValue);
205
+
206
+ if (true !== $result) {
207
+ $errors = array_merge($errors, $result);
208
+ }
209
+ }
210
+ }
211
+ $this->_setErrors($errors);
212
+
213
+ return $errors ? false : true;
214
+ }
215
+
216
+ /**
217
+ * Returns an array of errors
218
+ *
219
+ * @return array
220
+ */
221
+ public function getErrors()
222
+ {
223
+ // business asked to avoid additional validation message, so we filter it here
224
+ $errors = array();
225
+ $helper = Mage::helper('eav');
226
+ $requiredAttrs = array();
227
+ $isRequiredRE = '/^' . str_replace('%s', '(.+)', preg_quote($helper->__('"%s" is a required value.'))). '$/';
228
+ $greaterThanRE = '/^' . str_replace(
229
+ '%s', '(.+)', preg_quote($helper->__('"%s" length must be equal or greater than %s characters.'))
230
+ ) . '$/';
231
+
232
+ // find all required attributes labels
233
+ foreach ($this->_errors as $error) {
234
+ if (preg_match($isRequiredRE, $error, $matches)) {
235
+ $requiredAttrs[$matches[1]] = true;
236
+ }
237
+ }
238
+ // exclude additional messages for required attributes been failed
239
+ foreach ($this->_errors as $error) {
240
+ if (preg_match($isRequiredRE, $error)
241
+ || !preg_match($greaterThanRE, $error, $matches)
242
+ || !isset($requiredAttrs[$matches[1]])
243
+ ) {
244
+ $errors[] = $error;
245
+ }
246
+ }
247
+ return $errors;
248
+ }
249
+ }
app/code/core/Mage/Api2/Model/Resource/Validator/Fields.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Fields Validator
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Resource_Validator_Fields extends Mage_Api2_Model_Resource_Validator
35
+ {
36
+ /**
37
+ * Config node key of current validator
38
+ */
39
+ const CONFIG_NODE_KEY = 'fields';
40
+
41
+ /**
42
+ * Resource
43
+ *
44
+ * @var Mage_Api2_Model_Resource
45
+ */
46
+ protected $_resource;
47
+
48
+ /**
49
+ * List of Validators (Zend_Validate_Interface)
50
+ * The key is a field name, a value is validator for this field
51
+ *
52
+ * @var array
53
+ */
54
+ protected $_validators;
55
+
56
+ /**
57
+ * List of required fields
58
+ *
59
+ * @var array
60
+ */
61
+ protected $_requiredFields;
62
+
63
+ /**
64
+ * Construct. Set all depends.
65
+ *
66
+ * Required parameteres for options:
67
+ * - resource
68
+ *
69
+ * @param array $options
70
+ * @throws Exception If passed parameter 'resource' is wrong
71
+ */
72
+ public function __construct($options)
73
+ {
74
+ if (!isset($options['resource']) || !$options['resource'] instanceof Mage_Api2_Model_Resource) {
75
+ throw new Exception("Passed parameter 'resource' is wrong.");
76
+ }
77
+ $this->_resource = $options['resource'];
78
+
79
+ $validationConfig = $this->_resource->getConfig()->getValidationConfig(
80
+ $this->_resource->getResourceType(), self::CONFIG_NODE_KEY);
81
+ if (!is_array($validationConfig)) {
82
+ $validationConfig = array();
83
+ }
84
+ $this->_buildValidatorsChain($validationConfig);
85
+ }
86
+
87
+ /**
88
+ * Build validator chain with config data
89
+ *
90
+ * @param array $validationConfig
91
+ * @throws Exception If validator type is not set
92
+ * @throws Exception If validator is not exist
93
+ */
94
+ protected function _buildValidatorsChain(array $validationConfig)
95
+ {
96
+ foreach ($validationConfig as $field => $validatorsConfig) {
97
+ if (count($validatorsConfig)) {
98
+ $chainForOneField = new Zend_Validate();
99
+ foreach ($validatorsConfig as $validatorName => $validatorConfig) {
100
+ // it is required field
101
+ if ('required' == $validatorName && 1 == $validatorConfig) {
102
+ $this->_requiredFields[] = $field;
103
+ continue;
104
+ }
105
+ // instantiation of the validator class
106
+ if (!isset($validatorConfig['type'])) {
107
+ throw new Exception("Validator type is not set for {$validatorName}");
108
+ }
109
+ $validator = $this->_getValidatorInstance(
110
+ $validatorConfig['type'],
111
+ !empty($validatorConfig['options']) ? $validatorConfig['options'] : array()
112
+ );
113
+ // set custom message
114
+ if (isset($validatorConfig['message'])) {
115
+ $validator->setMessage($validatorConfig['message']);
116
+ }
117
+ // add to list of validators
118
+ $chainForOneField->addValidator($validator);
119
+ }
120
+ $this->_validators[$field] = $chainForOneField;
121
+ }
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Get validator object instance
127
+ * Override the method if we need to use not only Zend validators!
128
+ *
129
+ * @param string $type
130
+ * @param array $options
131
+ * @return Zend_Validate_Interface
132
+ * @throws Exception If validator is not exist
133
+ */
134
+ protected function _getValidatorInstance($type, $options)
135
+ {
136
+ $validatorClass = 'Zend_Validate_' . $type;
137
+ if (!class_exists($validatorClass)) {
138
+ throw new Exception("Validator {$type} is not exist");
139
+ }
140
+ return new $validatorClass($options);
141
+ }
142
+
143
+ /**
144
+ * Validate data.
145
+ * If fails validation, then this method returns false, and
146
+ * getErrors() will return an array of errors that explain why the
147
+ * validation failed.
148
+ *
149
+ * @param array $data
150
+ * @param bool $isPartial
151
+ * @return bool
152
+ */
153
+ public function isValidData(array $data, $isPartial = false)
154
+ {
155
+ $isValid = true;
156
+
157
+ // required fields
158
+ if (!$isPartial && count($this->_requiredFields) > 0) {
159
+ $notEmptyValidator = new Zend_Validate_NotEmpty();
160
+ foreach ($this->_requiredFields as $requiredField) {
161
+ if (!$notEmptyValidator->isValid(isset($data[$requiredField]) ? $data[$requiredField] : null)) {
162
+ $isValid = false;
163
+ foreach ($notEmptyValidator->getMessages() as $message) {
164
+ $this->_addError(sprintf('%s: %s', $requiredField, $message));
165
+ }
166
+ }
167
+ }
168
+ }
169
+
170
+ // fields rules
171
+ foreach ($data as $field => $value) {
172
+ if (isset($this->_validators[$field])) {
173
+ /* @var $validator Zend_Validate_Interface */
174
+ $validator = $this->_validators[$field];
175
+ if (!$validator->isValid($value)) {
176
+ $isValid = false;
177
+ foreach ($validator->getMessages() as $message) {
178
+ $this->_addError(sprintf('%s: %s', $field, $message));
179
+ }
180
+ }
181
+ }
182
+ }
183
+
184
+ return $isValid;
185
+ }
186
+ }
app/code/core/Mage/Api2/Model/Response.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API Response model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Response extends Zend_Controller_Response_Http
35
+ {
36
+ /**
37
+ * Character set which must be used in response
38
+ */
39
+ const RESPONSE_CHARSET = 'utf-8';
40
+
41
+ /**#@+
42
+ * Default message types
43
+ */
44
+ const MESSAGE_TYPE_SUCCESS = 'success';
45
+ const MESSAGE_TYPE_ERROR = 'error';
46
+ const MESSAGE_TYPE_WARNING = 'warning';
47
+ /**#@- */
48
+
49
+ /**
50
+ * Messages
51
+ *
52
+ * @var array
53
+ */
54
+ protected $_messages = array();
55
+
56
+ /**
57
+ * Set header appropriate to specified MIME type
58
+ *
59
+ * @param string $mimeType MIME type
60
+ * @return Mage_Api2_Model_Response
61
+ */
62
+ public function setMimeType($mimeType)
63
+ {
64
+ return $this->setHeader('Content-Type', "{$mimeType}; charset=" . self::RESPONSE_CHARSET, true);
65
+ }
66
+
67
+ /**
68
+ * Add message to responce
69
+ *
70
+ * @param string $message
71
+ * @param string $code
72
+ * @param array $params
73
+ * @param string $type
74
+ * return Mage_Api2_Model_Response
75
+ */
76
+ public function addMessage($message, $code, $params = array(), $type = self::MESSAGE_TYPE_ERROR)
77
+ {
78
+ $params['message'] = $message;
79
+ $params['code'] = $code;
80
+ $this->_messages[$type][] = $params;
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * Has messages
86
+ *
87
+ * @return bool
88
+ */
89
+ public function hasMessages()
90
+ {
91
+ return (bool)count($this->_messages) > 0;
92
+ }
93
+
94
+ /**
95
+ * Return messages
96
+ *
97
+ * @return array
98
+ */
99
+ public function getMessages()
100
+ {
101
+ return $this->_messages;
102
+ }
103
+
104
+ /**
105
+ * Clear messages
106
+ *
107
+ * return Mage_Api2_Model_Response
108
+ */
109
+ public function clearMessages()
110
+ {
111
+ $this->_messages = array();
112
+ return $this;
113
+ }
114
+ }
app/code/core/Mage/Api2/Model/Route/Abstract.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice apia2 route abstract
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Api2_Model_Route_Abstract extends Zend_Controller_Router_Route
35
+ {
36
+ /**#@+
37
+ * Names for Zend_Controller_Router_Route::__construct params
38
+ */
39
+ const PARAM_ROUTE = 'route';
40
+ const PARAM_DEFAULTS = 'defaults';
41
+ const PARAM_REQS = 'reqs';
42
+ const PARAM_TRANSLATOR = 'translator';
43
+ const PARAM_LOCALE = 'locale';
44
+ /**#@- */
45
+
46
+ /*
47
+ * Default values of parent::__construct() params
48
+ *
49
+ * @var array
50
+ */
51
+ protected $_paramsDefaultValues = array(
52
+ self::PARAM_ROUTE => null,
53
+ self::PARAM_DEFAULTS => array(),
54
+ self::PARAM_REQS => array(),
55
+ self::PARAM_TRANSLATOR => null,
56
+ self::PARAM_LOCALE => null
57
+ );
58
+
59
+ /**
60
+ * Process construct param and call parent::__construct() with params
61
+ *
62
+ * @param array $arguments
63
+ */
64
+ public function __construct(array $arguments)
65
+ {
66
+ parent::__construct(
67
+ $this->_getArgumentValue(self::PARAM_ROUTE, $arguments),
68
+ $this->_getArgumentValue(self::PARAM_DEFAULTS, $arguments),
69
+ $this->_getArgumentValue(self::PARAM_REQS, $arguments),
70
+ $this->_getArgumentValue(self::PARAM_TRANSLATOR, $arguments),
71
+ $this->_getArgumentValue(self::PARAM_LOCALE, $arguments)
72
+ );
73
+ }
74
+
75
+ /**
76
+ * Retrieve argument value
77
+ *
78
+ * @param string $name argument name
79
+ * @param array $arguments
80
+ * @return mixed
81
+ */
82
+ protected function _getArgumentValue($name, array $arguments)
83
+ {
84
+ return isset($arguments[$name]) ? $arguments[$name] : $this->_paramsDefaultValues[$name];
85
+ }
86
+
87
+ /**
88
+ * Matches a Request with parts defined by a map. Assigns and
89
+ * returns an array of variables on a successful match.
90
+ *
91
+ * @param Mage_Api2_Model_Request $request
92
+ * @param boolean $partial Partial path matching
93
+ * @return array|bool An array of assigned values or a boolean false on a mismatch
94
+ */
95
+ public function match($request, $partial = false)
96
+ {
97
+ return parent::match(ltrim($request->getPathInfo(), $this->_urlDelimiter), $partial);
98
+ }
99
+ }
app/code/core/Mage/Api2/Model/Route/ApiType.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice Api2 Route to find out API type from request
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Route_ApiType extends Mage_Api2_Model_Route_Abstract implements Mage_Api2_Model_Route_Interface
35
+ {
36
+ /**
37
+ * API url template with API type variable
38
+ */
39
+ const API_ROUTE = 'api/:api_type';
40
+
41
+ /**
42
+ * Prepares the route for mapping by splitting (exploding) it
43
+ * to a corresponding atomic parts. These parts are assigned
44
+ * a position which is later used for matching and preparing values.
45
+ *
46
+ * @param string $route Map used to match with later submitted URL path
47
+ * @param array $defaults Defaults for map variables with keys as variable names
48
+ * @param array $reqs Regular expression requirements for variables (keys as variable names)
49
+ * @param Zend_Translate $translator Translator to use for this instance
50
+ * @param mixed $locale
51
+ */
52
+ public function __construct($route, $defaults = array(), $reqs = array(), Zend_Translate $translator = null,
53
+ $locale = null
54
+ ) {
55
+ parent::__construct(array(Mage_Api2_Model_Route_Abstract::PARAM_ROUTE => self::API_ROUTE));
56
+ }
57
+ }
app/code/core/Mage/Api2/Model/Route/Interface.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice apia2 route interface
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ interface Mage_Api2_Model_Route_Interface
35
+ {
36
+ /**
37
+ * Matches a Request with parts defined by a map. Assigns and
38
+ * returns an array of variables on a successful match.
39
+ *
40
+ * @param Mage_Api2_Model_Request $request
41
+ * @param boolean $partial Partial path matching
42
+ * @return array|false An array of assigned values or a false on a mismatch
43
+ */
44
+ public function match($request, $partial = false);
45
+ }
app/code/core/Mage/Api2/Model/Route/Rest.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice apia2 REST route
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Route_Rest extends Mage_Api2_Model_Route_Abstract implements Mage_Api2_Model_Route_Interface
35
+ {
36
+ }
app/code/core/Mage/Api2/Model/Router.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Webservice api2 router model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Router
35
+ {
36
+ /**
37
+ * Routes which are stored in module config files api2.xml
38
+ *
39
+ * @var array
40
+ */
41
+ protected $_routes = array();
42
+
43
+ /**
44
+ * Set routes
45
+ *
46
+ * @param array $routes
47
+ * @return Mage_Api2_Model_Router
48
+ */
49
+ public function setRoutes(array $routes)
50
+ {
51
+ $this->_routes = $routes;
52
+
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * Get routes
58
+ *
59
+ * @return array
60
+ */
61
+ public function getRoutes()
62
+ {
63
+ return $this->_routes;
64
+ }
65
+
66
+ /**
67
+ * Route the Request, the only responsibility of the class
68
+ * Find route that match current URL, set parameters of the route to Request object
69
+ *
70
+ * @param Mage_Api2_Model_Request $request
71
+ * @return Mage_Api2_Model_Request
72
+ * @throws Mage_Api2_Exception
73
+ */
74
+ public function route(Mage_Api2_Model_Request $request)
75
+ {
76
+ $isMatched = false;
77
+
78
+ /** @var $route Mage_Api2_Model_Route_Interface */
79
+ foreach ($this->getRoutes() as $route) {
80
+ if ($params = $route->match($request)) {
81
+ $request->setParams($params);
82
+ $isMatched = true;
83
+ break;
84
+ }
85
+ }
86
+ if (!$isMatched) {
87
+ throw new Mage_Api2_Exception('Request does not match any route.', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
88
+ }
89
+ if (!$request->getResourceType() || !$request->getModel()) {
90
+ throw new Mage_Api2_Exception('Matched resource is not properly set.',
91
+ Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
92
+ }
93
+ return $request;
94
+ }
95
+
96
+ /**
97
+ * Set API type to request as a result of one pass route
98
+ *
99
+ * @param Mage_Api2_Model_Request $request
100
+ * @param boolean $trimApiTypePath OPTIONAL If TRUE - /api/:api_type part of request path info will be trimmed
101
+ * @return Mage_Api2_Model_Router
102
+ * @throws Mage_Api2_Exception
103
+ */
104
+ public function routeApiType(Mage_Api2_Model_Request $request, $trimApiTypePath = true)
105
+ {
106
+ /** @var $apiTypeRoute Mage_Api2_Model_Route_ApiType */
107
+ $apiTypeRoute = Mage::getModel('api2/route_apiType');
108
+
109
+ if (!($apiTypeMatch = $apiTypeRoute->match($request, true))) {
110
+ throw new Mage_Api2_Exception('Request does not match type route.', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
111
+ }
112
+ // Trim matched URI path for next routes
113
+ if ($trimApiTypePath) {
114
+ $matchedPathLength = strlen('/' . ltrim($apiTypeRoute->getMatchedPath(), '/'));
115
+
116
+ $request->setPathInfo(substr($request->getPathInfo(), $matchedPathLength));
117
+ }
118
+ $request->setParam('api_type', $apiTypeMatch['api_type']);
119
+
120
+ return $this;
121
+ }
122
+ }
app/code/core/Mage/Api2/Model/Server.php ADDED
@@ -0,0 +1,315 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Server
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Model_Server
35
+ {
36
+ /**
37
+ * Api2 REST type
38
+ */
39
+ const API_TYPE_REST = 'rest';
40
+
41
+ /**#@+
42
+ * HTTP Response Codes
43
+ */
44
+ const HTTP_OK = 200;
45
+ const HTTP_CREATED = 201;
46
+ const HTTP_MULTI_STATUS = 207;
47
+ const HTTP_BAD_REQUEST = 400;
48
+ const HTTP_UNAUTHORIZED = 401;
49
+ const HTTP_FORBIDDEN = 403;
50
+ const HTTP_NOT_FOUND = 404;
51
+ const HTTP_METHOD_NOT_ALLOWED = 405;
52
+ const HTTP_NOT_ACCEPTABLE = 406;
53
+ const HTTP_INTERNAL_ERROR = 500;
54
+ /**#@- */
55
+
56
+ /**
57
+ * List of api types
58
+ *
59
+ * @var array
60
+ */
61
+ protected static $_apiTypes = array(self::API_TYPE_REST);
62
+
63
+ /**
64
+ * @var Mage_Api2_Model_Auth_User_Abstract
65
+ */
66
+ protected $_authUser;
67
+
68
+ /**
69
+ * Run server
70
+ */
71
+ public function run()
72
+ {
73
+ // can not use response object case
74
+ try {
75
+ /** @var $response Mage_Api2_Model_Response */
76
+ $response = Mage::getSingleton('api2/response');
77
+ } catch (Exception $e) {
78
+ Mage::logException($e);
79
+
80
+ if (!headers_sent()) {
81
+ header('HTTP/1.1 ' . self::HTTP_INTERNAL_ERROR);
82
+ }
83
+ echo 'Service temporary unavailable';
84
+ return;
85
+ }
86
+ // can not render errors case
87
+ try {
88
+ /** @var $request Mage_Api2_Model_Request */
89
+ $request = Mage::getSingleton('api2/request');
90
+ /** @var $renderer Mage_Api2_Model_Renderer_Interface */
91
+ $renderer = Mage_Api2_Model_Renderer::factory($request->getAcceptTypes());
92
+ } catch (Exception $e) {
93
+ Mage::logException($e);
94
+
95
+ $response->setHttpResponseCode(self::HTTP_INTERNAL_ERROR)
96
+ ->setBody('Service temporary unavailable')
97
+ ->sendResponse();
98
+ return;
99
+ }
100
+ // default case
101
+ try {
102
+ /** @var $apiUser Mage_Api2_Model_Auth_User_Abstract */
103
+ $apiUser = $this->_authenticate($request);
104
+
105
+ $this->_route($request)
106
+ ->_allow($request, $apiUser)
107
+ ->_dispatch($request, $response, $apiUser);
108
+
109
+ if ($response->getHttpResponseCode() == self::HTTP_CREATED) {
110
+ // TODO: Re-factor this after _renderException refactoring
111
+ throw new Mage_Api2_Exception('Resource was partially created', self::HTTP_CREATED);
112
+ }
113
+ //NOTE: At this moment Renderer already could have some content rendered, so we should replace it
114
+ if ($response->isException()) {
115
+ throw new Mage_Api2_Exception('Unhandled simple errors.', self::HTTP_INTERNAL_ERROR);
116
+ }
117
+ } catch (Exception $e) {
118
+ Mage::logException($e);
119
+ $this->_renderException($e, $renderer, $response);
120
+ }
121
+
122
+ $response->sendResponse();
123
+ }
124
+
125
+ /**
126
+ * Make internal call to api
127
+ *
128
+ * @param Mage_Api2_Model_Request $request
129
+ * @param Mage_Api2_Model_Response $response
130
+ * @return Mage_Api2_Model_Response
131
+ */
132
+ public function internalCall(Mage_Api2_Model_Request $request, Mage_Api2_Model_Response $response)
133
+ {
134
+ $apiUser = $this->_getAuthUser();
135
+ $this->_route($request)
136
+ ->_allow($request, $apiUser)
137
+ ->_dispatch($request, $response, $apiUser);
138
+ }
139
+
140
+ /**
141
+ * Authenticate user
142
+ *
143
+ * @throws Exception
144
+ * @param Mage_Api2_Model_Request $request
145
+ * @return Mage_Api2_Model_Auth_User_Abstract
146
+ */
147
+ protected function _authenticate(Mage_Api2_Model_Request $request)
148
+ {
149
+ /** @var $authManager Mage_Api2_Model_Auth */
150
+ $authManager = Mage::getModel('api2/auth');
151
+
152
+ $this->_setAuthUser($authManager->authenticate($request));
153
+ return $this->_getAuthUser();
154
+ }
155
+
156
+ /**
157
+ * Set auth user
158
+ *
159
+ * @throws Exception
160
+ * @param Mage_Api2_Model_Auth_User_Abstract $authUser
161
+ * @return Mage_Api2_Model_Server
162
+ */
163
+ protected function _setAuthUser(Mage_Api2_Model_Auth_User_Abstract $authUser)
164
+ {
165
+ $this->_authUser = $authUser;
166
+ return $this;
167
+ }
168
+
169
+ /**
170
+ * Retrieve existing auth user
171
+ *
172
+ * @throws Exception
173
+ * @return Mage_Api2_Model_Auth_User_Abstract
174
+ */
175
+ protected function _getAuthUser()
176
+ {
177
+ if (!$this->_authUser) {
178
+ throw new Exception("Mage_Api2_Model_Server::internalCall() seems to be executed "
179
+ . "before Mage_Api2_Model_Server::run()");
180
+ }
181
+ return $this->_authUser;
182
+ }
183
+
184
+ /**
185
+ * Set all routes of the given api type to Route object
186
+ * Find route that match current URL, set parameters of the route to Request object
187
+ *
188
+ * @param Mage_Api2_Model_Request $request
189
+ * @return Mage_Api2_Model_Server
190
+ */
191
+ protected function _route(Mage_Api2_Model_Request $request)
192
+ {
193
+ /** @var $router Mage_Api2_Model_Router */
194
+ $router = Mage::getModel('api2/router');
195
+
196
+ $router->routeApiType($request, true)
197
+ ->setRoutes($this->_getConfig()->getRoutes($request->getApiType()))
198
+ ->route($request);
199
+
200
+ return $this;
201
+ }
202
+
203
+ /**
204
+ * Global ACL processing
205
+ *
206
+ * @param Mage_Api2_Model_Request $request
207
+ * @param Mage_Api2_Model_Auth_User_Abstract $apiUser
208
+ * @return Mage_Api2_Model_Server
209
+ * @throws Mage_Api2_Exception
210
+ */
211
+ protected function _allow(Mage_Api2_Model_Request $request, Mage_Api2_Model_Auth_User_Abstract $apiUser)
212
+ {
213
+ /** @var $globalAcl Mage_Api2_Model_Acl_Global */
214
+ $globalAcl = Mage::getModel('api2/acl_global');
215
+
216
+ if (!$globalAcl->isAllowed($apiUser, $request->getResourceType(), $request->getOperation())) {
217
+ throw new Mage_Api2_Exception('Access denied', self::HTTP_FORBIDDEN);
218
+ }
219
+ return $this;
220
+ }
221
+
222
+ /**
223
+ * Load class file, instantiate resource class, set parameters to the instance, run resource internal dispatch
224
+ * method
225
+ *
226
+ * @param Mage_Api2_Model_Request $request
227
+ * @param Mage_Api2_Model_Response $response
228
+ * @param Mage_Api2_Model_Auth_User_Abstract $apiUser
229
+ * @return Mage_Api2_Model_Server
230
+ */
231
+ protected function _dispatch(
232
+ Mage_Api2_Model_Request $request,
233
+ Mage_Api2_Model_Response $response,
234
+ Mage_Api2_Model_Auth_User_Abstract $apiUser
235
+ )
236
+ {
237
+ /** @var $dispatcher Mage_Api2_Model_Dispatcher */
238
+ $dispatcher = Mage::getModel('api2/dispatcher');
239
+ $dispatcher->setApiUser($apiUser)->dispatch($request, $response);
240
+
241
+ return $this;
242
+ }
243
+
244
+ /**
245
+ * Get api2 config instance
246
+ *
247
+ * @return Mage_Api2_Model_Config
248
+ */
249
+ protected function _getConfig()
250
+ {
251
+ return Mage::getModel('api2/config');
252
+ }
253
+
254
+ /**
255
+ * Process thrown exception
256
+ * Generate and set HTTP response code, error message to Response object
257
+ *
258
+ * @param Exception $exception
259
+ * @param Mage_Api2_Model_Renderer_Interface $renderer
260
+ * @param Mage_Api2_Model_Response $response
261
+ * @return Mage_Api2_Model_Server
262
+ */
263
+ protected function _renderException(Exception $exception, Mage_Api2_Model_Renderer_Interface $renderer,
264
+ Mage_Api2_Model_Response $response
265
+ ) {
266
+ if ($exception instanceof Mage_Api2_Exception && $exception->getCode()) {
267
+ $httpCode = $exception->getCode();
268
+ } else {
269
+ $httpCode = self::HTTP_INTERNAL_ERROR;
270
+ }
271
+ try {
272
+ //add last error to stack
273
+ $response->setException($exception);
274
+
275
+ $messages = array();
276
+
277
+ /** @var Exception $exception */
278
+ foreach ($response->getException() as $exception) {
279
+ $message = array('code' => $exception->getCode(), 'message' => $exception->getMessage());
280
+
281
+ if (Mage::getIsDeveloperMode()) {
282
+ $message['trace'] = $exception->getTraceAsString();
283
+ }
284
+ $messages['messages']['error'][] = $message;
285
+ }
286
+ //set HTTP Code of last error, Content-Type and Body
287
+ $response->setBody($renderer->render($messages));
288
+ $response->setHeader('Content-Type', sprintf(
289
+ '%s; charset=%s', $renderer->getMimeType(), Mage_Api2_Model_Response::RESPONSE_CHARSET
290
+ ));
291
+ } catch (Exception $e) {
292
+ //tunnelling of 406(Not acceptable) error
293
+ $httpCode = $e->getCode() == self::HTTP_NOT_ACCEPTABLE //$e->getCode() can result in one more loop
294
+ ? self::HTTP_NOT_ACCEPTABLE // of try..catch
295
+ : self::HTTP_INTERNAL_ERROR;
296
+
297
+ //if error appeared in "error rendering" process then show it in plain text
298
+ $response->setBody($e->getMessage());
299
+ $response->setHeader('Content-Type', 'text/plain; charset=' . Mage_Api2_Model_Response::RESPONSE_CHARSET);
300
+ }
301
+ $response->setHttpResponseCode($httpCode);
302
+
303
+ return $this;
304
+ }
305
+
306
+ /**
307
+ * Retrieve api types
308
+ *
309
+ * @return array
310
+ */
311
+ public static function getApiTypes()
312
+ {
313
+ return self::$_apiTypes;
314
+ }
315
+ }
app/code/core/Mage/Api2/controllers/Adminhtml/Api2/AttributeController.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 attribute controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Adminhtml_Api2_AttributeController extends Mage_Adminhtml_Controller_Action
35
+ {
36
+ /**
37
+ * Show user types grid
38
+ */
39
+ public function indexAction()
40
+ {
41
+ $this->_title($this->__('System'))
42
+ ->_title($this->__('Web Services'))
43
+ ->_title($this->__('REST Attributes'));
44
+
45
+ $this->loadLayout()->_setActiveMenu('system/services/attributes');
46
+
47
+ $this->_addBreadcrumb($this->__('Web services'), $this->__('Web services'))
48
+ ->_addBreadcrumb($this->__('REST Attributes'), $this->__('REST Attributes'))
49
+ ->_addBreadcrumb($this->__('Attributes'), $this->__('Attributes'));
50
+
51
+ $this->renderLayout();
52
+ }
53
+
54
+ /**
55
+ * Edit role
56
+ */
57
+ public function editAction()
58
+ {
59
+ $this->loadLayout()
60
+ ->_setActiveMenu('system/services/attributes');
61
+
62
+ $type = $this->getRequest()->getParam('type');
63
+
64
+ $userTypes = Mage_Api2_Model_Auth_User::getUserTypes();
65
+ if (!isset($userTypes[$type])) {
66
+ $this->_getSession()->addError($this->__('User type "%s" not found.', $type));
67
+ $this->_redirect('*/*/');
68
+ return;
69
+ }
70
+
71
+ $this->_title($this->__('System'))
72
+ ->_title($this->__('Web Services'))
73
+ ->_title($this->__('REST ACL Attributes'));
74
+
75
+ $title = $this->__('Edit %s ACL attribute rules', $userTypes[$type]);
76
+ $this->_title($title);
77
+ $this->_addBreadcrumb($title, $title);
78
+
79
+ $this->renderLayout();
80
+ }
81
+
82
+ /**
83
+ * Save role
84
+ */
85
+ public function saveAction()
86
+ {
87
+ $request = $this->getRequest();
88
+
89
+ $type = $request->getParam('type');
90
+
91
+ if (!$type) {
92
+ $this->_getSession()->addError(
93
+ $this->__('User type "%s" no longer exists', $type));
94
+ $this->_redirect('*/*/');
95
+ return;
96
+ }
97
+
98
+ /** @var $session Mage_Adminhtml_Model_Session */
99
+ $session = $this->_getSession();
100
+
101
+ try {
102
+ /** @var $ruleTree Mage_Api2_Model_Acl_Global_Rule_Tree */
103
+ $ruleTree = Mage::getSingleton(
104
+ 'api2/acl_global_rule_tree',
105
+ array('type' => Mage_Api2_Model_Acl_Global_Rule_Tree::TYPE_ATTRIBUTE)
106
+ );
107
+
108
+ /** @var $attribute Mage_Api2_Model_Acl_Filter_Attribute */
109
+ $attribute = Mage::getModel('api2/acl_filter_attribute');
110
+
111
+ /** @var $collection Mage_Api2_Model_Resource_Acl_Filter_Attribute_Collection */
112
+ $collection = $attribute->getCollection();
113
+ $collection->addFilterByUserType($type);
114
+
115
+ /** @var $model Mage_Api2_Model_Acl_Filter_Attribute */
116
+ foreach ($collection as $model) {
117
+ $model->delete();
118
+ }
119
+
120
+ foreach ($ruleTree->getPostResources() as $resourceId => $operations) {
121
+ if (Mage_Api2_Model_Acl_Global_Rule::RESOURCE_ALL === $resourceId) {
122
+ $attribute->setUserType($type)
123
+ ->setResourceId($resourceId)
124
+ ->save();
125
+ } else {
126
+ foreach ($operations as $operation => $attributes) {
127
+ $attribute->setId(null)
128
+ ->isObjectNew(true);
129
+
130
+ $attribute->setUserType($type)
131
+ ->setResourceId($resourceId)
132
+ ->setOperation($operation)
133
+ ->setAllowedAttributes(implode(',', array_keys($attributes)))
134
+ ->save();
135
+ }
136
+ }
137
+ }
138
+
139
+ $session->addSuccess($this->__('The attribute rules were saved.'));
140
+ } catch (Mage_Core_Exception $e) {
141
+ $session->addError($e->getMessage());
142
+ } catch (Exception $e) {
143
+ $session->addException($e, $this->__('An error occurred while saving attribute rules.'));
144
+ }
145
+
146
+ $this->_redirect('*/*/edit', array('type' => $type));
147
+ }
148
+ }
app/code/core/Mage/Api2/controllers/Adminhtml/Api2/RoleController.php ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 roles controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Api2
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Api2_Adminhtml_Api2_RoleController extends Mage_Adminhtml_Controller_Action
35
+ {
36
+ /**
37
+ * Show grid
38
+ */
39
+ public function indexAction()
40
+ {
41
+ $this->_title($this->__('System'))
42
+ ->_title($this->__('Web Services'))
43
+ ->_title($this->__('REST Roles'));
44
+
45
+ $this->loadLayout()->_setActiveMenu('system/services/roles');
46
+ $this->_addBreadcrumb($this->__('Web services'), $this->__('Web services'));
47
+ $this->_addBreadcrumb($this->__('REST Roles'), $this->__('REST Roles'));
48
+ $this->_addBreadcrumb($this->__('Roles'), $this->__('Roles'));
49
+
50
+ $this->renderLayout();
51
+ }
52
+
53
+ /**
54
+ * Updating grid by ajax
55
+ */
56
+ public function gridAction()
57
+ {
58
+ $this->loadLayout();
59
+ $this->renderLayout();
60
+ }
61
+
62
+ /**
63
+ * Updating users grid by ajax
64
+ */
65
+ public function usersGridAction()
66
+ {
67
+ $id = $this->getRequest()->getParam('id', false);
68
+
69
+ $this->loadLayout();
70
+ /** @var $grid Mage_Api2_Block_Adminhtml_Roles_Tab_Users */
71
+ $grid = $this->getLayout()->getBlock('adminhtml.role.edit.tab.users');
72
+ $grid->setUsers($this->_getUsers($id));
73
+
74
+ $this->renderLayout();
75
+ }
76
+
77
+ /**
78
+ * Create new role
79
+ */
80
+ public function newAction()
81
+ {
82
+ $this->_title($this->__('System'))
83
+ ->_title($this->__('Web Services'))
84
+ ->_title($this->__('Rest Roles'));
85
+
86
+ $this->loadLayout()->_setActiveMenu('system/services/roles');
87
+ $this->_addBreadcrumb($this->__('Web services'), $this->__('Web services'));
88
+ $this->_addBreadcrumb($this->__('REST Roles'), $this->__('REST Roles'));
89
+ $this->_addBreadcrumb($this->__('Roles'), $this->__('Roles'));
90
+
91
+ $breadCrumb = $this->__('Add New Role');
92
+ $breadCrumbTitle = $this->__('Add New Role');
93
+ $this->_title($this->__('New Role'));
94
+
95
+ $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle);
96
+
97
+ $this->renderLayout();
98
+ }
99
+
100
+ /**
101
+ * Edit role
102
+ */
103
+ public function editAction()
104
+ {
105
+ $id = (int) $this->getRequest()->getParam('id');
106
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
107
+ $role = Mage::getModel('api2/acl_global_role')->load($id);
108
+
109
+ if (!$role->getId()) {
110
+ $this->_getSession()->addError($this->__('Role "%s" not found.', $id));
111
+ $this->_redirect('*/*/');
112
+ return;
113
+ }
114
+
115
+ $this->loadLayout()->_setActiveMenu('system/services/roles');
116
+
117
+ $this->_title($this->__('System'))
118
+ ->_title($this->__('Web Services'))
119
+ ->_title($this->__('Rest Roles'));
120
+
121
+ $breadCrumb = $this->__('Edit Role');
122
+ $breadCrumbTitle = $this->__('Edit Role');
123
+ $this->_title($this->__('Edit Role'));
124
+ $this->_addBreadcrumb($breadCrumb, $breadCrumbTitle);
125
+
126
+ /** @var $tabs Mage_Api2_Block_Adminhtml_Roles_Tabs */
127
+ $tabs = $this->getLayout()->getBlock('adminhtml.role.edit.tabs');
128
+ $tabs->setRole($role);
129
+ /** @var $child Mage_Adminhtml_Block_Template */
130
+ foreach ($tabs->getChild() as $child) {
131
+ $child->setData('role', $role);
132
+ }
133
+
134
+ /** @var $buttons Mage_Api2_Block_Adminhtml_Roles_Buttons */
135
+ $buttons = $this->getLayout()->getBlock('adminhtml.roles.buttons');
136
+ $buttons->setRole($role);
137
+
138
+ /** @var $users Mage_Api2_Block_Adminhtml_Roles_Tab_Users */
139
+ $users = $this->getLayout()->getBlock('adminhtml.role.edit.tab.users');
140
+ $users->setUsers($this->_getUsers($id));
141
+
142
+ //$this->getLayout()->getBlock('adminhtml.role.edit.tab.resources')->getResTreeJson();
143
+ //exit;
144
+
145
+ $this->renderLayout();
146
+ }
147
+
148
+ /**
149
+ * Save role
150
+ */
151
+ public function saveAction()
152
+ {
153
+ $request = $this->getRequest();
154
+
155
+ $id = $request->getParam('id', false);
156
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
157
+ $role = Mage::getModel('api2/acl_global_role')->load($id);
158
+
159
+ if (!$role->getId() && $id) {
160
+ $this->_getSession()->addError(
161
+ $this->__('Role "%s" no longer exists', $role->getData('role_name')));
162
+ $this->_redirect('*/*/');
163
+ return;
164
+ }
165
+
166
+ $roleUsers = $request->getParam('in_role_users', null);
167
+ parse_str($roleUsers, $roleUsers);
168
+ $roleUsers = array_keys($roleUsers);
169
+
170
+ $oldRoleUsers = $this->getRequest()->getParam('in_role_users_old');
171
+ parse_str($oldRoleUsers, $oldRoleUsers);
172
+ $oldRoleUsers = array_keys($oldRoleUsers);
173
+
174
+ /** @var $session Mage_Adminhtml_Model_Session */
175
+ $session = $this->_getSession();
176
+
177
+ try {
178
+ $role->setRoleName($this->getRequest()->getParam('role_name', false))
179
+ ->save();
180
+
181
+ foreach($oldRoleUsers as $oUid) {
182
+ $this->_deleteUserFromRole($oUid, $role->getId());
183
+ }
184
+
185
+ foreach ($roleUsers as $nRuid) {
186
+ $this->_addUserToRole($nRuid, $role->getId());
187
+ }
188
+
189
+ /**
190
+ * Save rules with resources
191
+ */
192
+ /** @var $rule Mage_Api2_Model_Acl_Global_Rule */
193
+ $rule = Mage::getModel('api2/acl_global_rule');
194
+ if ($id) {
195
+ $collection = $rule->getCollection();
196
+ $collection->addFilterByRoleId($role->getId());
197
+
198
+ /** @var $model Mage_Api2_Model_Acl_Global_Rule */
199
+ foreach ($collection as $model) {
200
+ $model->delete();
201
+ }
202
+ }
203
+
204
+ /** @var $ruleTree Mage_Api2_Model_Acl_Global_Rule_Tree */
205
+ $ruleTree = Mage::getSingleton(
206
+ 'api2/acl_global_rule_tree',
207
+ array('type' => Mage_Api2_Model_Acl_Global_Rule_Tree::TYPE_PRIVILEGE)
208
+ );
209
+ $resources = $ruleTree->getPostResources();
210
+ $id = $role->getId();
211
+ foreach ($resources as $resourceId => $privileges) {
212
+ foreach ($privileges as $privilege => $allow) {
213
+ if (!$allow) {
214
+ continue;
215
+ }
216
+
217
+ $rule->setId(null)
218
+ ->isObjectNew(true);
219
+
220
+ $rule->setRoleId($id)
221
+ ->setResourceId($resourceId)
222
+ ->setPrivilege($privilege)
223
+ ->save();
224
+ }
225
+ }
226
+
227
+ $session->addSuccess($this->__('The role has been saved.'));
228
+ } catch (Mage_Core_Exception $e) {
229
+ $session->addError($e->getMessage());
230
+ } catch (Exception $e) {
231
+ $session->addException($e, $this->__('An error occurred while saving role.'));
232
+ }
233
+
234
+ $this->_redirect('*/*/edit', array('id'=>$id));
235
+ }
236
+
237
+ /**
238
+ * Delete role
239
+ */
240
+ public function deleteAction()
241
+ {
242
+ $id = $this->getRequest()->getParam('id', false);
243
+
244
+ try {
245
+ /** @var $model Mage_Api2_Model_Acl_Global_Role */
246
+ $model = Mage::getModel("api2/acl_global_role");
247
+ $model->load($id)->delete();
248
+ $this->_getSession()->addSuccess($this->__('Role has been deleted.'));
249
+ } catch (Mage_Core_Exception $e) {
250
+ $this->_getSession()->addError($e->getMessage());
251
+ } catch (Exception $e) {
252
+ $this->_getSession()->addException($e, $this->__('An error occurred while deleting the role.'));
253
+ }
254
+
255
+ $this->_redirect("*/*/");
256
+ }
257
+
258
+ /**
259
+ * Check against ACL
260
+ *
261
+ * @return bool
262
+ */
263
+ protected function _isAllowed()
264
+ {
265
+ /** @var $session Mage_Admin_Model_Session */
266
+ $session = Mage::getSingleton('admin/session');
267
+ return $session->isAllowed('system/api/roles_rest');
268
+ }
269
+
270
+ /**
271
+ * Get API2 roles ajax grid action
272
+ */
273
+ public function rolesGridAction()
274
+ {
275
+ /** @var $model Mage_Admin_Model_User */
276
+ $model = Mage::getModel('admin/user');
277
+ $model->load($this->getRequest()->getParam('user_id'));
278
+
279
+ Mage::register('permissions_user', $model);
280
+ $this->getResponse()
281
+ ->setBody($this->getLayout()->createBlock('api2/adminhtml_permissions_user_edit_tab_roles')->toHtml());
282
+ }
283
+
284
+ /**
285
+ * Get users possessing the role
286
+ *
287
+ * @param int $id
288
+ * @return array|mixed
289
+ */
290
+ protected function _getUsers($id)
291
+ {
292
+ if ( $this->getRequest()->getParam('in_role_users') != "" ) {
293
+ return $this->getRequest()->getParam('in_role_users');
294
+ }
295
+
296
+ /** @var $role Mage_Api2_Model_Acl_Global_Role */
297
+ $role = Mage::getModel('api2/acl_global_role');
298
+ $role->setId($id);
299
+
300
+ /** @var $resource Mage_Api2_Model_Resource_Acl_Global_Role */
301
+ $resource = $role->getResource();
302
+ $users = $resource->getRoleUsers($role);
303
+
304
+ if (sizeof($users) == 0) {
305
+ $users = array();
306
+ }
307
+
308
+ return $users;
309
+ }
310
+
311
+ /**
312
+ * Take away user role
313
+ *
314
+ * @param int $adminId
315
+ * @param int $roleId
316
+ * @return Mage_Api2_Adminhtml_Api2_RoleController
317
+ */
318
+ protected function _deleteUserFromRole($adminId, $roleId)
319
+ {
320
+ /** @var $resourceModel Mage_Api2_Model_Resource_Acl_Global_Role */
321
+ $resourceModel = Mage::getResourceModel('api2/acl_global_role');
322
+ $resourceModel->deleteAdminToRoleRelation($adminId, $roleId);
323
+ return $this;
324
+ }
325
+
326
+ /**
327
+ * Give user a role
328
+ *
329
+ * @param int $adminId
330
+ * @param int $roleId
331
+ * @return Mage_Api2_Adminhtml_Api2_RoleController
332
+ */
333
+ protected function _addUserToRole($adminId, $roleId)
334
+ {
335
+ /** @var $resourceModel Mage_Api2_Model_Resource_Acl_Global_Role */
336
+ $resourceModel = Mage::getResourceModel('api2/acl_global_role');
337
+ $resourceModel->saveAdminToRoleRelation($adminId, $roleId);
338
+ return $this;
339
+ }
340
+ }
app/code/core/Mage/Api2/etc/adminhtml.xml ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Api2
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <acl>
30
+ <resources>
31
+ <admin>
32
+ <children>
33
+ <system>
34
+ <children>
35
+ <api>
36
+ <children>
37
+ <rest_roles translate="title" module="api2">
38
+ <title>REST - Roles</title>
39
+ <sort_order>30</sort_order>
40
+ <children>
41
+ <add translate="title">
42
+ <title>Add</title>
43
+ <sort_order>10</sort_order>
44
+ </add>
45
+ <edit translate="title">
46
+ <title>Edit</title>
47
+ <sort_order>20</sort_order>
48
+ </edit>
49
+ <delete translate="title">
50
+ <title>Delete</title>
51
+ <sort_order>30</sort_order>
52
+ </delete>
53
+ </children>
54
+ </rest_roles>
55
+ <rest_attributes translate="title" module="api2">
56
+ <title>REST - Attributes</title>
57
+ <sort_order>40</sort_order>
58
+ <children>
59
+ <edit translate="title">
60
+ <title>Edit</title>
61
+ <sort_order>10</sort_order>
62
+ </edit>
63
+ </children>
64
+ </rest_attributes>
65
+ </children>
66
+ </api>
67
+ </children>
68
+ </system>
69
+ </children>
70
+ </admin>
71
+ </resources>
72
+ </acl>
73
+ <menu>
74
+ <system>
75
+ <children>
76
+ <api>
77
+ <children>
78
+ <rest_roles translate="title" module="api2">
79
+ <title>REST - Roles</title>
80
+ <sort_order>30</sort_order>
81
+ <action>adminhtml/api2_role</action>
82
+ </rest_roles>
83
+ <rest_attributes translate="title" module="api2">
84
+ <title>REST - Attributes</title>
85
+ <sort_order>40</sort_order>
86
+ <action>adminhtml/api2_attribute</action>
87
+ </rest_attributes>
88
+ </children>
89
+ </api>
90
+ </children>
91
+ </system>
92
+ </menu>
93
+ </config>
app/code/core/Mage/Api2/etc/config.xml ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Api2
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <modules>
30
+ <Mage_Api2>
31
+ <version>1.0.0.0</version>
32
+ </Mage_Api2>
33
+ </modules>
34
+ <global>
35
+ <cache>
36
+ <types>
37
+ <config_api2 translate="label,description" module="api2">
38
+ <label>Web Services Configuration</label>
39
+ <description>Web Services definition files (api2.xml).</description>
40
+ <tags>CONFIG_API2</tags>
41
+ </config_api2>
42
+ </types>
43
+ </cache>
44
+ <models>
45
+ <api2>
46
+ <class>Mage_Api2_Model</class>
47
+ <resourceModel>api2_resource</resourceModel>
48
+ </api2>
49
+ <api2_resource>
50
+ <class>Mage_Api2_Model_Resource</class>
51
+ <entities>
52
+ <acl_role>
53
+ <table>api2_acl_role</table>
54
+ </acl_role>
55
+ <acl_user>
56
+ <table>api2_acl_user</table>
57
+ </acl_user>
58
+ <acl_rule>
59
+ <table>api2_acl_rule</table>
60
+ </acl_rule>
61
+ <acl_attribute>
62
+ <table>api2_acl_attribute</table>
63
+ </acl_attribute>
64
+ </entities>
65
+ </api2_resource>
66
+ </models>
67
+ <blocks>
68
+ <api2>
69
+ <class>Mage_Api2_Block</class>
70
+ </api2>
71
+ </blocks>
72
+ <helpers>
73
+ <api2>
74
+ <class>Mage_Api2_Helper</class>
75
+ </api2>
76
+ </helpers>
77
+ <resources>
78
+ <api2_setup>
79
+ <setup>
80
+ <module>Mage_Api2</module>
81
+ <class>Mage_Api2_Model_Resource_Setup</class>
82
+ </setup>
83
+ </api2_setup>
84
+ </resources>
85
+ <events>
86
+ <admin_user_save_after>
87
+ <observers>
88
+ <api2>
89
+ <class>api2/observer</class>
90
+ <method>saveAdminToRoleRelation</method>
91
+ </api2>
92
+ </observers>
93
+ </admin_user_save_after>
94
+ </events>
95
+ <api2>
96
+ <auth_adapters>
97
+ <oauth module="api2" translate="label">
98
+ <model>api2/auth_adapter_oauth</model>
99
+ <label>OAuth</label>
100
+ <enabled>1</enabled>
101
+ <order>10</order>
102
+ </oauth>
103
+ </auth_adapters>
104
+ <user_types>
105
+ <admin>
106
+ <model>api2/auth_user_admin</model>
107
+ <allowed>1</allowed>
108
+ </admin>
109
+ <customer>
110
+ <model>api2/auth_user_customer</model>
111
+ <allowed>1</allowed>
112
+ </customer>
113
+ <guest>
114
+ <model>api2/auth_user_guest</model>
115
+ <allowed>1</allowed>
116
+ </guest>
117
+ </user_types>
118
+ <request>
119
+ <interpreters>
120
+ <!-- JSON -->
121
+ <application_json>
122
+ <type>application/json</type>
123
+ <model>api2/request_interpreter_json</model>
124
+ </application_json>
125
+
126
+ <!-- QUERY -->
127
+ <text_plain>
128
+ <type>text/plain</type>
129
+ <model>api2/request_interpreter_query</model>
130
+ </text_plain>
131
+
132
+ <!-- XML -->
133
+ <application_xml>
134
+ <type>application/xml</type>
135
+ <model>api2/request_interpreter_xml</model>
136
+ </application_xml>
137
+ <application_xhtml_xml>
138
+ <type>application/xhtml+xml</type>
139
+ <model>api2/request_interpreter_xml</model>
140
+ </application_xhtml_xml>
141
+ <text_xml>
142
+ <type>text/xml</type>
143
+ <model>api2/request_interpreter_xml</model>
144
+ </text_xml>
145
+ </interpreters>
146
+ </request>
147
+ <response>
148
+ <renders>
149
+ <!-- JSON -->
150
+ <default>
151
+ <type>*/*</type>
152
+ <model>api2/renderer_json</model>
153
+ </default>
154
+ <application_json>
155
+ <type>application/json</type>
156
+ <model>api2/renderer_json</model>
157
+ </application_json>
158
+
159
+ <!-- QUERY -->
160
+ <text_plain>
161
+ <type>text/plain</type>
162
+ <model>api2/renderer_query</model>
163
+ </text_plain>
164
+
165
+ <!-- XML -->
166
+ <text_xml>
167
+ <type>text/xml</type>
168
+ <model>api2/renderer_xml</model>
169
+ </text_xml>
170
+ <application_xml>
171
+ <type>application/xml</type>
172
+ <model>api2/renderer_xml</model>
173
+ </application_xml>
174
+ <application_xhtml_xml>
175
+ <type>application/xhtml+xml</type>
176
+ <model>api2/renderer_xml</model>
177
+ </application_xhtml_xml>
178
+ </renders>
179
+ </response>
180
+ </api2>
181
+ </global>
182
+ <admin>
183
+ <routers>
184
+ <adminhtml>
185
+ <args>
186
+ <modules>
187
+ <api2 before="Mage_Adminhtml">Mage_Api2_Adminhtml</api2>
188
+ </modules>
189
+ </args>
190
+ </adminhtml>
191
+ </routers>
192
+ </admin>
193
+ <adminhtml>
194
+ <layout>
195
+ <updates>
196
+ <api2>
197
+ <file>api2.xml</file>
198
+ </api2>
199
+ </updates>
200
+ </layout>
201
+ <events>
202
+ <catalog_entity_attribute_save_after>
203
+ <observers>
204
+ <api2>
205
+ <class>api2/observer</class>
206
+ <method>catalogAttributeSaveAfter</method>
207
+ </api2>
208
+ </observers>
209
+ </catalog_entity_attribute_save_after>
210
+ </events>
211
+ </adminhtml>
212
+ </config>
app/code/core/Mage/Api2/sql/api2_setup/install-1.0.0.0.php ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Api2
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ /**
27
+ * Installation of Api2 module tables
28
+ */
29
+ /** @var $installer Mage_Api2_Model_Resource_Setup */
30
+ $installer = $this;
31
+
32
+ $installer->startSetup();
33
+
34
+ /** @var $adapter Varien_Db_Adapter_Pdo_Mysql */
35
+ $adapter = $installer->getConnection();
36
+
37
+ /**
38
+ * Create table 'api2/acl_role'
39
+ */
40
+ $table = $adapter->newTable($installer->getTable('api2/acl_role'))
41
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
42
+ 'identity' => true,
43
+ 'unsigned' => true,
44
+ 'nullable' => false,
45
+ 'primary' => true,
46
+ ), 'Entity ID')
47
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null,
48
+ array(
49
+ 'nullable' => false,
50
+ 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT
51
+ ), 'Created At')
52
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null,
53
+ array(
54
+ 'nullable' => true
55
+ ), 'Updated At')
56
+ ->addColumn('role_name', Varien_Db_Ddl_Table::TYPE_VARCHAR,
57
+ 255, array('nullable' => false), 'Name of role')
58
+ ->addIndex($installer->getIdxName('api2/acl_role', array('created_at')), array('created_at'))
59
+ ->addIndex($installer->getIdxName('api2/acl_role', array('updated_at')), array('updated_at'))
60
+ ->setComment('Api2 Global ACL Roles');
61
+ $adapter->createTable($table);
62
+
63
+ // Create Guest and Customer User Roles
64
+ $adapter->insertMultiple(
65
+ $installer->getTable('api2/acl_role'),
66
+ array(
67
+ array('role_name' => 'Guest'),
68
+ array('role_name' => 'Customer')
69
+ )
70
+ );
71
+
72
+ /**
73
+ * Create table 'api2/acl_user'
74
+ */
75
+ $table = $adapter->newTable($installer->getTable('api2/acl_user'))
76
+ ->addColumn('admin_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
77
+ 'unsigned' => true,
78
+ 'nullable' => false,
79
+ ), 'Admin ID')
80
+ ->addColumn('role_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
81
+ 'unsigned' => true,
82
+ 'nullable' => false,
83
+ ), 'Role ID')
84
+ ->addIndex(
85
+ $installer->getIdxName(
86
+ $installer->getTable('api2/acl_user'),
87
+ array('admin_id'),
88
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
89
+ ),
90
+ array('admin_id'),
91
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))
92
+ ->addForeignKey(
93
+ $installer->getFkName('api2/acl_user', 'admin_id', 'admin/user', 'user_id'),
94
+ 'admin_id',
95
+ $installer->getTable('admin/user'),
96
+ 'user_id',
97
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
98
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
99
+ ->addForeignKey(
100
+ $installer->getFkName('api2/acl_user', 'role_id', 'api2/acl_role', 'entity_id'),
101
+ 'role_id',
102
+ $installer->getTable('api2/acl_role'),
103
+ 'entity_id',
104
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
105
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
106
+ ->setComment('Api2 Global ACL Users');
107
+ $adapter->createTable($table);
108
+
109
+ /**
110
+ * Create table 'api2/acl_rule'
111
+ */
112
+ $table = $adapter->newTable($installer->getTable('api2/acl_rule'))
113
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
114
+ 'primary' => true,
115
+ 'identity' => true,
116
+ 'unsigned' => true,
117
+ 'nullable' => false,
118
+ ), 'Entity ID')
119
+ ->addColumn('role_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
120
+ 'unsigned' => true,
121
+ 'nullable' => false,
122
+ ), 'Role ID')
123
+ ->addColumn('resource_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
124
+ 'nullable' => false
125
+ ), 'Resource ID')
126
+ ->addColumn('privilege', Varien_Db_Ddl_Table::TYPE_TEXT, 20, array(
127
+ 'nullable' => true
128
+ ), 'ACL Privilege')
129
+ ->addIndex(
130
+ $installer->getIdxName(
131
+ $installer->getTable('api2/acl_rule'),
132
+ array('role_id', 'resource_id', 'privilege'),
133
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
134
+ ),
135
+ array('role_id', 'resource_id', 'privilege'),
136
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))
137
+ ->addForeignKey(
138
+ $installer->getFkName('api2/acl_rule', 'role_id', 'api2/acl_role', 'entity_id'),
139
+ 'role_id',
140
+ $installer->getTable('api2/acl_role'),
141
+ 'entity_id',
142
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
143
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
144
+ ->setComment('Api2 Global ACL Rules');
145
+ $adapter->createTable($table);
146
+
147
+ /**
148
+ * Create table 'api2/acl_attribute'
149
+ */
150
+ $table = $adapter->newTable($installer->getTable('api2/acl_attribute'))
151
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
152
+ 'identity' => true,
153
+ 'unsigned' => true,
154
+ 'nullable' => false,
155
+ 'primary' => true,
156
+ ), 'Entity ID')
157
+ ->addColumn('user_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, 20, array(
158
+ 'nullable' => false
159
+ ), 'Type of user')
160
+ ->addColumn('resource_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
161
+ 'nullable' => false
162
+ ), 'Resource ID')
163
+ ->addColumn('operation', Varien_Db_Ddl_Table::TYPE_VARCHAR, 20, array(
164
+ 'nullable' => false
165
+ ), 'Operation')
166
+ ->addColumn('allowed_attributes', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
167
+ 'nullable' => true
168
+ ), 'Allowed attributes')
169
+ ->addIndex(
170
+ $installer->getIdxName('api2/acl_attribute', array('user_type')),
171
+ array('user_type'))
172
+ ->addIndex(
173
+ $installer->getIdxName(
174
+ $installer->getTable('api2/acl_attribute'),
175
+ array('user_type', 'resource_id', 'operation'),
176
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
177
+ ),
178
+ array('user_type', 'resource_id', 'operation'),
179
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))
180
+ ->setComment('Api2 Filter ACL Attributes');
181
+ $adapter->createTable($table);
182
+
183
+ $installer->endSetup();
app/code/core/Mage/Authorizenet/Block/Directpost/Form.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/Block/Directpost/Iframe.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/Helper/Data.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/Model/Directpost.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/Model/Directpost/Observer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/Model/Directpost/Request.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/Model/Directpost/Response.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/Model/Directpost/Session.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/controllers/Adminhtml/Authorizenet/Directpost/PaymentController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/controllers/Directpost/PaymentController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Authorizenet
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Authorizenet/etc/config.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Authorizenet
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
21
  *
22
  * @category Mage
23
  * @package Mage_Authorizenet
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
app/code/core/Mage/Authorizenet/etc/system.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Authorizenet
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
@@ -146,6 +146,7 @@
146
  <merchant_email translate="label">
147
  <label>Merchant's Email</label>
148
  <frontend_type>text</frontend_type>
 
149
  <sort_order>130</sort_order>
150
  <show_in_default>1</show_in_default>
151
  <show_in_website>1</show_in_website>
@@ -210,6 +211,7 @@
210
  <show_in_default>1</show_in_default>
211
  <show_in_website>1</show_in_website>
212
  <show_in_store>0</show_in_store>
 
213
  </sort_order>
214
  </fields>
215
  </authorizenet_directpost>
21
  *
22
  * @category Mage
23
  * @package Mage_Authorizenet
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
146
  <merchant_email translate="label">
147
  <label>Merchant's Email</label>
148
  <frontend_type>text</frontend_type>
149
+ <validate>validate-email</validate>
150
  <sort_order>130</sort_order>
151
  <show_in_default>1</show_in_default>
152
  <show_in_website>1</show_in_website>
211
  <show_in_default>1</show_in_default>
212
  <show_in_website>1</show_in_website>
213
  <show_in_store>0</show_in_store>
214
+ <frontend_class>validate-number</frontend_class>
215
  </sort_order>
216
  </fields>
217
  </authorizenet_directpost>
app/code/core/Mage/Backup/Exception.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Backup/Helper/Data.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -29,5 +29,295 @@
29
  */
30
  class Mage_Backup_Helper_Data extends Mage_Core_Helper_Abstract
31
  {
 
 
 
 
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
29
  */
30
  class Mage_Backup_Helper_Data extends Mage_Core_Helper_Abstract
31
  {
32
+ /**
33
+ * Backup type constant for database backup
34
+ */
35
+ const TYPE_DB = 'db';
36
 
37
+ /**
38
+ * Backup type constant for filesystem backup
39
+ */
40
+ const TYPE_FILESYSTEM = 'filesystem';
41
+
42
+ /**
43
+ * Backup type constant for full system backup(database + filesystem)
44
+ */
45
+ const TYPE_SYSTEM_SNAPSHOT = 'snapshot';
46
+
47
+ /**
48
+ * Backup type constant for media and database backup
49
+ */
50
+ const TYPE_MEDIA = 'media';
51
+
52
+ /**
53
+ * Backup type constant for full system backup excluding media folder
54
+ */
55
+ const TYPE_SNAPSHOT_WITHOUT_MEDIA = 'nomedia';
56
+
57
+ /**
58
+ * Get all possible backup type values with descriptive title
59
+ *
60
+ * @return array
61
+ */
62
+ public function getBackupTypes()
63
+ {
64
+ return array(
65
+ self::TYPE_DB => self::__('Database'),
66
+ self::TYPE_MEDIA => self::__('Database and Media'),
67
+ self::TYPE_SYSTEM_SNAPSHOT => self::__('System'),
68
+ self::TYPE_SNAPSHOT_WITHOUT_MEDIA => self::__('System (excluding Media)')
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Get all possible backup type values
74
+ *
75
+ * @return array
76
+ */
77
+ public function getBackupTypesList()
78
+ {
79
+ return array(
80
+ self::TYPE_DB,
81
+ self::TYPE_SYSTEM_SNAPSHOT,
82
+ self::TYPE_SNAPSHOT_WITHOUT_MEDIA,
83
+ self::TYPE_MEDIA
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Get default backup type value
89
+ *
90
+ * @return string
91
+ */
92
+ public function getDefaultBackupType()
93
+ {
94
+ return self::TYPE_DB;
95
+ }
96
+
97
+ /**
98
+ * Get directory path where backups stored
99
+ *
100
+ * @return string
101
+ */
102
+ public function getBackupsDir()
103
+ {
104
+ return Mage::getBaseDir('var') . DS . 'backups';
105
+ }
106
+
107
+ /**
108
+ * Get backup file extension by backup type
109
+ *
110
+ * @param string $type
111
+ * @return string
112
+ */
113
+ public function getExtensionByType($type)
114
+ {
115
+ $extensions = $this->getExtensions();
116
+ return isset($extensions[$type]) ? $extensions[$type] : '';
117
+ }
118
+
119
+ /**
120
+ * Get all types to extensions map
121
+ *
122
+ * @return array
123
+ */
124
+ public function getExtensions()
125
+ {
126
+ return array(
127
+ self::TYPE_SYSTEM_SNAPSHOT => 'tgz',
128
+ self::TYPE_SNAPSHOT_WITHOUT_MEDIA => 'tgz',
129
+ self::TYPE_MEDIA => 'tgz',
130
+ self::TYPE_DB => 'gz'
131
+ );
132
+ }
133
+
134
+ /**
135
+ * Generate backup download name
136
+ *
137
+ * @param Mage_Backup_Model_Backup $backup
138
+ * @return string
139
+ */
140
+ public function generateBackupDownloadName(Mage_Backup_Model_Backup $backup)
141
+ {
142
+ $additionalExtension = $backup->getType() == self::TYPE_DB ? '.sql' : '';
143
+ return $backup->getType() . '-' . date('YmdHis', $backup->getTime()) . $additionalExtension . '.'
144
+ . $this->getExtensionByType($backup->getType());
145
+ }
146
+
147
+ /**
148
+ * Check Permission for Rollback
149
+ *
150
+ * @return boolean
151
+ */
152
+ public function isRollbackAllowed(){
153
+ return Mage::getSingleton('admin/session')->isAllowed('system/tools/backup/rollback' );
154
+ }
155
+
156
+ /**
157
+ * Get paths that should be ignored when creating system snapshots
158
+ *
159
+ * @return array
160
+ */
161
+ public function getBackupIgnorePaths()
162
+ {
163
+ return array(
164
+ '.svn',
165
+ 'maintenance.flag',
166
+ Mage::getBaseDir('var') . DS . 'session',
167
+ Mage::getBaseDir('var') . DS . 'cache',
168
+ Mage::getBaseDir('var') . DS . 'full_page_cache',
169
+ Mage::getBaseDir('var') . DS . 'locks',
170
+ Mage::getBaseDir('var') . DS . 'log',
171
+ Mage::getBaseDir('var') . DS . 'report'
172
+ );
173
+ }
174
+
175
+ /**
176
+ * Get paths that should be ignored when rolling back system snapshots
177
+ *
178
+ * @return array
179
+ */
180
+ public function getRollbackIgnorePaths()
181
+ {
182
+ return array(
183
+ '.svn',
184
+ 'maintenance.flag',
185
+ Mage::getBaseDir('var') . DS . 'session',
186
+ Mage::getBaseDir('var') . DS . 'locks',
187
+ Mage::getBaseDir('var') . DS . 'log',
188
+ Mage::getBaseDir('var') . DS . 'report',
189
+ Mage::getBaseDir('app') . DS . 'Mage.php',
190
+ Mage::getBaseDir() . DS . 'errors',
191
+ Mage::getBaseDir() . DS . 'index.php'
192
+ );
193
+ }
194
+
195
+ /**
196
+ * Put store into maintenance mode
197
+ *
198
+ * @return bool
199
+ */
200
+ public function turnOnMaintenanceMode()
201
+ {
202
+ $maintenanceFlagFile = $this->getMaintenanceFlagFilePath();
203
+ $result = file_put_contents($maintenanceFlagFile, 'maintenance');
204
+
205
+ return $result !== false;
206
+ }
207
+
208
+ /**
209
+ * Turn off store maintenance mode
210
+ */
211
+ public function turnOffMaintenanceMode()
212
+ {
213
+ $maintenanceFlagFile = $this->getMaintenanceFlagFilePath();
214
+ @unlink($maintenanceFlagFile);
215
+ }
216
+
217
+ /**
218
+ * Get backup create success message by backup type
219
+ *
220
+ * @param string $type
221
+ * @return string
222
+ */
223
+ public function getCreateSuccessMessageByType($type)
224
+ {
225
+ $messagesMap = array(
226
+ self::TYPE_SYSTEM_SNAPSHOT => $this->__('The system backup has been created.'),
227
+ self::TYPE_SNAPSHOT_WITHOUT_MEDIA => $this->__('The system (excluding Media) backup has been created.'),
228
+ self::TYPE_MEDIA => $this->__('The database and media backup has been created.'),
229
+ self::TYPE_DB => $this->__('The database backup has been created.')
230
+ );
231
+
232
+ if (!isset($messagesMap[$type])) {
233
+ return;
234
+ }
235
+
236
+ return $messagesMap[$type];
237
+ }
238
+
239
+ /**
240
+ * Get path to maintenance flag file
241
+ *
242
+ * @return string
243
+ */
244
+ protected function getMaintenanceFlagFilePath()
245
+ {
246
+ return Mage::getBaseDir() . DS . 'maintenance.flag';
247
+ }
248
+
249
+ /**
250
+ * Invalidate Cache
251
+ * @return Mage_Backup_Helper_Data
252
+ */
253
+ public function invalidateCache()
254
+ {
255
+ if ($cacheTypesNode = Mage::getConfig()->getNode(Mage_Core_Model_Cache::XML_PATH_TYPES)) {
256
+ $cacheTypesList = array_keys($cacheTypesNode->asArray());
257
+ Mage::app()->getCacheInstance()->invalidateType($cacheTypesList);
258
+ }
259
+ return $this;
260
+ }
261
+
262
+ /**
263
+ * Invalidate Indexer
264
+ *
265
+ * @return Mage_Backup_Helper_Data
266
+ */
267
+ public function invalidateIndexer()
268
+ {
269
+ foreach (Mage::getResourceModel('index/process_collection') as $process){
270
+ $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
271
+ }
272
+ return $this;
273
+ }
274
+
275
+ /**
276
+ * Creates backup's display name from it's name
277
+ *
278
+ * @param string $name
279
+ * @return string
280
+ */
281
+ public function nameToDisplayName($name)
282
+ {
283
+ return str_replace('_', ' ', $name);
284
+ }
285
+
286
+ /**
287
+ * Extracts information from backup's filename
288
+ *
289
+ * @param string $filename
290
+ * @return Varien_Object
291
+ */
292
+ public function extractDataFromFilename($filename)
293
+ {
294
+ $extensions = $this->getExtensions();
295
+
296
+ $filenameWithoutExtension = $filename;
297
+
298
+ foreach ($extensions as $extension) {
299
+ $filenameWithoutExtension = preg_replace('/' . preg_quote($extension, '/') . '$/', '',
300
+ $filenameWithoutExtension
301
+ );
302
+ }
303
+
304
+ $filenameWithoutExtension = substr($filenameWithoutExtension, 0, strrpos($filenameWithoutExtension, "."));
305
+
306
+ list($time, $type) = explode("_", $filenameWithoutExtension);
307
+
308
+ $name = str_replace($time . '_' . $type, '', $filenameWithoutExtension);
309
+
310
+ if (!empty($name)) {
311
+ $name = substr($name, 1);
312
+ }
313
+
314
+ $result = new Varien_Object();
315
+ $result->addData(array(
316
+ 'name' => $name,
317
+ 'type' => $type,
318
+ 'time' => $time
319
+ ));
320
+
321
+ return $result;
322
+ }
323
  }
app/code/core/Mage/Backup/Model/Backup.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -29,23 +29,17 @@
29
  *
30
  * @category Mage
31
  * @package Mage_Backup
32
- * @author Magento Core Team <core@magentocommerce.com>
33
  */
34
  class Mage_Backup_Model_Backup extends Varien_Object
35
  {
36
- /* backup types */
37
- const BACKUP_DB = 'db';
38
- const BACKUP_VIEW = 'view';
39
- const BACKUP_MEDIA = 'media';
40
-
41
  /* internal constants */
42
- const BACKUP_EXTENSION = 'gz';
43
  const COMPRESS_RATE = 9;
44
 
45
  /**
46
  * Type of backup file
47
  *
48
- * @var string db|media|view
49
  */
50
  private $_type = 'db';
51
 
@@ -65,14 +59,19 @@ class Mage_Backup_Model_Backup extends Varien_Object
65
  */
66
  public function load($fileName, $filePath)
67
  {
68
- list ($time, $type) = explode("_", substr($fileName, 0, strrpos($fileName, ".")));
 
69
  $this->addData(array(
70
  'id' => $filePath . DS . $fileName,
71
- 'time' => (int)$time,
72
  'path' => $filePath,
73
- 'date_object' => new Zend_Date((int)$time)
 
 
 
74
  ));
75
- $this->setType($type);
 
76
  return $this;
77
  }
78
 
@@ -93,19 +92,29 @@ class Mage_Backup_Model_Backup extends Varien_Object
93
  */
94
  public function getFileName()
95
  {
96
- return $this->getTime() . "_" . $this->getType()
97
- . "." . self::BACKUP_EXTENSION;
 
 
 
 
 
 
 
 
98
  }
99
 
100
  /**
101
  * Sets type of file
102
  *
103
- * @param string $value db|media|view
 
104
  */
105
  public function setType($value='db')
106
  {
107
- if(!in_array($value, array('db','media','view'))) {
108
- $value = 'db';
 
109
  }
110
 
111
  $this->_type = $value;
@@ -117,7 +126,7 @@ class Mage_Backup_Model_Backup extends Varien_Object
117
  /**
118
  * Returns type of backup file
119
  *
120
- * @return string db|media|view
121
  */
122
  public function getType()
123
  {
@@ -205,6 +214,7 @@ class Mage_Backup_Model_Backup extends Varien_Object
205
  * Delete backup file
206
  *
207
  * @throws Mage_Backup_Exception
 
208
  */
209
  public function deleteFile()
210
  {
@@ -249,11 +259,12 @@ class Mage_Backup_Model_Backup extends Varien_Object
249
 
250
  $mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb';
251
 
252
- try {
253
- $this->_handler = gzopen($filePath, $mode);
254
- }
255
- catch (Exception $e) {
256
- Mage::exception('Mage_Backup', Mage::helper('backup')->__('Backup file "%s" cannot be read from or written to.', $this->getFileName()));
 
257
  }
258
 
259
  return $this;
@@ -351,4 +362,41 @@ class Mage_Backup_Model_Backup extends Varien_Object
351
 
352
  return 0;
353
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
29
  *
30
  * @category Mage
31
  * @package Mage_Backup
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
  */
34
  class Mage_Backup_Model_Backup extends Varien_Object
35
  {
 
 
 
 
 
36
  /* internal constants */
 
37
  const COMPRESS_RATE = 9;
38
 
39
  /**
40
  * Type of backup file
41
  *
42
+ * @var string
43
  */
44
  private $_type = 'db';
45
 
59
  */
60
  public function load($fileName, $filePath)
61
  {
62
+ $backupData = Mage::helper('backup')->extractDataFromFilename($fileName);
63
+
64
  $this->addData(array(
65
  'id' => $filePath . DS . $fileName,
66
+ 'time' => (int)$backupData->getTime(),
67
  'path' => $filePath,
68
+ 'extension' => Mage::helper('backup')->getExtensionByType($backupData->getType()),
69
+ 'display_name' => Mage::helper('backup')->nameToDisplayName($backupData->getName()),
70
+ 'name' => $backupData->getName(),
71
+ 'date_object' => new Zend_Date((int)$backupData->getTime(), Mage::app()->getLocale()->getLocaleCode())
72
  ));
73
+
74
+ $this->setType($backupData->getType());
75
  return $this;
76
  }
77
 
92
  */
93
  public function getFileName()
94
  {
95
+ $filename = $this->getTime() . "_" . $this->getType();
96
+ $backupName = $this->getName();
97
+
98
+ if (!empty($backupName)) {
99
+ $filename .= '_' . $backupName;
100
+ }
101
+
102
+ $filename .= '.' . Mage::helper('backup')->getExtensionByType($this->getType());
103
+
104
+ return $filename;
105
  }
106
 
107
  /**
108
  * Sets type of file
109
  *
110
+ * @param string $value
111
+ * @return Mage_Backup_Model_Backup
112
  */
113
  public function setType($value='db')
114
  {
115
+ $possibleTypes = Mage::helper('backup')->getBackupTypesList();
116
+ if(!in_array($value, $possibleTypes)) {
117
+ $value = Mage::helper('backup')->getDefaultBackupType();
118
  }
119
 
120
  $this->_type = $value;
126
  /**
127
  * Returns type of backup file
128
  *
129
+ * @return string
130
  */
131
  public function getType()
132
  {
214
  * Delete backup file
215
  *
216
  * @throws Mage_Backup_Exception
217
+ * @return Mage_Backup_Model_Backup
218
  */
219
  public function deleteFile()
220
  {
259
 
260
  $mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb';
261
 
262
+ $this->_handler = @gzopen($filePath, $mode);
263
+
264
+ if (!$this->_handler) {
265
+ throw new Mage_Backup_Exception_NotEnoughPermissions(
266
+ Mage::helper('backup')->__('Backup file "%s" cannot be read from or written to.', $this->getFileName())
267
+ );
268
  }
269
 
270
  return $this;
362
 
363
  return 0;
364
  }
365
+
366
+ /**
367
+ * Validate user password
368
+ *
369
+ * @param string $password
370
+ * @return bool
371
+ */
372
+ public function validateUserPassword($password)
373
+ {
374
+ $userPasswordHash = Mage::getModel('admin/session')->getUser()->getPassword();
375
+ return Mage::helper('core')->validateHash($password, $userPasswordHash);
376
+ }
377
+
378
+ /**
379
+ * Load backup by it's type and creation timestamp
380
+ *
381
+ * @param int $timestamp
382
+ * @param string $type
383
+ * @return Mage_Backup_Model_Backup
384
+ */
385
+ public function loadByTimeAndType($timestamp, $type)
386
+ {
387
+ $backupsCollection = Mage::getSingleton('backup/fs_collection');
388
+ $backupId = $timestamp . '_' . $type;
389
+
390
+ foreach ($backupsCollection as $backup) {
391
+ if ($backup->getId() == $backupId) {
392
+ $this->setType($backup->getType())
393
+ ->setTime($backup->getTime())
394
+ ->setName($backup->getName())
395
+ ->setPath($backup->getPath());
396
+ break;
397
+ }
398
+ }
399
+
400
+ return $this;
401
+ }
402
  }
app/code/core/Mage/Backup/Model/Config/Backend/Cron.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Backup by cron backend model
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Backup
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_Backup_Model_Config_Backend_Cron extends Mage_Core_Model_Config_Data
36
+ {
37
+ const CRON_STRING_PATH = 'crontab/jobs/system_backup/schedule/cron_expr';
38
+ const CRON_MODEL_PATH = 'crontab/jobs/system_backup/run/model';
39
+
40
+ const XML_PATH_BACKUP_ENABLED = 'groups/backup/fields/enabled/value';
41
+ const XML_PATH_BACKUP_TIME = 'groups/backup/fields/time/value';
42
+ const XML_PATH_BACKUP_FREQUENCY = 'groups/backup/fields/frequency/value';
43
+
44
+ /**
45
+ * Cron settings after save
46
+ *
47
+ * @return Mage_Adminhtml_Model_System_Config_Backend_Log_Cron
48
+ */
49
+ protected function _afterSave()
50
+ {
51
+ $enabled = $this->getData(self::XML_PATH_BACKUP_ENABLED);
52
+ $time = $this->getData(self::XML_PATH_BACKUP_TIME);
53
+ $frequency = $this->getData(self::XML_PATH_BACKUP_FREQUENCY);
54
+
55
+ $frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;
56
+ $frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;
57
+
58
+ if ($enabled) {
59
+ $cronExprArray = array(
60
+ intval($time[1]), # Minute
61
+ intval($time[0]), # Hour
62
+ ($frequency == $frequencyMonthly) ? '1' : '*', # Day of the Month
63
+ '*', # Month of the Year
64
+ ($frequency == $frequencyWeekly) ? '1' : '*', # Day of the Week
65
+ );
66
+ $cronExprString = join(' ', $cronExprArray);
67
+ }
68
+ else {
69
+ $cronExprString = '';
70
+ }
71
+
72
+ try {
73
+ Mage::getModel('core/config_data')
74
+ ->load(self::CRON_STRING_PATH, 'path')
75
+ ->setValue($cronExprString)
76
+ ->setPath(self::CRON_STRING_PATH)
77
+ ->save();
78
+
79
+ Mage::getModel('core/config_data')
80
+ ->load(self::CRON_MODEL_PATH, 'path')
81
+ ->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))
82
+ ->setPath(self::CRON_MODEL_PATH)
83
+ ->save();
84
+ }
85
+ catch (Exception $e) {
86
+ Mage::throwException(Mage::helper('backup')->__('Unable to save the cron expression.'));
87
+ }
88
+ }
89
+ }
app/code/core/Mage/Backup/Model/Config/Source/Type.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Backups types' source model for system configuration
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Backup
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Backup_Model_Config_Source_Type
35
+ {
36
+ /**
37
+ * return possible options
38
+ *
39
+ * @return array
40
+ */
41
+ public function toOptionArray()
42
+ {
43
+ $backupTypes = array();
44
+ foreach(Mage::helper('backup')->getBackupTypes() as $type => $label) {
45
+ $backupTypes[] = array(
46
+ 'label' => $label,
47
+ 'value' => $type,
48
+ );
49
+ }
50
+ return $backupTypes;
51
+ }
52
+ }
app/code/core/Mage/Backup/Model/Db.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -37,10 +37,19 @@ class Mage_Backup_Model_Db
37
 
38
  /**
39
  * Buffer length for multi rows
40
- * default 512 Kb
41
  *
42
  */
43
- const BUFFER_LENGTH = 524288;
 
 
 
 
 
 
 
 
 
44
 
45
  /**
46
  * Retrieve resource model
@@ -108,13 +117,16 @@ class Mage_Backup_Model_Db
108
 
109
  $backup->write($this->getResource()->getHeader());
110
 
 
 
111
  foreach ($tables as $table) {
112
- $backup->write($this->getResource()->getTableHeader($table) . $this->getResource()->getTableDropSql($table) . "\n");
 
113
  $backup->write($this->getResource()->getTableCreateSql($table, false) . "\n");
114
 
115
  $tableStatus = $this->getResource()->getTableStatus($table);
116
 
117
- if ($tableStatus->getRows()) {
118
  $backup->write($this->getResource()->getTableDataBeforeSql($table));
119
 
120
  if ($tableStatus->getDataLength() > self::BUFFER_LENGTH) {
@@ -149,4 +161,20 @@ class Mage_Backup_Model_Db
149
  return $this;
150
  }
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
37
 
38
  /**
39
  * Buffer length for multi rows
40
+ * default 100 Kb
41
  *
42
  */
43
+ const BUFFER_LENGTH = 102400;
44
+
45
+ /**
46
+ * List of tables which data should not be backed up
47
+ *
48
+ * @var array
49
+ */
50
+ protected $_ignoreDataTablesList = array(
51
+ 'importexport/importdata'
52
+ );
53
 
54
  /**
55
  * Retrieve resource model
117
 
118
  $backup->write($this->getResource()->getHeader());
119
 
120
+ $ignoreDataTablesList = $this->getIgnoreDataTablesList();
121
+
122
  foreach ($tables as $table) {
123
+ $backup->write($this->getResource()->getTableHeader($table)
124
+ . $this->getResource()->getTableDropSql($table) . "\n");
125
  $backup->write($this->getResource()->getTableCreateSql($table, false) . "\n");
126
 
127
  $tableStatus = $this->getResource()->getTableStatus($table);
128
 
129
+ if ($tableStatus->getRows() && !in_array($table, $ignoreDataTablesList)) {
130
  $backup->write($this->getResource()->getTableDataBeforeSql($table));
131
 
132
  if ($tableStatus->getDataLength() > self::BUFFER_LENGTH) {
161
  return $this;
162
  }
163
 
164
+ /**.
165
+ * Returns the list of tables which data should not be backed up
166
+ *
167
+ * @return array
168
+ */
169
+ public function getIgnoreDataTablesList()
170
+ {
171
+ $result = array();
172
+ $resource = Mage::getSingleton('core/resource');
173
+
174
+ foreach ($this->_ignoreDataTablesList as $table) {
175
+ $result[] = $resource->getTableName($table);
176
+ }
177
+
178
+ return $result;
179
+ }
180
  }
app/code/core/Mage/Backup/Model/Fs/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -58,10 +58,17 @@ class Mage_Backup_Model_Fs_Collection extends Varien_Data_Collection_Filesystem
58
  }
59
 
60
  // set collection specific params
 
 
 
 
 
 
 
61
  $this
62
  ->setOrder('time', self::SORT_ORDER_DESC)
63
  ->addTargetDir($this->_baseDir)
64
- ->setFilesFilter('/^[a-z0-9\-\_]+\.' . preg_quote(Mage_Backup_Model_Backup::BACKUP_EXTENSION, '/') . '$/')
65
  ->setCollectRecursively(false)
66
  ;
67
  }
@@ -80,6 +87,7 @@ class Mage_Backup_Model_Fs_Collection extends Varien_Data_Collection_Filesystem
80
  $row[$key] = $value;
81
  }
82
  $row['size'] = filesize($filename);
 
83
  return $row;
84
  }
85
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
58
  }
59
 
60
  // set collection specific params
61
+ $extensions = Mage::helper('backup')->getExtensions();
62
+
63
+ foreach ($extensions as $key => $value) {
64
+ $extensions[] = '(' . preg_quote($value, '/') . ')';
65
+ }
66
+ $extensions = implode('|', $extensions);
67
+
68
  $this
69
  ->setOrder('time', self::SORT_ORDER_DESC)
70
  ->addTargetDir($this->_baseDir)
71
+ ->setFilesFilter('/^[a-z0-9\-\_]+\.' . $extensions . '$/')
72
  ->setCollectRecursively(false)
73
  ;
74
  }
87
  $row[$key] = $value;
88
  }
89
  $row['size'] = filesize($filename);
90
+ $row['id'] = $row['time'] . '_' . $row['type'];
91
  return $row;
92
  }
93
  }
app/code/core/Mage/Backup/Model/Mysql4/Db.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Backup/Model/Observer.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Backup Observer
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Backup
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_Backup_Model_Observer
36
+ {
37
+ const XML_PATH_BACKUP_ENABLED = 'system/backup/enabled';
38
+ const XML_PATH_BACKUP_TYPE = 'system/backup/type';
39
+ const XML_PATH_BACKUP_MAINTENANCE_MODE = 'system/backup/maintenance';
40
+
41
+ /**
42
+ * Error messages
43
+ *
44
+ * @var array
45
+ */
46
+ protected $_errors = array();
47
+
48
+ /**
49
+ * Create Backup
50
+ *
51
+ * @return Mage_Log_Model_Cron
52
+ */
53
+ public function scheduledBackup()
54
+ {
55
+ if (!Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_ENABLED)) {
56
+ return $this;
57
+ }
58
+
59
+ if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
60
+ Mage::helper('backup')->turnOnMaintenanceMode();
61
+ }
62
+
63
+ $type = Mage::getStoreConfig(self::XML_PATH_BACKUP_TYPE);
64
+
65
+ $this->_errors = array();
66
+ try {
67
+ $backupManager = Mage_Backup::getBackupInstance($type)
68
+ ->setBackupExtension(Mage::helper('backup')->getExtensionByType($type))
69
+ ->setTime(time())
70
+ ->setBackupsDir(Mage::helper('backup')->getBackupsDir());
71
+
72
+ Mage::register('backup_manager', $backupManager);
73
+
74
+ if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
75
+ $backupManager->setRootDir(Mage::getBaseDir())
76
+ ->addIgnorePaths(Mage::helper('backup')->getBackupIgnorePaths());
77
+ }
78
+
79
+ $backupManager->create();
80
+ Mage::log(Mage::helper('backup')->getCreateSuccessMessageByType($type));
81
+ }
82
+ catch (Exception $e) {
83
+ $this->_errors[] = $e->getMessage();
84
+ $this->_errors[] = $e->getTrace();
85
+ Mage::log($e->getMessage(), Zend_Log::ERR);
86
+ Mage::logException($e);
87
+ }
88
+
89
+ if (Mage::getStoreConfigFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE)) {
90
+ Mage::helper('backup')->turnOffMaintenanceMode();
91
+ }
92
+
93
+ return $this;
94
+ }
95
+ }
app/code/core/Mage/Backup/Model/Resource/Db.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -35,11 +35,11 @@
35
  class Mage_Backup_Model_Resource_Db
36
  {
37
  /**
38
- * Read connection
39
  *
40
  * @var Varien_Db_Adapter_Pdo_Mysql
41
  */
42
- protected $_read;
43
 
44
  /**
45
  * tables Foreign key data array
@@ -55,7 +55,7 @@ class Mage_Backup_Model_Resource_Db
55
  */
56
  public function __construct()
57
  {
58
- $this->_read = Mage::getSingleton('core/resource')->getConnection('backup_read');
59
  }
60
 
61
  /**
@@ -85,7 +85,7 @@ class Mage_Backup_Model_Resource_Db
85
  */
86
  public function getTables()
87
  {
88
- return $this->_read->listTables();
89
  }
90
 
91
  /**
@@ -123,7 +123,10 @@ class Mage_Backup_Model_Resource_Db
123
  if (!$tableName) {
124
  $tables = $this->getTables();
125
  foreach($tables as $table) {
126
- $fkScript = $fkScript . Mage::getResourceHelper('backup')->getTableForeignKeysSql($table);
 
 
 
127
  }
128
  } else {
129
  $fkScript = $this->getTableForeignKeysSql($tableName);
@@ -139,7 +142,7 @@ class Mage_Backup_Model_Resource_Db
139
  */
140
  public function getTableStatus($tableName)
141
  {
142
- $row = $this->_read->showTableStatus($tableName);
143
 
144
  if ($row) {
145
  $statusObject = new Varien_Object();
@@ -148,8 +151,8 @@ class Mage_Backup_Model_Resource_Db
148
  $statusObject->setData(strtolower($field), $value);
149
  }
150
 
151
- $cntRow = $this->_read->fetchRow(
152
- $this->_read->select()->from($tableName, 'COUNT(1) as rows'));
153
  $statusObject->setRows($cntRow['rows']);
154
 
155
  return $statusObject;
@@ -161,7 +164,7 @@ class Mage_Backup_Model_Resource_Db
161
  /**
162
  * Quote Table Row
163
  *
164
- * @deprecated
165
  *
166
  * @param string $tableName
167
  * @param array $row
@@ -169,7 +172,7 @@ class Mage_Backup_Model_Resource_Db
169
  */
170
  protected function _quoteRow($tableName, array $row)
171
  {
172
- return $row;
173
  }
174
 
175
  /**
@@ -182,8 +185,7 @@ class Mage_Backup_Model_Resource_Db
182
  */
183
  public function getTableDataSql($tableName, $count = null, $offset = null)
184
  {
185
- return Mage::getResourceHelper('backup')->getInsertSql($tableName);
186
-
187
  }
188
 
189
  /**
@@ -206,7 +208,7 @@ class Mage_Backup_Model_Resource_Db
206
  */
207
  public function getTableHeader($tableName)
208
  {
209
- $quotedTableName = $this->_read->quoteIdentifier($tableName);
210
  return "\n--\n"
211
  . "-- Table structure for table {$quotedTableName}\n"
212
  . "--\n\n";
@@ -241,7 +243,7 @@ class Mage_Backup_Model_Resource_Db
241
  */
242
  public function getFooter()
243
  {
244
- return Mage::getResourceHelper('backup')->getFooter();
245
  }
246
 
247
  /**
@@ -274,7 +276,7 @@ class Mage_Backup_Model_Resource_Db
274
  public function beginTransaction()
275
  {
276
  Mage::getResourceHelper('backup')->turnOnSerializableMode();
277
- $this->_read->beginTransaction();
278
  return $this;
279
  }
280
 
@@ -285,7 +287,7 @@ class Mage_Backup_Model_Resource_Db
285
  */
286
  public function commitTransaction()
287
  {
288
- $this->_read->commit();
289
  Mage::getResourceHelper('backup')->turnOnReadCommittedMode();
290
  return $this;
291
  }
@@ -297,7 +299,18 @@ class Mage_Backup_Model_Resource_Db
297
  */
298
  public function rollBackTransaction()
299
  {
300
- $this->_read->rollBack();
 
 
 
 
 
 
 
 
 
 
 
301
  return $this;
302
  }
303
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
35
  class Mage_Backup_Model_Resource_Db
36
  {
37
  /**
38
+ * Database connection adapter
39
  *
40
  * @var Varien_Db_Adapter_Pdo_Mysql
41
  */
42
+ protected $_write;
43
 
44
  /**
45
  * tables Foreign key data array
55
  */
56
  public function __construct()
57
  {
58
+ $this->_write = Mage::getSingleton('core/resource')->getConnection('backup_write');
59
  }
60
 
61
  /**
85
  */
86
  public function getTables()
87
  {
88
+ return $this->_write->listTables();
89
  }
90
 
91
  /**
123
  if (!$tableName) {
124
  $tables = $this->getTables();
125
  foreach($tables as $table) {
126
+ $tableFkScript = Mage::getResourceHelper('backup')->getTableForeignKeysSql($table);
127
+ if (!empty($tableFkScript)) {
128
+ $fkScript .= "\n" . $tableFkScript;
129
+ }
130
  }
131
  } else {
132
  $fkScript = $this->getTableForeignKeysSql($tableName);
142
  */
143
  public function getTableStatus($tableName)
144
  {
145
+ $row = $this->_write->showTableStatus($tableName);
146
 
147
  if ($row) {
148
  $statusObject = new Varien_Object();
151
  $statusObject->setData(strtolower($field), $value);
152
  }
153
 
154
+ $cntRow = $this->_write->fetchRow(
155
+ $this->_write->select()->from($tableName, 'COUNT(1) as rows'));
156
  $statusObject->setRows($cntRow['rows']);
157
 
158
  return $statusObject;
164
  /**
165
  * Quote Table Row
166
  *
167
+ * @deprecated
168
  *
169
  * @param string $tableName
170
  * @param array $row
172
  */
173
  protected function _quoteRow($tableName, array $row)
174
  {
175
+ return $row;
176
  }
177
 
178
  /**
185
  */
186
  public function getTableDataSql($tableName, $count = null, $offset = null)
187
  {
188
+ return Mage::getResourceHelper('backup')->getPartInsertSql($tableName, $count, $offset);
 
189
  }
190
 
191
  /**
208
  */
209
  public function getTableHeader($tableName)
210
  {
211
+ $quotedTableName = $this->_write->quoteIdentifier($tableName);
212
  return "\n--\n"
213
  . "-- Table structure for table {$quotedTableName}\n"
214
  . "--\n\n";
243
  */
244
  public function getFooter()
245
  {
246
+ return Mage::getResourceHelper('backup')->getFooter();
247
  }
248
 
249
  /**
276
  public function beginTransaction()
277
  {
278
  Mage::getResourceHelper('backup')->turnOnSerializableMode();
279
+ $this->_write->beginTransaction();
280
  return $this;
281
  }
282
 
287
  */
288
  public function commitTransaction()
289
  {
290
+ $this->_write->commit();
291
  Mage::getResourceHelper('backup')->turnOnReadCommittedMode();
292
  return $this;
293
  }
299
  */
300
  public function rollBackTransaction()
301
  {
302
+ $this->_write->rollBack();
303
+ return $this;
304
+ }
305
+
306
+ /**
307
+ * Run sql code
308
+ *
309
+ * @param $command
310
+ * @return Mage_Backup_Model_Resource_Db
311
+ */
312
+ public function runCommand($command){
313
+ $this->_write->query($command);
314
  return $this;
315
  }
316
  }
app/code/core/Mage/Backup/Model/Resource/Helper/Mysql4.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -54,19 +54,40 @@ class Mage_Backup_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_
54
  */
55
  public function getTableForeignKeysSql($tableName = null)
56
  {
 
 
57
  if ($tableName === null) {
58
  $sql = '';
59
  foreach ($this->_foreignKeys as $table => $foreignKeys) {
60
- $sql .= sprintf("ALTER TABLE %s\n %s;\n",
61
- $this->_getReadAdapter()->quoteIdentifier($table),
62
- join(",\n ", $foreignKeys)
63
- );
64
  }
65
- return $sql;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
 
68
- return false;
 
 
 
69
  }
 
70
  /**
71
  * Get create script for table
72
  *
@@ -217,14 +238,17 @@ class Mage_Backup_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_
217
  * Return table part data SQL insert
218
  *
219
  * @param string $tableName
 
 
220
  * @return string
221
  */
222
- public function getInsertSql($tableName)
223
  {
224
  $sql = null;
225
  $adapter = $this->_getWriteAdapter();
226
  $select = $adapter->select()
227
- ->from($tableName);
 
228
  $query = $adapter->query($select);
229
 
230
  while ($row = $query->fetch()) {
@@ -243,7 +267,16 @@ class Mage_Backup_Model_Resource_Helper_Mysql4 extends Mage_Core_Model_Resource_
243
 
244
  return $sql;
245
  }
246
-
 
 
 
 
 
 
 
 
 
247
  /**
248
  * Quote Table Row
249
  *
20
  *
21
  * @category Mage
22
  * @package Mage_Backup
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
54
  */
55
  public function getTableForeignKeysSql($tableName = null)
56
  {
57
+ $sql = false;
58
+
59
  if ($tableName === null) {
60
  $sql = '';
61
  foreach ($this->_foreignKeys as $table => $foreignKeys) {
62
+ $sql .= $this->_buildForeignKeysAlterTableSql($table, $foreignKeys);
 
 
 
63
  }
64
+ } else if (isset($this->_foreignKeys[$tableName])) {
65
+ $foreignKeys = $this->_foreignKeys[$tableName];
66
+ $sql = $this->_buildForeignKeysAlterTableSql($tableName, $foreignKeys);
67
+ }
68
+
69
+ return $sql;
70
+ }
71
+
72
+ /**
73
+ * Build sql that will add foreign keys to it
74
+ *
75
+ * @param string $tableName
76
+ * @param array $foreignKeys
77
+ * @return string
78
+ */
79
+ protected function _buildForeignKeysAlterTableSql($tableName, $foreignKeys)
80
+ {
81
+ if (!is_array($foreignKeys) || empty($foreignKeys)) {
82
+ return '';
83
  }
84
 
85
+ return sprintf("ALTER TABLE %s\n %s;\n",
86
+ $this->_getReadAdapter()->quoteIdentifier($tableName),
87
+ join(",\n ", $foreignKeys)
88
+ );
89
  }
90
+
91
  /**
92
  * Get create script for table
93
  *
238
  * Return table part data SQL insert
239
  *
240
  * @param string $tableName
241
+ * @param int $count
242
+ * @param int $offset
243
  * @return string
244
  */
245
+ public function getPartInsertSql($tableName, $count = null, $offset = null)
246
  {
247
  $sql = null;
248
  $adapter = $this->_getWriteAdapter();
249
  $select = $adapter->select()
250
+ ->from($tableName)
251
+ ->limit($count, $offset);
252
  $query = $adapter->query($select);
253
 
254
  while ($row = $query->fetch()) {
267
 
268
  return $sql;
269
  }
270
+ /**
271
+ * Return table data SQL insert
272
+ *
273
+ * @param string $tableName
274
+ * @return string
275
+ */
276
+ public function getInsertSql($tableName)
277
+ {
278
+ return $this->getPartInsertSql($tableName);
279
+ }
280
  /**
281
  * Quote Table Row
282
  *
app/code/core/Mage/Backup/etc/adminhtml.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Backup
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
@@ -50,6 +50,11 @@
50
  <children>
51
  <backup translate="title" module="backup">
52
  <title>Backups</title>
 
 
 
 
 
53
  </backup>
54
  </children>
55
  </tools>
21
  *
22
  * @category Mage
23
  * @package Mage_Backup
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
50
  <children>
51
  <backup translate="title" module="backup">
52
  <title>Backups</title>
53
+ <children>
54
+ <rollback translate="title" module="backup">
55
+ <title>Rollback</title>
56
+ </rollback>
57
+ </children>
58
  </backup>
59
  </children>
60
  </tools>
app/code/core/Mage/Backup/etc/config.xml CHANGED
@@ -21,7 +21,7 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Backup
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
@@ -61,4 +61,13 @@
61
  </modules>
62
  </translate>
63
  </adminhtml>
 
 
 
 
 
 
 
 
 
64
  </config>
21
  *
22
  * @category Mage
23
  * @package Mage_Backup
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
61
  </modules>
62
  </translate>
63
  </adminhtml>
64
+ <crontab>
65
+ <jobs>
66
+ <system_backup>
67
+ <run>
68
+ <model>backup/observer::scheduledBackup</model>
69
+ </run>
70
+ </system_backup>
71
+ </jobs>
72
+ </crontab>
73
  </config>
app/code/core/Mage/Backup/etc/system.xml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Backup
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <sections>
30
+ <system>
31
+ <groups>
32
+ <backup translate="label" module="backup">
33
+ <label>Scheduled Backup Settings</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>500</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>0</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ <fields>
40
+ <enabled translate="label">
41
+ <label>Enable Scheduled Backup</label>
42
+ <frontend_type>select</frontend_type>
43
+ <source_model>adminhtml/system_config_source_yesno</source_model>
44
+ <sort_order>10</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>0</show_in_website>
47
+ <show_in_store>0</show_in_store>
48
+ </enabled>
49
+ <type translate="label">
50
+ <label>Backup Type</label>
51
+ <frontend_type>select</frontend_type>
52
+ <depends><enabled>1</enabled></depends>
53
+ <source_model>backup/config_source_type</source_model>
54
+ <sort_order>20</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>0</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ </type>
59
+ <time translate="label">
60
+ <label>Start Time</label>
61
+ <frontend_type>time</frontend_type>
62
+ <depends><enabled>1</enabled></depends>
63
+ <sort_order>30</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>0</show_in_website>
66
+ <show_in_store>0</show_in_store>
67
+ </time>
68
+ <frequency translate="label">
69
+ <label>Frequency</label>
70
+ <frontend_type>select</frontend_type>
71
+ <depends><enabled>1</enabled></depends>
72
+ <source_model>adminhtml/system_config_source_cron_frequency</source_model>
73
+ <backend_model>backup/config_backend_cron</backend_model>
74
+ <sort_order>40</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>0</show_in_website>
77
+ <show_in_store>0</show_in_store>
78
+ </frequency>
79
+ <maintenance translate="label comment">
80
+ <label>Maintenance Mode</label>
81
+ <comment>Put store on the maintenance mode while backup's creation</comment>
82
+ <frontend_type>select</frontend_type>
83
+ <depends><enabled>1</enabled></depends>
84
+ <source_model>adminhtml/system_config_source_yesno</source_model>
85
+ <sort_order>50</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>0</show_in_website>
88
+ <show_in_store>0</show_in_store>
89
+ </maintenance>
90
+ </fields>
91
+ </backup>
92
+ </groups>
93
+ </system>
94
+ </sections>
95
+ </config>
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Bundle.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Checkbox.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Multi.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Radio.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Select.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -72,6 +72,7 @@ class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes
72
  $tax->setAfterElementHtml(
73
  '<script type="text/javascript">'
74
  . "
 
75
  function changeTaxClassId() {
76
  if ($('price_type').value == '" . Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC . "') {
77
  $('tax_class_id').disabled = true;
@@ -86,10 +87,13 @@ class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes
86
  }
87
  }
88
 
89
- if ($('price_type')) {
90
- $('price_type').observe('change', changeTaxClassId);
91
- changeTaxClassId();
92
- }
 
 
 
93
  "
94
  . '</script>'
95
  );
@@ -112,6 +116,15 @@ class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes
112
  );
113
  }
114
 
 
 
 
 
 
 
 
 
 
115
  $mapEnabled = $this->getForm()->getElement('msrp_enabled');
116
  if ($mapEnabled && $this->getCanEditPrice() !== false) {
117
  $mapEnabled->setAfterElementHtml(
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
72
  $tax->setAfterElementHtml(
73
  '<script type="text/javascript">'
74
  . "
75
+ //<![CDATA[
76
  function changeTaxClassId() {
77
  if ($('price_type').value == '" . Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC . "') {
78
  $('tax_class_id').disabled = true;
87
  }
88
  }
89
 
90
+ document.observe('dom:loaded', function() {
91
+ if ($('price_type')) {
92
+ $('price_type').observe('change', changeTaxClassId);
93
+ changeTaxClassId();
94
+ }
95
+ });
96
+ //]]>
97
  "
98
  . '</script>'
99
  );
116
  );
117
  }
118
 
119
+ $groupPrice = $this->getForm()->getElement('group_price');
120
+ if ($groupPrice) {
121
+ $groupPrice->setRenderer(
122
+ $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_group')
123
+ ->setPriceColumnHeader(Mage::helper('bundle')->__('Percent Discount'))
124
+ ->setPriceValidation('validate-greater-than-zero validate-percents')
125
+ );
126
+ }
127
+
128
  $mapEnabled = $this->getForm()->getElement('msrp_enabled');
129
  if ($mapEnabled && $this->getCanEditPrice() !== false) {
130
  $mapEnabled->setAfterElementHtml(
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Special.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -33,11 +33,35 @@
33
  */
34
  class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option extends Mage_Adminhtml_Block_Widget
35
  {
 
 
 
 
 
36
  protected $_element = null;
 
 
 
 
 
 
 
37
  protected $_customerGroups = null;
 
 
 
 
 
 
 
38
  protected $_websites = null;
39
 
40
- protected $_oprions = null;
 
 
 
 
 
41
 
42
  /**
43
  * Bundle option renderer class constructor
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
33
  */
34
  class Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option extends Mage_Adminhtml_Block_Widget
35
  {
36
+ /**
37
+ * Form element
38
+ *
39
+ * @var Varien_Data_Form_Element_Abstract|null
40
+ */
41
  protected $_element = null;
42
+
43
+ /**
44
+ * List of customer groups
45
+ *
46
+ * @deprecated since 1.7.0.0
47
+ * @var array|null
48
+ */
49
  protected $_customerGroups = null;
50
+
51
+ /**
52
+ * List of websites
53
+ *
54
+ * @deprecated since 1.7.0.0
55
+ * @var array|null
56
+ */
57
  protected $_websites = null;
58
 
59
+ /**
60
+ * List of bundle product options
61
+ *
62
+ * @var array|null
63
+ */
64
+ protected $_options = null;
65
 
66
  /**
67
  * Bundle option renderer class constructor
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search/Grid.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tabs.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Catalog/Product/List/Partof.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Catalog/Product/Price.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Catalog/Product/View.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -58,7 +58,9 @@ class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle extends Mage_Catalog_Bl
58
  $product
59
  );
60
 
61
- $this->_options = $optionCollection->appendSelections($selectionCollection, false, false);
 
 
62
  }
63
 
64
  return $this->_options;
@@ -122,7 +124,8 @@ class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle extends Mage_Catalog_Bl
122
  unset($tierPriceInfo); // break the reference with the last element
123
 
124
  $itemPrice = $bundlePriceModel->getSelectionFinalTotalPrice($currentProduct, $_selection,
125
- $currentProduct->getQty(), $_selection->getQty(), false);
 
126
 
127
  $canApplyMAP = false;
128
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
58
  $product
59
  );
60
 
61
+ $this->_options = $optionCollection->appendSelections($selectionCollection, false,
62
+ Mage::helper('catalog/product')->getSkipSaleableCheck()
63
+ );
64
  }
65
 
66
  return $this->_options;
124
  unset($tierPriceInfo); // break the reference with the last element
125
 
126
  $itemPrice = $bundlePriceModel->getSelectionFinalTotalPrice($currentProduct, $_selection,
127
+ $currentProduct->getQty(), $_selection->getQty(), false, false
128
+ );
129
 
130
  $canApplyMAP = false;
131
 
app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -163,6 +163,11 @@ class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option extends Mage_Bun
163
  return $selectedQty;
164
  }
165
 
 
 
 
 
 
166
  public function getProduct()
167
  {
168
  if (!$this->hasData('product')) {
@@ -175,7 +180,7 @@ class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option extends Mage_Bun
175
  {
176
  $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
177
  $this->setFormatProduct($_selection);
178
- $priceTitle = $_selection->getSelectionQty()*1 . ' x ' . $_selection->getName();
179
 
180
  $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '')
181
  . '+' . $this->formatPriceString($price, $includeContainer)
@@ -214,7 +219,7 @@ class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option extends Mage_Bun
214
  {
215
  $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection, 1);
216
  $this->setFormatProduct($_selection);
217
- $priceTitle = $_selection->getName();
218
  $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '')
219
  . '+' . $this->formatPriceString($price, $includeContainer)
220
  . ($includeContainer ? '</span>' : '');
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
163
  return $selectedQty;
164
  }
165
 
166
+ /**
167
+ * Get product model
168
+ *
169
+ * @return Mage_Catalog_Model_Product
170
+ */
171
  public function getProduct()
172
  {
173
  if (!$this->hasData('product')) {
180
  {
181
  $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
182
  $this->setFormatProduct($_selection);
183
+ $priceTitle = $_selection->getSelectionQty()*1 . ' x ' . $this->escapeHtml($_selection->getName());
184
 
185
  $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '')
186
  . '+' . $this->formatPriceString($price, $includeContainer)
219
  {
220
  $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection, 1);
221
  $this->setFormatProduct($_selection);
222
+ $priceTitle = $this->escapeHtml($_selection->getName());
223
  $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '')
224
  . '+' . $this->formatPriceString($price, $includeContainer)
225
  . ($includeContainer ? '</span>' : '');
app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Checkout/Cart/Item/Renderer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Block/Sales/Order/Items/Renderer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -57,12 +57,17 @@ class Mage_Bundle_Helper_Catalog_Product_Configuration extends Mage_Core_Helper_
57
  * @param Mage_Catalog_Model_Product $selectionProduct
58
  * @return decimal
59
  */
60
- public function getSelectionFinalPrice(Mage_Catalog_Model_Product_Configuration_Item_Interface $item, $selectionProduct)
 
61
  {
62
- return $item->getProduct()->getPriceModel()->getSelectionFinalPrice(
63
- $item->getProduct(), $selectionProduct,
 
 
64
  $item->getQty() * 1,
65
- $this->getSelectionQty($item->getProduct(), $selectionProduct->getSelectionId())
 
 
66
  );
67
  }
68
 
@@ -86,7 +91,7 @@ class Mage_Bundle_Helper_Catalog_Product_Configuration extends Mage_Core_Helper_
86
 
87
  // get bundle options
88
  $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
89
- $bundleOptionsIds = unserialize($optionsQuoteItemOption->getValue());
90
  if ($bundleOptionsIds) {
91
  /**
92
  * @var Mage_Bundle_Model_Mysql4_Option_Collection
@@ -115,7 +120,9 @@ class Mage_Bundle_Helper_Catalog_Product_Configuration extends Mage_Core_Helper_
115
  $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
116
  if ($qty) {
117
  $option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
118
- . ' ' . Mage::helper('core')->currency($this->getSelectionFinalPrice($item, $bundleSelection));
 
 
119
  }
120
  }
121
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
57
  * @param Mage_Catalog_Model_Product $selectionProduct
58
  * @return decimal
59
  */
60
+ public function getSelectionFinalPrice(Mage_Catalog_Model_Product_Configuration_Item_Interface $item,
61
+ $selectionProduct)
62
  {
63
+ $selectionProduct->unsetData('final_price');
64
+ return $item->getProduct()->getPriceModel()->getSelectionFinalTotalPrice(
65
+ $item->getProduct(),
66
+ $selectionProduct,
67
  $item->getQty() * 1,
68
+ $this->getSelectionQty($item->getProduct(), $selectionProduct->getSelectionId()),
69
+ false,
70
+ true
71
  );
72
  }
73
 
91
 
92
  // get bundle options
93
  $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
94
+ $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array();
95
  if ($bundleOptionsIds) {
96
  /**
97
  * @var Mage_Bundle_Model_Mysql4_Option_Collection
120
  $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
121
  if ($qty) {
122
  $option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
123
+ . ' ' . Mage::helper('core')->currency(
124
+ $this->getSelectionFinalPrice($item, $bundleSelection)
125
+ );
126
  }
127
  }
128
 
app/code/core/Mage/Bundle/Helper/Data.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/CatalogIndex/Data/Bundle.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Bundle.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Price.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Indexer/Stock.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Option.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Option/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Price/Index.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Selection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Mysql4/Selection/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Observer.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -256,6 +256,19 @@ class Mage_Bundle_Model_Observer
256
  return $this;
257
  }
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  /**
260
  * Add price index to bundle product after load
261
  *
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
256
  return $this;
257
  }
258
 
259
+ /**
260
+ * Initialize product options renderer with bundle specific params
261
+ *
262
+ * @param Varien_Event_Observer $observer
263
+ * @return Mage_Bundle_Model_Observer
264
+ */
265
+ public function initOptionRenderer(Varien_Event_Observer $observer)
266
+ {
267
+ $block = $observer->getBlock();
268
+ $block->addOptionsRenderCfg('bundle', 'bundle/catalog_product_configuration');
269
+ return $this;
270
+ }
271
+
272
  /**
273
  * Add price index to bundle product after load
274
  *
app/code/core/Mage/Bundle/Model/Option.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Price/Index.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Product/Attribute/Source/Price/View.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Product/Price.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -68,6 +68,40 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
68
  }
69
  }
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  /**
72
  * Get product final price
73
  *
@@ -81,45 +115,15 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
81
  return $product->getCalculatedFinalPrice();
82
  }
83
 
84
- $finalPrice = $product->getPrice();
 
 
 
85
 
86
- /**
87
- * Just product with fixed price calculation has price
88
- */
89
- if ($finalPrice) {
90
- $tierPrice = $this->_applyTierPrice($product, $qty, $finalPrice);
91
- $specialPrice = $this->_applySpecialPrice($product, $finalPrice);
92
- $finalPrice = min(array($tierPrice, $specialPrice));
93
-
94
- $product->setFinalPrice($finalPrice);
95
- Mage::dispatchEvent('catalog_product_get_final_price', array('product'=>$product));
96
- $finalPrice = $product->getData('final_price');
97
- }
98
- $basePrice = $finalPrice;
99
 
100
- if ($product->hasCustomOptions()) {
101
- $customOption = $product->getCustomOption('bundle_selection_ids');
102
- $selectionIds = unserialize($customOption->getValue());
103
- $selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product);
104
- $selections->addTierPriceData();
105
- Mage::dispatchEvent('prepare_catalog_product_collection_prices', array(
106
- 'collection' => $selections,
107
- 'store_id' => $product->getStoreId(),
108
- ));
109
- foreach ($selections->getItems() as $selection) {
110
- if ($selection->isSalable()) {
111
- $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
112
- if ($selectionQty) {
113
- $finalPrice += $this->getSelectionFinalPrice($product, $selection, $qty,
114
- $selectionQty->getValue());
115
- }
116
- }
117
- }
118
- }
119
-
120
- $finalPrice = $finalPrice + $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice;
121
  $product->setFinalPrice($finalPrice);
122
-
123
  return max(0, $product->getData('final_price'));
124
  }
125
 
@@ -134,13 +138,13 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
134
  */
135
  public function getChildFinalPrice($product, $productQty, $childProduct, $childProductQty)
136
  {
137
- return $this->getSelectionFinalPrice($product, $childProduct, $productQty, $childProductQty, false);
138
  }
139
 
140
  /**
141
  * Retrieve Price
142
  *
143
- * @deprecated after 1.10.1.1
144
  * @see Mage_Bundle_Model_Product_Price::getTotalPrices()
145
  *
146
  * @param Mage_Catalog_Model_Product $product
@@ -155,7 +159,7 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
155
  /**
156
  * Retrieve Prices depending on tax
157
  *
158
- * @deprecated after 1.10.1.1
159
  * @see Mage_Bundle_Model_Product_Price::getTotalPrices()
160
  *
161
  * @param Mage_Catalog_Model_Product $product
@@ -169,7 +173,7 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
169
  }
170
 
171
  /**
172
- * Retrieve Price with take into account tier price
173
  *
174
  * @param Mage_Catalog_Model_Product $product
175
  * @param string|null $which
@@ -181,9 +185,9 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
181
  {
182
  // check calculated price index
183
  if ($product->getData('min_price') && $product->getData('max_price')) {
184
- $minimalPrice = Mage::helper('tax')->getPrice($product, $product->getData('min_price'), $includeTax);
185
- $maximalPrice = Mage::helper('tax')->getPrice($product, $product->getData('max_price'), $includeTax);
186
- $this->_isPricesCalculatedByIndex = true;
187
  } else {
188
  /**
189
  * Check if product price is fixed
@@ -303,7 +307,7 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
303
 
304
  if ($which == 'max') {
305
  return $maximalPrice;
306
- } else if ($which == 'min') {
307
  return $minimalPrice;
308
  }
309
 
@@ -358,6 +362,9 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
358
  /**
359
  * Calculate price of selection
360
  *
 
 
 
361
  * @param Mage_Catalog_Model_Product $bundleProduct
362
  * @param Mage_Catalog_Model_Product $selectionProduct
363
  * @param float|null $selectionQty
@@ -366,27 +373,7 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
366
  */
367
  public function getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty = null, $multiplyQty = true)
368
  {
369
- if (is_null($selectionQty)) {
370
- $selectionQty = $selectionProduct->getSelectionQty();
371
- }
372
-
373
- if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
374
- if ($multiplyQty) {
375
- return $selectionProduct->getFinalPrice($selectionQty) * $selectionQty;
376
- } else {
377
- return $selectionProduct->getFinalPrice($selectionQty);
378
- }
379
- } else {
380
- if ($selectionProduct->getSelectionPriceType()) { // percent
381
- $price = $bundleProduct->getPrice() * ($selectionProduct->getSelectionPriceValue() / 100);
382
- } else { // fixed
383
- $price = $selectionProduct->getSelectionPriceValue();
384
- }
385
- if ($multiplyQty) {
386
- $price *= $selectionQty;
387
- }
388
- return $price;
389
- }
390
  }
391
 
392
  /**
@@ -399,16 +386,13 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
399
  */
400
  public function getSelectionPreFinalPrice($bundleProduct, $selectionProduct, $qty = null)
401
  {
402
- return $this->_applySpecialPrice(
403
- $bundleProduct,
404
- $this->getSelectionPrice($bundleProduct, $selectionProduct, $qty)
405
- );
406
  }
407
 
408
  /**
409
  * Calculate final price of selection
410
  *
411
- * @deprecated after 1.10.1.1
412
  * @see Mage_Bundle_Model_Product_Price::getSelectionFinalTotalPrice()
413
  *
414
  * @param Mage_Catalog_Model_Product $bundleProduct
@@ -440,18 +424,92 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
440
  public function getSelectionFinalTotalPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty,
441
  $multiplyQty = true, $takeTierPrice = true)
442
  {
443
- $selectionPrice = $this->getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty, $multiplyQty);
444
-
445
- // apply bundle special price
446
- $specialPrice = $this->_applySpecialPrice($bundleProduct, $selectionPrice);
447
 
448
- if ($takeTierPrice) {
449
- // apply bundle tier price
450
- $tierPrice = $this->_applyTierPrice($bundleProduct, $bundleQty, $selectionPrice);
451
- return min(array($tierPrice, $specialPrice));
452
  } else {
453
- return $specialPrice;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
  }
456
 
457
  /**
@@ -731,11 +789,11 @@ class Mage_Bundle_Model_Product_Price extends Mage_Catalog_Model_Product_Type_Pr
731
  }
732
 
733
  /**
734
- * Check is tier price value fixed or percent of original price
735
  *
736
  * @return bool
737
  */
738
- public function isTierPriceFixed()
739
  {
740
  return false;
741
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
68
  }
69
  }
70
 
71
+ /**
72
+ * Get Total price for Bundle items
73
+ *
74
+ * @param Mage_Catalog_Model_Product $product
75
+ * @param null|float $qty
76
+ * @return float
77
+ */
78
+ public function getTotalBundleItemsPrice($product, $qty = null)
79
+ {
80
+ $price = 0.0;
81
+ if ($product->hasCustomOptions()) {
82
+ $customOption = $product->getCustomOption('bundle_selection_ids');
83
+ if ($customOption) {
84
+ $selectionIds = unserialize($customOption->getValue());
85
+ $selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product);
86
+ $selections->addTierPriceData();
87
+ Mage::dispatchEvent('prepare_catalog_product_collection_prices', array(
88
+ 'collection' => $selections,
89
+ 'store_id' => $product->getStoreId(),
90
+ ));
91
+ foreach ($selections->getItems() as $selection) {
92
+ if ($selection->isSalable()) {
93
+ $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
94
+ if ($selectionQty) {
95
+ $price += $this->getSelectionFinalTotalPrice($product, $selection, $qty,
96
+ $selectionQty->getValue());
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ return $price;
103
+ }
104
+
105
  /**
106
  * Get product final price
107
  *
115
  return $product->getCalculatedFinalPrice();
116
  }
117
 
118
+ $finalPrice = $this->getBasePrice($product, $qty);
119
+ $product->setFinalPrice($finalPrice);
120
+ Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
121
+ $finalPrice = $product->getData('final_price');
122
 
123
+ $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
124
+ $finalPrice += $this->getTotalBundleItemsPrice($product, $qty);
 
 
 
 
 
 
 
 
 
 
 
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  $product->setFinalPrice($finalPrice);
 
127
  return max(0, $product->getData('final_price'));
128
  }
129
 
138
  */
139
  public function getChildFinalPrice($product, $productQty, $childProduct, $childProductQty)
140
  {
141
+ return $this->getSelectionFinalTotalPrice($product, $childProduct, $productQty, $childProductQty, false);
142
  }
143
 
144
  /**
145
  * Retrieve Price
146
  *
147
+ * @deprecated after 1.5.1.0
148
  * @see Mage_Bundle_Model_Product_Price::getTotalPrices()
149
  *
150
  * @param Mage_Catalog_Model_Product $product
159
  /**
160
  * Retrieve Prices depending on tax
161
  *
162
+ * @deprecated after 1.5.1.0
163
  * @see Mage_Bundle_Model_Product_Price::getTotalPrices()
164
  *
165
  * @param Mage_Catalog_Model_Product $product
173
  }
174
 
175
  /**
176
+ * Retrieve Price considering tier price
177
  *
178
  * @param Mage_Catalog_Model_Product $product
179
  * @param string|null $which
185
  {
186
  // check calculated price index
187
  if ($product->getData('min_price') && $product->getData('max_price')) {
188
+ $minimalPrice = Mage::helper('tax')->getPrice($product, $product->getData('min_price'), $includeTax);
189
+ $maximalPrice = Mage::helper('tax')->getPrice($product, $product->getData('max_price'), $includeTax);
190
+ $this->_isPricesCalculatedByIndex = true;
191
  } else {
192
  /**
193
  * Check if product price is fixed
307
 
308
  if ($which == 'max') {
309
  return $maximalPrice;
310
+ } elseif ($which == 'min') {
311
  return $minimalPrice;
312
  }
313
 
362
  /**
363
  * Calculate price of selection
364
  *
365
+ * @deprecated after 1.6.2.0
366
+ * @see Mage_Bundle_Model_Product_Price::getSelectionFinalTotalPrice()
367
+ *
368
  * @param Mage_Catalog_Model_Product $bundleProduct
369
  * @param Mage_Catalog_Model_Product $selectionProduct
370
  * @param float|null $selectionQty
373
  */
374
  public function getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty = null, $multiplyQty = true)
375
  {
376
+ return $this->getSelectionFinalTotalPrice($bundleProduct, $selectionProduct, 0, $selectionQty, $multiplyQty);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  }
378
 
379
  /**
386
  */
387
  public function getSelectionPreFinalPrice($bundleProduct, $selectionProduct, $qty = null)
388
  {
389
+ return $this->getSelectionPrice($bundleProduct, $selectionProduct, $qty);
 
 
 
390
  }
391
 
392
  /**
393
  * Calculate final price of selection
394
  *
395
+ * @deprecated after 1.5.1.0
396
  * @see Mage_Bundle_Model_Product_Price::getSelectionFinalTotalPrice()
397
  *
398
  * @param Mage_Catalog_Model_Product $bundleProduct
424
  public function getSelectionFinalTotalPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty,
425
  $multiplyQty = true, $takeTierPrice = true)
426
  {
427
+ if (is_null($selectionQty)) {
428
+ $selectionQty = $selectionProduct->getSelectionQty();
429
+ }
 
430
 
431
+ if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
432
+ $price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty : 1);
 
 
433
  } else {
434
+ if ($selectionProduct->getSelectionPriceType()) { // percent
435
+ $product = clone $bundleProduct;
436
+ $product->setFinalPrice($this->getPrice($product));
437
+ Mage::dispatchEvent(
438
+ 'catalog_product_get_final_price',
439
+ array('product' => $product, 'qty' => $bundleQty)
440
+ );
441
+ $price = $product->getData('final_price') * ($selectionProduct->getSelectionPriceValue() / 100);
442
+
443
+ } else { // fixed
444
+ $price = $selectionProduct->getSelectionPriceValue();
445
+ }
446
+ }
447
+
448
+ if ($multiplyQty) {
449
+ $price *= $selectionQty;
450
+ }
451
+
452
+ return min($price,
453
+ $this->_applyGroupPrice($bundleProduct, $price),
454
+ $this->_applyTierPrice($bundleProduct, $bundleQty, $price),
455
+ $this->_applySpecialPrice($bundleProduct, $price)
456
+ );
457
+ }
458
+
459
+ /**
460
+ * Apply group price for bundle product
461
+ *
462
+ * @param Mage_Catalog_Model_Product $product
463
+ * @param float $finalPrice
464
+ * @return float
465
+ */
466
+ protected function _applyGroupPrice($product, $finalPrice)
467
+ {
468
+ $result = $finalPrice;
469
+ $groupPrice = $product->getGroupPrice();
470
+
471
+ if (is_numeric($groupPrice)) {
472
+ $groupPrice = $finalPrice - ($finalPrice * ($groupPrice / 100));
473
+ $result = min($finalPrice, $groupPrice);
474
+ }
475
+
476
+ return $result;
477
+ }
478
+
479
+ /**
480
+ * Get product group price
481
+ *
482
+ * @param Mage_Catalog_Model_Product $product
483
+ * @return float|null
484
+ */
485
+ public function getGroupPrice($product)
486
+ {
487
+ $groupPrices = $product->getData('group_price');
488
+
489
+ if (is_null($groupPrices)) {
490
+ $attribute = $product->getResource()->getAttribute('group_price');
491
+ if ($attribute) {
492
+ $attribute->getBackend()->afterLoad($product);
493
+ $groupPrices = $product->getData('group_price');
494
+ }
495
  }
496
+
497
+ if (is_null($groupPrices) || !is_array($groupPrices)) {
498
+ return null;
499
+ }
500
+
501
+ $customerGroup = $this->_getCustomerGroupId($product);
502
+
503
+ $matchedPrice = 0;
504
+
505
+ foreach ($groupPrices as $groupPrice) {
506
+ if ($groupPrice['cust_group'] == $customerGroup && $groupPrice['website_price'] > $matchedPrice) {
507
+ $matchedPrice = $groupPrice['website_price'];
508
+ break;
509
+ }
510
+ }
511
+
512
+ return $matchedPrice;
513
  }
514
 
515
  /**
789
  }
790
 
791
  /**
792
+ * Check is group price value fixed or percent of original price
793
  *
794
  * @return bool
795
  */
796
+ public function isGroupPriceFixed()
797
  {
798
  return false;
799
  }
app/code/core/Mage/Bundle/Model/Product/Type.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -535,7 +535,9 @@ class Mage_Bundle_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abs
535
  $selections = array();
536
  $product = $this->getProduct($product);
537
  $isStrictProcessMode = $this->_isStrictProcessMode($processMode);
538
- $_appendAllSelections = (bool)$product->getSkipCheckRequiredOption();
 
 
539
 
540
  $options = $buyRequest->getBundleOption();
541
  if (is_array($options)) {
@@ -582,7 +584,7 @@ class Mage_Bundle_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abs
582
 
583
  // Check if added selections are still on sale
584
  foreach ($selections->getItems() as $key => $selection) {
585
- if (!$selection->isSalable()) {
586
  $_option = $optionsCollection->getItemById($selection->getOptionId());
587
  if (is_array($options[$_option->getId()]) && count($options[$_option->getId()]) > 1) {
588
  $moreSelections = true;
@@ -658,7 +660,7 @@ class Mage_Bundle_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abs
658
  * Create extra attributes that will be converted to product options in order item
659
  * for selection (not for all bundle)
660
  */
661
- $price = $product->getPriceModel()->getSelectionPrice($product, $selection, $qty);
662
  $attributes = array(
663
  'price' => Mage::app()->getStore()->convertPrice($price),
664
  'qty' => $qty,
@@ -799,9 +801,7 @@ class Mage_Bundle_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abs
799
  if ($selection->isSalable()) {
800
  $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
801
  if ($selectionQty) {
802
- $price = $product->getPriceModel()->getSelectionPrice(
803
- $product,
804
- $selection,
805
  $selectionQty->getValue()
806
  );
807
 
@@ -945,10 +945,11 @@ class Mage_Bundle_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abs
945
  Mage::throwException($this->getSpecifyOptionMessage());
946
  }
947
 
 
948
  foreach ($selectionIds as $selectionId) {
949
  /* @var $selection Mage_Bundle_Model_Selection */
950
  $selection = $productSelections->getItemById($selectionId);
951
- if (!$selection || !$selection->isSalable()) {
952
  Mage::throwException(
953
  Mage::helper('bundle')->__('Selected required options are not available.')
954
  );
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
535
  $selections = array();
536
  $product = $this->getProduct($product);
537
  $isStrictProcessMode = $this->_isStrictProcessMode($processMode);
538
+
539
+ $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
540
+ $_appendAllSelections = (bool)$product->getSkipCheckRequiredOption() || $skipSaleableCheck;
541
 
542
  $options = $buyRequest->getBundleOption();
543
  if (is_array($options)) {
584
 
585
  // Check if added selections are still on sale
586
  foreach ($selections->getItems() as $key => $selection) {
587
+ if (!$selection->isSalable() && !$skipSaleableCheck) {
588
  $_option = $optionsCollection->getItemById($selection->getOptionId());
589
  if (is_array($options[$_option->getId()]) && count($options[$_option->getId()]) > 1) {
590
  $moreSelections = true;
660
  * Create extra attributes that will be converted to product options in order item
661
  * for selection (not for all bundle)
662
  */
663
+ $price = $product->getPriceModel()->getSelectionFinalTotalPrice($product, $selection, 0, $qty);
664
  $attributes = array(
665
  'price' => Mage::app()->getStore()->convertPrice($price),
666
  'qty' => $qty,
801
  if ($selection->isSalable()) {
802
  $selectionQty = $product->getCustomOption('selection_qty_' . $selection->getSelectionId());
803
  if ($selectionQty) {
804
+ $price = $product->getPriceModel()->getSelectionFinalTotalPrice($product, $selection, 0,
 
 
805
  $selectionQty->getValue()
806
  );
807
 
945
  Mage::throwException($this->getSpecifyOptionMessage());
946
  }
947
 
948
+ $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
949
  foreach ($selectionIds as $selectionId) {
950
  /* @var $selection Mage_Bundle_Model_Selection */
951
  $selection = $productSelections->getItemById($selectionId);
952
+ if (!$selection || (!$selection->isSalable() && !$skipSaleableCheck)) {
953
  Mage::throwException(
954
  Mage::helper('bundle')->__('Selected required options are not available.')
955
  );
app/code/core/Mage/Bundle/Model/Resource/Bundle.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Resource/Indexer/Price.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -170,7 +170,13 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
170
  ->joinLeft(
171
  array('tp' => $this->_getTierPriceIndexTable()),
172
  'tp.entity_id = e.entity_id AND tp.website_id = cw.website_id'
173
- . ' AND tp.customer_group_id = cg.customer_group_id',
 
 
 
 
 
 
174
  array()
175
  )
176
  ->where('e.type_id=?', $this->getTypeId());
@@ -187,7 +193,9 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
187
  if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
188
  $select->columns(array('tax_class_id' => new Zend_Db_Expr('0')));
189
  } else {
190
- $select->columns(array('tax_class_id' => $write->getCheckSql($taxClassId . ' IS NOT NULL', $taxClassId, 0)));
 
 
191
  }
192
 
193
  $priceTypeCond = $write->quoteInto('=?', $priceType);
@@ -199,7 +207,6 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
199
  $specialTo = $this->_addAttributeToSelect($select, 'special_to_date', 'e.entity_id', 'cs.store_id');
200
  $curentDate = new Zend_Db_Expr('cwd.website_date');
201
 
202
-
203
  $specialExpr = $write->getCheckSql(
204
  $write->getCheckSql(
205
  $specialFrom . ' IS NULL',
@@ -223,6 +230,13 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
223
  $specialPrice,
224
  '0'
225
  );
 
 
 
 
 
 
 
226
  $tierExpr = new Zend_Db_Expr("tp.min_price");
227
 
228
  if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
@@ -233,24 +247,38 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
233
  );
234
  $tierPrice = $write->getCheckSql(
235
  $tierExpr . ' IS NOT NULL',
236
- 'ROUND(' . $price .' - ' . '(' . $price . ' * (' . $tierExpr . ' / 100)), 4)',
 
 
 
 
 
237
  'NULL'
238
  );
 
 
 
 
 
239
  } else {
240
  $finalPrice = new Zend_Db_Expr("0");
241
  $tierPrice = $write->getCheckSql($tierExpr . ' IS NOT NULL', '0', 'NULL');
 
242
  }
243
 
244
  $select->columns(array(
245
- 'price_type' => new Zend_Db_Expr($priceType),
246
- 'special_price' => $specialExpr,
247
- 'tier_percent' => $tierExpr,
248
- 'orig_price' => $write->getCheckSql($price . ' IS NULL', '0', $price),
249
- 'price' => $finalPrice,
250
- 'min_price' => $finalPrice,
251
- 'max_price' => $finalPrice,
252
- 'tier_price' => $tierPrice,
253
- 'base_tier' => $tierPrice,
 
 
 
254
  ));
255
 
256
  if (!is_null($entityIds)) {
@@ -300,6 +328,8 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
300
  'max_price' => $write->getCheckSql('i.group_type = 1', 'SUM(i.price)', 'MAX(i.price)'),
301
  'tier_price' => $write->getCheckSql('i.is_required = 1', 'MIN(i.tier_price)', '0'),
302
  'alt_tier_price' => $write->getCheckSql('i.is_required = 0', 'MIN(i.tier_price)', '0'),
 
 
303
  ));
304
 
305
  $query = $select->insertFromSelect($this->_getBundleOptionTable());
@@ -322,6 +352,15 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
322
  ) . ' + MIN(i.tier_price)',
323
  'NULL'
324
  );
 
 
 
 
 
 
 
 
 
325
 
326
  $select = $write->select()
327
  ->from(
@@ -337,12 +376,14 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
337
  ->group(array('io.entity_id', 'io.customer_group_id', 'io.website_id',
338
  'i.tax_class_id', 'i.orig_price', 'i.price'))
339
  ->columns(array('i.tax_class_id',
340
- 'orig_price' => 'i.orig_price',
341
- 'price' => 'i.price',
342
- 'min_price' => $minPrice,
343
- 'max_price' => $maxPrice,
344
- 'tier_price' => $tierPrice,
345
- 'base_tier' => 'MIN(i.base_tier)'
 
 
346
  ));
347
 
348
  $query = $select->insertFromSelect($this->_getDefaultFinalPriceTable());
@@ -385,7 +426,6 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
385
  ) . '* bs.selection_qty'
386
  );
387
 
388
-
389
  $tierExpr = $write->getCheckSql(
390
  'i.base_tier IS NOT NULL',
391
  $write->getCheckSql(
@@ -400,6 +440,24 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
400
  ) . ' * bs.selection_qty',
401
  'NULL'
402
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  } else {
404
  $priceExpr = new Zend_Db_Expr(
405
  $write->getCheckSql(
@@ -413,7 +471,21 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
413
  'ROUND(idx.min_price * (i.base_tier / 100), 4)* bs.selection_qty',
414
  'NULL'
415
  );
416
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  }
418
 
419
  $select = $write->select()
@@ -457,6 +529,7 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
457
  'is_required' => 'bo.required',
458
  'price' => $priceExpr,
459
  'tier_price' => $tierExpr,
 
460
  ));
461
 
462
  $query = $select->insertFromSelect($this->_getBundleSelectionTable());
@@ -474,6 +547,7 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
474
  protected function _prepareBundlePrice($entityIds = null)
475
  {
476
  $this->_prepareTierPriceIndex($entityIds);
 
477
  $this->_prepareBundlePriceTable();
478
  $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED, $entityIds);
479
  $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC, $entityIds);
@@ -562,4 +636,63 @@ class Mage_Bundle_Model_Resource_Indexer_Price extends Mage_Catalog_Model_Resour
562
 
563
  return $this;
564
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
170
  ->joinLeft(
171
  array('tp' => $this->_getTierPriceIndexTable()),
172
  'tp.entity_id = e.entity_id AND tp.website_id = cw.website_id'
173
+ . ' AND tp.customer_group_id = cg.customer_group_id',
174
+ array()
175
+ )
176
+ ->joinLeft(
177
+ array('gp' => $this->_getGroupPriceIndexTable()),
178
+ 'gp.entity_id = e.entity_id AND gp.website_id = cw.website_id'
179
+ . ' AND gp.customer_group_id = cg.customer_group_id',
180
  array()
181
  )
182
  ->where('e.type_id=?', $this->getTypeId());
193
  if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
194
  $select->columns(array('tax_class_id' => new Zend_Db_Expr('0')));
195
  } else {
196
+ $select->columns(
197
+ array('tax_class_id' => $write->getCheckSql($taxClassId . ' IS NOT NULL', $taxClassId, 0))
198
+ );
199
  }
200
 
201
  $priceTypeCond = $write->quoteInto('=?', $priceType);
207
  $specialTo = $this->_addAttributeToSelect($select, 'special_to_date', 'e.entity_id', 'cs.store_id');
208
  $curentDate = new Zend_Db_Expr('cwd.website_date');
209
 
 
210
  $specialExpr = $write->getCheckSql(
211
  $write->getCheckSql(
212
  $specialFrom . ' IS NULL',
230
  $specialPrice,
231
  '0'
232
  );
233
+
234
+ $groupPriceExpr = $write->getCheckSql(
235
+ 'gp.price IS NOT NULL AND gp.price > 0 AND gp.price < 100',
236
+ 'gp.price',
237
+ '0'
238
+ );
239
+
240
  $tierExpr = new Zend_Db_Expr("tp.min_price");
241
 
242
  if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
247
  );
248
  $tierPrice = $write->getCheckSql(
249
  $tierExpr . ' IS NOT NULL',
250
+ 'ROUND(' . $price . ' - ' . '(' . $price . ' * (' . $tierExpr . ' / 100)), 4)',
251
+ 'NULL'
252
+ );
253
+ $groupPrice = $write->getCheckSql(
254
+ $groupPriceExpr . ' > 0',
255
+ 'ROUND(' . $price . ' - ' . '(' . $price . ' * (' . $groupPriceExpr . ' / 100)), 4)',
256
  'NULL'
257
  );
258
+ $finalPrice = $write->getCheckSql(
259
+ "{$groupPrice} IS NOT NULL AND {$groupPrice} < {$finalPrice}",
260
+ $groupPrice,
261
+ $finalPrice
262
+ );
263
  } else {
264
  $finalPrice = new Zend_Db_Expr("0");
265
  $tierPrice = $write->getCheckSql($tierExpr . ' IS NOT NULL', '0', 'NULL');
266
+ $groupPrice = $write->getCheckSql($groupPriceExpr . ' > 0', $groupPriceExpr, 'NULL');
267
  }
268
 
269
  $select->columns(array(
270
+ 'price_type' => new Zend_Db_Expr($priceType),
271
+ 'special_price' => $specialExpr,
272
+ 'tier_percent' => $tierExpr,
273
+ 'orig_price' => $write->getCheckSql($price . ' IS NULL', '0', $price),
274
+ 'price' => $finalPrice,
275
+ 'min_price' => $finalPrice,
276
+ 'max_price' => $finalPrice,
277
+ 'tier_price' => $tierPrice,
278
+ 'base_tier' => $tierPrice,
279
+ 'group_price' => $groupPrice,
280
+ 'base_group_price' => $groupPrice,
281
+ 'group_price_percent' => new Zend_Db_Expr('gp.price'),
282
  ));
283
 
284
  if (!is_null($entityIds)) {
328
  'max_price' => $write->getCheckSql('i.group_type = 1', 'SUM(i.price)', 'MAX(i.price)'),
329
  'tier_price' => $write->getCheckSql('i.is_required = 1', 'MIN(i.tier_price)', '0'),
330
  'alt_tier_price' => $write->getCheckSql('i.is_required = 0', 'MIN(i.tier_price)', '0'),
331
+ 'group_price' => $write->getCheckSql('i.is_required = 1', 'MIN(i.group_price)', '0'),
332
+ 'alt_group_price' => $write->getCheckSql('i.is_required = 0', 'MIN(i.group_price)', '0'),
333
  ));
334
 
335
  $query = $select->insertFromSelect($this->_getBundleOptionTable());
352
  ) . ' + MIN(i.tier_price)',
353
  'NULL'
354
  );
355
+ $groupPrice = $write->getCheckSql(
356
+ 'MIN(i.group_price_percent) IS NOT NULL',
357
+ $write->getCheckSql(
358
+ 'SUM(io.group_price) = 0',
359
+ 'SUM(io.alt_group_price)',
360
+ 'SUM(io.group_price)'
361
+ ) . ' + MIN(i.group_price)',
362
+ 'NULL'
363
+ );
364
 
365
  $select = $write->select()
366
  ->from(
376
  ->group(array('io.entity_id', 'io.customer_group_id', 'io.website_id',
377
  'i.tax_class_id', 'i.orig_price', 'i.price'))
378
  ->columns(array('i.tax_class_id',
379
+ 'orig_price' => 'i.orig_price',
380
+ 'price' => 'i.price',
381
+ 'min_price' => $minPrice,
382
+ 'max_price' => $maxPrice,
383
+ 'tier_price' => $tierPrice,
384
+ 'base_tier' => 'MIN(i.base_tier)',
385
+ 'group_price' => $groupPrice,
386
+ 'base_group_price' => 'MIN(i.base_group_price)',
387
  ));
388
 
389
  $query = $select->insertFromSelect($this->_getDefaultFinalPriceTable());
426
  ) . '* bs.selection_qty'
427
  );
428
 
 
429
  $tierExpr = $write->getCheckSql(
430
  'i.base_tier IS NOT NULL',
431
  $write->getCheckSql(
440
  ) . ' * bs.selection_qty',
441
  'NULL'
442
  );
443
+
444
+ $groupExpr = $write->getCheckSql(
445
+ 'i.base_group_price IS NOT NULL',
446
+ $write->getCheckSql(
447
+ $selectionPriceType .' = 1',
448
+ $priceExpr,
449
+ $write->getCheckSql(
450
+ 'i.group_price_percent > 0',
451
+ 'ROUND(' . $selectionPriceValue
452
+ . ' - (' . $selectionPriceValue . ' * (i.group_price_percent / 100)),4)',
453
+ $selectionPriceValue
454
+ )
455
+ ) . ' * bs.selection_qty',
456
+ 'NULL'
457
+ );
458
+ $priceExpr = new Zend_Db_Expr(
459
+ $write->getCheckSql("{$groupExpr} < {$priceExpr}", $groupExpr, $priceExpr)
460
+ );
461
  } else {
462
  $priceExpr = new Zend_Db_Expr(
463
  $write->getCheckSql(
471
  'ROUND(idx.min_price * (i.base_tier / 100), 4)* bs.selection_qty',
472
  'NULL'
473
  );
474
+ $groupExpr = $write->getCheckSql(
475
+ 'i.base_group_price IS NOT NULL',
476
+ 'ROUND(idx.min_price * (i.base_group_price / 100), 4)* bs.selection_qty',
477
+ 'NULL'
478
+ );
479
+ $groupPriceExpr = new Zend_Db_Expr(
480
+ $write->getCheckSql(
481
+ 'i.base_group_price IS NOT NULL AND i.base_group_price > 0 AND i.base_group_price < 100',
482
+ 'ROUND(idx.min_price - idx.min_price * (i.base_group_price / 100), 4)',
483
+ 'idx.min_price'
484
+ ) . ' * bs.selection_qty'
485
+ );
486
+ $priceExpr = new Zend_Db_Expr(
487
+ $write->getCheckSql("{$groupPriceExpr} < {$priceExpr}", $groupPriceExpr, $priceExpr)
488
+ );
489
  }
490
 
491
  $select = $write->select()
529
  'is_required' => 'bo.required',
530
  'price' => $priceExpr,
531
  'tier_price' => $tierExpr,
532
+ 'group_price' => $groupExpr,
533
  ));
534
 
535
  $query = $select->insertFromSelect($this->_getBundleSelectionTable());
547
  protected function _prepareBundlePrice($entityIds = null)
548
  {
549
  $this->_prepareTierPriceIndex($entityIds);
550
+ $this->_prepareGroupPriceIndex($entityIds);
551
  $this->_prepareBundlePriceTable();
552
  $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED, $entityIds);
553
  $this->_prepareBundlePriceByType(Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC, $entityIds);
636
 
637
  return $this;
638
  }
639
+
640
+ /**
641
+ * Prepare percentage group price for bundle products
642
+ *
643
+ * @see Mage_Catalog_Model_Resource_Product_Indexer_Price::_prepareGroupPriceIndex
644
+ *
645
+ * @param int|array $entityIds
646
+ * @return Mage_Bundle_Model_Resource_Indexer_Price
647
+ */
648
+ protected function _prepareGroupPriceIndex($entityIds = null)
649
+ {
650
+ $adapter = $this->_getWriteAdapter();
651
+
652
+ // remove index by bundle products
653
+ $select = $adapter->select()
654
+ ->from(array('i' => $this->_getGroupPriceIndexTable()), null)
655
+ ->join(
656
+ array('e' => $this->getTable('catalog/product')),
657
+ 'i.entity_id=e.entity_id',
658
+ array()
659
+ )
660
+ ->where('e.type_id=?', $this->getTypeId());
661
+ $query = $select->deleteFromSelect('i');
662
+ $adapter->query($query);
663
+
664
+ $select = $adapter->select()
665
+ ->from(
666
+ array('gp' => $this->getValueTable('catalog/product', 'group_price')),
667
+ array('entity_id')
668
+ )
669
+ ->join(
670
+ array('e' => $this->getTable('catalog/product')),
671
+ 'gp.entity_id=e.entity_id',
672
+ array()
673
+ )
674
+ ->join(
675
+ array('cg' => $this->getTable('customer/customer_group')),
676
+ 'gp.all_groups = 1 OR (gp.all_groups = 0 AND gp.customer_group_id = cg.customer_group_id)',
677
+ array('customer_group_id')
678
+ )
679
+ ->join(
680
+ array('cw' => $this->getTable('core/website')),
681
+ 'gp.website_id = 0 OR gp.website_id = cw.website_id',
682
+ array('website_id')
683
+ )
684
+ ->where('cw.website_id != 0')
685
+ ->where('e.type_id=?', $this->getTypeId())
686
+ ->columns(new Zend_Db_Expr('MIN(gp.value)'))
687
+ ->group(array('gp.entity_id', 'cg.customer_group_id', 'cw.website_id'));
688
+
689
+ if (!empty($entityIds)) {
690
+ $select->where('gp.entity_id IN(?)', $entityIds);
691
+ }
692
+
693
+ $query = $select->insertFromSelect($this->_getGroupPriceIndexTable());
694
+ $adapter->query($query);
695
+
696
+ return $this;
697
+ }
698
  }
app/code/core/Mage/Bundle/Model/Resource/Indexer/Stock.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Resource/Option.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Resource/Option/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Resource/Price/Index.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Resource/Selection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Resource/Selection/Collection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Abstract.php CHANGED
@@ -20,11 +20,10 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
-
28
  /**
29
  * Sales Order Pdf Items renderer
30
  *
@@ -134,7 +133,9 @@ abstract class Mage_Bundle_Model_Sales_Order_Pdf_Items_Abstract extends Mage_Sal
134
  if ($parentItem) {
135
  $options = $parentItem->getProductOptions();
136
  if ($options) {
137
- if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
 
 
138
  return true;
139
  } else {
140
  return false;
@@ -143,7 +144,9 @@ abstract class Mage_Bundle_Model_Sales_Order_Pdf_Items_Abstract extends Mage_Sal
143
  } else {
144
  $options = $item->getProductOptions();
145
  if ($options) {
146
- if (isset($options['product_calculations']) && $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
 
 
147
  return false;
148
  } else {
149
  return true;
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
 
27
  /**
28
  * Sales Order Pdf Items renderer
29
  *
133
  if ($parentItem) {
134
  $options = $parentItem->getProductOptions();
135
  if ($options) {
136
+ if (isset($options['product_calculations']) &&
137
+ $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD
138
+ ) {
139
  return true;
140
  } else {
141
  return false;
144
  } else {
145
  $options = $item->getProductOptions();
146
  if ($options) {
147
+ if (isset($options['product_calculations']) &&
148
+ $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD
149
+ ) {
150
  return false;
151
  } else {
152
  return true;
app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php CHANGED
@@ -20,11 +20,10 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
-
28
  /**
29
  * Sales Order Creditmemo Pdf default items renderer
30
  *
@@ -47,8 +46,8 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
47
 
48
  $items = $this->getChilds($item);
49
  $_prevOptionId = '';
50
- $drawItems = array();
51
- $leftBound = 35;
52
  $rightBound = 565;
53
 
54
  foreach ($items as $_item) {
@@ -66,7 +65,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
66
  if (!isset($drawItems[$optionId])) {
67
  $drawItems[$optionId] = array(
68
  'lines' => array(),
69
- 'height' => 10
70
  );
71
  }
72
 
@@ -75,13 +74,13 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
75
  if ($_prevOptionId != $attributes['option_id']) {
76
  $line[0] = array(
77
  'font' => 'italic',
78
- 'text' => Mage::helper('core/string')->str_split($attributes['option_label'],60, true, true),
79
  'feed' => $x
80
  );
81
 
82
  $drawItems[$optionId] = array(
83
  'lines' => array($line),
84
- 'height' => 10
85
  );
86
 
87
  $line = array();
@@ -99,7 +98,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
99
  }
100
 
101
  $line[] = array(
102
- 'text' => Mage::helper('core/string')->str_split($name, 60, true, true),
103
  'feed' => $feed
104
  );
105
 
@@ -108,7 +107,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
108
  // draw SKUs
109
  if (!$_item->getOrderItem()->getParentItem()) {
110
  $text = array();
111
- foreach (Mage::helper('core/string')->str_split($item->getSku(), 30) as $part) {
112
  $text[] = $part;
113
  }
114
  $line[] = array(
@@ -166,7 +165,9 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
166
  $x += 45;
167
 
168
  // draw Total(inc)
169
- $text = $order->formatPriceTxt($_item->getRowTotal()+$_item->getTaxAmount()-$_item->getDiscountAmount());
 
 
170
  $line[] = array(
171
  'text' => $text,
172
  'feed' => $rightBound,
@@ -186,17 +187,19 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
186
  foreach ($options['options'] as $option) {
187
  $lines = array();
188
  $lines[][] = array(
189
- 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true),
190
  'font' => 'italic',
191
  'feed' => $leftBound
192
  );
193
 
194
  if ($option['value']) {
195
  $text = array();
196
- $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
 
 
197
  $values = explode(', ', $_printValue);
198
  foreach ($values as $value) {
199
- foreach (Mage::helper('core/string')->str_split($value, 50, true, true) as $_value) {
200
  $text[] = $_value;
201
  }
202
  }
@@ -209,7 +212,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Mod
209
 
210
  $drawItems[] = array(
211
  'lines' => $lines,
212
- 'height' => 10
213
  );
214
  }
215
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
 
27
  /**
28
  * Sales Order Creditmemo Pdf default items renderer
29
  *
46
 
47
  $items = $this->getChilds($item);
48
  $_prevOptionId = '';
49
+ $drawItems = array();
50
+ $leftBound = 35;
51
  $rightBound = 565;
52
 
53
  foreach ($items as $_item) {
65
  if (!isset($drawItems[$optionId])) {
66
  $drawItems[$optionId] = array(
67
  'lines' => array(),
68
+ 'height' => 15
69
  );
70
  }
71
 
74
  if ($_prevOptionId != $attributes['option_id']) {
75
  $line[0] = array(
76
  'font' => 'italic',
77
+ 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 38, true, true),
78
  'feed' => $x
79
  );
80
 
81
  $drawItems[$optionId] = array(
82
  'lines' => array($line),
83
+ 'height' => 15
84
  );
85
 
86
  $line = array();
98
  }
99
 
100
  $line[] = array(
101
+ 'text' => Mage::helper('core/string')->str_split($name, 35, true, true),
102
  'feed' => $feed
103
  );
104
 
107
  // draw SKUs
108
  if (!$_item->getOrderItem()->getParentItem()) {
109
  $text = array();
110
+ foreach (Mage::helper('core/string')->str_split($item->getSku(), 17) as $part) {
111
  $text[] = $part;
112
  }
113
  $line[] = array(
165
  $x += 45;
166
 
167
  // draw Total(inc)
168
+ $text = $order->formatPriceTxt(
169
+ $_item->getRowTotal() + $_item->getTaxAmount() - $_item->getDiscountAmount()
170
+ );
171
  $line[] = array(
172
  'text' => $text,
173
  'feed' => $rightBound,
187
  foreach ($options['options'] as $option) {
188
  $lines = array();
189
  $lines[][] = array(
190
+ 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true),
191
  'font' => 'italic',
192
  'feed' => $leftBound
193
  );
194
 
195
  if ($option['value']) {
196
  $text = array();
197
+ $_printValue = isset($option['print_value'])
198
+ ? $option['print_value']
199
+ : strip_tags($option['value']);
200
  $values = explode(', ', $_printValue);
201
  foreach ($values as $value) {
202
+ foreach (Mage::helper('core/string')->str_split($value, 30, true, true) as $_value) {
203
  $text[] = $_value;
204
  }
205
  }
212
 
213
  $drawItems[] = array(
214
  'lines' => $lines,
215
+ 'height' => 15
216
  );
217
  }
218
  }
app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php CHANGED
@@ -20,11 +20,10 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
-
28
  /**
29
  * Sales Order Invoice Pdf default items renderer
30
  *
@@ -65,7 +64,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Invoice extends Mage_Bundle_Model_
65
  if (!isset($drawItems[$optionId])) {
66
  $drawItems[$optionId] = array(
67
  'lines' => array(),
68
- 'height' => 10
69
  );
70
  }
71
 
@@ -73,13 +72,13 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Invoice extends Mage_Bundle_Model_
73
  if ($_prevOptionId != $attributes['option_id']) {
74
  $line[0] = array(
75
  'font' => 'italic',
76
- 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 70, true, true),
77
  'feed' => 35
78
  );
79
 
80
  $drawItems[$optionId] = array(
81
  'lines' => array($line),
82
- 'height' => 10
83
  );
84
 
85
  $line = array();
@@ -97,14 +96,14 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Invoice extends Mage_Bundle_Model_
97
  $name = $_item->getName();
98
  }
99
  $line[] = array(
100
- 'text' => Mage::helper('core/string')->str_split($name, 55, true, true),
101
  'feed' => $feed
102
  );
103
 
104
  // draw SKUs
105
  if (!$_item->getOrderItem()->getParentItem()) {
106
  $text = array();
107
- foreach (Mage::helper('core/string')->str_split($item->getSku(), 30) as $part) {
108
  $text[] = $part;
109
  }
110
  $line[] = array(
@@ -155,17 +154,19 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Invoice extends Mage_Bundle_Model_
155
  foreach ($options['options'] as $option) {
156
  $lines = array();
157
  $lines[][] = array(
158
- 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true),
159
  'font' => 'italic',
160
  'feed' => 35
161
  );
162
 
163
  if ($option['value']) {
164
  $text = array();
165
- $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
 
 
166
  $values = explode(', ', $_printValue);
167
  foreach ($values as $value) {
168
- foreach (Mage::helper('core/string')->str_split($value, 50, true, true) as $_value) {
169
  $text[] = $_value;
170
  }
171
  }
@@ -178,7 +179,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Invoice extends Mage_Bundle_Model_
178
 
179
  $drawItems[] = array(
180
  'lines' => $lines,
181
- 'height' => 10
182
  );
183
  }
184
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
 
27
  /**
28
  * Sales Order Invoice Pdf default items renderer
29
  *
64
  if (!isset($drawItems[$optionId])) {
65
  $drawItems[$optionId] = array(
66
  'lines' => array(),
67
+ 'height' => 15
68
  );
69
  }
70
 
72
  if ($_prevOptionId != $attributes['option_id']) {
73
  $line[0] = array(
74
  'font' => 'italic',
75
+ 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 45, true, true),
76
  'feed' => 35
77
  );
78
 
79
  $drawItems[$optionId] = array(
80
  'lines' => array($line),
81
+ 'height' => 15
82
  );
83
 
84
  $line = array();
96
  $name = $_item->getName();
97
  }
98
  $line[] = array(
99
+ 'text' => Mage::helper('core/string')->str_split($name, 35, true, true),
100
  'feed' => $feed
101
  );
102
 
103
  // draw SKUs
104
  if (!$_item->getOrderItem()->getParentItem()) {
105
  $text = array();
106
+ foreach (Mage::helper('core/string')->str_split($item->getSku(), 17) as $part) {
107
  $text[] = $part;
108
  }
109
  $line[] = array(
154
  foreach ($options['options'] as $option) {
155
  $lines = array();
156
  $lines[][] = array(
157
+ 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true),
158
  'font' => 'italic',
159
  'feed' => 35
160
  );
161
 
162
  if ($option['value']) {
163
  $text = array();
164
+ $_printValue = isset($option['print_value'])
165
+ ? $option['print_value']
166
+ : strip_tags($option['value']);
167
  $values = explode(', ', $_printValue);
168
  foreach ($values as $value) {
169
+ foreach (Mage::helper('core/string')->str_split($value, 30, true, true) as $_value) {
170
  $text[] = $_value;
171
  }
172
  }
179
 
180
  $drawItems[] = array(
181
  'lines' => $lines,
182
+ 'height' => 15
183
  );
184
  }
185
  }
app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php CHANGED
@@ -20,11 +20,10 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
27
-
28
  /**
29
  * Sales Order Shipment Pdf items renderer
30
  *
@@ -66,7 +65,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Shipment extends Mage_Bundle_Model
66
  if (!isset($drawItems[$optionId])) {
67
  $drawItems[$optionId] = array(
68
  'lines' => array(),
69
- 'height' => 10
70
  );
71
  }
72
 
@@ -74,13 +73,13 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Shipment extends Mage_Bundle_Model
74
  if ($_prevOptionId != $attributes['option_id']) {
75
  $line[0] = array(
76
  'font' => 'italic',
77
- 'text' => Mage::helper('core/string')->str_split($attributes['option_label'],60, true, true),
78
  'feed' => 60
79
  );
80
 
81
  $drawItems[$optionId] = array(
82
  'lines' => array($line),
83
- 'height' => 10
84
  );
85
 
86
  $line = array();
@@ -89,7 +88,9 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Shipment extends Mage_Bundle_Model
89
  }
90
  }
91
 
92
- if (($this->isShipmentSeparately() && $_item->getParentItem()) || (!$this->isShipmentSeparately() && !$_item->getParentItem())) {
 
 
93
  if (isset($shipItems[$_item->getId()])) {
94
  $qty = $shipItems[$_item->getId()]->getQty()*1;
95
  } else if ($_item->getIsVirtual()) {
@@ -125,7 +126,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Shipment extends Mage_Bundle_Model
125
 
126
  // draw SKUs
127
  $text = array();
128
- foreach (Mage::helper('core/string')->str_split($_item->getSku(), 30) as $part) {
129
  $text[] = $part;
130
  }
131
  $line[] = array(
@@ -150,7 +151,9 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Shipment extends Mage_Bundle_Model
150
 
151
  if ($option['value']) {
152
  $text = array();
153
- $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
 
 
154
  $values = explode(', ', $_printValue);
155
  foreach ($values as $value) {
156
  foreach (Mage::helper('core/string')->str_split($value, 50, true, true) as $_value) {
@@ -166,7 +169,7 @@ class Mage_Bundle_Model_Sales_Order_Pdf_Items_Shipment extends Mage_Bundle_Model
166
 
167
  $drawItems[] = array(
168
  'lines' => $lines,
169
- 'height' => 10
170
  );
171
  }
172
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
 
27
  /**
28
  * Sales Order Shipment Pdf items renderer
29
  *
65
  if (!isset($drawItems[$optionId])) {
66
  $drawItems[$optionId] = array(
67
  'lines' => array(),
68
+ 'height' => 15
69
  );
70
  }
71
 
73
  if ($_prevOptionId != $attributes['option_id']) {
74
  $line[0] = array(
75
  'font' => 'italic',
76
+ 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 60, true, true),
77
  'feed' => 60
78
  );
79
 
80
  $drawItems[$optionId] = array(
81
  'lines' => array($line),
82
+ 'height' => 15
83
  );
84
 
85
  $line = array();
88
  }
89
  }
90
 
91
+ if (($this->isShipmentSeparately() && $_item->getParentItem())
92
+ || (!$this->isShipmentSeparately() && !$_item->getParentItem())
93
+ ) {
94
  if (isset($shipItems[$_item->getId()])) {
95
  $qty = $shipItems[$_item->getId()]->getQty()*1;
96
  } else if ($_item->getIsVirtual()) {
126
 
127
  // draw SKUs
128
  $text = array();
129
+ foreach (Mage::helper('core/string')->str_split($_item->getSku(), 25) as $part) {
130
  $text[] = $part;
131
  }
132
  $line[] = array(
151
 
152
  if ($option['value']) {
153
  $text = array();
154
+ $_printValue = isset($option['print_value'])
155
+ ? $option['print_value']
156
+ : strip_tags($option['value']);
157
  $values = explode(', ', $_printValue);
158
  foreach ($values as $value) {
159
  foreach (Mage::helper('core/string')->str_split($value, 50, true, true) as $_value) {
169
 
170
  $drawItems[] = array(
171
  'lines' => $lines,
172
+ 'height' => 15
173
  );
174
  }
175
  }
app/code/core/Mage/Bundle/Model/Selection.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Source/Option/Selection/Price/Type.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/Model/Source/Option/Type.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/Product/EditController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/controllers/Adminhtml/Bundle/SelectionController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/controllers/Product/EditController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/controllers/SelectionController.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/data/bundle_setup/data-install-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/etc/config.xml CHANGED
@@ -21,14 +21,14 @@
21
  *
22
  * @category Mage
23
  * @package Mage_Bundle
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
  <Mage_Bundle>
31
- <version>1.6.0.0</version>
32
  </Mage_Bundle>
33
  </modules>
34
  <global>
@@ -216,6 +216,14 @@
216
  </bundle_observer>
217
  </observers>
218
  </catalog_product_collection_load_after>
 
 
 
 
 
 
 
 
219
  </events>
220
  </frontend>
221
  <admin>
21
  *
22
  * @category Mage
23
  * @package Mage_Bundle
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
  */
27
  -->
28
  <config>
29
  <modules>
30
  <Mage_Bundle>
31
+ <version>1.6.0.0.1</version>
32
  </Mage_Bundle>
33
  </modules>
34
  <global>
216
  </bundle_observer>
217
  </observers>
218
  </catalog_product_collection_load_after>
219
+ <product_option_renderer_init>
220
+ <observers>
221
+ <bundle_observer>
222
+ <class>bundle/observer</class>
223
+ <method>initOptionRenderer</method>
224
+ </bundle_observer>
225
+ </observers>
226
+ </product_option_renderer_init>
227
  </events>
228
  </frontend>
229
  <admin>
app/code/core/Mage/Bundle/sql/bundle_setup/install-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-data-upgrade-0.1.13-0.1.14.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-install-0.1.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.0-0.1.1.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.1-0.1.2.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.10-0.1.11.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.11-0.1.12.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.12-0.1.13.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.2-0.1.3.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.3-0.1.4.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.4-0.1.5.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.5-0.1.6.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.6-0.1.7.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.7-0.1.8.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.8-0.1.9.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-0.1.9-0.1.10.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Bundle/sql/bundle_setup/mysql4-upgrade-1.6.0.0-1.6.0.0.1.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ $installFile = dirname(__FILE__) . DS . 'upgrade-1.6.0.0-1.6.0.0.1.php';
28
+ if (file_exists($installFile)) {
29
+ include $installFile;
30
+ }
31
+
32
+ /** @var $installer Mage_Catalog_Model_Resource_Setup */
33
+ $installer = $this;
34
+ /** @var $connection Varien_Db_Adapter_Pdo_Mysql */
35
+ $connection = $installer->getConnection();
36
+ $memoryTables = array(
37
+ 'bundle/option_indexer_tmp',
38
+ 'bundle/selection_indexer_tmp',
39
+ 'bundle/price_indexer_tmp',
40
+ );
41
+
42
+ foreach ($memoryTables as $table) {
43
+ $connection->changeTableEngine($installer->getTable($table), Varien_Db_Adapter_Pdo_Mysql::ENGINE_MEMORY);
44
+ }
app/code/core/Mage/Bundle/sql/bundle_setup/upgrade-1.6.0.0-1.6.0.0.1.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Bundle
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /** @var $installer Mage_Catalog_Model_Resource_Setup */
28
+ $installer = $this;
29
+ $connection = $installer->getConnection();
30
+
31
+ $priceIndexerTables = array(
32
+ 'bundle/price_indexer_idx',
33
+ 'bundle/price_indexer_tmp',
34
+ );
35
+
36
+ $optionsPriceIndexerTables = array(
37
+ 'bundle/option_indexer_idx',
38
+ 'bundle/option_indexer_tmp',
39
+ );
40
+
41
+ $selectionPriceIndexerTables = array(
42
+ 'bundle/selection_indexer_idx',
43
+ 'bundle/selection_indexer_tmp',
44
+ );
45
+
46
+ foreach ($priceIndexerTables as $table) {
47
+ $connection->addColumn($installer->getTable($table), 'group_price', array(
48
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
49
+ 'length' => '12,4',
50
+ 'comment' => 'Group price',
51
+ ));
52
+ $connection->addColumn($installer->getTable($table), 'base_group_price', array(
53
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
54
+ 'length' => '12,4',
55
+ 'comment' => 'Base Group Price',
56
+ ));
57
+ $connection->addColumn($installer->getTable($table), 'group_price_percent', array(
58
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
59
+ 'length' => '12,4',
60
+ 'comment' => 'Group Price Percent',
61
+ ));
62
+ }
63
+
64
+ foreach (array_merge($optionsPriceIndexerTables, $selectionPriceIndexerTables) as $table) {
65
+ $connection->addColumn($installer->getTable($table), 'group_price', array(
66
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
67
+ 'length' => '12,4',
68
+ 'comment' => 'Group price',
69
+ ));
70
+ }
71
+
72
+ foreach ($optionsPriceIndexerTables as $table) {
73
+ $connection->addColumn($installer->getTable($table), 'alt_group_price', array(
74
+ 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
75
+ 'length' => '12,4',
76
+ 'comment' => 'Alt Group Price',
77
+ ));
78
+ }
79
+
80
+ $applyTo = explode(',', $installer->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'group_price', 'apply_to'));
81
+ if (!in_array('bundle', $applyTo)) {
82
+ $applyTo[] = 'bundle';
83
+ $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'group_price', 'apply_to', implode(',', $applyTo));
84
+ }
app/code/core/Mage/Captcha/Block/Captcha.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha block
29
+ *
30
+ * @category Core
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Block_Captcha extends Mage_Core_Block_Template
35
+ {
36
+ /**
37
+ * Renders captcha HTML (if required)
38
+ *
39
+ * @return string
40
+ */
41
+ protected function _toHtml()
42
+ {
43
+ $blockPath = Mage::helper('captcha')->getCaptcha($this->getFormId())->getBlockName();
44
+ $block = $this->getLayout()->createBlock($blockPath);
45
+ $block->setData($this->getData());
46
+ return $block->toHtml();
47
+ }
48
+ }
app/code/core/Mage/Captcha/Block/Captcha/Zend.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha block
29
+ *
30
+ * @category Core
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Block_Captcha_Zend extends Mage_Core_Block_Template
35
+ {
36
+ protected $_template = 'captcha/zend.phtml';
37
+
38
+ /**
39
+ * @var string
40
+ */
41
+ protected $_captcha;
42
+
43
+ /**
44
+ * Returns template path
45
+ *
46
+ * @return string
47
+ */
48
+ public function getTemplate()
49
+ {
50
+ return $this->getIsAjax() ? '' : $this->_template;
51
+ }
52
+
53
+ /**
54
+ * Returns URL to controller action which returns new captcha image
55
+ *
56
+ * @return string
57
+ */
58
+ public function getRefreshUrl()
59
+ {
60
+ return Mage::getUrl(
61
+ Mage::app()->getStore()->isAdmin() ? 'adminhtml/refresh/refresh' : 'captcha/refresh',
62
+ array('_secure' => Mage::app()->getStore()->isCurrentlySecure())
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Renders captcha HTML (if required)
68
+ *
69
+ * @return string
70
+ */
71
+ protected function _toHtml()
72
+ {
73
+ if ($this->getCaptchaModel()->isRequired()) {
74
+ $this->getCaptchaModel()->generate();
75
+ return parent::_toHtml();
76
+ }
77
+ return '';
78
+ }
79
+
80
+ /**
81
+ * Returns captcha model
82
+ *
83
+ * @return Mage_Captcha_Model_Abstract
84
+ */
85
+ public function getCaptchaModel()
86
+ {
87
+ return Mage::helper('captcha')->getCaptcha($this->getFormId());
88
+ }
89
+ }
app/code/core/Mage/Captcha/Helper/Data.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha image model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Helper_Data extends Mage_Core_Helper_Abstract
35
+ {
36
+ /**
37
+ * Used for "name" attribute of captcha's input field
38
+ */
39
+ const INPUT_NAME_FIELD_VALUE = 'captcha';
40
+
41
+ /**
42
+ * Always show captcha
43
+ */
44
+ const MODE_ALWAYS = 'always';
45
+
46
+ /**
47
+ * Show captcha only after certain number of unsuccessful attempts
48
+ */
49
+ const MODE_AFTER_FAIL = 'after_fail';
50
+
51
+ /**
52
+ * Captcha fonts path
53
+ */
54
+ const XML_PATH_CAPTCHA_FONTS = 'default/captcha/fonts';
55
+
56
+ /**
57
+ * List uses Models of Captcha
58
+ * @var array
59
+ */
60
+ protected $_captcha = array();
61
+
62
+ /**
63
+ * Get Captcha
64
+ *
65
+ * @param string $formId
66
+ * @return Mage_Captcha_Model_Interface
67
+ */
68
+ public function getCaptcha($formId)
69
+ {
70
+ if (!array_key_exists($formId, $this->_captcha)) {
71
+ $type = $this->getConfigNode('type');
72
+ $this->_captcha[$formId] = Mage::getModel('captcha/' . $type, array('formId' => $formId));
73
+ }
74
+ return $this->_captcha[$formId];
75
+ }
76
+
77
+ /**
78
+ * Returns value of the node with respect to current area (frontend or backend)
79
+ *
80
+ * @param string $id The last part of XML_PATH_$area_CAPTCHA_ constant (case insensitive)
81
+ * @param Mage_Core_Model_Store $store
82
+ * @return Mage_Core_Model_Config_Element
83
+ */
84
+ public function getConfigNode($id, $store = null)
85
+ {
86
+ $areaCode = Mage::app()->getStore($store)->isAdmin() ? 'admin' : 'customer';
87
+ return Mage::getStoreConfig( $areaCode . '/captcha/' . $id, $store);
88
+ }
89
+
90
+ /**
91
+ * Get list of available fonts
92
+ * Return format:
93
+ * [['arial'] => ['label' => 'Arial', 'path' => '/www/magento/fonts/arial.ttf']]
94
+ *
95
+ * @return array
96
+ */
97
+ public function getFonts()
98
+ {
99
+ $node = Mage::getConfig()->getNode(Mage_Captcha_Helper_Data::XML_PATH_CAPTCHA_FONTS);
100
+ $fonts = array();
101
+ if ($node) {
102
+ foreach ($node->children() as $fontName => $fontNode) {
103
+ $fonts[$fontName] = array(
104
+ 'label' => (string)$fontNode->label,
105
+ 'path' => Mage::getBaseDir('base') . DS . $fontNode->path
106
+ );
107
+ }
108
+ }
109
+ return $fonts;
110
+ }
111
+
112
+ /**
113
+ * Get captcha image directory
114
+ *
115
+ * @param mixed $website
116
+ * @return string
117
+ */
118
+ public function getImgDir($website = null)
119
+ {
120
+ $websiteCode = Mage::app()->getWebsite($website)->getCode();
121
+ $captchaDir = Mage::getBaseDir('media') . DS . 'captcha' . DS . $websiteCode . DS;
122
+ $io = new Varien_Io_File();
123
+ $io->checkAndCreateFolder($captchaDir, 0755);
124
+ return $captchaDir;
125
+ }
126
+
127
+ /**
128
+ * Get captcha image base URL
129
+ *
130
+ * @param mixed $website
131
+ * @return string
132
+ */
133
+ public function getImgUrl($website = null)
134
+ {
135
+ $websiteCode = Mage::app()->getWebsite($website)->getCode();
136
+ return Mage::getBaseUrl('media') . 'captcha' . '/' . $websiteCode . '/';
137
+ }
138
+ }
app/code/core/Mage/Captcha/Model/Config/Font.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha image model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Model_Config_Font
35
+ {
36
+ /**
37
+ * Get options for font selection field
38
+ *
39
+ * @return array
40
+ */
41
+ public function toOptionArray()
42
+ {
43
+ $optionArray = array();
44
+ foreach (Mage::helper('captcha')->getFonts() as $fontName => $fontData) {
45
+ $optionArray[] = array('label' => $fontData['label'], 'value' => $fontName);
46
+ }
47
+ return $optionArray;
48
+ }
49
+ }
app/code/core/Mage/Captcha/Model/Config/Form/Abstract.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Data source to fill "Forms" field
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Captcha_Model_Config_Form_Abstract extends Mage_Core_Model_Config_Data
35
+ {
36
+ /**
37
+ * @var string
38
+ */
39
+ protected $_configPath;
40
+
41
+ /**
42
+ * Returns options for form multiselect
43
+ *
44
+ * @return array
45
+ */
46
+ public function toOptionArray()
47
+ {
48
+ $optionArray = array();
49
+ /* @var $backendNode Mage_Core_Model_Config_Element */
50
+ $backendNode = Mage::getConfig()->getNode($this->_configPath);
51
+ if ($backendNode) {
52
+ foreach ($backendNode->children() as $formNode) {
53
+ /* @var $formNode Mage_Core_Model_Config_Element */
54
+ if (!empty($formNode->label)) {
55
+ $optionArray[] = array('label' => (string)$formNode->label, 'value' => $formNode->getName());
56
+ }
57
+ }
58
+ }
59
+ return $optionArray;
60
+ }
61
+ }
app/code/core/Mage/Captcha/Model/Config/Form/Backend.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha image model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Model_Config_Form_Backend extends Mage_Captcha_Model_Config_Form_Abstract
35
+ {
36
+ /**
37
+ * @var string
38
+ */
39
+ protected $_configPath = 'default/captcha/backend/areas';
40
+ }
app/code/core/Mage/Captcha/Model/Config/Form/Frontend.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha image model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Model_Config_Form_Frontend extends Mage_Captcha_Model_Config_Form_Abstract
35
+ {
36
+ /**
37
+ * @var string
38
+ */
39
+ protected $_configPath = 'default/captcha/frontend/areas';
40
+ }
app/code/core/Mage/Captcha/Model/Config/Mode.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha image model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Model_Config_Mode
35
+ {
36
+ /**
37
+ * Get options for captcha mode selection field
38
+ *
39
+ * @return array
40
+ */
41
+ public function toOptionArray()
42
+ {
43
+ return array(
44
+ array(
45
+ 'label' => Mage::helper('captcha')->__('Always'),
46
+ 'value' => Mage_Captcha_Helper_Data::MODE_ALWAYS
47
+ ),
48
+ array(
49
+ 'label' => Mage::helper('captcha')->__('After number of attempts to login'),
50
+ 'value' => Mage_Captcha_Helper_Data::MODE_AFTER_FAIL
51
+ ),
52
+ );
53
+ }
54
+ }
app/code/core/Mage/Captcha/Model/Interface.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha interface
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ interface Mage_Captcha_Model_Interface
35
+ {
36
+ /**
37
+ * Generates captcha
38
+ *
39
+ * @abstract
40
+ * @return void
41
+ */
42
+ public function generate();
43
+
44
+ /**
45
+ * Checks whether word entered by user corresponds to the one generated by generate()
46
+ *
47
+ * @abstract
48
+ * @param string $word
49
+ * @return void
50
+ */
51
+ public function isCorrect($word);
52
+
53
+
54
+ /**
55
+ * Get Block Name
56
+ *
57
+ * @return string
58
+ */
59
+ public function getBlockName();
60
+ }
app/code/core/Mage/Captcha/Model/Observer.php ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha Observer
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Model_Observer
35
+ {
36
+ /**
37
+ * Check Captcha On Forgot Password Page
38
+ *
39
+ * @param Varien_Event_Observer $observer
40
+ * @return Mage_Captcha_Model_Observer
41
+ */
42
+ public function checkForgotpassword($observer)
43
+ {
44
+ $formId = 'user_forgotpassword';
45
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
46
+ if ($captchaModel->isRequired()) {
47
+ $controller = $observer->getControllerAction();
48
+ if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
49
+ Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
50
+ $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
51
+ $controller->getResponse()->setRedirect(Mage::getUrl('*/*/forgotpassword'));
52
+ }
53
+ }
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Check Captcha On User Login Page
59
+ *
60
+ * @param Varien_Event_Observer $observer
61
+ * @return Mage_Captcha_Model_Observer
62
+ */
63
+ public function checkUserLogin($observer)
64
+ {
65
+ $formId = 'user_login';
66
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
67
+ $controller = $observer->getControllerAction();
68
+ $loginParams = $controller->getRequest()->getPost('login');
69
+ $login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
70
+ if ($captchaModel->isRequired($login)) {
71
+ $word = $this->_getCaptchaString($controller->getRequest(), $formId);
72
+ if (!$captchaModel->isCorrect($word)) {
73
+ Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
74
+ $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
75
+ Mage::getSingleton('customer/session')->setUsername($login);
76
+ $beforeUrl = Mage::getSingleton('customer/session')->getBeforeAuthUrl();
77
+ $url = $beforeUrl ? $beforeUrl : Mage::helper('customer')->getLoginUrl();
78
+ $controller->getResponse()->setRedirect($url);
79
+ }
80
+ }
81
+ $captchaModel->logAttempt($login);
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * Check Captcha On Register User Page
87
+ *
88
+ * @param Varien_Event_Observer $observer
89
+ * @return Mage_Captcha_Model_Observer
90
+ */
91
+ public function checkUserCreate($observer)
92
+ {
93
+ $formId = 'user_create';
94
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
95
+ if ($captchaModel->isRequired()) {
96
+ $controller = $observer->getControllerAction();
97
+ if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
98
+ Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
99
+ $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
100
+ Mage::getSingleton('customer/session')->setCustomerFormData($controller->getRequest()->getPost());
101
+ $controller->getResponse()->setRedirect(Mage::getUrl('*/*/create'));
102
+ }
103
+ }
104
+ return $this;
105
+ }
106
+
107
+ /**
108
+ * Check Captcha On Checkout as Guest Page
109
+ *
110
+ * @param Varien_Event_Observer $observer
111
+ * @return Mage_Captcha_Model_Observer
112
+ */
113
+ public function checkGuestCheckout($observer)
114
+ {
115
+ $formId = 'guest_checkout';
116
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
117
+ $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getQuote()->getCheckoutMethod();
118
+ if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST) {
119
+ if ($captchaModel->isRequired()) {
120
+ $controller = $observer->getControllerAction();
121
+ if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
122
+ $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
123
+ $result = array('error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
124
+ $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
125
+ }
126
+ }
127
+ }
128
+ return $this;
129
+ }
130
+
131
+ /**
132
+ * Check Captcha On Checkout Register Page
133
+ *
134
+ * @param Varien_Event_Observer $observer
135
+ * @return Mage_Captcha_Model_Observer
136
+ */
137
+ public function checkRegisterCheckout($observer)
138
+ {
139
+ $formId = 'register_during_checkout';
140
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
141
+ $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getQuote()->getCheckoutMethod();
142
+ if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) {
143
+ if ($captchaModel->isRequired()) {
144
+ $controller = $observer->getControllerAction();
145
+ if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
146
+ $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
147
+ $result = array('error' => 1, 'message' => Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
148
+ $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
149
+ }
150
+ }
151
+ }
152
+ return $this;
153
+ }
154
+
155
+ /**
156
+ * Check Captcha On User Login Backend Page
157
+ *
158
+ * @param Varien_Event_Observer $observer
159
+ * @return Mage_Captcha_Model_Observer
160
+ */
161
+ public function checkUserLoginBackend($observer)
162
+ {
163
+ $formId = 'backend_login';
164
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
165
+ $loginParams = Mage::app()->getRequest()->getPost('login');
166
+ $login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
167
+ if ($captchaModel->isRequired($login)) {
168
+ if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) {
169
+ $captchaModel->logAttempt($login);
170
+ Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
171
+ }
172
+ }
173
+ $captchaModel->logAttempt($login);
174
+ return $this;
175
+ }
176
+
177
+ /**
178
+ * Returns backend session
179
+ *
180
+ * @return Mage_Adminhtml_Model_Session
181
+ */
182
+ protected function _getBackendSession()
183
+ {
184
+ return Mage::getSingleton('adminhtml/session');
185
+ }
186
+
187
+ /**
188
+ * Check Captcha On User Login Backend Page
189
+ *
190
+ * @param Varien_Event_Observer $observer
191
+ * @return Mage_Captcha_Model_Observer
192
+ */
193
+ public function checkUserForgotPasswordBackend($observer)
194
+ {
195
+ $formId = 'backend_forgotpassword';
196
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
197
+ $controller = $observer->getControllerAction();
198
+ $email = (string) $observer->getControllerAction()->getRequest()->getParam('email');
199
+ $params = $observer->getControllerAction()->getRequest()->getParams();
200
+
201
+ if (!empty($email) && !empty($params)){
202
+ if ($captchaModel->isRequired()){
203
+ if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
204
+ $this->_getBackendSession()->setEmail((string) $controller->getRequest()->getPost('email'));
205
+ $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
206
+ $this->_getBackendSession()->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
207
+ $controller->getResponse()->setRedirect(Mage::getUrl('*/*/forgotpassword'));
208
+ }
209
+ }
210
+ }
211
+ return $this;
212
+ }
213
+
214
+ /**
215
+ * Reset Attempts For Frontend
216
+ *
217
+ * @param Varien_Event_Observer $observer
218
+ * @return Mage_Captcha_Model_Observer
219
+ */
220
+ public function resetAttemptForFrontend($observer)
221
+ {
222
+ return $this->_resetAttempt($observer->getModel()->getEmail());
223
+ }
224
+
225
+ /**
226
+ * Reset Attempts For Backend
227
+ *
228
+ * @param Varien_Event_Observer $observer
229
+ * @return Mage_Captcha_Model_Observer
230
+ */
231
+ public function resetAttemptForBackend($observer)
232
+ {
233
+ return $this->_resetAttempt($observer->getUser()->getUsername());
234
+ }
235
+
236
+ /**
237
+ * Delete Unnecessary logged attempts
238
+ *
239
+ * @return Mage_Captcha_Model_Observer
240
+ */
241
+ public function deleteOldAttempts()
242
+ {
243
+ Mage::getResourceModel('captcha/log')->deleteOldAttempts();
244
+ return $this;
245
+ }
246
+
247
+ /**
248
+ * Delete Expired Captcha Images
249
+ *
250
+ * @return Mage_Captcha_Model_Observer
251
+ */
252
+ public function deleteExpiredImages()
253
+ {
254
+ foreach (Mage::app()->getWebsites(true) as $website){
255
+ $expire = time() - Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore())*60;
256
+ $imageDirectory = Mage::helper('captcha')->getImgDir($website);
257
+ foreach (new DirectoryIterator($imageDirectory) as $file) {
258
+ if ($file->isFile() && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'png') {
259
+ if ($file->getMTime() < $expire) {
260
+ unlink($file->getPathname());
261
+ }
262
+ }
263
+ }
264
+ }
265
+ return $this;
266
+ }
267
+
268
+ /**
269
+ * Reset Attempts
270
+ *
271
+ * @param string $login
272
+ * @return Mage_Captcha_Model_Observer
273
+ */
274
+ protected function _resetAttempt($login)
275
+ {
276
+ Mage::getResourceModel('captcha/log')->deleteUserAttempts($login);
277
+ return $this;
278
+ }
279
+
280
+ /**
281
+ * Get Captcha String
282
+ *
283
+ * @param Varien_Object $request
284
+ * @param string $formId
285
+ * @return string
286
+ */
287
+ protected function _getCaptchaString($request, $formId)
288
+ {
289
+ $captchaParams = $request->getPost(Mage_Captcha_Helper_Data::INPUT_NAME_FIELD_VALUE);
290
+ return $captchaParams[$formId];
291
+ }
292
+ }
app/code/core/Mage/Captcha/Model/Resource/Log.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * Log Attempts resource
30
+ *
31
+ * @category Mage
32
+ * @package Mage_Captcha
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Mage_Captcha_Model_Resource_Log extends Mage_Core_Model_Resource_Db_Abstract
36
+ {
37
+ /**
38
+ * Type Remote Address
39
+ */
40
+ const TYPE_REMOTE_ADDRESS = 1;
41
+
42
+ /**
43
+ * Type User Login Name
44
+ */
45
+ const TYPE_LOGIN = 2;
46
+
47
+ /**
48
+ * Define main table
49
+ *
50
+ */
51
+ protected function _construct()
52
+ {
53
+ $this->_setMainTable('captcha/log');
54
+ }
55
+
56
+ /**
57
+ * Save or Update count Attempts
58
+ *
59
+ * @param string|null $login
60
+ * @return Mage_Captcha_Model_Resource_Log
61
+ */
62
+ public function logAttempt($login)
63
+ {
64
+ if ($login != null){
65
+ $this->_getWriteAdapter()->insertOnDuplicate(
66
+ $this->getMainTable(),
67
+ array(
68
+ 'type' => self::TYPE_LOGIN, 'value' => $login, 'count' => 1,
69
+ 'updated_at' => Mage::getSingleton('core/date')->gmtDate()
70
+ ),
71
+ array('count' => new Zend_Db_Expr('count+1'), 'updated_at')
72
+ );
73
+ }
74
+ $ip = Mage::helper('core/http')->getRemoteAddr();
75
+ if ($ip != null) {
76
+ $this->_getWriteAdapter()->insertOnDuplicate(
77
+ $this->getMainTable(),
78
+ array(
79
+ 'type' => self::TYPE_REMOTE_ADDRESS, 'value' => $ip, 'count' => 1,
80
+ 'updated_at' => Mage::getSingleton('core/date')->gmtDate()
81
+ ),
82
+ array('count' => new Zend_Db_Expr('count+1'), 'updated_at')
83
+ );
84
+ }
85
+ return $this;
86
+ }
87
+
88
+ /**
89
+ * Delete User attempts by login
90
+ *
91
+ * @param string $login
92
+ * @return Mage_Captcha_Model_Resource_Log
93
+ */
94
+ public function deleteUserAttempts($login)
95
+ {
96
+ if ($login != null) {
97
+ $this->_getWriteAdapter()->delete(
98
+ $this->getMainTable(),
99
+ array('type = ?' => self::TYPE_LOGIN, 'value = ?' => $login)
100
+ );
101
+ }
102
+ $ip = Mage::helper('core/http')->getRemoteAddr();
103
+ if ($ip != null) {
104
+ $this->_getWriteAdapter()->delete(
105
+ $this->getMainTable(), array('type = ?' => self::TYPE_REMOTE_ADDRESS, 'value = ?' => $ip)
106
+ );
107
+ }
108
+
109
+ return $this;
110
+ }
111
+
112
+ /**
113
+ * Get count attempts by ip
114
+ *
115
+ * @return null|int
116
+ */
117
+ public function countAttemptsByRemoteAddress()
118
+ {
119
+ $ip = Mage::helper('core/http')->getRemoteAddr();
120
+ if (!$ip) {
121
+ return 0;
122
+ }
123
+ $read = $this->_getReadAdapter();
124
+ $select = $read->select()->from($this->getMainTable(), 'count')->where('type = ?', self::TYPE_REMOTE_ADDRESS)
125
+ ->where('value = ?', $ip);
126
+ return $read->fetchOne($select);
127
+ }
128
+
129
+ /**
130
+ * Get count attempts by user login
131
+ *
132
+ * @param string $login
133
+ * @return null|int
134
+ */
135
+ public function countAttemptsByUserLogin($login)
136
+ {
137
+ if (!$login) {
138
+ return 0;
139
+ }
140
+ $read = $this->_getReadAdapter();
141
+ $select = $read->select()->from($this->getMainTable(), 'count')->where('type = ?', self::TYPE_LOGIN)
142
+ ->where('value = ?', $login);
143
+ return $read->fetchOne($select);
144
+ }
145
+
146
+ /**
147
+ * Delete attempts with expired in update_at time
148
+ *
149
+ * @return void
150
+ */
151
+ public function deleteOldAttempts()
152
+ {
153
+ $this->_getWriteAdapter()->delete(
154
+ $this->getMainTable(),
155
+ array('updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, time() - 60*30))
156
+ );
157
+ }
158
+ }
app/code/core/Mage/Captcha/Model/Zend.php ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Implementation of Zend_Captcha
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Captcha
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Model_Zend extends Zend_Captcha_Image implements Mage_Captcha_Model_Interface
35
+ {
36
+ /**
37
+ * Key in session for captcha code
38
+ */
39
+ const SESSION_WORD = 'word';
40
+
41
+ /**
42
+ * Min captcha lengths default value
43
+ */
44
+ const DEFAULT_WORD_LENGTH_FROM = 3;
45
+
46
+ /**
47
+ * Max captcha lengths default value
48
+ */
49
+ const DEFAULT_WORD_LENGTH_TO = 5;
50
+
51
+ /**
52
+ * Helper Instance
53
+ * @var Mage_Captcha_Helper_Data
54
+ */
55
+ protected $_helper = null;
56
+
57
+ /**
58
+ * Captcha expire time
59
+ * @var int
60
+ */
61
+ protected $_expiration;
62
+
63
+ /**
64
+ * Override default value to prevent a captcha cut off
65
+ * @var int
66
+ * @see Zend_Captcha_Image::$_fsize
67
+ */
68
+ protected $_fsize = 22;
69
+
70
+ /**
71
+ * Captcha form id
72
+ * @var string
73
+ */
74
+ protected $_formId;
75
+
76
+ /**
77
+ * Zend captcha constructor
78
+ *
79
+ * @param array $params
80
+ */
81
+ public function __construct($params)
82
+ {
83
+ if (!isset($params['formId'])) {
84
+ throw new Exception('formId is mandatory');
85
+ }
86
+ $this->_formId = $params['formId'];
87
+ $this->setExpiration($this->getTimeout());
88
+ }
89
+
90
+ /**
91
+ * Returns key with respect of current form ID
92
+ *
93
+ * @param string $key
94
+ * @return string
95
+ */
96
+ protected function _getFormIdKey($key)
97
+ {
98
+ return $this->_formId . '_' . $key;
99
+ }
100
+
101
+ /**
102
+ * Get Block Name
103
+ *
104
+ * @return string
105
+ */
106
+ public function getBlockName()
107
+ {
108
+ return 'captcha/captcha_zend';
109
+ }
110
+
111
+
112
+ /**
113
+ * Whether captcha is required to be inserted to this form
114
+ *
115
+ * @param null|string $login
116
+ * @return bool
117
+ */
118
+ public function isRequired($login = null)
119
+ {
120
+ if ($this->_isUserAuth() || !$this->_isEnabled() || !in_array($this->_formId, $this->_getTargetForms())) {
121
+ return false;
122
+ }
123
+
124
+ return ($this->_isShowAlways() || $this->_isOverLimitAttempts($login)
125
+ || $this->getSession()->getData($this->_getFormIdKey('show_captcha'))
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Check is overlimit attempts
131
+ *
132
+ * @param string $login
133
+ * @return bool
134
+ */
135
+ protected function _isOverLimitAttempts($login)
136
+ {
137
+ return ($this->_isOverLimitIpAttempt() || $this->_isOverLimitLoginAttempts($login));
138
+ }
139
+
140
+ /**
141
+ * Returns number of allowed attempts for same login
142
+ *
143
+ * @return int
144
+ */
145
+ protected function _getAllowedAttemptsForSameLogin()
146
+ {
147
+ return (int)$this->_getHelper()->getConfigNode('failed_attempts_login');
148
+ }
149
+
150
+ /**
151
+ * Returns number of allowed attempts from same IP
152
+ *
153
+ * @return int
154
+ */
155
+ protected function _getAllowedAttemptsFromSameIp()
156
+ {
157
+ return (int)$this->_getHelper()->getConfigNode('failed_attempts_ip');
158
+ }
159
+
160
+ /**
161
+ * Check is overlimit saved attempts from one ip
162
+ *
163
+ * @return bool
164
+ */
165
+ protected function _isOverLimitIpAttempt()
166
+ {
167
+ $countAttemptsByIp = Mage::getResourceModel('captcha/log')->countAttemptsByRemoteAddress();
168
+ return $countAttemptsByIp >= $this->_getAllowedAttemptsFromSameIp();
169
+ }
170
+
171
+ /**
172
+ * Is Over Limit Login Attempts
173
+ *
174
+ * @param string $login
175
+ * @return bool
176
+ */
177
+ protected function _isOverLimitLoginAttempts($login)
178
+ {
179
+ if ($login != false) {
180
+ $countAttemptsByLogin = Mage::getResourceModel('captcha/log')->countAttemptsByUserLogin($login);
181
+ return ($countAttemptsByLogin >= $this->_getAllowedAttemptsForSameLogin());
182
+ }
183
+ return false;
184
+ }
185
+
186
+ /**
187
+ * Check is user auth
188
+ *
189
+ * @return bool
190
+ */
191
+ protected function _isUserAuth()
192
+ {
193
+ return Mage::app()->getStore()->isAdmin()
194
+ ? Mage::getSingleton('admin/session')->isLoggedIn()
195
+ : Mage::getSingleton('customer/session')->isLoggedIn();
196
+ }
197
+
198
+ /**
199
+ * Whether to respect case while checking the answer
200
+ *
201
+ * @return bool
202
+ */
203
+ public function isCaseSensitive()
204
+ {
205
+ return (string)$this->_getHelper()->getConfigNode('case_sensitive');
206
+ }
207
+
208
+ /**
209
+ * Get font to use when generating captcha
210
+ *
211
+ * @return string
212
+ */
213
+ public function getFont()
214
+ {
215
+ return $this->_getFontPath();
216
+ }
217
+
218
+ /**
219
+ * After this time isCorrect() is going to return FALSE even if word was guessed correctly
220
+ *
221
+ * @return int
222
+ */
223
+ public function getTimeout()
224
+ {
225
+ if (!$this->_expiration) {
226
+ /**
227
+ * as "timeout" configuration parameter specifies timeout in minutes - we multiply it on 60 to set
228
+ * expiration in seconds
229
+ */
230
+ $this->_expiration = (int)$this->_getHelper()->getConfigNode('timeout') * 60;
231
+ }
232
+ return $this->_expiration;
233
+ }
234
+
235
+ /**
236
+ * Get captcha image directory
237
+ *
238
+ * @return string
239
+ */
240
+ public function getImgDir()
241
+ {
242
+ return $this->_helper->getImgDir();
243
+ }
244
+
245
+ /**
246
+ * Get captcha image base URL
247
+ *
248
+ * @return string
249
+ */
250
+ public function getImgUrl()
251
+ {
252
+ return $this->_helper->getImgUrl();
253
+ }
254
+
255
+ /**
256
+ * Checks whether captcha was guessed correctly by user
257
+ *
258
+ * @param string $word
259
+ * @return bool
260
+ */
261
+ public function isCorrect($word)
262
+ {
263
+ $storedWord = $this->getWord();
264
+ $this->_clearWord();
265
+
266
+ if (!$word || !$storedWord){
267
+ return false;
268
+ }
269
+
270
+ if (!$this->isCaseSensitive()) {
271
+ $storedWord = strtolower($storedWord);
272
+ $word = strtolower($word);
273
+ }
274
+ return $word == $storedWord;
275
+ }
276
+
277
+ /**
278
+ * Returns session instance
279
+ *
280
+ * @return Mage_Customer_Model_Session
281
+ */
282
+ public function getSession()
283
+ {
284
+ return Mage::getSingleton('customer/session');
285
+ }
286
+
287
+ /**
288
+ * Return full URL to captcha image
289
+ *
290
+ * @return string
291
+ */
292
+ public function getImgSrc()
293
+ {
294
+ return $this->getImgUrl() . $this->getId() . $this->getSuffix();
295
+ }
296
+
297
+ /**
298
+ * log Attempt
299
+ *
300
+ * @param string $login
301
+ * @return Mage_Captcha_Model_Zend
302
+ */
303
+ public function logAttempt($login)
304
+ {
305
+ if ($this->_isEnabled() && in_array($this->_formId, $this->_getTargetForms())) {
306
+ Mage::getResourceModel('captcha/log')->logAttempt($login);
307
+ if ($this->_isOverLimitLoginAttempts($login)) {
308
+ $this->getSession()->setData($this->_getFormIdKey('show_captcha'), 1);
309
+ }
310
+ }
311
+ return $this;
312
+ }
313
+
314
+ /**
315
+ * Returns path for the font file, chosen to generate captcha
316
+ *
317
+ * @return string
318
+ */
319
+ protected function _getFontPath()
320
+ {
321
+ $font = (string)$this->_getHelper()->getConfigNode('font');
322
+ $fonts = $this->_getHelper()->getFonts();
323
+
324
+ if (isset($fonts[$font])) {
325
+ $fontPath = $fonts[$font]['path'];
326
+ } else {
327
+ $fontData = array_shift($fonts);
328
+ $fontPath = $fontData['path'];
329
+ }
330
+
331
+ return $fontPath;
332
+ }
333
+
334
+ /**
335
+ * Returns captcha helper
336
+ *
337
+ * @return Mage_Captcha_Helper_Data
338
+ */
339
+ protected function _getHelper()
340
+ {
341
+ if (empty($this->_helper)) {
342
+ $this->_helper = Mage::helper('captcha');
343
+ }
344
+ return $this->_helper;
345
+ }
346
+
347
+ /**
348
+ * Generate word used for captcha render
349
+ *
350
+ * @return string
351
+ */
352
+ protected function _generateWord()
353
+ {
354
+ $word = '';
355
+ $symbols = $this->_getSymbols();
356
+ $wordLen = $this->_getWordLen();
357
+ for ($i = 0; $i < $wordLen; $i++) {
358
+ $word .= $symbols[array_rand($symbols)];
359
+ }
360
+ return $word;
361
+ }
362
+
363
+ /**
364
+ * Get symbols array to use for word generation
365
+ *
366
+ * @return array
367
+ */
368
+ protected function _getSymbols()
369
+ {
370
+ return str_split((string)$this->_getHelper()->getConfigNode('symbols'));
371
+ }
372
+
373
+ /**
374
+ * Returns length for generating captcha word. This value may be dynamic.
375
+ *
376
+ * @return int
377
+ */
378
+ protected function _getWordLen()
379
+ {
380
+ $from = 0;
381
+ $to = 0;
382
+ $length = (string)$this->_getHelper()->getConfigNode('length');
383
+ if (!is_numeric($length)) {
384
+ if (preg_match('/(\d+)-(\d+)/', $length, $matches)) {
385
+ $from = (int)$matches[1];
386
+ $to = (int)$matches[2];
387
+ }
388
+ } else {
389
+ $from = (int)$length;
390
+ $to = (int)$length;
391
+ }
392
+
393
+ if (($to < $from) || ($from < 1) || ($to < 1)) {
394
+ $from = self::DEFAULT_WORD_LENGTH_FROM;
395
+ $to = self::DEFAULT_WORD_LENGTH_TO;
396
+ }
397
+
398
+ return mt_rand($from, $to);
399
+ }
400
+
401
+ /**
402
+ * Whether to show captcha for this form every time
403
+ *
404
+ * @return bool
405
+ */
406
+ protected function _isShowAlways()
407
+ {
408
+ if ((string)$this->_getHelper()->getConfigNode('mode') == Mage_Captcha_Helper_Data::MODE_ALWAYS) {
409
+ return true;
410
+ }
411
+
412
+ $alwaysFor = $this->_getHelper()->getConfigNode('always_for');
413
+ foreach ($alwaysFor as $nodeFormId => $isAlwaysFor) {
414
+ if ($isAlwaysFor && $this->_formId == $nodeFormId) {
415
+ return true;
416
+ }
417
+ }
418
+
419
+ return false;
420
+ }
421
+
422
+ /**
423
+ * Whether captcha is enabled at this area
424
+ *
425
+ * @return bool
426
+ */
427
+ protected function _isEnabled()
428
+ {
429
+ return (string)$this->_getHelper()->getConfigNode('enable');
430
+ }
431
+
432
+ /**
433
+ * Retrieve list of forms where captcha must be shown
434
+ *
435
+ * For frontend this list is based on current website
436
+ *
437
+ * @return array
438
+ */
439
+ protected function _getTargetForms()
440
+ {
441
+ $formsString = (string) $this->_getHelper()->getConfigNode('forms');
442
+ return explode(',', $formsString);
443
+ }
444
+
445
+ /**
446
+ * Get captcha word
447
+ *
448
+ * @return string
449
+ */
450
+ public function getWord()
451
+ {
452
+ $sessionData = $this->getSession()->getData($this->_getFormIdKey(self::SESSION_WORD));
453
+ return time() < $sessionData['expires'] ? $sessionData['data'] : null;
454
+ }
455
+
456
+ /**
457
+ * Set captcha word
458
+ *
459
+ * @param string $word
460
+ * @return Zend_Captcha_Word
461
+ */
462
+ protected function _setWord($word)
463
+ {
464
+ $this->getSession()->setData($this->_getFormIdKey(self::SESSION_WORD),
465
+ array('data' => $word, 'expires' => time() + $this->getTimeout())
466
+ );
467
+ $this->_word = $word;
468
+ return $this;
469
+ }
470
+
471
+ /**
472
+ * Set captcha word
473
+ *
474
+ * @return Mage_Captcha_Model_Zend
475
+ */
476
+ protected function _clearWord()
477
+ {
478
+ $this->getSession()->unsetData($this->_getFormIdKey(self::SESSION_WORD));
479
+ $this->_word = null;
480
+ return $this;
481
+ }
482
+
483
+ /**
484
+ * Override function to generate less curly captcha that will not cut off
485
+ *
486
+ * @see Zend_Captcha_Image::_randomSize()
487
+ * @return int
488
+ */
489
+ protected function _randomSize()
490
+ {
491
+ return mt_rand(280, 300) / 100;
492
+ }
493
+
494
+ /**
495
+ * Overlap of the parent method
496
+ *
497
+ * Now deleting old captcha images make crontab script
498
+ * @see Mage_Captcha_Model_Observer::deleteExpiredImages
499
+ */
500
+ protected function _gc()
501
+ {
502
+ //do nothing
503
+ }
504
+ }
app/code/core/Mage/Captcha/controllers/Adminhtml/RefreshController.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Core
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_Adminhtml_RefreshController extends Mage_Adminhtml_Controller_Action
35
+ {
36
+ /**
37
+ * Refreshes captcha and returns JSON encoded URL to image (AJAX action)
38
+ * Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'}
39
+ *
40
+ * @return null
41
+ */
42
+ public function refreshAction()
43
+ {
44
+ $formId = $this->getRequest()->getPost('formId');
45
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
46
+ $this->getLayout()->createBlock($captchaModel->getBlockName())->setFormId($formId)->setIsAjax(true)->toHtml();
47
+ $this->getResponse()->setBody(json_encode(array('imgSrc' => $captchaModel->getImgSrc())));
48
+ $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
49
+ }
50
+ }
app/code/core/Mage/Captcha/controllers/RefreshController.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Captcha controller
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Core
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Captcha_RefreshController extends Mage_Core_Controller_Front_Action
35
+ {
36
+ /**
37
+ * Refreshes captcha and returns JSON encoded URL to image (AJAX action)
38
+ * Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'}
39
+ *
40
+ * @return null
41
+ */
42
+ public function indexAction()
43
+ {
44
+ $formId = $this->getRequest()->getPost('formId');
45
+ $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
46
+ $this->getLayout()->createBlock($captchaModel->getBlockName())->setFormId($formId)->setIsAjax(true)->toHtml();
47
+ $this->getResponse()->setBody(json_encode(array('imgSrc' => $captchaModel->getImgSrc())));
48
+ $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
49
+ }
50
+ }
app/code/core/Mage/Captcha/etc/config.xml ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Captcha
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <modules>
30
+ <Mage_Captcha>
31
+ <version>1.7.0.0.0</version>
32
+ </Mage_Captcha>
33
+ </modules>
34
+ <global>
35
+ <resources>
36
+ <captcha_setup>
37
+ <setup>
38
+ <module>Mage_Captcha</module>
39
+ </setup>
40
+ </captcha_setup>
41
+ </resources>
42
+ <models>
43
+ <captcha>
44
+ <class>Mage_Captcha_Model</class>
45
+ <resourceModel>captcha_resource</resourceModel>
46
+ </captcha>
47
+ <captcha_resource>
48
+ <class>Mage_Captcha_Model_Resource</class>
49
+ <entities>
50
+ <log>
51
+ <table>captcha_log</table>
52
+ </log>
53
+ </entities>
54
+ </captcha_resource>
55
+ </models>
56
+ <events>
57
+ <controller_action_predispatch_customer_account_loginPost>
58
+ <observers>
59
+ <captcha>
60
+ <class>captcha/observer</class>
61
+ <method>checkUserLogin</method>
62
+ </captcha>
63
+ </observers>
64
+ </controller_action_predispatch_customer_account_loginPost>
65
+ <controller_action_predispatch_customer_account_forgotpasswordpost>
66
+ <observers>
67
+ <captcha>
68
+ <class>captcha/observer</class>
69
+ <method>checkForgotPassword</method>
70
+ </captcha>
71
+ </observers>
72
+ </controller_action_predispatch_customer_account_forgotpasswordpost>
73
+ <controller_action_predispatch_customer_account_createpost>
74
+ <observers>
75
+ <captcha>
76
+ <class>captcha/observer</class>
77
+ <method>checkUserCreate</method>
78
+ </captcha>
79
+ </observers>
80
+ </controller_action_predispatch_customer_account_createpost>
81
+ <controller_action_predispatch_adminhtml_index_forgotpassword>
82
+ <observers>
83
+ <captcha>
84
+ <class>captcha/observer</class>
85
+ <method>checkUserForgotPasswordBackend</method>
86
+ </captcha>
87
+ </observers>
88
+ </controller_action_predispatch_adminhtml_index_forgotpassword>
89
+ <admin_user_authenticate_before>
90
+ <observers>
91
+ <captcha>
92
+ <class>captcha/observer</class>
93
+ <method>checkUserLoginBackend</method>
94
+ </captcha>
95
+ </observers>
96
+ </admin_user_authenticate_before>
97
+ <controller_action_predispatch_checkout_onepage_saveBilling>
98
+ <observers>
99
+ <captcha_guest>
100
+ <class>captcha/observer</class>
101
+ <method>checkGuestCheckout</method>
102
+ </captcha_guest>
103
+ <captcha_register>
104
+ <class>captcha/observer</class>
105
+ <method>checkRegisterCheckout</method>
106
+ </captcha_register>
107
+ </observers>
108
+ </controller_action_predispatch_checkout_onepage_saveBilling>
109
+ <customer_customer_authenticated>
110
+ <observers>
111
+ <captcha_reset_attempt>
112
+ <class>captcha/observer</class>
113
+ <method>resetAttemptForFrontend</method>
114
+ </captcha_reset_attempt>
115
+ </observers>
116
+ </customer_customer_authenticated>
117
+ <admin_session_user_login_success>
118
+ <observers>
119
+ <captcha_reset_attempt>
120
+ <class>captcha/observer</class>
121
+ <method>resetAttemptForBackend</method>
122
+ </captcha_reset_attempt>
123
+ </observers>
124
+ </admin_session_user_login_success>
125
+ </events>
126
+ </global>
127
+ <frontend>
128
+ <routers>
129
+ <captcha>
130
+ <use>standard</use>
131
+ <args>
132
+ <module>Mage_Captcha</module>
133
+ <frontName>captcha</frontName>
134
+ </args>
135
+ </captcha>
136
+ </routers>
137
+ <layout>
138
+ <updates>
139
+ <captcha>
140
+ <file>captcha.xml</file>
141
+ </captcha>
142
+ </updates>
143
+ </layout>
144
+ </frontend>
145
+ <admin>
146
+ <routers>
147
+ <adminhtml>
148
+ <args>
149
+ <modules>
150
+ <captcha>Mage_Captcha_Adminhtml</captcha>
151
+ </modules>
152
+ </args>
153
+ </adminhtml>
154
+ </routers>
155
+ </admin>
156
+ <adminhtml>
157
+ <layout>
158
+ <updates>
159
+ <captcha>
160
+ <file>captcha.xml</file>
161
+ </captcha>
162
+ </updates>
163
+ </layout>
164
+ </adminhtml>
165
+ <default>
166
+ <system>
167
+ <media_storage_configuration>
168
+ <allowed_resources>
169
+ <captcha_folder>captcha</captcha_folder>
170
+ </allowed_resources>
171
+ </media_storage_configuration>
172
+ </system>
173
+ <admin>
174
+ <captcha>
175
+ <type>zend</type>
176
+ <enable>0</enable>
177
+ <font>linlibertine</font>
178
+ <mode>after_fail</mode>
179
+ <forms>backend_forgotpassword</forms>
180
+ <failed_attempts_login>3</failed_attempts_login>
181
+ <failed_attempts_ip>1000</failed_attempts_ip>
182
+ <timeout>7</timeout>
183
+ <length>4-5</length>
184
+ <symbols>ABCDEFGHJKMnpqrstuvwxyz23456789</symbols>
185
+ <case_sensitive>0</case_sensitive>
186
+ <always_for>
187
+ <backend_forgotpassword>1</backend_forgotpassword>
188
+ </always_for>
189
+ </captcha>
190
+ </admin>
191
+ <customer>
192
+ <captcha>
193
+ <type>zend</type>
194
+ <enable>0</enable>
195
+ <font>linlibertine</font>
196
+ <mode>after_fail</mode>
197
+ <forms>user_forgotpassword</forms>
198
+ <failed_attempts_login>3</failed_attempts_login>
199
+ <failed_attempts_ip>1000</failed_attempts_ip>
200
+ <timeout>7</timeout>
201
+ <length>4-5</length>
202
+ <symbols>ABCDEFGHJKMnpqrstuvwxyz23456789</symbols>
203
+ <case_sensitive>0</case_sensitive>
204
+ <always_for>
205
+ <user_create>1</user_create>
206
+ <user_forgotpassword>1</user_forgotpassword>
207
+ <guest_checkout>1</guest_checkout>
208
+ <register_during_checkout>1</register_during_checkout>
209
+ </always_for>
210
+ </captcha>
211
+ </customer>
212
+ <captcha translate="label">
213
+ <fonts>
214
+ <linlibertine>
215
+ <label>LinLibertine</label>
216
+ <path>lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf</path>
217
+ </linlibertine>
218
+ </fonts>
219
+ <frontend>
220
+ <areas>
221
+ <user_create>
222
+ <label>Create user</label>
223
+ </user_create>
224
+ <user_login>
225
+ <label>Login</label>
226
+ </user_login>
227
+ <user_forgotpassword>
228
+ <label>Forgot password</label>
229
+ </user_forgotpassword>
230
+ <guest_checkout>
231
+ <label>Checkout as Guest</label>
232
+ </guest_checkout>
233
+ <register_during_checkout>
234
+ <label>Register during Checkout</label>
235
+ </register_during_checkout>
236
+ </areas>
237
+ </frontend>
238
+ <backend>
239
+ <areas>
240
+ <backend_login>
241
+ <label>Admin Login</label>
242
+ </backend_login>
243
+ <backend_forgotpassword>
244
+ <label>Admin Forgot Password</label>
245
+ </backend_forgotpassword>
246
+ </areas>
247
+ </backend>
248
+ </captcha>
249
+ </default>
250
+ <crontab>
251
+ <jobs>
252
+ <captcha_delete_old_attempts>
253
+ <schedule>
254
+ <cron_expr>*/30 * * * *</cron_expr>
255
+ </schedule>
256
+ <run>
257
+ <model>captcha/observer::deleteOldAttempts</model>
258
+ </run>
259
+ </captcha_delete_old_attempts>
260
+ <captcha_delete_expired_images>
261
+ <schedule>
262
+ <cron_expr>*/10 * * * *</cron_expr>
263
+ </schedule>
264
+ <run>
265
+ <model>captcha/observer::deleteExpiredImages</model>
266
+ </run>
267
+ </captcha_delete_expired_images>
268
+
269
+ </jobs>
270
+ </crontab>
271
+ </config>
app/code/core/Mage/Captcha/etc/system.xml ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Captcha
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
+ <config>
29
+ <sections>
30
+ <admin>
31
+ <groups>
32
+ <captcha translate="label">
33
+ <label>CAPTCHA</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>50</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ <fields>
40
+ <enable translate="label">
41
+ <label>Enable CAPTCHA in Admin</label>
42
+ <frontend_type>select</frontend_type>
43
+ <source_model>adminhtml/system_config_source_yesno</source_model>
44
+ <sort_order>1</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>0</show_in_website>
47
+ <show_in_store>0</show_in_store>
48
+ </enable>
49
+ <font translate="label">
50
+ <label>Font</label>
51
+ <frontend_type>select</frontend_type>
52
+ <source_model>captcha/config_font</source_model>
53
+ <sort_order>2</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>0</show_in_website>
56
+ <show_in_store>0</show_in_store>
57
+ <depends><enable>1</enable></depends>
58
+ </font>
59
+ <forms translate="label">
60
+ <label>Forms</label>
61
+ <frontend_type>multiselect</frontend_type>
62
+ <source_model>captcha/config_form_backend</source_model>
63
+ <sort_order>3</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>0</show_in_website>
66
+ <show_in_store>0</show_in_store>
67
+ <depends><enable>1</enable></depends>
68
+ </forms>
69
+ <mode translate="label">
70
+ <label>Displaying Mode</label>
71
+ <frontend_type>select</frontend_type>
72
+ <source_model>captcha/config_mode</source_model>
73
+ <sort_order>4</sort_order>
74
+ <show_in_default>1</show_in_default>
75
+ <show_in_website>0</show_in_website>
76
+ <show_in_store>0</show_in_store>
77
+ <depends><enable>1</enable></depends>
78
+ </mode>
79
+ <failed_attempts_login translate="label comment">
80
+ <label>Number of Unsuccessful Attempts to Login</label>
81
+ <frontend_type>text</frontend_type>
82
+ <comment>If 0 is specified, CAPTCHA on the Login form will be always available.</comment>
83
+ <sort_order>5</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>0</show_in_website>
86
+ <show_in_store>0</show_in_store>
87
+ <depends>
88
+ <mode>after_fail</mode>
89
+ <enable>1</enable>
90
+ </depends>
91
+ <frontend_class>required-entry validate-digits</frontend_class>
92
+ </failed_attempts_login>
93
+ <timeout translate="label">
94
+ <label>CAPTCHA Timeout (minutes)</label>
95
+ <frontend_type>text</frontend_type>
96
+ <sort_order>6</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>0</show_in_website>
99
+ <show_in_store>0</show_in_store>
100
+ <depends><enable>1</enable></depends>
101
+ <frontend_class>required-entry validate-digits</frontend_class>
102
+ </timeout>
103
+ <length translate="label comment">
104
+ <label>Number of Symbols</label>
105
+ <frontend_type>text</frontend_type>
106
+ <comment>Please specify 8 symbols at the most. Range allowed (e.g. 3-5)</comment>
107
+ <sort_order>7</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>0</show_in_website>
110
+ <show_in_store>0</show_in_store>
111
+ <depends><enable>1</enable></depends>
112
+ <frontend_class>required-entry</frontend_class>
113
+ </length>
114
+ <symbols translate="label comment">
115
+ <label>Symbols Used in CAPTCHA</label>
116
+ <frontend_type>text</frontend_type>
117
+ <comment><![CDATA[Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.<br />Similar looking characters (e.g. "i", "l", "1") decrease chance of correct recognition by customer.]]></comment>
118
+ <sort_order>8</sort_order>
119
+ <show_in_default>1</show_in_default>
120
+ <show_in_website>0</show_in_website>
121
+ <show_in_store>0</show_in_store>
122
+ <depends><enable>1</enable></depends>
123
+ <frontend_class>required-entry validate-alphanum</frontend_class>
124
+ </symbols>
125
+ <case_sensitive translate="label">
126
+ <label>Case Sensitive</label>
127
+ <frontend_type>select</frontend_type>
128
+ <source_model>adminhtml/system_config_source_yesno</source_model>
129
+ <sort_order>9</sort_order>
130
+ <show_in_default>1</show_in_default>
131
+ <show_in_website>0</show_in_website>
132
+ <show_in_store>0</show_in_store>
133
+ <depends><enable>1</enable></depends>
134
+ </case_sensitive>
135
+ </fields>
136
+ </captcha>
137
+ </groups>
138
+ </admin>
139
+ <customer>
140
+ <groups>
141
+ <captcha translate="label">
142
+ <label>CAPTCHA</label>
143
+ <frontend_type>text</frontend_type>
144
+ <sort_order>110</sort_order>
145
+ <show_in_default>1</show_in_default>
146
+ <show_in_website>1</show_in_website>
147
+ <show_in_store>0</show_in_store>
148
+ <fields>
149
+ <enable translate="label">
150
+ <label>Enable CAPTCHA on Frontend</label>
151
+ <frontend_type>select</frontend_type>
152
+ <source_model>adminhtml/system_config_source_yesno</source_model>
153
+ <sort_order>1</sort_order>
154
+ <show_in_default>1</show_in_default>
155
+ <show_in_website>1</show_in_website>
156
+ <show_in_store>0</show_in_store>
157
+ </enable>
158
+ <font translate="label">
159
+ <label>Font</label>
160
+ <frontend_type>select</frontend_type>
161
+ <source_model>captcha/config_font</source_model>
162
+ <sort_order>2</sort_order>
163
+ <show_in_default>1</show_in_default>
164
+ <show_in_website>1</show_in_website>
165
+ <show_in_store>0</show_in_store>
166
+ <depends><enable>1</enable></depends>
167
+ </font>
168
+ <forms translate="label comment">
169
+ <label>Forms</label>
170
+ <frontend_type>multiselect</frontend_type>
171
+ <source_model>captcha/config_form_frontend</source_model>
172
+ <comment>CAPTCHA for "Create user" and "Forgot password" forms is always enabled if chosen</comment>
173
+ <sort_order>3</sort_order>
174
+ <show_in_default>1</show_in_default>
175
+ <show_in_website>1</show_in_website>
176
+ <show_in_store>0</show_in_store>
177
+ <depends><enable>1</enable></depends>
178
+ </forms>
179
+ <mode translate="label">
180
+ <label>Displaying Mode</label>
181
+ <frontend_type>select</frontend_type>
182
+ <source_model>captcha/config_mode</source_model>
183
+ <sort_order>4</sort_order>
184
+ <show_in_default>1</show_in_default>
185
+ <show_in_website>1</show_in_website>
186
+ <show_in_store>0</show_in_store>
187
+ <depends><enable>1</enable></depends>
188
+ </mode>
189
+ <failed_attempts_login translate="label comment">
190
+ <label>Number of Unsuccessful Attempts to Login</label>
191
+ <frontend_type>text</frontend_type>
192
+ <comment>If 0 is specified, CAPTCHA on the Login form will be always available.</comment>
193
+ <sort_order>5</sort_order>
194
+ <show_in_default>1</show_in_default>
195
+ <show_in_website>1</show_in_website>
196
+ <show_in_store>0</show_in_store>
197
+ <depends>
198
+ <enable>1</enable>
199
+ <mode>after_fail</mode>
200
+ </depends>
201
+ <frontend_class>required-entry validate-digits</frontend_class>
202
+ </failed_attempts_login>
203
+ <timeout translate="label">
204
+ <label>CAPTCHA Timeout (minutes)</label>
205
+ <frontend_type>text</frontend_type>
206
+ <sort_order>6</sort_order>
207
+ <show_in_default>1</show_in_default>
208
+ <show_in_website>1</show_in_website>
209
+ <show_in_store>0</show_in_store>
210
+ <depends><enable>1</enable></depends>
211
+ <frontend_class>required-entry validate-digits</frontend_class>
212
+ </timeout>
213
+ <length translate="label comment">
214
+ <label>Number of Symbols</label>
215
+ <frontend_type>text</frontend_type>
216
+ <comment>Please specify 8 symbols at the most. Range allowed (e.g. 3-5)</comment>
217
+ <sort_order>7</sort_order>
218
+ <show_in_default>1</show_in_default>
219
+ <show_in_website>1</show_in_website>
220
+ <show_in_store>0</show_in_store>
221
+ <depends><enable>1</enable></depends>
222
+ <frontend_class>required-entry</frontend_class>
223
+ </length>
224
+ <symbols translate="label comment">
225
+ <label>Symbols Used in CAPTCHA</label>
226
+ <frontend_type>text</frontend_type>
227
+ <comment><![CDATA[Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.<br />Similar looking characters (e.g. "i", "l", "1") decrease chance of correct recognition by customer.]]></comment>
228
+ <sort_order>8</sort_order>
229
+ <show_in_default>1</show_in_default>
230
+ <show_in_website>1</show_in_website>
231
+ <show_in_store>0</show_in_store>
232
+ <depends><enable>1</enable></depends>
233
+ <frontend_class>required-entry validate-alphanum</frontend_class>
234
+ </symbols>
235
+ <case_sensitive translate="label">
236
+ <label>Case Sensitive</label>
237
+ <frontend_type>select</frontend_type>
238
+ <source_model>adminhtml/system_config_source_yesno</source_model>
239
+ <sort_order>9</sort_order>
240
+ <show_in_default>1</show_in_default>
241
+ <show_in_website>1</show_in_website>
242
+ <show_in_store>0</show_in_store>
243
+ <depends><enable>1</enable></depends>
244
+ </case_sensitive>
245
+ </fields>
246
+ </captcha>
247
+ </groups>
248
+ </customer>
249
+ </sections>
250
+ </config>
app/code/core/Mage/Captcha/sql/captcha_setup/install-1.7.0.0.0.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Captcha
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+ /* @var $installer Mage_Core_Model_Resource_Setup */
27
+ $installer = $this;
28
+
29
+ $installer->startSetup();
30
+
31
+ $table = $installer->getConnection()
32
+ ->newTable($installer->getTable('captcha/log'))
33
+ ->addColumn('type', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array(
34
+ 'nullable' => false,
35
+ 'primary' => true,
36
+ ), 'Type')
37
+ ->addColumn('value', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array(
38
+ 'nullable' => false,
39
+ 'unsigned' => true,
40
+ 'primary' => true,
41
+ ), 'Value')
42
+ ->addColumn('count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
43
+ 'unsigned' => true,
44
+ 'nullable' => false,
45
+ 'default' => '0',
46
+ ), 'Count')
47
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(), 'Update Time')
48
+ ->setComment('Count Login Attempts');
49
+ $installer->getConnection()->createTable($table);
50
+
51
+ $installer->endSetup();
app/code/core/Mage/Catalog/Block/Breadcrumbs.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Category/View.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Category/Widget/Link.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -47,6 +47,12 @@ abstract class Mage_Catalog_Block_Layer_Filter_Abstract extends Mage_Core_Block_
47
  */
48
  protected $_filterModelName;
49
 
 
 
 
 
 
 
50
  /**
51
  * Initialize filter template
52
  *
@@ -126,6 +132,18 @@ abstract class Mage_Catalog_Block_Layer_Filter_Abstract extends Mage_Core_Block_
126
  return $this->_filter->getItemsCount();
127
  }
128
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  /**
130
  * Retrieve block html
131
  *
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
47
  */
48
  protected $_filterModelName;
49
 
50
+ /**
51
+ * Whether to display product count for layer navigation items
52
+ * @var bool
53
+ */
54
+ protected $_displayProductCount = null;
55
+
56
  /**
57
  * Initialize filter template
58
  *
132
  return $this->_filter->getItemsCount();
133
  }
134
 
135
+ /**
136
+ * Getter for $_displayProductCount
137
+ * @return bool
138
+ */
139
+ public function shouldDisplayProductCount()
140
+ {
141
+ if ($this->_displayProductCount === null) {
142
+ $this->_displayProductCount = Mage::helper('catalog')->shouldDisplayProductCountOnLayer();
143
+ }
144
+ return $this->_displayProductCount;
145
+ }
146
+
147
  /**
148
  * Retrieve block html
149
  *
app/code/core/Mage/Catalog/Block/Layer/Filter/Attribute.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Layer/Filter/Category.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Layer/Filter/Decimal.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Layer/Filter/Price.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Layer/State.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Layer/View.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -242,4 +242,14 @@ class Mage_Catalog_Block_Layer_View extends Mage_Core_Block_Template
242
  {
243
  return $this->getChild('_price_filter');
244
  }
 
 
 
 
 
 
 
 
 
 
245
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
242
  {
243
  return $this->getChild('_price_filter');
244
  }
245
+
246
+ /**
247
+ * Get url for 'Clear All' link
248
+ *
249
+ * @return string
250
+ */
251
+ public function getClearUrl()
252
+ {
253
+ return $this->getChild('layer_state')->getClearUrl();
254
+ }
255
  }
app/code/core/Mage/Catalog/Block/Navigation.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -262,6 +262,7 @@ abstract class Mage_Catalog_Block_Product_Abstract extends Mage_Core_Block_Templ
262
  *
263
  * @param string $type
264
  * @param string $template
 
265
  */
266
  public function addReviewSummaryTemplate($type, $template)
267
  {
@@ -312,9 +313,10 @@ abstract class Mage_Catalog_Block_Product_Abstract extends Mage_Core_Block_Templ
312
  return $this->getData('tier_price_template');
313
  }
314
  /**
315
- * Returns product tierprice block html
316
  *
317
  * @param Mage_Catalog_Model_Product $product
 
318
  */
319
  public function getTierPriceHtml($product = null)
320
  {
@@ -344,12 +346,19 @@ abstract class Mage_Catalog_Block_Product_Abstract extends Mage_Core_Block_Templ
344
  $res = array();
345
  if (is_array($prices)) {
346
  foreach ($prices as $price) {
347
- $price['price_qty'] = $price['price_qty']*1;
348
- if ($product->getPrice() != $product->getFinalPrice()) {
 
 
349
  $_productPrice = $product->getFinalPrice();
350
- } else {
351
- $_productPrice = $product->getPrice();
352
  }
 
 
 
 
 
 
 
353
  if ($price['price'] < $_productPrice) {
354
  $price['savePercent'] = ceil(100 - ((100 / $_productPrice) * $price['price']));
355
 
@@ -389,8 +398,8 @@ abstract class Mage_Catalog_Block_Product_Abstract extends Mage_Core_Block_Templ
389
  * to get correct values in different products lists.
390
  * E.g. crosssells, upsells, new products, recently viewed
391
  *
392
- * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
393
- * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
394
  */
395
  protected function _addProductAttributesAndPrices(Mage_Catalog_Model_Resource_Product_Collection $collection)
396
  {
@@ -489,7 +498,7 @@ abstract class Mage_Catalog_Block_Product_Abstract extends Mage_Core_Block_Templ
489
  * Add row size depends on page layout
490
  *
491
  * @param string $pageLayout
492
- * @param int $rowSize
493
  * @return Mage_Catalog_Block_Product_List
494
  */
495
  public function addColumnCountLayoutDepend($pageLayout, $columnCount)
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
262
  *
263
  * @param string $type
264
  * @param string $template
265
+ * @return string
266
  */
267
  public function addReviewSummaryTemplate($type, $template)
268
  {
313
  return $this->getData('tier_price_template');
314
  }
315
  /**
316
+ * Returns product tier price block html
317
  *
318
  * @param Mage_Catalog_Model_Product $product
319
+ * @return string
320
  */
321
  public function getTierPriceHtml($product = null)
322
  {
346
  $res = array();
347
  if (is_array($prices)) {
348
  foreach ($prices as $price) {
349
+ $price['price_qty'] = $price['price_qty'] * 1;
350
+
351
+ $_productPrice = $product->getPrice();
352
+ if ($_productPrice != $product->getFinalPrice()) {
353
  $_productPrice = $product->getFinalPrice();
 
 
354
  }
355
+
356
+ // Group price must be used for percent calculation if it is lower
357
+ $groupPrice = $product->getGroupPrice();
358
+ if ($_productPrice > $groupPrice) {
359
+ $_productPrice = $groupPrice;
360
+ }
361
+
362
  if ($price['price'] < $_productPrice) {
363
  $price['savePercent'] = ceil(100 - ((100 / $_productPrice) * $price['price']));
364
 
398
  * to get correct values in different products lists.
399
  * E.g. crosssells, upsells, new products, recently viewed
400
  *
401
+ * @param Mage_Catalog_Model_Resource_Product_Collection $collection
402
+ * @return Mage_Catalog_Model_Resource_Product_Collection
403
  */
404
  protected function _addProductAttributesAndPrices(Mage_Catalog_Model_Resource_Product_Collection $collection)
405
  {
498
  * Add row size depends on page layout
499
  *
500
  * @param string $pageLayout
501
+ * @param int $columnCount
502
  * @return Mage_Catalog_Block_Product_List
503
  */
504
  public function addColumnCountLayoutDepend($pageLayout, $columnCount)
app/code/core/Mage/Catalog/Block/Product/Compare/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/Compare/List.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/Compare/Sidebar.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/Gallery.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/List.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/List/Crosssell.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -61,7 +61,7 @@ class Mage_Catalog_Block_Product_List_Crosssell extends Mage_Catalog_Block_Produ
61
 
62
  $this->_itemCollection = $product->getCrossSellProductCollection()
63
  ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
64
- ->addAttributeToSort('position', 'asc')
65
  ->addStoreFilter();
66
 
67
  // Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection);
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
61
 
62
  $this->_itemCollection = $product->getCrossSellProductCollection()
63
  ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
64
+ ->setPositionOrder()
65
  ->addStoreFilter();
66
 
67
  // Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection);
app/code/core/Mage/Catalog/Block/Product/List/Promotion.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
  class Mage_Catalog_Block_Product_List_Promotion extends Mage_Catalog_Block_Product_List
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
  class Mage_Catalog_Block_Product_List_Promotion extends Mage_Catalog_Block_Product_List
app/code/core/Mage/Catalog/Block/Product/List/Random.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/List/Related.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -50,7 +50,7 @@ class Mage_Catalog_Block_Product_List_Related extends Mage_Catalog_Block_Product
50
 
51
  $this->_itemCollection = $product->getRelatedProductCollection()
52
  ->addAttributeToSelect('required_options')
53
- ->addAttributeToSort('position', Varien_Db_Select::SQL_ASC)
54
  ->addStoreFilter()
55
  ;
56
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
50
 
51
  $this->_itemCollection = $product->getRelatedProductCollection()
52
  ->addAttributeToSelect('required_options')
53
+ ->setPositionOrder()
54
  ->addStoreFilter()
55
  ;
56
 
app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/List/Upsell.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -54,7 +54,7 @@ class Mage_Catalog_Block_Product_List_Upsell extends Mage_Catalog_Block_Product_
54
  $product = Mage::registry('product');
55
  /* @var $product Mage_Catalog_Model_Product */
56
  $this->_itemCollection = $product->getUpSellProductCollection()
57
- ->addAttributeToSort('position', Varien_Db_Select::SQL_ASC)
58
  ->addStoreFilter()
59
  ;
60
  if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
54
  $product = Mage::registry('product');
55
  /* @var $product Mage_Catalog_Model_Product */
56
  $this->_itemCollection = $product->getUpSellProductCollection()
57
+ ->setPositionOrder()
58
  ->addStoreFilter()
59
  ;
60
  if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
app/code/core/Mage/Catalog/Block/Product/New.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -81,19 +81,26 @@ class Mage_Catalog_Block_Product_New extends Mage_Catalog_Block_Product_Abstract
81
  */
82
  protected function _beforeToHtml()
83
  {
84
- $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
 
 
 
 
 
 
85
 
86
  $collection = Mage::getResourceModel('catalog/product_collection');
87
  $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
88
 
 
89
  $collection = $this->_addProductAttributesAndPrices($collection)
90
  ->addStoreFilter()
91
  ->addAttributeToFilter('news_from_date', array('or'=> array(
92
- 0 => array('date' => true, 'to' => $todayDate),
93
  1 => array('is' => new Zend_Db_Expr('null')))
94
  ), 'left')
95
  ->addAttributeToFilter('news_to_date', array('or'=> array(
96
- 0 => array('date' => true, 'from' => $todayDate),
97
  1 => array('is' => new Zend_Db_Expr('null')))
98
  ), 'left')
99
  ->addAttributeToFilter(
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
81
  */
82
  protected function _beforeToHtml()
83
  {
84
+ $todayStartOfDayDate = Mage::app()->getLocale()->date()
85
+ ->setTime('00:00:00')
86
+ ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
87
+
88
+ $todayEndOfDayDate = Mage::app()->getLocale()->date()
89
+ ->setTime('23:59:59')
90
+ ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
91
 
92
  $collection = Mage::getResourceModel('catalog/product_collection');
93
  $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
94
 
95
+
96
  $collection = $this->_addProductAttributesAndPrices($collection)
97
  ->addStoreFilter()
98
  ->addAttributeToFilter('news_from_date', array('or'=> array(
99
+ 0 => array('date' => true, 'to' => $todayEndOfDayDate),
100
  1 => array('is' => new Zend_Db_Expr('null')))
101
  ), 'left')
102
  ->addAttributeToFilter('news_to_date', array('or'=> array(
103
+ 0 => array('date' => true, 'from' => $todayStartOfDayDate),
104
  1 => array('is' => new Zend_Db_Expr('null')))
105
  ), 'left')
106
  ->addAttributeToFilter(
app/code/core/Mage/Catalog/Block/Product/Price.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -36,6 +36,11 @@ class Mage_Catalog_Block_Product_Price extends Mage_Core_Block_Template
36
  protected $_priceDisplayType = null;
37
  protected $_idSuffix = '';
38
 
 
 
 
 
 
39
  public function getProduct()
40
  {
41
  $product = $this->_getData('product');
@@ -72,21 +77,26 @@ class Mage_Catalog_Block_Product_Price extends Mage_Core_Block_Template
72
  if (is_null($product)) {
73
  $product = $this->getProduct();
74
  }
75
- $prices = $product->getFormatedTierPrice();
76
 
77
  $res = array();
78
  if (is_array($prices)) {
79
  foreach ($prices as $price) {
80
- $price['price_qty'] = $price['price_qty']*1;
81
 
 
82
  if ($product->getPrice() != $product->getFinalPrice()) {
83
  $productPrice = $product->getFinalPrice();
84
- } else {
85
- $productPrice = $product->getPrice();
86
  }
87
 
88
- if ($price['price']<$productPrice) {
89
- $price['savePercent'] = ceil(100 - (( 100/$productPrice ) * $price['price'] ));
 
 
 
 
 
 
90
 
91
  $tierPrice = Mage::app()->getStore()->convertPrice(
92
  Mage::helper('tax')->getPrice($product, $price['website_price'])
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
36
  protected $_priceDisplayType = null;
37
  protected $_idSuffix = '';
38
 
39
+ /**
40
+ * Retrieve product
41
+ *
42
+ * @return Mage_Catalog_Model_Product
43
+ */
44
  public function getProduct()
45
  {
46
  $product = $this->_getData('product');
77
  if (is_null($product)) {
78
  $product = $this->getProduct();
79
  }
80
+ $prices = $product->getFormatedTierPrice();
81
 
82
  $res = array();
83
  if (is_array($prices)) {
84
  foreach ($prices as $price) {
85
+ $price['price_qty'] = $price['price_qty'] * 1;
86
 
87
+ $productPrice = $product->getPrice();
88
  if ($product->getPrice() != $product->getFinalPrice()) {
89
  $productPrice = $product->getFinalPrice();
 
 
90
  }
91
 
92
+ // Group price must be used for percent calculation if it is lower
93
+ $groupPrice = $product->getGroupPrice();
94
+ if ($productPrice > $groupPrice) {
95
+ $productPrice = $groupPrice;
96
+ }
97
+
98
+ if ($price['price'] < $productPrice) {
99
+ $price['savePercent'] = ceil(100 - ((100 / $productPrice) * $price['price']));
100
 
101
  $tierPrice = Mage::app()->getStore()->convertPrice(
102
  Mage::helper('tax')->getPrice($product, $price['website_price'])
app/code/core/Mage/Catalog/Block/Product/Price/Template.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/Send.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -28,9 +28,10 @@
28
  /**
29
  * Product View block
30
  *
31
- * @category Mage
32
- * @package Mage_Catalog
33
- * @module Catalog
 
34
  */
35
  class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstract
36
  {
@@ -121,14 +122,14 @@ class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstrac
121
  }
122
 
123
  $addUrlKey = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
124
- $addUrlValue = Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => false));
125
  $additional[$addUrlKey] = Mage::helper('core')->urlEncode($addUrlValue);
126
 
127
  return $this->helper('checkout/cart')->getAddUrl($product, $additional);
128
  }
129
 
130
  /**
131
- * Get JSON encripted configuration array which can be used for JS dynamic
132
  * price calculation depending on product options
133
  *
134
  * @return string
@@ -141,20 +142,29 @@ class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstrac
141
  }
142
 
143
  $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
144
- $_request->setProductClassId($this->getProduct()->getTaxClassId());
 
 
145
  $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request);
146
 
147
  $_request = Mage::getSingleton('tax/calculation')->getRateRequest();
148
- $_request->setProductClassId($this->getProduct()->getTaxClassId());
149
  $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request);
150
 
151
- $_regularPrice = $this->getProduct()->getPrice();
152
- $_finalPrice = $this->getProduct()->getFinalPrice();
153
- $_priceInclTax = Mage::helper('tax')->getPrice($this->getProduct(), $_finalPrice, true);
154
- $_priceExclTax = Mage::helper('tax')->getPrice($this->getProduct(), $_finalPrice);
155
-
 
 
 
 
 
 
 
156
  $config = array(
157
- 'productId' => $this->getProduct()->getId(),
158
  'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(),
159
  'includeTax' => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
160
  'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(),
@@ -173,8 +183,11 @@ class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstrac
173
  'idSuffix' => '_clone',
174
  'oldPlusDisposition' => 0,
175
  'plusDisposition' => 0,
 
176
  'oldMinusDisposition' => 0,
177
  'minusDisposition' => 0,
 
 
178
  );
179
 
180
  $responseObject = new Varien_Object();
@@ -228,8 +241,7 @@ class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstrac
228
  * Get default qty - either as preconfigured, or as 1.
229
  * Also restricts it by minimal qty.
230
  *
231
- * @param null|Mage_Catalog_Model_Product
232
- *
233
  * @return int|float
234
  */
235
  public function getProductDefaultQty($product = null)
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
28
  /**
29
  * Product View block
30
  *
31
+ * @category Mage
32
+ * @package Mage_Catalog
33
+ * @module Catalog
34
+ * @author Magento Core Team <core@magentocommerce.com>
35
  */
36
  class Mage_Catalog_Block_Product_View extends Mage_Catalog_Block_Product_Abstract
37
  {
122
  }
123
 
124
  $addUrlKey = Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED;
125
+ $addUrlValue = Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true));
126
  $additional[$addUrlKey] = Mage::helper('core')->urlEncode($addUrlValue);
127
 
128
  return $this->helper('checkout/cart')->getAddUrl($product, $additional);
129
  }
130
 
131
  /**
132
+ * Get JSON encoded configuration array which can be used for JS dynamic
133
  * price calculation depending on product options
134
  *
135
  * @return string
142
  }
143
 
144
  $_request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
145
+ /* @var $product Mage_Catalog_Model_Product */
146
+ $product = $this->getProduct();
147
+ $_request->setProductClassId($product->getTaxClassId());
148
  $defaultTax = Mage::getSingleton('tax/calculation')->getRate($_request);
149
 
150
  $_request = Mage::getSingleton('tax/calculation')->getRateRequest();
151
+ $_request->setProductClassId($product->getTaxClassId());
152
  $currentTax = Mage::getSingleton('tax/calculation')->getRate($_request);
153
 
154
+ $_regularPrice = $product->getPrice();
155
+ $_finalPrice = $product->getFinalPrice();
156
+ $_priceInclTax = Mage::helper('tax')->getPrice($product, $_finalPrice, true);
157
+ $_priceExclTax = Mage::helper('tax')->getPrice($product, $_finalPrice);
158
+ $_tierPrices = array();
159
+ $_tierPricesInclTax = array();
160
+ foreach ($product->getTierPrice() as $tierPrice) {
161
+ $_tierPrices[] = Mage::helper('core')->currency($tierPrice['website_price'], false, false);
162
+ $_tierPricesInclTax[] = Mage::helper('core')->currency(
163
+ Mage::helper('tax')->getPrice($product, (int)$tierPrice['website_price'], true),
164
+ false, false);
165
+ }
166
  $config = array(
167
+ 'productId' => $product->getId(),
168
  'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(),
169
  'includeTax' => Mage::helper('tax')->priceIncludesTax() ? 'true' : 'false',
170
  'showIncludeTax' => Mage::helper('tax')->displayPriceIncludingTax(),
183
  'idSuffix' => '_clone',
184
  'oldPlusDisposition' => 0,
185
  'plusDisposition' => 0,
186
+ 'plusDispositionTax' => 0,
187
  'oldMinusDisposition' => 0,
188
  'minusDisposition' => 0,
189
+ 'tierPrices' => $_tierPrices,
190
+ 'tierPricesInclTax' => $_tierPricesInclTax,
191
  );
192
 
193
  $responseObject = new Varien_Object();
241
  * Get default qty - either as preconfigured, or as 1.
242
  * Also restricts it by minimal qty.
243
  *
244
+ * @param null|Mage_Catalog_Model_Product $product
 
245
  * @return int|float
246
  */
247
  public function getProductDefaultQty($product = null)
app/code/core/Mage/Catalog/Block/Product/View/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Additional.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Attributes.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Description.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Media.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -29,12 +29,22 @@
29
  *
30
  * @category Mage
31
  * @package Mage_Catalog
32
- * @author Magento Core Team <core@magentocommerce.com>
33
  */
34
  class Mage_Catalog_Block_Product_View_Media extends Mage_Catalog_Block_Product_View_Abstract
35
  {
 
 
 
 
 
36
  protected $_isGalleryDisabled;
37
 
 
 
 
 
 
38
  public function getGalleryImages()
39
  {
40
  if ($this->_isGalleryDisabled) {
@@ -44,16 +54,24 @@ class Mage_Catalog_Block_Product_View_Media extends Mage_Catalog_Block_Product_V
44
  return $collection;
45
  }
46
 
47
- public function getGalleryUrl($image=null)
 
 
 
 
 
 
48
  {
49
- $params = array('id'=>$this->getProduct()->getId());
50
  if ($image) {
51
  $params['image'] = $image->getValueId();
52
- return $this->getUrl('*/*/gallery', $params);
53
  }
54
- return $this->getUrl('*/*/gallery', $params);
55
  }
56
 
 
 
 
57
  public function disableGallery()
58
  {
59
  $this->_isGalleryDisabled = true;
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
29
  *
30
  * @category Mage
31
  * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
  */
34
  class Mage_Catalog_Block_Product_View_Media extends Mage_Catalog_Block_Product_View_Abstract
35
  {
36
+ /**
37
+ * Flag, that defines whether gallery is disabled
38
+ *
39
+ * @var boolean
40
+ */
41
  protected $_isGalleryDisabled;
42
 
43
+ /**
44
+ * Retrieve list of gallery images
45
+ *
46
+ * @return array|Varien_Data_Collection
47
+ */
48
  public function getGalleryImages()
49
  {
50
  if ($this->_isGalleryDisabled) {
54
  return $collection;
55
  }
56
 
57
+ /**
58
+ * Retrieve gallery url
59
+ *
60
+ * @param null|Varien_Object $image
61
+ * @return string
62
+ */
63
+ public function getGalleryUrl($image = null)
64
  {
65
+ $params = array('id' => $this->getProduct()->getId());
66
  if ($image) {
67
  $params['image'] = $image->getValueId();
 
68
  }
69
+ return $this->getUrl('catalog/product/gallery', $params);
70
  }
71
 
72
+ /**
73
+ * Disable gallery
74
+ */
75
  public function disableGallery()
76
  {
77
  $this->_isGalleryDisabled = true;
app/code/core/Mage/Catalog/Block/Product/View/Options.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -135,6 +135,29 @@ class Mage_Catalog_Block_Product_View_Options extends Mage_Core_Block_Template
135
  return false;
136
  }
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  public function getJsonConfig()
139
  {
140
  $config = array();
@@ -146,11 +169,12 @@ class Mage_Catalog_Block_Product_View_Options extends Mage_Core_Block_Template
146
  $_tmpPriceValues = array();
147
  foreach ($option->getValues() as $value) {
148
  /* @var $value Mage_Catalog_Model_Product_Option_Value */
149
- $_tmpPriceValues[$value->getId()] = Mage::helper('core')->currency($value->getPrice(true), false, false);
 
150
  }
151
  $priceValue = $_tmpPriceValues;
152
  } else {
153
- $priceValue = Mage::helper('core')->currency($option->getPrice(true), false, false);
154
  }
155
  $config[$option->getId()] = $priceValue;
156
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
135
  return false;
136
  }
137
 
138
+ /**
139
+ * Get price configuration
140
+ *
141
+ * @param Mage_Catalog_Model_Product_Option_Value|Mage_Catalog_Model_Product_Option $option
142
+ * @return array
143
+ */
144
+ protected function _getPriceConfiguration($option)
145
+ {
146
+ $data = array();
147
+ $data['price'] = Mage::helper('core')->currency($option->getPrice(true), false, false);
148
+ $data['oldPrice'] = Mage::helper('core')->currency($option->getPrice(false), false, false);
149
+ $data['priceValue'] = $option->getPrice(false);
150
+ $data['type'] = $option->getPriceType();
151
+ $data['excludeTax'] = $price = Mage::helper('tax')->getPrice($option->getProduct(), $data['price'], false);
152
+ $data['includeTax'] = $price = Mage::helper('tax')->getPrice($option->getProduct(), $data['price'], true);
153
+ return $data;
154
+ }
155
+
156
+ /**
157
+ * Get json representation of
158
+ *
159
+ * @return string
160
+ */
161
  public function getJsonConfig()
162
  {
163
  $config = array();
169
  $_tmpPriceValues = array();
170
  foreach ($option->getValues() as $value) {
171
  /* @var $value Mage_Catalog_Model_Product_Option_Value */
172
+ $id = $value->getId();
173
+ $_tmpPriceValues[$id] = $this->_getPriceConfiguration($value);
174
  }
175
  $priceValue = $_tmpPriceValues;
176
  } else {
177
+ $priceValue = $this->_getPriceConfiguration($option);
178
  }
179
  $config[$option->getId()] = $priceValue;
180
  }
app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -96,8 +96,8 @@ abstract class Mage_Catalog_Block_Product_View_Options_Abstract extends Mage_Cor
96
  {
97
  if ($option = $this->getOption()) {
98
  return $this->_formatPrice(array(
99
- 'is_percent' => ($option->getPriceType() == 'percent') ? true : false,
100
- 'pricing_value' => $option->getPrice(true)
101
  ));
102
  }
103
  return '';
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
96
  {
97
  if ($option = $this->getOption()) {
98
  return $this->_formatPrice(array(
99
+ 'is_percent' => ($option->getPriceType() == 'percent'),
100
+ 'pricing_value' => $option->getPrice($option->getPriceType() == 'percent')
101
  ));
102
  }
103
  return '';
app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Date.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Default.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Options/Type/File.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -64,8 +64,8 @@ class Mage_Catalog_Block_Product_View_Options_Type_Select
64
  }
65
  foreach ($_option->getValues() as $_value) {
66
  $priceStr = $this->_formatPrice(array(
67
- 'is_percent' => ($_value->getPriceType() == 'percent') ? true : false,
68
- 'pricing_value' => $_value->getPrice(true)
69
  ), false);
70
  $select->addOption(
71
  $_value->getOptionTypeId(),
@@ -99,7 +99,11 @@ class Mage_Catalog_Block_Product_View_Options_Type_Select
99
  $type = 'radio';
100
  $class = 'radio';
101
  if (!$_option->getIsRequire()) {
102
- $selectHtml .= '<li><input type="radio" id="options_'.$_option->getId().'" class="'.$class.' product-custom-option" name="options['.$_option->getId().']"' . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') . ' value="" checked="checked" /><span class="label"><label for="options_'.$_option->getId().'">' . $this->__('None') . '</label></span></li>';
 
 
 
 
103
  }
104
  break;
105
  case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX:
@@ -113,8 +117,8 @@ class Mage_Catalog_Block_Product_View_Options_Type_Select
113
  $count++;
114
 
115
  $priceStr = $this->_formatPrice(array(
116
- 'is_percent' => ($_value->getPriceType() == 'percent') ? true : false,
117
- 'pricing_value' => $_value->getPrice(true)
118
  ));
119
 
120
  $htmlValue = $_value->getOptionTypeId();
@@ -124,14 +128,19 @@ class Mage_Catalog_Block_Product_View_Options_Type_Select
124
  $checked = $configValue == $htmlValue ? 'checked' : '';
125
  }
126
 
127
- $selectHtml .= '<li>' .
128
- '<input type="'.$type.'" class="'.$class.' '.$require.' product-custom-option"' . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') . ' name="options['.$_option->getId().']'.$arraySign.'" id="options_'.$_option->getId().'_'.$count.'" value="' . $htmlValue . '" ' . $checked . ' price="' . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />' .
129
- '<span class="label"><label for="options_'.$_option->getId().'_'.$count.'">'.$_value->getTitle().' '.$priceStr.'</label></span>';
 
 
 
 
 
130
  if ($_option->getIsRequire()) {
131
- $selectHtml .= '<script type="text/javascript">' .
132
- '$(\'options_'.$_option->getId().'_'.$count.'\').advaiceContainer = \'options-'.$_option->getId().'-container\';' .
133
- '$(\'options_'.$_option->getId().'_'.$count.'\').callbackFunction = \'validateOptionsCallback\';' .
134
- '</script>';
135
  }
136
  $selectHtml .= '</li>';
137
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
64
  }
65
  foreach ($_option->getValues() as $_value) {
66
  $priceStr = $this->_formatPrice(array(
67
+ 'is_percent' => ($_value->getPriceType() == 'percent'),
68
+ 'pricing_value' => $_value->getPrice(($_value->getPriceType() == 'percent'))
69
  ), false);
70
  $select->addOption(
71
  $_value->getOptionTypeId(),
99
  $type = 'radio';
100
  $class = 'radio';
101
  if (!$_option->getIsRequire()) {
102
+ $selectHtml .= '<li><input type="radio" id="options_' . $_option->getId() . '" class="'
103
+ . $class . ' product-custom-option" name="options[' . $_option->getId() . ']"'
104
+ . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
105
+ . ' value="" checked="checked" /><span class="label"><label for="options_'
106
+ . $_option->getId() . '">' . $this->__('None') . '</label></span></li>';
107
  }
108
  break;
109
  case Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX:
117
  $count++;
118
 
119
  $priceStr = $this->_formatPrice(array(
120
+ 'is_percent' => ($_value->getPriceType() == 'percent'),
121
+ 'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent')
122
  ));
123
 
124
  $htmlValue = $_value->getOptionTypeId();
128
  $checked = $configValue == $htmlValue ? 'checked' : '';
129
  }
130
 
131
+ $selectHtml .= '<li>' . '<input type="' . $type . '" class="' . $class . ' ' . $require
132
+ . ' product-custom-option"'
133
+ . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
134
+ . ' name="options[' . $_option->getId() . ']' . $arraySign . '" id="options_' . $_option->getId()
135
+ . '_' . $count . '" value="' . $htmlValue . '" ' . $checked . ' price="'
136
+ . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />'
137
+ . '<span class="label"><label for="options_' . $_option->getId() . '_' . $count . '">'
138
+ . $_value->getTitle() . ' ' . $priceStr . '</label></span>';
139
  if ($_option->getIsRequire()) {
140
+ $selectHtml .= '<script type="text/javascript">' . '$(\'options_' . $_option->getId() . '_'
141
+ . $count . '\').advaiceContainer = \'options-' . $_option->getId() . '-container\';'
142
+ . '$(\'options_' . $_option->getId() . '_' . $count
143
+ . '\').callbackFunction = \'validateOptionsCallback\';' . '</script>';
144
  }
145
  $selectHtml .= '</li>';
146
  }
app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Text.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Price.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Tabs.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -34,20 +34,41 @@
34
  */
35
  class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Block_Product_View_Abstract
36
  {
 
 
 
 
 
37
  protected $_prices = array();
 
 
 
 
 
 
38
  protected $_resPrices = array();
39
 
 
 
 
 
 
40
  public function getAllowAttributes()
41
  {
42
  return $this->getProduct()->getTypeInstance(true)
43
  ->getConfigurableAttributes($this->getProduct());
44
  }
45
 
 
 
 
 
 
46
  public function hasOptions()
47
  {
48
  $attributes = $this->getAllowAttributes();
49
  if (count($attributes)) {
50
- foreach ($attributes as $key => $attribute) {
51
  /** @var Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute */
52
  if ($attribute->getData('prices')) {
53
  return true;
@@ -57,14 +78,20 @@ class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Blo
57
  return false;
58
  }
59
 
 
 
 
 
 
60
  public function getAllowProducts()
61
  {
62
  if (!$this->hasAllowProducts()) {
63
  $products = array();
 
64
  $allProducts = $this->getProduct()->getTypeInstance(true)
65
  ->getUsedProducts(null, $this->getProduct());
66
  foreach ($allProducts as $product) {
67
- if ($product->isSaleable()) {
68
  $products[] = $product;
69
  }
70
  }
@@ -171,11 +198,10 @@ class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Blo
171
  'id' => $value['value_index'],
172
  'label' => $value['label'],
173
  'price' => $configurablePrice,
174
- 'oldPrice' => $this->_preparePrice($value['pricing_value'], $value['is_percent']),
175
  'products' => $productsIndex,
176
  );
177
  $optionPrices[] = $configurablePrice;
178
- //$this->_registerAdditionalJsPrice($value['pricing_value'], $value['is_percent']);
179
  }
180
  }
181
  /**
@@ -224,7 +250,6 @@ class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Blo
224
  $config = array(
225
  'attributes' => $attributes,
226
  'template' => str_replace('%s', '#{price}', $store->getCurrentCurrency()->getOutputFormat()),
227
- // 'prices' => $this->_prices,
228
  'basePrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getFinalPrice())),
229
  'oldPrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getPrice())),
230
  'productId' => $currentProduct->getId(),
@@ -244,7 +269,7 @@ class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Blo
244
  /**
245
  * Validating of super product option value
246
  *
247
- * @param array $attribute
248
  * @param array $value
249
  * @param array $options
250
  * @return boolean
@@ -272,26 +297,57 @@ class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Blo
272
  return false;
273
  }
274
 
275
- protected function _preparePrice($price, $isPercent=false)
 
 
 
 
 
 
 
276
  {
277
  if ($isPercent && !empty($price)) {
278
- $price = $this->getProduct()->getFinalPrice()*$price/100;
279
  }
280
 
281
  return $this->_registerJsPrice($this->_convertPrice($price, true));
282
  }
283
 
284
- protected function _registerJsPrice($price)
 
 
 
 
 
 
 
285
  {
286
- $jsPrice = str_replace(',', '.', $price);
 
 
287
 
288
- // if (!isset($this->_prices[$jsPrice])) {
289
- // $this->_prices[$jsPrice] = strip_tags(Mage::app()->getStore()->formatPrice($price));
290
- // }
291
- return $jsPrice;
 
 
 
 
 
 
 
 
292
  }
293
 
294
- protected function _convertPrice($price, $round=false)
 
 
 
 
 
 
 
295
  {
296
  if (empty($price)) {
297
  return 0;
@@ -302,32 +358,6 @@ class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Blo
302
  $price = $this->getCurrentStore()->roundPrice($price);
303
  }
304
 
305
-
306
  return $price;
307
  }
308
-
309
- // protected function _registerAdditionalJsPrice($price, $isPercent=false)
310
- // {
311
- // if (empty($price) && isset($this->_prices[0])) {
312
- // return $this;
313
- // }
314
- //
315
- // $basePrice = $this->getProduct()->getFinalPrice();
316
- // if ($isPercent) {
317
- // $price = $basePrice*$price/100;
318
- // }
319
- // else {
320
- // $price = $price;
321
- // }
322
- //
323
- // $price = $this->_convertPrice($price);
324
- //
325
- // foreach ($this->_resPrices as $prevPrice) {
326
- // $additionalPrice = $prevPrice + $price;
327
- // $this->_resPrices[] = $additionalPrice;
328
- // $jsAdditionalPrice = str_replace(',', '.', $additionalPrice);
329
- // $this->_prices[$jsAdditionalPrice] = strip_tags(Mage::app()->getStore()->formatPrice($additionalPrice));
330
- // }
331
- // return $this;
332
- // }
333
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
34
  */
35
  class Mage_Catalog_Block_Product_View_Type_Configurable extends Mage_Catalog_Block_Product_View_Abstract
36
  {
37
+ /**
38
+ * Prices
39
+ *
40
+ * @var array
41
+ */
42
  protected $_prices = array();
43
+
44
+ /**
45
+ * Prepared prices
46
+ *
47
+ * @var array
48
+ */
49
  protected $_resPrices = array();
50
 
51
+ /**
52
+ * Get allowed attributes
53
+ *
54
+ * @return array
55
+ */
56
  public function getAllowAttributes()
57
  {
58
  return $this->getProduct()->getTypeInstance(true)
59
  ->getConfigurableAttributes($this->getProduct());
60
  }
61
 
62
+ /**
63
+ * Check if allowed attributes have options
64
+ *
65
+ * @return bool
66
+ */
67
  public function hasOptions()
68
  {
69
  $attributes = $this->getAllowAttributes();
70
  if (count($attributes)) {
71
+ foreach ($attributes as $attribute) {
72
  /** @var Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute */
73
  if ($attribute->getData('prices')) {
74
  return true;
78
  return false;
79
  }
80
 
81
+ /**
82
+ * Get Allowed Products
83
+ *
84
+ * @return array
85
+ */
86
  public function getAllowProducts()
87
  {
88
  if (!$this->hasAllowProducts()) {
89
  $products = array();
90
+ $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
91
  $allProducts = $this->getProduct()->getTypeInstance(true)
92
  ->getUsedProducts(null, $this->getProduct());
93
  foreach ($allProducts as $product) {
94
+ if ($product->isSaleable() || $skipSaleableCheck) {
95
  $products[] = $product;
96
  }
97
  }
198
  'id' => $value['value_index'],
199
  'label' => $value['label'],
200
  'price' => $configurablePrice,
201
+ 'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
202
  'products' => $productsIndex,
203
  );
204
  $optionPrices[] = $configurablePrice;
 
205
  }
206
  }
207
  /**
250
  $config = array(
251
  'attributes' => $attributes,
252
  'template' => str_replace('%s', '#{price}', $store->getCurrentCurrency()->getOutputFormat()),
 
253
  'basePrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getFinalPrice())),
254
  'oldPrice' => $this->_registerJsPrice($this->_convertPrice($currentProduct->getPrice())),
255
  'productId' => $currentProduct->getId(),
269
  /**
270
  * Validating of super product option value
271
  *
272
+ * @param array $attributeId
273
  * @param array $value
274
  * @param array $options
275
  * @return boolean
297
  return false;
298
  }
299
 
300
+ /**
301
+ * Calculation real price
302
+ *
303
+ * @param float $price
304
+ * @param bool $isPercent
305
+ * @return mixed
306
+ */
307
+ protected function _preparePrice($price, $isPercent = false)
308
  {
309
  if ($isPercent && !empty($price)) {
310
+ $price = $this->getProduct()->getFinalPrice() * $price / 100;
311
  }
312
 
313
  return $this->_registerJsPrice($this->_convertPrice($price, true));
314
  }
315
 
316
+ /**
317
+ * Calculation price before special price
318
+ *
319
+ * @param float $price
320
+ * @param bool $isPercent
321
+ * @return mixed
322
+ */
323
+ protected function _prepareOldPrice($price, $isPercent = false)
324
  {
325
+ if ($isPercent && !empty($price)) {
326
+ $price = $this->getProduct()->getPrice() * $price / 100;
327
+ }
328
 
329
+ return $this->_registerJsPrice($this->_convertPrice($price, true));
330
+ }
331
+
332
+ /**
333
+ * Replace ',' on '.' for js
334
+ *
335
+ * @param float $price
336
+ * @return string
337
+ */
338
+ protected function _registerJsPrice($price)
339
+ {
340
+ return str_replace(',', '.', $price);
341
  }
342
 
343
+ /**
344
+ * Convert price from default currency to current currency
345
+ *
346
+ * @param float $price
347
+ * @param boolean $round
348
+ * @return float
349
+ */
350
+ protected function _convertPrice($price, $round = false)
351
  {
352
  if (empty($price)) {
353
  return 0;
358
  $price = $this->getCurrentStore()->roundPrice($price);
359
  }
360
 
 
361
  return $price;
362
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  }
app/code/core/Mage/Catalog/Block/Product/View/Type/Grouped.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Type/Simple.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/View/Type/Virtual.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/Widget/Link.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Product/Widget/New.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Seo/Sitemap/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Seo/Sitemap/Product.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Category.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Block/Widget/Link.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Exception.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Category.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Category/Flat.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Data.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -41,6 +41,7 @@ class Mage_Catalog_Helper_Data extends Mage_Core_Helper_Abstract
41
  const CONFIG_USE_STATIC_URLS = 'cms/wysiwyg/use_static_urls_in_catalog';
42
  const CONFIG_PARSE_URL_DIRECTIVES = 'catalog/frontend/parse_url_directives';
43
  const XML_PATH_CONTENT_TEMPLATE_FILTER = 'global/catalog/content/tempate_filter';
 
44
 
45
  /**
46
  * Minimum advertise price constants
@@ -464,4 +465,14 @@ class Mage_Catalog_Helper_Data extends Mage_Core_Helper_Abstract
464
  Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_ON_GESTURE
465
  );
466
  }
 
 
 
 
 
 
 
 
 
 
467
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
41
  const CONFIG_USE_STATIC_URLS = 'cms/wysiwyg/use_static_urls_in_catalog';
42
  const CONFIG_PARSE_URL_DIRECTIVES = 'catalog/frontend/parse_url_directives';
43
  const XML_PATH_CONTENT_TEMPLATE_FILTER = 'global/catalog/content/tempate_filter';
44
+ const XML_PATH_DISPLAY_PRODUCT_COUNT = 'catalog/layered_navigation/display_product_count';
45
 
46
  /**
47
  * Minimum advertise price constants
465
  Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_ON_GESTURE
466
  );
467
  }
468
+
469
+ /**
470
+ * Whether to display items count for each filter option
471
+ * @param int $storeId Store view ID
472
+ * @return bool
473
+ */
474
+ public function shouldDisplayProductCountOnLayer($storeId = null)
475
+ {
476
+ return Mage::getStoreConfigFlag(self::XML_PATH_DISPLAY_PRODUCT_COUNT, $storeId);
477
+ }
478
  }
app/code/core/Mage/Catalog/Helper/Image.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -31,22 +31,87 @@
31
  */
32
  class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
33
  {
 
 
 
 
 
34
  protected $_model;
 
 
 
 
 
 
35
  protected $_scheduleResize = false;
 
 
 
 
 
 
36
  protected $_scheduleRotate = false;
 
 
 
 
 
 
37
  protected $_angle;
38
 
 
 
 
 
 
39
  protected $_watermark;
 
 
 
 
 
 
40
  protected $_watermarkPosition;
 
 
 
 
 
 
41
  protected $_watermarkSize;
 
 
 
 
 
 
42
  protected $_watermarkImageOpacity;
43
 
 
 
 
 
 
44
  protected $_product;
 
 
 
 
 
 
45
  protected $_imageFile;
 
 
 
 
 
 
46
  protected $_placeholder;
47
 
48
  /**
49
- * Reset all previos data
 
 
50
  */
51
  protected function _reset()
52
  {
@@ -63,6 +128,14 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
63
  return $this;
64
  }
65
 
 
 
 
 
 
 
 
 
66
  public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)
67
  {
68
  $this->_reset();
@@ -70,17 +143,24 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
70
  $this->_getModel()->setDestinationSubdir($attributeName);
71
  $this->setProduct($product);
72
 
73
- $this->setWatermark(Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image"));
74
- $this->setWatermarkImageOpacity(Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity"));
75
- $this->setWatermarkPosition(Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position"));
76
- $this->setWatermarkSize(Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_size"));
 
 
 
 
 
 
 
 
77
 
78
  if ($imageFile) {
79
  $this->setImageFile($imageFile);
80
- }
81
- else {
82
  // add for work original size
83
- $this->_getModel()->setBaseFile( $this->getProduct()->getData($this->_getModel()->getDestinationSubdir()) );
84
  }
85
  return $this;
86
  }
@@ -198,6 +278,12 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
198
  return $this;
199
  }
200
 
 
 
 
 
 
 
201
  public function rotate($angle)
202
  {
203
  $this->setAngle($angle);
@@ -225,11 +311,22 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
225
  return $this;
226
  }
227
 
 
 
 
 
 
 
228
  public function placeholder($fileName)
229
  {
230
  $this->_placeholder = $fileName;
231
  }
232
 
 
 
 
 
 
233
  public function getPlaceholder()
234
  {
235
  if (!$this->_placeholder) {
@@ -239,41 +336,49 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
239
  return $this->_placeholder;
240
  }
241
 
 
 
 
 
 
242
  public function __toString()
243
  {
244
  try {
245
- if( $this->getImageFile() ) {
246
- $this->_getModel()->setBaseFile( $this->getImageFile() );
 
 
247
  } else {
248
- $this->_getModel()->setBaseFile( $this->getProduct()->getData($this->_getModel()->getDestinationSubdir()) );
249
  }
250
 
251
- if( $this->_getModel()->isCached() ) {
252
- return $this->_getModel()->getUrl();
253
  } else {
254
- if( $this->_scheduleRotate ) {
255
- $this->_getModel()->rotate( $this->getAngle() );
256
  }
257
 
258
  if ($this->_scheduleResize) {
259
- $this->_getModel()->resize();
260
  }
261
 
262
- if( $this->getWatermark() ) {
263
- $this->_getModel()->setWatermark($this->getWatermark());
264
  }
265
 
266
- $url = $this->_getModel()->saveFile()->getUrl();
267
  }
268
- } catch( Exception $e ) {
269
  $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
270
  }
271
  return $url;
272
  }
273
 
274
  /**
275
- * Enter description here...
276
  *
 
277
  * @return Mage_Catalog_Helper_Image
278
  */
279
  protected function _setModel($model)
@@ -283,7 +388,7 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
283
  }
284
 
285
  /**
286
- * Enter description here...
287
  *
288
  * @return Mage_Catalog_Model_Product_Image
289
  */
@@ -292,12 +397,23 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
292
  return $this->_model;
293
  }
294
 
 
 
 
 
 
 
295
  protected function setAngle($angle)
296
  {
297
  $this->_angle = $angle;
298
  return $this;
299
  }
300
 
 
 
 
 
 
301
  protected function getAngle()
302
  {
303
  return $this->_angle;
@@ -393,44 +509,67 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
393
  */
394
  protected function getWatermarkImageOpacity()
395
  {
396
- if( $this->_watermarkImageOpacity ) {
397
  return $this->_watermarkImageOpacity;
398
  }
399
 
400
  return $this->_getModel()->getWatermarkImageOpacity();
401
  }
402
 
 
 
 
 
 
 
403
  protected function setProduct($product)
404
  {
405
  $this->_product = $product;
406
  return $this;
407
  }
408
 
 
 
 
 
 
409
  protected function getProduct()
410
  {
411
  return $this->_product;
412
  }
413
 
 
 
 
 
 
 
414
  protected function setImageFile($file)
415
  {
416
  $this->_imageFile = $file;
417
  return $this;
418
  }
419
 
 
 
 
 
 
420
  protected function getImageFile()
421
  {
422
  return $this->_imageFile;
423
  }
424
 
425
  /**
426
- * Enter description here...
427
  *
428
- * @return array
 
429
  */
430
  protected function parseSize($string)
431
  {
432
  $size = explode('x', strtolower($string));
433
- if( sizeof($size) == 2 ) {
434
  return array(
435
  'width' => ($size[0] > 0) ? $size[0] : null,
436
  'heigth' => ($size[1] > 0) ? $size[1] : null,
@@ -485,17 +624,19 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
485
  }
486
 
487
  /**
488
- * Check - is this file an image
489
  *
490
  * @param string $filePath
491
  * @return bool
492
- * @throw Mage_Core_Exception
493
  */
494
  public function validateUploadFile($filePath) {
495
  if (!getimagesize($filePath)) {
496
  Mage::throwException($this->__('Disallowed file type.'));
497
  }
498
- return true;
 
 
499
  }
500
 
501
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
31
  */
32
  class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
33
  {
34
+ /**
35
+ * Current model
36
+ *
37
+ * @var Mage_Catalog_Model_Product_Image
38
+ */
39
  protected $_model;
40
+
41
+ /**
42
+ * Scheduled for resize image
43
+ *
44
+ * @var bool
45
+ */
46
  protected $_scheduleResize = false;
47
+
48
+ /**
49
+ * Scheduled for rotate image
50
+ *
51
+ * @var bool
52
+ */
53
  protected $_scheduleRotate = false;
54
+
55
+ /**
56
+ * Angle
57
+ *
58
+ * @var int
59
+ */
60
  protected $_angle;
61
 
62
+ /**
63
+ * Watermark file name
64
+ *
65
+ * @var string
66
+ */
67
  protected $_watermark;
68
+
69
+ /**
70
+ * Watermark Position
71
+ *
72
+ * @var string
73
+ */
74
  protected $_watermarkPosition;
75
+
76
+ /**
77
+ * Watermark Size
78
+ *
79
+ * @var string
80
+ */
81
  protected $_watermarkSize;
82
+
83
+ /**
84
+ * Watermark Image opacity
85
+ *
86
+ * @var int
87
+ */
88
  protected $_watermarkImageOpacity;
89
 
90
+ /**
91
+ * Current Product
92
+ *
93
+ * @var Mage_Catalog_Model_Product
94
+ */
95
  protected $_product;
96
+
97
+ /**
98
+ * Image File
99
+ *
100
+ * @var string
101
+ */
102
  protected $_imageFile;
103
+
104
+ /**
105
+ * Image Placeholder
106
+ *
107
+ * @var string
108
+ */
109
  protected $_placeholder;
110
 
111
  /**
112
+ * Reset all previous data
113
+ *
114
+ * @return Mage_Catalog_Helper_Image
115
  */
116
  protected function _reset()
117
  {
128
  return $this;
129
  }
130
 
131
+ /**
132
+ * Initialize Helper to work with Image
133
+ *
134
+ * @param Mage_Catalog_Model_Product $product
135
+ * @param string $attributeName
136
+ * @param mixed $imageFile
137
+ * @return Mage_Catalog_Helper_Image
138
+ */
139
  public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)
140
  {
141
  $this->_reset();
143
  $this->_getModel()->setDestinationSubdir($attributeName);
144
  $this->setProduct($product);
145
 
146
+ $this->setWatermark(
147
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image")
148
+ );
149
+ $this->setWatermarkImageOpacity(
150
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity")
151
+ );
152
+ $this->setWatermarkPosition(
153
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position")
154
+ );
155
+ $this->setWatermarkSize(
156
+ Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_size")
157
+ );
158
 
159
  if ($imageFile) {
160
  $this->setImageFile($imageFile);
161
+ } else {
 
162
  // add for work original size
163
+ $this->_getModel()->setBaseFile($this->getProduct()->getData($this->_getModel()->getDestinationSubdir()));
164
  }
165
  return $this;
166
  }
278
  return $this;
279
  }
280
 
281
+ /**
282
+ * Rotate image into specified angle
283
+ *
284
+ * @param int $angle
285
+ * @return Mage_Catalog_Helper_Image
286
+ */
287
  public function rotate($angle)
288
  {
289
  $this->setAngle($angle);
311
  return $this;
312
  }
313
 
314
+ /**
315
+ * Set placeholder
316
+ *
317
+ * @param string $fileName
318
+ * @return void
319
+ */
320
  public function placeholder($fileName)
321
  {
322
  $this->_placeholder = $fileName;
323
  }
324
 
325
+ /**
326
+ * Get Placeholder
327
+ *
328
+ * @return string
329
+ */
330
  public function getPlaceholder()
331
  {
332
  if (!$this->_placeholder) {
336
  return $this->_placeholder;
337
  }
338
 
339
+ /**
340
+ * Return Image URL
341
+ *
342
+ * @return string
343
+ */
344
  public function __toString()
345
  {
346
  try {
347
+ $model = $this->_getModel();
348
+
349
+ if ($this->getImageFile()) {
350
+ $model->setBaseFile($this->getImageFile());
351
  } else {
352
+ $model->setBaseFile($this->getProduct()->getData($model->getDestinationSubdir()));
353
  }
354
 
355
+ if ($model->isCached()) {
356
+ return $model->getUrl();
357
  } else {
358
+ if ($this->_scheduleRotate) {
359
+ $model->rotate($this->getAngle());
360
  }
361
 
362
  if ($this->_scheduleResize) {
363
+ $model->resize();
364
  }
365
 
366
+ if ($this->getWatermark()) {
367
+ $model->setWatermark($this->getWatermark());
368
  }
369
 
370
+ $url = $model->saveFile()->getUrl();
371
  }
372
+ } catch (Exception $e) {
373
  $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
374
  }
375
  return $url;
376
  }
377
 
378
  /**
379
+ * Set current Image model
380
  *
381
+ * @param Mage_Catalog_Model_Product_Image $model
382
  * @return Mage_Catalog_Helper_Image
383
  */
384
  protected function _setModel($model)
388
  }
389
 
390
  /**
391
+ * Get current Image model
392
  *
393
  * @return Mage_Catalog_Model_Product_Image
394
  */
397
  return $this->_model;
398
  }
399
 
400
+ /**
401
+ * Set Rotation Angle
402
+ *
403
+ * @param int $angle
404
+ * @return Mage_Catalog_Helper_Image
405
+ */
406
  protected function setAngle($angle)
407
  {
408
  $this->_angle = $angle;
409
  return $this;
410
  }
411
 
412
+ /**
413
+ * Get Rotation Angle
414
+ *
415
+ * @return int
416
+ */
417
  protected function getAngle()
418
  {
419
  return $this->_angle;
509
  */
510
  protected function getWatermarkImageOpacity()
511
  {
512
+ if ($this->_watermarkImageOpacity) {
513
  return $this->_watermarkImageOpacity;
514
  }
515
 
516
  return $this->_getModel()->getWatermarkImageOpacity();
517
  }
518
 
519
+ /**
520
+ * Set current Product
521
+ *
522
+ * @param Mage_Catalog_Model_Product $product
523
+ * @return Mage_Catalog_Helper_Image
524
+ */
525
  protected function setProduct($product)
526
  {
527
  $this->_product = $product;
528
  return $this;
529
  }
530
 
531
+ /**
532
+ * Get current Product
533
+ *
534
+ * @return Mage_Catalog_Model_Product
535
+ */
536
  protected function getProduct()
537
  {
538
  return $this->_product;
539
  }
540
 
541
+ /**
542
+ * Set Image file
543
+ *
544
+ * @param string $file
545
+ * @return Mage_Catalog_Helper_Image
546
+ */
547
  protected function setImageFile($file)
548
  {
549
  $this->_imageFile = $file;
550
  return $this;
551
  }
552
 
553
+ /**
554
+ * Get Image file
555
+ *
556
+ * @return string
557
+ */
558
  protected function getImageFile()
559
  {
560
  return $this->_imageFile;
561
  }
562
 
563
  /**
564
+ * Retrieve size from string
565
  *
566
+ * @param string $string
567
+ * @return array|bool
568
  */
569
  protected function parseSize($string)
570
  {
571
  $size = explode('x', strtolower($string));
572
+ if (sizeof($size) == 2) {
573
  return array(
574
  'width' => ($size[0] > 0) ? $size[0] : null,
575
  'heigth' => ($size[1] > 0) ? $size[1] : null,
624
  }
625
 
626
  /**
627
+ * Check - is this file an image
628
  *
629
  * @param string $filePath
630
  * @return bool
631
+ * @throws Mage_Core_Exception
632
  */
633
  public function validateUploadFile($filePath) {
634
  if (!getimagesize($filePath)) {
635
  Mage::throwException($this->__('Disallowed file type.'));
636
  }
637
+
638
+ $_processor = new Varien_Image($filePath);
639
+ return $_processor->getMimeType() !== null;
640
  }
641
 
642
  }
app/code/core/Mage/Catalog/Helper/Map.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Output.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Product.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
@@ -35,6 +35,13 @@ class Mage_Catalog_Helper_Product extends Mage_Core_Helper_Url
35
  const XML_PATH_PRODUCT_URL_USE_CATEGORY = 'catalog/seo/product_use_categories';
36
  const XML_PATH_USE_PRODUCT_CANONICAL_TAG = 'catalog/seo/product_canonical_tag';
37
 
 
 
 
 
 
 
 
38
  /**
39
  * Cache for product rewrite suffix
40
  *
@@ -307,6 +314,8 @@ class Mage_Catalog_Helper_Product extends Mage_Core_Helper_Url
307
  if ($product->canBeShowInCategory($lastId)) {
308
  $categoryId = $lastId;
309
  }
 
 
310
  }
311
 
312
  if ($categoryId) {
@@ -407,38 +416,56 @@ class Mage_Catalog_Helper_Product extends Mage_Core_Helper_Url
407
  * @param string $identifierType
408
  * @return Mage_Catalog_Model_Product
409
  */
410
- public function getProduct($productId, $store, $identifierType = null) {
411
- $loadByIdOnFalse = false;
412
- if ($identifierType == null) {
 
 
 
 
413
  if (is_string($productId) && !preg_match("/^[+-]?[1-9][0-9]*$|^0$/", $productId)) {
414
- $identifierType = 'sku';
415
- $loadByIdOnFalse = true;
416
- } else {
417
- $identifierType = 'id';
418
  }
419
  }
420
 
421
- /** @var $product Mage_Catalog_Model_Product */
422
- $product = Mage::getModel('catalog/product');
423
- if ($store !== null) {
424
- $product->setStoreId($store);
425
- }
426
- if ($identifierType == 'sku') {
427
  $idBySku = $product->getIdBySku($productId);
428
  if ($idBySku) {
429
  $productId = $idBySku;
430
- }
431
- if ($loadByIdOnFalse) {
432
- $identifierType = 'id';
433
  }
434
  }
435
 
436
- if ($identifierType == 'id' && is_numeric($productId)) {
437
- $productId = !is_float($productId) ? (int) $productId : 0;
438
- $product->load($productId);
439
  }
440
 
441
  return $product;
442
  }
443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  }
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
35
  const XML_PATH_PRODUCT_URL_USE_CATEGORY = 'catalog/seo/product_use_categories';
36
  const XML_PATH_USE_PRODUCT_CANONICAL_TAG = 'catalog/seo/product_canonical_tag';
37
 
38
+ /**
39
+ * Flag that shows if Magento has to check product to be saleable (enabled and/or inStock)
40
+ *
41
+ * @var boolean
42
+ */
43
+ protected $_skipSaleableCheck = false;
44
+
45
  /**
46
  * Cache for product rewrite suffix
47
  *
314
  if ($product->canBeShowInCategory($lastId)) {
315
  $categoryId = $lastId;
316
  }
317
+ } elseif (!$product->canBeShowInCategory($categoryId)) {
318
+ $categoryId = null;
319
  }
320
 
321
  if ($categoryId) {
416
  * @param string $identifierType
417
  * @return Mage_Catalog_Model_Product
418
  */
419
+ public function getProduct($productId, $store, $identifierType = null)
420
+ {
421
+ /** @var $product Mage_Catalog_Model_Product */
422
+ $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore($store)->getId());
423
+
424
+ $expectedIdType = false;
425
+ if ($identifierType === null) {
426
  if (is_string($productId) && !preg_match("/^[+-]?[1-9][0-9]*$|^0$/", $productId)) {
427
+ $expectedIdType = 'sku';
 
 
 
428
  }
429
  }
430
 
431
+ if ($identifierType == 'sku' || $expectedIdType == 'sku') {
 
 
 
 
 
432
  $idBySku = $product->getIdBySku($productId);
433
  if ($idBySku) {
434
  $productId = $idBySku;
435
+ } else if ($identifierType == 'sku') {
436
+ // Return empty product because it was not found by originally specified SKU identifier
437
+ return $product;
438
  }
439
  }
440
 
441
+ if ($productId && is_numeric($productId)) {
442
+ $product->load((int) $productId);
 
443
  }
444
 
445
  return $product;
446
  }
447
 
448
+ /**
449
+ * Set flag that shows if Magento has to check product to be saleable (enabled and/or inStock)
450
+ *
451
+ * For instance, during order creation in the backend admin has ability to add any products to order
452
+ *
453
+ * @param bool $skipSaleableCheck
454
+ * @return Mage_Catalog_Helper_Product
455
+ */
456
+ public function setSkipSaleableCheck($skipSaleableCheck = false)
457
+ {
458
+ $this->_skipSaleableCheck = $skipSaleableCheck;
459
+ return $this;
460
+ }
461
+
462
+ /**
463
+ * Get flag that shows if Magento has to check product to be saleable (enabled and/or inStock)
464
+ *
465
+ * @return boolean
466
+ */
467
+ public function getSkipSaleableCheck()
468
+ {
469
+ return $this->_skipSaleableCheck;
470
+ }
471
  }
app/code/core/Mage/Catalog/Helper/Product/Compare.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Product/Configuration.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Product/Configuration/Interface.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Product/Flat.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Product/Options.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Product/Url.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Helper/Product/View.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Model/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Model/Api/Resource.php CHANGED
@@ -20,7 +20,7 @@
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
20
  *
21
  * @category Mage
22
  * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
26
 
app/code/core/Mage/Catalog/Model/Api2/Product.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract Api2 model for product instance
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product extends Mage_Api2_Model_Resource
35
+ {
36
+ /**
37
+ * Get available attributes of API resource
38
+ *
39
+ * @param string $userType
40
+ * @param string $operation
41
+ * @return array
42
+ */
43
+ public function getAvailableAttributes($userType, $operation)
44
+ {
45
+ $attributes = $this->getAvailableAttributesFromConfig();
46
+ /** @var $entityType Mage_Eav_Model_Entity_Type */
47
+ $entityType = Mage::getModel('eav/entity_type')->loadByCode('catalog_product');
48
+ $entityOnlyAttrs = $this->getEntityOnlyAttributes($userType, $operation);
49
+ /** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
50
+ foreach ($entityType->getAttributeCollection() as $attribute) {
51
+ if ($this->_isAttributeVisible($attribute, $userType)) {
52
+ $attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel();
53
+ }
54
+ }
55
+ $excludedAttrs = $this->getExcludedAttributes($userType, $operation);
56
+ $includedAttrs = $this->getIncludedAttributes($userType, $operation);
57
+ foreach ($attributes as $code => $label) {
58
+ if (in_array($code, $excludedAttrs) || ($includedAttrs && !in_array($code, $includedAttrs))) {
59
+ unset($attributes[$code]);
60
+ }
61
+ if (in_array($code, $entityOnlyAttrs)) {
62
+ $attributes[$code] .= ' *';
63
+ }
64
+ }
65
+
66
+ return $attributes;
67
+ }
68
+
69
+ /**
70
+ * Define if attribute should be visible for passed user type
71
+ *
72
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
73
+ * @param string $userType
74
+ * @return bool
75
+ */
76
+ protected function _isAttributeVisible(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $userType)
77
+ {
78
+ $isAttributeVisible = false;
79
+ if ($userType == Mage_Api2_Model_Auth_User_Admin::USER_TYPE) {
80
+ $isAttributeVisible = $attribute->getIsVisible();
81
+ } else {
82
+ $systemAttributesForNonAdmin = array(
83
+ 'sku', 'name', 'short_description', 'description', 'tier_price', 'meta_title', 'meta_description',
84
+ 'meta_keyword',
85
+ );
86
+ if ($attribute->getIsUserDefined()) {
87
+ $isAttributeVisible = $attribute->getIsVisibleOnFront();
88
+ } else if (in_array($attribute->getAttributeCode(), $systemAttributesForNonAdmin)) {
89
+ $isAttributeVisible = true;
90
+ }
91
+ }
92
+ return (bool)$isAttributeVisible;
93
+ }
94
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Category.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract Api2 model for product categories collection
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Category extends Mage_Api2_Model_Resource
35
+ {
36
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract API2 class for product categories
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Catalog_Model_Api2_Product_Category_Rest extends Mage_Catalog_Model_Api2_Product_Rest
35
+ {
36
+ /**
37
+ * Product category assign is not available
38
+ *
39
+ * @param array $data
40
+ */
41
+ protected function _create(array $data)
42
+ {
43
+ $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
44
+ }
45
+
46
+ /**
47
+ * Product category update is not available
48
+ *
49
+ * @param array $data
50
+ */
51
+ protected function _update(array $data)
52
+ {
53
+ $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
54
+ }
55
+
56
+ /**
57
+ * Retrieve product data
58
+ *
59
+ * @return array
60
+ */
61
+ protected function _retrieveCollection()
62
+ {
63
+ $return = array();
64
+
65
+ foreach ($this->_getCategoryIds() as $categoryId) {
66
+ $return[] = array('category_id' => $categoryId);
67
+ }
68
+ return $return;
69
+ }
70
+
71
+ /**
72
+ * Only admin have permissions for product category unassign
73
+ */
74
+ protected function _delete()
75
+ {
76
+ $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
77
+ }
78
+
79
+ /**
80
+ * Load category by id
81
+ *
82
+ * @param int $categoryId
83
+ * @return Mage_Catalog_Model_Category
84
+ */
85
+ protected function _getCategoryById($categoryId)
86
+ {
87
+ /** @var $category Mage_Catalog_Model_Category */
88
+ $category = Mage::getModel('catalog/category')->setStoreId(0)->load($categoryId);
89
+ if (!$category->getId()) {
90
+ $this->_critical('Category not found', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
91
+ }
92
+
93
+ return $category;
94
+ }
95
+
96
+ /**
97
+ * Get assigned categories ids
98
+ *
99
+ * @return array
100
+ */
101
+ protected function _getCategoryIds()
102
+ {
103
+ return $this->_getProduct()->getCategoryCollection()->addIsActiveFilter()->getAllIds();
104
+ }
105
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest/Admin/V1.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 for product categories
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Category_Rest_Admin_V1 extends Mage_Catalog_Model_Api2_Product_Category_Rest
35
+ {
36
+ /**
37
+ * Product category assign
38
+ *
39
+ * @param array $data
40
+ * @return string
41
+ */
42
+ protected function _create(array $data)
43
+ {
44
+ /* @var $validator Mage_Api2_Model_Resource_Validator_Fields */
45
+ $validator = Mage::getResourceModel('api2/validator_fields', array('resource' => $this));
46
+ if (!$validator->isValidData($data)) {
47
+ foreach ($validator->getErrors() as $error) {
48
+ $this->_error($error, Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
49
+ }
50
+ $this->_critical(self::RESOURCE_DATA_PRE_VALIDATION_ERROR);
51
+ }
52
+
53
+ $product = $this->_getProduct();
54
+ $category = $this->_getCategoryById($data['category_id']);
55
+
56
+ $categoryIds = $product->getCategoryIds();
57
+ if (!is_array($categoryIds)) {
58
+ $categoryIds = array();
59
+ }
60
+ if (in_array($category->getId(), $categoryIds)) {
61
+ $this->_critical(sprintf('Product #%d is already assigned to category #%d',
62
+ $product->getId(), $category->getId()), Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
63
+ }
64
+ if ($category->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID) {
65
+ $this->_critical('Cannot assign product to tree root category.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
66
+ }
67
+ $categoryIds[] = $category->getId();
68
+ $product->setCategoryIds(implode(',', $categoryIds));
69
+
70
+ try{
71
+ $product->save();
72
+ } catch (Mage_Core_Exception $e) {
73
+ $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
74
+ } catch (Exception $e) {
75
+ $this->_critical(self::RESOURCE_INTERNAL_ERROR);
76
+ }
77
+
78
+ return $this->_getLocation($category);
79
+ }
80
+
81
+ /**
82
+ * Product category unassign
83
+ *
84
+ * @return bool
85
+ */
86
+ protected function _delete()
87
+ {
88
+ $product = $this->_getProduct();
89
+ $category = $this->_getCategoryById($this->getRequest()->getParam('category_id'));
90
+
91
+ $categoryIds = $product->getCategoryIds();
92
+ $categoryToBeDeletedId = array_search($category->getId(), $categoryIds);
93
+ if (false === $categoryToBeDeletedId) {
94
+ $this->_critical(sprintf('Product #%d isn\'t assigned to category #%d',
95
+ $product->getId(), $category->getId()), Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
96
+ }
97
+
98
+ // delete category
99
+ unset($categoryIds[$categoryToBeDeletedId]);
100
+ $product->setCategoryIds(implode(',', $categoryIds));
101
+
102
+ try{
103
+ $product->save();
104
+ } catch (Mage_Core_Exception $e) {
105
+ $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
106
+ } catch (Exception $e) {
107
+ $this->_critical(self::RESOURCE_INTERNAL_ERROR);
108
+ }
109
+
110
+ return true;
111
+ }
112
+
113
+ /**
114
+ * Return all assigned categories
115
+ *
116
+ * @return array
117
+ */
118
+ protected function _getCategoryIds()
119
+ {
120
+ return $this->_getProduct()->getCategoryIds();
121
+ }
122
+
123
+ /**
124
+ * Get resource location
125
+ *
126
+ * @param Mage_Core_Model_Abstract $resource
127
+ * @return string URL
128
+ */
129
+ protected function _getLocation($resource)
130
+ {
131
+ /** @var $apiTypeRoute Mage_Api2_Model_Route_ApiType */
132
+ $apiTypeRoute = Mage::getModel('api2/route_apiType');
133
+
134
+ $chain = $apiTypeRoute->chain(new Zend_Controller_Router_Route(
135
+ $this->getConfig()->getRouteWithEntityTypeAction($this->getResourceType())
136
+ ));
137
+ $params = array(
138
+ 'api_type' => $this->getRequest()->getApiType(),
139
+ 'id' => $this->getRequest()->getParam('id'),
140
+ 'category_id' => $resource->getId()
141
+ );
142
+ $uri = $chain->assemble($params);
143
+
144
+ return '/' . $uri;
145
+ }
146
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest/Customer/V1.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 for product categories
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Category_Rest_Customer_V1 extends Mage_Catalog_Model_Api2_Product_Category_Rest
35
+ {
36
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Category/Rest/Guest/V1.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 for product categories
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Category_Rest_Guest_V1 extends Mage_Catalog_Model_Api2_Product_Category_Rest
35
+ {
36
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Image.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract Api2 model for product image
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Image extends Mage_Api2_Model_Resource
35
+ {
36
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest.php ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract API2 class for product images resource
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Catalog_Model_Api2_Product_Image_Rest extends Mage_Catalog_Model_Api2_Product_Rest
35
+ {
36
+ /**
37
+ * Attribute code for media gallery
38
+ */
39
+ const GALLERY_ATTRIBUTE_CODE = 'media_gallery';
40
+
41
+ /**
42
+ * Allowed MIME types for image
43
+ *
44
+ * @var array
45
+ */
46
+ protected $_mimeTypes = array(
47
+ 'image/jpg' => 'jpg',
48
+ 'image/jpeg' => 'jpg',
49
+ 'image/gif' => 'gif',
50
+ 'image/png' => 'png'
51
+ );
52
+
53
+ /**
54
+ * Retrieve product image data for customer and guest roles
55
+ *
56
+ * @throws Mage_Api2_Exception
57
+ * @return array
58
+ */
59
+ protected function _retrieve()
60
+ {
61
+ $imageData = array();
62
+ $imageId = (int)$this->getRequest()->getParam('image');
63
+ $galleryData = $this->_getProduct()->getData(self::GALLERY_ATTRIBUTE_CODE);
64
+
65
+ if (!isset($galleryData['images']) || !is_array($galleryData['images'])) {
66
+ $this->_critical(self::RESOURCE_NOT_FOUND);
67
+ }
68
+ foreach ($galleryData['images'] as $image) {
69
+ if ($image['value_id'] == $imageId && !$image['disabled']) {
70
+ $imageData = $this->_formatImageData($image);
71
+ break;
72
+ }
73
+ }
74
+ if (empty($imageData)) {
75
+ $this->_critical(self::RESOURCE_NOT_FOUND);
76
+ }
77
+ return $imageData;
78
+ }
79
+
80
+ /**
81
+ * Retrieve product images data for customer and guest
82
+ *
83
+ * @return array
84
+ */
85
+ protected function _retrieveCollection()
86
+ {
87
+ $images = array();
88
+ $galleryData = $this->_getProduct()->getData(self::GALLERY_ATTRIBUTE_CODE);
89
+ if (isset($galleryData['images']) && is_array($galleryData['images'])) {
90
+ foreach ($galleryData['images'] as $image) {
91
+ if (!$image['disabled']) {
92
+ $images[] = $this->_formatImageData($image);
93
+ }
94
+ }
95
+ }
96
+ return $images;
97
+ }
98
+
99
+ /**
100
+ * Retrieve media gallery
101
+ *
102
+ * @throws Mage_Api2_Exception
103
+ * @return Mage_Catalog_Model_Product_Attribute_Backend_Media
104
+ */
105
+ protected function _getMediaGallery()
106
+ {
107
+ $attributes = $this->_getProduct()->getTypeInstance(true)->getSetAttributes($this->_getProduct());
108
+
109
+ if (!isset($attributes[self::GALLERY_ATTRIBUTE_CODE])
110
+ || !$attributes[self::GALLERY_ATTRIBUTE_CODE] instanceof Mage_Eav_Model_Entity_Attribute_Abstract
111
+ ) {
112
+ $this->_critical('Requested product does not support images', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
113
+ }
114
+ $galleryAttribute = $attributes[self::GALLERY_ATTRIBUTE_CODE];
115
+ /** @var $mediaGallery Mage_Catalog_Model_Product_Attribute_Backend_Media */
116
+ $mediaGallery = $galleryAttribute->getBackend();
117
+ return $mediaGallery;
118
+ }
119
+
120
+ /**
121
+ * Create image data representation for API
122
+ *
123
+ * @param array $image
124
+ * @return array
125
+ */
126
+ protected function _formatImageData($image)
127
+ {
128
+ $result = array(
129
+ 'id' => $image['value_id'],
130
+ 'label' => $image['label'],
131
+ 'position' => $image['position'],
132
+ 'exclude' => $image['disabled'],
133
+ 'url' => $this->_getMediaConfig()->getMediaUrl($image['file']),
134
+ 'types' => $this->_getImageTypesAssignedToProduct($image['file'])
135
+ );
136
+ return $result;
137
+ }
138
+
139
+ /**
140
+ * Retrieve image types assigned to product (base, small, thumbnail)
141
+ *
142
+ * @param string $imageFile
143
+ * @return array
144
+ */
145
+ protected function _getImageTypesAssignedToProduct($imageFile)
146
+ {
147
+ $types = array();
148
+ foreach ($this->_getProduct()->getMediaAttributes() as $attribute) {
149
+ if ($this->_getProduct()->getData($attribute->getAttributeCode()) == $imageFile) {
150
+ $types[] = $attribute->getAttributeCode();
151
+ }
152
+ }
153
+ return $types;
154
+ }
155
+
156
+ /**
157
+ * Retrieve media config
158
+ *
159
+ * @return Mage_Catalog_Model_Product_Media_Config
160
+ */
161
+ protected function _getMediaConfig()
162
+ {
163
+ return Mage::getSingleton('catalog/product_media_config');
164
+ }
165
+
166
+ /**
167
+ * Create file name from received data
168
+ *
169
+ * @param array $data
170
+ * @return string
171
+ */
172
+ protected function _getFileName($data)
173
+ {
174
+ $fileName = 'image';
175
+ if (isset($data['file_name']) && $data['file_name']) {
176
+ $fileName = $data['file_name'];
177
+ }
178
+ $fileName .= '.' . $this->_getExtensionByMimeType($data['file_mime_type']);
179
+ return $fileName;
180
+ }
181
+
182
+ /**
183
+ * Retrieve file extension using MIME type
184
+ *
185
+ * @throws Mage_Api2_Exception
186
+ * @param string $mimeType
187
+ * @return string
188
+ */
189
+ protected function _getExtensionByMimeType($mimeType)
190
+ {
191
+ if (!array_key_exists($mimeType, $this->_mimeTypes)) {
192
+ $this->_critical('Unsuppoted image MIME type', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
193
+ }
194
+ return $this->_mimeTypes[$mimeType];
195
+ }
196
+
197
+ /**
198
+ * Get file URI by its id. File URI is used by media backend to identify image
199
+ *
200
+ * @throws Mage_Api2_Exception
201
+ * @param int $imageId
202
+ * @return string
203
+ */
204
+ protected function _getImageFileById($imageId)
205
+ {
206
+ $file = null;
207
+ $mediaGalleryData = $this->_getProduct()->getData('media_gallery');
208
+ if (!isset($mediaGalleryData['images'])) {
209
+ $this->_critical(self::RESOURCE_NOT_FOUND);
210
+ }
211
+ foreach ($mediaGalleryData['images'] as $image) {
212
+ if ($image['value_id'] == $imageId) {
213
+ $file = $image['file'];
214
+ break;
215
+ }
216
+ }
217
+ if (!($file && $this->_getMediaGallery()->getImage($this->_getProduct(), $file))) {
218
+ $this->_critical(self::RESOURCE_NOT_FOUND);
219
+ }
220
+ return $file;
221
+ }
222
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest/Admin/V1.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 for product image. Admin role
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Image_Rest_Admin_V1 extends Mage_Catalog_Model_Api2_Product_Image_Rest
35
+ {
36
+ /**
37
+ * Product image add
38
+ *
39
+ * @throws Mage_Api2_Exception
40
+ * @param array $data
41
+ * @return string
42
+ */
43
+ protected function _create(array $data)
44
+ {
45
+ /* @var $validator Mage_Catalog_Model_Api2_Product_Image_Validator_Image */
46
+ $validator = Mage::getModel('catalog/api2_product_image_validator_image');
47
+ if (!$validator->isValidData($data)) {
48
+ foreach ($validator->getErrors() as $error) {
49
+ $this->_error($error, Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
50
+ }
51
+ $this->_critical(self::RESOURCE_DATA_PRE_VALIDATION_ERROR);
52
+ }
53
+ $imageFileContent = @base64_decode($data['file_content'], true);
54
+ if (!$imageFileContent) {
55
+ $this->_critical('The image content must be valid base64 encoded data',
56
+ Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
57
+ }
58
+ unset($data['file_content']);
59
+
60
+ $apiTempDir = Mage::getBaseDir('var') . DS . 'api' . DS . Mage::getSingleton('api/session')->getSessionId();
61
+ $imageFileName = $this->_getFileName($data);
62
+
63
+ try {
64
+ $ioAdapter = new Varien_Io_File();
65
+ $ioAdapter->checkAndCreateFolder($apiTempDir);
66
+ $ioAdapter->open(array('path' => $apiTempDir));
67
+ $ioAdapter->write($imageFileName, $imageFileContent, 0666);
68
+ unset($imageFileContent);
69
+
70
+ // try to create Image object to check if image data is valid
71
+ try {
72
+ new Varien_Image($apiTempDir . DS . $imageFileName);
73
+ } catch (Exception $e) {
74
+ $ioAdapter->rmdir($apiTempDir, true);
75
+ $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
76
+ }
77
+ $product = $this->_getProduct();
78
+ $imageFileUri = $this->_getMediaGallery()
79
+ ->addImage($product, $apiTempDir . DS . $imageFileName, null, false, false);
80
+ $ioAdapter->rmdir($apiTempDir, true);
81
+ // updateImage() must be called to add image data that is missing after addImage() call
82
+ $this->_getMediaGallery()->updateImage($product, $imageFileUri, $data);
83
+
84
+ if (isset($data['types'])) {
85
+ $this->_getMediaGallery()->setMediaAttribute($product, $data['types'], $imageFileUri);
86
+ }
87
+ $product->save();
88
+ return $this->_getImageLocation($this->_getCreatedImageId($imageFileUri));
89
+ } catch (Mage_Core_Exception $e) {
90
+ $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
91
+ } catch (Exception $e) {
92
+ $this->_critical(self::RESOURCE_UNKNOWN_ERROR);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Get added image ID
98
+ *
99
+ * @throws Mage_Api2_Exception
100
+ * @param string $imageFileUri
101
+ * @return int
102
+ */
103
+ protected function _getCreatedImageId($imageFileUri)
104
+ {
105
+ $imageId = null;
106
+
107
+ $imageData = Mage::getResourceModel('catalog/product_attribute_backend_media')
108
+ ->loadGallery($this->_getProduct(), $this->_getMediaGallery());
109
+ foreach ($imageData as $image) {
110
+ if ($image['file'] == $imageFileUri) {
111
+ $imageId = $image['value_id'];
112
+ break;
113
+ }
114
+ }
115
+ if (!$imageId) {
116
+ $this->_critical('Unknown error during image save', Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
117
+ }
118
+ return $imageId;
119
+ }
120
+
121
+ /**
122
+ * Retrieve product images data
123
+ *
124
+ * @throws Mage_Api2_Exception
125
+ * @return array
126
+ */
127
+ protected function _retrieve()
128
+ {
129
+ $result = array();
130
+ $imageId = (int) $this->getRequest()->getParam('image');
131
+ $galleryData = $this->_getProduct()->getData(self::GALLERY_ATTRIBUTE_CODE);
132
+ if (!isset($galleryData['images']) || !is_array($galleryData['images'])) {
133
+ $this->_critical('Product image not found', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
134
+ }
135
+ foreach ($galleryData['images'] as &$image) {
136
+ if ($image['value_id'] == $imageId) {
137
+ $result = $this->_formatImageData($image);
138
+ break;
139
+ }
140
+ }
141
+ if (empty($result)) {
142
+ $this->_critical('Product image not found', Mage_Api2_Model_Server::HTTP_NOT_FOUND);
143
+ }
144
+ return $result;
145
+ }
146
+
147
+ /**
148
+ * Update product image
149
+ *
150
+ * @throws Mage_Api2_Exception
151
+ * @param array $data
152
+ * @return bool
153
+ */
154
+ protected function _update(array $data)
155
+ {
156
+ $imageId = (int)$this->getRequest()->getParam('image');
157
+ $imageFileUri = $this->_getImageFileById($imageId);
158
+ $product = $this->_getProduct();
159
+ $this->_getMediaGallery()->updateImage($product, $imageFileUri, $data);
160
+ if (isset($data['types']) && is_array($data['types'])) {
161
+ $assignedTypes = $this->_getImageTypesAssignedToProduct($imageFileUri);
162
+ $typesToBeCleared = array_diff($assignedTypes, $data['types']);
163
+ if (count($typesToBeCleared) > 0) {
164
+ $this->_getMediaGallery()->clearMediaAttribute($product, $typesToBeCleared);
165
+ }
166
+ $this->_getMediaGallery()->setMediaAttribute($product, $data['types'], $imageFileUri);
167
+ }
168
+ try {
169
+ $product->save();
170
+ } catch (Mage_Core_Exception $e) {
171
+ $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
172
+ } catch (Exception $e) {
173
+ $this->_critical(self::RESOURCE_INTERNAL_ERROR);
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Product image delete
179
+ *
180
+ * @throws Mage_Api2_Exception
181
+ */
182
+ protected function _delete()
183
+ {
184
+ $imageId = (int)$this->getRequest()->getParam('image');
185
+ $product = $this->_getProduct();
186
+ $imageFileUri = $this->_getImageFileById($imageId);
187
+ $this->_getMediaGallery()->removeImage($product, $imageFileUri);
188
+ try {
189
+ $product->save();
190
+ } catch (Mage_Core_Exception $e) {
191
+ $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
192
+ } catch (Exception $e) {
193
+ $this->_critical(self::RESOURCE_INTERNAL_ERROR);
194
+ }
195
+ }
196
+
197
+ /**
198
+ * Retrieve product images data
199
+ *
200
+ * @throws Mage_Api2_Exception
201
+ * @return array
202
+ */
203
+ protected function _retrieveCollection()
204
+ {
205
+ $images = array();
206
+ $galleryData = $this->_getProduct()->getData(self::GALLERY_ATTRIBUTE_CODE);
207
+ if (isset($galleryData['images']) && is_array($galleryData['images'])) {
208
+ foreach ($galleryData['images'] as $image) {
209
+ $images[] = $this->_formatImageData($image);
210
+ }
211
+ }
212
+ return $images;
213
+ }
214
+
215
+ /**
216
+ * Get image resource location
217
+ *
218
+ * @param int $imageId
219
+ * @return string URL
220
+ */
221
+ protected function _getImageLocation($imageId)
222
+ {
223
+ /* @var $apiTypeRoute Mage_Api2_Model_Route_ApiType */
224
+ $apiTypeRoute = Mage::getModel('api2/route_apiType');
225
+
226
+ $chain = $apiTypeRoute->chain(
227
+ new Zend_Controller_Router_Route($this->getConfig()->getRouteWithEntityTypeAction($this->getResourceType()))
228
+ );
229
+ $params = array(
230
+ 'api_type' => $this->getRequest()->getApiType(),
231
+ 'id' => $this->getRequest()->getParam('id'),
232
+ 'image' => $imageId
233
+ );
234
+ $uri = $chain->assemble($params);
235
+ return '/' . $uri;
236
+ }
237
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest/Customer/V1.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 for product image. Customer role
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Image_Rest_Customer_V1 extends Mage_Catalog_Model_Api2_Product_Image_Rest
35
+ {
36
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest/Guest/V1.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 for product image. Guest role
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Image_Rest_Guest_V1 extends Mage_Catalog_Model_Api2_Product_Image_Rest
35
+ {
36
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Image/Validator/Image.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 Product image validator
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Image_Validator_Image extends Mage_Api2_Model_Resource_Validator
35
+ {
36
+ /**
37
+ * Validate data. In case of validation failure return false,
38
+ * getErrors() could be used to retrieve list of validation error messages
39
+ *
40
+ * @param array $data
41
+ * @return bool
42
+ */
43
+ public function isValidData(array $data)
44
+ {
45
+ if (!isset($data['file_content']) || !isset($data['file_mime_type']) || empty($data['file_content']) ||
46
+ empty($data['file_mime_type'])
47
+ ) {
48
+ $this->_addError('The image is not specified');
49
+ }
50
+
51
+ return !count($this->getErrors());
52
+ }
53
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Rest.php ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Abstract API2 class for product instance
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Catalog_Model_Api2_Product_Rest extends Mage_Catalog_Model_Api2_Product
35
+ {
36
+ /**
37
+ * Current loaded product
38
+ *
39
+ * @var Mage_Catalog_Model_Product
40
+ */
41
+ protected $_product;
42
+
43
+ /**
44
+ * Retrieve product data
45
+ *
46
+ * @return array
47
+ */
48
+ protected function _retrieve()
49
+ {
50
+ $product = $this->_getProduct();
51
+
52
+ $this->_prepareProductForResponse($product);
53
+ return $product->getData();
54
+ }
55
+
56
+ /**
57
+ * Retrieve list of products
58
+ *
59
+ * @return array
60
+ */
61
+ protected function _retrieveCollection()
62
+ {
63
+ /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
64
+ $collection = Mage::getResourceModel('catalog/product_collection');
65
+ $store = $this->_getStore();
66
+ $entityOnlyAttributes = $this->getEntityOnlyAttributes($this->getUserType(),
67
+ Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ);
68
+ $availableAttributes = array_keys($this->getAvailableAttributes($this->getUserType(),
69
+ Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ));
70
+ // available attributes not contain image attribute, but it needed for get image_url
71
+ $availableAttributes[] = 'image';
72
+ $collection->addStoreFilter($store->getId())
73
+ ->addPriceData($this->_getCustomerGroupId(), $store->getWebsiteId())
74
+ ->addAttributeToSelect(array_diff($availableAttributes, $entityOnlyAttributes))
75
+ ->addAttributeToFilter('visibility', array(
76
+ 'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE))
77
+ ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
78
+ $this->_applyCategoryFilter($collection);
79
+ $this->_applyCollectionModifiers($collection);
80
+ $products = $collection->load();
81
+
82
+ /** @var Mage_Catalog_Model_Product $product */
83
+ foreach ($products as $product) {
84
+ $this->_setProduct($product);
85
+ $this->_prepareProductForResponse($product);
86
+ }
87
+ return $products->toArray();
88
+ }
89
+
90
+ /**
91
+ * Apply filter by category id
92
+ *
93
+ * @param Mage_Catalog_Model_Resource_Product_Collection $collection
94
+ */
95
+ protected function _applyCategoryFilter(Mage_Catalog_Model_Resource_Product_Collection $collection)
96
+ {
97
+ $categoryId = $this->getRequest()->getParam('category_id');
98
+ if ($categoryId) {
99
+ $category = $this->_getCategoryById($categoryId);
100
+ if (!$category->getId()) {
101
+ $this->_critical('Category not found.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
102
+ }
103
+ $collection->addCategoryFilter($category);
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Add special fields to product get response
109
+ *
110
+ * @param Mage_Catalog_Model_Product $product
111
+ */
112
+ protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product)
113
+ {
114
+ /** @var $productHelper Mage_Catalog_Helper_Product */
115
+ $productHelper = Mage::helper('catalog/product');
116
+ $productData = $product->getData();
117
+ $product->setWebsiteId($this->_getStore()->getWebsiteId());
118
+ // customer group is required in product for correct prices calculation
119
+ $product->setCustomerGroupId($this->_getCustomerGroupId());
120
+ // calculate prices
121
+ $finalPrice = $product->getFinalPrice();
122
+ $productData['regular_price_with_tax'] = $this->_applyTaxToPrice($product->getPrice(), true);
123
+ $productData['regular_price_without_tax'] = $this->_applyTaxToPrice($product->getPrice(), false);
124
+ $productData['final_price_with_tax'] = $this->_applyTaxToPrice($finalPrice, true);
125
+ $productData['final_price_without_tax'] = $this->_applyTaxToPrice($finalPrice, false);
126
+
127
+ $productData['is_saleable'] = $product->getIsSalable();
128
+ $productData['image_url'] = (string)Mage::helper('catalog/image')->init($product, 'image');
129
+
130
+ if ($this->getActionType() == self::ACTION_TYPE_ENTITY) {
131
+ // define URLs
132
+ $productData['url'] = $productHelper->getProductUrl($product->getId());
133
+ /** @var $cartHelper Mage_Checkout_Helper_Cart */
134
+ $cartHelper = Mage::helper('checkout/cart');
135
+ $productData['buy_now_url'] = $cartHelper->getAddUrl($product);
136
+
137
+ /** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
138
+ $stockItem = $product->getStockItem();
139
+ if (!$stockItem) {
140
+ $stockItem = Mage::getModel('cataloginventory/stock_item');
141
+ $stockItem->loadByProduct($product);
142
+ }
143
+ $productData['is_in_stock'] = $stockItem->getIsInStock();
144
+
145
+ /** @var $reviewModel Mage_Review_Model_Review */
146
+ $reviewModel = Mage::getModel('review/review');
147
+ $productData['total_reviews_count'] = $reviewModel->getTotalReviews($product->getId(), true,
148
+ $this->_getStore()->getId());
149
+
150
+ $productData['tier_price'] = $this->_getTierPrices();
151
+ $productData['has_custom_options'] = count($product->getOptions()) > 0;
152
+ } else {
153
+ // remove tier price from response
154
+ $product->unsetData('tier_price');
155
+ unset($productData['tier_price']);
156
+ }
157
+ $product->addData($productData);
158
+ }
159
+
160
+ /**
161
+ * Product create only available for admin
162
+ *
163
+ * @param array $data
164
+ */
165
+ protected function _create(array $data)
166
+ {
167
+ $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
168
+ }
169
+
170
+ /**
171
+ * Product update only available for admin
172
+ *
173
+ * @param array $data
174
+ */
175
+ protected function _update(array $data)
176
+ {
177
+ $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
178
+ }
179
+
180
+ /**
181
+ * Product delete only available for admin
182
+ */
183
+ protected function _delete()
184
+ {
185
+ $this->_critical(self::RESOURCE_METHOD_NOT_ALLOWED);
186
+ }
187
+
188
+ /**
189
+ * Load product by its SKU or ID provided in request
190
+ *
191
+ * @return Mage_Catalog_Model_Product
192
+ */
193
+ protected function _getProduct()
194
+ {
195
+ if (is_null($this->_product)) {
196
+ $productId = $this->getRequest()->getParam('id');
197
+ /** @var $productHelper Mage_Catalog_Helper_Product */
198
+ $productHelper = Mage::helper('catalog/product');
199
+ $product = $productHelper->getProduct($productId, $this->_getStore()->getId());
200
+ if (!($product->getId())) {
201
+ $this->_critical(self::RESOURCE_NOT_FOUND);
202
+ }
203
+ // check if product belongs to website current
204
+ if ($this->_getStore()->getId()) {
205
+ $isValidWebsite = in_array($this->_getStore()->getWebsiteId(), $product->getWebsiteIds());
206
+ if (!$isValidWebsite) {
207
+ $this->_critical(self::RESOURCE_NOT_FOUND);
208
+ }
209
+ }
210
+ // Check display settings for customers & guests
211
+ if ($this->getApiUser()->getType() != Mage_Api2_Model_Auth_User_Admin::USER_TYPE) {
212
+ // check if product assigned to any website and can be shown
213
+ if ((!Mage::app()->isSingleStoreMode() && !count($product->getWebsiteIds()))
214
+ || !$productHelper->canShow($product)
215
+ ) {
216
+ $this->_critical(self::RESOURCE_NOT_FOUND);
217
+ }
218
+ }
219
+ $this->_product = $product;
220
+ }
221
+ return $this->_product;
222
+ }
223
+
224
+ /**
225
+ * Set product
226
+ *
227
+ * @param Mage_Catalog_Model_Product $product
228
+ */
229
+ protected function _setProduct(Mage_Catalog_Model_Product $product)
230
+ {
231
+ $this->_product = $product;
232
+ }
233
+
234
+ /**
235
+ * Load category by id
236
+ *
237
+ * @param int $categoryId
238
+ * @return Mage_Catalog_Model_Category
239
+ */
240
+ protected function _getCategoryById($categoryId)
241
+ {
242
+ return Mage::getModel('catalog/category')->load($categoryId);
243
+ }
244
+
245
+ /**
246
+ * Get product price with all tax settings processing
247
+ *
248
+ * @param float $price inputed product price
249
+ * @param bool $includingTax return price include tax flag
250
+ * @param null|Mage_Customer_Model_Address $shippingAddress
251
+ * @param null|Mage_Customer_Model_Address $billingAddress
252
+ * @param null|int $ctc customer tax class
253
+ * @param bool $priceIncludesTax flag that price parameter contain tax
254
+ * @return float
255
+ * @see Mage_Tax_Helper_Data::getPrice()
256
+ */
257
+ protected function _getPrice($price, $includingTax = null, $shippingAddress = null,
258
+ $billingAddress = null, $ctc = null, $priceIncludesTax = null
259
+ )
260
+ {
261
+ $product = $this->_getProduct();
262
+ $store = $this->_getStore();
263
+
264
+ if (is_null($priceIncludesTax)) {
265
+ /** @var $config Mage_Tax_Model_Config */
266
+ $config = Mage::getSingleton('tax/config');
267
+ $priceIncludesTax = $config->priceIncludesTax($store) || $config->getNeedUseShippingExcludeTax();
268
+ }
269
+
270
+ $percent = $product->getTaxPercent();
271
+ $includingPercent = null;
272
+
273
+ $taxClassId = $product->getTaxClassId();
274
+ if (is_null($percent)) {
275
+ if ($taxClassId) {
276
+ $request = Mage::getSingleton('tax/calculation')
277
+ ->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
278
+ $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
279
+ }
280
+ }
281
+ if ($taxClassId && $priceIncludesTax) {
282
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false, $store);
283
+ $includingPercent = Mage::getSingleton('tax/calculation')
284
+ ->getRate($request->setProductClassId($taxClassId));
285
+ }
286
+
287
+ if ($percent === false || is_null($percent)) {
288
+ if ($priceIncludesTax && !$includingPercent) {
289
+ return $price;
290
+ }
291
+ }
292
+ $product->setTaxPercent($percent);
293
+
294
+ if (!is_null($includingTax)) {
295
+ if ($priceIncludesTax) {
296
+ if ($includingTax) {
297
+ /**
298
+ * Recalculate price include tax in case of different rates
299
+ */
300
+ if ($includingPercent != $percent) {
301
+ $price = $this->_calculatePrice($price, $includingPercent, false);
302
+ /**
303
+ * Using regular rounding. Ex:
304
+ * price incl tax = 52.76
305
+ * store tax rate = 19.6%
306
+ * customer tax rate= 19%
307
+ *
308
+ * price excl tax = 52.76 / 1.196 = 44.11371237 ~ 44.11
309
+ * tax = 44.11371237 * 0.19 = 8.381605351 ~ 8.38
310
+ * price incl tax = 52.49531773 ~ 52.50 != 52.49
311
+ *
312
+ * that why we need round prices excluding tax before applying tax
313
+ * this calculation is used for showing prices on catalog pages
314
+ */
315
+ if ($percent != 0) {
316
+ $price = Mage::getSingleton('tax/calculation')->round($price);
317
+ $price = $this->_calculatePrice($price, $percent, true);
318
+ }
319
+ }
320
+ } else {
321
+ $price = $this->_calculatePrice($price, $includingPercent, false);
322
+ }
323
+ } else {
324
+ if ($includingTax) {
325
+ $price = $this->_calculatePrice($price, $percent, true);
326
+ }
327
+ }
328
+ } else {
329
+ if ($priceIncludesTax) {
330
+ if ($includingTax) {
331
+ $price = $this->_calculatePrice($price, $includingPercent, false);
332
+ $price = $this->_calculatePrice($price, $percent, true);
333
+ } else {
334
+ $price = $this->_calculatePrice($price, $includingPercent, false);
335
+ }
336
+ } else {
337
+ if ($includingTax) {
338
+ $price = $this->_calculatePrice($price, $percent, true);
339
+ }
340
+ }
341
+ }
342
+
343
+ return $store->roundPrice($price);
344
+ }
345
+
346
+ /**
347
+ * Calculate price imcluding/excluding tax base on tax rate percent
348
+ *
349
+ * @param float $price
350
+ * @param float $percent
351
+ * @param bool $includeTax true - for calculate price including tax and false if price excluding tax
352
+ * @return float
353
+ */
354
+ protected function _calculatePrice($price, $percent, $includeTax)
355
+ {
356
+ /** @var $calculator Mage_Tax_Model_Calculation */
357
+ $calculator = Mage::getSingleton('tax/calculation');
358
+ $taxAmount = $calculator->calcTaxAmount($price, $percent, !$includeTax, false);
359
+
360
+ return $includeTax ? $price + $taxAmount : $price - $taxAmount;
361
+ }
362
+
363
+ /**
364
+ * Retrive tier prices in special format
365
+ *
366
+ * @return array
367
+ */
368
+ protected function _getTierPrices()
369
+ {
370
+ $tierPrices = array();
371
+ foreach ($this->_getProduct()->getTierPrice() as $tierPrice) {
372
+ $tierPrices[] = array(
373
+ 'qty' => $tierPrice['price_qty'],
374
+ 'price_with_tax' => $this->_applyTaxToPrice($tierPrice['price']),
375
+ 'price_without_tax' => $this->_applyTaxToPrice($tierPrice['price'], false)
376
+ );
377
+ }
378
+ return $tierPrices;
379
+ }
380
+
381
+ /**
382
+ * Default implementation. May be different for customer/guest/admin role.
383
+ *
384
+ * @return null
385
+ */
386
+ protected function _getCustomerGroupId()
387
+ {
388
+ return null;
389
+ }
390
+
391
+ /**
392
+ * Default implementation. May be different for customer/guest/admin role.
393
+ *
394
+ * @param float $price
395
+ * @param bool $withTax
396
+ * @return float
397
+ */
398
+ protected function _applyTaxToPrice($price, $withTax = true)
399
+ {
400
+ return $price;
401
+ }
402
+ }
app/code/core/Mage/Catalog/Model/Api2/Product/Rest/Admin/V1.php ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Catalog
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * API2 for catalog_product (Admin)
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Catalog
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Catalog_Model_Api2_Product_Rest_Admin_V1 extends Mage_Catalog_Model_Api2_Product_Rest
35
+ {
36
+ /**
37
+ * The greatest decimal value which could be stored. Corresponds to DECIMAL (12,4) SQL type
38
+ */
39
+ const MAX_DECIMAL_VALUE = 99999999.9999;
40
+
41
+ /**
42
+ * Add special fields to pro