m2epro_ebay_magento - Version 6.3.0

Version Notes

The M2E Pro extension fully integrates Magento into eBay, Amazon and Rakuten platforms. This allows quick and simple creation as well as management of product listings (inc. automated synchronization of stock levels, pricing, and product details), import of eBay and Amazon order, automated feedback posting for buyers and many other tasks which significantly reduce time required for listing maintenance.

The extension interacts with all 23 major eBay and 7 Amazon marketplaces. It supports multiple eBay/Amazon accounts and multiple Magento stores.

Download this release

Release Info

Developer ESSUA
Extension m2epro_ebay_magento
Version 6.3.0
Comparing to
See all releases


Code changes from version 1.0.3 to 6.3.0

Files changed (184) hide show
  1. app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Grid.php +147 -0
  2. app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Switcher.php +63 -0
  3. app/code/community/Ess/M2ePro/Block/Adminhtml/Category/Grid.php +104 -0
  4. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account.php +71 -0
  5. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Grid.php +105 -0
  6. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Help.php +18 -0
  7. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit.php +144 -0
  8. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Form.php +33 -0
  9. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs.php +49 -0
  10. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/General.php +50 -0
  11. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/ListingOther.php +27 -0
  12. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Order.php +85 -0
  13. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing.php +128 -0
  14. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Form.php +22 -0
  15. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin.php +130 -0
  16. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category.php +159 -0
  17. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category/Grid.php +342 -0
  18. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual.php +161 -0
  19. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/Grid.php +355 -0
  20. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/SkipPopup.php +38 -0
  21. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Review.php +28 -0
  22. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin.php +270 -0
  23. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php +684 -0
  24. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Help.php +20 -0
  25. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NewAsinPopup.php +38 -0
  26. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/SearchSettings.php +71 -0
  27. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/General.php +25 -0
  28. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Search.php +45 -0
  29. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Selling.php +76 -0
  30. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode.php +11 -0
  31. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category.php +23 -0
  32. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Form.php +35 -0
  33. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Group/Grid.php +16 -0
  34. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Global.php +21 -0
  35. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Website.php +21 -0
  36. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit.php +166 -0
  37. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Form.php +35 -0
  38. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Tabs.php +44 -0
  39. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Filter.php +114 -0
  40. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Grid.php +325 -0
  41. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/Grid.php +567 -0
  42. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product.php +97 -0
  43. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product/Help.php +20 -0
  44. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Grid.php +528 -0
  45. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Main.php +61 -0
  46. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Menu.php +88 -0
  47. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/SuggestedAsinGridHelp.php +21 -0
  48. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search.php +161 -0
  49. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search/Grid.php +531 -0
  50. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Grid.php +416 -0
  51. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Main.php +79 -0
  52. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs.php +143 -0
  53. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php +682 -0
  54. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations.php +37 -0
  55. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Child/Form.php +398 -0
  56. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Grid.php +1404 -0
  57. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Help.php +21 -0
  58. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToIndividualPopup.php +47 -0
  59. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToParentPopup.php +47 -0
  60. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View.php +744 -0
  61. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php +1359 -0
  62. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Help.php +20 -0
  63. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ListingSwitcher.php +18 -0
  64. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Magento/Grid.php +336 -0
  65. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.php +41 -0
  66. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php +833 -0
  67. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Marketplace/Form.php +90 -0
  68. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress.php +65 -0
  69. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress/Form.php +55 -0
  70. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Grid.php +558 -0
  71. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View.php +105 -0
  72. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Form.php +110 -0
  73. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Item.php +302 -0
  74. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Synchronization/Form.php +234 -0
  75. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description.php +70 -0
  76. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Edit.php +99 -0
  77. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs.php +71 -0
  78. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Browse.php +28 -0
  79. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Recent.php +42 -0
  80. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Search.php +28 -0
  81. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add.php +71 -0
  82. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add/Grid.php +248 -0
  83. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit.php +103 -0
  84. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Form.php +39 -0
  85. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs.php +58 -0
  86. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Definition.php +141 -0
  87. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/General.php +60 -0
  88. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Specifics.php +36 -0
  89. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Grid.php +223 -0
  90. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Help.php +18 -0
  91. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit.php +101 -0
  92. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit/Form.php +54 -0
  93. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit.php +106 -0
  94. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Form.php +34 -0
  95. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs.php +61 -0
  96. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/List.php +21 -0
  97. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Relist.php +21 -0
  98. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Revise.php +21 -0
  99. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Stop.php +21 -0
  100. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit.php +150 -0
  101. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Form.php +33 -0
  102. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs.php +52 -0
  103. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/General.php +76 -0
  104. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/ListingOther.php +27 -0
  105. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/Order.php +85 -0
  106. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing.php +135 -0
  107. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Form.php +22 -0
  108. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/General.php +25 -0
  109. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Search.php +42 -0
  110. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Selling.php +84 -0
  111. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode.php +11 -0
  112. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category.php +23 -0
  113. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Form.php +11 -0
  114. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Group/Grid.php +16 -0
  115. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Global.php +11 -0
  116. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Website.php +11 -0
  117. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit.php +166 -0
  118. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Form.php +35 -0
  119. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Tabs.php +44 -0
  120. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Filter.php +114 -0
  121. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Grid.php +320 -0
  122. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/Grid.php +530 -0
  123. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product.php +96 -0
  124. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product/Help.php +20 -0
  125. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Grid.php +254 -0
  126. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Main.php +50 -0
  127. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Menu.php +30 -0
  128. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search.php +160 -0
  129. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search/Grid.php +458 -0
  130. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View.php +596 -0
  131. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Grid.php +972 -0
  132. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Help.php +20 -0
  133. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/ListingSwitcher.php +18 -0
  134. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress.php +65 -0
  135. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress/Form.php +56 -0
  136. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Grid.php +434 -0
  137. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View.php +72 -0
  138. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Form.php +112 -0
  139. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Item.php +238 -0
  140. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Synchronization/Form.php +236 -0
  141. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct.php +77 -0
  142. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit.php +85 -0
  143. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Form.php +66 -0
  144. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs.php +52 -0
  145. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Attributes.php +20 -0
  146. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Description.php +73 -0
  147. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/General.php +122 -0
  148. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Grid.php +195 -0
  149. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Help.php +20 -0
  150. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Search/Grid.php +158 -0
  151. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit.php +101 -0
  152. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit/Form.php +50 -0
  153. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit.php +102 -0
  154. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Form.php +33 -0
  155. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs.php +56 -0
  156. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/List.php +20 -0
  157. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Relist.php +21 -0
  158. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Revise.php +21 -0
  159. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Stop.php +20 -0
  160. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Abstract.php +322 -0
  161. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Grid/Container.php +91 -0
  162. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Tabs.php +35 -0
  163. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Tabs/Container.php +19 -0
  164. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing.php +264 -0
  165. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Form.php +93 -0
  166. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Main.php +20 -0
  167. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Review.php +92 -0
  168. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceCategory.php +127 -0
  169. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceMode.php +64 -0
  170. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceMode/Form.php +56 -0
  171. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceProduct.php +126 -0
  172. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/StepOne.php +57 -0
  173. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/StepThree.php +70 -0
  174. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/StepTwo.php +72 -0
  175. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Tabs/General.php +54 -0
  176. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Tabs/Search.php +73 -0
  177. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Tabs/Selling.php +137 -0
  178. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Breadcrumb.php +21 -0
  179. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Category/Tree.php +379 -0
  180. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Help.php +14 -0
  181. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Log.php +241 -0
  182. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Log/Grid.php +51 -0
  183. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Log/Help.php +20 -0
  184. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Other.php +222 -0
app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Grid.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ abstract class Ess_M2ePro_Block_Adminhtml_Account_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ protected $viewComponentHelper = NULL;
10
+
11
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialize view
18
+ //------------------------------
19
+ $view = Mage::helper('M2ePro/View')->getCurrentView();
20
+ $this->viewComponentHelper = Mage::helper('M2ePro/View')->getComponentHelper($view);
21
+ //------------------------------
22
+
23
+ // Initialization block
24
+ //------------------------------
25
+ $this->setId($view . 'AccountGrid');
26
+ //------------------------------
27
+
28
+ // Set default values
29
+ //------------------------------
30
+ $this->setDefaultSort('title');
31
+ $this->setDefaultDir('ASC');
32
+ $this->setSaveParametersInSession(true);
33
+ $this->setUseAjax(true);
34
+ //------------------------------
35
+ }
36
+
37
+ // ####################################
38
+
39
+ protected function _prepareCollection()
40
+ {
41
+ // Get collection of accounts
42
+ $collection = $this->getCollection();
43
+ if (is_null($collection)) {
44
+ $collection = Mage::getModel('M2ePro/Account')->getCollection();
45
+ }
46
+
47
+ $components = $this->viewComponentHelper->getActiveComponents();
48
+ $collection->addFieldToFilter('main_table.component_mode', array('in'=>$components));
49
+
50
+ // Set collection to grid
51
+ $this->setCollection($collection);
52
+
53
+ return parent::_prepareCollection();
54
+ }
55
+
56
+ protected function _prepareColumns()
57
+ {
58
+ $this->addColumn('create_date', array(
59
+ 'header' => Mage::helper('M2ePro')->__('Creation Date'),
60
+ 'align' => 'left',
61
+ 'width' => '150px',
62
+ 'type' => 'datetime',
63
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
64
+ 'index' => 'create_date',
65
+ 'filter_index' => 'main_table.create_date'
66
+ ));
67
+
68
+ $this->addColumn('update_date', array(
69
+ 'header' => Mage::helper('M2ePro')->__('Update Date'),
70
+ 'align' => 'left',
71
+ 'width' => '150px',
72
+ 'type' => 'datetime',
73
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
74
+ 'index' => 'update_date',
75
+ 'filter_index' => 'main_table.update_date'
76
+ ));
77
+
78
+ $confirm = 'Attention! By deleting account you delete all information on it from M2E Pro server. ';
79
+ $confirm .= 'This will cause inappropriate work of all accounts\' copies.';
80
+ $confirm = Mage::helper('M2ePro')->__($confirm);
81
+
82
+ $this->addColumn('actions', array(
83
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
84
+ 'align' => 'left',
85
+ 'width' => '150px',
86
+ 'type' => 'action',
87
+ 'index' => 'actions',
88
+ 'filter' => false,
89
+ 'sortable' => false,
90
+ 'getter' => 'getId',
91
+ 'actions' => array(
92
+ array(
93
+ 'caption' => Mage::helper('M2ePro')->__('Edit'),
94
+ 'url' => array('base'=> '*/*/edit'),
95
+ 'field' => 'id'
96
+ ),
97
+ array(
98
+ 'caption' => Mage::helper('M2ePro')->__('Delete'),
99
+ 'url' => array('base'=> '*/*/delete'),
100
+ 'field' => 'id',
101
+ 'confirm' => $confirm
102
+ )
103
+ )
104
+ ));
105
+
106
+ return parent::_prepareColumns();
107
+ }
108
+
109
+ protected function _prepareMassaction()
110
+ {
111
+ // Set massaction identifiers
112
+ //--------------------------------
113
+ $this->setMassactionIdField('main_table.id');
114
+ $this->getMassactionBlock()->setFormFieldName('ids');
115
+ //--------------------------------
116
+
117
+ // Set delete action
118
+ //--------------------------------
119
+ $confirm = 'Attention! By deleting account you delete all information on it from M2E Pro Server. ';
120
+ $confirm .= 'This will cause inappropriate work of all accounts\' copies.';
121
+ $confirm = Mage::helper('M2ePro')->__($confirm);
122
+
123
+ $this->getMassactionBlock()->addItem('delete', array(
124
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
125
+ 'url' => $this->getUrl('*/*/delete'),
126
+ 'confirm' => $confirm
127
+ ));
128
+ //--------------------------------
129
+
130
+ return parent::_prepareMassaction();
131
+ }
132
+
133
+ // ####################################
134
+
135
+ public function getGridUrl()
136
+ {
137
+ return $this->getUrl('*/*/accountGrid', array('_current'=>true));
138
+ }
139
+
140
+ public function getRowUrl($row)
141
+ {
142
+ return Mage::helper('M2ePro/View')
143
+ ->getUrl($row, 'account', 'edit', array('id' => $row->getData('id')));
144
+ }
145
+
146
+ // ####################################
147
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Switcher.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Account_Switcher extends Ess_M2ePro_Block_Adminhtml_Component_Switcher
8
+ {
9
+ protected $paramName = 'account';
10
+
11
+ // ########################################
12
+
13
+ public function getLabel()
14
+ {
15
+ return Mage::helper('M2ePro')->__($this->getComponentLabel('%component% Account'));
16
+ }
17
+
18
+ public function getItems()
19
+ {
20
+ $collection = Mage::getModel('M2ePro/Account')->getCollection()
21
+ ->setOrder('component_mode', 'ASC')
22
+ ->setOrder('title', 'ASC');
23
+
24
+ if (!is_null($this->getData('component_mode'))) {
25
+ $collection->addFieldToFilter('component_mode', $this->getData('component_mode'));
26
+ }
27
+
28
+ if ($collection->getSize() < 2) {
29
+ return array();
30
+ }
31
+
32
+ $items = array();
33
+
34
+ foreach ($collection as $account) {
35
+ /** @var $account Ess_M2ePro_Model_Account */
36
+
37
+ if (!isset($items[$account->getComponentMode()]['label'])) {
38
+ $label = '';
39
+ if (isset($componentTitles[$account->getComponentMode()])) {
40
+ $label = $componentTitles[$account->getComponentMode()];
41
+ }
42
+
43
+ $items[$account->getComponentMode()]['label'] = $label;
44
+ }
45
+
46
+ $items[$account->getComponentMode()]['value'][] = array(
47
+ 'value' => $account->getId(),
48
+ 'label' => $account->getTitle()
49
+ );
50
+ }
51
+
52
+ return $items;
53
+ }
54
+
55
+ // ########################################
56
+
57
+ public function getDefaultOptionName()
58
+ {
59
+ return Mage::helper('M2ePro')->__('All Accounts');
60
+ }
61
+
62
+ // ########################################
63
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Category/Grid.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Category_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ // ####################################
10
+
11
+ public function getStoreId()
12
+ {
13
+ return !is_null($this->getData('store_id')) ? $this->getData('store_id') : Mage_Core_Model_App::ADMIN_STORE_ID;
14
+ }
15
+
16
+ public function setStoreId($storeId)
17
+ {
18
+ $this->setData('store_id',$storeId);
19
+ return $this;
20
+ }
21
+
22
+ // ####################################
23
+
24
+ public function setCollection($collection)
25
+ {
26
+ $this->_prepareCache(clone $collection);
27
+ parent::setCollection($collection);
28
+ }
29
+
30
+ protected function _prepareCache($collection)
31
+ {
32
+ $stmt = $collection->getSelect()->query();
33
+
34
+ $ids = array();
35
+ foreach ($stmt as $item) {
36
+ $ids = array_merge($ids,array_map('intval',explode('/',$item['path'])));
37
+ }
38
+ $ids = array_unique($ids);
39
+
40
+ if (empty($ids)) {
41
+ return;
42
+ }
43
+
44
+ /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
45
+ $attribute = $collection->getFirstItem()->getResource()->getAttribute('name');
46
+
47
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
48
+
49
+ $tableName = Mage_Catalog_Model_Category::ENTITY . '_entity_' . $attribute->getBackendType();
50
+
51
+ $dbSelect1 = $connRead
52
+ ->select()
53
+ ->from(Mage::getSingleton('core/resource')->getTableName($tableName), new Zend_Db_Expr('MAX(`store_id`)'))
54
+ ->where("`entity_id` = `ccev`.`entity_id`")
55
+ ->where("`attribute_id` = `ccev`.`attribute_id`")
56
+ ->where("`store_id` = 0 OR `store_id` = ?",$this->getStoreId());
57
+
58
+ $dbSelect2 = $connRead
59
+ ->select()
60
+ ->from(
61
+ array('ccev' => Mage::getSingleton('core/resource')->getTableName($tableName)),
62
+ array('name' => 'value','category_id' => 'entity_id')
63
+ )
64
+ ->where('ccev.entity_id IN ('.implode(',',$ids).')')
65
+ ->where('ccev.attribute_id = ?', $attribute->getAttributeId())
66
+ ->where('ccev.entity_type_id = ?', $attribute->getEntityTypeId())
67
+ ->where('ccev.store_id = ('.$dbSelect1->__toString().')');
68
+
69
+ $cacheData = array();
70
+
71
+ foreach ($connRead->fetchAll($dbSelect2) as $row) {
72
+ $cacheData[$row['category_id']] = $row['name'];
73
+ }
74
+ $this->setData('categories_cache', $cacheData);
75
+ }
76
+
77
+ // ####################################
78
+
79
+ public function callbackColumnMagentoCategory($value, $row, $column, $isExport)
80
+ {
81
+ $ids = explode('/',$row->getPath());
82
+
83
+ $categoriesCache = $this->getData('categories_cache');
84
+ $path = '';
85
+ foreach ($ids as $id) {
86
+ if (!isset($categoriesCache[$id])) {
87
+ continue;
88
+ }
89
+ $path != '' && $path .= ' > ';
90
+ $path .= $categoriesCache[$id];
91
+ }
92
+
93
+ return Mage::helper('M2ePro')->escapeHtml($path);
94
+ }
95
+
96
+ // ####################################
97
+
98
+ public function getMultipleRows($item)
99
+ {
100
+ return false;
101
+ }
102
+
103
+ // ####################################
104
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Account extends Ess_M2ePro_Block_Adminhtml_Common_Component_Grid_Container
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('account');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_account';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $this->_headerText = Mage::helper('M2ePro')->__('Accounts');
25
+ //------------------------------
26
+
27
+ // Set buttons actions
28
+ //------------------------------
29
+ $this->removeButton('back');
30
+ $this->removeButton('reset');
31
+ $this->removeButton('delete');
32
+ $this->removeButton('add');
33
+ $this->removeButton('save');
34
+ $this->removeButton('edit');
35
+
36
+ //------------------------------
37
+ $this->_addButton('add', array(
38
+ 'label' => Mage::helper('M2ePro')->__('Add Account'),
39
+ 'onclick' => $this->getAddButtonOnClickAction(),
40
+ 'class' => 'add add-button-drop-down'
41
+ ));
42
+ //------------------------------
43
+ }
44
+
45
+ // ########################################
46
+
47
+ protected function getAmazonNewUrl()
48
+ {
49
+ return $this->getUrl('*/adminhtml_common_amazon_account/new');
50
+ }
51
+
52
+ protected function getBuyNewUrl()
53
+ {
54
+ return $this->getUrl('*/adminhtml_common_buy_account/new');
55
+ }
56
+
57
+ protected function getPlayNewUrl()
58
+ {
59
+ return $this->getUrl('*/adminhtml_common_play_account/new');
60
+ }
61
+
62
+ // ########################################
63
+
64
+ public function getGridHtml()
65
+ {
66
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_account_help');
67
+ return $helpBlock->toHtml() . parent::getGridHtml();
68
+ }
69
+
70
+ // ########################################
71
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Grid.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Account_Grid extends Ess_M2ePro_Block_Adminhtml_Account_Grid
8
+ {
9
+
10
+ protected function _prepareCollection()
11
+ {
12
+ // Get collection of accounts
13
+ $collection = Mage::getModel('M2ePro/Account')->getCollection();
14
+
15
+ $collection->getSelect()
16
+ ->joinLeft(array('aa'=>Mage::getResourceModel('M2ePro/Amazon_Account')->getMainTable()),
17
+ '(`aa`.`account_id` = `main_table`.`id`)',
18
+ array())
19
+ ->joinLeft(array('m'=>Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
20
+ '(`m`.`id` = `aa`.`marketplace_id`)',
21
+ array('marketplace_title'=>'title'));
22
+
23
+ // Set collection to grid
24
+ $this->setCollection($collection);
25
+
26
+ return parent::_prepareCollection();
27
+ }
28
+
29
+ // ####################################
30
+
31
+ protected function _prepareColumns()
32
+ {
33
+ $this->addColumn('id', array(
34
+ 'header' => Mage::helper('M2ePro')->__('ID'),
35
+ 'align' => 'right',
36
+ 'width' => '100px',
37
+ 'type' => 'number',
38
+ 'index' => 'id',
39
+ 'filter_index' => 'main_table.id'
40
+ ));
41
+
42
+ $this->addColumn('title', array(
43
+ 'header' => Mage::helper('M2ePro')->__('Title / Info'),
44
+ 'align' => 'left',
45
+ //'width' => '200px',
46
+ 'type' => 'text',
47
+ 'index' => 'title',
48
+ 'escape' => true,
49
+ 'filter_index' => 'main_table.title',
50
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
51
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
52
+ ));
53
+
54
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
55
+ $this->addColumn('component_mode', array(
56
+ 'header' => Mage::helper('M2ePro')->__('Channel'),
57
+ 'align' => 'left',
58
+ 'width' => '120px',
59
+ 'type' => 'options',
60
+ 'index' => 'component_mode',
61
+ 'filter_index' => 'main_table.component_mode',
62
+ 'sortable' => false,
63
+ 'options' => Mage::helper('M2ePro/View_Common_Component')->getActiveComponentsTitles()
64
+ ));
65
+ }
66
+
67
+ return parent::_prepareColumns();
68
+ }
69
+
70
+ // ####################################
71
+
72
+ public function callbackColumnTitle($value, $row, $column, $isExport)
73
+ {
74
+ if ($row->isComponentModeAmazon()) {
75
+ $account = Mage::helper('M2ePro')->__('Account');
76
+ $marketplace = Mage::helper('M2ePro')->__('Marketplace');
77
+
78
+ $marketplaceTitle = $row->getData('marketplace_title');
79
+ $value = <<<HTML
80
+ <div>
81
+ {$value}<br/>
82
+ <span style="font-weight: bold">{$marketplace}</span>: <span style="color: #505050">{$marketplaceTitle}</span><br/>
83
+ </div>
84
+ HTML;
85
+ }
86
+
87
+ return $value;
88
+ }
89
+
90
+ // ####################################
91
+
92
+ protected function callbackFilterTitle($collection, $column)
93
+ {
94
+ $value = $column->getFilter()->getValue();
95
+
96
+ if ($value == null) {
97
+ return;
98
+ }
99
+
100
+ $where = "main_table.title LIKE '%{$value}%' OR m.title LIKE '%{$value}%'";
101
+ $collection->getSelect()->where($where);
102
+ }
103
+
104
+ // ####################################
105
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Help.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Account_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+ $this->setTemplate('M2ePro/common/account/help.phtml');
15
+ }
16
+
17
+ // ########################################
18
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonAccountEdit');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_amazon_account';
18
+ $this->_mode = 'edit';
19
+ //------------------------------
20
+
21
+ // Set header text
22
+ //------------------------------
23
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
24
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
25
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit %component_name% Account", $componentName);
26
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add %component_name% Account", $componentName);
27
+ } else {
28
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit Account");
29
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add Account");
30
+ }
31
+
32
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
33
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
34
+ ) {
35
+ $this->_headerText = $headerTextEdit;
36
+ $this->_headerText .= ' "'.$this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
37
+ ->getTitle()).'"';
38
+ } else {
39
+ $this->_headerText = $headerTextAdd;
40
+ }
41
+ //------------------------------
42
+
43
+ // Set buttons actions
44
+ //------------------------------
45
+ $this->removeButton('back');
46
+ $this->removeButton('reset');
47
+ $this->removeButton('delete');
48
+ $this->removeButton('add');
49
+ $this->removeButton('save');
50
+ $this->removeButton('edit');
51
+ //------------------------------
52
+
53
+ /* @var $wizardHelper Ess_M2ePro_Helper_Module_Wizard */
54
+ $wizardHelper = Mage::helper('M2ePro/Module_Wizard');
55
+
56
+ if ($wizardHelper->isActive('amazon') &&
57
+ $wizardHelper->getStep('amazon') == 'account') {
58
+
59
+ //------------------------------
60
+ $this->_addButton('save_and_continue', array(
61
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
62
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
63
+ 'class' => 'save'
64
+ ));
65
+ //------------------------------
66
+
67
+ if ($this->getRequest()->getParam('id')) {
68
+ //------------------------------
69
+ $url = $this->getUrl('*/adminhtml_common_amazon_account/new', array('wizard' => true));
70
+ $this->_addButton('add_new_account', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Add New Account'),
72
+ 'onclick' => 'setLocation(\''. $url .'\')',
73
+ 'class' => 'add_new_account'
74
+ ));
75
+ //------------------------------
76
+
77
+ //------------------------------
78
+ $this->_addButton('close', array(
79
+ 'label' => Mage::helper('M2ePro')->__('Complete This Step'),
80
+ 'onclick' => 'AmazonAccountHandlerObj.completeStep();',
81
+ 'class' => 'close'
82
+ ));
83
+ //------------------------------
84
+ }
85
+ } else {
86
+
87
+ if ((bool)$this->getRequest()->getParam('close_on_save',false)) {
88
+
89
+ if ($this->getRequest()->getParam('id')) {
90
+ $this->_addButton('save', array(
91
+ 'label' => Mage::helper('M2ePro')->__('Save And Close'),
92
+ 'onclick' => 'AmazonAccountHandlerObj.saveAndClose()',
93
+ 'class' => 'save'
94
+ ));
95
+ } else {
96
+ $this->_addButton('save_and_continue', array(
97
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
98
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
99
+ 'class' => 'save'
100
+ ));
101
+ }
102
+ return;
103
+ }
104
+
105
+ //------------------------------
106
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
107
+ $this->_addButton('back', array(
108
+ 'label' => Mage::helper('M2ePro')->__('Back'),
109
+ 'onclick' => 'AmazonAccountHandlerObj.back_click(\''. $url .'\')',
110
+ 'class' => 'back'
111
+ ));
112
+ //------------------------------
113
+
114
+ //------------------------------
115
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
116
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
117
+ ) {
118
+ //------------------------------
119
+ $this->_addButton('delete', array(
120
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
121
+ 'onclick' => 'AmazonAccountHandlerObj.delete_click()',
122
+ 'class' => 'delete M2ePro_delete_button'
123
+ ));
124
+ //------------------------------
125
+ }
126
+
127
+ //------------------------------
128
+ $this->_addButton('save', array(
129
+ 'label' => Mage::helper('M2ePro')->__('Save'),
130
+ 'onclick' => 'AmazonAccountHandlerObj.save_click()',
131
+ 'class' => 'save'
132
+ ));
133
+ //------------------------------
134
+
135
+ //------------------------------
136
+ $this->_addButton('save_and_continue', array(
137
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
138
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
139
+ 'class' => 'save'
140
+ ));
141
+ //------------------------------
142
+ }
143
+ }
144
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Form.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonAccountEditForm');
16
+ //------------------------------
17
+ }
18
+
19
+ protected function _prepareForm()
20
+ {
21
+ $form = new Varien_Data_Form(array(
22
+ 'id' => 'edit_form',
23
+ 'action' => $this->getUrl('*/*/save'),
24
+ 'method' => 'post',
25
+ 'enctype' => 'multipart/form-data'
26
+ ));
27
+
28
+ $form->setUseContainer(true);
29
+ $this->setForm($form);
30
+
31
+ return parent::_prepareForm();
32
+ }
33
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonAccountEditTabs');
16
+ //------------------------------
17
+
18
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
19
+ $this->setDestElementId('edit_form');
20
+ }
21
+
22
+ protected function _beforeToHtml()
23
+ {
24
+ $this->addTab('general', array(
25
+ 'label' => Mage::helper('M2ePro')->__('General'),
26
+ 'title' => Mage::helper('M2ePro')->__('General'),
27
+ 'content' => $this->getLayout()
28
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_general')->toHtml(),
29
+ ));
30
+
31
+ $this->addTab('listingOther', array(
32
+ 'label' => Mage::helper('M2ePro')->__('3rd Party Listings'),
33
+ 'title' => Mage::helper('M2ePro')->__('3rd Party Listings'),
34
+ 'content' => $this->getLayout()
35
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_listingOther')->toHtml(),
36
+ ));
37
+
38
+ $this->addTab('orders', array(
39
+ 'label' => Mage::helper('M2ePro')->__('Orders'),
40
+ 'title' => Mage::helper('M2ePro')->__('Orders'),
41
+ 'content' => $this->getLayout()
42
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_order')->toHtml(),
43
+ ));
44
+
45
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
46
+
47
+ return parent::_beforeToHtml();
48
+ }
49
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/General.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs_General extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonAccountEditTabsGeneral');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/general.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ $this->synchronizeProcessing = false;
24
+
25
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
26
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) {
27
+
28
+ /** @var $accountObj Ess_M2ePro_Model_Account */
29
+ $accountObj = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
30
+
31
+ $this->synchronizeProcessing = $accountObj->isLockedObject('server_synchronize');
32
+
33
+ if (!$this->synchronizeProcessing) {
34
+ $accountId = $accountObj->getId();
35
+
36
+ Mage::helper('M2ePro/Data_Global')->unsetValue('temp_data');
37
+ Mage::helper('M2ePro/Data_Global')->setValue(
38
+ 'temp_data',
39
+ Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Account',$accountId)
40
+ );
41
+ }
42
+ }
43
+
44
+ $marketplaces = Mage::helper('M2ePro/Component_Amazon')->getMarketplacesAvailableForApiCreation();
45
+ $marketplaces = $marketplaces->toArray();
46
+ $this->marketplaces = $marketplaces['items'];
47
+
48
+ return parent::_beforeToHtml();
49
+ }
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/ListingOther.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs_ListingOther extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonAccountEditTabsListingOther');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/listing_other.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
24
+
25
+ return parent::_beforeToHtml();
26
+ }
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Order.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs_Order extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ protected $_possibleMagentoStatuses = null;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonAccountEditTabsOrder');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/order.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
26
+ $magentoOrdersSettings = !empty($data['magento_orders_settings'])
27
+ ? json_decode($data['magento_orders_settings'], true) : array();
28
+
29
+ //----------------------------
30
+ $temp = Mage::getModel('core/website')->getCollection()->setOrder('sort_order','ASC')->toArray();
31
+ $this->websites = $temp['items'];
32
+ //----------------------------
33
+
34
+ //----------------------------
35
+ $temp = Mage::getModel('customer/group')->getCollection()->toArray();
36
+ $this->groups = $temp['items'];
37
+ //----------------------------
38
+
39
+ //----------------------------
40
+ $selectedStore = !empty($magentoOrdersSettings['listing']['store_id'])
41
+ ? $magentoOrdersSettings['listing']['store_id'] : '';
42
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
43
+ 'id' => 'magento_orders_listings_store_id',
44
+ 'name' => 'magento_orders_settings[listing][store_id]',
45
+ 'selected' => $selectedStore
46
+ ));
47
+ $blockStoreSwitcher->hasDefaultOption(false);
48
+ $this->setChild('magento_orders_listings_store_id', $blockStoreSwitcher);
49
+ //----------------------------
50
+
51
+ //----------------------------
52
+ $selectedStore = !empty($magentoOrdersSettings['listing_other']['store_id'])
53
+ ? $magentoOrdersSettings['listing_other']['store_id'] : '';
54
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
55
+ 'id' => 'magento_orders_listings_other_store_id',
56
+ 'name' => 'magento_orders_settings[listing_other][store_id]',
57
+ 'selected' => $selectedStore
58
+ ));
59
+ $blockStoreSwitcher->hasDefaultOption(false);
60
+ $this->setChild('magento_orders_listings_other_store_id', $blockStoreSwitcher);
61
+ //----------------------------
62
+
63
+ //----------------------------
64
+ $productTaxClasses = Mage::getModel('tax/class')->getCollection()
65
+ ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)
66
+ ->toOptionArray();
67
+
68
+ $none = array('value' => Ess_M2ePro_Model_Magento_Product::TAX_CLASS_ID_NONE, 'label' => 'None');
69
+ array_unshift($productTaxClasses, $none);
70
+
71
+ $this->productTaxClasses = $productTaxClasses;
72
+ //----------------------------
73
+
74
+ return parent::_beforeToHtml();
75
+ }
76
+
77
+ public function getMagentoOrderStatusList()
78
+ {
79
+ if (is_null($this->_possibleMagentoStatuses)) {
80
+ $this->_possibleMagentoStatuses = Mage::getSingleton('sales/order_config')->getStatuses();
81
+ }
82
+
83
+ return $this->_possibleMagentoStatuses;
84
+ }
85
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListing');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_amazon_listing';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $this->_headerText = '';
25
+ //------------------------------
26
+
27
+ // Set buttons actions
28
+ //------------------------------
29
+ $this->removeButton('back');
30
+ $this->removeButton('reset');
31
+ $this->removeButton('delete');
32
+ $this->removeButton('add');
33
+ $this->removeButton('save');
34
+ $this->removeButton('edit');
35
+ //------------------------------
36
+
37
+ //------------------------------
38
+
39
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
40
+ '*/adminhtml_common_listing/index',
41
+ array(
42
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
43
+ )
44
+ );
45
+
46
+ //------------------------------
47
+ $url = $this->getUrl(
48
+ '*/adminhtml_common_log/listing',
49
+ array(
50
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_AMAZON
51
+ )
52
+ );
53
+ $this->_addButton('view_log', array(
54
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
55
+ 'onclick' => 'window.open(\'' . $url . '\')',
56
+ 'class' => 'button_link'
57
+ ));
58
+ //------------------------------
59
+
60
+ //------------------------------
61
+ $url = $this->getUrl(
62
+ '*/adminhtml_common_amazon_listing/search',
63
+ array(
64
+ 'back' => $backUrl
65
+ )
66
+ );
67
+ $this->_addButton('search_amazon_products', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Search'),
69
+ 'onclick' => 'setLocation(\'' . $url . '\')',
70
+ 'class' => 'button_link search'
71
+ ));
72
+ //------------------------------
73
+
74
+ //------------------------------
75
+ $url = $this->getUrl('*/adminhtml_common_listing_create/index', array(
76
+ 'step' => '1',
77
+ 'clear' => 'yes',
78
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
79
+ ));
80
+ $this->_addButton('add', array(
81
+ 'label' => Mage::helper('M2ePro')->__('Add Listing'),
82
+ 'onclick' => 'setLocation(\'' . $url . '\')',
83
+ 'class' => 'add'
84
+ ));
85
+ //------------------------------
86
+ }
87
+
88
+ // ####################################
89
+
90
+ public function getTemplatesButtonJavascript()
91
+ {
92
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown', '', array(
93
+ 'target_css_class' => 'amazon-templates-drop-down',
94
+ 'items' => $this->getTemplatesButtonDropDownItems()
95
+ ));
96
+
97
+ return $dropDownBlock->toHtml();
98
+ }
99
+
100
+ protected function getTemplatesButtonDropDownItems()
101
+ {
102
+ $items = array();
103
+
104
+ $filter = base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Amazon::NICK);
105
+
106
+ //------------------------------
107
+ $url = $this->getUrl('*/adminhtml_common_template_sellingFormat/index', array('filter' => $filter));
108
+ $items[] = array(
109
+ 'url' => $url,
110
+ 'label' => Mage::helper('M2ePro')->__('Selling Format Policies'),
111
+ 'target' => '_blank'
112
+ );
113
+ //------------------------------
114
+
115
+ //------------------------------
116
+ $url = $this->getUrl('*/adminhtml_common_template_synchronization/index', array('filter' => $filter));
117
+ $items[] = array(
118
+ 'url' => $url,
119
+ 'label' => Mage::helper('M2ePro')->__('Synchronization Policies'),
120
+ 'target' => '_blank'
121
+ );
122
+ //------------------------------
123
+
124
+ return $items;
125
+ }
126
+
127
+ // ####################################
128
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Form.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Form
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Form
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->component = Ess_M2ePro_Helper_Component_Amazon::NICK;
17
+ $this->setId('amazonListingEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ // ########################################
22
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingAddNewAsin');
18
+ //------------------------------
19
+
20
+ $this->_headerText = Mage::helper('M2ePro')->__('New ASIN/ISBN Creation');
21
+
22
+ $url = $this->getUrl('*/*/index', array(
23
+ 'step' => 1,
24
+ '_current' => true
25
+ ));
26
+ $this->_addButton('back', array(
27
+ 'label' => Mage::helper('M2ePro')->__('Back'),
28
+ 'class' => 'back',
29
+ 'onclick' => 'setLocation(\''.$url.'\');'
30
+ ));
31
+
32
+ $this->_addButton('next', array(
33
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
34
+ 'class' => 'scalable next',
35
+ 'onclick' => "descriptionTemplateModeFormSubmit()"
36
+ ));
37
+
38
+ $this->setTemplate('M2ePro/common/amazon/listing/add/new_asin.phtml');
39
+ }
40
+
41
+ // ####################################
42
+
43
+ public function getHeaderCssClass()
44
+ {
45
+ return 'icon-head ' . parent::getHeaderCssClass();
46
+ }
47
+
48
+ public function getHeaderWidth()
49
+ {
50
+ return 'width:50%;';
51
+ }
52
+
53
+ // ####################################
54
+
55
+ protected function _beforeToHtml()
56
+ {
57
+ parent::_beforeToHtml();
58
+
59
+ $listing = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
60
+ 'Listing', $this->getRequest()->getParam('id')
61
+ );
62
+
63
+ $viewHeaderBlock = $this->getLayout()->createBlock(
64
+ 'M2ePro/adminhtml_listing_view_header','',
65
+ array('listing' => $listing)
66
+ );
67
+
68
+ $this->setChild('view_header', $viewHeaderBlock);
69
+
70
+ // ------------------------------------------------
71
+ $buttonBlock = $this->getLayout()
72
+ ->createBlock('adminhtml/widget_button')
73
+ ->setData( array(
74
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
75
+ 'onclick' => '',
76
+ ) );
77
+ $this->setChild('mode_same_remember_pop_up_confirm_button',$buttonBlock);
78
+ }
79
+
80
+ // ####################################
81
+
82
+ /**
83
+ * @return Ess_M2ePro_Model_Listing
84
+ * @throws Exception
85
+ */
86
+ public function getListing()
87
+ {
88
+ if (!$listingId = $this->getRequest()->getParam('id')) {
89
+ throw new Exception('Listing is not defined');
90
+ }
91
+
92
+ if (is_null($this->listing)) {
93
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
94
+ ->getObject('Listing', $listingId);
95
+ }
96
+
97
+ return $this->listing;
98
+ }
99
+
100
+ // ####################################
101
+
102
+ public function getProductsIds()
103
+ {
104
+ return $this->getListing()->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
105
+ }
106
+
107
+ // ####################################
108
+
109
+ public function getDescriptionTemplateMode()
110
+ {
111
+ $listingAdditionalData = $this->getListing()->getData('additional_data');
112
+ $listingAdditionalData = json_decode($listingAdditionalData, true);
113
+
114
+ $mode = 'same';
115
+
116
+ $sessionMode = Mage::helper('M2ePro/Data_Session')->getValue('products_source');
117
+ if ($sessionMode == 'category') {
118
+ $mode = $sessionMode;
119
+ }
120
+
121
+ if (!empty($listingAdditionalData['new_asin_mode'])) {
122
+ $mode = $listingAdditionalData['new_asin_mode'];
123
+ }
124
+
125
+ return $mode;
126
+ }
127
+
128
+ // ####################################
129
+
130
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category.php ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Category
8
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('newAsinDescriptionTemplateCategory');
17
+ //------------------------------
18
+
19
+ // Set header text
20
+ //------------------------------
21
+ $this->_headerText = Mage::helper('M2ePro')->__("Set Description Policy for New ASIN/ISBN Creation");
22
+ $this->_blockGroup = 'M2ePro';
23
+ $this->_controller = 'adminhtml_common_amazon_listing_add_newAsin_category';
24
+ //------------------------------
25
+
26
+ // Set buttons actions
27
+ //------------------------------
28
+ $this->removeButton('back');
29
+ $this->removeButton('reset');
30
+ $this->removeButton('delete');
31
+ $this->removeButton('add');
32
+ $this->removeButton('save');
33
+ $this->removeButton('edit');
34
+ //------------------------------
35
+
36
+ //------------------------------
37
+ $url = $this->getUrl('*/*/resetNewAsin', array(
38
+ '_current' => true
39
+ ));
40
+ $this->_addButton('back', array(
41
+ 'label' => Mage::helper('M2ePro')->__('Back'),
42
+ 'onclick' => 'ListingGridHandlerObj.back_click(\'' . $url . '\')',
43
+ 'class' => 'back'
44
+ ));
45
+ //------------------------------
46
+
47
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
48
+ //------------------------------
49
+ $this->_addButton('save_and_go_to_listing_view', array(
50
+ 'id' => 'save_and_go_to_listing_view',
51
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
52
+ 'onclick' => 'ListingGridHandlerObj.checkCategoryProducts(\''.$url.'\')',
53
+ 'class' => 'scalable next'
54
+ ));
55
+ //------------------------------
56
+ }
57
+
58
+ public function getGridHtml()
59
+ {
60
+ $listing = Mage::helper('M2ePro/Component')
61
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
62
+
63
+ $viewHeaderBlock = $this->getLayout()->createBlock(
64
+ 'M2ePro/adminhtml_listing_view_header','',
65
+ array('listing' => $listing)
66
+ );
67
+
68
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml();
69
+ }
70
+
71
+ protected function _toHtml()
72
+ {
73
+ $helper = Mage::helper('M2ePro');
74
+
75
+ // --------TEXT------------------
76
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
77
+ // -------------------------------
78
+
79
+ // ---------URL-------------------
80
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
81
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
82
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
83
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
84
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/*/viewTemplateDescriptionsGrid');
85
+
86
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
87
+ $unmapFromNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
88
+
89
+ $checkNewAsinCategoryProducts = $this->getUrl('*/*/checkNewAsinCategoryProducts', array('_current' => true));
90
+ // -------------------------------
91
+
92
+ $javascript = <<<HTML
93
+ <script type="text/javascript">
94
+ selectTemplateDescription = function (el, templateId, mapToGeneralId)
95
+ {
96
+ ListingGridHandlerObj.mapToTemplateDescription(el, templateId, mapToGeneralId);
97
+ };
98
+
99
+ if (typeof M2ePro == 'undefined') {
100
+ M2ePro = {};
101
+ M2ePro.url = {};
102
+ M2ePro.formData = {};
103
+ M2ePro.customData = {};
104
+ M2ePro.text = {};
105
+ }
106
+
107
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
108
+
109
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
110
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
111
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
112
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
113
+
114
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
115
+ M2ePro.url.unmapFromNewAsin = '{$unmapFromNewAsin}';
116
+
117
+ M2ePro.url.checkNewAsinCategoryProducts = '{$checkNewAsinCategoryProducts}';
118
+
119
+ Event.observe(window, 'load', function() {
120
+
121
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
122
+
123
+ ListingGridHandlerObj = new NewAsinTemplateDescriptionGridHandler(
124
+ '{$this->getChild('grid')->getId()}',
125
+ {$this->getListing()->getId()}
126
+ );
127
+
128
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
129
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
130
+ });
131
+
132
+ </script>
133
+ HTML;
134
+
135
+ return $javascript .
136
+ '<div id="search_asin_products_container">' .
137
+ parent::_toHtml() .
138
+ '</div>';
139
+ }
140
+
141
+ // ####################################
142
+
143
+ public function getListing()
144
+ {
145
+ if (!$listingId = $this->getRequest()->getParam('id')) {
146
+ throw new Exception('Listing is not defined');
147
+ }
148
+
149
+ if (is_null($this->listing)) {
150
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
151
+ ->getObject('Listing', $listingId)->getChildObject();
152
+ }
153
+
154
+ return $this->listing;
155
+ }
156
+
157
+ // ####################################
158
+
159
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category/Grid.php ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Category_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Category_Grid
9
+ {
10
+ /** @var Ess_M2ePro_Model_Listing */
11
+ private $listing = NULL;
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('newAsinCategoryGrid');
20
+ //------------------------------
21
+
22
+ // Set default values
23
+ //------------------------------
24
+ $this->setDefaultSort('id');
25
+ $this->setDefaultDir('DESC');
26
+ $this->setUseAjax(true);
27
+ //------------------------------
28
+
29
+ $this->prepareDataByCategories();
30
+ }
31
+
32
+ // ####################################
33
+
34
+ protected function _prepareCollection()
35
+ {
36
+ /* @var $collection Mage_Catalog_Model_Resource_Category_Collection */
37
+ $collection = Mage::getModel('catalog/category')->getCollection();
38
+ $collection->addAttributeToSelect('name');
39
+
40
+ $collection->addFieldToFilter(array(
41
+ array('attribute' => 'entity_id', 'in' => array_keys($this->getData('categories_data')))
42
+ ));
43
+
44
+ $this->setCollection($collection);
45
+
46
+ return parent::_prepareCollection();
47
+ }
48
+
49
+ // ####################################
50
+
51
+ protected function _prepareColumns()
52
+ {
53
+ $this->addColumn('magento_category', array(
54
+ 'header' => Mage::helper('M2ePro')->__('Magento Category'),
55
+ 'align' => 'left',
56
+ 'width' => '500px',
57
+ 'type' => 'text',
58
+ 'index' => 'name',
59
+ 'filter' => false,
60
+ 'sortable' => false,
61
+ 'frame_callback' => array($this, 'callbackColumnMagentoCategory')
62
+ ));
63
+
64
+ $this->addColumn('description_template', array(
65
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
66
+ 'align' => 'left',
67
+ 'width' => '*',
68
+ 'sortable' => false,
69
+ 'type' => 'options',
70
+ 'index' => 'description_template_id',
71
+ 'filter_index' => 'description_template_id',
72
+ 'options' => array(
73
+ 1 => Mage::helper('M2ePro')->__('Description Policy Selected'),
74
+ 0 => Mage::helper('M2ePro')->__('Description Policy Not Selected')
75
+ ),
76
+ 'frame_callback' => array($this, 'callbackColumnDescriptionTemplateCallback'),
77
+ 'filter_condition_callback' => array($this, 'callbackColumnDescriptionTemplateFilterCallback')
78
+ ));
79
+
80
+ $actionsColumn = array(
81
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
82
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
83
+ 'align' => 'center',
84
+ 'width' => '130px',
85
+ 'type' => 'text',
86
+ 'sortable' => false,
87
+ 'filter' => false,
88
+ 'actions' => array()
89
+ );
90
+
91
+ $actions = array(
92
+ array(
93
+ 'caption' => Mage::helper('M2ePro')->__('Set Description Policy'),
94
+ 'field' => 'entity_id',
95
+ 'onclick_action' => 'ListingGridHandlerObj.setDescriptionTemplateByCategoryRowAction'
96
+ ),
97
+ array(
98
+ 'caption' => Mage::helper('M2ePro')->__('Reset Description Policy'),
99
+ 'field' => 'entity_id',
100
+ 'onclick_action' => 'ListingGridHandlerObj.resetDescriptionTemplateByCategoryRowAction'
101
+ )
102
+ );
103
+
104
+ $actionsColumn['actions'] = $actions;
105
+
106
+ $this->addColumn('actions', $actionsColumn);
107
+
108
+ return parent::_prepareColumns();
109
+ }
110
+
111
+ // ####################################
112
+
113
+ protected function _prepareMassaction()
114
+ {
115
+ $this->setMassactionIdField('entity_id');
116
+ $this->setMassactionIdFieldOnlyIndexValue(true);
117
+
118
+ //--------------------------------
119
+ $this->getMassactionBlock()->addItem('setDescriptionTemplateByCategory', array(
120
+ 'label' => Mage::helper('M2ePro')->__('Set Description Policy'),
121
+ 'url' => ''
122
+ ));
123
+
124
+ $this->getMassactionBlock()->addItem('resetDescriptionTemplateByCategory', array(
125
+ 'label' => Mage::helper('M2ePro')->__('Reset Description Policy'),
126
+ 'url' => ''
127
+ ));
128
+ //--------------------------------
129
+
130
+ return parent::_prepareMassaction();
131
+ }
132
+
133
+ // ########################################
134
+
135
+ public function callbackColumnDescriptionTemplateCallback($value, $row, $column, $isExport)
136
+ {
137
+ $categoriesData = $this->getData('categories_data');
138
+ $productsIds = implode(',', $categoriesData[$row->getData('entity_id')]);
139
+
140
+ $descriptionTemplatesData = $this->getData('description_templates_data');
141
+ $descriptionTemplatesIds = array();
142
+ foreach ($categoriesData[$row->getData('entity_id')] as $productId) {
143
+ if (empty($descriptionTemplatesIds[$descriptionTemplatesData[$productId]])) {
144
+ $descriptionTemplatesIds[$descriptionTemplatesData[$productId]] = 0;
145
+ }
146
+ $descriptionTemplatesIds[$descriptionTemplatesData[$productId]]++;
147
+ }
148
+
149
+ arsort($descriptionTemplatesIds);
150
+
151
+ reset($descriptionTemplatesIds);
152
+ $descriptionTemplateId = key($descriptionTemplatesIds);
153
+
154
+ if (empty($descriptionTemplateId)) {
155
+ $iconSrc = $this->getSkinUrl('M2ePro/images/warning.png');
156
+ $label = Mage::helper('M2ePro')->__('Not Selected');
157
+
158
+ return <<<HTML
159
+ <img src="{$iconSrc}" alt="">&nbsp;<span style="color: gray; font-style: italic;">{$label}</span>
160
+ <input type="hidden" id="products_ids_{$row->getData('entity_id')}" value="{$productsIds}">
161
+ HTML;
162
+ }
163
+
164
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
165
+ 'id' => $descriptionTemplateId
166
+ ));
167
+
168
+ /** @var Ess_M2ePro_Model_Amazon_Template_Description $descriptionTemplate */
169
+ $descriptionTemplate = Mage::helper('M2ePro/Component_Amazon')
170
+ ->getModel('Template_Description')->load($descriptionTemplateId);
171
+
172
+ $title = Mage::helper('M2ePro')->escapeHtml($descriptionTemplate->getData('title'));
173
+
174
+ return <<<HTML
175
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
176
+ <input type="hidden" id="products_ids_{$row->getData('entity_id')}" value="{$productsIds}">
177
+ HTML;
178
+ }
179
+
180
+ // ########################################
181
+
182
+ protected function callbackColumnDescriptionTemplateFilterCallback($collection, $column)
183
+ {
184
+ $value = $column->getFilter()->getValue();
185
+
186
+ if ($value == null) {
187
+ return;
188
+ }
189
+
190
+ $filteredProductsCategories = array();
191
+ $filteredListingProductsIds = array();
192
+
193
+ $categoriesData = $this->getData('categories_data');
194
+ $descriptionTemplatesIds = $this->getData('description_templates_data');
195
+
196
+ foreach ($descriptionTemplatesIds as $listingProductId => $descriptionTemplateId) {
197
+ if ($descriptionTemplateId !== NULL) {
198
+ $filteredListingProductsIds[] = $listingProductId;
199
+ }
200
+ }
201
+
202
+ foreach ($categoriesData as $categoryId => $listingProducts) {
203
+ foreach ($filteredListingProductsIds as $listingProductId) {
204
+ if (in_array($listingProductId, $listingProducts)) {
205
+ $filteredProductsCategories[] = $categoryId;
206
+ }
207
+ }
208
+ }
209
+
210
+ $filteredProductsCategories = array_unique($filteredProductsCategories);
211
+
212
+ if ($value) {
213
+ $collection->addFieldToFilter('entity_id', array('in' => $filteredProductsCategories));
214
+ } else if (!empty($filteredProductsCategories)){
215
+ $collection->addFieldToFilter('entity_id', array('nin' => $filteredProductsCategories));
216
+ }
217
+ }
218
+
219
+ // ########################################
220
+
221
+ public function getRowUrl($row)
222
+ {
223
+ return false;
224
+ }
225
+
226
+ // ####################################
227
+
228
+ protected function _toHtml()
229
+ {
230
+ $addErrorJs = '';
231
+
232
+ if (count($this->getData('categories_data')) === 0) {
233
+ $msg = Mage::helper('M2ePro')
234
+ ->__('Magento Categories are not specified for Products you are adding.');
235
+
236
+ $addErrorJs = <<<JS
237
+ MagentoMessageObj['addError']('{$msg}');
238
+ $('save_and_go_to_listing_view').addClassName('disabled').onclick = function() {
239
+ return null;
240
+ };
241
+ JS;
242
+
243
+ }
244
+
245
+ $javascriptsMain = <<<JAVASCRIPT
246
+ <script type="text/javascript">
247
+
248
+ if (typeof ListingGridHandlerObj != 'undefined') {
249
+ ListingGridHandlerObj.afterInitPage();
250
+ }
251
+
252
+ {$addErrorJs}
253
+
254
+ Event.observe(window, 'load', function() {
255
+ setTimeout(function() {
256
+ ListingGridHandlerObj.afterInitPage();
257
+ }, 350);
258
+ });
259
+
260
+ </script>
261
+ JAVASCRIPT;
262
+
263
+ return parent::_toHtml() . $javascriptsMain;
264
+ }
265
+
266
+ // ####################################
267
+
268
+ /**
269
+ * @return Ess_M2ePro_Model_Amazon_Listing
270
+ * @throws Exception
271
+ */
272
+ public function getListing()
273
+ {
274
+ if (!$listingId = $this->getRequest()->getParam('id')) {
275
+ throw new Exception('Listing is not defined');
276
+ }
277
+
278
+ if (is_null($this->listing)) {
279
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
280
+ ->getObject('Listing', $listingId);
281
+ }
282
+
283
+ return $this->listing;
284
+ }
285
+
286
+ // ####################################
287
+
288
+ private function prepareDataByCategories()
289
+ {
290
+ $listingProductsIds = $this->getListing()
291
+ ->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
292
+
293
+ $listingProductCollection = Mage::helper('M2ePro/Component_Amazon')
294
+ ->getCollection('Listing_Product')
295
+ ->addFieldToFilter('id',array('in' => $listingProductsIds));
296
+
297
+ $productsIds = array();
298
+ $descriptionTemplatesIds = array();
299
+ foreach ($listingProductCollection->getData() as $item) {
300
+ $productsIds[$item['id']] = $item['product_id'];
301
+ $descriptionTemplatesIds[$item['id']] = $item['template_description_id'];
302
+ }
303
+ $productsIds = array_unique($productsIds);
304
+
305
+ $categoriesIds = Mage::helper('M2ePro/Magento_Category')->getLimitedCategoriesByProducts(
306
+ $productsIds,
307
+ $this->getListing()->getStoreId()
308
+ );
309
+
310
+ $categoriesData = array();
311
+
312
+ foreach ($categoriesIds as $categoryId) {
313
+ /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
314
+ $collection = Mage::getModel('catalog/product')->getCollection();
315
+ $collection->addFieldToFilter('entity_id', array('in' => $productsIds));
316
+
317
+ $collection->joinTable(
318
+ array('ccp' => 'catalog/category_product'),
319
+ 'product_id=entity_id',
320
+ array('category_id' => 'category_id')
321
+ );
322
+ $collection->addFieldToFilter('category_id', $categoryId);
323
+
324
+ $data = $collection->getData();
325
+
326
+ foreach ($data as $item) {
327
+ $categoriesData[$categoryId][] = array_search($item['entity_id'], $productsIds);
328
+ }
329
+
330
+ $categoriesData[$categoryId] = array_unique($categoriesData[$categoryId]);
331
+ }
332
+
333
+ $this->setData('categories_data', $categoriesData);
334
+ $this->setData('description_templates_data', $descriptionTemplatesIds);
335
+
336
+ $this->getListing()
337
+ ->setSetting('additional_data', 'adding_new_asin_description_templates_data', $descriptionTemplatesIds);
338
+ $this->getListing()->save();
339
+ }
340
+
341
+ // ####################################
342
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Manual
8
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ $listingId = $this->getRequest()->getParam('id');
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('newAsinDescriptionTemplateManual');
19
+ //------------------------------
20
+
21
+ // Set header text
22
+ //------------------------------
23
+ $this->_headerText = Mage::helper('M2ePro')->__("Set Description Policy for New ASIN/ISBN Creation");
24
+ $this->_blockGroup = 'M2ePro';
25
+ $this->_controller = 'adminhtml_common_amazon_listing_add_newAsin_manual';
26
+ //------------------------------
27
+
28
+ // Set buttons actions
29
+ //------------------------------
30
+ $this->removeButton('back');
31
+ $this->removeButton('reset');
32
+ $this->removeButton('delete');
33
+ $this->removeButton('add');
34
+ $this->removeButton('save');
35
+ $this->removeButton('edit');
36
+ //------------------------------
37
+
38
+ //------------------------------
39
+ $url = $this->getUrl('*/*/resetNewAsin', array(
40
+ '_current' => true
41
+ ));
42
+ $this->_addButton('back', array(
43
+ 'label' => Mage::helper('M2ePro')->__('Back'),
44
+ 'onclick' => 'ListingGridHandlerObj.back_click(\'' . $url . '\')',
45
+ 'class' => 'back'
46
+ ));
47
+
48
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
49
+ //------------------------------
50
+ $this->_addButton('save_and_go_to_listing_view', array(
51
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
52
+ 'onclick' => 'ListingGridHandlerObj.checkManualProducts(\''.$url.'\')',
53
+ 'class' => 'scalable next'
54
+ ));
55
+ //------------------------------
56
+ }
57
+
58
+ public function getGridHtml()
59
+ {
60
+ $listing = Mage::helper('M2ePro/Component')
61
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
62
+
63
+ $viewHeaderBlock = $this->getLayout()->createBlock(
64
+ 'M2ePro/adminhtml_listing_view_header','',
65
+ array('listing' => $listing)
66
+ );
67
+
68
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml();
69
+ }
70
+
71
+ protected function _toHtml()
72
+ {
73
+ $helper = Mage::helper('M2ePro');
74
+
75
+ // --------TEXT------------------
76
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
77
+ $setDescriptionPolicy = $helper->escapeJs($helper->__('Set Description Policy.'));
78
+ // -------------------------------
79
+
80
+ // ---------URL-------------------
81
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
82
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
83
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
84
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
85
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/*/viewTemplateDescriptionsGrid');
86
+
87
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
88
+ $unmapFromNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
89
+
90
+ $checkNewAsinManualProducts = $this->getUrl('*/*/checkNewAsinManualProducts', array('_current' => true));
91
+ // -------------------------------
92
+
93
+ $javascript = <<<HTML
94
+ <script type="text/javascript">
95
+ selectTemplateDescription = function (el, templateId, mapToGeneralId)
96
+ {
97
+ ListingGridHandlerObj.mapToTemplateDescription(el, templateId, mapToGeneralId);
98
+ };
99
+
100
+ if (typeof M2ePro == 'undefined') {
101
+ M2ePro = {};
102
+ M2ePro.url = {};
103
+ M2ePro.formData = {};
104
+ M2ePro.customData = {};
105
+ M2ePro.text = {};
106
+ }
107
+
108
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
109
+ M2ePro.text.setDescriptionPolicy = '{$setDescriptionPolicy}';
110
+
111
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
112
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
113
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
114
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
115
+
116
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
117
+ M2ePro.url.unmapFromNewAsin = '{$unmapFromNewAsin}';
118
+
119
+ M2ePro.url.checkNewAsinManualProducts = '{$checkNewAsinManualProducts}';
120
+
121
+ Event.observe(window, 'load', function() {
122
+
123
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
124
+
125
+ ListingGridHandlerObj = new NewAsinTemplateDescriptionGridHandler(
126
+ '{$this->getChild('grid')->getId()}',
127
+ {$this->getListing()->getId()}
128
+ );
129
+
130
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
131
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
132
+ });
133
+
134
+ </script>
135
+ HTML;
136
+
137
+ return $javascript .
138
+ '<div id="search_asin_products_container">' .
139
+ parent::_toHtml() .
140
+ '</div>';
141
+ }
142
+
143
+ // ####################################
144
+
145
+ public function getListing()
146
+ {
147
+ if (!$listingId = $this->getRequest()->getParam('id')) {
148
+ throw new Exception('Listing is not defined');
149
+ }
150
+
151
+ if (is_null($this->listing)) {
152
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
153
+ ->getObject('Listing', $listingId)->getChildObject();
154
+ }
155
+
156
+ return $this->listing;
157
+ }
158
+
159
+ // ####################################
160
+
161
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/Grid.php ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Manual_Grid
8
+ extends Mage_Adminhtml_Block_Widget_Grid
9
+ {
10
+ /** @var Ess_M2ePro_Model_Listing */
11
+ private $listing = NULL;
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('newAsinManualGrid');
20
+ //------------------------------
21
+
22
+ // Set default values
23
+ //------------------------------
24
+ $this->setDefaultSort('product_id');
25
+ $this->setDefaultDir('DESC');
26
+ $this->setUseAjax(true);
27
+ //------------------------------
28
+ }
29
+
30
+ // ####################################
31
+
32
+ protected function _prepareCollection()
33
+ {
34
+ // Get collection
35
+ //----------------------------
36
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
37
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
38
+ Mage::getModel('catalog/product')->getResource())
39
+ ->setStoreId($this->getListing()->getData('store_id'))
40
+ ->setListingProductModeOn()
41
+ ->addAttributeToSelect('name')
42
+ ->addAttributeToSelect('sku');
43
+ //----------------------------
44
+
45
+ //------------------------------
46
+ $listingProductsIds = $this->getListing()
47
+ ->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
48
+
49
+ $collection->joinTable(
50
+ array('lp' => 'M2ePro/Listing_Product'),
51
+ 'product_id=entity_id',
52
+ array(
53
+ 'id' => 'id'
54
+ ),
55
+ '{{table}}.listing_id='.(int)$this->getListing()->getId()
56
+ );
57
+ $collection->joinTable(
58
+ array('elp' => 'M2ePro/Amazon_Listing_Product'),
59
+ 'listing_product_id=id',
60
+ array(
61
+ 'listing_product_id' => 'listing_product_id',
62
+ 'template_description_id' => 'template_description_id'
63
+ )
64
+ );
65
+
66
+ $collection->getSelect()->where('lp.id IN (?)', $listingProductsIds);
67
+ $collection->getSelect()->where('elp.search_settings_status != ? OR elp.search_settings_status IS NULL',
68
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS);
69
+ $collection->getSelect()->where('elp.general_id IS NULL');
70
+ //------------------------------
71
+
72
+ //exit($collection->getSelect()->__toString());
73
+
74
+ // Set collection to grid
75
+ $this->setCollection($collection);
76
+
77
+ parent::_prepareCollection();
78
+
79
+ return $this;
80
+ }
81
+
82
+ protected function _prepareColumns()
83
+ {
84
+ $this->addColumn('product_id', array(
85
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
86
+ 'align' => 'right',
87
+ 'width' => '100px',
88
+ 'type' => 'number',
89
+ 'index' => 'entity_id',
90
+ 'filter_index' => 'entity_id',
91
+ 'frame_callback' => array($this, 'callbackColumnProductId')
92
+ ));
93
+
94
+ $this->addColumn('name', array(
95
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
96
+ 'align' => 'left',
97
+ 'width' => '400px',
98
+ 'type' => 'text',
99
+ 'index' => 'name',
100
+ 'filter_index' => 'name',
101
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
102
+ 'filter_condition_callback' => array($this, 'callbackFilterProductTitle')
103
+ ));
104
+
105
+ $this->addColumn('description_template', array(
106
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
107
+ 'align' => 'left',
108
+ 'width' => '*',
109
+ 'type' => 'options',
110
+ 'index' => 'description_template_id',
111
+ 'filter_index' => 'description_template_id',
112
+ 'options' => array(
113
+ 1 => Mage::helper('M2ePro')->__('Description Policy Selected'),
114
+ 0 => Mage::helper('M2ePro')->__('Description Policy Not Selected')
115
+ ),
116
+ 'frame_callback' => array($this, 'callbackColumnDescriptionTemplateCallback'),
117
+ 'filter_condition_callback' => array($this, 'callbackColumnDescriptionTemplateFilterCallback')
118
+ ));
119
+
120
+ $actionsColumn = array(
121
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
122
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
123
+ 'align' => 'center',
124
+ 'width' => '130px',
125
+ 'type' => 'text',
126
+ 'field' => 'id',
127
+ 'sortable' => false,
128
+ 'filter' => false,
129
+ 'actions' => array()
130
+ );
131
+
132
+ $actions = array(
133
+ array(
134
+ 'caption' => Mage::helper('M2ePro')->__('Set Description Policy'),
135
+ 'field' => 'id',
136
+ 'onclick_action' => 'ListingGridHandlerObj.setDescriptionTemplateRowAction'
137
+ ),
138
+ array(
139
+ 'caption' => Mage::helper('M2ePro')->__('Reset Description Policy'),
140
+ 'field' => 'id',
141
+ 'onclick_action' => 'ListingGridHandlerObj.resetDescriptionTemplateRowAction'
142
+ )
143
+ );
144
+
145
+ $actionsColumn['actions'] = $actions;
146
+
147
+ $this->addColumn('actions', $actionsColumn);
148
+
149
+ return parent::_prepareColumns();
150
+ }
151
+
152
+ protected function _prepareMassaction()
153
+ {
154
+ $this->setMassactionIdField('listing_product_id');
155
+ $this->setMassactionIdFieldOnlyIndexValue(true);
156
+
157
+ //--------------------------------
158
+ $this->getMassactionBlock()->addItem('setDescriptionTemplate', array(
159
+ 'label' => Mage::helper('M2ePro')->__('Set Description Policy'),
160
+ 'url' => ''
161
+ ));
162
+
163
+ $this->getMassactionBlock()->addItem('resetDescriptionTemplate', array(
164
+ 'label' => Mage::helper('M2ePro')->__('Reset Description Policy'),
165
+ 'url' => ''
166
+ ));
167
+ //--------------------------------
168
+
169
+ return parent::_prepareMassaction();
170
+ }
171
+
172
+ // ########################################
173
+
174
+ public function callbackColumnProductId($value, $row, $column, $isExport)
175
+ {
176
+ $productId = (int)$row->getData('entity_id');
177
+ $storeId = (int)$this->listing->getData('store_id');
178
+
179
+ $url = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
180
+ $htmlWithoutThumbnail = '<a href="' . $url . '" target="_blank">'.$productId.'</a>';
181
+
182
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
183
+ ->getGroupValue('/view/','show_products_thumbnails');
184
+
185
+ if (!$showProductsThumbnails) {
186
+ return $htmlWithoutThumbnail;
187
+ }
188
+
189
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
190
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
191
+ $magentoProduct->setProductId($productId);
192
+ $magentoProduct->setStoreId($storeId);
193
+
194
+ $thumbnail = $magentoProduct->getThumbnailImageLink();
195
+ if (is_null($thumbnail)) {
196
+ return $htmlWithoutThumbnail;
197
+ }
198
+
199
+ return <<<HTML
200
+ <a href="{$url}" target="_blank">
201
+ {$productId}
202
+ <hr style="border: 1px solid silver; border-bottom: none;">
203
+ <img src="{$thumbnail}" />
204
+ </a>
205
+ HTML;
206
+ }
207
+
208
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
209
+ {
210
+ if (strlen($productTitle) > 60) {
211
+ $productTitle = substr($productTitle, 0, 60) . '...';
212
+ }
213
+
214
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
215
+
216
+ $value = '<span>'.$productTitle.'</span>';
217
+
218
+ $sku = $row->getData('sku');
219
+
220
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
221
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($sku) . '<br/>';
222
+
223
+ $listingProductId = (int)$row->getData('id');
224
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
225
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
226
+
227
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
228
+ return $value;
229
+ }
230
+
231
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
232
+ ->getTypeModel()->getProductAttributes();
233
+
234
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
235
+ $value .= implode(', ', $productOptions);
236
+ $value .= '</div>';
237
+
238
+ return $value;
239
+ }
240
+
241
+ public function callbackColumnDescriptionTemplateCallback($value, $row, $column, $isExport)
242
+ {
243
+ $descriptionTemplateId = $row->getData('template_description_id');
244
+
245
+ if (empty($descriptionTemplateId)) {
246
+ $iconSrc = $this->getSkinUrl('M2ePro/images/warning.png');
247
+ $label = Mage::helper('M2ePro')->__('Not Selected');
248
+
249
+ return <<<HTML
250
+ <img src="{$iconSrc}" alt="">&nbsp;<span style="color: gray; font-style: italic;">{$label}</span>
251
+ HTML;
252
+ }
253
+
254
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
255
+ 'id' => $descriptionTemplateId
256
+ ));
257
+
258
+ /** @var Ess_M2ePro_Model_Amazon_Template_Description $descriptionTemplate */
259
+ $descriptionTemplate = Mage::helper('M2ePro/Component_Amazon')
260
+ ->getModel('Template_Description')->load($descriptionTemplateId);
261
+
262
+ $title = Mage::helper('M2ePro')->escapeHtml($descriptionTemplate->getData('title'));
263
+
264
+ return <<<HTML
265
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
266
+ HTML;
267
+ }
268
+
269
+ // ########################################
270
+
271
+ protected function callbackFilterProductTitle($collection, $column)
272
+ {
273
+ $value = $column->getFilter()->getValue();
274
+
275
+ if ($value == null) {
276
+ return;
277
+ }
278
+
279
+ $collection->addFieldToFilter(
280
+ array(
281
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
282
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
283
+ )
284
+ );
285
+ }
286
+
287
+ // ----------------------------------------
288
+
289
+ protected function callbackColumnDescriptionTemplateFilterCallback($collection, $column)
290
+ {
291
+ $value = $column->getFilter()->getValue();
292
+
293
+ if ($value == null) {
294
+ return;
295
+ }
296
+
297
+ if ($value) {
298
+ $collection->addFieldToFilter('template_description_id', array('notnull' => null));
299
+ } else {
300
+ $collection->addFieldToFilter('template_description_id', array('null' => null));
301
+ }
302
+ }
303
+
304
+ // ########################################
305
+
306
+ public function getRowUrl($row)
307
+ {
308
+ return false;
309
+ }
310
+
311
+ // ####################################
312
+
313
+ protected function _toHtml()
314
+ {
315
+ $javascriptsMain = <<<JAVASCRIPT
316
+ <script type="text/javascript">
317
+
318
+ if (typeof ListingGridHandlerObj != 'undefined') {
319
+ ListingGridHandlerObj.afterInitPage();
320
+ }
321
+
322
+ Event.observe(window, 'load', function() {
323
+ setTimeout(function() {
324
+ ListingGridHandlerObj.afterInitPage();
325
+ }, 350);
326
+ });
327
+
328
+ </script>
329
+ JAVASCRIPT;
330
+
331
+ return parent::_toHtml() . $javascriptsMain;
332
+ }
333
+
334
+ // ####################################
335
+
336
+ /**
337
+ * @return Ess_M2ePro_Model_Amazon_Listing
338
+ * @throws Exception
339
+ */
340
+ public function getListing()
341
+ {
342
+ if (!$listingId = $this->getRequest()->getParam('id')) {
343
+ throw new Exception('Listing is not defined');
344
+ }
345
+
346
+ if (is_null($this->listing)) {
347
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
348
+ ->getObject('Listing', $listingId)->getChildObject();
349
+ }
350
+
351
+ return $this->listing;
352
+ }
353
+
354
+ // ####################################
355
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/SkipPopup.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Manual_SkipPopup
8
+ extends Mage_Adminhtml_Block_Template
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingAddNewAsinManualPopup');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/manual/skip_popup.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ parent::_beforeToHtml();
26
+
27
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
28
+
29
+ $data = array(
30
+ 'class' => 'next',
31
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
32
+ 'onclick' => 'setLocation(\''.$url.'\')',
33
+ );
34
+ $this->setChild('continue_button',$this->getLayout()->createBlock('adminhtml/widget_button')->setData($data));
35
+
36
+ return $this;
37
+ }
38
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Review.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Review
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Review
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('listingProductReview');
19
+ $this->setData('component', Ess_M2ePro_Helper_Component_Amazon::NICK);
20
+ //------------------------------
21
+
22
+ $this->_headerText = Mage::helper('M2ePro')->__('Congratulations');
23
+
24
+ $this->setTemplate('M2ePro/common/amazon/listing/add/review.phtml');
25
+ }
26
+
27
+ // ####################################
28
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin.php ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin
8
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ $listingId = $this->getRequest()->getParam('id');
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('searchAsinForListingProducts');
19
+ //------------------------------
20
+
21
+ // Set header text
22
+ //------------------------------
23
+ $this->_headerText = Mage::helper('M2ePro')->__("Search Existing Amazon Products (ASIN/ISBN)");
24
+ $this->_blockGroup = 'M2ePro';
25
+ $this->_controller = 'adminhtml_common_amazon_listing_add_searchAsin';
26
+ //------------------------------
27
+
28
+ // Set buttons actions
29
+ //------------------------------
30
+ $this->removeButton('back');
31
+ $this->removeButton('reset');
32
+ $this->removeButton('delete');
33
+ $this->removeButton('add');
34
+ $this->removeButton('save');
35
+ $this->removeButton('edit');
36
+ //------------------------------
37
+
38
+ //------------------------------
39
+ $url = $this->getUrl('*/*/removeAddedProducts', array(
40
+ 'id' => $listingId,
41
+ '_current' => true
42
+ ));
43
+ $this->_addButton('back', array(
44
+ 'label' => Mage::helper('M2ePro')->__('Back'),
45
+ 'onclick' => 'ListingGridHandlerObj.back_click(\'' . $url . '\')',
46
+ 'class' => 'back'
47
+ ));
48
+
49
+ //------------------------------
50
+ $this->_addButton('auto_action', array(
51
+ 'label' => Mage::helper('M2ePro')->__('Edit Search Settings'),
52
+ 'onclick' => 'ListingGridHandlerObj.editSearchSettings(\'' .
53
+ Mage::helper('M2ePro')->__('Listing Search Settings') . '\' ,' .
54
+ $this->getListing()->getId() .
55
+ ');'
56
+ ));
57
+ //------------------------------
58
+
59
+ //------------------------------
60
+ $this->_addButton('save_and_go_to_listing_view', array(
61
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
62
+ 'onclick' => 'ListingGridHandlerObj.checkSearchResults('.$listingId.')',
63
+ 'class' => 'scalable next'
64
+ ));
65
+ //------------------------------
66
+ }
67
+
68
+ public function getGridHtml()
69
+ {
70
+ $listing = Mage::helper('M2ePro/Component')
71
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
72
+
73
+ $viewHeaderBlock = $this->getLayout()->createBlock(
74
+ 'M2ePro/adminhtml_listing_view_header','',
75
+ array('listing' => $listing)
76
+ );
77
+
78
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_add_searchAsin_help');
79
+
80
+ $productSearchBlock = $this->getLayout()
81
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_productSearch_main');
82
+
83
+ return $helpBlock->toHtml()
84
+ . $viewHeaderBlock->toHtml()
85
+ . $productSearchBlock->toHtml()
86
+ . parent::getGridHtml();
87
+ }
88
+
89
+ protected function _toHtml()
90
+ {
91
+ $helper = Mage::helper('M2ePro');
92
+
93
+ // --------TEXT------------------
94
+ $createEmptyListingMessage = $helper->escapeJs($helper->__('Are you sure you want to create empty Listing?'));
95
+
96
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
97
+ $taskCompletedSuccessMessage = $helper->escapeJs(
98
+ $helper->__('"%task_title%" task has successfully submitted to be processed.')
99
+ );
100
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
101
+ '"%task_title%" task has completed with warnings. <a target="_blank" href="%url%">View log</a> for details.'
102
+ ));
103
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
104
+ '"%task_title%" task has completed with errors. <a target="_blank" href="%url%">View log</a> for details.'
105
+ ));
106
+
107
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
108
+ 'Sending %product_title% Product(s) data on Amazon.')
109
+ );
110
+
111
+ $selectItemsMessage = $helper->escapeJs(
112
+ $helper->__('Please select the Products you want to perform the action on.')
113
+ );
114
+
115
+ $assignString = Mage::helper('M2ePro')->__('Assign');
116
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
117
+
118
+ $enterProductSearchQueryMessage = $helper->escapeJs(
119
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
120
+ );
121
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
122
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
123
+ $autoMapAsinErrorMessage = $helper->escapeJs(
124
+ $helper->__('Server is currently unavailable. Please try again later.')
125
+ );
126
+ $newAsinNotAvailable = $helper->escapeJs(
127
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
128
+ );
129
+ $notSynchronizedMarketplace = $helper->escapeJs(
130
+ $helper->__(
131
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
132
+ ).' '.
133
+ $helper->__(
134
+ 'Press "Save And Update" button after redirect on Marketplace page.'
135
+ )
136
+ );
137
+
138
+ $newAsinPopupTitle = $helper->escapeJs($helper->__('New ASIN/ISBN creation'));
139
+ // -------------------------------
140
+
141
+ // ---------URL-------------------
142
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
143
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
144
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
145
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
146
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
147
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
148
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
149
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
150
+
151
+ $viewSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/viewSearchSettings');
152
+ $saveSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/saveSearchSettings');
153
+
154
+ $checkSearchResults = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/checkSearchResults', array(
155
+ 'id' => $this->getListing()->getId()
156
+ ));
157
+
158
+ $showNewAsinStep = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/showNewAsinStep', array(
159
+ 'id' => $this->getListing()->getId()
160
+ ));
161
+
162
+ $getProductsUrl = $this->getUrl(
163
+ '*/adminhtml_common_' . $this->getData('component') . '_listing/getProductsFromCategories'
164
+ );
165
+ $addProductsUrl = $this->getUrl(
166
+ '*/adminhtml_common_listing_productAdd/addProducts', array(
167
+ 'component' => $this->getData('component')
168
+ )
169
+ );
170
+ $backUrl = $this->getUrl('*/*/index');
171
+ // -------------------------------
172
+
173
+ $javascript = <<<JAVASCRIPT
174
+ <script type="text/javascript">
175
+ if (typeof M2ePro == 'undefined') {
176
+ M2ePro = {};
177
+ M2ePro.url = {};
178
+ M2ePro.formData = {};
179
+ M2ePro.customData = {};
180
+ M2ePro.text = {};
181
+ }
182
+
183
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
184
+ M2ePro.text.create_empty_listing_message = '{$createEmptyListingMessage}';
185
+
186
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
187
+
188
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
189
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
190
+
191
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
192
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
193
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
194
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
195
+
196
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
197
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
198
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
199
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
200
+
201
+ M2ePro.text.assign = '{$assignString}';
202
+ M2ePro.text.confirm = '{$textConfirm}';
203
+
204
+ M2ePro.text.new_asin_popup_title = '{$newAsinPopupTitle}';
205
+
206
+ M2ePro.url.get_products_from_categories = '{$getProductsUrl}';
207
+ M2ePro.url.add_products = '{$addProductsUrl}';
208
+ M2ePro.url.back = '{$backUrl}';
209
+
210
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
211
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
212
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
213
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
214
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
215
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
216
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
217
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
218
+
219
+ M2ePro.url.viewSearchSettings = '{$viewSearchSettings}';
220
+ M2ePro.url.saveSearchSettings = '{$saveSearchSettings}';
221
+
222
+ M2ePro.url.checkSearchResults = '{$checkSearchResults}';
223
+ M2ePro.url.showNewAsinStep = '{$showNewAsinStep}';
224
+
225
+ Event.observe(window, 'load', function() {
226
+
227
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
228
+
229
+ ListingGridHandlerObj = new SearchAsinGridHandler(
230
+ '{$this->getChild('grid')->getId()}',
231
+ {$this->getListing()->getId()}
232
+ );
233
+
234
+ // todo next (temp solution)
235
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
236
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
237
+
238
+ ListingProgressBarObj = new ProgressBar('search_asin_progress_bar');
239
+ GridWrapperObj = new AreaWrapper('search_asin_products_container');
240
+ });
241
+
242
+ </script>
243
+ JAVASCRIPT;
244
+
245
+ return $javascript .
246
+ '<div id="search_asin_progress_bar"></div>' .
247
+ '<div id="search_asin_products_container">' .
248
+ parent::_toHtml() .
249
+ '</div>';
250
+ }
251
+
252
+ // ####################################
253
+
254
+ public function getListing()
255
+ {
256
+ if (!$listingId = $this->getRequest()->getParam('id')) {
257
+ throw new Exception('Listing is not defined');
258
+ }
259
+
260
+ if (is_null($this->listing)) {
261
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
262
+ ->getObject('Listing', $listingId)->getChildObject();
263
+ }
264
+
265
+ return $this->listing;
266
+ }
267
+
268
+ // ####################################
269
+
270
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php ADDED
@@ -0,0 +1,684 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_Grid
8
+ extends Mage_Adminhtml_Block_Widget_Grid
9
+ {
10
+ /** @var Ess_M2ePro_Model_Listing */
11
+ private $listing = NULL;
12
+
13
+ const SEARCH_SETTINGS_STATUS_NONE = 'none';
14
+ const SEARCH_SETTINGS_STATUS_COMPLETED = 'completed';
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ $listingData = $this->getListing()->getData();
21
+
22
+ // Initialization block
23
+ //------------------------------
24
+ $this->setId('searchAsinForListingProductsGrid'.$listingData['id']);
25
+ //------------------------------
26
+
27
+ // Set default values
28
+ //------------------------------
29
+ $this->setDefaultSort('product_id');
30
+ $this->setDefaultDir('DESC');
31
+ $this->setUseAjax(true);
32
+ //------------------------------
33
+ }
34
+
35
+ // ####################################
36
+
37
+ protected function _prepareCollection()
38
+ {
39
+ $listingProductsIds = $this->getListing()->getSetting('additional_data', 'adding_listing_products_ids');
40
+ $listingData = $this->getListing()->getData();
41
+
42
+ // Get collection
43
+ //----------------------------
44
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
45
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
46
+ Mage::getModel('catalog/product')->getResource());
47
+ $collection->setStoreId($listingData['store_id'])
48
+ ->setListingProductModeOn()
49
+ ->addAttributeToSelect('name')
50
+ ->addAttributeToSelect('sku')
51
+ ->joinTable(
52
+ array('cisi' => 'cataloginventory/stock_item'),
53
+ 'product_id=entity_id',
54
+ array('qty' => 'qty'),
55
+ '{{table}}.stock_id=1',
56
+ 'left'
57
+ );
58
+
59
+ //----------------------------
60
+
61
+ $collection->joinTable(
62
+ array('lp' => 'M2ePro/Listing_Product'),
63
+ 'product_id=entity_id',
64
+ array(
65
+ 'id' => 'id',
66
+ 'component_mode' => 'component_mode',
67
+ 'amazon_status' => 'status',
68
+ 'additional_data' => 'additional_data'
69
+ ),
70
+ array(
71
+ 'listing_id' => (int)$listingData['id']
72
+ )
73
+ );
74
+ $collection->joinTable(
75
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
76
+ 'listing_product_id=id',
77
+ array(
78
+ 'general_id' => 'general_id',
79
+ 'general_id_search_info' => 'general_id_search_info',
80
+ 'search_settings_status' => 'search_settings_status',
81
+ 'search_settings_data' => 'search_settings_data',
82
+ 'variation_child_statuses' => 'variation_child_statuses',
83
+ 'amazon_sku' => 'sku',
84
+ 'online_qty' => 'online_qty',
85
+ 'online_price' => 'online_price',
86
+ 'online_sale_price' => 'online_sale_price',
87
+ 'is_afn_channel' => 'is_afn_channel',
88
+ 'is_general_id_owner' => 'is_general_id_owner',
89
+ 'is_variation_parent' => 'is_variation_parent',
90
+ ),
91
+ '{{table}}.variation_parent_id is NULL'
92
+ );
93
+
94
+ $collection->getSelect()->where('id IN (?)', $listingProductsIds);
95
+
96
+ //----------------------------
97
+ // exit($collection->getSelect()->__toString());
98
+
99
+ // Set collection to grid
100
+ $this->setCollection($collection);
101
+
102
+ return parent::_prepareCollection();
103
+ }
104
+
105
+ protected function _prepareColumns()
106
+ {
107
+ $this->addColumn('product_id', array(
108
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
109
+ 'align' => 'right',
110
+ 'width' => '100px',
111
+ 'type' => 'number',
112
+ 'index' => 'entity_id',
113
+ 'filter_index' => 'entity_id',
114
+ 'frame_callback' => array($this, 'callbackColumnProductId')
115
+ ));
116
+
117
+ $this->addColumn('name', array(
118
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
119
+ 'align' => 'left',
120
+ 'type' => 'text',
121
+ 'index' => 'name',
122
+ 'filter_index' => 'name',
123
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
124
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
125
+ ));
126
+
127
+ $this->addColumn('general_id', array(
128
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
129
+ 'align' => 'left',
130
+ 'width' => '140px',
131
+ 'type' => 'text',
132
+ 'index' => 'general_id',
133
+ 'filter_index' => 'general_id',
134
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
135
+ ));
136
+
137
+ if ($this->getListing()->getChildObject()->isGeneralIdAttributeMode() ||
138
+ $this->getListing()->getChildObject()->isWorldwideIdAttributeMode()) {
139
+
140
+ $this->addColumn('settings', array(
141
+ 'header' => Mage::helper('M2ePro')->__('Search Settings Values'),
142
+ 'align' => 'left',
143
+ 'width' => '240px',
144
+ 'filter' => false,
145
+ 'sortable' => false,
146
+ 'type' => 'text',
147
+ 'index' => 'id',
148
+ 'frame_callback' => array($this, 'callbackColumnSettings')
149
+ ));
150
+ }
151
+
152
+ $this->addColumn('status', array(
153
+ 'header' => Mage::helper('M2ePro')->__('Status'),
154
+ 'width' => '200px',
155
+ 'index' => 'search_settings_status',
156
+ 'filter_index' => 'search_settings_status',
157
+ 'sortable' => false,
158
+ 'type' => 'options',
159
+ 'options' => array(
160
+ self::SEARCH_SETTINGS_STATUS_NONE => Mage::helper('M2ePro')->__('None'),
161
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS =>
162
+ Mage::helper('M2ePro')->__('In Progress'),
163
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND =>
164
+ Mage::helper('M2ePro')->__('Not Found'),
165
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_ACTION_REQUIRED =>
166
+ Mage::helper('M2ePro')->__('Action Required'),
167
+ self::SEARCH_SETTINGS_STATUS_COMPLETED => Mage::helper('M2ePro')->__('Completed')
168
+ ),
169
+ 'frame_callback' => array($this, 'callbackColumnStatus'),
170
+ 'filter_condition_callback' => array($this, 'callbackFilterStatus')
171
+ ));
172
+
173
+ return parent::_prepareColumns();
174
+ }
175
+
176
+ protected function _prepareMassaction()
177
+ {
178
+ $this->setMassactionIdField('id');
179
+ $this->setMassactionIdFieldOnlyIndexValue(true);
180
+
181
+ //--------------------------------
182
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
183
+ 'label' => Mage::helper('M2ePro')->__('Search ASIN/ISBN automatically'),
184
+ 'url' => '',
185
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
186
+ ));
187
+
188
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
189
+ 'label' => Mage::helper('M2ePro')->__('Reset ASIN/ISBN information'),
190
+ 'url' => '',
191
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
192
+ ));
193
+ //--------------------------------
194
+
195
+ return parent::_prepareMassaction();
196
+ }
197
+
198
+ // ####################################
199
+
200
+ public function callbackColumnProductId($value, $row, $column, $isExport)
201
+ {
202
+ $listingData = $this->getListing()->getData();
203
+
204
+ $productId = (int)$value;
205
+ $storeId = (int)$listingData['store_id'];
206
+
207
+ $withoutImageHtml = '<a href="'
208
+ .$this->getUrl('adminhtml/catalog_product/edit',
209
+ array('id' => $productId))
210
+ .'" target="_blank">'
211
+ .$productId
212
+ .'</a>';
213
+
214
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')
215
+ ->getConfig()
216
+ ->getGroupValue('/view/','show_products_thumbnails');
217
+ if (!$showProductsThumbnails) {
218
+ return $withoutImageHtml;
219
+ }
220
+
221
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
222
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
223
+ $magentoProduct->setProductId($productId);
224
+ $magentoProduct->setStoreId($storeId);
225
+
226
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
227
+ if (is_null($imageUrlResized)) {
228
+ return $withoutImageHtml;
229
+ }
230
+
231
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
232
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
233
+
234
+ return $withImageHtml;
235
+ }
236
+
237
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
238
+ {
239
+ if (strlen($productTitle) > 60) {
240
+ $productTitle = substr($productTitle, 0, 60) . '...';
241
+ }
242
+
243
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
244
+
245
+ $value = '<span>'.$productTitle.'</span>';
246
+
247
+ $tempSku = $row->getData('sku');
248
+ is_null($tempSku)
249
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
250
+
251
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
252
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
253
+
254
+ $listingProductId = (int)$row->getData('id');
255
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
256
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
257
+
258
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
259
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
260
+
261
+ if (!$variationManager->isRelationParentType()) {
262
+ return $value;
263
+ }
264
+
265
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
266
+
267
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
268
+ $value .= implode(', ', $productAttributes);
269
+ $value .= '</div>';
270
+
271
+ return $value;
272
+ }
273
+
274
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
275
+ {
276
+ if (empty($generalId)) {
277
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
278
+ }
279
+
280
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
281
+ }
282
+
283
+ public function callbackColumnSettings($id, $row, $column, $isExport)
284
+ {
285
+ $value = '';
286
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $listingProduct */
287
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $id)->getChildObject();
288
+
289
+ if ($this->getListing()->getChildObject()->isGeneralIdAttributeMode()) {
290
+ $attrValue = $listingProduct->getListingSource()->getSearchGeneralId();
291
+
292
+ if (empty($attrValue)) {
293
+ $attrValue = Mage::helper('M2ePro')->__('Not set');
294
+ } else if (!Mage::helper('M2ePro/Component_Amazon')->isASIN($attrValue) &&
295
+ !Mage::helper('M2ePro')->isISBN($attrValue)) {
296
+ $attrValue = Mage::helper('M2ePro')->__('Inappropriate value');
297
+ }
298
+
299
+ $value .= '<b>' . Mage::helper('M2ePro')->__('ASIN/ISBN') . '</b>: ' . $attrValue . '<br/>';
300
+ }
301
+
302
+ if ($this->getListing()->getChildObject()->isWorldwideIdAttributeMode()) {
303
+ $attrValue = $listingProduct->getListingSource()->getSearchWorldwideId();
304
+
305
+ if (empty($attrValue)) {
306
+ $attrValue = Mage::helper('M2ePro')->__('Not Set');
307
+ } else if (!Mage::helper('M2ePro')->isUPC($attrValue) && !Mage::helper('M2ePro')->isEAN($attrValue)) {
308
+ $attrValue = Mage::helper('M2ePro')->__('Inappropriate value');
309
+ }
310
+
311
+ $value .= '<b>' . Mage::helper('M2ePro')->__('UPC/EAN') . '</b>: ' . $attrValue;
312
+ }
313
+
314
+ return $value;
315
+ }
316
+
317
+ public function callbackColumnStatus($value, $row, $column, $isExport)
318
+ {
319
+ $generalId = $row->getData('general_id');
320
+ $searchSettingsStatus = $row->getData('search_settings_status');
321
+ $skinUrl = $this->getSkinUrl('M2ePro');
322
+ $style = 'display: inline-block; vertical-align: middle;';
323
+
324
+ if (empty($generalId) && empty($searchSettingsStatus)) {
325
+
326
+ $msg = Mage::helper('M2ePro')->__('None');
327
+ $tip = Mage::helper('M2ePro')->__('The Search of Product was not performed yet');
328
+
329
+ return <<<HTML
330
+ <span style="color: gray; {$style}">{$msg}</span>&nbsp;
331
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
332
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
333
+ <img src="{$skinUrl}/images/help.png">
334
+ <span>{$tip}</span>
335
+ </span><br/>
336
+ HTML;
337
+ }
338
+
339
+ switch ($searchSettingsStatus) {
340
+ case Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS:
341
+ $searchData = json_decode($row->getData('search_settings_data'), true);
342
+
343
+ $msg = Mage::helper('M2ePro')->__('In Progress');
344
+ $tip = Mage::helper('M2ePro')->__(
345
+ 'The Search is being performed now by %type% "%value%"',
346
+ $this->prepareSearchType($searchData['type']), $searchData['value']
347
+ );
348
+
349
+ return <<<HTML
350
+ <span style="color: orange; {$style}">{$msg}</span>&nbsp;
351
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
352
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
353
+ <img src="{$skinUrl}/images/help.png">
354
+ <span>{$tip}</span>
355
+ </span><br/>
356
+ HTML;
357
+
358
+ case Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND:
359
+
360
+ $msg = Mage::helper('M2ePro')->__('Product was not found');
361
+ $tip = Mage::helper('M2ePro')->__('There are no Products found on Amazon after the Automatic Search
362
+ was performed according to Listing Search Settings.');
363
+
364
+ return <<<HTML
365
+ <span style="color: red; {$style}">{$msg}</span>&nbsp;
366
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
367
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
368
+ <img src="{$skinUrl}/images/help.png">
369
+ <span>{$tip}</span>
370
+ </span><br/>
371
+ HTML;
372
+ case Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_ACTION_REQUIRED:
373
+
374
+ $searchData = json_decode($row->getData('search_settings_data'), true);
375
+
376
+ $lpId = $row->getData('id');
377
+
378
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
379
+ if (strlen($productTitle) > 60) {
380
+ $productTitle = substr($productTitle, 0, 60) . '...';
381
+ }
382
+ $productTitle = Mage::helper('M2ePro')->__(
383
+ 'Search ASIN/ISBN For &quot;%product_title%&quot;',
384
+ $productTitle
385
+ );
386
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
387
+
388
+ $linkTxt = Mage::helper('M2ePro')->__('Choose ASIN/ISBN');
389
+
390
+ $msg = Mage::helper('M2ePro')->__('Action Required');
391
+ $tip = Mage::helper('M2ePro')->__(
392
+ 'Please choose one of the Results that were found by %type% "%value%"',
393
+ $this->prepareSearchType($searchData['type']), $searchData['value']
394
+ );
395
+
396
+ return <<<HTML
397
+ <span style="color: orange; {$style}">{$msg}</span>&nbsp;
398
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
399
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
400
+ <img src="{$skinUrl}/images/help.png">
401
+ <span>{$tip}</span>
402
+ </span><br/>
403
+ <a href="javascript:;" title="{$linkTxt}"
404
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">{$linkTxt}</a>
405
+ HTML;
406
+ }
407
+
408
+ $searchInfo = json_decode($row->getData('general_id_search_info'), true);
409
+
410
+ $msg = Mage::helper('M2ePro')->__('Completed');
411
+ $tip = Mage::helper('M2ePro')->__(
412
+ 'Product was found by %type% "%value%"',
413
+ $this->prepareSearchType($searchInfo['type']), $searchInfo['value']
414
+ );
415
+
416
+ return <<<HTML
417
+ <span style="color: green; {$style}">{$msg}</span>&nbsp;
418
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
419
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
420
+ <img src="{$skinUrl}/images/help.png">
421
+ <span>{$tip}</span>
422
+ </span><br/>
423
+ HTML;
424
+ }
425
+
426
+ private function prepareSearchType($searchType)
427
+ {
428
+ if ($searchType == 'string') {
429
+ return 'query';
430
+ }
431
+
432
+ return strtoupper($searchType);
433
+ }
434
+
435
+ // ####################################
436
+
437
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
438
+ {
439
+ // ---------------------------------
440
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
441
+ // ---------------------------------
442
+
443
+ // ---------------------------------
444
+ $lpId = $row->getData('id');
445
+
446
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
447
+ if (strlen($productTitle) > 60) {
448
+ $productTitle = substr($productTitle, 0, 60) . '...';
449
+ }
450
+ $productTitle = Mage::helper('M2ePro')->__('Search ASIN/ISBN For &quot;%product_title%&quot;', $productTitle);
451
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
452
+ // ---------------------------------
453
+
454
+ // ---------------------------------
455
+
456
+ $searchSettingsStatus = $row->getData('search_settings_status');
457
+
458
+ // ---------------------------------
459
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
460
+
461
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN search in Progress.');
462
+ $iconSrc = $iconPath.'processing.gif';
463
+
464
+ return <<<HTML
465
+ &nbsp;
466
+ <a href="javascript: void(0);" title="{$tip}">
467
+ <img src="{$iconSrc}" alt="">
468
+ </a>
469
+ HTML;
470
+ }
471
+ // ---------------------------------
472
+
473
+ $na = Mage::helper('M2ePro')->__('N/A');
474
+ $tip = Mage::helper('M2ePro')->__('Search for ASIN/ISBN');
475
+ $iconSrc = $iconPath.'search.png';
476
+
477
+ return <<<HTML
478
+ {$na} &nbsp;
479
+ <a href="javascript:;" title="{$tip}"
480
+ onclick="ListingGridHandlerObj.productSearchHandler.showSearchManualPrompt('{$productTitle}',{$lpId});">
481
+ <img src="{$iconSrc}" alt="" width="16" height="16">
482
+ </a>
483
+ HTML;
484
+ }
485
+
486
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
487
+ {
488
+ $generalId = $row->getData('general_id');
489
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
490
+
491
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
492
+ $generalId,
493
+ $marketplaceId
494
+ );
495
+
496
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
497
+
498
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
499
+
500
+ if (!empty($generalIdSearchInfo)) {
501
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
502
+ }
503
+
504
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
505
+
506
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
507
+
508
+ $text = <<<HTML
509
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
510
+ HTML;
511
+
512
+ } else {
513
+
514
+ $text = <<<HTML
515
+ <a href="{$url}" target="_blank">{$generalId}</a>
516
+ HTML;
517
+
518
+ }
519
+
520
+ // ---------------------------------
521
+ $hasInActionLock = $this->getLockedData($row);
522
+ $hasInActionLock = $hasInActionLock['in_action'];
523
+ // ---------------------------------
524
+
525
+ if ($hasInActionLock) {
526
+ return $text;
527
+ }
528
+
529
+ $listingProductId = (int)$row->getData('id');
530
+
531
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
532
+ $iconSrc = $iconPath.'unassign.png';
533
+
534
+ $text .= <<<HTML
535
+ <a href="javascript:;"
536
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$listingProductId});"
537
+ title="{$tip}">
538
+ <img src="{$iconSrc}" width="16" height="16"/>
539
+ </a>
540
+ HTML;
541
+
542
+ return $text;
543
+ }
544
+
545
+ // ####################################
546
+
547
+ protected function callbackFilterTitle($collection, $column)
548
+ {
549
+ $value = $column->getFilter()->getValue();
550
+
551
+ if ($value == null) {
552
+ return;
553
+ }
554
+
555
+ $collection->addFieldToFilter(
556
+ array(
557
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
558
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
559
+ )
560
+ );
561
+ }
562
+
563
+ protected function callbackFilterStatus($collection, $column)
564
+ {
565
+ $value = $column->getFilter()->getValue();
566
+
567
+ if ($value == null) {
568
+ return;
569
+ }
570
+
571
+ if ($value == self::SEARCH_SETTINGS_STATUS_NONE) {
572
+ $collection->addFieldToFilter('general_id', array('null' => NULL));
573
+ $collection->addFieldToFilter('search_settings_status', array('null' => NULL));
574
+ return;
575
+ }
576
+
577
+ if ($value == self::SEARCH_SETTINGS_STATUS_COMPLETED) {
578
+ $collection->addFieldToFilter(
579
+ array(
580
+ array('attribute'=>'general_id', 'notnull' => NULL)
581
+ )
582
+ );
583
+
584
+ return;
585
+ }
586
+
587
+ $collection->addFieldToFilter(
588
+ array(
589
+ array('attribute' => 'search_settings_status', 'eq' => $value)
590
+ )
591
+ );
592
+ }
593
+
594
+ // ####################################
595
+
596
+ public function getRowUrl($row)
597
+ {
598
+ return false;
599
+ }
600
+
601
+ // ####################################
602
+
603
+ protected function _toHtml()
604
+ {
605
+ $disableMassactionSearch = '';
606
+ $startSearch = '';
607
+
608
+ $listing = $this->getListing();
609
+
610
+ if (!$listing->getChildObject()->isGeneralIdAttributeMode() &&
611
+ !$listing->getChildObject()->isWorldwideIdAttributeMode()) {
612
+
613
+ if (!$listing->getChildObject()->isSearchByMagentoTitleModeEnabled()) {
614
+ $gridId = $this->getId();
615
+
616
+ $disableMassactionSearch = <<<JS
617
+ var mmassActionEl = $("{$gridId}_massaction-select");
618
+
619
+ if (mmassActionEl && mmassActionEl.select('option[value="assignGeneralId"]').length > 0) {
620
+ var assignGeneralIdOption = mmassActionEl.select('option[value="assignGeneralId"]')[0];
621
+ assignGeneralIdOption.disabled = true;
622
+
623
+ mmassActionEl.insert({bottom: assignGeneralIdOption.remove()});
624
+ }
625
+ JS;
626
+ }
627
+
628
+ } else {
629
+ $autoSearchSetting = $listing->getSetting('additional_data', 'auto_search_was_performed');
630
+
631
+ if (!$autoSearchSetting) {
632
+ $listing->setSetting('additional_data', 'auto_search_was_performed', 1);
633
+ $listing->save();
634
+
635
+ $startSearch = <<<JS
636
+ ListingGridHandlerObj.getGridMassActionObj().selectAll();
637
+ ListingGridHandlerObj.productSearchHandler.searchGeneralIdAuto(ListingGridHandlerObj.getSelectedProductsString());
638
+ JS;
639
+ }
640
+ }
641
+
642
+ $javascriptsMain = <<<JAVASCRIPT
643
+ <script type="text/javascript">
644
+
645
+ if (typeof ListingGridHandlerObj != 'undefined') {
646
+ ListingGridHandlerObj.afterInitPage();
647
+ {$disableMassactionSearch}
648
+ }
649
+
650
+ Event.observe(window, 'load', function() {
651
+ setTimeout(function() {
652
+ ListingGridHandlerObj.afterInitPage();
653
+ {$disableMassactionSearch}
654
+ {$startSearch}
655
+ }, 350);
656
+ });
657
+
658
+ </script>
659
+ JAVASCRIPT;
660
+
661
+ return parent::_toHtml() . $javascriptsMain;
662
+ }
663
+
664
+ // ####################################
665
+
666
+ /**
667
+ * @return Ess_M2ePro_Model_Amazon_Listing
668
+ * @throws Exception
669
+ */
670
+ public function getListing()
671
+ {
672
+ if (!$listingId = $this->getRequest()->getParam('id')) {
673
+ throw new Exception('Listing is not defined');
674
+ }
675
+
676
+ if (is_null($this->listing)) {
677
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing', $listingId);
678
+ }
679
+
680
+ return $this->listing;
681
+ }
682
+
683
+ // ####################################
684
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonListingViewHelp');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/help.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NewAsinPopup.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_NewAsinPopup extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('searchAsinNewAsinPopup');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/new_asin_popup.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ $data = array(
24
+ 'label' => Mage::helper('M2ePro')->__('Yes'),
25
+ 'onclick' => 'ListingGridHandlerObj.newAsinPopupYesClick()'
26
+ );
27
+ $yesButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
28
+ $this->setChild('yesBtn', $yesButton);
29
+
30
+ $data = array(
31
+ 'label' => Mage::helper('M2ePro')->__('No'),
32
+ 'onclick' => 'ListingGridHandlerObj.noAsinPopupNoClick()'
33
+ );
34
+ $noButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
35
+ $this->setChild('noBtn', $noButton);
36
+ }
37
+
38
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/SearchSettings.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_SearchSettings
8
+ extends Mage_Adminhtml_Block_Widget_Form
9
+ {
10
+ protected $component;
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('searchSettings');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/search_settings.phtml');
22
+ }
23
+
24
+ protected function _prepareForm()
25
+ {
26
+ // Prepare action
27
+ // -------------------
28
+ $action = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/saveSearchSettings', array(
29
+ 'id' => (int)$this->getRequest()->getParam('id')
30
+ ));
31
+ // -------------------
32
+
33
+ $form = new Varien_Data_Form(array(
34
+ 'id' => 'search_settings_form',
35
+ 'action' => $action,
36
+ 'method' => 'post'
37
+ ));
38
+
39
+ $form->setUseContainer(true);
40
+ $this->setForm($form);
41
+
42
+ return parent::_prepareForm();
43
+ }
44
+
45
+ protected function _beforeToHtml()
46
+ {
47
+ $child = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_search');
48
+
49
+ $this->setChild('content', $child);
50
+
51
+ return parent::_beforeToHtml();
52
+ }
53
+
54
+ // ########################################
55
+
56
+ protected function _toHtml()
57
+ {
58
+ $buttonSave = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
59
+ 'id' => 'save_search_settings',
60
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
61
+ 'style' => 'float: right; margin: 0 0 7px 5px;',
62
+ 'onclick' => 'ListingGridHandlerObj.saveSearchSettings()'
63
+ ));
64
+
65
+ $this->setChild('save_search_settings', $buttonSave);
66
+
67
+ return parent::_toHtml();
68
+ }
69
+
70
+ // ########################################
71
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/General.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Tabs_General
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_General
9
+ {
10
+ // #############################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->sessionKey = 'amazon_listing_create';
19
+ $this->setId('amazonListingAddTabsGeneral');
20
+ $this->setTemplate('M2ePro/common/amazon/listing/add/tabs/general.phtml');
21
+ //------------------------------
22
+ }
23
+
24
+ // #############################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Search.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Tabs_Search
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Search
9
+ {
10
+ // #############################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->sessionKey = 'amazon_listing_create';
19
+ $this->setId('amazonListingAddTabsGeneral');
20
+ $this->setTemplate('M2ePro/common/amazon/listing/add/tabs/search.phtml');
21
+ //------------------------------
22
+ }
23
+
24
+ // #############################################
25
+
26
+ protected function getDefaults()
27
+ {
28
+ return self::getDefaultFieldsValues();
29
+ }
30
+
31
+ static function getDefaultFieldsValues()
32
+ {
33
+ return array(
34
+ 'general_id_mode' => Ess_M2ePro_Model_Amazon_Listing::GENERAL_ID_MODE_NOT_SET,
35
+ 'general_id_custom_attribute' => '',
36
+
37
+ 'worldwide_id_mode' => Ess_M2ePro_Model_Amazon_Listing::WORLDWIDE_ID_MODE_NOT_SET,
38
+ 'worldwide_id_custom_attribute' => '',
39
+
40
+ 'search_by_magento_title_mode' => Ess_M2ePro_Model_Amazon_Listing::SEARCH_BY_MAGENTO_TITLE_MODE_NONE
41
+ );
42
+ }
43
+
44
+ // ####################################
45
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Selling.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Tabs_Selling
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Selling
9
+ {
10
+ // #############################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->component = Ess_M2ePro_Helper_Component_Amazon::NICK;
19
+ $this->sessionKey = 'amazon_listing_create';
20
+ $this->setId('amazonListingAddTabsSelling');
21
+ $this->setTemplate('M2ePro/common/amazon/listing/add/tabs/selling.phtml');
22
+ //------------------------------
23
+ }
24
+
25
+ // #############################################
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ $buttonBlock = $this->getLayout()
30
+ ->createBlock('adminhtml/widget_button')
31
+ ->setData( array(
32
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
33
+ 'onclick' => "AmazonListingChannelSettingsHandlerObj.appendToText"
34
+ ."('condition_note_custom_attribute', 'condition_note_value');",
35
+ 'class' => 'condition_note_value_insert_button'
36
+ ) );
37
+ $this->setChild('condition_note_value_insert_button',$buttonBlock);
38
+
39
+ return parent::_beforeToHtml();
40
+ }
41
+
42
+ // #############################################
43
+
44
+ protected function getDefaults()
45
+ {
46
+ return self::getDefaultFieldsValues();
47
+ }
48
+
49
+ static function getDefaultFieldsValues()
50
+ {
51
+ return array(
52
+ 'sku_mode' => Ess_M2ePro_Model_Amazon_Listing::SKU_MODE_DEFAULT,
53
+ 'sku_custom_attribute' => '',
54
+ 'generate_sku_mode' => Ess_M2ePro_Model_Amazon_Listing::GENERATE_SKU_MODE_NO,
55
+
56
+ 'template_selling_format_id' => '',
57
+ 'template_synchronization_id' => '',
58
+
59
+ 'condition_mode' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_MODE_DEFAULT,
60
+ 'condition_value' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_NEW,
61
+ 'condition_custom_attribute' => '',
62
+ 'condition_note_mode' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_NOTE_MODE_NONE,
63
+ 'condition_note_value' => '',
64
+
65
+ 'handling_time_mode' => Ess_M2ePro_Model_Amazon_Listing::HANDLING_TIME_MODE_NONE,
66
+ 'handling_time_value' => '',
67
+ 'handling_time_custom_attribute' => '',
68
+
69
+ 'restock_date_mode' => Ess_M2ePro_Model_Amazon_Listing::RESTOCK_DATE_MODE_NONE,
70
+ 'restock_date_value' => Mage::helper('M2ePro')->getCurrentTimezoneDate(),
71
+ 'restock_date_custom_attribute' => ''
72
+ );
73
+ }
74
+
75
+ // ####################################
76
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode
9
+ {
10
+
11
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Category
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category
9
+ {
10
+ // ####################################
11
+
12
+ protected function prepareGroupsGrid()
13
+ {
14
+ $groupGrid = $this->getLayout()
15
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_autoAction_mode_category_group_grid');
16
+ $groupGrid->prepareGrid();
17
+ $this->setChild('group_grid', $groupGrid);
18
+
19
+ return $groupGrid;
20
+ }
21
+
22
+ // ####################################
23
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Form.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Category_Form
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Form
9
+ {
10
+
11
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ $this->setTemplate('M2ePro/common/amazon/listing/auto_action/mode/category/form.phtml');
18
+ }
19
+
20
+ // ####################################
21
+
22
+ public function getDefault()
23
+ {
24
+ return array(
25
+ 'id' => NULL,
26
+ 'title' => NULL,
27
+ 'category_id' => NULL,
28
+ 'adding_mode' => Ess_M2ePro_Model_Listing::ADDING_MODE_NONE,
29
+ 'deleting_mode' => Ess_M2ePro_Model_Listing::DELETING_MODE_NONE,
30
+ 'adding_description_template_id' => NULL
31
+ );
32
+ }
33
+
34
+ // ####################################
35
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Group/Grid.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Category_Group_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Group_Grid
9
+ {
10
+
11
+ public function getGridUrl()
12
+ {
13
+ return $this->getUrl('*/adminhtml_common_listing_autoAction/getCategoryGroupGrid', array('_current' => true));
14
+ }
15
+
16
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Global.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Global
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Global
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setTemplate('M2ePro/common/amazon/listing/auto_action/mode/global.phtml');
17
+ }
18
+
19
+ // ####################################
20
+
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Website.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Website
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Website
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setTemplate('M2ePro/common/amazon/listing/auto_action/mode/website.phtml');
17
+ }
18
+
19
+ // ####################################
20
+
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonListingEdit');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_amazon_listing';
21
+ $this->_mode = 'edit';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+
28
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
29
+ $headerText = Mage::helper('M2ePro')->__(
30
+ 'Edit %component_name% Listing Settings "%listing_title%"',
31
+ Mage::helper('M2ePro/Component_Amazon')->getTitle(),
32
+ $this->escapeHtml($listingData['title'])
33
+ );
34
+ } else {
35
+ $headerText = Mage::helper('M2ePro')->__(
36
+ 'Edit Listing Settings "%listing_title%"',
37
+ $this->escapeHtml($listingData['title'])
38
+ );
39
+ }
40
+
41
+ $this->_headerText = $headerText;
42
+ //------------------------------
43
+
44
+ // Set buttons actions
45
+ //------------------------------
46
+ $this->removeButton('back');
47
+ $this->removeButton('reset');
48
+ $this->removeButton('delete');
49
+ $this->removeButton('add');
50
+ $this->removeButton('save');
51
+ $this->removeButton('edit');
52
+ //------------------------------
53
+
54
+ if (!is_null($this->getRequest()->getParam('back'))) {
55
+ //------------------------------
56
+ $url = Mage::helper('M2ePro')->getBackUrl(
57
+ '*/adminhtml_common_listing/index',
58
+ array(
59
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
60
+ )
61
+ );
62
+ $this->_addButton('back', array(
63
+ 'label' => Mage::helper('M2ePro')->__('Back'),
64
+ 'onclick' => 'CommonListingSettingsHandlerObj.back_click(\''.$url.'\')',
65
+ 'class' => 'back'
66
+ ));
67
+ //------------------------------
68
+ }
69
+
70
+ //------------------------------
71
+ $this->_addButton('auto_action', array(
72
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
73
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
74
+ ));
75
+ //------------------------------
76
+
77
+ $backUrl = Mage::helper('M2ePro')->getBackUrlParam('list');
78
+
79
+ //------------------------------
80
+ $url = $this->getUrl(
81
+ '*/adminhtml_common_amazon_listing/save',
82
+ array(
83
+ 'id' => $listingData['id'],
84
+ 'back' => $backUrl
85
+ )
86
+ );
87
+ $this->_addButton('save', array(
88
+ 'label' => Mage::helper('M2ePro')->__('Save'),
89
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_click(\'' . $url . '\')',
90
+ 'class' => 'save'
91
+ ));
92
+ //------------------------------
93
+
94
+ //------------------------------
95
+ $this->_addButton('save_and_continue', array(
96
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
97
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_and_edit_click(\''.$url.'\', 1)',
98
+ 'class' => 'save'
99
+ ));
100
+ //------------------------------
101
+ }
102
+
103
+ // ####################################
104
+
105
+ protected function _beforeToHtml()
106
+ {
107
+ parent::_beforeToHtml();
108
+
109
+ //------------------------------
110
+ $tabs = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_edit_tabs');
111
+ $this->setChild('tabs', $tabs);
112
+ //------------------------------
113
+
114
+ return $this;
115
+ }
116
+
117
+ // ####################################
118
+
119
+ public function getFormHtml()
120
+ {
121
+ $listing = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
122
+ 'Listing', $this->getRequest()->getParam('id')
123
+ );
124
+
125
+ $viewHeaderBlock = $this->getLayout()->createBlock(
126
+ 'M2ePro/adminhtml_listing_view_header','',
127
+ array('listing' => $listing)
128
+ );
129
+
130
+ $tabs = $this->getChild('tabs');
131
+
132
+ $urls = Mage::helper('M2ePro')->getControllerActions(
133
+ 'adminhtml_common_listing_autoAction',
134
+ array(
135
+ 'listing_id' => $this->getRequest()->getParam('id'),
136
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
137
+ )
138
+ );
139
+ $urls = json_encode($urls);
140
+
141
+ /** @var $helper Ess_M2ePro_Helper_Data */
142
+ $helper = Mage::helper('M2ePro');
143
+
144
+ $translations = json_encode(array(
145
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
146
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
147
+ 'You must select at least 1 category.' => $helper->__('You must select at least 1 category.'),
148
+ 'Rule with the same title already exists.' => $helper->__('Rule with the same title already exists.')
149
+ ));
150
+
151
+ $js = <<<HTML
152
+ <script type="text/javascript">
153
+
154
+ M2ePro.url.add({$urls});
155
+ M2ePro.translator.add({$translations});
156
+
157
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
158
+
159
+ </script>
160
+ HTML;
161
+
162
+ return $viewHeaderBlock->toHtml() . $tabs->toHtml() . parent::getFormHtml() . $js;
163
+ }
164
+
165
+ // ####################################
166
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Form.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonListingEditForm');
16
+ //------------------------------
17
+ }
18
+
19
+ protected function _prepareForm()
20
+ {
21
+ $form = new Varien_Data_Form(array(
22
+ 'id' => 'edit_form',
23
+ 'action' => $this->getUrl('*/adminhtml_common_amazon_listing/save'),
24
+ 'method' => 'post',
25
+ 'enctype' => 'multipart/form-data'
26
+ ));
27
+
28
+ $form->setUseContainer(true);
29
+ $this->setForm($form);
30
+
31
+ return parent::_prepareForm();
32
+ }
33
+
34
+ // ####################################
35
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Tabs.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonListingEditTabs');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('widget/tabshoriz.phtml');
19
+ $this->setDestElementId('edit_form');
20
+ }
21
+
22
+ protected function _beforeToHtml()
23
+ {
24
+ $this->addTab('selling', array(
25
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
26
+ 'title' => Mage::helper('M2ePro')->__('Selling Settings'),
27
+ 'content' => $this->getLayout()
28
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_selling')
29
+ ->toHtml(),
30
+ ));
31
+
32
+ $this->addTab('search', array(
33
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
34
+ 'title' => Mage::helper('M2ePro')->__('Search Settings'),
35
+ 'content' => $this->getLayout()
36
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_search')
37
+ ->toHtml(),
38
+ ));
39
+
40
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'selling'));
41
+
42
+ return parent::_beforeToHtml();
43
+ }
44
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Filter.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Filter extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonListingFilter');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/filter.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ //-------------------------------
24
+ $maxRecordsQuantity = Mage::helper('M2ePro/View_Common')->getAutocompleteMaxItems();
25
+ //-------------------------------
26
+
27
+ //-------------------------------
28
+ $this->selectedSellingFormatTemplate = (int)$this->getRequest()
29
+ ->getParam('filter_amazon_selling_format_template');
30
+ $sellingFormatTemplatesCollection = Mage::helper('M2ePro/Component_Amazon')
31
+ ->getCollection('Template_SellingFormat')
32
+ ->setOrder('title', 'ASC');
33
+
34
+ if ($sellingFormatTemplatesCollection->getSize() < $maxRecordsQuantity) {
35
+ $this->sellingFormatTemplatesDropDown = true;
36
+ $sellingFormatTemplates = array();
37
+
38
+ foreach ($sellingFormatTemplatesCollection->getItems() as $item) {
39
+ $sellingFormatTemplates[$item->getId()] = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
40
+ }
41
+ $this->sellingFormatTemplates = $sellingFormatTemplates;
42
+ } else {
43
+ $this->sellingFormatTemplatesDropDown = false;
44
+ $this->sellingFormatTemplates = array();
45
+
46
+ if ($this->selectedSellingFormatTemplate > 0) {
47
+ $this->selectedSellingFormatTemplateValue = Mage::helper('M2ePro/Component_Amazon')
48
+ ->getCachedObject('Template_SellingFormat',
49
+ $this->selectedSellingFormatTemplate, NULL,
50
+ array('template'))
51
+ ->getTitle();
52
+ } else {
53
+ $this->selectedSellingFormatTemplateValue = '';
54
+ }
55
+ }
56
+
57
+ $this->sellingFormatTemplateUrl = $this->makeCutUrlForTemplate('filter_amazon_selling_format_template');
58
+ //-------------------------------
59
+
60
+ //-------------------------------
61
+ $this->selectedSynchronizationTemplate = (int)$this->getRequest()
62
+ ->getParam('filter_amazon_synchronization_template');
63
+ $synchronizationsTemplatesCollection = Mage::helper('M2ePro/Component_Amazon')
64
+ ->getCollection('Template_Synchronization')
65
+ ->setOrder('title', 'ASC');
66
+
67
+ if ($synchronizationsTemplatesCollection->getSize() < $maxRecordsQuantity) {
68
+ $this->synchronizationsTemplatesDropDown = true;
69
+ $synchronizationsTemplates = array();
70
+
71
+ foreach ($synchronizationsTemplatesCollection->getItems() as $item) {
72
+ $synchronizationsTemplates[$item->getId()] = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
73
+ }
74
+ $this->synchronizationsTemplates = $synchronizationsTemplates;
75
+ } else {
76
+ $this->synchronizationsTemplatesDropDown = false;
77
+ $this->synchronizationsTemplates = array();
78
+
79
+ if ($this->selectedSynchronizationTemplate > 0) {
80
+ $this->selectedSynchronizationTemplateValue = Mage::helper('M2ePro/Component_Amazon')
81
+ ->getCachedObject('Template_Synchronization',
82
+ $this->selectedSynchronizationTemplate, NULL,
83
+ array('template'))
84
+ ->getTitle();
85
+ } else {
86
+ $this->selectedSynchronizationTemplateValue = '';
87
+ }
88
+ }
89
+
90
+ $this->synchronizationTemplateUrl = $this->makeCutUrlForTemplate('filter_amazon_synchronization_template');
91
+ //-------------------------------
92
+
93
+ return parent::_beforeToHtml();
94
+ }
95
+
96
+ protected function makeCutUrlForTemplate($templateUrlParamName)
97
+ {
98
+ $paramsFilters = array(
99
+ 'filter_amazon_selling_format_template',
100
+ 'filter_amazon_synchronization_template'
101
+ );
102
+
103
+ $params = array();
104
+ foreach ($paramsFilters as $value) {
105
+ if ($value != $templateUrlParamName) {
106
+ $params[$value] = $this->getRequest()->getParam($value);
107
+ }
108
+ }
109
+
110
+ $params['tab'] = Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON;
111
+
112
+ return $this->getUrl('*/adminhtml_common_listing/*',$params);
113
+ }
114
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Grid.php ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Grid
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingGrid');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareCollection()
22
+ {
23
+ // Update statistic table values
24
+ Mage::getResourceModel('M2ePro/Amazon_Listing')->updateStatisticColumns();
25
+
26
+ // Get collection of listings
27
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing');
28
+
29
+ // Set global filters
30
+ //--------------------------
31
+ $filterSellingFormatTemplate = $this->getRequest()->getParam('filter_amazon_selling_format_template');
32
+ $filterSynchronizationTemplate = $this->getRequest()->getParam('filter_amazon_synchronization_template');
33
+
34
+ if ($filterSellingFormatTemplate != 0) {
35
+ $collection->addFieldToFilter(
36
+ 'second_table.template_selling_format_id', (int)$filterSellingFormatTemplate
37
+ );
38
+ }
39
+
40
+ if ($filterSynchronizationTemplate != 0) {
41
+ $collection->addFieldToFilter(
42
+ 'second_table.template_synchronization_id', (int)$filterSynchronizationTemplate
43
+ );
44
+ }
45
+ //--------------------------
46
+
47
+ // join marketplace and accounts
48
+ //--------------------------
49
+ $collection->getSelect()
50
+ ->join(array('a'=>Mage::getResourceModel('M2ePro/Account')->getMainTable()),
51
+ '(`a`.`id` = `main_table`.`account_id`)',
52
+ array('account_title'=>'title'))
53
+ ->join(array('m'=>Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
54
+ '(`m`.`id` = `main_table`.`marketplace_id`)',
55
+ array('marketplace_title'=>'title'));
56
+ //--------------------------
57
+
58
+ //exit($collection->getSelect()->__toString());
59
+
60
+ // Set collection to grid
61
+ $this->setCollection($collection);
62
+
63
+ return parent::_prepareCollection();
64
+ }
65
+
66
+ // ####################################
67
+
68
+ protected function _prepareMassaction()
69
+ {
70
+ // Set massaction identifiers
71
+ //--------------------------------
72
+ $this->setMassactionIdField('main_table.id');
73
+ $this->getMassactionBlock()->setFormFieldName('ids');
74
+ //--------------------------------
75
+
76
+ // Set clear log action
77
+ //--------------------------------
78
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
79
+ '*/adminhtml_common_listing/index',
80
+ array(
81
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
82
+ )
83
+ );
84
+
85
+ $this->getMassactionBlock()->addItem('clear_logs', array(
86
+ 'label' => Mage::helper('M2ePro')->__('Clear Log(s)'),
87
+ 'url' => $this->getUrl('*/adminhtml_listing/clearLog', array('back' => $backUrl)),
88
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
89
+ ));
90
+ //--------------------------------
91
+
92
+ // Set remove listings action
93
+ //--------------------------------
94
+ $this->getMassactionBlock()->addItem('delete_listings', array(
95
+ 'label' => Mage::helper('M2ePro')->__('Delete Listing(s)'),
96
+ 'url' => $this->getUrl('*/adminhtml_common_amazon_listing/delete'),
97
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
98
+ ));
99
+ //--------------------------------
100
+
101
+ return parent::_prepareMassaction();
102
+ }
103
+
104
+ // ####################################
105
+
106
+ protected function getColumnActionsItems()
107
+ {
108
+ $helper = Mage::helper('M2ePro');
109
+ $backUrl = $helper->makeBackUrlParam(
110
+ '*/adminhtml_common_listing/index',
111
+ array(
112
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
113
+ )
114
+ );
115
+
116
+ $actions = array(
117
+ 'manageProducts' => array(
118
+ 'caption' => $helper->__('Manage'),
119
+ 'group' => 'products_actions',
120
+ 'field' => 'id',
121
+ 'url' => array(
122
+ 'base' => '*/adminhtml_common_amazon_listing/view',
123
+ 'params' => array('back' => $backUrl)
124
+ )
125
+ ),
126
+
127
+ 'addProductsFromProductsList' => array(
128
+ 'caption' => $helper->__('Add From Products List'),
129
+ 'group' => 'products_actions',
130
+ 'field' => 'id',
131
+ 'url' => array(
132
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
133
+ 'params' => array(
134
+ 'back' => $backUrl,
135
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
136
+ 'step' => 2,
137
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
138
+ )
139
+ )
140
+ ),
141
+
142
+ 'addProductsFromCategories' => array(
143
+ 'caption' => $helper->__('Add From Categories'),
144
+ 'group' => 'products_actions',
145
+ 'field' => 'id',
146
+ 'url' => array(
147
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
148
+ 'params' => array(
149
+ 'back' => $backUrl,
150
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
151
+ 'step' => 2,
152
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
153
+ )
154
+ )
155
+ ),
156
+
157
+ 'automaticActions' => array(
158
+ 'caption' => $helper->__('Auto Add/Remove Rules'),
159
+ 'group' => 'products_actions',
160
+ 'field' => 'id',
161
+ 'url' => array(
162
+ 'base' => '*/adminhtml_common_amazon_listing/view',
163
+ 'params' => array(
164
+ 'back' => $backUrl,
165
+ 'auto_actions' => 1
166
+ )
167
+ )
168
+ ),
169
+
170
+ 'viewLog' => array(
171
+ 'caption' => $helper->__('View Log'),
172
+ 'group' => 'other',
173
+ 'field' => 'id',
174
+ 'url' => array(
175
+ 'base' => '*/adminhtml_common_log/listing',
176
+ 'params' => array(
177
+ 'back' => $backUrl,
178
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_AMAZON
179
+ )
180
+ )
181
+ ),
182
+
183
+ 'clearLogs' => array(
184
+ 'caption' => $helper->__('Clear Log'),
185
+ 'confirm' => $helper->__('Are you sure?'),
186
+ 'group' => 'other',
187
+ 'field' => 'id',
188
+ 'url' => array(
189
+ 'base' => '*/adminhtml_listing/clearLog',
190
+ 'params' => array(
191
+ 'back' => $backUrl
192
+ )
193
+ )
194
+ ),
195
+
196
+ 'deleteListing' => array(
197
+ 'caption' => $helper->__('Delete Listing'),
198
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
199
+ 'group' => 'other',
200
+ 'field' => 'id',
201
+ 'url' => array(
202
+ 'base' => '*/adminhtml_common_amazon_listing/delete',
203
+ )
204
+ ),
205
+
206
+ 'editListingTitle' => array(
207
+ 'caption' => $helper->__('Title'),
208
+ 'group' => 'edit_actions',
209
+ 'confirm' => $helper->__('Are you sure?'),
210
+ 'field' => 'id',
211
+ 'onclick_action' => 'editListingTitle'
212
+ ),
213
+
214
+ 'sellingSetting' => array(
215
+ 'caption' => $helper->__('Selling'),
216
+ 'group' => 'edit_actions',
217
+ 'field' => 'id',
218
+ 'url' => array(
219
+ 'base' => '*/adminhtml_common_amazon_listing/edit',
220
+ 'params' => array(
221
+ 'back' => $backUrl,
222
+ 'tab' => 'selling'
223
+ )
224
+ )
225
+ ),
226
+
227
+ 'searchSetting' => array(
228
+ 'caption' => $helper->__('Search'),
229
+ 'group' => 'edit_actions',
230
+ 'field' => 'id',
231
+ 'url' => array(
232
+ 'base' => '*/adminhtml_common_amazon_listing/edit',
233
+ 'params' => array(
234
+ 'back' => $backUrl,
235
+ 'tab' => 'search'
236
+ )
237
+ )
238
+ )
239
+ );
240
+
241
+ return $actions;
242
+ }
243
+
244
+ // ####################################
245
+
246
+ public function callbackColumnSoldProducts($value, $row, $column, $isExport)
247
+ {
248
+ return $this->getColumnValue($value);
249
+ }
250
+
251
+ public function callbackColumnTitle($value, $row, $column, $isExport)
252
+ {
253
+ $value = '<span id="listing_title_'.$row->getId().'">' .
254
+ Mage::helper('M2ePro')->escapeHtml($value) .
255
+ '</span>';
256
+
257
+ /* @var $row Ess_M2ePro_Model_Listing */
258
+ $accountTitle = $row->getData('account_title');
259
+ $marketplaceTitle = $row->getData('marketplace_title');
260
+
261
+ $storeModel = Mage::getModel('core/store')->load($row->getStoreId());
262
+ $storeView = $storeModel->getWebsite()->getName();
263
+ if (strtolower($storeView) != 'admin') {
264
+ $storeView .= ' > '.$storeModel->getGroup()->getName();
265
+ $storeView .= ' > '.$storeModel->getName();
266
+ } else {
267
+ $storeView = Mage::helper('M2ePro')->__('Admin (Default Values)');
268
+ }
269
+
270
+ $account = Mage::helper('M2ePro')->__('Account');
271
+ $marketplace = Mage::helper('M2ePro')->__('Marketplace');
272
+ $store = Mage::helper('M2ePro')->__('Magento Store View');
273
+
274
+ $value .= <<<HTML
275
+ <div>
276
+ <span style="font-weight: bold">{$account}</span>: <span style="color: #505050">{$accountTitle}</span><br/>
277
+ <span style="font-weight: bold">{$marketplace}</span>: <span style="color: #505050">{$marketplaceTitle}</span><br/>
278
+ <span style="font-weight: bold">{$store}</span>: <span style="color: #505050">{$storeView}</span>
279
+ </div>
280
+ HTML;
281
+
282
+ return $value;
283
+ }
284
+
285
+ // ####################################
286
+
287
+ protected function callbackFilterTitle($collection, $column)
288
+ {
289
+ $value = $column->getFilter()->getValue();
290
+
291
+ if ($value == null) {
292
+ return;
293
+ }
294
+
295
+ $where = "main_table.title LIKE '%{$value}%' OR m.title LIKE '%{$value}%' OR a.title LIKE '%{$value}%'";
296
+ $collection->getSelect()->where($where);
297
+ }
298
+
299
+ // ####################################
300
+
301
+ public function getGridUrl()
302
+ {
303
+ return $this->getUrl('*/adminhtml_common_amazon_listing/listingGrid', array('_current'=>true));
304
+ }
305
+
306
+ public function getRowUrl($row)
307
+ {
308
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
309
+ '*/adminhtml_common_listing/index',
310
+ array(
311
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
312
+ )
313
+ );
314
+
315
+ return $this->getUrl(
316
+ '*/adminhtml_common_amazon_listing/view',
317
+ array(
318
+ 'id' => $row->getId(),
319
+ 'back' => $backUrl
320
+ )
321
+ );
322
+ }
323
+
324
+ // ####################################
325
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/Grid.php ADDED
@@ -0,0 +1,567 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Other_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ /** @var $this->connRead Varien_Db_Adapter_Pdo_Mysql */
16
+ $this->connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('amazonListingOtherGrid');
21
+ //------------------------------
22
+
23
+ // Set default values
24
+ //------------------------------
25
+ $this->setDefaultSort('id');
26
+ $this->setDefaultDir('DESC');
27
+ $this->setSaveParametersInSession(true);
28
+ $this->setUseAjax(true);
29
+ //------------------------------
30
+ }
31
+
32
+ public function getMassactionBlockName()
33
+ {
34
+ return 'M2ePro/adminhtml_grid_massaction';
35
+ }
36
+
37
+ // ####################################
38
+
39
+ protected function _prepareCollection()
40
+ {
41
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
42
+
43
+ $collection->getSelect()->joinLeft(
44
+ array('mp' => Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
45
+ 'mp.id = main_table.marketplace_id',
46
+ array('marketplace_title' => 'mp.title')
47
+ )->joinLeft(
48
+ array('am' => Mage::getResourceModel('M2ePro/Amazon_Marketplace')->getMainTable()),
49
+ 'am.marketplace_id = main_table.marketplace_id',
50
+ array('currency' => 'am.default_currency'));
51
+
52
+ // Add Filter By Account
53
+ if ($this->getRequest()->getParam('amazonAccount')) {
54
+ $collection->addFieldToFilter('main_table.account_id',
55
+ $this->getRequest()->getParam('amazonAccount'));
56
+ }
57
+
58
+ // Add Filter By Marketplace
59
+ if ($this->getRequest()->getParam('amazonMarketplace')) {
60
+ $collection->addFieldToFilter('main_table.marketplace_id',
61
+ $this->getRequest()->getParam('amazonMarketplace'));
62
+ }
63
+
64
+ //var_dump($collection->getSelect()->__toString()); exit();
65
+
66
+ $this->setCollection($collection);
67
+
68
+ return parent::_prepareCollection();
69
+ }
70
+
71
+ protected function _prepareColumns()
72
+ {
73
+ $this->addColumn('product_id', array(
74
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
75
+ 'align' => 'left',
76
+ 'width' => '80px',
77
+ 'type' => 'number',
78
+ 'index' => 'product_id',
79
+ 'filter_index' => 'product_id',
80
+ 'frame_callback' => array($this, 'callbackColumnProductId')
81
+ ));
82
+
83
+ $this->addColumn('title', array(
84
+ 'header' => Mage::helper('M2ePro')->__('Title / SKU'),
85
+ 'align' => 'left',
86
+ 'type' => 'text',
87
+ 'index' => 'title',
88
+ 'filter_index' => 'second_table.title',
89
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
90
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
91
+ ));
92
+
93
+ $this->addColumn('general_id', array(
94
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
95
+ 'align' => 'left',
96
+ 'width' => '100px',
97
+ 'type' => 'text',
98
+ 'index' => 'general_id',
99
+ 'filter_index' => 'general_id',
100
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
101
+ ));
102
+
103
+ $this->addColumn('online_qty', array(
104
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
105
+ 'align' => 'right',
106
+ 'width' => '100px',
107
+ 'type' => 'number',
108
+ 'index' => 'online_qty',
109
+ 'filter_index' => 'online_qty',
110
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
111
+ ));
112
+
113
+ $this->addColumn('online_price', array(
114
+ 'header' => Mage::helper('M2ePro')->__('Price'),
115
+ 'align' => 'right',
116
+ 'width' => '100px',
117
+ 'type' => 'number',
118
+ 'index' => 'online_price',
119
+ 'filter_index' => 'online_price',
120
+ 'frame_callback' => array($this, 'callbackColumnPrice')
121
+ ));
122
+
123
+ $this->addColumn('is_afn_channel', array(
124
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
125
+ 'width' => '100px',
126
+ 'index' => 'is_afn_channel',
127
+ 'filter_index' => 'second_table.is_afn_channel',
128
+ 'type' => 'options',
129
+ 'sortable' => false,
130
+ 'options' => array(
131
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
132
+ 1 => Mage::helper('M2ePro')->__('Amazon')
133
+ ),
134
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
135
+ ));
136
+
137
+ $this->addColumn('status', array(
138
+ 'header' => Mage::helper('M2ePro')->__('Status'),
139
+ 'width' => '60px',
140
+ 'index' => 'status',
141
+ 'filter_index' => 'main_table.status',
142
+ 'type' => 'options',
143
+ 'sortable' => false,
144
+ 'options' => array(
145
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
146
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
147
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
148
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
149
+ ),
150
+ 'frame_callback' => array($this, 'callbackColumnStatus')
151
+ ));
152
+
153
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
154
+ '*/adminhtml_common_listing_other/index',
155
+ array(
156
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
157
+ )
158
+ );
159
+
160
+ $this->addColumn('actions', array(
161
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
162
+ 'align' => 'left',
163
+ 'width' => '70px',
164
+ 'type' => 'action',
165
+ 'index' => 'actions',
166
+ 'filter' => false,
167
+ 'sortable' => false,
168
+ 'getter' => 'getId',
169
+ 'actions' => array(
170
+ array(
171
+ 'caption' => Mage::helper('M2ePro')->__('View Log'),
172
+ 'field' => 'id',
173
+ 'url' => array(
174
+ 'base' => '*/adminhtml_common_log/listingOther',
175
+ 'params' => array(
176
+ 'back' => $backUrl,
177
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK
178
+ )
179
+ )
180
+ ),
181
+ array(
182
+ 'caption' => Mage::helper('M2ePro')->__('Clear Log'),
183
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
184
+ 'field' => 'id',
185
+ 'url' => array(
186
+ 'base' => '*/adminhtml_listing_other/clearLog',
187
+ 'params' => array(
188
+ 'back' => $backUrl
189
+ )
190
+ )
191
+ )
192
+ )
193
+ ));
194
+
195
+ return parent::_prepareColumns();
196
+ }
197
+
198
+ protected function _prepareMassaction()
199
+ {
200
+ // Set mass-action identifiers
201
+ //--------------------------------
202
+ $this->setMassactionIdField('`main_table`.id');
203
+ $this->getMassactionBlock()->setFormFieldName('ids');
204
+ //--------------------------------
205
+
206
+ $this->getMassactionBlock()->setGroups(array(
207
+ 'mapping' => Mage::helper('M2ePro')->__('Mapping'),
208
+ 'other' => Mage::helper('M2ePro')->__('Other')
209
+ ));
210
+
211
+ // Set mass-action
212
+ //--------------------------------
213
+ $this->getMassactionBlock()->addItem('autoMapping', array(
214
+ 'label' => Mage::helper('M2ePro')->__('Map Item(s) Automatically'),
215
+ 'url' => '',
216
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
217
+ ), 'mapping');
218
+ $this->getMassactionBlock()->addItem('moving', array(
219
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Listing'),
220
+ 'url' => '',
221
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
222
+ ), 'other');
223
+ $this->getMassactionBlock()->addItem('removing', array(
224
+ 'label' => Mage::helper('M2ePro')->__('Remove Item(s)'),
225
+ 'url' => '',
226
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
227
+ ), 'other');
228
+ $this->getMassactionBlock()->addItem('unmapping', array(
229
+ 'label' => Mage::helper('M2ePro')->__('Unmap Item(s)'),
230
+ 'url' => '',
231
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
232
+ ), 'mapping');
233
+ //--------------------------------
234
+
235
+ return parent::_prepareMassaction();
236
+ }
237
+
238
+ // ####################################
239
+
240
+ public function callbackColumnProductId($value, $row, $column, $isExport)
241
+ {
242
+ if (empty($value)) {
243
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('title'));
244
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
245
+ if (strlen($productTitle) > 60) {
246
+ $productTitle = substr($productTitle, 0, 60) . '...';
247
+ }
248
+ $htmlValue = '&nbsp;<a href="javascript:void(0);"
249
+ onclick="AmazonListingOtherMappingHandlerObj.openPopUp(\''.
250
+ $productTitle.
251
+ '\','.
252
+ (int)$row->getId().
253
+ ');">' . Mage::helper('M2ePro')->__('Map') . '</a>';
254
+
255
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
256
+ $htmlValue .= '<br/>' . $row->getId();
257
+ }
258
+ return $htmlValue;
259
+ }
260
+
261
+ $htmlValue = '&nbsp<a href="'
262
+ .$this->getUrl('adminhtml/catalog_product/edit',
263
+ array('id' => $row->getData('product_id')))
264
+ .'" target="_blank">'
265
+ .$row->getData('product_id')
266
+ .'</a>';
267
+
268
+ $htmlValue .= '&nbsp&nbsp&nbsp<a href="javascript:void(0);"'
269
+ .' onclick="AmazonListingOtherGridHandlerObj.movingHandler.getGridHtml('
270
+ .json_encode(array((int)$row->getData('id')))
271
+ .')">'
272
+ .Mage::helper('M2ePro')->__('Move')
273
+ .'</a>';
274
+
275
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
276
+ $htmlValue .= '<br/>' . $row->getId();
277
+ }
278
+
279
+ return $htmlValue;
280
+ }
281
+
282
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
283
+ {
284
+ $value = '<span>' . Mage::helper('M2ePro')->escapeHtml($value) . '</span>';
285
+
286
+ $tempSku = $row->getData('sku');
287
+ empty($tempSku) && $tempSku = 'N/A';
288
+
289
+ $value .= '<br/><strong>'
290
+ .Mage::helper('M2ePro')->__('SKU')
291
+ .':</strong> '
292
+ .Mage::helper('M2ePro')->escapeHtml($tempSku);
293
+
294
+ return $value;
295
+ }
296
+
297
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
298
+ {
299
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($value, $row->getData('marketplace_id'));
300
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
301
+ }
302
+
303
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
304
+ {
305
+ if (is_null($value) || $value === '') {
306
+ return Mage::helper('M2ePro')->__('N/A');
307
+ }
308
+
309
+ if ((bool)$row->getData('is_afn_channel')) {
310
+ return '--';
311
+ }
312
+
313
+ if ($value <= 0) {
314
+ return '<span style="color: red;">0</span>';
315
+ }
316
+
317
+ return $value;
318
+ }
319
+
320
+ public function callbackColumnPrice($value, $row, $column, $isExport)
321
+ {
322
+ if (is_null($value) || $value === '') {
323
+ return Mage::helper('M2ePro')->__('N/A');
324
+ }
325
+
326
+ if ((float)$value <= 0) {
327
+ return '<span style="color: #f00;">0</span>';
328
+ }
329
+
330
+ $currency = Mage::helper('M2ePro/Component_Amazon')
331
+ ->getCachedObject('Marketplace',$row->getData('marketplace_id'))
332
+ ->getChildObject()
333
+ ->getDefaultCurrency();
334
+
335
+ return Mage::app()->getLocale()->currency($currency)->toCurrency($value);
336
+ }
337
+
338
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
339
+ {
340
+ switch ($row->getData('is_afn_channel')) {
341
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
342
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
343
+ break;
344
+
345
+ default:
346
+ break;
347
+ }
348
+
349
+ return $value;
350
+ }
351
+
352
+ public function callbackColumnStatus($value, $row, $column, $isExport)
353
+ {
354
+ switch ($row->getData('status')) {
355
+
356
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
357
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
358
+ $value = '<span style="color: gray;">' . $value . '</span>';
359
+ break;
360
+
361
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
362
+ $value = '<span style="color: green;">' . $value . '</span>';
363
+ break;
364
+
365
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
366
+ $value = '<span style="color: red;">' . $value . '</span>';
367
+ break;
368
+
369
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
370
+ $value = '<span style="color: orange; font-weight: bold;">' . $value . '</span>';
371
+ break;
372
+
373
+ default:
374
+ break;
375
+ }
376
+
377
+ return $value.$this->getViewLogIconHtml($row->getId());
378
+ }
379
+
380
+ protected function callbackFilterTitle($collection, $column)
381
+ {
382
+ $value = $column->getFilter()->getValue();
383
+
384
+ if ($value == null) {
385
+ return;
386
+ }
387
+
388
+ $collection->getSelect()->where('second_table.title LIKE ? OR second_table.sku LIKE ?', '%'.$value.'%');
389
+ }
390
+
391
+ // ####################################
392
+
393
+ public function getViewLogIconHtml($listingOtherId)
394
+ {
395
+ $listingOtherId = (int)$listingOtherId;
396
+
397
+ // Get last messages
398
+ //--------------------------
399
+ $dbSelect = $this->connRead->select()
400
+ ->from(
401
+ Mage::getResourceModel('M2ePro/Listing_Other_Log')->getMainTable(),
402
+ array('action_id','action','type','description','create_date','initiator')
403
+ )
404
+ ->where('`listing_other_id` = ?', $listingOtherId)
405
+ ->where('`action_id` IS NOT NULL')
406
+ ->order(array('id DESC'))
407
+ ->limit(30);
408
+
409
+ $logRows = $this->connRead->fetchAll($dbSelect);
410
+ //--------------------------
411
+
412
+ // Get grouped messages by action_id
413
+ //--------------------------
414
+ $actionsRows = array();
415
+ $tempActionRows = array();
416
+ $lastActionId = false;
417
+
418
+ foreach ($logRows as $row) {
419
+
420
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
421
+
422
+ if ($row['action_id'] !== $lastActionId) {
423
+ if (count($tempActionRows) > 0) {
424
+ $actionsRows[] = array(
425
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
426
+ 'date' => $this->getMainDateForActionId($tempActionRows),
427
+ 'action' => $this->getActionForAction($tempActionRows[0]),
428
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
429
+ 'items' => $tempActionRows
430
+ );
431
+ $tempActionRows = array();
432
+ }
433
+ $lastActionId = $row['action_id'];
434
+ }
435
+ $tempActionRows[] = $row;
436
+ }
437
+
438
+ if (count($tempActionRows) > 0) {
439
+ $actionsRows[] = array(
440
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
441
+ 'date' => $this->getMainDateForActionId($tempActionRows),
442
+ 'action' => $this->getActionForAction($tempActionRows[0]),
443
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
444
+ 'items' => $tempActionRows
445
+ );
446
+ }
447
+
448
+ if (count($actionsRows) <= 0) {
449
+ return '';
450
+ }
451
+
452
+ $tips = array(
453
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last action was completed successfully.',
454
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last action was completed with error(s).',
455
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last action was completed with warning(s).'
456
+ );
457
+
458
+ $icons = array(
459
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
460
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
461
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
462
+ );
463
+
464
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
465
+ 'entity_id' => $listingOtherId,
466
+ 'rows' => $actionsRows,
467
+ 'tips' => $tips,
468
+ 'icons' => $icons,
469
+ 'view_help_handler' => 'AmazonListingOtherGridHandlerObj.viewItemHelp',
470
+ 'hide_help_handler' => 'AmazonListingOtherGridHandlerObj.hideItemHelp',
471
+ ));
472
+
473
+ return $summary->toHtml();
474
+ }
475
+
476
+ public function getActionForAction($actionRows)
477
+ {
478
+ $string = '';
479
+
480
+ switch ((int)$actionRows['action']) {
481
+ case Ess_M2ePro_Model_Listing_Other_Log::ACTION_CHANGE_STATUS_ON_CHANNEL:
482
+ $string = Mage::helper('M2ePro')->__('Status Change');
483
+ break;
484
+ }
485
+
486
+ return $string;
487
+ }
488
+
489
+ public function getInitiatorForAction($actionRows)
490
+ {
491
+ $string = '';
492
+
493
+ switch ($actionRows['initiator']) {
494
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
495
+ $string = '';
496
+ break;
497
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
498
+ $string = Mage::helper('M2ePro')->__('Manual');
499
+ break;
500
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
501
+ $string = Mage::helper('M2ePro')->__('Automatic');
502
+ break;
503
+ }
504
+
505
+ return $string;
506
+ }
507
+
508
+ public function getMainTypeForActionId($actionRows)
509
+ {
510
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
511
+
512
+ foreach ($actionRows as $row) {
513
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
514
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
515
+ break;
516
+ }
517
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
518
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
519
+ }
520
+ }
521
+
522
+ return $type;
523
+ }
524
+
525
+ public function getMainDateForActionId($actionRows)
526
+ {
527
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
528
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
529
+ }
530
+
531
+ // ####################################
532
+
533
+ protected function _toHtml()
534
+ {
535
+ $javascriptsMain = <<<JAVASCRIPT
536
+ <script type="text/javascript">
537
+
538
+ if (typeof AmazonListingOtherGridHandlerObj != 'undefined') {
539
+ AmazonListingOtherGridHandlerObj.afterInitPage();
540
+ }
541
+
542
+ Event.observe(window, 'load', function() {
543
+ setTimeout(function() {
544
+ AmazonListingOtherGridHandlerObj.afterInitPage();
545
+ }, 350);
546
+ });
547
+
548
+ </script>
549
+ JAVASCRIPT;
550
+
551
+ return parent::_toHtml().$javascriptsMain;
552
+ }
553
+
554
+ // ####################################
555
+
556
+ public function getGridUrl()
557
+ {
558
+ return $this->getUrl('*/adminhtml_common_amazon_listing_other/grid', array('_current' => true));
559
+ }
560
+
561
+ public function getRowUrl($row)
562
+ {
563
+ return false;
564
+ }
565
+
566
+ // ####################################
567
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Product extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonListingProduct');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_amazon_listing_product';
18
+ //------------------------------
19
+
20
+ // Set header text
21
+ //------------------------------
22
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
23
+
24
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
25
+ $headerText = Mage::helper('M2ePro')->__(
26
+ 'Add Products To %component_name% Listing "%listing_title%"',
27
+ Mage::helper('M2ePro/Component_Amazon')->getTitle(),
28
+ $this->escapeHtml($listingData['title'])
29
+ );
30
+ } else {
31
+ $headerText = Mage::helper('M2ePro')->__(
32
+ 'Add Products To Listing "%listing_title%"',
33
+ $this->escapeHtml($listingData['title'])
34
+ );
35
+ }
36
+
37
+ $this->_headerText = $headerText;
38
+ //------------------------------
39
+
40
+ // Set buttons actions
41
+ //------------------------------
42
+ $this->removeButton('back');
43
+ $this->removeButton('reset');
44
+ $this->removeButton('delete');
45
+ $this->removeButton('add');
46
+ $this->removeButton('save');
47
+ $this->removeButton('edit');
48
+ //------------------------------
49
+
50
+ //------------------------------
51
+ if (is_null($this->getRequest()->getParam('back'))) {
52
+ $url = $this->getUrl(
53
+ '*/adminhtml_common_amazon_listing/categoryProduct',
54
+ array(
55
+ 'id' => $listingData['id'],
56
+ 'save_categories' => $this->getRequest()->getParam('save_categories', 1),
57
+ 'selected_categories' => $this->getRequest()->getParam('selected_categories')
58
+ )
59
+ );
60
+ } else {
61
+ $url = Mage::helper('M2ePro')->getBackUrl(
62
+ '*/adminhtml_common_listing/index',
63
+ array(
64
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
65
+ )
66
+ );
67
+ }
68
+ $this->_addButton('back', array(
69
+ 'label' => Mage::helper('M2ePro')->__('Back'),
70
+ 'onclick' => 'ProductGridHandlerObj.back_click(\''.$url.'\')',
71
+ 'class' => 'back'
72
+ ));
73
+ //------------------------------
74
+
75
+ //------------------------------
76
+ $this->_addButton('save', array(
77
+ 'label' => Mage::helper('M2ePro')->__('Save'),
78
+ 'onclick' => 'ProductGridHandlerObj.save_click(\'view\')',
79
+ 'class' => 'save'
80
+ ));
81
+ //------------------------------
82
+ }
83
+
84
+ public function getGridHtml()
85
+ {
86
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_product_help');
87
+ return $helpBlock->toHtml() . parent::getGridHtml();
88
+ }
89
+
90
+ protected function _toHtml()
91
+ {
92
+ return '<div id="add_products_progress_bar"></div>'.
93
+ '<div id="add_products_container">'.
94
+ parent::_toHtml().
95
+ '</div>';
96
+ }
97
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Product_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonListingProductHelp');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/product/help.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Grid.php ADDED
@@ -0,0 +1,528 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ private $productId;
10
+ private $currency;
11
+
12
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
13
+ private $listingProduct;
14
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute $matcherAttributes */
15
+ private $matcherAttributes;
16
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Option $matcherOptions */
17
+ private $matcherOptions;
18
+
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+
23
+ $this->productId = Mage::helper('M2ePro/Data_Global')->getValue('product_id');
24
+ $this->listingProduct = Mage::getModel('M2ePro/Listing_Product')->load($this->productId);
25
+
26
+ $this->matcherAttributes = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Attribute');
27
+ $this->matcherAttributes->setMarketplaceId(Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'));
28
+
29
+ $this->matcherOptions = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Option');
30
+ $this->matcherOptions->setMarketplaceId(Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'));
31
+
32
+ $this->currency = Mage::helper('M2ePro/Component_Amazon')
33
+ ->getCachedObject('Marketplace', Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'))
34
+ ->getChildObject()
35
+ ->getDefaultCurrency();
36
+
37
+ // Initialization block
38
+ //------------------------------
39
+ $this->setId('amazonProductSearchGrid');
40
+ //------------------------------
41
+
42
+ // Set default values
43
+ //------------------------------
44
+ $this->setFilterVisibility(false);
45
+ $this->setPagerVisibility(false);
46
+ $this->setDefaultSort('id');
47
+ $this->setDefaultDir('ASC');
48
+ $this->setSaveParametersInSession(true);
49
+ $this->setUseAjax(true);
50
+ //------------------------------
51
+ }
52
+
53
+ protected function _prepareCollection()
54
+ {
55
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
56
+
57
+ $results = new Varien_Data_Collection();
58
+ foreach ($data['data'] as $index => $item) {
59
+ $temp = array(
60
+ 'id' => $index,
61
+ 'general_id' => $item['general_id'],
62
+ 'brand' => $item['brand'],
63
+ 'title' => $item['title'],
64
+ 'image_url' => $item['image_url'],
65
+ 'price' => isset($item['list_price']['amount']) ? $item['list_price']['amount'] : null,
66
+ 'is_variation_product' => $item['is_variation_product']
67
+ );
68
+
69
+ if ($temp['is_variation_product']) {
70
+ if(!$item['bad_parent']) {
71
+ $temp += array(
72
+ 'parentage' => $item['parentage'],
73
+ 'variations' => $item['variations'],
74
+ 'bad_parent' => $item['bad_parent']
75
+ );
76
+ } else {
77
+ $temp['bad_parent'] = $item['bad_parent'];
78
+ }
79
+
80
+ if (!empty($item['requested_child_id'])) {
81
+ $temp['requested_child_id'] = $item['requested_child_id'];
82
+ }
83
+ }
84
+
85
+ $results->addItem(new Varien_Object($temp));
86
+ }
87
+
88
+ $this->setCollection($results);
89
+
90
+ return parent::_prepareCollection();
91
+ }
92
+
93
+ protected function _prepareColumns()
94
+ {
95
+ $this->addColumn('image', array(
96
+ 'header' => Mage::helper('M2ePro')->__('Image'),
97
+ 'align' => 'center',
98
+ 'type' => 'text',
99
+ 'width' => '80px',
100
+ 'index' => 'image_url',
101
+ 'filter' => false,
102
+ 'sortable' => false,
103
+ 'frame_callback' => array($this, 'callbackColumnImage')
104
+ ));
105
+
106
+ $this->addColumn('title', array(
107
+ 'header' => Mage::helper('M2ePro')->__('Title'),
108
+ 'align' => 'left',
109
+ 'type' => 'text',
110
+ 'string_limit' => 10000,
111
+ 'width' => '375px',
112
+ 'index' => 'title',
113
+ 'filter' => false,
114
+ 'sortable' => false,
115
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
116
+ ));
117
+
118
+ $this->addColumn('price',array(
119
+ 'header' => Mage::helper('catalog')->__('Price'),
120
+ 'width' => '60px',
121
+ 'align' => 'right',
122
+ 'index' => 'price',
123
+ 'filter' => false,
124
+ 'sortable' => false,
125
+ 'type' => 'number',
126
+ 'frame_callback' => array($this, 'callbackColumnPrice')
127
+ ));
128
+
129
+ $this->addColumn('general_id', array(
130
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
131
+ 'align' => 'center',
132
+ 'type' => 'text',
133
+ 'width' => '75px',
134
+ 'index' => 'general_id',
135
+ 'filter' => false,
136
+ 'sortable' => false,
137
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
138
+ ));
139
+
140
+ $this->addColumn('actions', array(
141
+ 'header' => Mage::helper('M2ePro')->__('Action'),
142
+ 'align' => 'center',
143
+ 'type' => 'text',
144
+ 'width' => '78px',
145
+ 'filter' => false,
146
+ 'sortable' => false,
147
+ 'frame_callback' => array($this, 'callbackColumnActions'),
148
+ ));
149
+
150
+ }
151
+
152
+ // ####################################
153
+
154
+ public function callbackColumnImage($value, $product, $column, $isExport)
155
+ {
156
+ return '<img src="'.$value.'" />';
157
+ }
158
+
159
+ public function callbackColumnGeneralId($value, $product, $column, $isExport)
160
+ {
161
+ $url = Mage::helper('M2ePro/Component_Amazon')
162
+ ->getItemUrl($value, Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'));
163
+
164
+ $parentAsinText = Mage::helper('M2ePro')->__('parent ASIN/ISBN');
165
+
166
+ return <<<HTML
167
+ <a id="asin_link_{$product->getData('id')}" href="{$url}" target="_blank">{$value}</a>
168
+ <div id="parent_asin_text_{$product->getData('id')}" style="font-size: 9px; color: grey; display: none">
169
+ {$parentAsinText}
170
+ </div>
171
+ HTML;
172
+
173
+ }
174
+
175
+ public function callbackColumnTitle($value, $row, $column, $isExport)
176
+ {
177
+ $value = '<div style="margin-left: 3px; margin-bottom: 10px;">'.
178
+ Mage::helper('M2ePro')->escapeHtml($value)."</div>";
179
+
180
+ if(!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct()
181
+ || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
182
+ if(!$row->getData('is_variation_product')) {
183
+ return $value;
184
+ }
185
+ } else {
186
+ if(!$row->getData('is_variation_product')) {
187
+ return $value;
188
+ }
189
+ }
190
+
191
+ if($row->getData('is_variation_product') && $row->getData('bad_parent')) {
192
+ return $value;
193
+ }
194
+
195
+ $id = $row->getId();
196
+ $variations = $row->getData('variations');
197
+
198
+ if($this->listingProduct->getChildObject()->getVariationManager()->isRelationParentType()) {
199
+
200
+ $magentoProductAttributesHtml = '';
201
+ $magentoProductAttributesJs = '';
202
+
203
+ $destinationAttributes = array_keys($variations['set']);
204
+
205
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
206
+ $this->matcherAttributes->setDestinationAttributes($destinationAttributes);
207
+
208
+ if($this->matcherAttributes->isAmountEqual()) {
209
+ $magentoProductAttributesJs .= '<script type="text/javascript">';
210
+ $magentoProductAttributesHtml .= '<div><span style="margin-left: 10px;
211
+ font-size: 11px;
212
+ font-weight: bold;
213
+ color: #808080;
214
+ display: inline-block;
215
+ width: 170px;">' .
216
+ Mage::helper('M2ePro')->__('Magento Attributes') .
217
+ '</span><span style="margin-left: 10px;
218
+ font-size: 11px;
219
+ font-weight: bold;
220
+ color: #808080;
221
+ display: inline-block;">' .
222
+ Mage::helper('M2ePro')->__('Amazon Attributes') .
223
+ '</span></div>';
224
+
225
+ $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
226
+ $attributeId = 0;
227
+ foreach($matchedAttributes as $magentoAttr => $amazonAttr){
228
+
229
+ $magentoProductAttributesHtml .= '<span style="margin-left: 10px;
230
+ font-size: 11px;
231
+ color: #808080;
232
+ display: inline-block;
233
+ width: 170px;">'.
234
+ ucfirst(strtolower($magentoAttr)).
235
+ '</span>';
236
+ $magentoProductAttributesHtml .= '<input type="hidden" value="'.$magentoAttr.'"
237
+ id="magento_product_attribute_'.$attributeId.'_'.$id.'">';
238
+ $magentoProductAttributesHtml .= '<select class="amazon_product_attribute_'.$id.'"
239
+ onchange="ListingGridHandlerObj.productSearchHandler.attributesChange(this)"
240
+ style="width: 170px; margin-left: 5px; margin-right: 5px;
241
+ margin-bottom: 7px; font-size: 10px;"
242
+ id="amazon_product_attribute_'.$attributeId.'_'.$id.'">';
243
+
244
+ if (!array_key_exists($amazonAttr,$variations['set']))
245
+ {
246
+ $magentoProductAttributesHtml .= '<option class="empty" value=""></option>';
247
+ }
248
+
249
+ foreach ($variations['set'] as $attrKey => $attrData) {
250
+
251
+ $selected = '';
252
+ if ($attrKey == $amazonAttr) {
253
+ $selected = 'selected';
254
+ $magentoProductAttributesJs .= <<<JS
255
+ ListingGridHandlerObj.productSearchHandler.attributesChange({id:"magento_product_attribute_{$magentoAttr}_{$id}"});
256
+ JS;
257
+ }
258
+
259
+ $attrKey = Mage::helper('M2ePro')->escapeHtml($attrKey);
260
+ $magentoProductAttributesHtml .= '<option value="'.$attrKey.'" '.$selected.'>'
261
+ .$attrKey.'</option>';
262
+ }
263
+ $magentoProductAttributesHtml .= '</select><br/>';
264
+ $attributeId++;
265
+ }
266
+
267
+ $magentoProductAttributesJs .= '</script>';
268
+
269
+ $magentoProductAttributesHtml .= '<div id="variations_'.$id.'" style="display: none;">'.
270
+ json_encode($variations).
271
+ '</div>';
272
+ } else {
273
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
274
+ $value .= implode(', ', $destinationAttributes);
275
+ $value .= '</div>';
276
+ }
277
+
278
+ return $value . $magentoProductAttributesHtml . $magentoProductAttributesJs;
279
+ }
280
+
281
+ $specificsHtml = '';
282
+ $specificsJs = '<script type="text/javascript">';
283
+
284
+ //match options for individual
285
+ if ($this->listingProduct->getChildObject()->getVariationManager()->isIndividualType() &&
286
+ $this->listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()
287
+ ) {
288
+ $channelVariations = array();
289
+ foreach($variations['asins'] as $asin => $asinAttributes) {
290
+ $channelVariations[$asin] = $asinAttributes['specifics'];
291
+ }
292
+
293
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
294
+ $this->matcherAttributes->setDestinationAttributes(array_keys($variations['set']));
295
+
296
+ if ($this->matcherAttributes->isAmountEqual() && $this->matcherAttributes->isFullyMatched()) {
297
+ $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
298
+
299
+ $this->matcherOptions->setMagentoProduct($this->listingProduct->getMagentoProduct());
300
+ $this->matcherOptions->setDestinationOptions($channelVariations);
301
+ $this->matcherOptions->setMatchedAttributes($matchedAttributes);
302
+
303
+ $productOptions = $this->listingProduct->getChildObject()->getVariationManager()
304
+ ->getTypeModel()->getProductOptions();
305
+
306
+ $requestedChildAsin = $this->matcherOptions->getMatchedOptionGeneralId($productOptions);
307
+ }
308
+ }
309
+
310
+ if (empty($requestedChildAsin)) {
311
+ $requestedChildAsin = $row->getData('requested_child_id');
312
+ }
313
+
314
+ $selectedOptions = array();
315
+ if ($requestedChildAsin) {
316
+ $selectedOptions = $variations['asins'][$requestedChildAsin]['specifics'];
317
+ }
318
+
319
+ $attributesNames = '<span style="margin-left: 10px;
320
+ min-width: 100px;
321
+ max-width: 170px;
322
+ font-size: 11px;
323
+ color: #808080;
324
+ display: inline-block;">';
325
+ $attributeValues = '<span style="margin-left: 5px; display: inline-block;">';
326
+ foreach ($variations['set'] as $specificName => $specific) {
327
+ $attributesNames .= '<span style="margin-bottom: 5px; display: inline-block;">'.
328
+ ucfirst(strtolower($specificName)).
329
+ '</span><br/>';
330
+ $attributeValues .= '<select class="specifics_'.$id.'"
331
+ onchange="ListingGridHandlerObj.productSearchHandler.specificsChange(this)"
332
+ style="width: 170px; margin-bottom: 5px; font-size: 10px;"
333
+ id="specific_'.$specificName.'_'.$id.'">';
334
+ $attributeValues .= '<option class="empty" value=""></option>';
335
+ foreach ($specific as $option) {
336
+
337
+ $selected = '';
338
+ if ($requestedChildAsin && $selectedOptions[$specificName] == $option) {
339
+ $selected = 'selected';
340
+ }
341
+
342
+ $option = Mage::helper('M2ePro')->escapeHtml($option);
343
+ $attributeValues .= '<option value="'.$option.'" '.$selected.'>'.$option.'</option>';
344
+ }
345
+ $attributeValues .= '</select><br/>';
346
+
347
+ $specificsJs .= <<<JS
348
+ ListingGridHandlerObj.productSearchHandler.specificsChange({id:"specific_{$specificName}_{$id}"});
349
+ JS;
350
+ }
351
+
352
+ $specificsHtml .= $attributesNames . '</span>';
353
+ $specificsHtml .= $attributeValues . '</span>';
354
+
355
+ $specificsJs .= '</script>';
356
+
357
+ $specificsJsonContainer = '<div id="parent_asin_'.$row->getId().'" style="display: none">'.
358
+ $row->getData('general_id').
359
+ '</div>'.
360
+ '<div id="asins_'.$id.'" style="display: none;">'.
361
+ json_encode($variations['asins']).
362
+ '</div>';
363
+
364
+ return $value . $specificsHtml . $specificsJsonContainer . $specificsJs;
365
+ }
366
+
367
+ public function callbackColumnPrice($value, $row, $column, $isExport)
368
+ {
369
+ if (empty($value) || $row->getData('is_variation_product')) {
370
+ $value = Mage::helper('M2ePro')->__('N/A');
371
+ } else {
372
+ $value = Mage::app()->getLocale()->currency($this->currency)->toCurrency($value);
373
+ }
374
+
375
+ return '<div style="margin-right: 5px;">'.$value.'</div>';
376
+ }
377
+
378
+ public function callbackColumnActions($value, $row, $column, $isExport)
379
+ {
380
+ $assignText = Mage::helper('M2ePro')->__('Assign');
381
+ $iconWarningPath = $this->getSkinUrl('M2ePro/images/warning.png');
382
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_notice.gif');
383
+
384
+ if(!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct()
385
+ || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
386
+ if (!$row->getData('is_variation_product')) {
387
+
388
+ return <<<HTML
389
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
390
+ {$this->productId}, '{$row->getData('general_id')}');">{$assignText}</a>
391
+ HTML;
392
+ }
393
+
394
+ if(!$row->getData('bad_parent')) {
395
+
396
+ $msg = Mage::helper('M2ePro')->__(
397
+ 'Please select necessary Options for this Amazon Product to be able to assign ASIN/ISBN.'
398
+ );
399
+
400
+ return <<<HTML
401
+ <span>
402
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
403
+ <img id="map_link_error_icon_{$row->getId()}"
404
+ class="tool-tip-image"
405
+ style="vertical-align: middle; display: none;"
406
+ src="{$iconWarningPath}">
407
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
408
+ <img src="{$iconHelpPath}">
409
+ <span>{$msg}</span>
410
+ </span>
411
+ </span>
412
+ <div id="template_map_link_{$row->getId()}" style="display: none;">
413
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
414
+ {$this->productId}, '%general_id%', '%options_data%'
415
+ );">{$assignText}</a>
416
+ </div>
417
+ HTML;
418
+ }
419
+ }
420
+
421
+ if($row->getData('is_variation_product') && !$row->getData('bad_parent')) {
422
+
423
+ $msg = Mage::helper('M2ePro')->__(
424
+ 'Please map Amazon and Magento Attributes for this Amazon Product to be able to assign ASIN/ISBN.'
425
+ );
426
+
427
+ $variations = $row->getData('variations');
428
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
429
+ $this->matcherAttributes->setDestinationAttributes(array_keys($variations['set']));
430
+
431
+ if(!$this->matcherAttributes->isAmountEqual()) {
432
+ $msg = Mage::helper('M2ePro')->__(
433
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
434
+ The number of Magento Attributes is different from Amazon Attributes.'
435
+ );
436
+ }
437
+
438
+ return <<<HTML
439
+ <span>
440
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
441
+ <img id="map_link_error_icon_{$row->getId()}"
442
+ class="tool-tip-image"
443
+ style="vertical-align: middle;"
444
+ src="{$iconWarningPath}">
445
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
446
+ <img src="{$iconHelpPath}">
447
+ <span>{$msg}</span>
448
+ </span>
449
+ </span>
450
+ <div id="template_map_link_{$row->getId()}" style="display: none;">
451
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
452
+ {$this->productId}, '{$row->getData('general_id')}', '%options_data%'
453
+ );">{$assignText}</a>
454
+ </div>
455
+ HTML;
456
+
457
+ }
458
+
459
+ $msg = Mage::helper('M2ePro')->__(
460
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
461
+ This Amazon Product has no Variations. <br/>
462
+ Only Amazon Parent/Child Products can be assigned in "All Variations" Mode.'
463
+ );
464
+
465
+ if ($row->getData('is_variation_product') && $row->getData('bad_parent')) {
466
+ $msg = Mage::helper('M2ePro')->__(
467
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
468
+ Amazon Service (API) does not return all required information about this Amazon Product.'
469
+ );
470
+ }
471
+
472
+ return <<<HTML
473
+ <span>
474
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
475
+ <img id="map_link_error_icon_{$row->getId()}"
476
+ class="tool-tip-image"
477
+ style="vertical-align: middle;"
478
+ src="{$iconWarningPath}">
479
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
480
+ <img src="{$iconHelpPath}">
481
+ <span>{$msg}</span>
482
+ </span>
483
+ </span>
484
+ HTML;
485
+ }
486
+
487
+ // ####################################
488
+
489
+ protected function _toHtml()
490
+ {
491
+ $javascriptsMain = <<<JAVASCRIPT
492
+ <script type="text/javascript">
493
+
494
+ $$('#amazonProductSearchGrid div.grid th').each(function(el){
495
+ el.style.padding = '2px 2px';
496
+ });
497
+
498
+ $$('#amazonProductSearchGrid div.grid td').each(function(el){
499
+ el.style.padding = '2px 2px';
500
+ });
501
+
502
+ </script>
503
+ JAVASCRIPT;
504
+
505
+ $searchData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
506
+
507
+ $searchParamsHtml = <<<HTML
508
+ <input id="amazon_asin_search_type" type="hidden" value="{$searchData['type']}">
509
+ <input id="amazon_asin_search_value" type="hidden" value="{$searchData['value']}">
510
+ HTML;
511
+
512
+ return parent::_toHtml() . $javascriptsMain . $searchParamsHtml;
513
+ }
514
+
515
+ // ####################################
516
+
517
+ public function getGridUrl()
518
+ {
519
+ return $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid', array('_current'=>true));
520
+ }
521
+
522
+ public function getRowUrl($row)
523
+ {
524
+ return false;
525
+ }
526
+
527
+ // ####################################
528
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Main.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_Main extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/main.phtml');
14
+ }
15
+
16
+ protected function _beforeToHtml()
17
+ {
18
+ //------------------------------
19
+ $data = array(
20
+ 'id' => 'productSearch_submit_button',
21
+ 'label' => Mage::helper('M2ePro')->__('Search'),
22
+ 'class' => 'productSearch_submit_button submit'
23
+ );
24
+ $buttonSubmitBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
25
+ $this->setChild('productSearch_submit_button', $buttonSubmitBlock);
26
+ //------------------------------
27
+
28
+ //------------------------------
29
+ $data = array(
30
+ 'id' => 'productSearch_back_button',
31
+ 'label' => Mage::helper('M2ePro')->__('Back'),
32
+ 'class' => 'productSearch_back_button'
33
+ );
34
+ $buttonBackBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
35
+ $this->setChild('productSearch_back_button', $buttonBackBlock);
36
+ //------------------------------
37
+
38
+ //------------------------------
39
+ $data = array(
40
+ 'id' => 'productSearch_cancel_button',
41
+ 'label' => Mage::helper('M2ePro')->__('Close'),
42
+ 'class' => 'productSearch_cancel_button'
43
+ );
44
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
45
+ $this->setChild('productSearch_cancel_button', $buttonCancelBlock);
46
+ //------------------------------
47
+
48
+ //------------------------------
49
+ $data = array(
50
+ 'id' => 'productSearch_cleanSuggest_button',
51
+ 'label' => Mage::helper('M2ePro')->__('Clear Search Results'),
52
+ 'class' => 'productSearch_cleanSuggest_button',
53
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndOpenSearchMenu()'
54
+ );
55
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
56
+ $this->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
57
+ //------------------------------
58
+
59
+ parent::_beforeToHtml();
60
+ }
61
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Menu.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_Menu extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ protected $listingProductId;
10
+
11
+ /**
12
+ * @param mixed $listingProductId
13
+ * @return $this
14
+ */
15
+ public function setListingProductId($listingProductId)
16
+ {
17
+ $this->listingProductId = $listingProductId;
18
+
19
+ return $this;
20
+ }
21
+ /**
22
+ * @return mixed
23
+ */
24
+ public function getListingProductId()
25
+ {
26
+ return $this->listingProductId;
27
+ }
28
+
29
+ //------------------------------
30
+
31
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
32
+ protected $listingProduct = null;
33
+
34
+ /**
35
+ * @return Ess_M2ePro_Model_Listing_Product|null
36
+ */
37
+ public function getListingProduct()
38
+ {
39
+ if(is_null($this->listingProduct)) {
40
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
41
+ ->getObject('Listing_Product', $this->getListingProductId());
42
+ }
43
+
44
+ return $this->listingProduct;
45
+ }
46
+
47
+ public function isIndividualFromBundleOrSimpleWithCustome()
48
+ {
49
+ if (!$this->getListingProduct()->getChildObject()->getVariationManager()->isIndividualType()) {
50
+ return false;
51
+ }
52
+
53
+ return $this->getListingProduct()->getMagentoProduct()->isBundleType() ||
54
+ $this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
55
+ }
56
+
57
+ public function isParentFromBundleOrSimpleWithCustome()
58
+ {
59
+ if (!$this->getListingProduct()->getChildObject()->getVariationManager()->isRelationParentType()) {
60
+ return false;
61
+ }
62
+
63
+ return $this->getListingProduct()->getMagentoProduct()->isBundleType() ||
64
+ $this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
65
+ }
66
+
67
+ public function __construct()
68
+ {
69
+ parent::__construct();
70
+
71
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/menu.phtml');
72
+ }
73
+
74
+ protected function _beforeToHtml()
75
+ {
76
+ //------------------------------
77
+ $data = array(
78
+ 'id' => 'productSearchMenu_cancel_button',
79
+ 'label' => Mage::helper('M2ePro')->__('Close'),
80
+ 'class' => 'productSearchMenu_cancel_button'
81
+ );
82
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
83
+ $this->setChild('productSearchMenu_cancel_button', $buttonCancelBlock);
84
+ //------------------------------
85
+
86
+ parent::_beforeToHtml();
87
+ }
88
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/SuggestedAsinGridHelp.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_SuggestedAsinGridHelp
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonSuggestedAsinGridHelp');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/suggested_asin_grid_help.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Search extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingAmazonSearch');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_amazon_listing_search';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
25
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
26
+ $headerText = Mage::helper('M2ePro')->__("Search %component_name% Listings Items", $componentName);
27
+ } else {
28
+ $headerText = Mage::helper('M2ePro')->__("Search Listings Items");
29
+ }
30
+
31
+ $this->_headerText = $headerText;
32
+ //------------------------------
33
+
34
+ // Set buttons actions
35
+ //------------------------------
36
+ $this->removeButton('back');
37
+ $this->removeButton('reset');
38
+ $this->removeButton('delete');
39
+ $this->removeButton('add');
40
+ $this->removeButton('save');
41
+ $this->removeButton('edit');
42
+ //------------------------------
43
+
44
+ if (!is_null($this->getRequest()->getParam('back'))) {
45
+ //------------------------------
46
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_amazon_listing/search');
47
+ $this->_addButton('back', array(
48
+ 'label' => Mage::helper('M2ePro')->__('Back'),
49
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
50
+ 'class' => 'back'
51
+ ));
52
+ //------------------------------
53
+ }
54
+
55
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/search');
56
+
57
+ //------------------------------
58
+ $url = $this->getUrl(
59
+ '*/adminhtml_common_listing/index',
60
+ array(
61
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON,
62
+ 'back'=> $backUrl
63
+ )
64
+ );
65
+ $this->_addButton('goto_listings', array(
66
+ 'label' => Mage::helper('M2ePro')->__('Listings'),
67
+ 'onclick' => 'setLocation(\'' . $url . '\')',
68
+ 'class' => 'button_link'
69
+ ));
70
+ //------------------------------
71
+
72
+ //------------------------------
73
+ $this->_addButton('goto_templates', array(
74
+ 'label' => Mage::helper('M2ePro')->__('Policies'),
75
+ 'onclick' => '',
76
+ 'class' => 'button_link drop_down templates-drop-down'
77
+ ));
78
+ //------------------------------
79
+
80
+ //------------------------------
81
+ $url = $this->getUrl(
82
+ '*/adminhtml_common_log/listing',
83
+ array(
84
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_AMAZON
85
+ )
86
+ );
87
+ $this->_addButton('view_log', array(
88
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
89
+ 'onclick' => 'window.open(\'' . $url . '\')',
90
+ 'class' => 'button_link'
91
+ ));
92
+ //------------------------------
93
+ }
94
+
95
+ // ########################################
96
+
97
+ protected function _toHtml()
98
+ {
99
+ return $this->getTemplatesButtonJavascript() . parent::_toHtml();
100
+ }
101
+
102
+ public function getGridHtml()
103
+ {
104
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_listing_search_help');
105
+ return $helpBlock->toHtml() . parent::getGridHtml();
106
+ }
107
+
108
+ // ########################################
109
+
110
+ protected function getTemplatesButtonJavascript()
111
+ {
112
+ $data = array(
113
+ 'target_css_class' => 'templates-drop-down',
114
+ 'items' => $this->getTemplatesButtonDropDownItems()
115
+ );
116
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
117
+ $dropDownBlock->setData($data);
118
+
119
+ return $dropDownBlock->toHtml();
120
+ }
121
+
122
+ protected function getTemplatesButtonDropDownItems()
123
+ {
124
+ $items = array();
125
+
126
+ $filter = base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Amazon::NICK);
127
+
128
+ //------------------------------
129
+ $url = $this->getUrl('*/adminhtml_common_template_sellingFormat/index', array('filter' => $filter));
130
+ $items[] = array(
131
+ 'url' => $url,
132
+ 'label' => Mage::helper('M2ePro')->__('Selling Format Policies'),
133
+ 'target' => '_blank'
134
+ );
135
+ //------------------------------
136
+
137
+ //------------------------------
138
+ $url = $this->getUrl('*/adminhtml_common_template_synchronization/index', array('filter' => $filter));
139
+ $items[] = array(
140
+ 'url' => $url,
141
+ 'label' => Mage::helper('M2ePro')->__('Synchronization Policies'),
142
+ 'target' => '_blank'
143
+ );
144
+ //------------------------------
145
+
146
+ //------------------------------
147
+ $url = $this->getUrl(
148
+ '*/adminhtml_common_amazon_template_description/index'
149
+ );
150
+ $items[] = array(
151
+ 'url' => $url,
152
+ 'label' => Mage::helper('M2ePro')->__('Amazon Description Policies'),
153
+ 'target' => '_blank'
154
+ );
155
+ //------------------------------
156
+
157
+ return $items;
158
+ }
159
+
160
+ // ########################################
161
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search/Grid.php ADDED
@@ -0,0 +1,531 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Search_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingSearchGrid');
18
+ //------------------------------
19
+
20
+ // Set default values
21
+ //------------------------------
22
+ $this->setDefaultSort('id');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setUseAjax(true);
26
+ //------------------------------
27
+ }
28
+
29
+ // ####################################
30
+
31
+ protected function _prepareCollection()
32
+ {
33
+ // Get collection products in listing
34
+ //--------------------------------
35
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
36
+ $collection->getSelect()->distinct();
37
+ $collection->getSelect()
38
+ ->join(array('l'=>Mage::getResourceModel('M2ePro/Listing')->getMainTable()),
39
+ '(`l`.`id` = `main_table`.`listing_id`)',
40
+ array('listing_title'=>'title','store_id','marketplace_id'))
41
+ ->join(array('al'=>Mage::getResourceModel('M2ePro/Amazon_Listing')->getMainTable()),
42
+ '(`al`.`listing_id` = `l`.`id`)',
43
+ array('template_selling_format_id'));
44
+ //--------------------------------
45
+
46
+ // only parents and individuals
47
+ $collection->getSelect()->where('second_table.variation_parent_id IS NULL');
48
+
49
+ // Communicate with magento product table
50
+ //--------------------------------
51
+ $dbSelect = Mage::getResourceModel('core/config')->getReadConnection()
52
+ ->select()
53
+ ->from(Mage::getSingleton('core/resource')
54
+ ->getTableName('catalog_product_entity_varchar'),
55
+ new Zend_Db_Expr('MAX(`store_id`)'))
56
+ ->where("`entity_id` = `main_table`.`product_id`")
57
+ ->where("`attribute_id` = `ea`.`attribute_id`")
58
+ ->where("`store_id` = 0 OR `store_id` = `l`.`store_id`");
59
+
60
+ $collection->getSelect()
61
+ //->join(array('csi'=>Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
62
+ // '(csi.product_id = `main_table`.product_id)',array('qty'))
63
+ ->join(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
64
+ '(cpe.entity_id = `main_table`.product_id)',
65
+ array('magento_sku'=>'sku'))
66
+ ->join(array('cisi'=>Mage::getSingleton('core/resource')
67
+ ->getTableName('cataloginventory_stock_item')),
68
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
69
+ array('is_in_stock'))
70
+ ->join(array('cpev'=>Mage::getSingleton('core/resource')
71
+ ->getTableName('catalog_product_entity_varchar')),
72
+ "(`cpev`.`entity_id` = `main_table`.product_id)",
73
+ array('value'))
74
+ ->join(array('ea'=>Mage::getSingleton('core/resource')->getTableName('eav_attribute')),
75
+ '(`cpev`.`attribute_id` = `ea`.`attribute_id` AND `ea`.`attribute_code` = \'name\')',
76
+ array())
77
+ ->where('`cpev`.`store_id` = ('.$dbSelect->__toString().')');
78
+ //--------------------------------
79
+
80
+ //exit($collection->getSelect()->__toString());
81
+
82
+ // Set collection to grid
83
+ $this->setCollection($collection);
84
+
85
+ return parent::_prepareCollection();
86
+ }
87
+
88
+ protected function _prepareColumns()
89
+ {
90
+ $this->addColumn('product_id', array(
91
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
92
+ 'align' => 'right',
93
+ 'width' => '100px',
94
+ 'type' => 'number',
95
+ 'index' => 'product_id',
96
+ 'filter_index' => 'main_table.product_id',
97
+ 'frame_callback' => array($this, 'callbackColumnProductId')
98
+ ));
99
+
100
+ $this->addColumn('name', array(
101
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Listing / Product SKU'),
102
+ 'align' => 'left',
103
+ //'width' => '300px',
104
+ 'type' => 'text',
105
+ 'index' => 'value',
106
+ 'filter_index' => 'cpev.value',
107
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
108
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
109
+ ));
110
+
111
+ $this->addColumn('stock_availability',
112
+ array(
113
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
114
+ 'width' => '100px',
115
+ 'index' => 'is_in_stock',
116
+ 'filter_index' => 'cisi.is_in_stock',
117
+ 'type' => 'options',
118
+ 'sortable' => false,
119
+ 'options' => array(
120
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
121
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
122
+ ),
123
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
124
+ ));
125
+
126
+ $this->addColumn('sku', array(
127
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
128
+ 'align' => 'left',
129
+ 'width' => '150px',
130
+ 'type' => 'text',
131
+ 'index' => 'sku',
132
+ 'filter_index' => 'second_table.sku',
133
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
134
+ ));
135
+
136
+ $this->addColumn('general_id', array(
137
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
138
+ 'align' => 'left',
139
+ 'width' => '90px',
140
+ 'type' => 'text',
141
+ 'index' => 'general_id',
142
+ 'filter_index' => 'second_table.general_id',
143
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
144
+ ));
145
+
146
+ $this->addColumn('online_qty', array(
147
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
148
+ 'align' => 'right',
149
+ 'width' => '70px',
150
+ 'type' => 'number',
151
+ 'index' => 'online_qty',
152
+ 'filter_index' => 'second_table.online_qty',
153
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
154
+ ));
155
+
156
+ $this->addColumn('online_price', array(
157
+ 'header' => Mage::helper('M2ePro')->__('Price'),
158
+ 'align' => 'right',
159
+ 'width' => '70px',
160
+ 'type' => 'number',
161
+ 'index' => 'online_price',
162
+ 'filter_index' => 'second_table.online_price',
163
+ 'frame_callback' => array($this, 'callbackColumnPrice')
164
+ ));
165
+
166
+ $this->addColumn('is_afn_channel', array(
167
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
168
+ 'width' => '90px',
169
+ 'index' => 'is_afn_channel',
170
+ 'filter_index' => 'second_table.is_afn_channel',
171
+ 'type' => 'options',
172
+ 'sortable' => false,
173
+ 'options' => array(
174
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
175
+ 1 => Mage::helper('M2ePro')->__('Amazon')
176
+ ),
177
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
178
+ ));
179
+
180
+ $this->addColumn('status', array(
181
+ 'header' => Mage::helper('M2ePro')->__('Status'),
182
+ 'width' => '125px',
183
+ 'index' => 'status',
184
+ 'filter_index' => 'main_table.status',
185
+ 'type' => 'options',
186
+ 'sortable' => false,
187
+ 'options' => array(
188
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
189
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
190
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
191
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
192
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
193
+ ),
194
+ 'frame_callback' => array($this, 'callbackColumnStatus')
195
+ ));
196
+
197
+ $this->addColumn('goto_listing_item', array(
198
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
199
+ 'align' => 'center',
200
+ 'width' => '50px',
201
+ 'type' => 'text',
202
+ 'filter' => false,
203
+ 'sortable' => false,
204
+ 'frame_callback' => array($this, 'callbackColumnActions')
205
+ ));
206
+
207
+ return parent::_prepareColumns();
208
+ }
209
+
210
+ // ####################################
211
+
212
+ public function callbackColumnProductId($value, $row, $column, $isExport)
213
+ {
214
+ $productId = (int)$row->getData('product_id');
215
+ $storeId = (int)$row->getData('store_id');
216
+
217
+ $withoutImageHtml = '<a href="'
218
+ .$this->getUrl('adminhtml/catalog_product/edit',
219
+ array('id' => $productId))
220
+ .'" target="_blank">'
221
+ .$productId
222
+ .'</a>';
223
+
224
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
225
+ ->getGroupValue('/view/',
226
+ 'show_products_thumbnails');
227
+ if (!$showProductsThumbnails) {
228
+ return $withoutImageHtml;
229
+ }
230
+
231
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
232
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
233
+ $magentoProduct->setProductId($productId);
234
+ $magentoProduct->setStoreId($storeId);
235
+
236
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
237
+ if (is_null($imageUrlResized)) {
238
+ return $withoutImageHtml;
239
+ }
240
+
241
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
242
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
243
+
244
+ return $withImageHtml;
245
+ }
246
+
247
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
248
+ {
249
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
250
+
251
+ $urlParams = array();
252
+ $urlParams['id'] = $row->getData('listing_id');
253
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/search');
254
+
255
+ $listingUrl = $this->getUrl('*/adminhtml_common_amazon_listing/view',$urlParams);
256
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
257
+
258
+ if (strlen($listingTitle) > 50) {
259
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
260
+ }
261
+
262
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
263
+ $value .= '<strong>'
264
+ .Mage::helper('M2ePro')->__('Listing')
265
+ .': </strong> <a href="'
266
+ .$listingUrl
267
+ .'">'
268
+ .$listingTitle
269
+ .'</a>';
270
+
271
+ $tempSku = $row->getData('magento_sku');
272
+ is_null($tempSku)
273
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('product_id'))->getSku();
274
+
275
+ $value .= '<br/><strong>'
276
+ .Mage::helper('M2ePro')->__('SKU')
277
+ .':</strong> '
278
+ .Mage::helper('M2ePro')->escapeHtml($tempSku);
279
+
280
+ if ($row->getChildObject()->getVariationManager()->isVariationParent()) {
281
+ $productOptions = $row->getChildObject()->getVariationManager()
282
+ ->getTypeModel()->getProductAttributes();
283
+
284
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey;"><br/>';
285
+ $value .= implode(', ', $productOptions);
286
+ $value .= '</div>';
287
+ }
288
+
289
+ if ($row->getChildObject()->getVariationManager()->isIndividualType() &&
290
+ $row->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()
291
+ ) {
292
+ $productOptions = $row->getChildObject()->getVariationManager()->getTypeModel()->getProductOptions();
293
+
294
+ $value .= '<br/>';
295
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
296
+ foreach ($productOptions as $attribute => $option) {
297
+ !$option && $option = '--';
298
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
299
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
300
+ }
301
+ $value .= '</div>';
302
+ $value .= '<br/>';
303
+ }
304
+
305
+ return $value;
306
+ }
307
+
308
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
309
+ {
310
+ if ((int)$row->getData('is_in_stock') <= 0) {
311
+ return '<span style="color: red;">'.$value.'</span>';
312
+ }
313
+
314
+ return $value;
315
+ }
316
+
317
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
318
+ {
319
+ if (is_null($value) || $value === '') {
320
+ return Mage::helper('M2ePro')->__('N/A');
321
+ }
322
+ return $value;
323
+ }
324
+
325
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
326
+ {
327
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
328
+ if (is_null($value) || $value === '') {
329
+ return Mage::helper('M2ePro')->__('N/A');
330
+ }
331
+ } else {
332
+ if (is_null($value) || $value === '') {
333
+ return '<i style="color:gray;">receiving...</i>';
334
+ }
335
+ }
336
+
337
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($value, $row->getData('marketplace_id'));
338
+
339
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
340
+ }
341
+
342
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
343
+ {
344
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
345
+ if (is_null($value) || $value === '') {
346
+ return Mage::helper('M2ePro')->__('N/A');
347
+ }
348
+ } else {
349
+ if (is_null($value) || $value === '') {
350
+ return '<i style="color:gray;">receiving...</i>';
351
+ }
352
+ }
353
+
354
+ if ((bool)$row->getData('is_afn_channel')) {
355
+ return '--';
356
+ }
357
+
358
+ if ($value <= 0) {
359
+ return '<span style="color: red;">0</span>';
360
+ }
361
+
362
+ return $value;
363
+ }
364
+
365
+ public function callbackColumnPrice($value, $row, $column, $isExport)
366
+ {
367
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
368
+ if (is_null($value) || $value === '') {
369
+ return Mage::helper('M2ePro')->__('N/A');
370
+ }
371
+ } else {
372
+ if (is_null($value) || $value === '') {
373
+ return '<i style="color:gray;">receiving...</i>';
374
+ }
375
+ }
376
+
377
+ if ((float)$value <= 0) {
378
+ return '<span style="color: #f00;">0</span>';
379
+ }
380
+
381
+ $marketplaceId = Mage::helper('M2ePro/Component_Amazon')
382
+ ->getCachedObject('Listing',
383
+ $row->getData('listing_id'), NULL,
384
+ array('listing'))
385
+ ->getMarketplaceId();
386
+
387
+ $currency = Mage::helper('M2ePro/Component_Amazon')
388
+ ->getCachedObject('Marketplace',$marketplaceId)
389
+ ->getChildObject()
390
+ ->getDefaultCurrency();
391
+
392
+ $value = Mage::app()->getLocale()->currency($currency)->toCurrency($value);
393
+
394
+ $salePriceValue = $row->getData('online_sale_price');
395
+ if (!is_null($salePriceValue) &&
396
+ (float)$salePriceValue > 0) {
397
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePriceValue);
398
+ $value .= '<br/><span style="color:gray;">'.$salePriceValue.'</span>';
399
+ }
400
+
401
+ return $value;
402
+ }
403
+
404
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
405
+ {
406
+ if (is_null($value) || $value === '') {
407
+ return Mage::helper('M2ePro')->__('N/A');
408
+ }
409
+
410
+ switch ($row->getData('is_afn_channel')) {
411
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
412
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
413
+ break;
414
+
415
+ default:
416
+ break;
417
+ }
418
+
419
+ return $value;
420
+ }
421
+
422
+ public function callbackColumnStatus($value, $row, $column, $isExport)
423
+ {
424
+ switch ($row->getData('status')) {
425
+
426
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
427
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
428
+ $value = '<span style="color: gray;">' . $value . '</span>';
429
+ break;
430
+
431
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
432
+ $value = '<span style="color: green;">' . $value . '</span>';
433
+ break;
434
+
435
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
436
+ $value = '<span style="color: red;">'.$value.'</span>';
437
+ break;
438
+
439
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
440
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
441
+ break;
442
+
443
+ default:
444
+ break;
445
+ }
446
+
447
+ $tempLocks = $row->getObjectLocks();
448
+
449
+ foreach ($tempLocks as $lock) {
450
+
451
+ switch ($lock->getTag()) {
452
+
453
+ case 'list_action':
454
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
455
+ break;
456
+
457
+ case 'relist_action':
458
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
459
+ break;
460
+
461
+ case 'revise_action':
462
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
463
+ break;
464
+
465
+ case 'stop_action':
466
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
467
+ break;
468
+
469
+ case 'stop_and_remove_action':
470
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
471
+ break;
472
+
473
+ case 'delete_and_remove_action':
474
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
475
+ break;
476
+
477
+ default:
478
+ break;
479
+
480
+ }
481
+ }
482
+
483
+ return $value;
484
+ }
485
+
486
+ public function callbackColumnActions($value, $row, $column, $isExport)
487
+ {
488
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to listing'));
489
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
490
+ $url = $this->getUrl('*/adminhtml_common_amazon_listing/view/',array(
491
+ 'id' => $row->getData('listing_id'),
492
+ 'filter' => base64_encode(
493
+ 'product_id[from]='.(int)$row->getData('product_id')
494
+ .'&product_id[to]='.(int)$row->getData('product_id')
495
+ )
496
+ ));
497
+
498
+ $html = <<<HTML
499
+ <div style="float:right; margin:5px 15px 0 0;">
500
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" alt="{$altTitle}" /></a>
501
+ </div>
502
+ HTML;
503
+
504
+ return $html;
505
+ }
506
+
507
+ protected function callbackFilterTitle($collection, $column)
508
+ {
509
+ $value = $column->getFilter()->getValue();
510
+
511
+ if ($value == null) {
512
+ return;
513
+ }
514
+
515
+ $collection->getSelect()->where('cpev.value LIKE ? OR cpe.sku LIKE ? OR l.title LIKE ?', '%'.$value.'%');
516
+ }
517
+
518
+ // ####################################
519
+
520
+ public function getGridUrl()
521
+ {
522
+ return $this->getUrl('*/adminhtml_common_amazon_listing/searchGrid', array('_current'=>true));
523
+ }
524
+
525
+ public function getRowUrl($row)
526
+ {
527
+ return false;
528
+ }
529
+
530
+ // ####################################
531
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Grid.php ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_TemplateDescription_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ protected $attributesSetsIds;
10
+ protected $marketplaceId;
11
+ protected $listingProduct;
12
+ protected $productsAttributesCountVariations;
13
+
14
+ protected $checkNewAsinAccepted = false;
15
+ protected $productsIds;
16
+ protected $mapToTemplateJsFn = 'ListingGridHandlerObj.templateDescriptionHandler.mapToTemplateDescription';
17
+
18
+ //------------------------------
19
+
20
+ /**
21
+ * @return string
22
+ */
23
+ public function getMapToTemplateJsFn()
24
+ {
25
+ return $this->mapToTemplateJsFn;
26
+ }
27
+
28
+ /**
29
+ * @param string $mapToTemplateLink
30
+ */
31
+ public function setMapToTemplateJsFn($mapToTemplateLink)
32
+ {
33
+ $this->mapToTemplateJsFn = $mapToTemplateLink;
34
+ }
35
+
36
+ //------------------------------
37
+
38
+ /**
39
+ * @param boolean $checkNewAsinAccepted
40
+ */
41
+ public function setCheckNewAsinAccepted($checkNewAsinAccepted)
42
+ {
43
+ $this->checkNewAsinAccepted = $checkNewAsinAccepted;
44
+ }
45
+
46
+ /**
47
+ * @return boolean
48
+ */
49
+ public function getCheckNewAsinAccepted()
50
+ {
51
+ return (bool) $this->checkNewAsinAccepted;
52
+ }
53
+
54
+ //------------------------------
55
+
56
+ /**
57
+ * @param mixed $productsIds
58
+ */
59
+ public function setProductsIds($productsIds)
60
+ {
61
+ $this->productsIds = $productsIds;
62
+ }
63
+
64
+ /**
65
+ * @return mixed
66
+ */
67
+ public function getProductsIds()
68
+ {
69
+ return $this->productsIds;
70
+ }
71
+
72
+ //------------------------------
73
+
74
+ public function __construct()
75
+ {
76
+ parent::__construct();
77
+
78
+ $this->setId('amazonTemplateDescriptionGrid');
79
+
80
+ // Set default values
81
+ //------------------------------
82
+ $this->setFilterVisibility(false);
83
+ //$this->setPagerVisibility(false);
84
+ $this->setDefaultSort('id');
85
+ $this->setDefaultDir('ASC');
86
+ $this->setSaveParametersInSession(false);
87
+ $this->setUseAjax(true);
88
+ //------------------------------
89
+ }
90
+
91
+ //------------------------------
92
+
93
+ protected function _prepareCollection()
94
+ {
95
+ $this->setNoTemplatesText();
96
+
97
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Template_Description_Collection $collection */
98
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Template_Description');
99
+ $collection->addFieldToFilter('marketplace_id', $this->getMarketplaceId());
100
+
101
+ $this->setCollection($collection);
102
+
103
+ return parent::_prepareCollection();
104
+ }
105
+
106
+ protected function _prepareColumns()
107
+ {
108
+ $this->addColumn('title', array(
109
+ 'header' => Mage::helper('M2ePro')->__('Title'),
110
+ 'align' => 'left',
111
+ 'type' => 'text',
112
+ 'index' => 'title',
113
+ 'filter' => false,
114
+ 'sortable' => false,
115
+ 'frame_callback' => array($this, 'callbackColumnTitle')
116
+ ));
117
+
118
+ $this->addColumn('status', array(
119
+ 'header' => Mage::helper('M2ePro')->__('Status/Reason'),
120
+ 'align' => 'left',
121
+ 'type' => 'text',
122
+ 'width' => '140px',
123
+ 'index' => 'title',
124
+ 'filter' => false,
125
+ 'sortable' => false,
126
+ 'frame_callback' => array($this, 'callbackColumnStatus')
127
+ ));
128
+
129
+ $this->addColumn('action', array(
130
+ 'header' => Mage::helper('M2ePro')->__('Action'),
131
+ 'align' => 'left',
132
+ 'type' => 'number',
133
+ 'width' => '55px',
134
+ 'index' => 'id',
135
+ 'filter' => false,
136
+ 'sortable' => false,
137
+ 'frame_callback' => array($this, 'callbackColumnAction')
138
+ ));
139
+ }
140
+
141
+ protected function _prepareLayout()
142
+ {
143
+ $this->setChild('refresh_button',
144
+ $this->getLayout()->createBlock('adminhtml/widget_button')
145
+ ->setData(array(
146
+ 'id' => 'description_template_refresh_btn',
147
+ 'label' => Mage::helper('M2ePro')->__('Refresh'),
148
+ 'onclick' => $this->getJsObjectName().'.reload()'
149
+ ))
150
+ );
151
+
152
+ return parent::_prepareLayout();
153
+ }
154
+
155
+ // ####################################
156
+
157
+ public function getRefreshButtonHtml()
158
+ {
159
+ return $this->getChildHtml('refresh_button');
160
+ }
161
+
162
+ // ####################################
163
+
164
+ public function getMainButtonsHtml()
165
+ {
166
+ return $this->getRefreshButtonHtml() . parent::getMainButtonsHtml();
167
+ }
168
+
169
+ // ####################################
170
+
171
+ public function callbackColumnTitle($value, $row, $column, $isExport)
172
+ {
173
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
174
+ 'id' => $row->getData('id')
175
+ ));
176
+
177
+ $title = Mage::helper('M2ePro')->escapeHtml($row->getData('title'));
178
+
179
+ $categoryWord = Mage::helper('M2ePro')->__('Category');
180
+ $categoryPath = !empty($row['category_path']) ? "{$row['category_path']} ({$row['browsenode_id']})"
181
+ : Mage::helper('M2ePro')->__('N/A');
182
+
183
+ return <<<HTML
184
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
185
+ <div>
186
+ <span style="font-weight: bold">{$categoryWord}</span>: <span style="color: #505050">{$categoryPath}</span><br/>
187
+ </div>
188
+ HTML;
189
+
190
+ }
191
+
192
+ public function callbackColumnStatus($value, $row, $column, $isExport)
193
+ {
194
+ if ($this->getCheckNewAsinAccepted()) {
195
+ if (!$row->getChildObject()->isNewAsinAccepted()) {
196
+ return '<span style="color: #808080;">' .
197
+ Mage::helper('M2ePro')->__('New ASIN/ISBN feature is disabled') . '</span>';
198
+ }
199
+
200
+ $productAttrCounts = $this->getProductAttributesCountVariations();
201
+
202
+ if (!empty($productAttrCounts)) {
203
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
204
+ $detailsModel->setMarketplaceId($this->getMarketplaceId());
205
+ $themes = $detailsModel->getVariationThemes($row->getProductDataNick());
206
+
207
+ if (empty($themes)) {
208
+ return '<span style="color: #808080;">' .
209
+ Mage::helper('M2ePro')->__(
210
+ 'Selected Category doesn\'t support Variational Products'
211
+ ) . '</span>';
212
+ }
213
+
214
+ $themeAttrCounts = array();
215
+ foreach ($themes as $theme) {
216
+ $themeAttrCounts[] = count($theme['attributes']);
217
+ }
218
+
219
+ if (count(array_intersect($productAttrCounts, $themeAttrCounts)) !== count($productAttrCounts)) {
220
+ return '<span style="color: #808080;">' .
221
+ Mage::helper('M2ePro')->__(
222
+ 'This number of variation attributes cannot be used in chosen Category'
223
+ ) . '</span>';
224
+ }
225
+ }
226
+ }
227
+
228
+ return '<span style="color: green;">' . Mage::helper('M2ePro')->__('Ready to be assigned') . '</span>';
229
+ }
230
+
231
+ public function callbackColumnAction($value, $row, $column, $isExport)
232
+ {
233
+ $assignText = Mage::helper('M2ePro')->__('Assign');
234
+ $mapToAsin = '';
235
+
236
+ if ($this->getCheckNewAsinAccepted()) {
237
+ if (!$row->getChildObject()->isNewAsinAccepted()) {
238
+ return '<span style="color: #808080;">' . $assignText . '</span>';
239
+ }
240
+
241
+ $productAttrCounts = $this->getProductAttributesCountVariations();
242
+
243
+ if (!empty($productAttrCounts)) {
244
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
245
+ $detailsModel->setMarketplaceId($this->getMarketplaceId());
246
+ $themes = $detailsModel->getVariationThemes($row->getProductDataNick());
247
+
248
+ if (empty($themes)) {
249
+ return '<span style="color: #808080;">' . $assignText . '</span>';
250
+ }
251
+
252
+ $themeAttrCounts = array();
253
+ foreach ($themes as $theme) {
254
+ $themeAttrCounts[] = count($theme['attributes']);
255
+ }
256
+
257
+ if (count(array_intersect($productAttrCounts, $themeAttrCounts)) !== count($productAttrCounts)) {
258
+ return '<span style="color: #808080;">' . $assignText . '</span>';
259
+ }
260
+ }
261
+
262
+ $mapToAsin = ',1';
263
+ }
264
+
265
+ return '<a href="javascript:void(0);"'
266
+ . 'onclick="' . $this->getMapToTemplateJsFn() . '(this, '
267
+ . $value . $mapToAsin .');">'.$assignText.'</a>';
268
+ }
269
+
270
+ // ####################################
271
+
272
+ protected function _toHtml()
273
+ {
274
+ $javascriptsMain = <<<JAVASCRIPT
275
+ <script type="text/javascript">
276
+
277
+ $$('#amazonTemplateDescriptionGrid div.grid th').each(function(el){
278
+ el.style.padding = '5px 5px';
279
+ });
280
+
281
+ $$('#amazonTemplateDescriptionGrid div.grid td').each(function(el){
282
+ el.style.padding = '5px 5px';
283
+ });
284
+
285
+ </script>
286
+ JAVASCRIPT;
287
+
288
+ //------------------------------
289
+ $templateDescriptionNewUrl = $this->getNewTemplateDescriptionUrl();
290
+
291
+ $data = array(
292
+ 'id' => 'templateDescription_addNew_button',
293
+ 'label' => Mage::helper('M2ePro')->__('Add New Description Policy'),
294
+ 'class' => 'templateDescription_addNew_button',
295
+ 'style' => 'float: right;',
296
+ 'onclick' => 'ListingGridHandlerObj.templateDescriptionHandler'
297
+ . '.createTemplateDescriptionInNewTab(\'' . $templateDescriptionNewUrl . '\')'
298
+ );
299
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
300
+ //------------------------------
301
+
302
+ $buttonBlockHtml = ($this->canDisplayContainer()) ? $buttonBlock->toHtml(): '';
303
+
304
+ return parent::_toHtml() . $buttonBlockHtml . $javascriptsMain;
305
+ }
306
+
307
+ // ####################################
308
+
309
+ public function getGridUrl()
310
+ {
311
+ return $this->getUrl('*/*/viewTemplateDescriptionsGrid', array(
312
+ '_current' => true,
313
+ '_query' => array(
314
+ 'products_ids' => $this->getProductsIds(),
315
+ 'check_is_new_asin_accepted' => $this->getCheckNewAsinAccepted()
316
+ )
317
+ ));
318
+ }
319
+
320
+ public function getRowUrl($row)
321
+ {
322
+ return false;
323
+ }
324
+
325
+ // ####################################
326
+
327
+ protected function getMarketplaceId()
328
+ {
329
+ if(empty($this->marketplaceId)) {
330
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
331
+ $productsIds = $this->getProductsIds();
332
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $productsIds[0]);
333
+ $this->marketplaceId = $listingProduct->getListing()->getMarketplaceId();
334
+ }
335
+
336
+ return $this->marketplaceId;
337
+ }
338
+
339
+ //---------------------------------------
340
+
341
+ protected function setNoTemplatesText()
342
+ {
343
+ $templateDescriptionEditUrl = $this->getNewTemplateDescriptionUrl();
344
+
345
+ $messageTxt = Mage::helper('M2ePro')->__('Description Policies are not found for current Marketplace.');
346
+ $linkTitle = Mage::helper('M2ePro')->__('Create New Description Policy.');
347
+
348
+ $message = <<<HTML
349
+ <p>{$messageTxt} <a href="javascript:void(0);"
350
+ id="templateDescription_addNew_link"
351
+ onclick="ListingGridHandlerObj.templateDescriptionHandler.createTemplateDescriptionInNewTab(
352
+ '{$templateDescriptionEditUrl}');">{$linkTitle}</a>
353
+ </p>
354
+ HTML;
355
+
356
+ $this->setEmptyText($message);
357
+ }
358
+
359
+ protected function getNewTemplateDescriptionUrl()
360
+ {
361
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/new', array(
362
+ 'is_new_asin_accepted' => $this->getCheckNewAsinAccepted(),
363
+ 'marketplace_id' => $this->getMarketplaceId()
364
+ ));
365
+ }
366
+
367
+ //---------------------------------------
368
+
369
+ protected function getParentListingProduct()
370
+ {
371
+ $productIds = $this->getProductsIds();
372
+ if (count($productIds) == 1 && empty($this->listingProduct)) {
373
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $productIds[0]);
374
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
375
+ $this->listingProduct = $listingProduct;
376
+ }
377
+ }
378
+ return $this->listingProduct;
379
+ }
380
+
381
+ //---------------------------------------
382
+
383
+ protected function getProductAttributesCountVariations()
384
+ {
385
+ if (is_null($this->productsAttributesCountVariations)) {
386
+ $this->productsAttributesCountVariations = array();
387
+
388
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Listing_Product_Collection $collection */
389
+ $collection = Mage::getModel('M2ePro/Listing_Product')->getCollection();
390
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
391
+ $collection->addFieldToFilter('additional_data', array('notnull' => true));
392
+ $collection->addFieldToFilter('id', array('in' => $this->getProductsIds()));
393
+ $collection->addFieldToSelect('additional_data');
394
+
395
+ $collection->join(
396
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
397
+ 'listing_product_id=id',
398
+ null
399
+ );
400
+ $collection->addFieldToFilter('is_variation_parent', 1);
401
+
402
+ foreach ($collection->getData() as $row) {
403
+ $data = json_decode($row['additional_data'], true);
404
+
405
+ $count = count($data['variation_product_attributes']);
406
+ if (!in_array($count, $this->productsAttributesCountVariations)) {
407
+ $this->productsAttributesCountVariations[] = $count;
408
+ }
409
+ }
410
+ }
411
+
412
+ return $this->productsAttributesCountVariations;
413
+ }
414
+
415
+ //---------------------------------------
416
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Main.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_TemplateDescription_Main
8
+ extends Mage_Adminhtml_Block_Widget_Container
9
+ {
10
+
11
+ protected $newAsin = false;
12
+ protected $messages = array();
13
+ /**
14
+ * @param array $messages
15
+ */
16
+ public function setMessages($messages)
17
+ {
18
+ $this->messages = $messages;
19
+ }
20
+
21
+ /**
22
+ * @return array
23
+ */
24
+ public function getMessages()
25
+ {
26
+ return $this->messages;
27
+ }
28
+
29
+ /**
30
+ * @return boolean
31
+ */
32
+ public function isNewAsin()
33
+ {
34
+ return $this->newAsin;
35
+ }
36
+
37
+ /**
38
+ * @param boolean $newAsin
39
+ */
40
+ public function setNewAsin($newAsin)
41
+ {
42
+ $this->newAsin = $newAsin;
43
+ }
44
+
45
+ public function __construct()
46
+ {
47
+ parent::__construct();
48
+
49
+ $this->setTemplate('M2ePro/common/amazon/listing/template_description/main.phtml');
50
+ }
51
+
52
+ public function getWarnings()
53
+ {
54
+ $warnings = '';
55
+ foreach ($this->getMessages() as $message) {
56
+ $warnings .= <<<HTML
57
+ <ul class="messages">
58
+ <li class="{$message['type']}-msg">
59
+ <ul>
60
+ <li>{$message['text']}</li>
61
+ </ul>
62
+ </li>
63
+ </ul>
64
+ HTML;
65
+ }
66
+ return $warnings;
67
+ }
68
+
69
+ public function getReasonMessage()
70
+ {
71
+ if ($this->isNewAsin()) {
72
+ return Mage::helper('M2ePro')->__(
73
+ 'For all Products the Description Policies can be <i class="underline">Assigned</i> from the list below.
74
+ <br/><br/><b>Note:</b> List of Description Policies available for assigning depends on the
75
+ combination of the chosen Products.');
76
+ }
77
+ return Mage::helper('M2ePro')->__('Please select Description Policy.');
78
+ }
79
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2014 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs
8
+ extends Mage_Adminhtml_Block_Widget_Tabs
9
+ {
10
+ protected $listingProductId;
11
+ /**
12
+ * @param mixed $listingProductId
13
+ */
14
+ public function setListingProductId($listingProductId)
15
+ {
16
+ $this->listingProductId = $listingProductId;
17
+ }
18
+
19
+ /**
20
+ * @return mixed
21
+ */
22
+ public function getListingProductId()
23
+ {
24
+ return $this->listingProductId;
25
+ }
26
+
27
+ //------------------------------
28
+
29
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
30
+ protected $listingProduct;
31
+
32
+ /**
33
+ * @return Ess_M2ePro_Model_Listing_Product|null
34
+ */
35
+ public function getListingProduct()
36
+ {
37
+ if(empty($this->listingProduct)) {
38
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
39
+ ->getObject('Listing_Product', $this->getListingProductId());
40
+ }
41
+
42
+ return $this->listingProduct;
43
+ }
44
+
45
+ //------------------------------
46
+
47
+ public function __construct()
48
+ {
49
+ parent::__construct();
50
+
51
+ // Initialization block
52
+ //------------------------------
53
+ $this->setId('amazonVariationProductManageTabs');
54
+ //------------------------------
55
+
56
+ $this->setTemplate('widget/tabshoriz.phtml');
57
+ $this->setDestElementId('variation_product_manage_tabs_container');
58
+ }
59
+
60
+ //------------------------------
61
+
62
+ protected function _beforeToHtml()
63
+ {
64
+ $this->addTab('variations', array(
65
+ 'label' => Mage::helper('M2ePro')->__('Child Products'),
66
+ 'title' => Mage::helper('M2ePro')->__('Child Products'),
67
+ 'content' => $this->getLayout()
68
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_variations')
69
+ ->setListingProductId($this->getListingProductId())
70
+ ->toHtml()
71
+ ));
72
+
73
+ $settingsBlock = $this->getLayout()
74
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_settings')
75
+ ->setListingProductId($this->getListingProductId());
76
+ $settingsBlock->calculateWarnings();
77
+
78
+ $settingsBlockLabel = Mage::helper('M2ePro')->__('Settings');
79
+ $settingsBlockTitle = Mage::helper('M2ePro')->__('Settings');
80
+
81
+ if(count($settingsBlock->getMessages()) > 0) {
82
+ $iconPath = $this->getSkinUrl('M2ePro/images/'. $settingsBlock->getMessagesType() .'.png');
83
+ $problemIcon = '<img style="vertical-align: middle;" src="'
84
+ . $iconPath . '" alt="" width="16" height="15"> ';
85
+ $settingsBlockLabel = $problemIcon.$settingsBlockLabel;
86
+ $settingsBlockTitle = Mage::helper('M2ePro')->__(
87
+ 'Action required.'
88
+ );
89
+ }
90
+
91
+ $this->addTab('settings', array(
92
+ 'label' => $settingsBlockLabel,
93
+ 'title' => $settingsBlockTitle,
94
+ 'content' => $this->getLayout()
95
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_settings')
96
+ ->setListingProductId($this->getListingProductId())
97
+ ->toHtml()
98
+ ));
99
+
100
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
101
+ if(empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner()) {
102
+ $this->setActiveTab('settings');
103
+ } else {
104
+ $this->setActiveTab('variations');
105
+ }
106
+
107
+ return parent::_beforeToHtml();
108
+ }
109
+
110
+ protected function _toHtml()
111
+ {
112
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
113
+
114
+ $showMask = 0;
115
+ if(!(empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner())) {
116
+ $showMask = 1;
117
+ }
118
+
119
+ $data = array(
120
+ 'style' => 'float: right; margin-top: 7px; ',
121
+ 'label' => Mage::helper('M2ePro')->__('Close'),
122
+ 'onclick' => 'ListingGridHandlerObj.variationProductManageHandler.closeManageVariationsPopup()'
123
+ );
124
+ $closeBtn = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
125
+
126
+ $additionalJavascript = <<<JAVASCRIPT
127
+ <script type="text/javascript">
128
+ amazonVariationProductManageTabsJsTabs.moveTabContentInDest();
129
+
130
+ if (!{$showMask}) {
131
+ amazonVariationProductManageTabsJsTabs.tabs[0].hide();
132
+ }
133
+
134
+ ListingGridHandlerObj.variationProductManageHandler.loadVariationsGrid({$showMask});
135
+ </script>
136
+ JAVASCRIPT;
137
+
138
+ return parent::_toHtml() .
139
+ '<div id="variation_product_manage_tabs_container"></div>' .
140
+ $additionalJavascript .
141
+ $closeBtn->toHtml();
142
+ }
143
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php ADDED
@@ -0,0 +1,682 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Settings
8
+ extends Mage_Adminhtml_Block_Widget_Container
9
+ {
10
+
11
+ const MESSAGE_TYPE_ERROR = 'error';
12
+ const MESSAGE_TYPE_WARNING = 'warning';
13
+
14
+ protected $warningsCalculated = false;
15
+
16
+ protected $channelThemes = null;
17
+ protected $childListingProducts = null;
18
+ protected $currentProductVariations = null;
19
+ protected $productVariationsTree = array();
20
+ protected $channelVariationsTree = array();
21
+
22
+ //------------------------------
23
+
24
+ protected $listingProductId;
25
+
26
+ /**
27
+ * @param mixed $listingProductId
28
+ * @return $this
29
+ */
30
+ public function setListingProductId($listingProductId)
31
+ {
32
+ $this->listingProductId = $listingProductId;
33
+
34
+ return $this;
35
+ }
36
+ /**
37
+ * @return mixed
38
+ */
39
+ public function getListingProductId()
40
+ {
41
+ return $this->listingProductId;
42
+ }
43
+
44
+ //------------------------------
45
+
46
+ protected $messages = array();
47
+ /**
48
+ * @param array $message
49
+ */
50
+ public function addMessage($message, $type = self::MESSAGE_TYPE_ERROR)
51
+ {
52
+ $this->messages[] = array(
53
+ 'type' => $type,
54
+ 'msg' => $message
55
+ );
56
+ }
57
+ /**
58
+ * @param array $messages
59
+ */
60
+ public function setMessages($messages)
61
+ {
62
+ $this->messages = $messages;
63
+ }
64
+ /**
65
+ * @return array
66
+ */
67
+ public function getMessages()
68
+ {
69
+ return $this->messages;
70
+ }
71
+
72
+ public function getMessagesType()
73
+ {
74
+ $type = self::MESSAGE_TYPE_WARNING;
75
+ foreach ($this->messages as $message) {
76
+ if($message['type'] === self::MESSAGE_TYPE_ERROR) {
77
+ $type = $message['type'];
78
+ break;
79
+ }
80
+ }
81
+
82
+ return $type;
83
+ }
84
+
85
+ //------------------------------
86
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
87
+ protected $listingProduct;
88
+
89
+ /**
90
+ * @return Ess_M2ePro_Model_Listing_Product|null
91
+ */
92
+ public function getListingProduct()
93
+ {
94
+ if(empty($this->listingProduct)) {
95
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
96
+ ->getObject('Listing_Product', $this->getListingProductId());
97
+ }
98
+
99
+ return $this->listingProduct;
100
+ }
101
+
102
+ //------------------------------
103
+
104
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute $matcherAttribute */
105
+ protected $matcherAttributes;
106
+
107
+ /**
108
+ * @return Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute
109
+ */
110
+ public function getMatcherAttributes()
111
+ {
112
+ if(empty($this->matcherAttributes)) {
113
+ $this->matcherAttributes = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Attribute');
114
+ $this->matcherAttributes->setMarketplaceId($this->getListingProduct()->getListing()->getMarketplaceId());
115
+ $this->matcherAttributes->setMagentoProduct($this->getListingProduct()->getMagentoProduct());
116
+ $this->matcherAttributes->setDestinationAttributes($this->getDestinationAttributes());
117
+ }
118
+
119
+ return $this->matcherAttributes;
120
+ }
121
+
122
+ public function __construct()
123
+ {
124
+ parent::__construct();
125
+
126
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/settings.phtml');
127
+ }
128
+
129
+ //------------------------------
130
+
131
+ public function getWarnings()
132
+ {
133
+ $warnings = '';
134
+ foreach ($this->getMessages() as $message) {
135
+ $warnings .= <<<HTML
136
+ <li class="{$message['type']}-msg">
137
+ <ul>
138
+ <li>{$message['msg']}</li>
139
+ </ul>
140
+ </li>
141
+ HTML;
142
+ }
143
+ return $warnings;
144
+ }
145
+
146
+ public function calculateWarnings()
147
+ {
148
+ if(!$this->warningsCalculated) {
149
+
150
+ $this->warningsCalculated = true;
151
+
152
+ if (!$this->hasGeneralId() && $this->isGeneralIdOwner()) {
153
+ if(!$this->hasChannelTheme() || !$this->hasMatchedAttributes()) {
154
+ $this->addMessage(
155
+ Mage::helper('M2ePro')
156
+ ->__('Creation of New Parent-Child Product is impossible because Variation Theme
157
+ or correspondence between Magento Product Attributes and Amazon Product Attributes
158
+ was not set. Please, specify a Variation Theme or correspondence between
159
+ Variation Attributes.'),
160
+ self::MESSAGE_TYPE_ERROR
161
+ );
162
+ }
163
+ } elseif ($this->hasGeneralId()) {
164
+ if (!$this->hasMatchedAttributes()) {
165
+ $this->addMessage(
166
+ Mage::helper('M2ePro')->__(
167
+ 'Selling of existing Child Products on Amazon is impossible because correspondence
168
+ between Magento Product Attributes and Amazon Product Attributes was not set.
169
+ Please, specify correspondence between Variation Attributes.'
170
+ ),
171
+ self::MESSAGE_TYPE_ERROR
172
+ );
173
+ }
174
+ if ($this->isGeneralIdOwner() && !$this->hasChannelTheme()) {
175
+ $this->addMessage(
176
+ Mage::helper('M2ePro')->__(
177
+ 'Creation of New Amazon Child Products feature is temporary unavailable because
178
+ Variation Theme was not set. Please, specify Variation Theme.'
179
+ ),
180
+ self::MESSAGE_TYPE_WARNING
181
+ );
182
+ }
183
+ }
184
+
185
+ }
186
+ }
187
+
188
+ //------------------------------
189
+
190
+ protected function _beforeToHtml()
191
+ {
192
+ $this->calculateWarnings();
193
+
194
+ return parent::_beforeToHtml();
195
+ }
196
+
197
+ // ###########################################
198
+
199
+ public function isInAction()
200
+ {
201
+ $lockedObjects = $this->getListingProduct()->getObjectLocks('in_action');
202
+ return !empty($lockedObjects);
203
+ }
204
+
205
+ // -------------------------------------------
206
+
207
+ public function getProductAttributes()
208
+ {
209
+ return $this->getListingProduct()->getChildObject()
210
+ ->getVariationManager()->getTypeModel()->getProductAttributes();
211
+ }
212
+
213
+ // -------------------------------------------
214
+
215
+ public function showGeneralIdActions()
216
+ {
217
+ return !$this->getListingProduct()->getMagentoProduct()->isBundleType() &&
218
+ !$this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
219
+ }
220
+
221
+ // -------------------------------------------
222
+
223
+ public function hasGeneralId()
224
+ {
225
+ return $this->getListingProduct()->getChildObject()->getGeneralId() !== NULL;
226
+ }
227
+
228
+ public function getGeneralId()
229
+ {
230
+ return $this->getListingProduct()->getChildObject()->getGeneralId();
231
+ }
232
+
233
+ public function getGeneralIdLink()
234
+ {
235
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
236
+ $this->getGeneralId(),
237
+ $this->getListingProduct()->getListing()->getMarketplaceId()
238
+ );
239
+
240
+ return <<<HTML
241
+ <a href="{$url}" target="_blank" title="{$this->getGeneralId()}" >{$this->getGeneralId()}</a>
242
+ HTML;
243
+ }
244
+
245
+ public function isGeneralIdOwner()
246
+ {
247
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
248
+ }
249
+
250
+ // -------------------------------------------
251
+
252
+ public function getDescriptionTemplateLink()
253
+ {
254
+ $url = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
255
+ 'id' => $this->getListingProduct()->getChildObject()->getTemplateDescriptionId()
256
+ ));
257
+
258
+ $templateTitle = $this->getListingProduct()->getChildObject()->getDescriptionTemplate()->getTitle();
259
+
260
+ return <<<HTML
261
+ <a href="{$url}" target="_blank" title="{$templateTitle}" >{$templateTitle}</a>
262
+ HTML;
263
+ }
264
+
265
+ // -------------------------------------------
266
+
267
+ public function hasChannelTheme()
268
+ {
269
+ return $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel()->hasChannelTheme();
270
+ }
271
+
272
+ public function getChannelTheme()
273
+ {
274
+ return $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel()->getChannelTheme();
275
+ }
276
+
277
+ public function getChannelThemes()
278
+ {
279
+ if (!is_null($this->channelThemes)) {
280
+ return $this->channelThemes;
281
+ }
282
+
283
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
284
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
285
+ $descriptionTemplate = $amazonListingProduct->getAmazonDescriptionTemplate();
286
+
287
+ if (!$descriptionTemplate) {
288
+ return array();
289
+ }
290
+
291
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
292
+ $detailsModel->setMarketplaceId($this->getListingProduct()->getListing()->getMarketplaceId());
293
+
294
+ return $this->channelThemes = $detailsModel->getVariationThemes($descriptionTemplate->getProductDataNick());
295
+ }
296
+
297
+ public function getChannelThemeAttr()
298
+ {
299
+ $theme = $this->getChannelTheme();
300
+ $themes = $this->getChannelThemes();
301
+
302
+ if(!empty($themes[$theme])) {
303
+ return $themes[$theme]['attributes'];
304
+ }
305
+
306
+ return null;
307
+ }
308
+
309
+ public function getChannelThemeNote()
310
+ {
311
+ $theme = $this->getChannelTheme();
312
+ $themes = $this->getChannelThemes();
313
+
314
+ if(!empty($themes[$theme])) {
315
+ return $themes[$theme]['note'];
316
+ }
317
+
318
+ return null;
319
+ }
320
+
321
+ public function getChannelThemeAttrString()
322
+ {
323
+ $themesAttributes = $this->getChannelThemeAttr();
324
+
325
+ if(!empty($themesAttributes)) {
326
+ return implode(', ', $themesAttributes);
327
+ }
328
+
329
+ return Mage::helper('M2ePro')->__('Variation Theme not found.');
330
+ }
331
+
332
+ // ----------------------------------------
333
+
334
+ public function hasMatchedAttributes()
335
+ {
336
+ return $this->getListingProduct()->getChildObject()
337
+ ->getVariationManager()->getTypeModel()->hasMatchedAttributes();
338
+ }
339
+
340
+ public function getMatchedAttributes()
341
+ {
342
+ if($this->hasMatchedAttributes()) {
343
+ return $this->getListingProduct()->getChildObject()
344
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
345
+ }
346
+ return $this->getMatcherAttributes()->getMatchedAttributes();
347
+ }
348
+
349
+ public function getDestinationAttributes()
350
+ {
351
+ if(!$this->hasGeneralId() && $this->isGeneralIdOwner() && $this->hasChannelTheme()) {
352
+ return $this->getChannelThemeAttr();
353
+ }
354
+ return array_keys($this->getListingProduct()->getChildObject()
355
+ ->getVariationManager()->getTypeModel()->getChannelAttributesSets());
356
+ }
357
+
358
+ // ###########################################
359
+
360
+ public function getChildListingProducts()
361
+ {
362
+ if (!is_null($this->childListingProducts)) {
363
+ return $this->childListingProducts;
364
+ }
365
+
366
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
367
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
368
+ }
369
+
370
+ public function getCurrentProductVariations()
371
+ {
372
+ if (!is_null($this->currentProductVariations)) {
373
+ return $this->currentProductVariations;
374
+ }
375
+
376
+ $magentoProductVariations = $this->getListingProduct()
377
+ ->getMagentoProduct()
378
+ ->getVariationInstance()
379
+ ->getVariationsTypeStandard();
380
+
381
+ $productVariations = array();
382
+
383
+ foreach ($magentoProductVariations['variations'] as $option) {
384
+ $productOption = array();
385
+
386
+ foreach ($option as $attribute) {
387
+ $productOption[$attribute['attribute']] = $attribute['option'];
388
+ }
389
+
390
+ $productVariations[] = $productOption;
391
+ }
392
+
393
+ return $this->currentProductVariations = $productVariations;
394
+ }
395
+
396
+ public function getChannelVariations()
397
+ {
398
+ if (!is_null($this->childListingProducts)) {
399
+ return $this->childListingProducts;
400
+ }
401
+
402
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
403
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
404
+ }
405
+
406
+ public function getCurrentChannelVariations()
407
+ {
408
+ return $this->getListingProduct()->getChildObject()
409
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
410
+ }
411
+
412
+ // ------------------------------------------
413
+
414
+ public function getUsedChannelVariations()
415
+ {
416
+ $usedOptions = array();
417
+
418
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
419
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
420
+
421
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
422
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
423
+
424
+ if (!$childTypeModel->isVariationChannelMatched()) {
425
+ continue;
426
+ }
427
+
428
+ $usedOptions[] = $childTypeModel->getChannelOptions();
429
+ }
430
+
431
+ return $usedOptions;
432
+ }
433
+
434
+ public function getUsedProductVariations()
435
+ {
436
+ $usedOptions = array();
437
+
438
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
439
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
440
+
441
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
442
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
443
+
444
+ if (!$childTypeModel->isVariationProductMatched()) {
445
+ continue;
446
+ }
447
+
448
+ $usedOptions[] = $childTypeModel->getProductOptions();
449
+ }
450
+
451
+ return $usedOptions;
452
+ }
453
+
454
+ // ------------------------------------------
455
+
456
+ public function getUnusedProductVariations()
457
+ {
458
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
459
+ }
460
+
461
+ public function getUnusedChannelVariations()
462
+ {
463
+ return $this->getUnusedVariations($this->getCurrentChannelVariations(), $this->getUsedChannelVariations());
464
+ }
465
+
466
+ private function getUnusedVariations($currentVariations, $usedVariations)
467
+ {
468
+ if (empty($currentVariations)) {
469
+ return array();
470
+ }
471
+
472
+ if (empty($usedVariations)) {
473
+ return $currentVariations;
474
+ }
475
+
476
+ $unusedOptions = array();
477
+
478
+ foreach ($currentVariations as $id => $currentOption) {
479
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
480
+ continue;
481
+ }
482
+
483
+ $unusedOptions[$id] = $currentOption;
484
+ }
485
+
486
+ return $unusedOptions;
487
+ }
488
+
489
+ private function isVariationExistsInArray(array $needle, array $haystack)
490
+ {
491
+ foreach ($haystack as $option) {
492
+ if ($option != $needle) {
493
+ continue;
494
+ }
495
+
496
+ return true;
497
+ }
498
+
499
+ return false;
500
+ }
501
+
502
+ // ------------------------------------------
503
+
504
+ public function getAttributesOptionsFromVariations($variations)
505
+ {
506
+ $attributesOptions = array();
507
+
508
+ foreach ($variations as $variation) {
509
+ foreach ($variation as $attr => $option) {
510
+ if (!isset($attributesOptions[$attr])) {
511
+ $attributesOptions[$attr] = array();
512
+ }
513
+ if (!in_array($option, $attributesOptions[$attr])) {
514
+ $attributesOptions[$attr][] = $option;
515
+ }
516
+ }
517
+ }
518
+
519
+ ksort($attributesOptions);
520
+
521
+ return $attributesOptions;
522
+ }
523
+
524
+ // ------------------------------------------
525
+
526
+ public function getProductVariationsTree()
527
+ {
528
+ if (empty($this->productVariationsTree)) {
529
+
530
+ $unusedVariations = $this->getUnusedProductVariations();
531
+ $variationsSets = $this->getAttributesOptionsFromVariations($unusedVariations);
532
+ $firstAttribute = key($variationsSets);
533
+
534
+ $this->productVariationsTree = $this->prepareVariations(
535
+ $firstAttribute,$unusedVariations,$variationsSets
536
+ );
537
+ }
538
+
539
+ return $this->productVariationsTree;
540
+ }
541
+
542
+ public function getChannelVariationsTree()
543
+ {
544
+ if (empty($this->channelVariationsTree)) {
545
+
546
+ $unusedVariations = $this->getUnusedChannelVariations();
547
+ $variationsSets = $this->getAttributesOptionsFromVariations($unusedVariations);
548
+ $firstAttribute = key($variationsSets);
549
+
550
+ $this->channelVariationsTree = $this->prepareVariations(
551
+ $firstAttribute,$unusedVariations,$variationsSets
552
+ );
553
+ }
554
+
555
+ return $this->channelVariationsTree;
556
+ }
557
+
558
+ private function prepareVariations($currentAttribute,$magentoVariations,$variationsSets,$filters = array())
559
+ {
560
+ $return = false;
561
+
562
+ $temp = array_flip(array_keys($variationsSets));
563
+
564
+ $lastAttributePosition = count($variationsSets) - 1;
565
+ $currentAttributePosition = $temp[$currentAttribute];
566
+
567
+ if ($currentAttributePosition != $lastAttributePosition) {
568
+
569
+ $temp = array_keys($variationsSets);
570
+ $nextAttribute = $temp[$currentAttributePosition + 1];
571
+
572
+ foreach ($variationsSets[$currentAttribute] as $option) {
573
+
574
+ $filters[$currentAttribute] = $option;
575
+
576
+ $result = $this->prepareVariations(
577
+ $nextAttribute,$magentoVariations,$variationsSets,$filters
578
+ );
579
+
580
+ if (!$result) {
581
+ continue;
582
+ }
583
+
584
+ $return[$currentAttribute][$option] = $result;
585
+ }
586
+
587
+ ksort($return[$currentAttribute]);
588
+
589
+ return $return;
590
+ }
591
+
592
+ $return = false;
593
+ foreach ($magentoVariations as $key => $magentoVariation) {
594
+ foreach ($magentoVariation as $attribute => $option) {
595
+
596
+ if ($attribute == $currentAttribute) {
597
+
598
+ if (count($variationsSets) != 1) {
599
+ continue;
600
+ }
601
+
602
+ $values = array_flip($variationsSets[$currentAttribute]);
603
+ $return = array($currentAttribute => $values);
604
+
605
+ foreach ($return[$currentAttribute] as &$option) {
606
+ $option = true;
607
+ }
608
+
609
+ return $return;
610
+ }
611
+
612
+ if ($option != $filters[$attribute]) {
613
+ unset($magentoVariations[$key]);
614
+ continue;
615
+ }
616
+
617
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
618
+ if ($tempAttribute == $currentAttribute) {
619
+ $option = $tempOption;
620
+ $return[$currentAttribute][$option] = true;
621
+ }
622
+ }
623
+ }
624
+ }
625
+
626
+ if (count($magentoVariations) < 1) {
627
+ return false;
628
+ }
629
+
630
+ ksort($return[$currentAttribute]);
631
+
632
+ return $return;
633
+ }
634
+
635
+ // ------------------------------------------
636
+
637
+ public function hasUnusedProductVariation()
638
+ {
639
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
640
+ }
641
+
642
+ public function hasUnusedChannelVariations()
643
+ {
644
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
645
+ }
646
+
647
+ // ------------------------------------------
648
+
649
+ public function hasChildWithEmptyProductOptions()
650
+ {
651
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
652
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
653
+
654
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
655
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
656
+
657
+ if (!$childTypeModel->isVariationProductMatched()) {
658
+ return true;
659
+ }
660
+ }
661
+
662
+ return false;
663
+ }
664
+
665
+ public function hasChildWithEmptyChannelOptions()
666
+ {
667
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
668
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
669
+
670
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
671
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
672
+
673
+ if (!$childTypeModel->isVariationChannelMatched()) {
674
+ return true;
675
+ }
676
+ }
677
+
678
+ return false;
679
+ }
680
+
681
+ // ###########################################
682
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations
8
+ extends Mage_Adminhtml_Block_Widget_Container
9
+ {
10
+ protected $listingProductId;
11
+ /**
12
+ * @param mixed $listingProductId
13
+ * @return $this
14
+ */
15
+ public function setListingProductId($listingProductId)
16
+ {
17
+ $this->listingProductId = $listingProductId;
18
+
19
+ return $this;
20
+ }
21
+ /**
22
+ * @return mixed
23
+ */
24
+ public function getListingProductId()
25
+ {
26
+ return $this->listingProductId;
27
+ }
28
+
29
+ public function __construct()
30
+ {
31
+ parent::__construct();
32
+
33
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations.phtml');
34
+
35
+ return $this;
36
+ }
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Child/Form.php ADDED
@@ -0,0 +1,398 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations_Child_Form
8
+ extends Mage_Adminhtml_Block_Widget_Form
9
+ {
10
+ protected $childListingProducts = null;
11
+ protected $currentProductVariations = null;
12
+ protected $productVariationsTree = array();
13
+ protected $channelVariationsTree = array();
14
+
15
+ protected $listingProductId;
16
+
17
+ /**
18
+ * @param mixed $listingProductId
19
+ * @return $this
20
+ */
21
+ public function setListingProductId($listingProductId)
22
+ {
23
+ $this->listingProductId = $listingProductId;
24
+
25
+ return $this;
26
+ }
27
+ /**
28
+ * @return mixed
29
+ */
30
+ public function getListingProductId()
31
+ {
32
+ return $this->listingProductId;
33
+ }
34
+
35
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
36
+ protected $listingProduct;
37
+
38
+ public function __construct()
39
+ {
40
+ parent::__construct();
41
+
42
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations/child/form.phtml');
43
+ }
44
+
45
+ // ----------------------------------------
46
+ /**
47
+ * @return Ess_M2ePro_Model_Listing_Product|null
48
+ */
49
+ public function getListingProduct()
50
+ {
51
+ if(empty($this->listingProduct)) {
52
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
53
+ ->getObject('Listing_Product', $this->getListingProductId());
54
+ }
55
+
56
+ return $this->listingProduct;
57
+ }
58
+
59
+ // ########################################
60
+
61
+ public function isGeneralIdOwner()
62
+ {
63
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
64
+ }
65
+
66
+ // ----------------------------------------
67
+
68
+ public function hasChannelTheme()
69
+ {
70
+ return $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel()->hasChannelTheme();
71
+ }
72
+
73
+ public function hasUnusedChannelVariations()
74
+ {
75
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
76
+ }
77
+
78
+ // ----------------------------------------
79
+
80
+ public function getMatchedAttributes()
81
+ {
82
+ return $this->getListingProduct()->getChildObject()
83
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
84
+ }
85
+
86
+ // ----------------------------------------
87
+
88
+ public function getUnusedProductVariations()
89
+ {
90
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
91
+ }
92
+
93
+ public function getUnusedChannelVariations()
94
+ {
95
+ return $this->getUnusedVariations($this->getCurrentChannelVariations(), $this->getUsedChannelVariations());
96
+ }
97
+
98
+ private function getUnusedVariations($currentVariations, $usedVariations)
99
+ {
100
+ if (empty($currentVariations)) {
101
+ return array();
102
+ }
103
+
104
+ if (empty($usedVariations)) {
105
+ return $currentVariations;
106
+ }
107
+
108
+ $unusedOptions = array();
109
+
110
+ foreach ($currentVariations as $id => $currentOption) {
111
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
112
+ continue;
113
+ }
114
+
115
+ $unusedOptions[$id] = $currentOption;
116
+ }
117
+
118
+ return $unusedOptions;
119
+ }
120
+
121
+ private function isVariationExistsInArray(array $needle, array $haystack)
122
+ {
123
+ foreach ($haystack as $option) {
124
+ if ($option != $needle) {
125
+ continue;
126
+ }
127
+
128
+ return true;
129
+ }
130
+
131
+ return false;
132
+ }
133
+
134
+ // ----------------------------------------
135
+
136
+ public function getChildListingProducts()
137
+ {
138
+ if (!is_null($this->childListingProducts)) {
139
+ return $this->childListingProducts;
140
+ }
141
+
142
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
143
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
144
+ }
145
+
146
+ public function getCurrentProductVariations()
147
+ {
148
+ if (!is_null($this->currentProductVariations)) {
149
+ return $this->currentProductVariations;
150
+ }
151
+
152
+ $magentoProductVariations = $this->getListingProduct()
153
+ ->getMagentoProduct()
154
+ ->getVariationInstance()
155
+ ->getVariationsTypeStandard();
156
+
157
+ $productVariations = array();
158
+
159
+ foreach ($magentoProductVariations['variations'] as $option) {
160
+ $productOption = array();
161
+
162
+ foreach ($option as $attribute) {
163
+ $productOption[$attribute['attribute']] = $attribute['option'];
164
+ }
165
+
166
+ $productVariations[] = $productOption;
167
+ }
168
+
169
+ return $this->currentProductVariations = $productVariations;
170
+ }
171
+
172
+ public function getCurrentChannelVariations()
173
+ {
174
+ return $this->getListingProduct()->getChildObject()
175
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
176
+ }
177
+
178
+ // ----------------------------------------
179
+
180
+ public function getAttributesOptionsFromVariations($variations)
181
+ {
182
+ $attributesOptions = array();
183
+
184
+ foreach ($variations as $variation) {
185
+ foreach ($variation as $attr => $option) {
186
+ if (!isset($attributesOptions[$attr])) {
187
+ $attributesOptions[$attr] = array();
188
+ }
189
+ if (!in_array($option, $attributesOptions[$attr])) {
190
+ $attributesOptions[$attr][] = $option;
191
+ }
192
+ }
193
+ }
194
+
195
+ ksort($attributesOptions);
196
+
197
+ return $attributesOptions;
198
+ }
199
+
200
+ // ----------------------------------------
201
+
202
+ public function getUsedChannelVariations()
203
+ {
204
+ $usedOptions = array();
205
+
206
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
207
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
208
+
209
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
210
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
211
+
212
+ if (!$childTypeModel->isVariationChannelMatched()) {
213
+ continue;
214
+ }
215
+
216
+ $usedOptions[] = $childTypeModel->getChannelOptions();
217
+ }
218
+
219
+ return $usedOptions;
220
+ }
221
+
222
+ public function getUsedProductVariations()
223
+ {
224
+ $usedOptions = array();
225
+
226
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
227
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
228
+
229
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
230
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
231
+
232
+ if (!$childTypeModel->isVariationProductMatched()) {
233
+ continue;
234
+ }
235
+
236
+ $usedOptions[] = $childTypeModel->getProductOptions();
237
+ }
238
+
239
+ return $usedOptions;
240
+ }
241
+
242
+ // ----------------------------------------
243
+
244
+ public function getProductVariationsTree()
245
+ {
246
+ if (empty($this->productVariationsTree)) {
247
+
248
+ $matchedAttributes = $this->getMatchedAttributes();
249
+ $unusedVariations = $this->sortVariationsAttributes(
250
+ $this->getUnusedProductVariations(),
251
+ array_keys($matchedAttributes)
252
+ );
253
+ $variationsSets = $this->sortVariationAttributes(
254
+ $this->getAttributesOptionsFromVariations($unusedVariations),
255
+ array_keys($matchedAttributes)
256
+ );
257
+
258
+ $firstAttribute = key($matchedAttributes);
259
+
260
+ $this->productVariationsTree = $this->prepareVariations(
261
+ $firstAttribute,$unusedVariations,$variationsSets
262
+ );
263
+ }
264
+
265
+ return $this->productVariationsTree;
266
+ }
267
+
268
+ public function getChannelVariationsTree()
269
+ {
270
+ if (empty($this->channelVariationsTree)) {
271
+
272
+ $matchedAttributes = $this->getMatchedAttributes();
273
+ $unusedVariations = $this->sortVariationsAttributes(
274
+ $this->getUnusedChannelVariations(),
275
+ array_values($matchedAttributes)
276
+ );
277
+
278
+ if (empty($unusedVariations)) {
279
+ $this->channelVariationsTree = new stdClass();
280
+
281
+ return $this->channelVariationsTree;
282
+ }
283
+
284
+ $variationsSets = $this->sortVariationAttributes(
285
+ $this->getAttributesOptionsFromVariations($unusedVariations),
286
+ array_values($matchedAttributes)
287
+ );
288
+
289
+ $firstAttribute = $matchedAttributes[key($matchedAttributes)];
290
+
291
+ $this->channelVariationsTree = $this->prepareVariations(
292
+ $firstAttribute,$unusedVariations,$variationsSets
293
+ );
294
+ }
295
+
296
+ return $this->channelVariationsTree;
297
+ }
298
+
299
+ private function sortVariationsAttributes($variations, $sortTemplate)
300
+ {
301
+ foreach ($variations as $key => $variation) {
302
+ $variations[$key] = $this->sortVariationAttributes($variation, $sortTemplate);
303
+ }
304
+
305
+ return $variations;
306
+ }
307
+
308
+ private function sortVariationAttributes($variation, $sortTemplate)
309
+ {
310
+ $sortedData = array();
311
+
312
+ foreach ($sortTemplate as $attr) {
313
+ $sortedData[$attr] = $variation[$attr];
314
+ }
315
+
316
+ return $sortedData;
317
+ }
318
+
319
+ private function prepareVariations($currentAttribute,$magentoVariations,$variationsSets,$filters = array())
320
+ {
321
+ $return = false;
322
+
323
+ $temp = array_flip(array_keys($variationsSets));
324
+
325
+ $lastAttributePosition = count($variationsSets) - 1;
326
+ $currentAttributePosition = $temp[$currentAttribute];
327
+
328
+ if ($currentAttributePosition != $lastAttributePosition) {
329
+
330
+ $temp = array_keys($variationsSets);
331
+ $nextAttribute = $temp[$currentAttributePosition + 1];
332
+
333
+ foreach ($variationsSets[$currentAttribute] as $option) {
334
+
335
+ $filters[$currentAttribute] = $option;
336
+
337
+ $result = $this->prepareVariations(
338
+ $nextAttribute,$magentoVariations,$variationsSets,$filters
339
+ );
340
+
341
+ if (!$result) {
342
+ continue;
343
+ }
344
+
345
+ $return[$currentAttribute][$option] = $result;
346
+ }
347
+
348
+ ksort($return[$currentAttribute]);
349
+
350
+ return $return;
351
+ }
352
+
353
+ $return = false;
354
+ foreach ($magentoVariations as $key => $magentoVariation) {
355
+ foreach ($magentoVariation as $attribute => $option) {
356
+
357
+ if ($attribute == $currentAttribute) {
358
+
359
+ if (count($variationsSets) != 1) {
360
+ continue;
361
+ }
362
+
363
+ $values = array_flip($variationsSets[$currentAttribute]);
364
+ $return = array($currentAttribute => $values);
365
+
366
+ foreach ($return[$currentAttribute] as &$option) {
367
+ $option = true;
368
+ }
369
+
370
+ return $return;
371
+ }
372
+
373
+ if ($option != $filters[$attribute]) {
374
+ unset($magentoVariations[$key]);
375
+ continue;
376
+ }
377
+
378
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
379
+ if ($tempAttribute == $currentAttribute) {
380
+ $option = $tempOption;
381
+ $return[$currentAttribute][$option] = true;
382
+ }
383
+ }
384
+ }
385
+ }
386
+
387
+ if (count($magentoVariations) < 1) {
388
+ return false;
389
+ }
390
+
391
+ ksort($return[$currentAttribute]);
392
+
393
+ return $return;
394
+ }
395
+
396
+ // ----------------------------------------
397
+
398
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Grid.php ADDED
@@ -0,0 +1,1404 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations_Grid
8
+ extends Mage_Adminhtml_Block_Widget_Grid
9
+ {
10
+
11
+ protected $childListingProducts = null;
12
+ protected $currentProductVariations = null;
13
+ protected $usedProductVariations = null;
14
+
15
+ protected $listingProductId;
16
+ /**
17
+ * @param mixed $listingProductId
18
+ */
19
+ public function setListingProductId($listingProductId)
20
+ {
21
+ $this->listingProductId = $listingProductId;
22
+ }
23
+ /**
24
+ * @return mixed
25
+ */
26
+ public function getListingProductId()
27
+ {
28
+ return $this->listingProductId;
29
+ }
30
+
31
+ //------------------------------
32
+
33
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
34
+ protected $listingProduct;
35
+
36
+ protected function getListingProduct()
37
+ {
38
+ if(empty($this->listingProduct)) {
39
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
40
+ ->getObject('Listing_Product', $this->getListingProductId());
41
+ }
42
+
43
+ return $this->listingProduct;
44
+ }
45
+
46
+ //------------------------------
47
+
48
+ private $lockedDataCache = array();
49
+
50
+ // ####################################
51
+
52
+ public function __construct()
53
+ {
54
+ parent::__construct();
55
+
56
+ // Initialization block
57
+ //------------------------------
58
+ $this->setId('amazonVariationProductManageGrid');
59
+ $this->setDefaultSort('id');
60
+ $this->setDefaultDir('ASC');
61
+ $this->setUseAjax(true);
62
+ //------------------------------
63
+ }
64
+
65
+ // ####################################
66
+
67
+ protected function _prepareCollection()
68
+ {
69
+ // Get collection
70
+ //----------------------------
71
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Listing_Product_Collection $collection */
72
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
73
+ $collection->getSelect()->distinct();
74
+ $collection->getSelect()->where("`second_table`.`variation_parent_id` = ?",(int)$this->getListingProductId());
75
+ //----------------------------
76
+
77
+ // Set collection to grid
78
+ $this->setCollection($collection);
79
+
80
+ return parent::_prepareCollection();
81
+ }
82
+
83
+ protected function _prepareColumns()
84
+ {
85
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
86
+ $parentType = $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel();
87
+
88
+ $channelAttributesSets = $parentType->getChannelAttributesSets();
89
+
90
+ if (!empty($channelAttributesSets)) {
91
+ $channelAttributes = array_keys($channelAttributesSets);
92
+ } else if ($parentType->hasMatchedAttributes()) {
93
+ $channelAttributes = array_values($parentType->getMatchedAttributes());
94
+ } else {
95
+ $channelAttributes = array();
96
+ }
97
+
98
+ $this->addColumn('product_options', array(
99
+ 'header' => Mage::helper('M2ePro')->__('Magento Variation'),
100
+ 'align' => 'left',
101
+ 'width' => '210px',
102
+ 'sortable' => false,
103
+ 'index' => 'additional_data',
104
+ 'filter_index' => 'additional_data',
105
+ 'frame_callback' => array($this, 'callbackColumnProductOptions'),
106
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
107
+ 'options' => $parentType->getProductAttributes(),
108
+ 'filter_condition_callback' => array($this, 'callbackProductOptions')
109
+ ));
110
+
111
+ $this->addColumn('channel_options', array(
112
+ 'header' => Mage::helper('M2ePro')->__('Amazon Variation'),
113
+ 'align' => 'left',
114
+ 'width' => '210px',
115
+ 'sortable' => false,
116
+ 'index' => 'additional_data',
117
+ 'filter_index' => 'additional_data',
118
+ 'frame_callback' => array($this, 'callbackColumnChannelOptions'),
119
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
120
+ 'options' => $channelAttributes,
121
+ 'filter_condition_callback' => array($this, 'callbackChannelOptions')
122
+ ));
123
+
124
+ $this->addColumn('sku', array(
125
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
126
+ 'align' => 'left',
127
+ 'type' => 'text',
128
+ 'index' => 'sku',
129
+ 'filter_index' => 'sku',
130
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
131
+ ));
132
+
133
+ $this->addColumn('general_id', array(
134
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
135
+ 'align' => 'left',
136
+ 'width' => '100px',
137
+ 'type' => 'text',
138
+ 'index' => 'general_id',
139
+ 'filter_index' => 'general_id',
140
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
141
+ ));
142
+
143
+ $this->addColumn('online_qty', array(
144
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
145
+ 'align' => 'right',
146
+ 'width' => '70px',
147
+ 'type' => 'number',
148
+ 'index' => 'online_qty',
149
+ 'filter_index' => 'online_qty',
150
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
151
+ ));
152
+
153
+ $this->addColumn('online_price', array(
154
+ 'header' => Mage::helper('M2ePro')->__('Price'),
155
+ 'align' => 'right',
156
+ 'width' => '70px',
157
+ 'type' => 'number',
158
+ 'index' => 'online_price',
159
+ 'filter_index' => 'online_price',
160
+ 'frame_callback' => array($this, 'callbackColumnPrice')
161
+ ));
162
+
163
+ $this->addColumn('status', array(
164
+ 'header' => Mage::helper('M2ePro')->__('Status'),
165
+ 'width' => '100px',
166
+ 'index' => 'status',
167
+ 'filter_index' => 'status',
168
+ 'type' => 'options',
169
+ 'sortable' => false,
170
+ 'options' => array(
171
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
172
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
173
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
174
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
175
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
176
+ ),
177
+ 'frame_callback' => array($this, 'callbackColumnStatus')
178
+ ));
179
+
180
+ return parent::_prepareColumns();
181
+ }
182
+
183
+ protected function _prepareMassaction()
184
+ {
185
+ // Set massaction identifiers
186
+ //--------------------------------
187
+ $this->setMassactionIdField('id');
188
+ $this->setMassactionIdFieldOnlyIndexValue(true);
189
+ //--------------------------------
190
+
191
+ // Set mass-action
192
+ //--------------------------------
193
+ $this->getMassactionBlock()->addItem('list', array(
194
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
195
+ 'url' => '',
196
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
197
+ ));
198
+
199
+ $this->getMassactionBlock()->addItem('revise', array(
200
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
201
+ 'url' => '',
202
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
203
+ ));
204
+
205
+ $this->getMassactionBlock()->addItem('relist', array(
206
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
207
+ 'url' => '',
208
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
209
+ ));
210
+
211
+ $this->getMassactionBlock()->addItem('stop', array(
212
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
213
+ 'url' => '',
214
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
215
+ ));
216
+
217
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
218
+ 'label' => Mage::helper('M2ePro')->__('Reset / Remove Item(s)'),
219
+ 'url' => '',
220
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
221
+ ));
222
+
223
+ //--------------------------------
224
+
225
+ return parent::_prepareMassaction();
226
+ }
227
+
228
+ // ####################################
229
+
230
+ public function callbackColumnProductOptions($additionalData, $row, $column, $isExport)
231
+ {
232
+ $html = '';
233
+
234
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $typeModel */
235
+ $typeModel = $row->getChildObject()->getVariationManager()->getTypeModel();
236
+
237
+ $html .= '<div class="product-options-main" style="font-size: 11px; color: grey; margin-left: 7px">';
238
+ if ($typeModel->isVariationProductMatched()) {
239
+ $html .= '<div class="product-options-list">';
240
+ foreach ($typeModel->getProductOptions() as $attribute => $option) {
241
+ !$option && $option = '--';
242
+ $html .= '<span class="attribute-row"><span class="attribute"><strong>' .
243
+ Mage::helper('M2ePro')->escapeHtml($attribute) .
244
+ '</strong></span>:&nbsp;<span class="value">' . Mage::helper('M2ePro')->escapeHtml($option) .
245
+ '</span></span><br/>';
246
+ }
247
+ $html .= '</div>';
248
+ }
249
+
250
+ $unusedVariations = $this->getUnusedProductVariations();
251
+ $hasInActionLock = $this->getLockedData($row);
252
+ $hasInActionLock = $hasInActionLock['in_action'];
253
+
254
+ if (!empty($unusedVariations) && !$hasInActionLock &&
255
+ (!$typeModel->isVariationProductMatched() || $row->getChildObject()->getGeneralId() !== NULL)
256
+ ) {
257
+
258
+ $listingProductId = $row->getId();
259
+ $attributes = $this->getListingProduct()->getChildObject()
260
+ ->getVariationManager()->getTypeModel()->getProductAttributes();
261
+ $variationsTree = $this->getProductVariationsTree($row);
262
+
263
+ sort($attributes);
264
+
265
+ $linkTitle = Mage::helper('M2ePro')->__('Change Variation');
266
+ $linkContent = Mage::helper('M2ePro')->__('Change Variation');
267
+
268
+ $attributes = Mage::helper('M2ePro')->escapeHtml(json_encode($attributes));
269
+ $variationsTree = Mage::helper('M2ePro')->escapeHtml(json_encode($variationsTree));
270
+
271
+ $html .= <<<HTML
272
+ <form action="javascript:void(0);" class="product-options-edit"></form>
273
+ <a href="javascript:"
274
+ onclick="ListingGridHandlerObj.editProductOptions(this, {$attributes}, {$variationsTree}, {$listingProductId})"
275
+ title="{$linkTitle}">{$linkContent}</a>
276
+ HTML;
277
+ }
278
+
279
+ $html .= '</div>';
280
+
281
+ return $html;
282
+ }
283
+
284
+ public function callbackColumnChannelOptions($additionalData, $row, $column, $isExport)
285
+ {
286
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
287
+ $amazonListingProduct = $row->getChildObject();
288
+
289
+ $typeModel = $amazonListingProduct->getVariationManager()->getTypeModel();
290
+
291
+ if (!$typeModel->isVariationChannelMatched()) {
292
+ if (!$typeModel->isVariationProductMatched() || !$amazonListingProduct->isGeneralIdOwner()) {
293
+ return '';
294
+ }
295
+
296
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $parentAmazonListingProduct */
297
+ $parentAmazonListingProduct = $typeModel->getParentListingProduct()->getChildObject();
298
+
299
+ $matchedAttributes = $parentAmazonListingProduct->getVariationManager()
300
+ ->getTypeModel()
301
+ ->getMatchedAttributes();
302
+
303
+ if (empty($matchedAttributes)) {
304
+ return '';
305
+ }
306
+
307
+ $options = array();
308
+
309
+ foreach ($typeModel->getProductOptions() as $attribute => $value) {
310
+ $options[$matchedAttributes[$attribute]] = $value;
311
+ }
312
+ } else {
313
+ $options = $typeModel->getChannelOptions();
314
+ }
315
+
316
+ if (empty($options)) {
317
+ return '';
318
+ }
319
+
320
+ $generalId = $amazonListingProduct->getGeneralId();
321
+
322
+ $html = '<div style="font-size: 11px; color: grey; margin-left: 7px">';
323
+
324
+ foreach ($options as $attribute => $option) {
325
+ !$option && $option = '--';
326
+
327
+ $attrName = Mage::helper('M2ePro')->escapeHtml($attribute);
328
+ $optionName = Mage::helper('M2ePro')->escapeHtml($option);
329
+
330
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
331
+ $html .= <<<HTML
332
+ {$attrName}:&nbsp;{$optionName}<br/>
333
+ HTML;
334
+ } else {
335
+ $html .= <<<HTML
336
+ <b>{$attrName}</b>:&nbsp;{$optionName}<br/>
337
+ HTML;
338
+ }
339
+
340
+ }
341
+
342
+ $html .= '</div>';
343
+
344
+ return $html;
345
+ }
346
+
347
+ public function callbackColumnAmazonSku($sku, $row, $column, $isExport)
348
+ {
349
+ if (is_null($sku) || $sku === '') {
350
+ return Mage::helper('M2ePro')->__('N/A');
351
+ }
352
+ return $sku;
353
+ }
354
+
355
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
356
+ {
357
+ if (is_null($generalId) || $generalId === '') {
358
+
359
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
360
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
361
+ if ($amazonListingProduct->isGeneralIdOwner()) {
362
+ return Mage::helper('M2ePro')->__('New ASIN/ISBN');
363
+ }
364
+
365
+ return Mage::helper('M2ePro')->__('N/A');
366
+ }
367
+ return $this->getGeneralIdLink($generalId);
368
+ }
369
+
370
+ public function callbackColumnAvailableQty($qty, $row, $column, $isExport)
371
+ {
372
+ if (is_null($qty) || $qty === '') {
373
+ return Mage::helper('M2ePro')->__('N/A');
374
+ }
375
+ return $qty;
376
+ }
377
+
378
+ public function callbackColumnPrice($value, $row, $column, $isExport)
379
+ {
380
+ if (is_null($value) || $value === '') {
381
+ return Mage::helper('M2ePro')->__('N/A');
382
+ }
383
+
384
+ $marketplaceId = $this->getListingProduct()->getListing()->getMarketplaceId();
385
+ $currency = Mage::helper('M2ePro/Component_Amazon')
386
+ ->getCachedObject('Marketplace',$marketplaceId)
387
+ ->getChildObject()
388
+ ->getDefaultCurrency();
389
+
390
+ $salePriceValue = $row->getData('online_sale_price');
391
+ if (is_null($salePriceValue) ||
392
+ (float)$salePriceValue <= 0) {
393
+ $salePriceValue = null;
394
+ } else {
395
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePriceValue);
396
+ }
397
+
398
+ if ((float)$value <= 0) {
399
+ $result = '<span style="color: #f00;">0</span>';
400
+ } else {
401
+ $result = Mage::app()->getLocale()->currency($currency)->toCurrency($value);
402
+ }
403
+
404
+ return $result.($salePriceValue ? ' <br/><span style="color:gray;">'.$salePriceValue.'</span>' : '');
405
+ }
406
+
407
+ public function callbackColumnStatus($value, $row, $column, $isExport)
408
+ {
409
+ $listingProductId = (int)$row->getData('id');
410
+
411
+ $html = $this->getViewLogIconHtml($row);
412
+
413
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
414
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
415
+
416
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
417
+ if (!empty($synchNote)) {
418
+
419
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
420
+
421
+ if (empty($html)) {
422
+ $html = <<<HTML
423
+ <span style="float:right;">
424
+ <img id="map_link_error_icon_{$row->getId()}"
425
+ class="tool-tip-image"
426
+ style="vertical-align: middle;"
427
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
428
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
429
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
430
+ <span>{$synchNote}</span>
431
+ </span>
432
+ </span>
433
+ HTML;
434
+ } else {
435
+ $html .= <<<HTML
436
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
437
+ HTML;
438
+ }
439
+ }
440
+
441
+ switch ($row->getData('status')) {
442
+
443
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
444
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
445
+ $html .= '<span style="color: gray;">' . $value . '</span>';
446
+ break;
447
+
448
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
449
+ $html .= '<span style="color: green;">' . $value . '</span>';
450
+ break;
451
+
452
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
453
+ $html .= '<span style="color: red;">'.$value.'</span>';
454
+ break;
455
+
456
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
457
+ $html .= '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
458
+ break;
459
+
460
+ default:
461
+ break;
462
+ }
463
+
464
+ $tempLocks = $this->getLockedData($row);
465
+ $tempLocks = $tempLocks['object_locks'];
466
+
467
+ foreach ($tempLocks as $lock) {
468
+
469
+ switch ($lock->getTag()) {
470
+
471
+ case 'list_action':
472
+ $html .= '<br/><span style="color: #605fff">[Listing...]</span>';
473
+ break;
474
+
475
+ case 'relist_action':
476
+ $html .= '<br/><span style="color: #605fff">[Relisting...]</span>';
477
+ break;
478
+
479
+ case 'revise_action':
480
+ $html .= '<br/><span style="color: #605fff">[Revising...]</span>';
481
+ break;
482
+
483
+ case 'stop_action':
484
+ $html .= '<br/><span style="color: #605fff">[Stoping...]</span>';
485
+ break;
486
+
487
+ case 'delete_and_remove_action':
488
+ $html .= '<br/><span style="color: #605fff">[Removing...]</span>';
489
+ break;
490
+
491
+ default:
492
+ break;
493
+
494
+ }
495
+ }
496
+
497
+ return $html;
498
+ }
499
+
500
+ public function callbackProductOptions($collection, $column)
501
+ {
502
+ $values = $column->getFilter()->getValue();
503
+
504
+ if ($values == null && !is_array($values)) {
505
+ return;
506
+ }
507
+
508
+ foreach ($values as $value) {
509
+ if(is_array($value) && isset($value['value'])) {
510
+ $collection->addFieldToFilter(
511
+ 'additional_data',
512
+ array('regexp'=> '"variation_product_options":[^}]*'.$value['attr'].'":"' .
513
+ // trying to screen slashes that in json
514
+ addslashes(addslashes($value['value'])))
515
+ );
516
+ }
517
+ }
518
+ }
519
+
520
+ public function callbackChannelOptions($collection, $column)
521
+ {
522
+ $values = $column->getFilter()->getValue();
523
+
524
+ if ($values == null && !is_array($values)) {
525
+ return;
526
+ }
527
+
528
+ foreach ($values as $value) {
529
+ if(is_array($value) && isset($value['value'])) {
530
+ $collection->addFieldToFilter(
531
+ 'additional_data',
532
+ array('regexp'=> '"variation_channel_options":[^}]*'.$value['attr'].'":"' .
533
+ // trying to screen slashes that in json
534
+ addslashes(addslashes($value['value'])))
535
+ );
536
+ }
537
+ }
538
+ }
539
+
540
+ // ####################################
541
+
542
+ /**
543
+ * @param Ess_M2ePro_Model_Listing_Product $listingProduct
544
+ * @return string
545
+ */
546
+ public function getViewLogIconHtml($listingProduct)
547
+ {
548
+ $listingProductId = (int)$listingProduct->getId();
549
+
550
+ // Get last messages
551
+ //--------------------------
552
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
553
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
554
+
555
+ $dbSelect = $connRead->select()
556
+ ->from(
557
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
558
+ array('action_id','action','type','description','create_date','initiator')
559
+ )
560
+ ->where('`listing_product_id` = ?', $listingProductId)
561
+ ->where('`action_id` IS NOT NULL')
562
+ ->order(array('id DESC'))
563
+ ->limit(30);
564
+
565
+ $logRows = $connRead->fetchAll($dbSelect);
566
+ //--------------------------
567
+
568
+ // Get grouped messages by action_id
569
+ //--------------------------
570
+ $actionsRows = array();
571
+ $tempActionRows = array();
572
+ $lastActionId = false;
573
+
574
+ foreach ($logRows as $row) {
575
+
576
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
577
+
578
+ if ($row['action_id'] !== $lastActionId) {
579
+ if (count($tempActionRows) > 0) {
580
+ $actionsRows[] = array(
581
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
582
+ 'date' => $this->getMainDateForActionId($tempActionRows),
583
+ 'action' => $this->getActionForAction($tempActionRows[0]),
584
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
585
+ 'items' => $tempActionRows
586
+ );
587
+ $tempActionRows = array();
588
+ }
589
+ $lastActionId = $row['action_id'];
590
+ }
591
+ $tempActionRows[] = $row;
592
+ }
593
+
594
+ if (count($tempActionRows) > 0) {
595
+ $actionsRows[] = array(
596
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
597
+ 'date' => $this->getMainDateForActionId($tempActionRows),
598
+ 'action' => $this->getActionForAction($tempActionRows[0]),
599
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
600
+ 'items' => $tempActionRows
601
+ );
602
+ }
603
+
604
+ if (count($actionsRows) <= 0) {
605
+ return '';
606
+ }
607
+
608
+ $tips = array(
609
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last action was completed successfully.',
610
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last action was completed with error(s).',
611
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last action was completed with warning(s).'
612
+ );
613
+
614
+ $icons = array(
615
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
616
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
617
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
618
+ );
619
+
620
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
621
+ 'entity_id' => (int)$listingProduct->getId(),
622
+ 'rows' => $actionsRows,
623
+ 'tips' => $tips,
624
+ 'icons' => $icons,
625
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
626
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
627
+ ));
628
+
629
+ return $summary->toHtml();
630
+ }
631
+
632
+ public function getActionForAction($actionRows)
633
+ {
634
+ $string = '';
635
+
636
+ switch ($actionRows['action']) {
637
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
638
+ $string = Mage::helper('M2ePro')->__('List');
639
+ break;
640
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
641
+ $string = Mage::helper('M2ePro')->__('Relist');
642
+ break;
643
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
644
+ $string = Mage::helper('M2ePro')->__('Revise');
645
+ break;
646
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
647
+ $string = Mage::helper('M2ePro')->__('Stop');
648
+ break;
649
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
650
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
651
+ break;
652
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
653
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
654
+ break;
655
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
656
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
657
+ break;
658
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANGE_STATUS_ON_CHANNEL:
659
+ $string = Mage::helper('M2ePro')->__('Status Change');
660
+ break;
661
+ }
662
+
663
+ return $string;
664
+ }
665
+
666
+ public function getInitiatorForAction($actionRows)
667
+ {
668
+ $string = '';
669
+
670
+ switch ((int)$actionRows['initiator']) {
671
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
672
+ $string = '';
673
+ break;
674
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
675
+ $string = Mage::helper('M2ePro')->__('Manual');
676
+ break;
677
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
678
+ $string = Mage::helper('M2ePro')->__('Automatic');
679
+ break;
680
+ }
681
+
682
+ return $string;
683
+ }
684
+
685
+ public function getMainTypeForActionId($actionRows)
686
+ {
687
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
688
+
689
+ foreach ($actionRows as $row) {
690
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
691
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
692
+ break;
693
+ }
694
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
695
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
696
+ }
697
+ }
698
+
699
+ return $type;
700
+ }
701
+
702
+ public function getMainDateForActionId($actionRows)
703
+ {
704
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
705
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
706
+ }
707
+
708
+ // ####################################
709
+
710
+ public function getMainButtonsHtml()
711
+ {
712
+ $html = '';
713
+ if($this->getFilterVisibility()){
714
+ $html.= $this->getAddNewChildButtonsHtml();
715
+ $html.= $this->getResetFilterButtonHtml();
716
+ $html.= $this->getSearchButtonHtml();
717
+ }
718
+ return $html;
719
+ }
720
+
721
+ public function getMassactionBlockHtml()
722
+ {
723
+ if ($this->isNewChildAllowed()) {
724
+ $blockName = 'adminhtml_common_amazon_listing_variation_product_manage_tabs_variations_child_form';
725
+ $form = $this->getLayout()->createBlock('M2ePro/'.$blockName);
726
+ $form->setListingProductId($this->getListingProductId());
727
+
728
+ return $form->toHtml() . parent::getMassactionBlockHtml();
729
+ }
730
+
731
+ return parent::getMassactionBlockHtml();
732
+ }
733
+
734
+ private function getAddNewChildButtonsHtml()
735
+ {
736
+ if ($this->isNewChildAllowed()) {
737
+
738
+ //------------------------------
739
+ $data = array(
740
+ 'label' => Mage::helper('adminhtml')->__('Add New Child Product'),
741
+ 'onclick' => 'ListingGridHandlerObj.showNewChildForm('. !$this->hasUnusedChannelVariations() .')',
742
+ 'class' => 'task',
743
+ 'id' => 'add_new_child_button'
744
+ );
745
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
746
+ $this->setChild('add_new_child_button', $buttonBlock);
747
+ //------------------------------
748
+
749
+ }
750
+
751
+ return $this->getChildHtml('add_new_child_button');
752
+ }
753
+
754
+ protected function isNewChildAllowed()
755
+ {
756
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
757
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
758
+
759
+ if (!$amazonListingProduct->getGeneralId()) {
760
+ return false;
761
+ }
762
+
763
+ if (!$amazonListingProduct->getVariationManager()->getTypeModel()->hasMatchedAttributes()) {
764
+ return false;
765
+ }
766
+
767
+ if (!$this->hasUnusedProductVariation()) {
768
+ return false;
769
+ }
770
+
771
+ if ($this->hasChildWithEmptyProductOptions()) {
772
+ return false;
773
+ }
774
+
775
+ if (!$this->isGeneralIdOwner() && !$this->hasUnusedChannelVariations()) {
776
+ return false;
777
+ }
778
+
779
+ if (!$this->isGeneralIdOwner() && $this->hasChildWithEmptyChannelOptions()) {
780
+ return false;
781
+ }
782
+
783
+ return true;
784
+ }
785
+
786
+ public function isGeneralIdOwner()
787
+ {
788
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
789
+ }
790
+
791
+ public function getCurrentChannelVariations()
792
+ {
793
+ return $this->getListingProduct()->getChildObject()
794
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
795
+ }
796
+
797
+ public function hasUnusedProductVariation()
798
+ {
799
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
800
+ }
801
+
802
+ public function hasUnusedChannelVariations()
803
+ {
804
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
805
+ }
806
+
807
+ public function hasChildWithEmptyProductOptions()
808
+ {
809
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
810
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
811
+
812
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
813
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
814
+
815
+ if (!$childTypeModel->isVariationProductMatched()) {
816
+ return true;
817
+ }
818
+ }
819
+
820
+ return false;
821
+ }
822
+
823
+ public function hasChildWithEmptyChannelOptions()
824
+ {
825
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
826
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
827
+
828
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
829
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
830
+
831
+ if (!$childTypeModel->isVariationChannelMatched()) {
832
+ return true;
833
+ }
834
+ }
835
+
836
+ return false;
837
+ }
838
+
839
+ public function getUsedChannelVariations()
840
+ {
841
+ $usedOptions = array();
842
+
843
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
844
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
845
+
846
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
847
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
848
+
849
+ if (!$childTypeModel->isVariationChannelMatched()) {
850
+ continue;
851
+ }
852
+
853
+ $usedOptions[] = $childTypeModel->getChannelOptions();
854
+ }
855
+
856
+ return $usedOptions;
857
+ }
858
+
859
+ // ------------------------------------
860
+
861
+ public function getGridUrl()
862
+ {
863
+ return $this->getUrl('*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsGridAjax', array(
864
+ '_current' => true
865
+ ));
866
+ }
867
+
868
+ public function getRowUrl($row)
869
+ {
870
+ return false;
871
+ }
872
+
873
+ // ####################################
874
+
875
+ protected function _toHtml()
876
+ {
877
+ $listingId = $this->getListingProduct()->getListingId();
878
+
879
+ /** @var $helper Ess_M2ePro_Helper_Data */
880
+ $helper = Mage::helper('M2ePro');
881
+
882
+ //------------------------------
883
+ $urls = array();
884
+
885
+ $path = 'adminhtml_common_log/listingProduct';
886
+ $urls[$path] = $this->getUrl('*/' . $path, array(
887
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
888
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array('id' => $listingId))
889
+ ));
890
+
891
+ $urls['adminhtml_common_amazon_listing_variation_product_manage/createNewChild'] = $this->getUrl(
892
+ '*/adminhtml_common_amazon_listing_variation_product_manage/createNewChild');
893
+
894
+ $urls = json_encode($urls);
895
+ //------------------------------
896
+
897
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
898
+
899
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing', array(
900
+ 'id' =>$listingId,
901
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_AMAZON,
902
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array('id' => $listingId))
903
+ ));
904
+
905
+ $checkLockListing = $this->getUrl('*/adminhtml_listing/checkLockListing', array('component' => $component));
906
+ $lockListingNow = $this->getUrl('*/adminhtml_listing/lockListingNow', array('component' => $component));
907
+ $unlockListingNow = $this->getUrl('*/adminhtml_listing/unlockListingNow', array('component' => $component));
908
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
909
+
910
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
911
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
912
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
913
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
914
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
915
+
916
+ $setChildListingProductOptions = $this->getUrl(
917
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setChildListingProductOptions');
918
+
919
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
920
+ $taskCompletedSuccessMessage = $helper->escapeJs(
921
+ $helper->__('"%task_title%" task has successfully submitted to be processed.')
922
+ );
923
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
924
+ '"%task_title%" task has completed with warnings.
925
+ <a target="_blank" href="%url%">View log</a> for details.'
926
+ ));
927
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
928
+ '"%task_title%" task has completed with errors. <a target="_blank" href="%url%">View log</a> for details.'
929
+ ));
930
+
931
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
932
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
933
+ 'Sending %product_title% Product(s) data on Amazon.'
934
+ ));
935
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
936
+
937
+ $listingLockedMessage = $helper->escapeJs(
938
+ $helper->__('The listing was locked by another process. Please try again later.')
939
+ );
940
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
941
+
942
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
943
+ ->__('Listing All Items On Amazon'));
944
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
945
+ ->__('Listing Selected Items On Amazon'));
946
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
947
+ ->__('Revising Selected Items On Amazon'));
948
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
949
+ ->__('Relisting Selected Items On Amazon'));
950
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
951
+ ->__('Stopping Selected Items On Amazon'));
952
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
953
+ ->escapeJs(Mage::helper('M2ePro')
954
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
955
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
956
+ ->escapeJs(Mage::helper('M2ePro')
957
+ ->__('Reset / Remove Item(s)'));
958
+
959
+ $selectItemsMessage = $helper->escapeJs($helper->__('Please select Items.'));
960
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select action.'));
961
+
962
+ $errorChangingProductOptions = $helper->escapeJs($helper->__('Please Select Product Options.'));
963
+
964
+ $successWord = $helper->escapeJs($helper->__('Success'));
965
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
966
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
967
+ $errorWord = $helper->escapeJs($helper->__('Error'));
968
+ $closeWord = $helper->escapeJs($helper->__('Close'));
969
+ $confirmWord = $helper->escapeJs($helper->__('Confirm'));
970
+ $cancelWord = $helper->escapeJs($helper->__('Cancel'));
971
+
972
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
973
+
974
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
975
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
976
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
977
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
978
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
979
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy for Products'));
980
+
981
+ $generalId = $this->getListingProduct()->getGeneralId();
982
+ $hideMassAction = empty($generalId) ?
983
+ '$(\'amazonVariationProductManageGrid_massaction-form\').hide();' : '';
984
+
985
+ $javascriptMain = <<<JAVASCRIPT
986
+ <script type="text/javascript">
987
+
988
+ if (typeof M2ePro == 'undefined') {
989
+ M2ePro = {};
990
+ M2ePro.url = {};
991
+ M2ePro.formData = {};
992
+ M2ePro.customData = {};
993
+ M2ePro.text = {};
994
+ }
995
+
996
+ M2ePro.url.add({$urls});
997
+
998
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
999
+
1000
+ M2ePro.url.checkLockListing = '{$checkLockListing}';
1001
+ M2ePro.url.lockListingNow = '{$lockListingNow}';
1002
+ M2ePro.url.unlockListingNow = '{$unlockListingNow}';
1003
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
1004
+
1005
+ M2ePro.url.runListProducts = '{$runListProducts}';
1006
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
1007
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
1008
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
1009
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
1010
+ M2ePro.url.setChildListingProductOptions = '{$setChildListingProductOptions}';
1011
+
1012
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
1013
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
1014
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
1015
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
1016
+
1017
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
1018
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
1019
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
1020
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
1021
+
1022
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
1023
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
1024
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
1025
+
1026
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
1027
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
1028
+
1029
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
1030
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
1031
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
1032
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
1033
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
1034
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
1035
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
1036
+
1037
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
1038
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
1039
+
1040
+ M2ePro.text.error_changing_product_options = '{$errorChangingProductOptions}';
1041
+
1042
+ M2ePro.text.success_word = '{$successWord}';
1043
+ M2ePro.text.notice_word = '{$noticeWord}';
1044
+ M2ePro.text.warning_word = '{$warningWord}';
1045
+ M2ePro.text.error_word = '{$errorWord}';
1046
+ M2ePro.text.close_word = '{$closeWord}';
1047
+ M2ePro.text.confirm_word = '{$confirmWord}';
1048
+ M2ePro.text.cancel_word = '{$cancelWord}';
1049
+
1050
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
1051
+
1052
+ M2ePro.text.confirm = '{$textConfirm}';
1053
+
1054
+ M2ePro.customData.componentMode = '{$component}';
1055
+ M2ePro.customData.gridId = 'amazonVariationProductManageGrid';
1056
+
1057
+ Event.observe(window, 'load', function() {
1058
+
1059
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
1060
+
1061
+ ListingGridHandlerObj = new AmazonListingVariationProductManageVariationsGridHandler(
1062
+ 'amazonVariationProductManageGrid',
1063
+ {$listingId}
1064
+ );
1065
+
1066
+ // todo next (temp solution)
1067
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
1068
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
1069
+
1070
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
1071
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
1072
+
1073
+ setTimeout(function() {
1074
+ ListingGridHandlerObj.afterInitPage();
1075
+ }, 350);
1076
+ });
1077
+
1078
+ if (typeof ListingGridHandlerObj != 'undefined') {
1079
+ ListingGridHandlerObj.afterInitPage();
1080
+ }
1081
+
1082
+ {$hideMassAction}
1083
+
1084
+ </script>
1085
+ JAVASCRIPT;
1086
+
1087
+ $additionalCss = <<<CSS
1088
+ <style>
1089
+ body {
1090
+ background: none;
1091
+ }
1092
+
1093
+ .wrapper {
1094
+ min-width: inherit;
1095
+ }
1096
+
1097
+ .footer {
1098
+ display: none;
1099
+ }
1100
+
1101
+ .middle {
1102
+ padding: 0px;
1103
+ background: none;
1104
+ }
1105
+
1106
+ td.help_line .hl_close {
1107
+ margin-top: -6px;
1108
+ }
1109
+
1110
+ td.help_line .hl_header {
1111
+ padding: 0 0 10px !important;
1112
+ }
1113
+
1114
+ </style>
1115
+ CSS;
1116
+
1117
+ return '<div id="messages"></div>' .
1118
+ '<div id="listing_view_progress_bar"></div>' .
1119
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
1120
+ '<div id="listing_view_content_container">'.
1121
+ parent::_toHtml() .
1122
+ '</div>' . $javascriptMain . $additionalCss;
1123
+ }
1124
+
1125
+ // ####################################
1126
+
1127
+ private function getLockedData($row)
1128
+ {
1129
+ $listingProductId = $row->getData('id');
1130
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1131
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
1132
+ $tempArray = array(
1133
+ 'object_locks' => $objectLocks,
1134
+ 'in_action' => !empty($objectLocks),
1135
+ );
1136
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1137
+ }
1138
+
1139
+ return $this->lockedDataCache[$listingProductId];
1140
+ }
1141
+
1142
+ // ####################################
1143
+
1144
+ protected function getTemplateDescriptionLinkHtml($listingProduct)
1145
+ {
1146
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
1147
+ 'id' => $listingProduct->getChildObject()->getTemplateDescriptionId()
1148
+ ));
1149
+
1150
+ $helper = Mage::helper('M2ePro');
1151
+ $templateTitle = $listingProduct->getChildObject()->getDescriptionTemplate()->getTitle();
1152
+
1153
+ return <<<HTML
1154
+ <span style="font-size: 9px;">{$helper->__('Description Title')}:&nbsp;
1155
+ <a target="_blank" href="{$templateDescriptionEditUrl}">
1156
+ {$helper->escapeHtml($templateTitle)}</a>
1157
+ </span>
1158
+ <br/>
1159
+ HTML;
1160
+ }
1161
+
1162
+ // ####################################
1163
+
1164
+ public function getProductVariationsTree($childProduct)
1165
+ {
1166
+ $unusedVariations = $this->getUnusedProductVariations();
1167
+
1168
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1169
+ $childTypeModel = $childProduct->getChildObject()->getVariationManager()->getTypeModel();
1170
+
1171
+ if ($childTypeModel->isVariationProductMatched()) {
1172
+ $unusedVariations[] = $childTypeModel->getProductOptions();
1173
+ }
1174
+
1175
+ $variationsSets = $this->getAttributesVariationsSets($unusedVariations);
1176
+ $firstAttribute = key($variationsSets);
1177
+
1178
+ return $this->prepareVariations($firstAttribute,$unusedVariations,$variationsSets);
1179
+ }
1180
+
1181
+ private function prepareVariations($currentAttribute,$unusedVariations,$variationsSets,$filters = array())
1182
+ {
1183
+ $return = false;
1184
+
1185
+ $temp = array_flip(array_keys($variationsSets));
1186
+
1187
+ $lastAttributePosition = count($variationsSets) - 1;
1188
+ $currentAttributePosition = $temp[$currentAttribute];
1189
+
1190
+ if ($currentAttributePosition != $lastAttributePosition) {
1191
+
1192
+ $temp = array_keys($variationsSets);
1193
+ $nextAttribute = $temp[$currentAttributePosition + 1];
1194
+
1195
+ foreach ($variationsSets[$currentAttribute] as $option) {
1196
+
1197
+ $filters[$currentAttribute] = $option;
1198
+
1199
+ $result = $this->prepareVariations(
1200
+ $nextAttribute,$unusedVariations,$variationsSets,$filters
1201
+ );
1202
+
1203
+ if (!$result) {
1204
+ continue;
1205
+ }
1206
+
1207
+ $return[$currentAttribute][$option] = $result;
1208
+ }
1209
+
1210
+ ksort($return[$currentAttribute]);
1211
+
1212
+ return $return;
1213
+ }
1214
+
1215
+ $return = false;
1216
+ foreach ($unusedVariations as $key => $magentoVariation) {
1217
+ foreach ($magentoVariation as $attribute => $option) {
1218
+
1219
+ if ($attribute == $currentAttribute) {
1220
+
1221
+ if (count($variationsSets) != 1) {
1222
+ continue;
1223
+ }
1224
+
1225
+ $values = array_flip($variationsSets[$currentAttribute]);
1226
+ $return = array($currentAttribute => $values);
1227
+
1228
+ foreach ($return[$currentAttribute] as &$option) {
1229
+ $option = true;
1230
+ }
1231
+
1232
+ return $return;
1233
+ }
1234
+
1235
+ if ($option != $filters[$attribute]) {
1236
+ unset($unusedVariations[$key]);
1237
+ continue;
1238
+ }
1239
+
1240
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
1241
+ if ($tempAttribute == $currentAttribute) {
1242
+ $option = $tempOption;
1243
+ $return[$currentAttribute][$option] = true;
1244
+ }
1245
+ }
1246
+ }
1247
+ }
1248
+
1249
+ if (count($unusedVariations) < 1) {
1250
+ return false;
1251
+ }
1252
+
1253
+ ksort($return[$currentAttribute]);
1254
+
1255
+ return $return;
1256
+ }
1257
+
1258
+ // ####################################
1259
+
1260
+ public function getCurrentProductVariations()
1261
+ {
1262
+
1263
+ if (!is_null($this->currentProductVariations)) {
1264
+ return $this->currentProductVariations;
1265
+ }
1266
+
1267
+ $magentoProductVariations = $this->getListingProduct()
1268
+ ->getMagentoProduct()
1269
+ ->getVariationInstance()
1270
+ ->getVariationsTypeStandard();
1271
+
1272
+ $productVariations = array();
1273
+
1274
+ foreach ($magentoProductVariations['variations'] as $option) {
1275
+ $productOption = array();
1276
+
1277
+ foreach ($option as $attribute) {
1278
+ $productOption[$attribute['attribute']] = $attribute['option'];
1279
+ }
1280
+
1281
+ $productVariations[] = $productOption;
1282
+ }
1283
+
1284
+ return $this->currentProductVariations = $productVariations;
1285
+ }
1286
+
1287
+ public function getUsedProductVariations()
1288
+ {
1289
+ if (is_null($this->usedProductVariations)) {
1290
+
1291
+ $usedOptions = array();
1292
+
1293
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1294
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1295
+
1296
+ /**
1297
+ * @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel
1298
+ */
1299
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1300
+
1301
+ if (!$childTypeModel->isVariationProductMatched()) {
1302
+ continue;
1303
+ }
1304
+
1305
+ $usedOptions[] = $childTypeModel->getProductOptions();
1306
+ }
1307
+
1308
+ $this->usedProductVariations = $usedOptions;
1309
+ }
1310
+
1311
+ return $this->usedProductVariations;
1312
+ }
1313
+
1314
+ // ####################################
1315
+
1316
+ public function getUnusedProductVariations()
1317
+ {
1318
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
1319
+ }
1320
+
1321
+ private function getUnusedVariations($currentVariations, $usedVariations)
1322
+ {
1323
+ if (empty($currentVariations)) {
1324
+ return array();
1325
+ }
1326
+
1327
+ if (empty($usedVariations)) {
1328
+ return $currentVariations;
1329
+ }
1330
+
1331
+ $unusedOptions = array();
1332
+
1333
+ foreach ($currentVariations as $id => $currentOption) {
1334
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
1335
+ continue;
1336
+ }
1337
+
1338
+ $unusedOptions[$id] = $currentOption;
1339
+ }
1340
+
1341
+ return $unusedOptions;
1342
+ }
1343
+
1344
+ private function isVariationExistsInArray(array $needle, array $haystack)
1345
+ {
1346
+ foreach ($haystack as $option) {
1347
+ if ($option != $needle) {
1348
+ continue;
1349
+ }
1350
+
1351
+ return true;
1352
+ }
1353
+
1354
+ return false;
1355
+ }
1356
+
1357
+ // ####################################
1358
+
1359
+ public function getChildListingProducts()
1360
+ {
1361
+ if (!is_null($this->childListingProducts)) {
1362
+ return $this->childListingProducts;
1363
+ }
1364
+
1365
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
1366
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
1367
+ }
1368
+
1369
+ public function getAttributesVariationsSets($variations)
1370
+ {
1371
+ $attributesOptions = array();
1372
+
1373
+ foreach ($variations as $variation) {
1374
+ foreach ($variation as $attr => $option) {
1375
+ if (!isset($attributesOptions[$attr])) {
1376
+ $attributesOptions[$attr] = array();
1377
+ }
1378
+ if (!in_array($option, $attributesOptions[$attr])) {
1379
+ $attributesOptions[$attr][] = $option;
1380
+ }
1381
+ }
1382
+ }
1383
+
1384
+ ksort($attributesOptions);
1385
+
1386
+ return $attributesOptions;
1387
+ }
1388
+
1389
+ // ####################################
1390
+
1391
+ protected function getGeneralIdLink($generalId)
1392
+ {
1393
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1394
+ $generalId,
1395
+ $this->getListingProduct()->getListing()->getMarketplaceId()
1396
+ );
1397
+
1398
+ return <<<HTML
1399
+ <a href="{$url}" target="_blank" title="{$generalId}" >{$generalId}</a>
1400
+ HTML;
1401
+ }
1402
+
1403
+ // ####################################
1404
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Help.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations_Help
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonListingViewHelp');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations/help.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToIndividualPopup.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_SwitchToIndividualPopup
8
+ extends Mage_Adminhtml_Block_Template
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingAddNewAsinManualPopup');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/switch_to_individual_popup.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ parent::_beforeToHtml();
26
+
27
+ $data = array(
28
+ 'class' => 'switch-to-individual-btn',
29
+ 'label' => Mage::helper('M2ePro')->__('Yes')
30
+ );
31
+ $this->setChild(
32
+ 'yes_btn',
33
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
34
+ );
35
+
36
+ $data = array(
37
+ 'class' => 'switch-to-individual-popup-close',
38
+ 'label' => Mage::helper('M2ePro')->__('No')
39
+ );
40
+ $this->setChild(
41
+ 'no_btn',
42
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
43
+ );
44
+
45
+ return $this;
46
+ }
47
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToParentPopup.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_SwitchToParentPopup
8
+ extends Mage_Adminhtml_Block_Template
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingAddNewAsinManualPopup');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/switch_to_parent_popup.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ parent::_beforeToHtml();
26
+
27
+ $data = array(
28
+ 'class' => 'switch-to-parent-btn',
29
+ 'label' => Mage::helper('M2ePro')->__('Yes')
30
+ );
31
+ $this->setChild(
32
+ 'yes_btn',
33
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
34
+ );
35
+
36
+ $data = array(
37
+ 'class' => 'switch-to-parent-popup-close',
38
+ 'label' => Mage::helper('M2ePro')->__('No')
39
+ );
40
+ $this->setChild(
41
+ 'no_btn',
42
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
43
+ );
44
+
45
+ return $this;
46
+ }
47
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View.php ADDED
@@ -0,0 +1,744 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ const VIEW_MODE_AMAZON = 'amazon';
10
+ const VIEW_MODE_MAGENTO = 'magento';
11
+ const VIEW_MODE_SELLERCENTRAL = 'sellercentral';
12
+
13
+ const DEFAULT_VIEW_MODE = self::VIEW_MODE_AMAZON;
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ //------------------------------
21
+ $this->setId('amazonListingView');
22
+ $this->_blockGroup = 'M2ePro';
23
+ $this->_controller = 'adminhtml_common_amazon_listing_view_' . $this->getViewMode();
24
+ //------------------------------
25
+
26
+ // Set header text
27
+ //------------------------------
28
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
29
+
30
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
31
+ $headerText = Mage::helper('M2ePro')->__(
32
+ 'View %component_name% Listing',
33
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()
34
+ );
35
+ } else {
36
+ $headerText = Mage::helper('M2ePro')->__('View Listing ');
37
+ }
38
+
39
+ $this->_headerText = $headerText;
40
+ //------------------------------
41
+
42
+ // Set buttons actions
43
+ //------------------------------
44
+ $this->removeButton('back');
45
+ $this->removeButton('reset');
46
+ $this->removeButton('delete');
47
+ $this->removeButton('add');
48
+ $this->removeButton('save');
49
+ $this->removeButton('edit');
50
+ //------------------------------
51
+
52
+ //------------------------------
53
+ $url = $this->getUrl('*/adminhtml_common_log/listing', array(
54
+ 'id' => $listingData['id'],
55
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_AMAZON
56
+ ));
57
+ $this->_addButton('view_log', array(
58
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
59
+ 'onclick' => 'window.open(\'' . $url . '\')',
60
+ 'class' => 'button_link'
61
+ ));
62
+ //------------------------------
63
+
64
+ //------------------------------
65
+ $this->_addButton('edit_settings', array(
66
+ 'label' => Mage::helper('M2ePro')->__('Edit Settings'),
67
+ 'onclick' => '',
68
+ 'class' => 'drop_down edit_settings_drop_down'
69
+ ));
70
+ //------------------------------
71
+
72
+ //------------------------------
73
+ $this->_addButton('add_products', array(
74
+ 'label' => Mage::helper('M2ePro')->__('Add Products'),
75
+ 'onclick' => '',
76
+ 'class' => 'add drop_down add_products_drop_down'
77
+ ));
78
+ //------------------------------
79
+ }
80
+
81
+ // ####################################
82
+
83
+ public function getViewMode()
84
+ {
85
+ $allowedModes = array(self::VIEW_MODE_AMAZON, self::VIEW_MODE_MAGENTO, self::VIEW_MODE_SELLERCENTRAL);
86
+ $mode = $this->getParam('view_mode', self::DEFAULT_VIEW_MODE);
87
+
88
+ if (in_array($mode, $allowedModes)) {
89
+ return $mode;
90
+ }
91
+
92
+ return self::DEFAULT_VIEW_MODE;
93
+ }
94
+
95
+ protected function getParam($paramName, $default = NULL)
96
+ {
97
+ $session = Mage::helper('M2ePro/Data_Session');
98
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
99
+ $sessionParamName = $this->getId() . $listingData['id'] . $paramName;
100
+
101
+ if ($this->getRequest()->has($paramName)) {
102
+ $param = $this->getRequest()->getParam($paramName);
103
+ $session->setValue($sessionParamName, $param);
104
+ return $param;
105
+ } elseif ($param = $session->getValue($sessionParamName)) {
106
+ return $param;
107
+ }
108
+
109
+ return $default;
110
+ }
111
+
112
+ // ####################################
113
+
114
+ protected function _toHtml()
115
+ {
116
+ return '<div id="listing_view_progress_bar"></div>' .
117
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
118
+ '<div id="listing_view_content_container">'.
119
+ parent::_toHtml() .
120
+ '</div>';
121
+ }
122
+
123
+ public function getGridHtml()
124
+ {
125
+ if ($this->getRequest()->isXmlHttpRequest()) {
126
+ return parent::getGridHtml();
127
+ }
128
+
129
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
130
+
131
+ /** @var $helper Ess_M2ePro_Helper_Data */
132
+ $helper = Mage::helper('M2ePro');
133
+
134
+ //------------------------------
135
+ $urls = $helper->getControllerActions(
136
+ 'adminhtml_common_listing_autoAction', array(
137
+ 'listing_id' => $this->getRequest()->getParam('id'),
138
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
139
+ )
140
+ );
141
+ $showAutoAction = json_encode((bool)$this->getRequest()->getParam('auto_actions'));
142
+
143
+ $path = 'adminhtml_common_log/listingProduct';
144
+ $urls[$path] = $this->getUrl('*/' . $path, array(
145
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
146
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array(
147
+ 'id' => $listingData['id']
148
+ ))
149
+ ));
150
+
151
+ $path = 'adminhtml_common_listing/duplicateProducts';
152
+ $urls[$path] = $this->getUrl('*/' . $path);
153
+
154
+ $urls = json_encode($urls);
155
+ //------------------------------
156
+
157
+ // todo next (change)
158
+
159
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
160
+
161
+ $temp = Mage::helper('M2ePro/Data_Session')->getValue('products_ids_for_list', true);
162
+ $productsIdsForList = empty($temp) ? '' : $temp;
163
+
164
+ $gridId = $this->getChild('grid')->getId();
165
+ $ignoreListings = json_encode(array($listingData['id']));
166
+
167
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
168
+ $marketplaceInstance = Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Marketplace',$marketplaceId);
169
+ $marketplace = json_encode($marketplaceInstance->getData());
170
+ $isNewAsinAvailable = json_encode($marketplaceInstance->getChildObject()->isNewAsinAvailable());
171
+ $isMarketplaceSynchronized = json_encode($marketplaceInstance->getChildObject()->isSynchronized());
172
+
173
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing',array(
174
+ 'id' => $listingData['id'],
175
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_AMAZON,
176
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',
177
+ array('id' =>$listingData['id']))
178
+ ));
179
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
180
+
181
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
182
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
183
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
184
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
185
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopAndRemoveProducts');
186
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
187
+
188
+ $prepareData = $this->getUrl('*/adminhtml_listing_moving/prepareMoveToListing');
189
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_moving/moveToListingGrid');
190
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_moving/getFailedProductsGrid');
191
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_moving/tryToMoveToListing');
192
+ $moveToListing = $this->getUrl('*/adminhtml_listing_moving/moveToListing');
193
+
194
+ $marketplaceSynchUrl = $this->getUrl(
195
+ '*/adminhtml_common_marketplace/index',
196
+ array('tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON)
197
+ );
198
+
199
+ $getVariationEditPopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationEditPopup');
200
+ $getVariationManagePopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationManagePopup');
201
+
202
+ $variationEditActionUrl = $this->getUrl('*/adminhtml_common_listing/variationEdit');
203
+ $variationManageActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManage');
204
+ $variationManageGenerateActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManageGenerate');
205
+ $variationResetActionUrl = $this->getUrl('*/adminhtml_common_listing/variationReset');
206
+
207
+ $saveListingAdditionalDataActionUrl = $this->getUrl('*/adminhtml_listing/saveListingAdditionalData', array(
208
+ 'id' => $listingData['id']
209
+ ));
210
+
211
+ $popupTitle = $helper->escapeJs($helper->__('Moving Amazon Items'));
212
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Amazon Item'));
213
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
214
+
215
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
216
+ $taskCompletedSuccessMessage = $helper->escapeJs(
217
+ $helper->__('"%task_title%" task has successfully submitted to be processed.')
218
+ );
219
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
220
+ '"%task_title%" task has completed with warnings. <a target="_blank" href="%url%">View log</a> for details.'
221
+ ));
222
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
223
+ '"%task_title%" task has completed with errors. <a target="_blank" href="%url%">View log</a> for details.'
224
+ ));
225
+
226
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
227
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
228
+ 'Sending %product_title% Product(s) data on Amazon.')
229
+ );
230
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
231
+
232
+ $listingLockedMessage = $helper->escapeJs(
233
+ $helper->__('The Listing was locked by another process. Please try again later.')
234
+ );
235
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
236
+
237
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
238
+ ->__('Listing All Items On Amazon'));
239
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
240
+ ->__('Listing Selected Items On Amazon'));
241
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
242
+ ->__('Revising Selected Items On Amazon'));
243
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
244
+ ->__('Relisting Selected Items On Amazon'));
245
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
246
+ ->__('Stopping Selected Items On Amazon'));
247
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
248
+ ->escapeJs(Mage::helper('M2ePro')
249
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
250
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
251
+ ->escapeJs(Mage::helper('M2ePro')
252
+ ->__('Removing From Amazon And Listing Selected Items'));
253
+
254
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully moved.'));
255
+ $productsWereNotMovedMessage = $helper->escapeJs(
256
+ $helper->__('Product(s) was not moved. <a target="_blank" href="%url%">View log</a> for details.')
257
+ );
258
+ $someProductsWereNotMovedMessage = $helper->escapeJs(
259
+ $helper->__('Some Product(s) was not moved. <a target="_blank" href="%url%">View log</a> for details.')
260
+ );
261
+
262
+ $selectItemsMessage = $helper->escapeJs(
263
+ $helper->__('Please select the Products you want to perform the action on.')
264
+ );
265
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select action.'));
266
+
267
+ $successWord = $helper->escapeJs($helper->__('Success'));
268
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
269
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
270
+ $errorWord = $helper->escapeJs($helper->__('Error'));
271
+ $closeWord = $helper->escapeJs($helper->__('Close'));
272
+
273
+ $assignString = Mage::helper('M2ePro')->__('Assign');
274
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
275
+
276
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
277
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
278
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
279
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
280
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
281
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
282
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
283
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
284
+
285
+ $variationProductManage = $this->getUrl(
286
+ '*/adminhtml_common_amazon_listing_variation_product_manage/index');
287
+ $variationProductSetGeneralIdOwner = $this->getUrl(
288
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setGeneralIdOwner');
289
+ $variationProductSetVariationTheme = $this->getUrl(
290
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setVariationTheme');
291
+ $variationProductSetMatchedAttributes = $this->getUrl(
292
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setMatchedAttributes');
293
+ $variationProductSetListingProductSku = $this->getUrl(
294
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setListingProductSku');
295
+ $manageVariationViewTemplateDescriptionsGrid = $this->getUrl(
296
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewTemplateDescriptionsGrid');
297
+ $manageVariationMapToTemplateDescription = $this->getUrl(
298
+ '*/adminhtml_common_amazon_listing_variation_product_manage/mapToTemplateDescription');
299
+
300
+ $viewVariationsSettingsAjax = $this->getUrl(
301
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsSettingsAjax');
302
+
303
+ $newAsinUrl = $this->getUrl('*/adminhtml_common_amazon_template_newProduct',array(
304
+ 'marketplace_id' => Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'),
305
+ ));
306
+
307
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
308
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
309
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
310
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
311
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
312
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
313
+
314
+ $enterProductSearchQueryMessage = $helper->escapeJs(
315
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
316
+ );
317
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
318
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
319
+ $autoMapAsinErrorMessage = $helper->escapeJs(
320
+ $helper->__('Server is currently unavailable. Please try again later.')
321
+ );
322
+ $newAsinNotAvailable = $helper->escapeJs(
323
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
324
+ );
325
+ $notSynchronizedMarketplace = $helper->escapeJs(
326
+ $helper->__(
327
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
328
+ ).' '.
329
+ $helper->__(
330
+ 'Press "Save And Update" button after redirect on Marketplace page.'
331
+ )
332
+ );
333
+
334
+ $noVariationsLeftText = $helper->__('All variations are already added.');
335
+
336
+ $variationManageMatchedAttributesError = $helper->__('Please choose valid attributes.');
337
+ $variationManageMatchedAttributesErrorDuplicateSelection =
338
+ $helper->__('You can not choose the same attribute twice.');
339
+
340
+ $variationManageSkuPopUpTitle =
341
+ $helper->__('Enter Amazon Parent Product SKU.');
342
+
343
+ $switchToIndividualModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
344
+ $switchToParentModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
345
+
346
+ $emptySkuError = $helper->escapeJs($helper->__('Please enter Amazon Parent Product SKU.'));
347
+
348
+ $translations = json_encode(array(
349
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
350
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
351
+ 'You must select at least 1 category.' => $helper->__('You must select at least 1 category.'),
352
+ 'Rule with the same title already exists.' => $helper->__('Rule with the same title already exists.')
353
+ ));
354
+
355
+ $javascriptsMain = <<<JAVASCRIPT
356
+ <script type="text/javascript">
357
+
358
+ if (typeof M2ePro == 'undefined') {
359
+ M2ePro = {};
360
+ M2ePro.url = {};
361
+ M2ePro.formData = {};
362
+ M2ePro.customData = {};
363
+ M2ePro.text = {};
364
+ }
365
+
366
+ M2ePro.url.add({$urls});
367
+ M2ePro.translator.add({$translations});
368
+
369
+ M2ePro.productsIdsForList = '{$productsIdsForList}';
370
+
371
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
372
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
373
+
374
+ M2ePro.url.runListProducts = '{$runListProducts}';
375
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
376
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
377
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
378
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
379
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
380
+
381
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
382
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
383
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
384
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
385
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
386
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
387
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
388
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
389
+
390
+ M2ePro.url.variationProductManage = '{$variationProductManage}';
391
+ M2ePro.url.variationProductSetGeneralIdOwner = '{$variationProductSetGeneralIdOwner}';
392
+ M2ePro.url.variationProductSetVariationTheme = '{$variationProductSetVariationTheme}';
393
+ M2ePro.url.variationProductSetMatchedAttributes = '{$variationProductSetMatchedAttributes}';
394
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
395
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
396
+ M2ePro.url.manageVariationViewTemplateDescriptionsGrid = '{$manageVariationViewTemplateDescriptionsGrid}';
397
+ M2ePro.url.manageVariationMapToTemplateDescription = '{$manageVariationMapToTemplateDescription}';
398
+ M2ePro.url.viewVariationsSettingsAjax = '{$viewVariationsSettingsAjax}';
399
+
400
+ M2ePro.url.newAsin = '{$newAsinUrl}';
401
+
402
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
403
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
404
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
405
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
406
+
407
+ M2ePro.url.prepareData = '{$prepareData}';
408
+ M2ePro.url.getGridHtml = '{$getMoveToListingGridHtml}';
409
+ M2ePro.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
410
+ M2ePro.url.tryToMoveToListing = '{$tryToMoveToListing}';
411
+ M2ePro.url.moveToListing = '{$moveToListing}';
412
+
413
+ M2ePro.url.marketplace_synch = '{$marketplaceSynchUrl}';
414
+
415
+ M2ePro.url.get_variation_edit_popup = '{$getVariationEditPopupUrl}';
416
+ M2ePro.url.get_variation_manage_popup = '{$getVariationManagePopupUrl}';
417
+
418
+ M2ePro.url.variation_edit_action = '{$variationEditActionUrl}';
419
+ M2ePro.url.variation_manage_action = '{$variationManageActionUrl}';
420
+ M2ePro.url.variation_manage_generate_action = '{$variationManageGenerateActionUrl}';
421
+ M2ePro.url.variation_reset_action = '{$variationResetActionUrl}';
422
+
423
+ M2ePro.url.save_listing_additional_data = '{$saveListingAdditionalDataActionUrl}';
424
+
425
+ M2ePro.text.popup_title = '{$popupTitle}';
426
+ M2ePro.text.popup_title_single = '{$popupTitleSingle}';
427
+ M2ePro.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
428
+
429
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
430
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
431
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
432
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
433
+
434
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
435
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
436
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
437
+
438
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
439
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
440
+
441
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
442
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
443
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
444
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
445
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
446
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
447
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
448
+
449
+ M2ePro.text.successfully_moved = '{$successfullyMovedMessage}';
450
+ M2ePro.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
451
+ M2ePro.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
452
+
453
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
454
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
455
+
456
+ M2ePro.text.success_word = '{$successWord}';
457
+ M2ePro.text.notice_word = '{$noticeWord}';
458
+ M2ePro.text.warning_word = '{$warningWord}';
459
+ M2ePro.text.error_word = '{$errorWord}';
460
+ M2ePro.text.close_word = '{$closeWord}';
461
+
462
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
463
+
464
+ M2ePro.text.assign = '{$assignString}';
465
+ M2ePro.text.confirm = '{$textConfirm}';
466
+
467
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
468
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
469
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
470
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
471
+
472
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
473
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
474
+
475
+ M2ePro.text.no_variations_left = '{$noVariationsLeftText}';
476
+
477
+ M2ePro.text.variation_manage_matched_attributes_error = '{$variationManageMatchedAttributesError}';
478
+ M2ePro.text.variation_manage_matched_attributes_error_duplicate =
479
+ '{$variationManageMatchedAttributesErrorDuplicateSelection}';
480
+
481
+ M2ePro.text.variation_manage_matched_sku_popup_title = '{$variationManageSkuPopUpTitle}';
482
+ M2ePro.text.empty_sku_error = '{$emptySkuError}';
483
+
484
+ M2ePro.text.switch_to_individual_mode_popup_title = '{$switchToIndividualModePopUpTitle}';
485
+ M2ePro.text.switch_to_parent_mode_popup_title = '{$switchToParentModePopUpTitle}';
486
+
487
+ M2ePro.customData.componentMode = '{$component}';
488
+ M2ePro.customData.gridId = '{$gridId}';
489
+ M2ePro.customData.ignoreListings = '{$ignoreListings}';
490
+
491
+ M2ePro.customData.marketplace = {$marketplace};
492
+ M2ePro.customData.isNewAsinAvailable = {$isNewAsinAvailable};
493
+ M2ePro.customData.isMarketplaceSynchronized = {$isMarketplaceSynchronized};
494
+
495
+ Event.observe(window, 'load', function() {
496
+
497
+ ListingGridHandlerObj = new AmazonListingGridHandler(
498
+ '{$gridId}',
499
+ {$listingData['id']}
500
+ );
501
+
502
+ // todo next
503
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
504
+ ListingGridHandlerObj.movingHandler.setOptions(M2ePro);
505
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
506
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
507
+ ListingGridHandlerObj.variationProductManageHandler.setOptions(M2ePro);
508
+
509
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
510
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
511
+
512
+ ListingProductVariationHandlerObj = new ListingProductVariationHandler(M2ePro,
513
+ ListingGridHandlerObj);
514
+
515
+ if (M2ePro.productsIdsForList) {
516
+ ListingGridHandlerObj.getGridMassActionObj().checkedString = M2ePro.productsIdsForList;
517
+ ListingGridHandlerObj.actionHandler.listAction();
518
+ }
519
+
520
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
521
+ if ({$showAutoAction}) {
522
+ ListingAutoActionHandlerObj.loadAutoActionHtml();
523
+ }
524
+
525
+ });
526
+
527
+ </script>
528
+ JAVASCRIPT;
529
+
530
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_view_help');
531
+ $productSearchBlock = $this->getLayout()
532
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_productSearch_main');
533
+
534
+ //------------------------------
535
+ $data = array(
536
+ 'target_css_class' => 'edit_settings_drop_down',
537
+ 'items' => $this->getTemplatesButtonDropDownItems()
538
+ );
539
+ $templatesDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
540
+ $templatesDropDownBlock->setData($data);
541
+ //------------------------------
542
+
543
+ //------------------------------
544
+ $data = array(
545
+ 'target_css_class' => 'add_products_drop_down',
546
+ 'items' => $this->getAddProductsDropDownItems()
547
+ );
548
+ $addProductsDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
549
+ $addProductsDropDownBlock->setData($data);
550
+ //------------------------------
551
+
552
+ //------------------------------
553
+ $listingSwitcher = $this->getLayout()->createBlock(
554
+ 'M2ePro/adminhtml_common_amazon_listing_view_listingSwitcher'
555
+ );
556
+ //------------------------------
557
+
558
+ //------------------------------
559
+ $viewHeaderBlock = $this->getLayout()->createBlock(
560
+ 'M2ePro/adminhtml_listing_view_header','',
561
+ array('listing' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Listing',$listingData['id']))
562
+ );
563
+ //------------------------------
564
+
565
+ //------------------------------
566
+ $switchToIndividualPopup = $this->getLayout()->createBlock(
567
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToIndividualPopup');
568
+ //------------------------------
569
+
570
+ //------------------------------
571
+ $switchToParentPopup = $this->getLayout()->createBlock(
572
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToParentPopup');
573
+ //------------------------------
574
+
575
+ return $javascriptsMain
576
+ . $templatesDropDownBlock->toHtml()
577
+ . $listingSwitcher->toHtml()
578
+ . $addProductsDropDownBlock->toHtml()
579
+ . $helpBlock->toHtml()
580
+ . $viewHeaderBlock->toHtml()
581
+ . $productSearchBlock->toHtml()
582
+ . $switchToIndividualPopup->toHtml()
583
+ . $switchToParentPopup->toHtml()
584
+ . parent::getGridHtml();
585
+ }
586
+
587
+ public function getHeaderHtml()
588
+ {
589
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
590
+
591
+ //------------------------------
592
+ $collection = Mage::getModel('M2ePro/Listing')->getCollection();
593
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
594
+ $collection->addFieldToFilter('id', array('neq' => $listingData['id']));
595
+ $collection->setPageSize(200);
596
+ $collection->setOrder('title', 'ASC');
597
+
598
+ $items = array();
599
+ foreach ($collection->getItems() as $item) {
600
+ $items[] = array(
601
+ 'label' => $item->getTitle(),
602
+ 'url' => $this->getUrl('*/*/view', array('id' => $item->getId()))
603
+ );
604
+ }
605
+ //------------------------------
606
+
607
+ if (count($items) == 0) {
608
+ return parent::getHeaderHtml();
609
+ }
610
+
611
+ //------------------------------
612
+ $data = array(
613
+ 'target_css_class' => 'listing-profile-title',
614
+ 'style' => 'max-height: 120px; overflow: auto; width: 200px;',
615
+ 'items' => $items
616
+ );
617
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
618
+ $dropDownBlock->setData($data);
619
+ //------------------------------
620
+
621
+ return parent::getHeaderHtml() . $dropDownBlock->toHtml();
622
+ }
623
+
624
+ public function getHeaderText()
625
+ {
626
+ //------------------------------
627
+ $changeProfile = Mage::helper('M2ePro')->__('Change Listing');
628
+ $headerText = parent::getHeaderText();
629
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
630
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($listingData['title']);
631
+ //------------------------------
632
+
633
+ return <<<HTML
634
+ {$headerText} <a href="javascript: void(0);"
635
+ id="listing-profile-title"
636
+ class="listing-profile-title"
637
+ style="font-weight: bold;"
638
+ title="{$changeProfile}"><span class="drop_down_header">"{$listingTitle}"</span></a>
639
+ HTML;
640
+ }
641
+
642
+ protected function getTemplatesButtonDropDownItems()
643
+ {
644
+ $items = array();
645
+
646
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
647
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
648
+ '*/adminhtml_common_amazon_listing/view',
649
+ array(
650
+ 'id' => $listingData['id']
651
+ )
652
+ );
653
+
654
+ //------------------------------
655
+ $url = $this->getUrl(
656
+ '*/adminhtml_common_amazon_listing/edit',
657
+ array(
658
+ 'id'=>$listingData['id'],
659
+ 'back'=>$backUrl,
660
+ 'tab' => 'selling'
661
+ )
662
+ );
663
+ $items[] = array(
664
+ 'url' => $url,
665
+ 'label' => Mage::helper('M2ePro')->__('Selling'),
666
+ 'target' => '_blank'
667
+ );
668
+ //------------------------------
669
+
670
+ //------------------------------
671
+ $url = $this->getUrl(
672
+ '*/adminhtml_common_amazon_listing/edit',
673
+ array(
674
+ 'id'=>$listingData['id'],
675
+ 'back'=>$backUrl,
676
+ 'tab' => 'search'
677
+ )
678
+ );
679
+ $items[] = array(
680
+ 'url' => $url,
681
+ 'label' => Mage::helper('M2ePro')->__('Search'),
682
+ 'target' => '_blank'
683
+ );
684
+ //------------------------------
685
+
686
+ //------------------------------
687
+ $items[] = array(
688
+ 'url' => 'javascript: void(0);',
689
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();',
690
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules')
691
+ );
692
+ //------------------------------
693
+
694
+ return $items;
695
+ }
696
+
697
+ public function getAddProductsDropDownItems()
698
+ {
699
+ $items = array();
700
+
701
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
702
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array(
703
+ 'id' => $listingData['id']
704
+ ));
705
+
706
+ //------------------------------
707
+ $url = $this->getUrl(
708
+ '*/adminhtml_common_listing_productAdd/index',
709
+ array(
710
+ 'id' => $listingData['id'],
711
+ 'back' => $backUrl,
712
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
713
+ 'clear' => 1,
714
+ 'step' => 2,
715
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
716
+ )
717
+ );
718
+ $items[] = array(
719
+ 'url' => $url,
720
+ 'label' => Mage::helper('M2ePro')->__('From Products List')
721
+ );
722
+ //------------------------------
723
+
724
+ //------------------------------
725
+ $url = $this->getUrl(
726
+ '*/adminhtml_common_listing_productAdd/index',
727
+ array(
728
+ 'id' => $listingData['id'],
729
+ 'back' => $backUrl,
730
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
731
+ 'clear' => 1,
732
+ 'step' => 2,
733
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
734
+ )
735
+ );
736
+ $items[] = array(
737
+ 'url' => $url,
738
+ 'label' => Mage::helper('M2ePro')->__('From Categories')
739
+ );
740
+ //------------------------------
741
+
742
+ return $items;
743
+ }
744
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php ADDED
@@ -0,0 +1,1359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Amazon_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
9
+ {
10
+ /** @var $sellingFormatTemplate Ess_M2ePro_Model_Amazon_Template_SellingFormat */
11
+ private $sellingFormatTemplate = NULL;
12
+
13
+ private $lockedDataCache = array();
14
+
15
+ private $hideSwitchToIndividualConfirm;
16
+ private $hideSwitchToParentConfirm;
17
+
18
+ // ####################################
19
+
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
25
+
26
+ $listing = Mage::helper('M2ePro/Component')->getUnknownObject('Listing', $listingData['id']);
27
+
28
+ $this->hideSwitchToIndividualConfirm =
29
+ $listing->getSetting('additional_data', 'hide_switch_to_individual_confirm', 0);
30
+
31
+ $this->hideSwitchToParentConfirm =
32
+ $listing->getSetting('additional_data', 'hide_switch_to_parent_confirm', 0);
33
+
34
+ // Initialization block
35
+ //------------------------------
36
+ $this->setId('amazonListingViewAmazonGrid'.$listingData['id']);
37
+ //------------------------------
38
+
39
+ $this->showAdvancedFilterProductsOption = false;
40
+
41
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
42
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
43
+ array('template')
44
+ );
45
+ }
46
+
47
+ // ####################################
48
+
49
+ public function getMainButtonsHtml()
50
+ {
51
+ $data = array(
52
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
53
+ );
54
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
55
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
56
+ );
57
+ $viewModeSwitcherBlock->addData($data);
58
+
59
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
60
+ }
61
+
62
+ // ####################################
63
+
64
+ protected function _prepareCollection()
65
+ {
66
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
67
+
68
+ // Get collection
69
+ //----------------------------
70
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
71
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
72
+ Mage::getModel('catalog/product')->getResource());
73
+ $collection->setListingProductModeOn();
74
+ $collection
75
+ ->addAttributeToSelect('name')
76
+ ->addAttributeToSelect('sku')
77
+ ->joinTable(
78
+ array('cisi' => 'cataloginventory/stock_item'),
79
+ 'product_id=entity_id',
80
+ array('qty' => 'qty'),
81
+ '{{table}}.stock_id=1',
82
+ 'left'
83
+ );
84
+
85
+ //----------------------------
86
+
87
+ $collection->joinTable(
88
+ array('lp' => 'M2ePro/Listing_Product'),
89
+ 'product_id=entity_id',
90
+ array(
91
+ 'id' => 'id',
92
+ 'component_mode' => 'component_mode',
93
+ 'amazon_status' => 'status',
94
+ 'additional_data' => 'additional_data'
95
+ ),
96
+ array(
97
+ 'listing_id' => (int)$listingData['id']
98
+ )
99
+ );
100
+ $collection->joinTable(
101
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
102
+ 'listing_product_id=id',
103
+ array(
104
+ 'general_id' => 'general_id',
105
+ 'general_id_search_info' => 'general_id_search_info',
106
+ 'search_settings_status' => 'search_settings_status',
107
+ 'search_settings_data' => 'search_settings_data',
108
+ 'variation_child_statuses' => 'variation_child_statuses',
109
+ 'amazon_sku' => 'sku',
110
+ 'online_qty' => 'online_qty',
111
+ 'online_price' => 'online_price',
112
+ 'online_sale_price' => 'online_sale_price',
113
+ 'is_afn_channel' => 'is_afn_channel',
114
+ 'is_general_id_owner' => 'is_general_id_owner',
115
+ 'is_variation_parent' => 'is_variation_parent'
116
+ ),
117
+ '{{table}}.variation_parent_id is NULL'
118
+ );
119
+ //----------------------------
120
+ // exit($collection->getSelect()->__toString());
121
+
122
+ // Set collection to grid
123
+ $this->setCollection($collection);
124
+
125
+ return parent::_prepareCollection();
126
+ }
127
+
128
+ protected function _prepareColumns()
129
+ {
130
+ $this->addColumn('product_id', array(
131
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
132
+ 'align' => 'right',
133
+ 'width' => '100px',
134
+ 'type' => 'number',
135
+ 'index' => 'entity_id',
136
+ 'filter_index' => 'entity_id',
137
+ 'frame_callback' => array($this, 'callbackColumnProductId')
138
+ ));
139
+
140
+ $this->addColumn('name', array(
141
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
142
+ 'align' => 'left',
143
+ //'width' => '300px',
144
+ 'type' => 'text',
145
+ 'index' => 'name',
146
+ 'filter_index' => 'name',
147
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
148
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
149
+ ));
150
+
151
+ $this->addColumn('sku', array(
152
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
153
+ 'align' => 'left',
154
+ 'width' => '150px',
155
+ 'type' => 'text',
156
+ 'index' => 'amazon_sku',
157
+ 'filter_index' => 'amazon_sku',
158
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
159
+ ));
160
+
161
+ $this->addColumn('general_id', array(
162
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
163
+ 'align' => 'left',
164
+ 'width' => '140px',
165
+ 'type' => 'text',
166
+ 'index' => 'general_id',
167
+ 'filter_index' => 'general_id',
168
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
169
+ ));
170
+
171
+ $this->addColumn('online_qty', array(
172
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
173
+ 'align' => 'right',
174
+ 'width' => '70px',
175
+ 'type' => 'number',
176
+ 'index' => 'online_qty',
177
+ 'filter_index' => 'online_qty',
178
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
179
+ ));
180
+
181
+ $this->addColumn('online_price', array(
182
+ 'header' => Mage::helper('M2ePro')->__('Price'),
183
+ 'align' => 'right',
184
+ 'width' => '70px',
185
+ 'type' => 'number',
186
+ 'index' => 'online_price',
187
+ 'filter_index' => 'online_price',
188
+ 'frame_callback' => array($this, 'callbackColumnPrice')
189
+ ));
190
+
191
+ $this->addColumn('is_afn_channel', array(
192
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
193
+ 'align' => 'right',
194
+ 'width' => '90px',
195
+ 'index' => 'is_afn_channel',
196
+ 'filter_index' => 'is_afn_channel',
197
+ 'type' => 'options',
198
+ 'sortable' => false,
199
+ 'options' => array(
200
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
201
+ 1 => Mage::helper('M2ePro')->__('Amazon')
202
+ ),
203
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
204
+ ));
205
+
206
+ $this->addColumn('status', array(
207
+ 'header' => Mage::helper('M2ePro')->__('Status'),
208
+ 'width' => '145px',
209
+ 'index' => 'amazon_status',
210
+ 'filter_index' => 'amazon_status',
211
+ 'type' => 'options',
212
+ 'sortable' => false,
213
+ 'options' => array(
214
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
215
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
216
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
217
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
218
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
219
+ ),
220
+ 'frame_callback' => array($this, 'callbackColumnStatus'),
221
+ 'filter_condition_callback' => array($this, 'callbackFilterStatus')
222
+ ));
223
+
224
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
225
+ $this->addColumn('developer_action', array(
226
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
227
+ 'align' => 'left',
228
+ 'width' => '100px',
229
+ 'type' => 'text',
230
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
231
+ 'index' => 'value',
232
+ 'filter' => false,
233
+ 'sortable' => false,
234
+ 'js_handler' => 'ListingGridHandlerObj'
235
+ ));
236
+ }
237
+
238
+ return parent::_prepareColumns();
239
+ }
240
+
241
+ protected function _prepareMassaction()
242
+ {
243
+ // Set massaction identifiers
244
+ //--------------------------------
245
+ $this->setMassactionIdField('id');
246
+ $this->setMassactionIdFieldOnlyIndexValue(true);
247
+ //--------------------------------
248
+
249
+ // Set mass-action
250
+ //--------------------------------
251
+ $groups = array(
252
+ 'actions' => Mage::helper('M2ePro')->__('Actions'),
253
+ 'description_policy' => Mage::helper('M2ePro')->__('Description Policy'),
254
+ 'asin_isbn' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
255
+ 'other' => Mage::helper('M2ePro')->__('Other'),
256
+ );
257
+
258
+ $this->getMassactionBlock()->setGroups($groups);
259
+
260
+ $this->getMassactionBlock()->addItem('list', array(
261
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
262
+ 'url' => '',
263
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
264
+ ), 'actions');
265
+
266
+ $this->getMassactionBlock()->addItem('revise', array(
267
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
268
+ 'url' => '',
269
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
270
+ ), 'actions');
271
+
272
+ $this->getMassactionBlock()->addItem('relist', array(
273
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
274
+ 'url' => '',
275
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
276
+ ), 'actions');
277
+
278
+ $this->getMassactionBlock()->addItem('stop', array(
279
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
280
+ 'url' => '',
281
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
282
+ ), 'actions');
283
+
284
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
285
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
286
+ 'url' => '',
287
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
288
+ ), 'actions');
289
+
290
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
291
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
292
+ 'url' => '',
293
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
294
+ ), 'actions');
295
+
296
+ $this->getMassactionBlock()->addItem('assignTemplateDescriptionId', array(
297
+ 'label' => Mage::helper('M2ePro')->__('Assign'),
298
+ 'url' => '',
299
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
300
+ ), 'description_policy');
301
+
302
+ $this->getMassactionBlock()->addItem('unassignTemplateDescriptionId', array(
303
+ 'label' => Mage::helper('M2ePro')->__('Unassign'),
304
+ 'url' => '',
305
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
306
+ ), 'description_policy');
307
+
308
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
309
+ 'label' => Mage::helper('M2ePro')->__('Search Automatically'),
310
+ 'url' => '',
311
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
312
+ ), 'asin_isbn');
313
+
314
+ $this->getMassactionBlock()->addItem('newGeneralId', array(
315
+ 'label' => Mage::helper('M2ePro')->__('Assign Settings for New ASIN/ISBN'),
316
+ 'url' => '',
317
+ ), 'asin_isbn');
318
+
319
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
320
+ 'label' => Mage::helper('M2ePro')->__('Reset Information'),
321
+ 'url' => '',
322
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
323
+ ), 'asin_isbn');
324
+
325
+ $this->getMassactionBlock()->addItem('moving', array(
326
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Another Listing'),
327
+ 'url' => '',
328
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
329
+ ), 'other');
330
+
331
+ $this->getMassactionBlock()->addItem('duplicate', array(
332
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
333
+ 'url' => '',
334
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
335
+ ), 'other');
336
+ //--------------------------------
337
+
338
+ return parent::_prepareMassaction();
339
+ }
340
+
341
+ // ####################################
342
+
343
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
344
+ {
345
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
346
+
347
+ $value = '<span>'.$productTitle.'</span>';
348
+
349
+ $tempSku = $row->getData('sku');
350
+ is_null($tempSku)
351
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
352
+
353
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
354
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
355
+
356
+ $listingProductId = (int)$row->getData('id');
357
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
358
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
359
+
360
+ if ($listingProduct->getChildObject()->isExistDescriptionTemplate()) {
361
+ $value .= $this->getTemplateDescriptionLinkHtml($listingProduct);
362
+ }
363
+
364
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
365
+ return $value;
366
+ }
367
+
368
+ $generalId = $row->getData('general_id');
369
+
370
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
371
+ $amazonListingProduct = $listingProduct->getChildObject();
372
+ $variationManager = $amazonListingProduct->getVariationManager();
373
+
374
+ if ($variationManager->isRelationParentType()) {
375
+
376
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
377
+
378
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
379
+ $value .= implode(', ', $productAttributes);
380
+
381
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
382
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
383
+ Mage::helper('M2ePro')->__('Manage Magento Product Variations'))
384
+ );
385
+
386
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
387
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
388
+ );
389
+
390
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
391
+
392
+ $switchToIndividualJsMethod = <<<JS
393
+ ListingProductVariationHandlerObj
394
+ .setListingProductId({$listingProductId})
395
+ .showSwitchToIndividualModePopUp('{$popupTitle}');
396
+ JS;
397
+
398
+ if ($this->hideSwitchToIndividualConfirm) {
399
+ $switchToIndividualJsMethod = <<<JS
400
+ ListingProductVariationHandlerObj
401
+ .setListingProductId({$listingProductId})
402
+ .showManagePopup('{$popupTitle}');
403
+ JS;
404
+ }
405
+
406
+ $value .= <<<HTML
407
+ &nbsp;
408
+ <a href="javascript:"
409
+ onclick="{$switchToIndividualJsMethod}"
410
+ title="{$linkTitle}">
411
+ <img width="12" height="12" style="height: 12px; width: 12px; vertical-align: middle;" src="{$iconSettingsPath}">
412
+ </a>
413
+ HTML;
414
+ }
415
+
416
+ $value .= '</div>';
417
+
418
+ if (!empty($generalId) || $amazonListingProduct->isGeneralIdOwner()) {
419
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
420
+ $parentType = $variationManager->getTypeModel();
421
+
422
+ $linkContent = Mage::helper('M2ePro')->__('Manage Variations');
423
+ $vpmt = Mage::helper('M2ePro')->__('Manage Variations of &quot;%s&quot; ', $productTitle);
424
+ $vpmt = addslashes($vpmt);
425
+
426
+ if (!empty($generalId)) {
427
+ $vpmt .= '('. $generalId .')';
428
+ }
429
+
430
+ $problemStyle = '';
431
+ $problemIcon = '';
432
+
433
+ $linkTitle = '';
434
+
435
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
436
+ if (!$parentType->hasChannelTheme() || !$parentType->hasMatchedAttributes()) {
437
+
438
+ $problemStyle = 'style="font-weight: bold; color: #FF0000;" ';
439
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
440
+ $problemIcon = '<img style="vertical-align: middle;" src="'
441
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
442
+ }
443
+ } elseif (!empty($generalId)) {
444
+ if (!$parentType->hasMatchedAttributes()) {
445
+
446
+ $problemStyle = 'style="font-weight: bold;color: #FF0000;" ';
447
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
448
+ $problemIcon = '<img style="vertical-align: middle;" src="'
449
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
450
+ } elseif ($listingProduct->getChildObject()->isGeneralIdOwner() &&
451
+ !$parentType->hasChannelTheme()) {
452
+
453
+ $problemStyle = 'style="font-weight: bold;" ';
454
+ $iconPath = $this->getSkinUrl('M2ePro/images/warning.png');
455
+ $problemIcon = '<img style="vertical-align: middle;" src="'
456
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
457
+ }
458
+ }
459
+
460
+ $value .= <<<HTML
461
+ <div style="float: left; margin: 0 0 0 7px">
462
+ <a {$problemStyle}href="javascript:"
463
+ onclick="ListingGridHandlerObj.variationProductManageHandler.openPopUp({$listingProductId}, '{$vpmt}')"
464
+ title="{$linkTitle}">{$linkContent}</a>&nbsp;{$problemIcon}
465
+ </div>
466
+ HTML;
467
+ }
468
+
469
+ return $value;
470
+ }
471
+
472
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
473
+
474
+ if (!empty($productOptions)) {
475
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
476
+ foreach ($productOptions as $attribute => $option) {
477
+ !$option && $option = '--';
478
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
479
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
480
+ }
481
+ $value .= '</div>';
482
+ }
483
+
484
+ // ---------------------------------
485
+ $hasInActionLock = $this->getLockedData($row);
486
+ $hasInActionLock = $hasInActionLock['in_action'];
487
+ // ---------------------------------
488
+
489
+ if (!$hasInActionLock) {
490
+
491
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variation');
492
+ $linkTitle = Mage::helper('M2ePro')->__('Edit Variation');
493
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/pencil.png').'">';
494
+
495
+ $value .= <<<HTML
496
+ <div style="clear: both"></div>
497
+ <div style="margin: 0 0 0 7px; float: left;">
498
+ <a href="javascript:"
499
+ onclick="ListingProductVariationHandlerObj
500
+ .setListingProductId({$listingProductId})
501
+ .showEditPopup('{$popupTitle}');"
502
+ title="{$linkTitle}">{$linkContent}</a>
503
+ </div>
504
+ HTML;
505
+ }
506
+
507
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variations') ;
508
+ $linkTitle = Mage::helper('M2ePro')->__('Add Another Variation(s)');
509
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
510
+
511
+ $value.= <<<HTML
512
+ <div style="margin: 0 0 0 7px; float: left;">
513
+ <a href="javascript:"
514
+ onclick="ListingProductVariationHandlerObj
515
+ .setListingProductId({$listingProductId})
516
+ .showManagePopup('{$popupTitle}');"
517
+ title="{$linkTitle}">{$linkContent}</a>
518
+ </div>
519
+ HTML;
520
+
521
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
522
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
523
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
524
+ );
525
+
526
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
527
+
528
+ $switchToParentJsMethod = <<<JS
529
+ ListingProductVariationHandlerObj
530
+ .setListingProductId({$listingProductId})
531
+ .showSwitchToParentModePopUp('{$popupTitle}');
532
+ JS;
533
+
534
+ if ($this->hideSwitchToParentConfirm) {
535
+ $switchToParentJsMethod = <<<JS
536
+ ListingProductVariationHandlerObj
537
+ .setListingProductId({$listingProductId})
538
+ .resetListingProductVariation();
539
+ JS;
540
+ }
541
+
542
+ $value .= <<<HTML
543
+ <div style="margin: 0 0 0 7px; float: left;">
544
+ <a href="javascript:"
545
+ onclick="{$switchToParentJsMethod}"
546
+ title="{$linkTitle}">
547
+ <img width="12" height="12" src="{$iconSettingsPath}">
548
+ </a>
549
+ </div>
550
+ HTML;
551
+ }
552
+
553
+ return $value;
554
+ }
555
+
556
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
557
+ {
558
+ if (is_null($value) || $value === '') {
559
+ return Mage::helper('M2ePro')->__('N/A');
560
+ }
561
+ return $value;
562
+ }
563
+
564
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
565
+ {
566
+ if (empty($generalId)) {
567
+ if($row->getData('is_general_id_owner') == 1){
568
+ return $this->getGeneralIdColumnValueGeneralIdOwner($row);
569
+ }
570
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
571
+ }
572
+
573
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
574
+ }
575
+
576
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
577
+ {
578
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
579
+ $row->getData('is_variation_parent')
580
+ ) {
581
+ if (is_null($value) || $value === '') {
582
+ return Mage::helper('M2ePro')->__('N/A');
583
+ }
584
+ } else {
585
+ if (is_null($value) || $value === '') {
586
+ return '<i style="color:gray;">receiving...</i>';
587
+ }
588
+ }
589
+
590
+ if ((bool)$row->getData('is_afn_channel')) {
591
+ return '--';
592
+ }
593
+
594
+ if ($value <= 0) {
595
+ return '<span style="color: red;">0</span>';
596
+ }
597
+
598
+ return $value;
599
+ }
600
+
601
+ public function callbackColumnPrice($value, $row, $column, $isExport)
602
+ {
603
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
604
+ $row->getData('is_variation_parent')
605
+ ) {
606
+ if (is_null($value) || $value === '') {
607
+ return Mage::helper('M2ePro')->__('N/A');
608
+ }
609
+ } else {
610
+ if (is_null($value) || $value === '') {
611
+ return '<i style="color:gray;">receiving...</i>';
612
+ }
613
+ }
614
+
615
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
616
+ $currency = Mage::helper('M2ePro/Component_Amazon')
617
+ ->getCachedObject('Marketplace',$marketplaceId)
618
+ ->getChildObject()
619
+ ->getDefaultCurrency();
620
+
621
+ $salePriceValue = $row->getData('online_sale_price');
622
+ if (is_null($salePriceValue) ||
623
+ (float)$salePriceValue <= 0) {
624
+ $salePriceValue = null;
625
+ } else {
626
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePriceValue);
627
+ }
628
+
629
+ if ((float)$value <= 0) {
630
+ $result = '<span style="color: #f00;">0</span>';
631
+ } else {
632
+ $result = Mage::app()->getLocale()->currency($currency)->toCurrency($value);
633
+ }
634
+
635
+ return $result.($salePriceValue ? ' <br/><span style="color:gray;">'.$salePriceValue.'</span>' : '');
636
+ }
637
+
638
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
639
+ {
640
+ if (is_null($value) || $value === '') {
641
+ return Mage::helper('M2ePro')->__('N/A');
642
+ }
643
+
644
+ switch ($row->getData('is_afn_channel')) {
645
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
646
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
647
+ break;
648
+
649
+ default:
650
+ break;
651
+ }
652
+
653
+ return $value;
654
+ }
655
+
656
+ public function callbackColumnStatus($value, $row, $column, $isExport)
657
+ {
658
+ $listingProductId = (int)$row->getData('id');
659
+
660
+ $html = $this->getViewLogIconHtml($listingProductId);
661
+
662
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
663
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
664
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
665
+
666
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
667
+ if (!empty($synchNote)) {
668
+
669
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
670
+
671
+ if (empty($html)) {
672
+ $html = <<<HTML
673
+ <span style="float:right;">
674
+ <img id="map_link_error_icon_{$row->getId()}"
675
+ class="tool-tip-image"
676
+ style="vertical-align: middle;"
677
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
678
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
679
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
680
+ <span>{$synchNote}</span>
681
+ </span>
682
+ </span>
683
+ HTML;
684
+ } else {
685
+ $html .= <<<HTML
686
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
687
+ HTML;
688
+ }
689
+ }
690
+
691
+ if (!$variationManager->isVariationParent()) {
692
+ return $html . $this->getProductStatus($row->getData('amazon_status')). $this->getLockedTag($row);
693
+ } else {
694
+
695
+ $generalId = $listingProduct->getGeneralId();
696
+ $variationChildStatuses = $row->getData('variation_child_statuses');
697
+ if (empty($generalId) || empty($variationChildStatuses)) {
698
+ return $html . $this->getProductStatus(Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) .
699
+ $this->getLockedTag($row);
700
+ }
701
+
702
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
703
+ $variationChildStatuses = array(
704
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED =>
705
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED],
706
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED =>
707
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_LISTED],
708
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED =>
709
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED],
710
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED =>
711
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED]
712
+ );
713
+
714
+ foreach ($variationChildStatuses as $status => $productsCount) {
715
+ if (empty($productsCount)) {
716
+ continue;
717
+ }
718
+ $html .= '' . $this->getProductStatus($status) . ' ('. $productsCount . ')<br/>';
719
+ }
720
+
721
+ $html .= $this->getLockedTag($row);
722
+ }
723
+
724
+ return $html;
725
+ }
726
+
727
+ private function getProductStatus($status)
728
+ {
729
+ switch ($status) {
730
+
731
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
732
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
733
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
734
+
735
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
736
+ return '<span style="color: green;">' . Mage::helper('M2ePro')->__('Active') . '</span>';
737
+
738
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
739
+ return'<span style="color: red;">' . Mage::helper('M2ePro')->__('Inactive') . '</span>';
740
+
741
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
742
+ return'<span style="color: orange; font-weight: bold;">' .
743
+ Mage::helper('M2ePro')->__('Inactive (Blocked)') . '</span>';
744
+ }
745
+
746
+ return '';
747
+ }
748
+
749
+ private function getLockedTag($row)
750
+ {
751
+ $html = '';
752
+
753
+ $tempLocks = $this->getLockedData($row);
754
+ $tempLocks = $tempLocks['object_locks'];
755
+
756
+ $childCount = 0;
757
+
758
+ foreach ($tempLocks as $lock) {
759
+
760
+ switch ($lock->getTag()) {
761
+
762
+ case 'list_action':
763
+ $html .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
764
+ break;
765
+
766
+ case 'relist_action':
767
+ $html .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
768
+ break;
769
+
770
+ case 'revise_action':
771
+ $html .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
772
+ break;
773
+
774
+ case 'stop_action':
775
+ $html .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
776
+ break;
777
+
778
+ case 'stop_and_remove_action':
779
+ $html .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
780
+ break;
781
+
782
+ case 'delete_and_remove_action':
783
+ $html .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
784
+ break;
785
+
786
+ case 'child_products_in_action':
787
+ $childCount++;
788
+ break;
789
+
790
+ default:
791
+ break;
792
+
793
+ }
794
+ }
795
+
796
+ if ($childCount > 0) {
797
+ $html .= '<br/><span style="color: #605fff">[Some Child Products in Action...]</span>';
798
+ }
799
+
800
+ return $html;
801
+ }
802
+
803
+ //----------------------------------------
804
+
805
+ protected function callbackFilterTitle($collection, $column)
806
+ {
807
+ $value = $column->getFilter()->getValue();
808
+
809
+ if ($value == null) {
810
+ return;
811
+ }
812
+
813
+ $collection->addFieldToFilter(
814
+ array(
815
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
816
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
817
+ )
818
+ );
819
+ }
820
+
821
+ protected function callbackFilterStatus($collection, $column)
822
+ {
823
+ $value = $column->getFilter()->getValue();
824
+
825
+ if ($value == null) {
826
+ return;
827
+ }
828
+
829
+ $collection->getSelect()->where("lp.status = {$value} OR
830
+ (alp.variation_child_statuses REGEXP '\"{$value}\":[^0]') AND alp.is_variation_parent = 1");
831
+ }
832
+
833
+ //----------------------------------------
834
+
835
+ public function getViewLogIconHtml($listingProductId)
836
+ {
837
+ $listingProductId = (int)$listingProductId;
838
+
839
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
840
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
841
+
842
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
843
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
844
+
845
+ // Get last messages
846
+ //--------------------------
847
+ $dbSelect = $connRead->select()
848
+ ->from(
849
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
850
+ array('action_id','action','type','description','create_date','initiator','listing_product_id')
851
+ )
852
+ ->where('`action_id` IS NOT NULL')
853
+ ->order(array('id DESC'))
854
+ ->limit(30);
855
+
856
+ if($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
857
+ $dbSelect->where('listing_product_id = ? OR parent_listing_product_id = ?', $listingProductId);
858
+ } else {
859
+ $dbSelect->where('listing_product_id = ?', $listingProductId);
860
+ }
861
+
862
+ $logRows = $connRead->fetchAll($dbSelect);
863
+ //--------------------------
864
+
865
+ // Get grouped messages by action_id
866
+ //--------------------------
867
+ $actionsRows = array();
868
+ $tempActionRows = array();
869
+ $lastActionId = false;
870
+
871
+ foreach ($logRows as $row) {
872
+
873
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
874
+
875
+ if ($row['action_id'] !== $lastActionId) {
876
+ if (count($tempActionRows) > 0) {
877
+ $actionsRows[] = array(
878
+ 'action_id' => $lastActionId,
879
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
880
+ 'date' => $this->getMainDateForActionId($tempActionRows),
881
+ 'action' => $this->getActionForAction($tempActionRows[0]),
882
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
883
+ 'items' => $tempActionRows
884
+ );
885
+ $tempActionRows = array();
886
+ }
887
+ $lastActionId = $row['action_id'];
888
+ }
889
+ $tempActionRows[] = $row;
890
+ }
891
+
892
+ if (count($tempActionRows) > 0) {
893
+ $actionsRows[] = array(
894
+ 'action_id' => $lastActionId,
895
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
896
+ 'date' => $this->getMainDateForActionId($tempActionRows),
897
+ 'action' => $this->getActionForAction($tempActionRows[0]),
898
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
899
+ 'items' => $tempActionRows
900
+ );
901
+ }
902
+
903
+ if (count($actionsRows) <= 0) {
904
+ return '';
905
+ }
906
+
907
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
908
+ foreach ($actionsRows as &$actionsRow) {
909
+ if (!empty($actionsRow['items']) && $actionsRow['items'][0]['listing_product_id']==$listingProductId) {
910
+ continue;
911
+ }
912
+ $actionsRow['action_in_progress'] = $this->isActionInProgress($actionsRow['action_id']);
913
+
914
+ $descArr = array();
915
+ foreach ($actionsRow['items'] as $key => &$item) {
916
+ if (array_key_exists($item['description'], $descArr)) {
917
+ $descArr[$item['description']]['count']++;
918
+ unset($actionsRow['items'][$key]);
919
+ continue;
920
+ }
921
+ $item['count'] = 1;
922
+ $descArr[$item['description']] = $item;
923
+ }
924
+ $actionsRow['items'] = array_values($descArr);
925
+ }
926
+
927
+ foreach ($actionsRows as &$actionsRow) {
928
+ usort($actionsRow['items'], function($a, $b)
929
+ {
930
+ return $a["type"] < $b["type"];
931
+ });
932
+ }
933
+ }
934
+
935
+ $tips = array(
936
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last action was completed successfully.',
937
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last action was completed with error(s).',
938
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last action was completed with warning(s).'
939
+ );
940
+
941
+ $icons = array(
942
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
943
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
944
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
945
+ );
946
+
947
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
948
+ 'entity_id' => $listingProductId,
949
+ 'rows' => $actionsRows,
950
+ 'tips' => $tips,
951
+ 'icons' => $icons,
952
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
953
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
954
+ ));
955
+
956
+ return $summary->toHtml();
957
+ }
958
+
959
+ public function getActionForAction($actionRows)
960
+ {
961
+ $string = '';
962
+
963
+ switch ($actionRows['action']) {
964
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
965
+ $string = Mage::helper('M2ePro')->__('List');
966
+ break;
967
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
968
+ $string = Mage::helper('M2ePro')->__('Relist');
969
+ break;
970
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
971
+ $string = Mage::helper('M2ePro')->__('Revise');
972
+ break;
973
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
974
+ $string = Mage::helper('M2ePro')->__('Stop');
975
+ break;
976
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
977
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
978
+ break;
979
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
980
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
981
+ break;
982
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
983
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
984
+ break;
985
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANGE_STATUS_ON_CHANNEL:
986
+ $string = Mage::helper('M2ePro')->__('Status Change');
987
+ break;
988
+ }
989
+
990
+ return $string;
991
+ }
992
+
993
+ public function getInitiatorForAction($actionRows)
994
+ {
995
+ $string = '';
996
+
997
+ switch ((int)$actionRows['initiator']) {
998
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
999
+ $string = '';
1000
+ break;
1001
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
1002
+ $string = Mage::helper('M2ePro')->__('Manual');
1003
+ break;
1004
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
1005
+ $string = Mage::helper('M2ePro')->__('Automatic');
1006
+ break;
1007
+ }
1008
+
1009
+ return $string;
1010
+ }
1011
+
1012
+ public function getMainTypeForActionId($actionRows)
1013
+ {
1014
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
1015
+
1016
+ foreach ($actionRows as $row) {
1017
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
1018
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
1019
+ break;
1020
+ }
1021
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
1022
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
1023
+ }
1024
+ }
1025
+
1026
+ return $type;
1027
+ }
1028
+
1029
+ public function getMainDateForActionId($actionRows)
1030
+ {
1031
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
1032
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
1033
+ }
1034
+
1035
+ public function isActionInProgress($actionId)
1036
+ {
1037
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
1038
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1039
+
1040
+ // Get last messages
1041
+ //--------------------------
1042
+ $dbSelect = $connRead->select()
1043
+ ->from(
1044
+ Mage::getResourceModel('M2ePro/Processing_Request')->getMainTable()
1045
+ )
1046
+ ->where('responser_params REGEXP \'"logs_action_id":'.$actionId.'\'');
1047
+
1048
+ $result = $connRead->fetchAll($dbSelect);
1049
+
1050
+ return !empty($result);
1051
+ }
1052
+
1053
+ // ####################################
1054
+
1055
+ public function getGridUrl()
1056
+ {
1057
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
1058
+ }
1059
+
1060
+ public function getRowUrl($row)
1061
+ {
1062
+ return false;
1063
+ }
1064
+
1065
+ // ####################################
1066
+
1067
+ protected function _getStore()
1068
+ {
1069
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
1070
+
1071
+ // Get store filter
1072
+ //----------------------------
1073
+ $storeId = $listing['store_id'];
1074
+ //----------------------------
1075
+
1076
+ return Mage::app()->getStore((int)$storeId);
1077
+ }
1078
+
1079
+ // ####################################
1080
+
1081
+ protected function _toHtml()
1082
+ {
1083
+ $javascriptsMain = <<<JAVASCRIPT
1084
+ <script type="text/javascript">
1085
+
1086
+ if (typeof ListingGridHandlerObj != 'undefined') {
1087
+ ListingGridHandlerObj.afterInitPage();
1088
+ }
1089
+
1090
+ Event.observe(window, 'load', function() {
1091
+ setTimeout(function() {
1092
+ ListingGridHandlerObj.afterInitPage();
1093
+ }, 350);
1094
+ });
1095
+
1096
+ </script>
1097
+ JAVASCRIPT;
1098
+
1099
+ return parent::_toHtml().$javascriptsMain;
1100
+ }
1101
+
1102
+ // ####################################
1103
+
1104
+ private function getLockedData($row)
1105
+ {
1106
+ $listingProductId = $row->getData('id');
1107
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1108
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($listingProductId)->getObjectLocks();
1109
+ $tempArray = array(
1110
+ 'object_locks' => $objectLocks,
1111
+ 'in_action' => !empty($objectLocks),
1112
+ );
1113
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1114
+ }
1115
+
1116
+ return $this->lockedDataCache[$listingProductId];
1117
+ }
1118
+
1119
+ // ####################################
1120
+
1121
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
1122
+ {
1123
+ // ---------------------------------
1124
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1125
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
1126
+ }
1127
+ // ---------------------------------
1128
+
1129
+ // ---------------------------------
1130
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1131
+ // ---------------------------------
1132
+
1133
+ // ---------------------------------
1134
+ $lpId = $row->getData('id');
1135
+
1136
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
1137
+ if (strlen($productTitle) > 60) {
1138
+ $productTitle = substr($productTitle, 0, 60) . '...';
1139
+ }
1140
+ $productTitle = Mage::helper('M2ePro')->__('Assign ASIN/ISBN For &quot;%product_title%&quot;', $productTitle);
1141
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
1142
+ // ---------------------------------
1143
+
1144
+ // ---------------------------------
1145
+
1146
+ $searchSettingsStatus = $row->getData('search_settings_status');
1147
+
1148
+ // ---------------------------------
1149
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
1150
+
1151
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN search in Progress.');
1152
+ $iconSrc = $iconPath.'processing.gif';
1153
+
1154
+ return <<<HTML
1155
+ &nbsp;
1156
+ <a href="javascript: void(0);" title="{$tip}">
1157
+ <img src="{$iconSrc}" alt="">
1158
+ </a>
1159
+ HTML;
1160
+ }
1161
+ // ---------------------------------
1162
+
1163
+ // ---------------------------------
1164
+ $searchSettingsData = $row->getData('search_settings_data');
1165
+
1166
+ $suggestData = array();
1167
+ if (!is_null($searchSettingsData)) {
1168
+ $searchSettingsData = @json_decode($searchSettingsData,true);
1169
+ !empty($searchSettingsData['data']) && $suggestData = $searchSettingsData['data'];
1170
+
1171
+ }
1172
+ // ---------------------------------
1173
+
1174
+ $na = Mage::helper('M2ePro')->__('N/A');
1175
+
1176
+ if (!empty($suggestData)) {
1177
+
1178
+ $tip = Mage::helper('M2ePro')->__('Choose ASIN/ISBN from the list');
1179
+ $iconSrc = $iconPath.'list.png';
1180
+
1181
+ return <<<HTML
1182
+ {$na} &nbsp;
1183
+ <a href="javascript:;" title="{$tip}"
1184
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">
1185
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1186
+ </a>
1187
+ HTML;
1188
+ }
1189
+
1190
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND) {
1191
+
1192
+ $tip = Mage::helper('M2ePro')->__(
1193
+ 'There were no Products found on Amazon according to the Listing Search Settings.'
1194
+ );
1195
+ $tip = Mage::helper('M2ePro')->escapeJs($tip);
1196
+
1197
+ $iconSrc = $iconPath.'error.png';
1198
+
1199
+ return <<<HTML
1200
+ {$na} &nbsp;
1201
+ <a href="javascript: void(0);" title="{$tip}"
1202
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId},'{$tip}');">
1203
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1204
+ </a>
1205
+ HTML;
1206
+ }
1207
+
1208
+ $tip = Mage::helper('M2ePro')->__('Search for ASIN/ISBN');
1209
+ $iconSrc = $iconPath.'search.png';
1210
+
1211
+ return <<<HTML
1212
+ {$na} &nbsp;
1213
+ <a href="javascript:;" title="{$tip}"
1214
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId});">
1215
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1216
+ </a>
1217
+ HTML;
1218
+ }
1219
+
1220
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
1221
+ {
1222
+ $generalId = $row->getData('general_id');
1223
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
1224
+
1225
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1226
+ $generalId,
1227
+ $marketplaceId
1228
+ );
1229
+
1230
+ $generalIdOwnerHtml = '';
1231
+ if($row->getData('is_general_id_owner') == Ess_M2ePro_Model_Amazon_Listing_Product::IS_GENERAL_ID_OWNER_YES){
1232
+
1233
+ $generalIdOwnerHtml = '<br/><span style="font-size: 10px; color: grey;">'.
1234
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
1235
+ '</span>';
1236
+ }
1237
+
1238
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1239
+
1240
+ return <<<HTML
1241
+ <a href="{$url}" target="_blank">{$generalId}</a>{$generalIdOwnerHtml}
1242
+ HTML;
1243
+ }
1244
+
1245
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1246
+
1247
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
1248
+
1249
+ if (!empty($generalIdSearchInfo)) {
1250
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
1251
+ }
1252
+
1253
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
1254
+
1255
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
1256
+
1257
+ $text = <<<HTML
1258
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
1259
+ HTML;
1260
+
1261
+ } else {
1262
+
1263
+ $text = <<<HTML
1264
+ <a href="{$url}" target="_blank">{$generalId}</a>
1265
+ HTML;
1266
+
1267
+ }
1268
+
1269
+ // ---------------------------------
1270
+ $hasInActionLock = $this->getLockedData($row);
1271
+ $hasInActionLock = $hasInActionLock['in_action'];
1272
+ // ---------------------------------
1273
+
1274
+ if ($hasInActionLock) {
1275
+ return $text . $generalIdOwnerHtml;
1276
+ }
1277
+
1278
+ $listingProductId = (int)$row->getData('id');
1279
+
1280
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
1281
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
1282
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
1283
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
1284
+ $variationChildStatuses = $row->getData('variation_child_statuses');
1285
+
1286
+ if ($variationManager->isVariationParent() && !empty($variationChildStatuses)) {
1287
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
1288
+ unset($variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED]);
1289
+
1290
+ foreach ($variationChildStatuses as $variationChildStatus) {
1291
+ if (!empty($variationChildStatus)) {
1292
+ return $text . $generalIdOwnerHtml;
1293
+ }
1294
+ }
1295
+ }
1296
+
1297
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1298
+ $iconSrc = $iconPath.'unassign.png';
1299
+
1300
+ $text .= <<<HTML
1301
+ <a href="javascript:;"
1302
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$listingProductId});"
1303
+ title="{$tip}">
1304
+ <img src="{$iconSrc}" width="16" height="16"/>
1305
+ </a>{$generalIdOwnerHtml}
1306
+ HTML;
1307
+
1308
+ return $text;
1309
+ }
1310
+
1311
+ private function getGeneralIdColumnValueGeneralIdOwner($row)
1312
+ {
1313
+ $text = Mage::helper('M2ePro')->__('New ASIN/ISBN');
1314
+
1315
+ // ---------------------------------
1316
+ $hasInActionLock = $this->getLockedData($row);
1317
+ $hasInActionLock = $hasInActionLock['in_action'];
1318
+ // ---------------------------------
1319
+
1320
+ if ($hasInActionLock) {
1321
+ return $text;
1322
+ }
1323
+
1324
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1325
+
1326
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1327
+ $iconSrc = $iconPath.'unassign.png';
1328
+
1329
+ $lpId = $row->getData('id');
1330
+
1331
+ $text .= <<<HTML
1332
+ <a href="javascript:;"
1333
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$lpId});"
1334
+ title="{$tip}"><img src="{$iconSrc}" width="16" height="16"/>
1335
+ </a>
1336
+ HTML;
1337
+ return $text;
1338
+ }
1339
+
1340
+ // ####################################
1341
+
1342
+ protected function getTemplateDescriptionLinkHtml($listingProduct)
1343
+ {
1344
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
1345
+ 'id' => $listingProduct->getChildObject()->getTemplateDescriptionId()
1346
+ ));
1347
+
1348
+ $helper = Mage::helper('M2ePro');
1349
+ $templateTitle = $listingProduct->getChildObject()->getDescriptionTemplate()->getTitle();
1350
+
1351
+ return <<<HTML
1352
+ <span style="font-size: 9px;">{$helper->__('Description Policy')}:&nbsp;
1353
+ <a target="_blank" href="{$templateDescriptionEditUrl}">
1354
+ {$helper->escapeHtml($templateTitle)}</a>
1355
+ </span>
1356
+ <br/>
1357
+ HTML;
1358
+ }
1359
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonListingViewHelp');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/view/help.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ListingSwitcher.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_ListingSwitcher
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_View_ListingSwitcher_Abstract
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+
16
+ $this->setAddListingUrl('*/adminhtml_common_listing_create/index/step/1/component/amazon/');
17
+ }
18
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Magento/Grid.php ADDED
@@ -0,0 +1,336 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Magento_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
9
+ {
10
+
11
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
18
+
19
+ // Initialization block
20
+ //------------------------------
21
+ $this->setId('amazonListingViewMagentoGrid'.$listingData['id']);
22
+ //------------------------------
23
+
24
+ $this->hideMassactionColumn = true;
25
+ $this->hideMassactionDropDown = true;
26
+ $this->showAdvancedFilterProductsOption = false;
27
+ }
28
+
29
+ // ####################################
30
+
31
+ public function getMainButtonsHtml()
32
+ {
33
+ $data = array(
34
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
35
+ );
36
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
37
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
38
+ );
39
+ $viewModeSwitcherBlock->addData($data);
40
+
41
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
42
+ }
43
+
44
+ // ####################################
45
+
46
+ protected function _prepareCollection()
47
+ {
48
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
49
+
50
+ // Get collection
51
+ //----------------------------
52
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
53
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
54
+ Mage::getModel('catalog/product')->getResource());
55
+ $collection->getSelect()->group('e.entity_id');
56
+ $collection
57
+ ->addAttributeToSelect('name')
58
+ ->joinTable(
59
+ array('cisi' => 'cataloginventory/stock_item'),
60
+ 'product_id=entity_id',
61
+ array('qty' => 'qty',
62
+ 'is_in_stock' => 'is_in_stock'),
63
+ '{{table}}.stock_id=1',
64
+ 'left'
65
+ );
66
+
67
+ //----------------------------
68
+
69
+ $collection->joinTable(
70
+ array('lp' => 'M2ePro/Listing_Product'),
71
+ 'product_id=entity_id',
72
+ array(
73
+ 'id' => 'id',
74
+ 'amazon_status' => 'status',
75
+ 'additional_data' => 'additional_data'
76
+ ),
77
+ array(
78
+ 'listing_id' => (int)$listingData['id']
79
+ )
80
+ );
81
+ $collection->joinTable(
82
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
83
+ 'listing_product_id=id',
84
+ array(
85
+ 'general_id' => 'general_id',
86
+ 'amazon_sku' => 'sku',
87
+ 'online_qty' => 'online_qty',
88
+ 'online_price' => 'online_price',
89
+ 'online_sale_price' => 'online_sale_price',
90
+ 'is_afn_channel' => 'is_afn_channel'
91
+ ),
92
+ NULL,
93
+ 'left'
94
+ );
95
+ //----------------------------
96
+
97
+ // Set filter store
98
+ //----------------------------
99
+ $store = $this->_getStore();
100
+
101
+ if ($store->getId()) {
102
+ $collection->joinAttribute(
103
+ 'price', 'catalog_product/price', 'entity_id', NULL, 'left', $store->getId()
104
+ );
105
+ $collection->joinAttribute(
106
+ 'status', 'catalog_product/status', 'entity_id', NULL, 'inner',$store->getId()
107
+ );
108
+ $collection->joinAttribute(
109
+ 'visibility', 'catalog_product/visibility', 'entity_id', NULL, 'inner',$store->getId()
110
+ );
111
+ $collection->joinAttribute(
112
+ 'thumbnail', 'catalog_product/thumbnail', 'entity_id', NULL, 'left',$store->getId()
113
+ );
114
+ } else {
115
+ $collection->addAttributeToSelect('price');
116
+ $collection->addAttributeToSelect('status');
117
+ $collection->addAttributeToSelect('visibility');
118
+ $collection->addAttributeToSelect('thumbnail');
119
+ }
120
+ //----------------------------
121
+
122
+ // exit($collection->getSelect()->__toString());
123
+
124
+ // Set collection to grid
125
+ $this->setCollection($collection);
126
+
127
+ parent::_prepareCollection();
128
+
129
+ $this->getCollection()->addWebsiteNamesToResult();
130
+
131
+ return $this;
132
+ }
133
+
134
+ protected function _prepareColumns()
135
+ {
136
+ $this->addColumn('product_id', array(
137
+ 'header' => Mage::helper('M2ePro')->__('ID'),
138
+ 'align' => 'right',
139
+ 'width' => '100px',
140
+ 'type' => 'number',
141
+ 'index' => 'entity_id',
142
+ 'filter_index' => 'entity_id',
143
+ 'frame_callback' => array($this, 'callbackColumnProductId')
144
+ ));
145
+
146
+ $this->addColumn('name', array(
147
+ 'header' => Mage::helper('M2ePro')->__('Title'),
148
+ 'align' => 'left',
149
+ //'width' => '100px',
150
+ 'type' => 'text',
151
+ 'index' => 'name',
152
+ 'filter_index' => 'name',
153
+ 'frame_callback' => array($this, 'callbackColumnProductTitle')
154
+ ));
155
+
156
+ $tempTypes = Mage::getSingleton('catalog/product_type')->getOptionArray();
157
+ unset($tempTypes['virtual']);
158
+
159
+ $this->addColumn('type', array(
160
+ 'header' => Mage::helper('M2ePro')->__('Type'),
161
+ 'align' => 'left',
162
+ 'width' => '90px',
163
+ 'type' => 'options',
164
+ 'sortable' => false,
165
+ 'index' => 'type_id',
166
+ 'filter_index' => 'type_id',
167
+ 'options' => $tempTypes
168
+ ));
169
+
170
+ $this->addColumn('is_in_stock', array(
171
+ 'header' => Mage::helper('M2ePro')->__('Stock Availability'),
172
+ 'align' => 'left',
173
+ 'width' => '90px',
174
+ 'type' => 'options',
175
+ 'sortable' => false,
176
+ 'index' => 'is_in_stock',
177
+ 'filter_index' => 'is_in_stock',
178
+ 'options' => array(
179
+ '1' => Mage::helper('M2ePro')->__('In Stock'),
180
+ '0' => Mage::helper('M2ePro')->__('Out of Stock')
181
+ ),
182
+ 'frame_callback' => array($this, 'callbackColumnIsInStock')
183
+ ));
184
+
185
+ $this->addColumn('sku', array(
186
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
187
+ 'align' => 'left',
188
+ 'width' => '90px',
189
+ 'type' => 'text',
190
+ 'index' => 'sku',
191
+ 'filter_index' => 'sku'
192
+ ));
193
+
194
+ $store = $this->_getStore();
195
+
196
+ $this->addColumn('price', array(
197
+ 'header' => Mage::helper('M2ePro')->__('Price'),
198
+ 'align' => 'right',
199
+ 'width' => '100px',
200
+ 'type' => 'price',
201
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
202
+ 'index' => 'price',
203
+ 'filter_index' => 'price',
204
+ 'frame_callback' => array($this, 'callbackColumnPrice')
205
+ ));
206
+
207
+ $this->addColumn('qty', array(
208
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
209
+ 'align' => 'right',
210
+ 'width' => '100px',
211
+ 'type' => 'number',
212
+ 'index' => 'qty',
213
+ 'filter_index' => 'qty',
214
+ 'frame_callback' => array($this, 'callbackColumnQty')
215
+ ));
216
+
217
+ $this->addColumn('visibility', array(
218
+ 'header' => Mage::helper('M2ePro')->__('Visibility'),
219
+ 'align' => 'left',
220
+ 'width' => '90px',
221
+ 'type' => 'options',
222
+ 'sortable' => false,
223
+ 'index' => 'visibility',
224
+ 'filter_index' => 'visibility',
225
+ 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray()
226
+ ));
227
+
228
+ $this->addColumn('status', array(
229
+ 'header' => Mage::helper('M2ePro')->__('Status'),
230
+ 'align' => 'left',
231
+ 'width' => '90px',
232
+ 'type' => 'options',
233
+ 'sortable' => false,
234
+ 'index' => 'status',
235
+ 'filter_index' => 'status',
236
+ 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
237
+ 'frame_callback' => array($this, 'callbackColumnStatus')
238
+ ));
239
+
240
+ if (!Mage::app()->isSingleStoreMode()) {
241
+
242
+ $this->addColumn('websites', array(
243
+ 'header' => Mage::helper('M2ePro')->__('Websites'),
244
+ 'align' => 'left',
245
+ 'width' => '90px',
246
+ 'type' => 'options',
247
+ 'sortable' => false,
248
+ 'index' => 'websites',
249
+ 'filter_index' => 'websites',
250
+ 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash()
251
+ ));
252
+ }
253
+
254
+ return parent::_prepareColumns();
255
+ }
256
+
257
+ // ####################################
258
+
259
+ public function getGridUrl()
260
+ {
261
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
262
+ }
263
+
264
+ public function getRowUrl($row)
265
+ {
266
+ return false;
267
+ }
268
+
269
+ // ####################################
270
+
271
+ protected function _addColumnFilterToCollection($column)
272
+ {
273
+ if ($this->getCollection()) {
274
+ if ($column->getId() == 'websites') {
275
+ $this->getCollection()->joinField('websites',
276
+ 'catalog/product_website',
277
+ 'website_id',
278
+ 'product_id=entity_id',
279
+ null,
280
+ 'left');
281
+ }
282
+ }
283
+ return parent::_addColumnFilterToCollection($column);
284
+ }
285
+
286
+ // ####################################
287
+
288
+ protected function _getStore()
289
+ {
290
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
291
+
292
+ // Get store filter
293
+ //----------------------------
294
+ $storeId = $listing['store_id'];
295
+ //----------------------------
296
+
297
+ return Mage::app()->getStore((int)$storeId);
298
+ }
299
+
300
+ protected function _toHtml()
301
+ {
302
+ $javascriptsMain = <<<JAVASCRIPT
303
+ <script type="text/javascript">
304
+
305
+ if (typeof ListingGridHandlerObj != 'undefined') {
306
+ ListingGridHandlerObj.afterInitPage();
307
+ }
308
+
309
+ Event.observe(window, 'load', function() {
310
+ setTimeout(function() {
311
+ ListingGridHandlerObj.afterInitPage();
312
+ }, 350);
313
+ });
314
+
315
+ </script>
316
+ JAVASCRIPT;
317
+
318
+ return parent::_toHtml().$javascriptsMain;
319
+ }
320
+
321
+ // ####################################
322
+
323
+ protected function isShowRuleBlock()
324
+ {
325
+ /** @var $ruleModel Ess_M2ePro_Model_Magento_Product_Rule */
326
+ $ruleModel = Mage::helper('M2ePro/Data_Global')->getValue('rule_model');
327
+ if ($ruleModel->isEmpty()) {
328
+ return false;
329
+ }
330
+
331
+ return parent::isShowRuleBlock();
332
+ }
333
+
334
+ // ####################################
335
+
336
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_ModeSwitcher
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_View_ModeSwitcher_Abstract
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingViewModeSwitcher');
18
+ //------------------------------
19
+
20
+ $this->setData('component_nick', 'amazon');
21
+ $this->setData('component_label', 'Amazon');
22
+ }
23
+
24
+ protected function getMenuItems()
25
+ {
26
+ return array(
27
+ array(
28
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_AMAZON,
29
+ 'label' => Mage::helper('M2ePro')->__($this->getComponentLabel())
30
+ ),
31
+ array(
32
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_SELLERCENTRAL,
33
+ 'label' => Mage::helper('M2ePro')->__('Seller Сentral')
34
+ ),
35
+ array(
36
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_MAGENTO,
37
+ 'label' => Mage::helper('M2ePro')->__('Magento')
38
+ )
39
+ );
40
+ }
41
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php ADDED
@@ -0,0 +1,833 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Sellercentral_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
9
+ {
10
+ /** @var $sellingFormatTemplate Ess_M2ePro_Model_Amazon_Template_SellingFormat */
11
+ private $sellingFormatTemplate = NULL;
12
+
13
+ private $lockedDataCache = array();
14
+
15
+ private $parentAsins;
16
+
17
+ // ####################################
18
+
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+
23
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
24
+
25
+ // Initialization block
26
+ //------------------------------
27
+ $this->setId('amazonListingViewSellercentralGrid'.$listingData['id']);
28
+ //------------------------------
29
+
30
+ $this->showAdvancedFilterProductsOption = false;
31
+
32
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
33
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
34
+ array('template')
35
+ );
36
+ }
37
+
38
+ // ####################################
39
+
40
+ public function getMainButtonsHtml()
41
+ {
42
+ $data = array(
43
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
44
+ );
45
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
46
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
47
+ );
48
+ $viewModeSwitcherBlock->addData($data);
49
+
50
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
51
+ }
52
+
53
+ // ####################################
54
+
55
+ protected function _prepareCollection()
56
+ {
57
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
58
+
59
+ // Get collection
60
+ //----------------------------
61
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
62
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
63
+ Mage::getModel('catalog/product')->getResource());
64
+ $collection
65
+ ->setListingProductModeOn()
66
+ ->addAttributeToSelect('name')
67
+ ->addAttributeToSelect('sku')
68
+ ->joinTable(
69
+ array('cisi' => 'cataloginventory/stock_item'),
70
+ 'product_id=entity_id',
71
+ array('qty' => 'qty',
72
+ 'is_in_stock' => 'is_in_stock'),
73
+ '{{table}}.stock_id=1',
74
+ 'left'
75
+ );
76
+
77
+ //----------------------------
78
+
79
+ $collection->joinTable(
80
+ array('lp' => 'M2ePro/Listing_Product'),
81
+ 'product_id=entity_id',
82
+ array(
83
+ 'id' => 'id',
84
+ 'amazon_status' => 'status',
85
+ 'component_mode' => 'component_mode',
86
+ 'additional_data' => 'additional_data'
87
+ ),
88
+ array(
89
+ 'listing_id' => (int)$listingData['id'],
90
+ 'status' => array(
91
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED,
92
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED,
93
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED
94
+ )
95
+ )
96
+ );
97
+ $collection->joinTable(
98
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
99
+ 'listing_product_id=id',
100
+ array(
101
+ 'general_id' => 'general_id',
102
+ 'search_settings_status' => 'search_settings_status',
103
+ 'amazon_sku' => 'sku',
104
+ 'online_qty' => 'online_qty',
105
+ 'online_price' => 'online_price',
106
+ 'online_sale_price' => 'online_sale_price',
107
+ 'is_afn_channel' => 'is_afn_channel',
108
+ 'is_general_id_owner' => 'is_general_id_owner',
109
+ 'variation_child_statuses' => 'variation_child_statuses',
110
+ 'is_variation_parent' => 'is_variation_parent',
111
+ 'variation_parent_id' => 'variation_parent_id'
112
+ ),
113
+ '{{table}}.is_variation_parent = 0'
114
+ );
115
+ //----------------------------
116
+ // exit($collection->getSelect()->__toString());
117
+
118
+ // Change default Magento message when items count is zero
119
+ $collectionForCounting = clone $collection;
120
+
121
+ if (count($collectionForCounting) === 0) {
122
+ $this->setEmptyText(
123
+ Mage::helper('M2ePro')->__(
124
+ 'Only Simple and Child Products listed on Amazon will be shown in Seller Сentral View Mode.'
125
+ )
126
+ );
127
+ }
128
+
129
+ // Set collection to grid
130
+ $this->setCollection($collection);
131
+
132
+ return parent::_prepareCollection();
133
+ }
134
+
135
+ protected function _prepareColumns()
136
+ {
137
+ $this->addColumn('product_id', array(
138
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
139
+ 'align' => 'right',
140
+ 'width' => '100px',
141
+ 'type' => 'number',
142
+ 'index' => 'entity_id',
143
+ 'filter_index' => 'entity_id',
144
+ 'frame_callback' => array($this, 'callbackColumnProductId')
145
+ ));
146
+
147
+ $this->addColumn('name', array(
148
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
149
+ 'align' => 'left',
150
+ 'width' => '300px',
151
+ 'type' => 'text',
152
+ 'index' => 'name',
153
+ 'filter_index' => 'name',
154
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
155
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
156
+ ));
157
+
158
+ $this->addColumn('general_id', array(
159
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
160
+ 'align' => 'left',
161
+ 'width' => '100px',
162
+ 'type' => 'text',
163
+ 'index' => 'general_id',
164
+ 'filter_index' => 'general_id',
165
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
166
+ ));
167
+
168
+ $this->addColumn('online_qty', array(
169
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
170
+ 'align' => 'right',
171
+ 'width' => '70px',
172
+ 'type' => 'number',
173
+ 'index' => 'online_qty',
174
+ 'filter_index' => 'online_qty',
175
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
176
+ ));
177
+
178
+ $this->addColumn('online_price', array(
179
+ 'header' => Mage::helper('M2ePro')->__('Price'),
180
+ 'align' => 'right',
181
+ 'width' => '70px',
182
+ 'type' => 'number',
183
+ 'index' => 'online_price',
184
+ 'filter_index' => 'online_price',
185
+ 'frame_callback' => array($this, 'callbackColumnPrice')
186
+ ));
187
+
188
+ $this->addColumn('is_afn_channel', array(
189
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
190
+ 'align' => 'right',
191
+ 'width' => '90px',
192
+ 'index' => 'is_afn_channel',
193
+ 'filter_index' => 'is_afn_channel',
194
+ 'type' => 'options',
195
+ 'sortable' => false,
196
+ 'options' => array(
197
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
198
+ 1 => Mage::helper('M2ePro')->__('Amazon')
199
+ ),
200
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
201
+ ));
202
+
203
+ $this->addColumn('status', array(
204
+ 'header' => Mage::helper('M2ePro')->__('Status'),
205
+ 'width' => '125px',
206
+ 'index' => 'amazon_status',
207
+ 'filter_index' => 'amazon_status',
208
+ 'type' => 'options',
209
+ 'sortable' => false,
210
+ 'options' => array(
211
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
212
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
213
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
214
+ ),
215
+ 'frame_callback' => array($this, 'callbackColumnStatus')
216
+ ));
217
+
218
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
219
+ $this->addColumn('developer_action', array(
220
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
221
+ 'align' => 'left',
222
+ 'width' => '100px',
223
+ 'type' => 'text',
224
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
225
+ 'index' => 'value',
226
+ 'filter' => false,
227
+ 'sortable' => false,
228
+ 'js_handler' => 'ListingGridHandlerObj'
229
+ ));
230
+ }
231
+
232
+ return parent::_prepareColumns();
233
+ }
234
+
235
+ protected function _prepareMassaction()
236
+ {
237
+ // Set massaction identifiers
238
+ //--------------------------------
239
+ $this->setMassactionIdField('id');
240
+ $this->setMassactionIdFieldOnlyIndexValue(true);
241
+ //--------------------------------
242
+
243
+ // Set mass-action
244
+ //--------------------------------
245
+ $this->getMassactionBlock()->addItem('revise', array(
246
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
247
+ 'url' => '',
248
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
249
+ ));
250
+
251
+ $this->getMassactionBlock()->addItem('relist', array(
252
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
253
+ 'url' => '',
254
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
255
+ ));
256
+
257
+ $this->getMassactionBlock()->addItem('stop', array(
258
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
259
+ 'url' => '',
260
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
261
+ ));
262
+
263
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
264
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
265
+ 'url' => '',
266
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
267
+ ));
268
+
269
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
270
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
271
+ 'url' => '',
272
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
273
+ ));
274
+ //--------------------------------
275
+
276
+ return parent::_prepareMassaction();
277
+ }
278
+
279
+ // ####################################
280
+
281
+ public function callbackColumnProductId($value, $row, $column, $isExport)
282
+ {
283
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
284
+
285
+ $storeId = (int)$listingData['store_id'];
286
+
287
+ $withoutImageHtml = '<a href="'
288
+ .$this->getUrl('adminhtml/catalog_product/edit',
289
+ array('id' => $value))
290
+ .'" target="_blank">'.$value.'</a>';
291
+
292
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
293
+ ->getGroupValue('/view/',
294
+ 'show_products_thumbnails');
295
+ if (!$showProductsThumbnails) {
296
+ return $withoutImageHtml;
297
+ }
298
+
299
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
300
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
301
+ $magentoProduct->setProductId($value);
302
+ $magentoProduct->setStoreId($storeId);
303
+
304
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
305
+ if (is_null($imageUrlResized)) {
306
+ return $withoutImageHtml;
307
+ }
308
+
309
+ $imageHtml = $value.'<hr style="border: 1px solid silver; border-bottom: none;"><img src="'.
310
+ $imageUrlResized.'" />';
311
+ $withImageHtml = str_replace('>'.$value.'<','>'.$imageHtml.'<',$withoutImageHtml);
312
+
313
+ return $withImageHtml;
314
+ }
315
+
316
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
317
+ {
318
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
319
+
320
+ $value = '<span>'.$productTitle.'</span>';
321
+
322
+ $tempSku = $row->getData('sku');
323
+ is_null($tempSku)
324
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
325
+
326
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
327
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
328
+
329
+ $listingProduct = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'));
330
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
331
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
332
+
333
+ if (!$variationManager->isVariationProduct()) {
334
+ return $value;
335
+ }
336
+
337
+ if ($variationManager->isRelationChildType()) {
338
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
339
+ $channelOptions = $variationManager->getTypeModel()->getChannelOptions();
340
+
341
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
342
+ Mage::helper('M2ePro')->__('Magento Variation') . '</div>';
343
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
344
+ foreach ($productOptions as $attribute => $option) {
345
+ !$option && $option = '--';
346
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
347
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '</br>';
348
+ }
349
+ $value .= '</div>';
350
+
351
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
352
+ Mage::helper('M2ePro')->__('Amazon Variation') . '</div>';
353
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
354
+ foreach ($channelOptions as $attribute => $option) {
355
+ !$option && $option = '--';
356
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
357
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '</br>';
358
+ }
359
+ $value .= '</div>';
360
+
361
+ return $value;
362
+ }
363
+
364
+ $productOptions = array();
365
+ if ($listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()) {
366
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
367
+ ->getTypeModel()->getProductOptions();
368
+ }
369
+
370
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
371
+ foreach ($productOptions as $attribute => $option) {
372
+ !$option && $option = '--';
373
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
374
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
375
+ }
376
+ $value .= '</div>';
377
+
378
+ return $value;
379
+ }
380
+
381
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
382
+ {
383
+ if (is_null($value) || $value === '') {
384
+ return Mage::helper('M2ePro')->__('N/A');
385
+ }
386
+
387
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
388
+
389
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
390
+ $value,
391
+ $marketplaceId
392
+ );
393
+
394
+ $parentAsinHtml = '';
395
+ $variationParentId = $row->getData('variation_parent_id');
396
+ if(!empty($variationParentId)){
397
+ $parentAsinHtml = '<br><span style="font-size: 10px; color: grey; line-height: 1;">'.
398
+ Mage::helper('M2ePro')->__('child ASIN/ISBN</br>of parent %parent_asin%',
399
+ $this->getParentAsin($row->getData('id'))) . '</span>';
400
+ }
401
+
402
+ $generalIdOwnerHtml = '';
403
+ if($row->getData('is_general_id_owner') == 1){
404
+ $generalIdOwnerHtml = '<br/><span style="font-size: 10px; color: grey; margin-top: 10px; display: block;">'.
405
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
406
+ '</span>';
407
+ }
408
+ return <<<HTML
409
+ <a href="{$url}" target="_blank">{$value}</a>{$parentAsinHtml}{$generalIdOwnerHtml}
410
+ HTML;
411
+ }
412
+
413
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
414
+ {
415
+ if ((int)$row->getData('is_in_stock') <= 0) {
416
+ return '<span style="color: red;">'.$value.'</span>';
417
+ }
418
+
419
+ return $value;
420
+ }
421
+
422
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
423
+ {
424
+ if ((int)$row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
425
+ if (is_null($value) || $value === '') {
426
+ return Mage::helper('M2ePro')->__('N/A');
427
+ }
428
+ } else {
429
+ if (is_null($value) || $value === '') {
430
+ return '<i style="color:gray;">receiving...</i>';
431
+ }
432
+ }
433
+
434
+ if ((bool)$row->getData('is_afn_channel')) {
435
+ return '--';
436
+ }
437
+
438
+ if ($value <= 0) {
439
+ return '<span style="color: red;">0</span>';
440
+ }
441
+
442
+ return $value;
443
+ }
444
+
445
+ public function callbackColumnPrice($value, $row, $column, $isExport)
446
+ {
447
+ if ((int)$row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
448
+ if (is_null($value) || $value === '') {
449
+ return Mage::helper('M2ePro')->__('N/A');
450
+ }
451
+ } else {
452
+ if (is_null($value) || $value === '') {
453
+ return '<i style="color:gray;">receiving...</i>';
454
+ }
455
+ }
456
+
457
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
458
+ $currency = Mage::helper('M2ePro/Component_Amazon')
459
+ ->getCachedObject('Marketplace',$marketplaceId)
460
+ ->getChildObject()
461
+ ->getDefaultCurrency();
462
+
463
+ $salePriceValue = $row->getData('online_sale_price');
464
+ if (is_null($salePriceValue) ||
465
+ (float)$salePriceValue <= 0) {
466
+ $salePriceValue = null;
467
+ } else {
468
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePriceValue);
469
+ }
470
+
471
+ if ((float)$value <= 0) {
472
+ $result = '<span style="color: #f00;">0</span>';
473
+ } else {
474
+ $result = Mage::app()->getLocale()->currency($currency)->toCurrency($value);
475
+ }
476
+
477
+ return $result.($salePriceValue ? ' <br/><span style="color:gray;">'.$salePriceValue.'</span>' : '');
478
+ }
479
+
480
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
481
+ {
482
+ if (is_null($value) || $value === '') {
483
+ return Mage::helper('M2ePro')->__('N/A');
484
+ }
485
+
486
+ switch ($row->getData('is_afn_channel')) {
487
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
488
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
489
+ break;
490
+
491
+ default:
492
+ break;
493
+ }
494
+
495
+ return $value;
496
+ }
497
+
498
+ public function callbackColumnStatus($value, $row, $column, $isExport)
499
+ {
500
+ switch ($row->getData('amazon_status')) {
501
+
502
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
503
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
504
+ $value = '<span style="color: gray;">' . $value . '</span>';
505
+ break;
506
+
507
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
508
+ $value = '<span style="color: green;">' . $value . '</span>';
509
+ break;
510
+
511
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
512
+ $value = '<span style="color: red;">'.$value.'</span>';
513
+ break;
514
+
515
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
516
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
517
+ break;
518
+
519
+ default:
520
+ break;
521
+ }
522
+
523
+ $value .= $this->getViewLogIconHtml($row->getData('id'));
524
+
525
+ $tempLocks = $this->getLockedData($row);
526
+ $tempLocks = $tempLocks['object_locks'];
527
+
528
+ foreach ($tempLocks as $lock) {
529
+
530
+ switch ($lock->getTag()) {
531
+
532
+ case 'list_action':
533
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
534
+ break;
535
+
536
+ case 'relist_action':
537
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
538
+ break;
539
+
540
+ case 'revise_action':
541
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
542
+ break;
543
+
544
+ case 'stop_action':
545
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
546
+ break;
547
+
548
+ case 'stop_and_remove_action':
549
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
550
+ break;
551
+
552
+ case 'delete_and_remove_action':
553
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
554
+ break;
555
+
556
+ default:
557
+ break;
558
+
559
+ }
560
+ }
561
+
562
+ return $value;
563
+ }
564
+
565
+ protected function callbackFilterTitle($collection, $column)
566
+ {
567
+ $value = $column->getFilter()->getValue();
568
+
569
+ if ($value == null) {
570
+ return;
571
+ }
572
+
573
+ $collection->addFieldToFilter(
574
+ array(
575
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
576
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
577
+ )
578
+ );
579
+ }
580
+
581
+ //----------------------------------------
582
+
583
+ public function getViewLogIconHtml($listingProductId)
584
+ {
585
+ $listingProductId = (int)$listingProductId;
586
+
587
+ // Get last messages
588
+ //--------------------------
589
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
590
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
591
+
592
+ $dbSelect = $connRead->select()
593
+ ->from(
594
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
595
+ array('action_id','action','type','description','create_date','initiator')
596
+ )
597
+ ->where('`listing_product_id` = ?',$listingProductId)
598
+ ->where('`action_id` IS NOT NULL')
599
+ ->order(array('id DESC'))
600
+ ->limit(30);
601
+
602
+ $logRows = $connRead->fetchAll($dbSelect);
603
+ //--------------------------
604
+
605
+ // Get grouped messages by action_id
606
+ //--------------------------
607
+ $actionsRows = array();
608
+ $tempActionRows = array();
609
+ $lastActionId = false;
610
+
611
+ foreach ($logRows as $row) {
612
+
613
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
614
+
615
+ if ($row['action_id'] !== $lastActionId) {
616
+ if (count($tempActionRows) > 0) {
617
+ $actionsRows[] = array(
618
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
619
+ 'date' => $this->getMainDateForActionId($tempActionRows),
620
+ 'action' => $this->getActionForAction($tempActionRows[0]),
621
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
622
+ 'items' => $tempActionRows
623
+ );
624
+ $tempActionRows = array();
625
+ }
626
+ $lastActionId = $row['action_id'];
627
+ }
628
+ $tempActionRows[] = $row;
629
+ }
630
+
631
+ if (count($tempActionRows) > 0) {
632
+ $actionsRows[] = array(
633
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
634
+ 'date' => $this->getMainDateForActionId($tempActionRows),
635
+ 'action' => $this->getActionForAction($tempActionRows[0]),
636
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
637
+ 'items' => $tempActionRows
638
+ );
639
+ }
640
+
641
+ if (count($actionsRows) <= 0) {
642
+ return '';
643
+ }
644
+
645
+ $tips = array(
646
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last action was completed successfully.',
647
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last action was completed with error(s).',
648
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last action was completed with warning(s).'
649
+ );
650
+
651
+ $icons = array(
652
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
653
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
654
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
655
+ );
656
+
657
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
658
+ 'entity_id' => $listingProductId,
659
+ 'rows' => $actionsRows,
660
+ 'tips' => $tips,
661
+ 'icons' => $icons,
662
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
663
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
664
+ ));
665
+
666
+ return $summary->toHtml();
667
+ }
668
+
669
+ public function getActionForAction($actionRows)
670
+ {
671
+ $string = '';
672
+
673
+ switch ($actionRows['action']) {
674
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
675
+ $string = Mage::helper('M2ePro')->__('List');
676
+ break;
677
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
678
+ $string = Mage::helper('M2ePro')->__('Relist');
679
+ break;
680
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
681
+ $string = Mage::helper('M2ePro')->__('Revise');
682
+ break;
683
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
684
+ $string = Mage::helper('M2ePro')->__('Stop');
685
+ break;
686
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
687
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
688
+ break;
689
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
690
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
691
+ break;
692
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
693
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
694
+ break;
695
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANGE_STATUS_ON_CHANNEL:
696
+ $string = Mage::helper('M2ePro')->__('Status Change');
697
+ break;
698
+ }
699
+
700
+ return $string;
701
+ }
702
+
703
+ public function getInitiatorForAction($actionRows)
704
+ {
705
+ $string = '';
706
+
707
+ switch ((int)$actionRows['initiator']) {
708
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
709
+ $string = '';
710
+ break;
711
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
712
+ $string = Mage::helper('M2ePro')->__('Manual');
713
+ break;
714
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
715
+ $string = Mage::helper('M2ePro')->__('Automatic');
716
+ break;
717
+ }
718
+
719
+ return $string;
720
+ }
721
+
722
+ public function getMainTypeForActionId($actionRows)
723
+ {
724
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
725
+
726
+ foreach ($actionRows as $row) {
727
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
728
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
729
+ break;
730
+ }
731
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
732
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
733
+ }
734
+ }
735
+
736
+ return $type;
737
+ }
738
+
739
+ public function getMainDateForActionId($actionRows)
740
+ {
741
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
742
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
743
+ }
744
+
745
+ // ####################################
746
+
747
+ public function getGridUrl()
748
+ {
749
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
750
+ }
751
+
752
+ public function getRowUrl($row)
753
+ {
754
+ return false;
755
+ }
756
+
757
+ // ####################################
758
+
759
+ protected function _toHtml()
760
+ {
761
+ $javascriptsMain = <<<JAVASCRIPT
762
+ <script type="text/javascript">
763
+
764
+ if (typeof ListingGridHandlerObj != 'undefined') {
765
+ ListingGridHandlerObj.afterInitPage();
766
+ }
767
+
768
+ Event.observe(window, 'load', function() {
769
+ setTimeout(function() {
770
+ ListingGridHandlerObj.afterInitPage();
771
+ }, 350);
772
+ });
773
+
774
+ </script>
775
+ JAVASCRIPT;
776
+
777
+ return parent::_toHtml().$javascriptsMain;
778
+ }
779
+
780
+ // ####################################
781
+
782
+ private function getLockedData($row)
783
+ {
784
+ $listingProductId = $row->getData('id');
785
+ if (!isset($this->lockedDataCache[$listingProductId])) {
786
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
787
+ $tempArray = array(
788
+ 'object_locks' => $objectLocks,
789
+ 'in_action' => !empty($objectLocks),
790
+ );
791
+ $this->lockedDataCache[$listingProductId] = $tempArray;
792
+ }
793
+
794
+ return $this->lockedDataCache[$listingProductId];
795
+ }
796
+
797
+ // ####################################
798
+
799
+ private function getParentAsin($childId)
800
+ {
801
+ if (is_null($this->parentAsins)) {
802
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
803
+ $tableAmazonListingProduct = Mage::getSingleton('core/resource')
804
+ ->getTableName('m2epro_amazon_listing_product');
805
+
806
+ $select = $connRead->select();
807
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id','variation_parent_id'))
808
+ ->where('listing_product_id IN (?)', $this->getCollection()->getAllIds())
809
+ ->where('variation_parent_id IS NOT NULL');
810
+
811
+ $parentIds = Mage::getResourceModel('core/config')
812
+ ->getReadConnection()
813
+ ->fetchPairs($select);
814
+
815
+ $select = $connRead->select();
816
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id', 'general_id'))
817
+ ->where('listing_product_id IN (?)', $parentIds);
818
+
819
+ $parentAsins = Mage::getResourceModel('core/config')
820
+ ->getReadConnection()
821
+ ->fetchPairs($select);
822
+
823
+ $this->parentAsins = array();
824
+ foreach ($parentIds as $childId => $parentId) {
825
+ $this->parentAsins[$childId] = $parentAsins[$parentId];
826
+ }
827
+ }
828
+
829
+ return $this->parentAsins[$childId];
830
+ }
831
+
832
+ // ####################################
833
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Marketplace/Form.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Marketplace_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonMarketplaceForm');
18
+ $this->setContainerId('magento_block_amazon_marketplaces');
19
+ $this->setTemplate('M2ePro/common/amazon/marketplace.phtml');
20
+ //------------------------------
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ return parent::_prepareForm();
26
+ }
27
+
28
+ // ########################################
29
+
30
+ protected function _beforeToHtml()
31
+ {
32
+ //----------------------------
33
+ /** @var Ess_M2ePro_Model_Marketplace[] $marketplaces */
34
+ $marketplaces = Mage::helper('M2ePro/Component_Amazon')->getCollection('Marketplace')
35
+ ->setOrder('group_title', 'ASC')
36
+ ->setOrder('sorder','ASC')
37
+ ->setOrder('title','ASC')
38
+ ->getItems();
39
+ $groups = array();
40
+ $storedStatuses = array();
41
+ $previewGroup = '';
42
+ $idGroup = 1;
43
+ foreach($marketplaces as $marketplace) {
44
+
45
+ if ($marketplace->getGroupTitle() != $previewGroup) {
46
+ $previewGroup = $marketplace->getGroupTitle();
47
+ $groups[] = array(
48
+ 'id' => $idGroup,
49
+ 'title' => $previewGroup,
50
+ 'marketplaces' => array()
51
+ );
52
+ $idGroup++;
53
+ }
54
+
55
+ $storedStatuses[] = array(
56
+ 'marketplace_id' => $marketplace->getId(),
57
+ 'status' => $marketplace->getStatus()
58
+ );
59
+
60
+ $isLocked = (bool)Mage::helper('M2ePro/Component_Amazon')->getCollection('Account')
61
+ ->addFieldToFilter('marketplace_id', $marketplace->getId())
62
+ ->getSize();
63
+
64
+ $marketplace = array(
65
+ 'instance' => $marketplace,
66
+ 'params' => array('locked' => $isLocked)
67
+ );
68
+
69
+ $groups[count($groups)-1]['marketplaces'][] = $marketplace;
70
+ }
71
+
72
+ $this->groups = $groups;
73
+ $this->storedStatuses = $storedStatuses;
74
+ //----------------------------
75
+
76
+ //------------------------------
77
+ $data = array(
78
+ 'label' => Mage::helper('M2ePro')->__('Update Now'),
79
+ 'onclick' => 'MarketplaceHandlerObj.runSingleSynchronization(this)',
80
+ 'class' => 'run_single_button'
81
+ );
82
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
83
+ $this->setChild('run_single_button', $buttonBlock);
84
+ //------------------------------
85
+
86
+ return parent::_beforeToHtml();
87
+ }
88
+
89
+ // ########################################
90
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_Edit_ShippingAddress
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonOrderEditShippingAddress');
17
+ $this->_blockGroup = 'M2ePro';
18
+ $this->_controller = 'adminhtml_common_amazon_order_edit';
19
+ $this->_mode = 'shippingAddress';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $this->_headerText = Mage::helper('M2ePro')->__('Edit Shipping Address');
25
+ //------------------------------
26
+
27
+ // Set buttons actions
28
+ //------------------------------
29
+ $this->removeButton('back');
30
+ $this->removeButton('reset');
31
+ $this->removeButton('delete');
32
+ $this->removeButton('add');
33
+ $this->removeButton('save');
34
+ $this->removeButton('edit');
35
+ //------------------------------
36
+
37
+ if (!is_null($this->getRequest()->getParam('back'))) {
38
+ //------------------------------
39
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
40
+ $this->_addButton('back', array(
41
+ 'label' => Mage::helper('M2ePro')->__('Back'),
42
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
43
+ 'class' => 'back'
44
+ ));
45
+ //------------------------------
46
+ } else {
47
+ //------------------------------
48
+ $url = $this->getUrl('*/*/view', array('id' => $this->getRequest()->getParam('id')));
49
+ $this->_addButton('back', array(
50
+ 'label' => Mage::helper('M2ePro')->__('Back'),
51
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
52
+ 'class' => 'back'
53
+ ));
54
+ //------------------------------
55
+ }
56
+
57
+ //------------------------------
58
+ $this->_addButton('save', array(
59
+ 'label' => Mage::helper('M2ePro')->__('Save Order Address'),
60
+ 'onclick' => 'CommonHandlerObj.save_click()',
61
+ 'class' => 'save'
62
+ ));
63
+ //------------------------------
64
+ }
65
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress/Form.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_Edit_ShippingAddress_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ private $order;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonOrderEditShippingAddressForm');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/order/edit/shipping_address.phtml');
21
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
22
+ }
23
+
24
+ protected function _prepareForm()
25
+ {
26
+ $form = new Varien_Data_Form(array(
27
+ 'id' => 'edit_form',
28
+ 'action' => $this->getUrl('*/*/save'),
29
+ 'method' => 'post',
30
+ 'enctype' => 'multipart/form-data'
31
+ ));
32
+
33
+ $form->setUseContainer(true);
34
+ $this->setForm($form);
35
+
36
+ return parent::_prepareForm();
37
+ }
38
+
39
+ protected function _beforeToHtml()
40
+ {
41
+ try {
42
+ $regionCode = $this->order->getShippingAddress()->getRegionCode();
43
+ } catch (Exception $e) {
44
+ $regionCode = null;
45
+ }
46
+
47
+ $this->setData('countries', Mage::helper('M2ePro/Magento')->getCountries());
48
+ $this->setData('buyer_name', $this->order->getData('buyer_name'));
49
+ $this->setData('buyer_email', $this->order->getData('buyer_email'));
50
+ $this->setData('address', $this->order->getShippingAddress()->getData());
51
+ $this->setData('region_code', $regionCode);
52
+
53
+ return parent::_beforeToHtml();
54
+ }
55
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Grid.php ADDED
@@ -0,0 +1,558 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ /** @var $itemsCollection Ess_M2ePro_Model_Mysql4_Order_Item_Collection */
10
+ private $itemsCollection = NULL;
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonOrderGrid');
19
+ //------------------------------
20
+
21
+ // Set default values
22
+ //------------------------------
23
+ $this->setDefaultSort('purchase_create_date');
24
+ $this->setDefaultDir('DESC');
25
+ $this->setSaveParametersInSession(true);
26
+ $this->setUseAjax(true);
27
+ //------------------------------
28
+ }
29
+
30
+ public function getMassactionBlockName()
31
+ {
32
+ return 'M2ePro/adminhtml_grid_massaction';
33
+ }
34
+
35
+ protected function _prepareCollection()
36
+ {
37
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Order');
38
+
39
+ $collection->getSelect()
40
+ ->joinLeft(
41
+ array('so' => Mage::getSingleton('core/resource')->getTableName('sales/order')),
42
+ '(so.entity_id = `main_table`.magento_order_id)',
43
+ array('magento_order_num' => 'increment_id'));
44
+
45
+ // Add Filter By Account
46
+ //------------------------------
47
+ if ($accountId = $this->getRequest()->getParam('amazonAccount')) {
48
+ $collection->addFieldToFilter('`main_table`.account_id', $accountId);
49
+ }
50
+ //------------------------------
51
+
52
+ // Add Filter By Marketplace
53
+ //------------------------------
54
+ if ($marketplaceId = $this->getRequest()->getParam('amazonMarketplace')) {
55
+ $collection->addFieldToFilter('`main_table`.marketplace_id', $marketplaceId);
56
+ }
57
+ //------------------------------
58
+
59
+ // Add Not Created Magento Orders Filter
60
+ //------------------------------
61
+ if ($this->getRequest()->getParam('not_created_only')) {
62
+ $collection->addFieldToFilter('magento_order_id', array('null' => true));
63
+ }
64
+ //------------------------------
65
+
66
+ $this->setCollection($collection);
67
+ return parent::_prepareCollection();
68
+ }
69
+
70
+ protected function _afterLoadCollection()
71
+ {
72
+ $this->itemsCollection = Mage::helper('M2ePro/Component_Amazon')
73
+ ->getCollection('Order_Item')
74
+ ->addFieldToFilter('order_id', array('in' => $this->getCollection()->getColumnValues('id')));
75
+
76
+ return parent::_afterLoadCollection();
77
+ }
78
+
79
+ protected function _prepareColumns()
80
+ {
81
+ $this->addColumn('purchase_create_date', array(
82
+ 'header' => Mage::helper('M2ePro')->__('Sale Date'),
83
+ 'align' => 'left',
84
+ 'type' => 'datetime',
85
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
86
+ 'index' => 'purchase_create_date',
87
+ 'width' => '170px'
88
+ ));
89
+
90
+ $this->addColumn('magento_order_num', array(
91
+ 'header' => Mage::helper('M2ePro')->__('Magento Order #'),
92
+ 'align' => 'left',
93
+ 'index' => 'so.increment_id',
94
+ 'width' => '110px',
95
+ 'frame_callback' => array($this, 'callbackColumnMagentoOrder')
96
+ ));
97
+
98
+ $this->addColumn('amazon_order_id', array(
99
+ 'header' => Mage::helper('M2ePro')->__('Amazon Order #'),
100
+ 'align' => 'left',
101
+ 'width' => '110px',
102
+ 'index' => 'amazon_order_id',
103
+ 'frame_callback' => array($this, 'callbackColumnAmazonOrderId')
104
+ ));
105
+
106
+ $this->addColumn('amazon_order_items', array(
107
+ 'header' => Mage::helper('M2ePro')->__('Items'),
108
+ 'align' => 'left',
109
+ 'index' => 'amazon_order_items',
110
+ 'sortable' => false,
111
+ 'width' => '*',
112
+ 'frame_callback' => array($this, 'callbackColumnItems'),
113
+ 'filter_condition_callback' => array($this, 'callbackFilterItems')
114
+ ));
115
+
116
+ $this->addColumn('buyer', array(
117
+ 'header' => Mage::helper('M2ePro')->__('Buyer'),
118
+ 'align' => 'left',
119
+ 'index' => 'buyer_name',
120
+ 'width' => '120px',
121
+ 'frame_callback' => array($this, 'callbackColumnBuyer'),
122
+ 'filter_condition_callback' => array($this, 'callbackFilterBuyer')
123
+ ));
124
+
125
+ $this->addColumn('paid_amount', array(
126
+ 'header' => Mage::helper('M2ePro')->__('Total Paid'),
127
+ 'align' => 'left',
128
+ 'width' => '110px',
129
+ 'index' => 'paid_amount',
130
+ 'type' => 'number',
131
+ 'frame_callback' => array($this, 'callbackColumnTotal')
132
+ ));
133
+
134
+ $this->addColumn('is_afn_channel', array(
135
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
136
+ 'width' => '100px',
137
+ 'index' => 'is_afn_channel',
138
+ 'filter_index' => 'second_table.is_afn_channel',
139
+ 'type' => 'options',
140
+ 'sortable' => false,
141
+ 'options' => array(
142
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
143
+ 1 => Mage::helper('M2ePro')->__('Amazon')
144
+ ),
145
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
146
+ ));
147
+
148
+ $this->addColumn('reservation_state', array(
149
+ 'header' => Mage::helper('M2ePro')->__('Reservation'),
150
+ 'align' => 'left',
151
+ 'width' => '50px',
152
+ 'index' => 'reservation_state',
153
+ 'type' => 'options',
154
+ 'options' => array(
155
+ Ess_M2ePro_Model_Order_Reserve::STATE_UNKNOWN => Mage::helper('M2ePro')->__('N/A'),
156
+ Ess_M2ePro_Model_Order_Reserve::STATE_PLACED => Mage::helper('M2ePro')->__('Reserved'),
157
+ Ess_M2ePro_Model_Order_Reserve::STATE_RELEASED => Mage::helper('M2ePro')->__('Released'),
158
+ Ess_M2ePro_Model_Order_Reserve::STATE_CANCELED => Mage::helper('M2ePro')->__('Canceled'),
159
+ )
160
+ ));
161
+
162
+ $helper = Mage::helper('M2ePro');
163
+
164
+ $this->addColumn('status', array(
165
+ 'header' => Mage::helper('M2ePro')->__('Status'),
166
+ 'align' => 'left',
167
+ 'width' => '50px',
168
+ 'index' => 'status',
169
+ 'filter_index' => 'second_table.status',
170
+ 'type' => 'options',
171
+ 'options' => array(
172
+ Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => $helper->__('Pending'),
173
+ Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED => $helper->__('Unshipped'),
174
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED_PARTIALLY => $helper->__('Partially Shipped'),
175
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => $helper->__('Shipped'),
176
+ Ess_M2ePro_Model_Amazon_Order::STATUS_INVOICE_UNCONFIRMED => $helper->__('Invoice Not Confirmed'),
177
+ Ess_M2ePro_Model_Amazon_Order::STATUS_UNFULFILLABLE => $helper->__('Unfulfillable'),
178
+ Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => $helper->__('Canceled')
179
+ ),
180
+ 'frame_callback' => array($this, 'callbackColumnStatus')
181
+ ));
182
+
183
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_order/index', array(
184
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
185
+ ));
186
+
187
+ $this->addColumn('action', array(
188
+ 'header' => Mage::helper('M2ePro')->__('Action'),
189
+ 'width' => '80px',
190
+ 'type' => 'action',
191
+ 'getter' => 'getId',
192
+ 'actions' => array(
193
+ array(
194
+ 'caption' => Mage::helper('M2ePro')->__('View'),
195
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/view'),
196
+ 'field' => 'id'
197
+ ),
198
+ array(
199
+ 'caption' => Mage::helper('M2ePro')->__('Edit Shipping Address'),
200
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/editShippingAddress/back/'.$back.'/'),
201
+ 'field' => 'id'
202
+ ),
203
+ array(
204
+ 'caption' => Mage::helper('M2ePro')->__('Create Order'),
205
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/createMagentoOrder'),
206
+ 'field' => 'id'
207
+ ),
208
+ array(
209
+ 'caption' => Mage::helper('M2ePro')->__('Mark As Shipped'),
210
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/updateShippingStatus'),
211
+ 'field' => 'id'
212
+ )
213
+ ),
214
+ 'filter' => false,
215
+ 'sortable' => false,
216
+ 'is_system' => true
217
+ ));
218
+
219
+ return parent::_prepareColumns();
220
+ }
221
+
222
+ protected function _prepareMassaction()
223
+ {
224
+ // Set massaction identifiers
225
+ //--------------------------------
226
+ $this->setMassactionIdField('main_table.id');
227
+ $this->getMassactionBlock()->setFormFieldName('ids');
228
+ //--------------------------------
229
+
230
+ // Set mass-action
231
+ //--------------------------------
232
+ $this->getMassactionBlock()->addItem('reservation_place', array(
233
+ 'label' => Mage::helper('M2ePro')->__('Reserve QTY'),
234
+ 'url' => $this->getUrl('*/adminhtml_order/reservationPlace'),
235
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
236
+ ));
237
+
238
+ $this->getMassactionBlock()->addItem('reservation_cancel', array(
239
+ 'label' => Mage::helper('M2ePro')->__('Cancel QTY Reserve'),
240
+ 'url' => $this->getUrl('*/adminhtml_order/reservationCancel'),
241
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
242
+ ));
243
+
244
+ $this->getMassactionBlock()->addItem('ship', array(
245
+ 'label' => Mage::helper('M2ePro')->__('Mark Order(s) as Shipped'),
246
+ 'url' => $this->getUrl('*/adminhtml_common_amazon_order/updateShippingStatus'),
247
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
248
+ ));
249
+
250
+ $this->getMassactionBlock()->addItem('resend_shipping', array(
251
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
252
+ 'url' => $this->getUrl('*/adminhtml_order/resubmitShippingInfo'),
253
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
254
+ ));
255
+ //--------------------------------
256
+
257
+ return parent::_prepareMassaction();
258
+ }
259
+
260
+ //##############################################################
261
+
262
+ public function callbackColumnAmazonOrderId($value, $row, $column, $isExport)
263
+ {
264
+ $orderId = Mage::helper('M2ePro')->escapeHtml($row->getData('amazon_order_id'));
265
+ $url = Mage::helper('M2ePro/Component_Amazon')->getOrderUrl($orderId, $row->getData('marketplace_id'));
266
+
267
+ return <<<HTML
268
+ <a href="{$url}" target="_blank">{$orderId}</a>
269
+ HTML;
270
+ }
271
+
272
+ public function callbackColumnMagentoOrder($value, $row, $column, $isExport)
273
+ {
274
+ $magentoOrderId = $row['magento_order_id'];
275
+ $magentoOrderNumber = Mage::helper('M2ePro')->escapeHtml($row['magento_order_num']);
276
+
277
+ $returnString = Mage::helper('M2ePro')->__('N/A');
278
+
279
+ if ($row['magento_order_id']) {
280
+ if ($row['magento_order_num']) {
281
+ $orderUrl = $this->getUrl('adminhtml/sales_order/view', array('order_id' => $magentoOrderId));
282
+ $returnString = '<a href="' . $orderUrl . '" target="_blank">' . $magentoOrderNumber . '</a>';
283
+ } else {
284
+ $returnString = '<span style="color: red;">'.Mage::helper('M2ePro')->__('Deleted').'</span>';
285
+ }
286
+ }
287
+
288
+ return $returnString.$this->getViewLogIconHtml($row->getId());
289
+ }
290
+
291
+ private function getViewLogIconHtml($orderId)
292
+ {
293
+ $orderId = (int)$orderId;
294
+
295
+ // Prepare collection
296
+ // --------------------------------
297
+ $orderLogsCollection = Mage::getModel('M2ePro/Order_Log')->getCollection()
298
+ ->addFieldToFilter('order_id', $orderId)
299
+ ->setOrder('id', 'DESC');
300
+ $orderLogsCollection->getSelect()
301
+ ->limit(3);
302
+ // --------------------------------
303
+
304
+ // Prepare logs data
305
+ // --------------------------------
306
+ if ($orderLogsCollection->count() <= 0) {
307
+ return '';
308
+ }
309
+
310
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
311
+
312
+ $logRows = array();
313
+ foreach ($orderLogsCollection as $log) {
314
+ $logRows[] = array(
315
+ 'type' => $log->getData('type'),
316
+ 'text' => Mage::helper('M2ePro/View')->getModifiedLogMessage($log->getData('message')),
317
+ 'initiator' => $this->getInitiatorForAction($log->getData('initiator')),
318
+ 'date' => Mage::app()->getLocale()->date(strtotime($log->getData('create_date')))->toString($format)
319
+ );
320
+ }
321
+ // --------------------------------
322
+
323
+ $tips = array(
324
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last order action was completed successfully.',
325
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last order action was completed with error(s).',
326
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last order action was completed with warning(s).'
327
+ );
328
+
329
+ $icons = array(
330
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
331
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
332
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
333
+ );
334
+
335
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
336
+ 'entity_id' => $orderId,
337
+ 'rows' => $logRows,
338
+ 'tips' => $tips,
339
+ 'icons' => $icons,
340
+ 'view_help_handler' => 'OrderHandlerObj.viewOrderHelp',
341
+ 'hide_help_handler' => 'OrderHandlerObj.hideOrderHelp',
342
+ ));
343
+
344
+ return $summary->toHtml();
345
+ }
346
+
347
+ public function getInitiatorForAction($initiator)
348
+ {
349
+ $string = '';
350
+
351
+ switch ((int)$initiator) {
352
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
353
+ $string = '';
354
+ break;
355
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
356
+ $string = Mage::helper('M2ePro')->__('Manual');
357
+ break;
358
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
359
+ $string = Mage::helper('M2ePro')->__('Automatic');
360
+ break;
361
+ }
362
+
363
+ return $string;
364
+ }
365
+
366
+ //--------------------------------------------------------------
367
+
368
+ public function callbackColumnItems($value, $row, $column, $isExport)
369
+ {
370
+ /** @var $items Ess_M2ePro_Model_Order_Item[] */
371
+ $items = $this->itemsCollection->getItemsByColumnValue('order_id', $row->getData('id'));
372
+
373
+ $html = '';
374
+ $gridId = $this->getId();
375
+
376
+ foreach ($items as $item) {
377
+ if ($html != '') {
378
+ $html .= '<br/>';
379
+ }
380
+
381
+ $isShowEditLink = false;
382
+
383
+ $product = $item->getProduct();
384
+ if (!is_null($product)) {
385
+ /** @var Ess_M2ePro_Model_Magento_Product $magentoProduct */
386
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
387
+ $magentoProduct->setProduct($product);
388
+
389
+ $associatedProducts = $item->getAssociatedProducts();
390
+ $associatedOptions = $item->getAssociatedOptions();
391
+
392
+ if ($magentoProduct->isProductWithVariations()
393
+ && empty($associatedOptions)
394
+ && empty($associatedProducts)
395
+ ) {
396
+ $isShowEditLink = true;
397
+ }
398
+ }
399
+
400
+ $editItemHtml = '';
401
+ if ($isShowEditLink) {
402
+ $orderItemId = $item->getId();
403
+ $orderItemEditLabel = Mage::helper('M2ePro')->__('edit');
404
+
405
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
406
+
407
+ $editItemHtml = <<<HTML
408
+ <span>&nbsp;<a href="javascript:void(0);" onclick="{$js}">[{$orderItemEditLabel}]</a></span>
409
+ HTML;
410
+ }
411
+
412
+ $skuHtml = '';
413
+ if ($item->getSku()) {
414
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
415
+ $sku = Mage::helper('M2ePro')->escapeHtml($item->getSku());
416
+
417
+ $skuHtml = <<<STRING
418
+ <span style="padding-left: 10px;"><b>{$skuLabel}:</b>&nbsp;{$sku}</span><br/>
419
+ STRING;
420
+ }
421
+
422
+ $generalIdLabel = Mage::helper('M2ePro')->__($item->getIsIsbnGeneralId() ? 'ISBN' : 'ASIN');
423
+ $generalId = Mage::helper('M2ePro')->escapeHtml($item->getGeneralId());
424
+
425
+ $itemUrl = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($item->getGeneralId(),
426
+ $row->getData('marketplace_id'));
427
+
428
+ $itemLink = '<a href="'.$itemUrl.'" target="_blank">'.$generalId.'</a>';
429
+
430
+ $generalIdHtml = <<<STRING
431
+ <span style="padding-left: 10px;"><b>{$generalIdLabel}:</b>&nbsp;{$itemLink}</span><br/>
432
+ STRING;
433
+
434
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
435
+ $qtyLabel = Mage::helper('M2ePro')->__('QTY');
436
+ $qtyHtml = <<<HTML
437
+ <span style="padding-left: 10px;"><b>{$qtyLabel}:</b> {$item->getQtyPurchased()}</span>
438
+ HTML;
439
+
440
+ $html .= <<<HTML
441
+ {$itemTitle}&nbsp;{$editItemHtml}<br/>
442
+ <small>{$generalIdHtml}{$skuHtml}{$qtyHtml}</small>
443
+ HTML;
444
+ }
445
+
446
+ return $html;
447
+ }
448
+
449
+ public function callbackColumnBuyer($value, $row, $column, $isExport)
450
+ {
451
+ if ($row->getData('buyer_name') == '') {
452
+ return Mage::helper('M2ePro')->__('N/A');
453
+ }
454
+
455
+ $html = Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_name'));
456
+
457
+ if ($row->getData('buyer_email') != '') {
458
+ $html .= '<br/>';
459
+ $html .= '&lt;' . Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_email')) . '&gt;';
460
+ }
461
+
462
+ return $html;
463
+ }
464
+
465
+ public function callbackColumnTotal($value, $row, $column, $isExport)
466
+ {
467
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
468
+ $row->getData('currency'), $row->getData('paid_amount')
469
+ );
470
+ }
471
+
472
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
473
+ {
474
+ switch ($row->getData('is_afn_channel')) {
475
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
476
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
477
+ break;
478
+
479
+ default:
480
+ break;
481
+ }
482
+
483
+ return $value;
484
+ }
485
+
486
+ public function callbackColumnStatus($value, $row, $column, $isExport)
487
+ {
488
+ $status = $row->getData('status');
489
+
490
+ $statusColors = array(
491
+ Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => 'gray',
492
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => 'green',
493
+ Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => 'red'
494
+ );
495
+
496
+ $color = isset($statusColors[$status]) ? $statusColors[$status] : 'black';
497
+ $value = '<span style="color: '.$color.';">'.$value.'</span>';
498
+
499
+ if ($row->isLockedObject('update_order_status')) {
500
+ $value .= '<br/>';
501
+ $value .= '<span style="color: gray;">['
502
+ .Mage::helper('M2ePro')->__('Status Update in Progress...').']</span>';
503
+ }
504
+
505
+ return $value;
506
+ }
507
+
508
+ //##############################################################
509
+
510
+ protected function callbackFilterItems($collection, $column)
511
+ {
512
+ $value = $column->getFilter()->getValue();
513
+ if ($value == null) {
514
+ return;
515
+ }
516
+
517
+ $orderItemsCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Order_Item');
518
+
519
+ $orderItemsCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
520
+ $orderItemsCollection->getSelect()->columns('order_id');
521
+ $orderItemsCollection->getSelect()->distinct(true);
522
+
523
+ $orderItemsCollection->getSelect()->where('title LIKE ? OR sku LIKE ? or general_id LIKE ?', '%'.$value.'%');
524
+
525
+ $totalResult = $orderItemsCollection->getColumnValues('order_id');
526
+ $collection->addFieldToFilter('`main_table`.id', array('in' => $totalResult));
527
+ }
528
+
529
+ protected function callbackFilterBuyer($collection, $column)
530
+ {
531
+ $value = $column->getFilter()->getValue();
532
+ if ($value == null) {
533
+ return;
534
+ }
535
+
536
+ $collection
537
+ ->getSelect()
538
+ ->where('buyer_email LIKE ? OR buyer_name LIKE ?', '%'.$value.'%');
539
+ }
540
+
541
+ //##############################################################
542
+
543
+ public function getGridUrl()
544
+ {
545
+ return $this->getUrl('*/adminhtml_common_amazon_order/grid', array('_current' => true));
546
+ }
547
+
548
+ public function getRowUrl($row)
549
+ {
550
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_order/index', array(
551
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
552
+ ));
553
+
554
+ return $this->getUrl('*/adminhtml_common_amazon_order/view', array('id' => $row->getId(), 'back' => $back));
555
+ }
556
+
557
+ //##############################################################
558
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ /** @var $order Ess_M2ePro_Model_Order */
10
+ protected $order = null;
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonOrderView');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_amazon_order';
21
+ $this->_mode = 'view';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $this->_headerText = Mage::helper('M2ePro')->__('View Order Details');
27
+ //------------------------------
28
+
29
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
30
+
31
+ // Set buttons actions
32
+ //------------------------------
33
+ $this->removeButton('back');
34
+ $this->removeButton('reset');
35
+ $this->removeButton('delete');
36
+ $this->removeButton('add');
37
+ $this->removeButton('save');
38
+ $this->removeButton('edit');
39
+ //------------------------------
40
+
41
+ //------------------------------
42
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
43
+ $this->_addButton('back', array(
44
+ 'label' => Mage::helper('M2ePro')->__('Back'),
45
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
46
+ 'class' => 'back'
47
+ ));
48
+ //------------------------------
49
+
50
+ if ($this->order->getChildObject()->canUpdateShippingStatus()) {
51
+ //------------------------------
52
+ $url = $this->getUrl('*/*/updateShippingStatus', array('id' => $this->order->getId()));
53
+ $this->_addButton('update_shipping_status', array(
54
+ 'label' => Mage::helper('M2ePro')->__('Mark as Shipped'),
55
+ 'onclick' => "setLocation('".$url."');",
56
+ 'class' => 'scalable'
57
+ ));
58
+ //------------------------------
59
+ }
60
+
61
+ if ($this->order->getReserve()->isPlaced()) {
62
+ //------------------------------
63
+ $url = $this->getUrl('*/adminhtml_order/reservationCancel', array('ids' => $this->order->getId()));
64
+ $this->_addButton('reservation_cancel', array(
65
+ 'label' => Mage::helper('M2ePro')->__('Cancel QTY Reserve'),
66
+ 'onclick' => "confirmSetLocation(M2ePro.translator.translate('Are you sure?'), '".$url."');",
67
+ 'class' => 'scalable'
68
+ ));
69
+ //------------------------------
70
+ } elseif ($this->order->isReservable()) {
71
+ //------------------------------
72
+ $url = $this->getUrl('*/adminhtml_order/reservationPlace', array('ids' => $this->order->getId()));
73
+ $this->_addButton('reservation_place', array(
74
+ 'label' => Mage::helper('M2ePro')->__('Reserve QTY'),
75
+ 'onclick' => "confirmSetLocation(M2ePro.translator.translate('Are you sure?'), '".$url."');",
76
+ 'class' => 'scalable'
77
+ ));
78
+ //------------------------------
79
+ }
80
+
81
+ if (is_null($this->order->getMagentoOrderId())) {
82
+ //------------------------------
83
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId()));
84
+ $this->_addButton('order', array(
85
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
86
+ 'onclick' => "setLocation('".$url."');",
87
+ 'class' => 'scalable'
88
+ ));
89
+ //------------------------------
90
+ } elseif (is_null($this->order->getMagentoOrder()) || $this->order->getMagentoOrder()->isCanceled()) {
91
+ //------------------------------
92
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId(), 'force' => 'yes'));
93
+ $confirm = Mage::helper('M2ePro')->escapeJs(
94
+ Mage::helper('M2ePro')->__('Are you sure that you want to create new Magento Order?')
95
+ );
96
+
97
+ $this->_addButton('order', array(
98
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
99
+ 'onclick' => "confirmSetLocation('".$confirm."','".$url."');",
100
+ 'class' => 'scalable'
101
+ ));
102
+ //------------------------------
103
+ }
104
+ }
105
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Form.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_View_Form extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ public $shippingAddress = array();
10
+
11
+ public $realMagentoOrderId = NULL;
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('amazonOrderViewForm');
20
+ $this->setTemplate('M2ePro/common/amazon/order.phtml');
21
+ //------------------------------
22
+
23
+ /** @var $order Ess_M2ePro_Model_Order */
24
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
25
+ }
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ // Magento order data
30
+ // ---------------
31
+ $this->realMagentoOrderId = NULL;
32
+
33
+ $magentoOrder = $this->order->getMagentoOrder();
34
+ if (!is_null($magentoOrder)) {
35
+ $this->realMagentoOrderId = $magentoOrder->getRealOrderId();
36
+ }
37
+ // ---------------
38
+
39
+ // ---------------
40
+ if (!is_null($magentoOrder) && $magentoOrder->hasShipments()) {
41
+ $url = $this->getUrl('*/adminhtml_order/resubmitShippingInfo', array('id' => $this->order->getId()));
42
+ $data = array(
43
+ 'class' => '',
44
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
45
+ 'onclick' => 'setLocation(\''.$url.'\');',
46
+ );
47
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
48
+ $this->setChild('resubmit_shipping_info', $buttonBlock);
49
+ }
50
+ // ---------------
51
+
52
+ // Shipping data
53
+ // ---------------
54
+ /** @var $shippingAddress Ess_M2ePro_Model_Amazon_Order_ShippingAddress */
55
+ $shippingAddress = $this->order->getShippingAddress();
56
+
57
+ $this->shippingAddress = $shippingAddress->getData();
58
+ $this->shippingAddress['country_name'] = $shippingAddress->getCountryName();
59
+ // ---------------
60
+
61
+ $this->setChild('item', $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_order_view_item'));
62
+ $this->setChild('item_edit', $this->getLayout()->createBlock('M2ePro/adminhtml_order_item_edit'));
63
+ $this->setChild('log', $this->getLayout()->createBlock('M2ePro/adminhtml_order_view_log_grid'));
64
+
65
+ return parent::_beforeToHtml();
66
+ }
67
+
68
+ private function getStore()
69
+ {
70
+ if (is_null($this->order->getData('store_id'))) {
71
+ return null;
72
+ }
73
+
74
+ try {
75
+ $store = Mage::app()->getStore($this->order->getData('store_id'));
76
+ } catch (Exception $e) {
77
+ return null;
78
+ }
79
+
80
+ return $store;
81
+ }
82
+
83
+ public function isCurrencyAllowed()
84
+ {
85
+ $store = $this->getStore();
86
+
87
+ if (is_null($store)) {
88
+ return true;
89
+ }
90
+
91
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
92
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
93
+
94
+ return $currencyHelper->isAllowed($this->order->getChildObject()->getCurrency(), $store);
95
+ }
96
+
97
+ public function hasCurrencyConversionRate()
98
+ {
99
+ $store = $this->getStore();
100
+
101
+ if (is_null($store)) {
102
+ return true;
103
+ }
104
+
105
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
106
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
107
+
108
+ return $currencyHelper->getConvertRateFromBase($this->order->getChildObject()->getCurrency(), $store) != 0;
109
+ }
110
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Item.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_View_Item extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('amazonOrderViewItem');
16
+ //------------------------------
17
+
18
+ // Set default values
19
+ //------------------------------
20
+ $this->setDefaultSort('id');
21
+ $this->setDefaultDir('DESC');
22
+ $this->setPagerVisibility(false);
23
+ $this->setFilterVisibility(false);
24
+ $this->setUseAjax(true);
25
+ $this->_defaultLimit = 200;
26
+ //------------------------------
27
+
28
+ /** @var $order Ess_M2ePro_Model_Order */
29
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
30
+ }
31
+
32
+ protected function _prepareCollection()
33
+ {
34
+ $collection = Mage::helper('M2ePro/Component_Amazon')
35
+ ->getCollection('Order_Item')
36
+ ->addFieldToFilter('order_id', $this->order->getId());
37
+
38
+ $collection->getSelect()->joinLeft(
39
+ array('cisi' => Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
40
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
41
+ array('is_in_stock')
42
+ );
43
+
44
+ $this->setCollection($collection);
45
+
46
+ return parent::_prepareCollection();
47
+ }
48
+
49
+ protected function _prepareColumns()
50
+ {
51
+ $this->addColumn('product_id', array(
52
+ 'header' => Mage::helper('M2ePro')->__('Product'),
53
+ 'align' => 'left',
54
+ 'width' => '*',
55
+ 'index' => 'product_id',
56
+ 'frame_callback' => array($this, 'callbackColumnProduct')
57
+ ));
58
+
59
+ $this->addColumn('stock_availability', array(
60
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
61
+ 'width' => '100px',
62
+ 'index' => 'is_in_stock',
63
+ 'filter_index' => 'cisi.is_in_stock',
64
+ 'type' => 'options',
65
+ 'sortable' => false,
66
+ 'options' => array(
67
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
68
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
69
+ ),
70
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
71
+ ));
72
+
73
+ $this->addColumn('original_price', array(
74
+ 'header' => Mage::helper('M2ePro')->__('Original Price'),
75
+ 'align' => 'left',
76
+ 'width' => '80px',
77
+ 'filter' => false,
78
+ 'sortable' => false,
79
+ 'frame_callback' => array($this, 'callbackColumnOriginalPrice')
80
+ ));
81
+
82
+ $this->addColumn('qty_purchased', array(
83
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
84
+ 'align' => 'left',
85
+ 'width' => '80px',
86
+ 'index' => 'qty_purchased'
87
+ ));
88
+
89
+ $this->addColumn('price', array(
90
+ 'header' => Mage::helper('M2ePro')->__('Price'),
91
+ 'align' => 'left',
92
+ 'width' => '80px',
93
+ 'index' => 'price',
94
+ 'frame_callback' => array($this, 'callbackColumnPrice')
95
+ ));
96
+
97
+ $this->addColumn('discount_amount', array(
98
+ 'header' => Mage::helper('M2ePro')->__('Promotions'),
99
+ 'align' => 'left',
100
+ 'width' => '80px',
101
+ 'index' => 'discount_amount',
102
+ 'frame_callback' => array($this, 'callbackColumnDiscountAmount')
103
+ ));
104
+
105
+ if (Mage::getResourceModel('M2ePro/Amazon_Order')->hasGifts($this->order->getId())) {
106
+ $this->addColumn('gift_price', array(
107
+ 'header' => Mage::helper('M2ePro')->__('Gift Wrap Price'),
108
+ 'align' => 'left',
109
+ 'width' => '80px',
110
+ 'index' => 'gift_price',
111
+ 'frame_callback' => array($this, 'callbackColumnGiftPrice')
112
+ ));
113
+
114
+ $this->addColumn('gift_options', array(
115
+ 'header' => Mage::helper('M2ePro')->__('Gift Options'),
116
+ 'align' => 'left',
117
+ 'width' => '250px',
118
+ 'filter' => false,
119
+ 'sortable' => false,
120
+ 'frame_callback' => array($this, 'callbackColumnGiftOptions')
121
+ ));
122
+ }
123
+
124
+ $this->addColumn('row_total', array(
125
+ 'header' => Mage::helper('M2ePro')->__('Row Total'),
126
+ 'align' => 'left',
127
+ 'width' => '80px',
128
+ 'frame_callback' => array($this, 'callbackColumnRowTotal')
129
+ ));
130
+
131
+ return parent::_prepareColumns();
132
+ }
133
+
134
+ //##############################################################
135
+
136
+ /**
137
+ * @param $value
138
+ * @param $row Ess_M2ePro_Model_Order_Item
139
+ * @param $column
140
+ * @param $isExport
141
+ *
142
+ * @return string
143
+ */
144
+ public function callbackColumnProduct($value, $row, $column, $isExport)
145
+ {
146
+ $skuHtml = '';
147
+ if ($row->getSku()) {
148
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
149
+ $sku = Mage::helper('M2ePro')->escapeHtml($row->getSku());
150
+
151
+ $skuHtml = <<<HTML
152
+ <b>{$skuLabel}:</b> {$sku}<br/>
153
+ HTML;
154
+ }
155
+
156
+ $generalIdLabel = Mage::helper('M2ePro')->__($row->getIsIsbnGeneralId() ? 'ISBN' : 'ASIN');
157
+ $generalId = Mage::helper('M2ePro')->escapeHtml($row->getGeneralId());
158
+
159
+ $generalIdHtml = <<<HTML
160
+ <b>{$generalIdLabel}:</b> {$generalId}<br/>
161
+ HTML;
162
+
163
+ if ($row->getIsIsbnGeneralId() && !Mage::helper('M2ePro')->isISBN($row->getGeneralId())) {
164
+ $amazonLink = '';
165
+ } else {
166
+ $itemLinkText = Mage::helper('M2ePro')->__('View on Amazon');
167
+ $itemUrl = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
168
+ $row->getGeneralId(), $this->order->getData('marketplace_id')
169
+ );
170
+
171
+ $amazonLink = <<<HTML
172
+ <a href="{$itemUrl}" target="_blank">{$itemLinkText}</a>
173
+ HTML;
174
+ }
175
+
176
+ $productLink = '';
177
+ if ($productId = $row->getData('product_id')) {
178
+ $productUrl = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
179
+ $productLink = ' | <a href="'.$productUrl.'" target="_blank">'.Mage::helper('M2ePro')->__('View').'</a>';
180
+ }
181
+
182
+ $orderItemId = (int)$row->getId();
183
+ $gridId = $this->getId();
184
+
185
+ $editLink = '';
186
+ if (!$row->getProductId() || $row->getMagentoProduct()->hasRequiredOptions()) {
187
+
188
+ if (!$row->getProductId()) {
189
+ $action = Mage::helper('M2ePro')->__('Map to Magento Product');
190
+ } else {
191
+ $action = Mage::helper('M2ePro')->__('Set Options');
192
+ }
193
+
194
+ $class = 'class="gray"';
195
+
196
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
197
+ $editLink = '<a href="javascript:void(0);" onclick="'.$js.'" '.$class.'>'.$action.'</a>';
198
+ }
199
+
200
+ $discardLink = '';
201
+ if ($row->getProductId()) {
202
+ $action = Mage::helper('M2ePro')->__('Unmap');
203
+
204
+ $js = "{OrderEditItemHandlerObj.unassignProduct('{$gridId}', {$orderItemId});}";
205
+ $discardLink = '<a href="javascript:void(0);" onclick="'.$js.'" class="gray">'.$action.'</a>';
206
+
207
+ if ($editLink) {
208
+ $discardLink = '&nbsp;|&nbsp;' . $discardLink;
209
+ }
210
+ }
211
+
212
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($row->getTitle());
213
+
214
+ return <<<HTML
215
+ <b>{$itemTitle}</b><br/>
216
+ <div style="padding-left: 10px;">
217
+ {$skuHtml}
218
+ {$generalIdHtml}
219
+ </div>
220
+ <div style="float: left;">{$amazonLink}{$productLink}</div>
221
+ <div style="float: right;">{$editLink}{$discardLink}</div>
222
+ HTML;
223
+ }
224
+
225
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
226
+ {
227
+ if (is_null($row->getData('is_in_stock'))) {
228
+ return Mage::helper('M2ePro')->__('N/A');
229
+ }
230
+
231
+ if ((int)$row->getData('is_in_stock') <= 0) {
232
+ return '<span style="color: red;">'.$value.'</span>';
233
+ }
234
+
235
+ return $value;
236
+ }
237
+
238
+ public function callbackColumnOriginalPrice($value, $row, $column, $isExport)
239
+ {
240
+ $productId = $row->getData('product_id');
241
+ $formattedPrice = Mage::helper('M2ePro')->__('N/A');
242
+
243
+ if ($productId && $product = Mage::getModel('catalog/product')->load($productId)) {
244
+ $formattedPrice = $product->getFormatedPrice();
245
+ }
246
+
247
+ return $formattedPrice;
248
+ }
249
+
250
+ public function callbackColumnPrice($value, $row, $column, $isExport)
251
+ {
252
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($row->getData('currency'), $row->getData('price'));
253
+ }
254
+
255
+ public function callbackColumnGiftPrice($value, $row, $column, $isExport)
256
+ {
257
+ return Mage::getSingleton('M2ePro/Currency')
258
+ ->formatPrice($row->getData('currency'), $row->getData('gift_price'));
259
+ }
260
+
261
+ public function callbackColumnDiscountAmount($value, $row, $column, $isExport)
262
+ {
263
+ return Mage::getSingleton('M2ePro/Currency')
264
+ ->formatPrice($row->getData('currency'), $row->getData('discount_amount'));
265
+ }
266
+
267
+ public function callbackColumnGiftOptions($value, $row, $column, $isExport)
268
+ {
269
+ if ($row->getData('gift_type') == '' && $row->getData('gift_message') == '') {
270
+ return Mage::helper('M2ePro')->__('N/A');
271
+ }
272
+
273
+ $giftType = Mage::helper('M2ePro')->escapeHtml($row->getData('gift_type'));
274
+ $giftTypeLabel = Mage::helper('M2ePro')->__('Gift Wrap Type');
275
+
276
+ $giftMessage = Mage::helper('M2ePro')->escapeHtml($row->getData('gift_message'));
277
+ $giftMessageLabel = Mage::helper('M2ePro')->__('Gift Message');
278
+
279
+ return <<<HTML
280
+ <strong>{$giftTypeLabel}: </strong>{$giftType}<br/>
281
+ <strong>{$giftMessageLabel}: </strong>{$giftMessage}
282
+ HTML;
283
+ }
284
+
285
+ public function callbackColumnRowTotal($value, $row, $column, $isExport)
286
+ {
287
+ $price = (float)$row->getData('price') + (float)$row->getData('gift_price');
288
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
289
+ $row->getData('currency'), $price * $row->getData('qty_purchased')
290
+ );
291
+ }
292
+
293
+ public function getRowUrl($row)
294
+ {
295
+ return '';
296
+ }
297
+
298
+ public function getGridUrl()
299
+ {
300
+ return $this->getUrl('*/*/orderItemGrid', array('_current' => true));
301
+ }
302
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Synchronization/Form.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Synchronization_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ private $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonSynchronizationForm');
18
+ $this->setContainerId('magento_block_amazon_synchronization');
19
+ $this->setTemplate('M2ePro/common/amazon/synchronization.phtml');
20
+ //------------------------------
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ //----------------------------
26
+ $this->templatesMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
27
+ ->getGroupValue('/amazon/templates/', 'mode');
28
+ $this->ordersMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
29
+ ->getGroupValue('/amazon/orders/', 'mode');
30
+ $this->otherListingsMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
31
+ ->getGroupValue('/amazon/other_listings/', 'mode');
32
+ //----------------------------
33
+
34
+ //----------------------------
35
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
36
+
37
+ $this->reviseAllInProcessingState = !is_null(
38
+ Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
39
+ '/amazon/templates/revise/total/', 'last_listing_product_id'
40
+ )
41
+ );
42
+
43
+ $this->reviseAllStartDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
44
+ '/amazon/templates/revise/total/', 'start_date'
45
+ );
46
+ $this->reviseAllStartDate && $this->reviseAllStartDate = Mage::app()->getLocale()
47
+ ->date(strtotime($this->reviseAllStartDate))
48
+ ->toString($format);
49
+
50
+ $this->reviseAllEndDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
51
+ '/amazon/templates/revise/total/', 'end_date'
52
+ );
53
+ $this->reviseAllEndDate && $this->reviseAllEndDate = Mage::app()->getLocale()
54
+ ->date(strtotime($this->reviseAllEndDate))
55
+ ->toString($format);
56
+ //----------------------------
57
+
58
+ //----------------------------
59
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
60
+ $data = array(
61
+ 'class' => 'ok_button',
62
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
63
+ 'onclick' => "Windows.getFocusedWindow().close(); SynchronizationHandlerObj.runReviseAll('{$component}');",
64
+ );
65
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
66
+ $this->setChild('revise_all_confirm_popup_ok_button', $buttonBlock);
67
+ //------------------------------
68
+
69
+ //-------------------------------
70
+ $data = array(
71
+ 'label' => Mage::helper('M2ePro')->__('Run Now'),
72
+ 'onclick' => 'SynchronizationHandlerObj.saveSettings(\'runNowTemplates\', \'' . $this->component . '\');',
73
+ 'class' => 'templates_run_now'
74
+ );
75
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
76
+ $this->setChild('amazon_templates_run_now', $buttonBlock);
77
+ //-------------------------------
78
+
79
+ //-------------------------------
80
+ $areYouSure = Mage::helper('M2ePro')->__('Are you sure?');
81
+
82
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
83
+ '*/adminhtml_common_synchronization/index',
84
+ array(
85
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
86
+ )
87
+ );
88
+ //-------------------------------
89
+
90
+ //-------------------------------
91
+ $url = $this->getUrl(
92
+ '*/adminhtml_common_synchronization/clearLog',
93
+ array(
94
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_TEMPLATES,
95
+ 'component' => $this->component,
96
+ 'back'=> $backUrl
97
+ )
98
+ );
99
+ $data = array(
100
+ 'label' => Mage::helper('M2ePro')->__('Clear Log'),
101
+ 'onclick' => 'deleteConfirm(\'' . $areYouSure . '\', \'' . $url . '\')',
102
+ 'class' => 'templates_clear_log'
103
+ );
104
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
105
+ $this->setChild('amazon_templates_clear_log', $buttonBlock);
106
+ //-------------------------------
107
+
108
+ //-------------------------------
109
+ $url = $this->getUrl(
110
+ '*/adminhtml_common_log/synchronization',
111
+ array(
112
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_TEMPLATES,
113
+ 'channel' => $this->component
114
+ )
115
+ );
116
+ $data = array(
117
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
118
+ 'onclick' => 'window.open(\'' . $url . '\')',
119
+ 'class' => 'button_link'
120
+ );
121
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
122
+ $this->setChild('amazon_templates_view_log', $buttonBlock);
123
+ //-------------------------------
124
+
125
+ //-------------------------------
126
+ $data = array(
127
+ 'label' => Mage::helper('M2ePro')->__('Run Now'),
128
+ 'onclick' => 'SynchronizationHandlerObj.saveSettings(\'runNowOrders\', \'' . $this->component . '\');',
129
+ 'class' => 'orders_run_now'
130
+ );
131
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
132
+ $this->setChild('amazon_orders_run_now', $buttonBlock);
133
+ //-------------------------------
134
+
135
+ //-------------------------------
136
+ $url = $this->getUrl(
137
+ '*/adminhtml_common_synchronization/clearLog',
138
+ array(
139
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_ORDERS,
140
+ 'component' => $this->component,
141
+ 'back' => $backUrl
142
+ )
143
+ );
144
+ $data = array(
145
+ 'label' => Mage::helper('M2ePro')->__('Clear Log'),
146
+ 'onclick' => 'deleteConfirm(\'' . $areYouSure . '\', \'' . $url . '\')',
147
+ 'class' => 'orders_clear_log'
148
+ );
149
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
150
+ $this->setChild('amazon_orders_clear_log', $buttonBlock);
151
+ //-------------------------------
152
+
153
+ //-------------------------------
154
+ $url = $this->getUrl(
155
+ '*/adminhtml_common_log/synchronization',
156
+ array(
157
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_ORDERS,
158
+ 'channel' => $this->component,
159
+ )
160
+ );
161
+ $data = array(
162
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
163
+ 'onclick' => 'window.open(\'' . $url . '\')',
164
+ 'class' => 'button_link'
165
+ );
166
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
167
+ $this->setChild('amazon_orders_view_log', $buttonBlock);
168
+ //-------------------------------
169
+
170
+ //-------------------------------
171
+ $data = array(
172
+ 'label' => Mage::helper('M2ePro')->__('Run Now'),
173
+ 'onclick' => 'SynchronizationHandlerObj.saveSettings(\'runNowOtherListings\', \''.$this->component.'\');',
174
+ 'class' => 'other_listings_run_now'
175
+ );
176
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
177
+ $this->setChild('amazon_other_listings_run_now', $buttonBlock);
178
+ //-------------------------------
179
+
180
+ //-------------------------------
181
+ $url = $this->getUrl(
182
+ '*/adminhtml_common_synchronization/clearLog',
183
+ array(
184
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_OTHER_LISTINGS,
185
+ 'component' => $this->component,
186
+ 'back' => $backUrl
187
+ )
188
+ );
189
+ $data = array(
190
+ 'label' => Mage::helper('M2ePro')->__('Clear Log'),
191
+ 'onclick' => 'deleteConfirm(\'' . $areYouSure . '\', \'' . $url . '\')',
192
+ 'class' => 'orders_clear_log'
193
+ );
194
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
195
+ $this->setChild('amazon_other_listings_clear_log', $buttonBlock);
196
+ //-------------------------------
197
+
198
+ //-------------------------------
199
+ $url = $this->getUrl(
200
+ '*/adminhtml_common_log/synchronization',
201
+ array(
202
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_OTHER_LISTINGS,
203
+ 'channel' => $this->component,
204
+ )
205
+ );
206
+ $data = array(
207
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
208
+ 'onclick' => 'window.open(\'' . $url . '\')',
209
+ 'class' => 'button_link'
210
+ );
211
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
212
+ $this->setChild('amazon_other_listings_view_log', $buttonBlock);
213
+ //-------------------------------
214
+
215
+ //-------------------------------
216
+ $this->inspectorMode = (int)Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
217
+ '/defaults/inspector/','mode'
218
+ );
219
+ //-------------------------------
220
+
221
+ return parent::_beforeToHtml();
222
+ }
223
+
224
+ // ####################################
225
+
226
+ public function isShowReviseAll()
227
+ {
228
+ return Mage::helper('M2ePro/Module')->getConfig()->getGroupValue(
229
+ '/view/synchronization/revise_total/','show'
230
+ );
231
+ }
232
+
233
+ // ####################################
234
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonTemplateDescription');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_amazon_template_description';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $componentName = !Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()
25
+ ? Mage::helper('M2ePro/Component_Amazon')->getTitle().' ' : '';
26
+
27
+ $this->_headerText = Mage::helper('M2ePro')->__("%sDescription Policies", $componentName);
28
+ //------------------------------
29
+
30
+ // Set buttons actions
31
+ //------------------------------
32
+ $this->removeButton('back');
33
+ $this->removeButton('reset');
34
+ $this->removeButton('delete');
35
+ $this->removeButton('add');
36
+ $this->removeButton('save');
37
+ $this->removeButton('edit');
38
+ //------------------------------
39
+
40
+ //------------------------------
41
+ $url = $this->getUrl(
42
+ '*/adminhtml_common_listing/index', array('tab' => Ess_M2ePro_Helper_Component_Amazon::NICK)
43
+ );
44
+ $this->_addButton('goto_listings', array(
45
+ 'label' => Mage::helper('M2ePro')->__('Listings'),
46
+ 'onclick' => 'setLocation(\'' . $url .'\')',
47
+ 'class' => 'button_link'
48
+ ));
49
+ //------------------------------
50
+
51
+ //------------------------------
52
+ $url = $this->getUrl('*/adminhtml_common_amazon_template_description/new');
53
+ $this->_addButton('add', array(
54
+ 'label' => Mage::helper('M2ePro')->__('Add Description Policy'),
55
+ 'onclick' => 'setLocation(\'' . $url .'\')',
56
+ 'class' => 'add'
57
+ ));
58
+ //------------------------------
59
+ }
60
+
61
+ // ####################################
62
+
63
+ public function getGridHtml()
64
+ {
65
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_template_description_help');
66
+ return $helpBlock->toHtml() . parent::getGridHtml();
67
+ }
68
+
69
+ // ########################################
70
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Edit.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Edit
8
+ extends Mage_Adminhtml_Block_Widget_Container
9
+ {
10
+ // ########################################
11
+
12
+ protected $_marketplaceId;
13
+ protected $_selectedCategory = array();
14
+
15
+ // ########################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ // Initialization block
22
+ //------------------------------
23
+ $this->setId('amazonTemplateDescriptionCategoryChooserEdit');
24
+ //------------------------------
25
+
26
+ // Set buttons actions
27
+ //------------------------------
28
+ $this->removeButton('back');
29
+ $this->removeButton('reset');
30
+ $this->removeButton('delete');
31
+ $this->removeButton('add');
32
+ $this->removeButton('save');
33
+ $this->removeButton('edit');
34
+ //------------------------------
35
+
36
+ //------------------------------
37
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/edit.phtml');
38
+ //------------------------------
39
+ }
40
+
41
+ // ########################################
42
+
43
+ protected function _toHtml()
44
+ {
45
+ //------------------------------
46
+ $data = array(
47
+ 'id' => 'category_edit_confirm_button',
48
+ 'class' => '',
49
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
50
+ 'onclick' => 'AmazonTemplateDescriptionCategoryChooserHandlerObj.confirmCategory();',
51
+ );
52
+ $doneButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
53
+ //------------------------------
54
+
55
+ $cancelWord = Mage::helper('M2ePro')->__('Cancel');
56
+
57
+ $buttonsContainer = <<< HTML
58
+ <div id="chooser_buttons_container">
59
+ <a href="javascript:void(0)"
60
+ onclick="AmazonTemplateDescriptionCategoryChooserHandlerObj.cancelPopUp()">{$cancelWord}</a>
61
+ &nbsp;&nbsp;&nbsp;&nbsp;
62
+ {$doneButton->toHtml()}
63
+ <script type="text/javascript">amazonTemplateDescriptionCategoryChooserTabsJsTabs.moveTabContentInDest();</script>
64
+ </div>
65
+ HTML;
66
+
67
+ /** @var Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs $tabsBlock */
68
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs';
69
+ $tabsBlock = $this->getLayout()->createBlock($blockName);
70
+
71
+ return parent::_toHtml() .
72
+ $tabsBlock->toHtml() .
73
+ '<div id="chooser_tabs_container"></div>' .
74
+ $buttonsContainer;
75
+ }
76
+
77
+ // ########################################
78
+
79
+ public function getSelectedCategory()
80
+ {
81
+ return $this->_selectedCategory;
82
+ }
83
+
84
+ public function setSelectedCategory(array $selectedCategory)
85
+ {
86
+ $this->_selectedCategory = $selectedCategory;
87
+ return $this;
88
+ }
89
+
90
+ // ----------------------------------------
91
+
92
+ public function setMarketplaceId($value)
93
+ {
94
+ $this->_marketplaceId = $value;
95
+ return $this;
96
+ }
97
+
98
+ // ########################################
99
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs
8
+ extends Mage_Adminhtml_Block_Widget_Tabs
9
+ {
10
+ // ########################################
11
+
12
+ const TAB_ID_RECENT = 'recent';
13
+ const TAB_ID_BROWSE = 'browse';
14
+ const TAB_ID_SEARCH = 'search';
15
+
16
+ // ########################################
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+
22
+ $this->setTemplate('widget/tabshoriz.phtml');
23
+ $this->setId('amazonTemplateDescriptionCategoryChooserTabs');
24
+ $this->setDestElementId('chooser_tabs_container');
25
+ }
26
+
27
+ // ########################################
28
+
29
+ protected function _prepareLayout()
30
+ {
31
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs_recent';
32
+ !$this->isNeedToHideRecent() && $this->addTab(self::TAB_ID_RECENT, array(
33
+ 'label' => Mage::helper('M2ePro')->__('Recently Used'),
34
+ 'title' => Mage::helper('M2ePro')->__('Recently Used'),
35
+ 'content' => $this->getLayout()
36
+ ->createBlock($blockName)
37
+ ->toHtml(),
38
+ 'active' => true
39
+ ));
40
+
41
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs_browse';
42
+ $this->addTab(self::TAB_ID_BROWSE, array(
43
+ 'label' => Mage::helper('M2ePro')->__('Browse'),
44
+ 'title' => Mage::helper('M2ePro')->__('Browse'),
45
+ 'content' => $this->getLayout()
46
+ ->createBlock($blockName)
47
+ ->toHtml(),
48
+ 'active' => $this->isNeedToHideRecent() ? true : false
49
+ ));
50
+
51
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs_search';
52
+ $this->addTab(self::TAB_ID_SEARCH, array(
53
+ 'label' => Mage::helper('M2ePro')->__('Search'),
54
+ 'title' => Mage::helper('M2ePro')->__('Search'),
55
+ 'content' => $this->getLayout()
56
+ ->createBlock($blockName)
57
+ ->toHtml()
58
+ ));
59
+
60
+ return parent::_prepareLayout();
61
+ }
62
+
63
+ // ########################################
64
+
65
+ public function isNeedToHideRecent()
66
+ {
67
+ return Mage::helper('M2ePro/Data_Global')->getValue('category_chooser_hide_recent', true);
68
+ }
69
+
70
+ // ########################################
71
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Browse.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs_Browse
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ // ########################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateDescriptionCategoryChooserBrowse');
19
+ //------------------------------
20
+
21
+ // Set template
22
+ //------------------------------
23
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/tabs/browse.phtml');
24
+ // -----------------------------
25
+ }
26
+
27
+ // ########################################
28
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Recent.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs_Recent
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ protected $_selectedCategory = array();
11
+
12
+ // ########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('amazonTemplateDescriptionCategoryChooserRecent');
21
+ //------------------------------
22
+
23
+ // Set template
24
+ //------------------------------
25
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/tabs/recent.phtml');
26
+ // -----------------------------
27
+ }
28
+
29
+ // ########################################
30
+
31
+ public function getCategories()
32
+ {
33
+ return Mage::helper('M2ePro/Component_Amazon_Category')->getRecent(
34
+ $this->getRequest()->getPost('marketplace_id'),
35
+ array('product_data_nick' => $this->getRequest()->getPost('product_data_nick'),
36
+ 'browsenode_id' => $this->getRequest()->getPost('browsenode_id'),
37
+ 'path' => $this->getRequest()->getPost('category_path'))
38
+ );
39
+ }
40
+
41
+ // ########################################
42
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Search.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs_Search
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ // ########################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateDescriptionCategoryChooserSearch');
19
+ //------------------------------
20
+
21
+ // Set template
22
+ //------------------------------
23
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/tabs/search.phtml');
24
+ // -----------------------------
25
+ }
26
+
27
+ // ########################################
28
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Specific_Add
8
+ extends Mage_Adminhtml_Block_Widget_Container
9
+ {
10
+ // ########################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateDescriptionCategorySpecificAdd');
19
+ //------------------------------
20
+
21
+ // Set buttons actions
22
+ //------------------------------
23
+ $this->removeButton('back');
24
+ $this->removeButton('reset');
25
+ $this->removeButton('delete');
26
+ $this->removeButton('add');
27
+ $this->removeButton('save');
28
+ $this->removeButton('edit');
29
+ //------------------------------
30
+
31
+ //------------------------------
32
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/specific/add.phtml');
33
+ //------------------------------
34
+ }
35
+
36
+ // ########################################
37
+
38
+ protected function _beforeToHtml()
39
+ {
40
+ $additionalTitle = $this->getRequest()->getParam('current_indexed_xpath');
41
+ $additionalTitle = explode('/', ltrim($additionalTitle, '/'));
42
+ array_shift($additionalTitle);
43
+ $additionalTitle = array_map(function($el) { return preg_replace('/-\d+/', '', $el); }, $additionalTitle);
44
+ $this->setData('additional_title', implode(' > ', $additionalTitle));
45
+
46
+ return parent::_beforeToHtml();
47
+ }
48
+
49
+ protected function _toHtml()
50
+ {
51
+ //------------------------------
52
+ $data = array(
53
+ 'class' => 'specifics_done_button',
54
+ 'label' => Mage::helper('M2ePro')->__('Confirm')
55
+ );
56
+ $doneButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
57
+ //------------------------------
58
+
59
+ $cancelWord = Mage::helper('M2ePro')->__('Cancel');
60
+ $buttonsContainer = <<< HTML
61
+ <div style="margin-top: 17px; text-align: right; position: absolute; left: 86%; top: 90%;">
62
+ <a href="javascript:void(0)" class="specifics_cancel_button">{$cancelWord}</a>
63
+ &nbsp;&nbsp;&nbsp;&nbsp;
64
+ {$doneButton->toHtml()}
65
+ </div>
66
+ HTML;
67
+ return parent::_toHtml() . $buttonsContainer;
68
+ }
69
+
70
+ // ########################################
71
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add/Grid.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Specific_Add_Grid
8
+ extends Mage_Adminhtml_Block_Widget_Grid
9
+ {
10
+ public $marketplaceId;
11
+ public $productDataNick;
12
+
13
+ public $currentXpath;
14
+
15
+ public $searchQuery;
16
+ public $onlyDesired = false;
17
+
18
+ public $selectedSpecifics = array();
19
+ public $renderedSpecifics = array();
20
+
21
+ // ####################################
22
+
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+
27
+ // Initialization block
28
+ //------------------------------
29
+ $this->setId('amazonTemplateDescriptionCategorySpecificAddGrid');
30
+ //------------------------------
31
+
32
+ // Set default values
33
+ //------------------------------
34
+ $this->setFilterVisibility(false);
35
+ $this->setPagerVisibility(false);
36
+ $this->setDefaultSort('id');
37
+ $this->setDefaultDir('ASC');
38
+ $this->setSaveParametersInSession(true);
39
+ $this->setUseAjax(true);
40
+ //------------------------------
41
+ }
42
+
43
+ // ####################################
44
+
45
+ protected function _prepareCollection()
46
+ {
47
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
48
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
49
+
50
+ $select = $connRead->select()
51
+ ->from(Mage::getSingleton('core/resource')->getTableName('m2epro_amazon_dictionary_specific'))
52
+ ->where('marketplace_id = ?', (int)$this->marketplaceId)
53
+ ->where('product_data_nick = ?', $this->productDataNick)
54
+ ->where('type != ?', Ess_M2ePro_Model_Amazon_Template_Description_Specific::DICTIONARY_TYPE_CONTAINER)
55
+ ->where('xpath LIKE ?', "{$this->currentXpath}/%")
56
+ ->order('title ASC');
57
+
58
+ if ($this->searchQuery) {
59
+ $select->where('title LIKE ?', "%{$this->searchQuery}%");
60
+ }
61
+
62
+ $filteredResult = array();
63
+
64
+ $queryStmt = $select->query();
65
+ while ($row = $queryStmt->fetch()) {
66
+
67
+ if (in_array($row['xpath'], $this->renderedSpecifics) ||
68
+ in_array($row['xpath'], $this->selectedSpecifics)) {
69
+ continue;
70
+ }
71
+
72
+ $row['data_definition'] = (array)json_decode($row['data_definition'], true);
73
+ $row['is_desired'] = !empty($row['data_definition']['is_desired']) && $row['data_definition']['is_desired'];
74
+
75
+ if ($this->onlyDesired && !$row['is_desired']) {
76
+ continue;
77
+ }
78
+
79
+ $filteredResult[] = $row;
80
+ }
81
+
82
+ usort($filteredResult, function($a, $b) {
83
+
84
+ if ($a['is_desired'] && !$b['is_desired']) {
85
+ return -1;
86
+ }
87
+
88
+ if ($b['is_desired'] && !$a['is_desired']) {
89
+ return 1;
90
+ }
91
+
92
+ return $a['title'] == $b['title'] ? 0 : ($a['title'] > $b['title'] ? 1 : -1);
93
+ });
94
+
95
+ $collection = new Varien_Data_Collection();
96
+ foreach ($filteredResult as $item) {
97
+ $collection->addItem(new Varien_Object($item));
98
+ }
99
+ $this->setCollection($collection);
100
+
101
+ return parent::_prepareCollection();
102
+ }
103
+
104
+ protected function _prepareColumns()
105
+ {
106
+ $this->addColumn('title', array(
107
+ 'header' => Mage::helper('M2ePro')->__('Specific'),
108
+ 'align' => 'left',
109
+ 'type' => 'text',
110
+ 'index' => 'title',
111
+ 'width' => '700px',
112
+ 'filter' => false,
113
+ 'sortable' => false,
114
+ 'frame_callback' => array($this, 'callbackColumnTitle')
115
+ ));
116
+
117
+ $this->addColumn('is_desired', array(
118
+ 'header' => Mage::helper('M2ePro')->__('Desired'),
119
+ 'align' => 'center',
120
+ 'type' => 'text',
121
+ 'index' => 'is_desired',
122
+ 'width' => '80px',
123
+ 'filter' => false,
124
+ 'sortable' => false,
125
+ 'frame_callback' => array($this, 'callbackColumnIsDesired')
126
+ ));
127
+
128
+ $this->addColumn('actions', array(
129
+ 'header' => Mage::helper('M2ePro')->__('Action'),
130
+ 'align' => 'center',
131
+ 'type' => 'text',
132
+ 'width' => '80px',
133
+ 'filter' => false,
134
+ 'sortable' => false,
135
+ 'frame_callback' => array($this, 'callbackColumnActions'),
136
+ ));
137
+ }
138
+
139
+ // ####################################
140
+
141
+ public function callbackColumnTitle($title, $row, $column, $isExport)
142
+ {
143
+ strlen($title) > 60 && $title = substr($title, 0, 60) . '...';
144
+ $title = Mage::helper('M2ePro')->escapeHtml($title);
145
+
146
+ $path = explode('/', ltrim($row->getData('xpath'), '/'));
147
+ array_pop($path);
148
+ $path = implode(' > ', $path);
149
+ $path = Mage::helper('M2ePro')->escapeHtml($path);
150
+
151
+ $fullPath = $path;
152
+ strlen($path) > 135 && $path = substr($path, 0, 135) . '...';
153
+
154
+ $foundInWord = Mage::helper('M2ePro')->__('Found In: ');
155
+
156
+ return <<<HTML
157
+ <div style="margin-left: 3px">
158
+ <a href="javascript:void(0);" class="specific_search_result_row" xpath ="{$row->getData('xpath')}"
159
+ xml_tag = {$row->getData('xml_tag')}>
160
+ {$title}
161
+ </a><br/>
162
+ <span style="font-weight: bold;">{$foundInWord}</span>&nbsp;
163
+ <span title="{$fullPath}">{$path}</span><br/>
164
+ </div>
165
+ HTML;
166
+ }
167
+
168
+ public function callbackColumnIsDesired($value, $row, $column, $isExport)
169
+ {
170
+ return $value ? Mage::helper('M2ePro')->__('Yes') : Mage::helper('M2ePro')->__('No');
171
+ }
172
+
173
+ public function callbackColumnActions($value, $row, $column, $isExport)
174
+ {
175
+ $select = Mage::helper('M2ePro')->__('Select');
176
+ return <<<HTML
177
+ <a href="javascript:void(0);" class="specific_search_result_row" xpath = {$row->getData('xpath')}
178
+ xml_tag = {$row->getData('xml_tag')}>
179
+ {$select}
180
+ </a>
181
+ HTML;
182
+ }
183
+
184
+ // ####################################
185
+
186
+ public function setMarketplaceId($marketplaceId)
187
+ {
188
+ $this->marketplaceId = $marketplaceId;
189
+ return $this;
190
+ }
191
+
192
+ public function setProductDataNick($productDataNick)
193
+ {
194
+ $this->productDataNick = $productDataNick;
195
+ return $this;
196
+ }
197
+
198
+ public function setCurrentXpath($indexedXpath)
199
+ {
200
+ $this->currentXpath = preg_replace('/-\d+/', '', $indexedXpath);
201
+ return $this;
202
+ }
203
+
204
+ public function setRenderedSpecifics(array $specifics)
205
+ {
206
+ $this->renderedSpecifics = $this->replaceWithDictionaryXpathes($specifics);
207
+ return $this;
208
+ }
209
+
210
+ public function setSelectedSpecifics(array $specifics)
211
+ {
212
+ $this->selectedSpecifics = $this->replaceWithDictionaryXpathes($specifics);
213
+ return $this;
214
+ }
215
+
216
+ public function setOnlyDesired($value)
217
+ {
218
+ $this->onlyDesired = $value;
219
+ return $this;
220
+ }
221
+
222
+ public function setSearchQuery($searchQuery)
223
+ {
224
+ $this-> searchQuery = $searchQuery;
225
+ return $this;
226
+ }
227
+
228
+ // ------------------------------------
229
+
230
+ private function replaceWithDictionaryXpathes(array $xPathes)
231
+ {
232
+ return array_map(function($el) { return preg_replace('/-\d+/', '', $el); }, $xPathes);
233
+ }
234
+
235
+ // ####################################
236
+
237
+ public function getGridUrl()
238
+ {
239
+ return false;
240
+ }
241
+
242
+ public function getRowUrl($row)
243
+ {
244
+ return false;
245
+ }
246
+
247
+ // ####################################
248
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateDescriptionEdit');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_amazon_template_description';
21
+ $this->_mode = 'edit';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $componentName = !Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()
27
+ ? ' ' . Mage::helper('M2ePro/Component_Amazon')->getTitle() : '';
28
+
29
+ if ($this->isEditMode()) {
30
+ $this->_headerText = Mage::helper('M2ePro')->__("Edit%s Description Policy", $componentName);
31
+ $this->_headerText .= ' "'.$this->escapeHtml(
32
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
33
+ } else {
34
+ $this->_headerText = Mage::helper('M2ePro')->__("Add%s Description Policy", $componentName);
35
+ }
36
+ //------------------------------
37
+
38
+ // Set buttons actions
39
+ //------------------------------
40
+ $this->removeButton('back');
41
+ $this->removeButton('reset');
42
+ $this->removeButton('delete');
43
+ $this->removeButton('add');
44
+ $this->removeButton('save');
45
+ $this->removeButton('edit');
46
+ //------------------------------
47
+
48
+ //------------------------------
49
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
50
+ $this->_addButton('back', array(
51
+ 'label' => Mage::helper('M2ePro')->__('Back'),
52
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
53
+ 'class' => 'back'
54
+ ));
55
+ //------------------------------
56
+
57
+ if ($this->isEditMode()) {
58
+
59
+ $headId = 'common-amazon-template-description';
60
+ //------------------------------
61
+ $this->_addButton('duplicate', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
63
+ 'onclick' => "AmazonTemplateDescriptionHandlerObj.duplicate_click('{$headId}')",
64
+ 'class' => 'add M2ePro_duplicate_button'
65
+ ));
66
+ //------------------------------
67
+
68
+ //------------------------------
69
+ $this->_addButton('delete', array(
70
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
71
+ 'onclick' => 'CommonHandlerObj.delete_click()',
72
+ 'class' => 'delete M2ePro_delete_button'
73
+ ));
74
+ //------------------------------
75
+ }
76
+
77
+ //------------------------------
78
+ $this->_addButton('save', array(
79
+ 'label' => Mage::helper('M2ePro')->__('Save'),
80
+ 'onclick' => 'AmazonTemplateDescriptionHandlerObj.save_click()',
81
+ 'class' => 'save'
82
+ ));
83
+ //------------------------------
84
+
85
+ //------------------------------
86
+ $this->_addButton('save_and_continue', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
88
+ 'onclick' => 'AmazonTemplateDescriptionHandlerObj.save_and_edit_click()',
89
+ 'class' => 'save'
90
+ ));
91
+ //------------------------------
92
+ }
93
+
94
+ // ####################################
95
+
96
+ private function isEditMode()
97
+ {
98
+ $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
99
+ return $templateModel && $templateModel->getId();
100
+ }
101
+
102
+ // ####################################
103
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Form.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonTemplateDescriptionEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ // ####################################
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'method' => 'post',
28
+ 'action' => $this->getUrl('*/*/save'),
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ // ####################################
39
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonTemplateDescriptionEditTabs');
18
+ //------------------------------
19
+
20
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
21
+ $this->setDestElementId('edit_form');
22
+ }
23
+
24
+ // ####################################
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ $this->addTab('general', array(
29
+ 'label' => Mage::helper('M2ePro')->__('General'),
30
+ 'title' => Mage::helper('M2ePro')->__('General'),
31
+ 'content' => $this->getLayout()->createBlock(
32
+ 'M2ePro/adminhtml_common_amazon_template_description_edit_tabs_general'
33
+ )->toHtml(),
34
+ ));
35
+
36
+ $this->addTab('definition', array(
37
+ 'label' => Mage::helper('M2ePro')->__('Definition'),
38
+ 'title' => Mage::helper('M2ePro')->__('Definition'),
39
+ 'content' => $this->getLayout()->createBlock(
40
+ 'M2ePro/adminhtml_common_amazon_template_description_edit_tabs_definition'
41
+ )->toHtml(),
42
+ ));
43
+
44
+ $this->addTab('specifics', array(
45
+ 'label' => Mage::helper('M2ePro')->__('Specifics'),
46
+ 'title' => Mage::helper('M2ePro')->__('Specifics'),
47
+ 'content' => $this->getLayout()->createBlock(
48
+ 'M2ePro/adminhtml_common_amazon_template_description_edit_tabs_specifics'
49
+ )->toHtml(),
50
+ ));
51
+
52
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
53
+
54
+ return parent::_beforeToHtml();
55
+ }
56
+
57
+ // ####################################
58
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Definition.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs_Definition
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateDescriptionEditTabsDefinition');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/template/description/tabs/definition.phtml');
22
+ }
23
+
24
+ // ####################################
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ //------------------------------
29
+ $data = array(
30
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
31
+ 'onclick' => "AttributeHandlerObj.appendToText('select_attributes_for_title', 'title_template');",
32
+ 'class' => 'select_attributes_for_title_button'
33
+ );
34
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
35
+ $this->setChild('select_attributes_for_title_button', $buttonBlock);
36
+ //------------------------------
37
+
38
+ //------------------------------
39
+ $data = array(
40
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
41
+ 'onclick' => "AttributeHandlerObj.appendToTextarea('#' + $('select_attributes').value + '#');",
42
+ 'class' => 'add_product_attribute_button',
43
+ );
44
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
45
+ $this->setChild('add_product_attribute_button', $buttonBlock);
46
+ //------------------------------
47
+
48
+ //------------------------------
49
+ for ($i = 0; $i < 4; $i++) {
50
+ $button = $this->getMultiElementButton('target_audience', $i);
51
+ $this->setChild("select_attributes_for_target_audience_{$i}_button", $button);
52
+ }
53
+ //------------------------------
54
+
55
+ //------------------------------
56
+ for ($i = 0; $i < 5; $i++) {
57
+ $button = $this->getMultiElementButton('bullet_points', $i);
58
+ $this->setChild("select_attributes_for_bullet_points_{$i}_button", $button);
59
+ }
60
+ //------------------------------
61
+
62
+ //------------------------------
63
+ for ($i = 0; $i < 5; $i++) {
64
+ $button = $this->getMultiElementButton('search_terms', $i);
65
+ $this->setChild("select_attributes_for_search_terms_{$i}_button", $button);
66
+ }
67
+ //------------------------------
68
+
69
+ //--
70
+ $attributeHelper = Mage::helper('M2ePro/Magento_Attribute');
71
+ $this->setData('all_attributes', $attributeHelper->getAll());
72
+ $this->setData('general_attributes', $attributeHelper->getGeneralFromAllAttributeSets());
73
+ //--
74
+
75
+ return parent::_beforeToHtml();
76
+ }
77
+
78
+ // ####################################
79
+
80
+ private function getMultiElementButton($type, $index)
81
+ {
82
+ $onClick = <<<JS
83
+ AttributeHandlerObj.appendToText('select_attributes_for_{$type}_{$index}', '{$type}_{$index}');
84
+ AmazonTemplateDescriptionDefinitionHandlerObj.multi_element_keyup('{$type}',{value:' '});
85
+ JS;
86
+ $data = array(
87
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
88
+ 'onclick' => $onClick,
89
+ 'class' => "select_attributes_for_{$type}_{$index}_button"
90
+ );
91
+ return $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
92
+ }
93
+
94
+ // ####################################
95
+
96
+ public function getForceAddedAttributeOptionHtml($attributeName, $availableValues)
97
+ {
98
+ if ($attributeName == '') {
99
+ return '';
100
+ }
101
+
102
+ if (Mage::helper('M2ePro/Magento_Attribute')->isExistInAttributesArray($attributeName, $availableValues)) {
103
+ return '';
104
+ }
105
+
106
+ $attributeLabel = Mage::helper('M2ePro/Magento_Attribute')->getAttributeLabel($attributeName);
107
+
108
+ return <<<HTML
109
+ <option value="{$attributeName}" selected="selected">
110
+ {$attributeLabel}
111
+ </option>
112
+ HTML;
113
+
114
+ }
115
+
116
+ // ------------------------------------
117
+
118
+ public function getWeightUnits()
119
+ {
120
+ return array(
121
+ 'GR',
122
+ 'KG',
123
+ 'OZ',
124
+ 'LB',
125
+ 'MG'
126
+ );
127
+ }
128
+
129
+ public function getDimensionsUnits()
130
+ {
131
+ return array(
132
+ 'MM',
133
+ 'CM',
134
+ 'M',
135
+ 'IN',
136
+ 'FT'
137
+ );
138
+ }
139
+
140
+ // ####################################
141
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/General.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs_General
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateDescriptionEditTabsGeneral');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/template/description/tabs/general.phtml');
22
+ }
23
+
24
+ // ####################################
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
29
+
30
+ //--
31
+ $marketplaces = Mage::helper('M2ePro/Component_Amazon')->getMarketplacesAvailableForAsinCreation();
32
+ $marketplaces = $marketplaces->toArray();
33
+ $this->setData('marketplaces', $marketplaces['items']);
34
+ //--
35
+
36
+ //--
37
+ $marketplaceLocked = $categoryLocked = $newAsinSwitcherLocked = false;
38
+
39
+ if ($templateModel && $templateModel->getId()) {
40
+ $marketplaceLocked = $templateModel->isLocked();
41
+ $categoryLocked = $templateModel->getChildObject()->isLockedForCategoryChange();
42
+ $newAsinSwitcherLocked = $templateModel->getChildObject()->isLockedForNewAsinCreation();
43
+ }
44
+
45
+ $this->setData('marketplace_locked', $marketplaceLocked);
46
+ $this->setData('category_locked', $categoryLocked);
47
+ $this->setData('new_asin_switcher_locked', $newAsinSwitcherLocked);
48
+ //--
49
+
50
+ //--
51
+ $attributeHelper = Mage::helper('M2ePro/Magento_Attribute');
52
+ $this->setData('all_attributes', $attributeHelper->getAll());
53
+ $this->setData('general_attributes', $attributeHelper->getGeneralFromAllAttributeSets());
54
+ //--
55
+
56
+ return parent::_beforeToHtml();
57
+ }
58
+
59
+ // ####################################
60
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Specifics.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs_Specifics
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateDescriptionEditTabsSpecifics');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/template/description/tabs/specifics.phtml');
22
+ }
23
+
24
+ // ####################################
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ //--
29
+ $this->setData('attributes', Mage::helper('M2ePro/Magento_Attribute')->getAll());
30
+ //--
31
+
32
+ return parent::_beforeToHtml();
33
+ }
34
+
35
+ // ####################################
36
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Grid.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('templateDescriptionGrid');
18
+ //------------------------------
19
+
20
+ // Set default values
21
+ //------------------------------
22
+ $this->setDefaultSort('id');
23
+ $this->setDefaultDir('ASC');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setUseAjax(true);
26
+ //------------------------------
27
+ }
28
+
29
+ // ####################################
30
+
31
+ protected function _prepareCollection()
32
+ {
33
+ $collection = Mage::getModel('M2ePro/Template_Description')->getCollection();
34
+ $collection->addFieldToFilter('main_table.component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
35
+
36
+ $collection->getSelect()->join(
37
+ array('atd' => Mage::getModel('M2ePro/Amazon_Template_Description')->getResource()->getMainTable()),
38
+ 'atd.template_description_id=main_table.id',
39
+ array('marketplace_id','category_path','browsenode_id','is_new_asin_accepted')
40
+ );
41
+
42
+ $collection->getSelect()->join(
43
+ array('mm' => Mage::getModel('M2ePro/Marketplace')->getResource()->getMainTable()),
44
+ 'mm.id=atd.marketplace_id',
45
+ array('status')
46
+ );
47
+
48
+ $collection->addFieldToFilter('mm.status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
49
+
50
+ $this->setCollection($collection);
51
+ return parent::_prepareCollection();
52
+ }
53
+
54
+ protected function _prepareColumns()
55
+ {
56
+ $this->addColumn('id', array(
57
+ 'header' => Mage::helper('M2ePro')->__('ID'),
58
+ 'align' => 'right',
59
+ 'type' => 'number',
60
+ 'width' => '50px',
61
+ 'index' => 'id',
62
+ 'filter_index' => 'main_table.id',
63
+ 'frame_callback' => array($this, 'callbackColumnId')
64
+ ));
65
+
66
+ $this->addColumn('title', array(
67
+ 'header' => Mage::helper('M2ePro')->__('Title / Category'),
68
+ 'align' => 'left',
69
+ 'type' => 'text',
70
+ 'width' => '500px',
71
+ 'index' => 'title',
72
+ 'filter_index' => 'main_table.title',
73
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
74
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
75
+ ));
76
+
77
+ $this->addColumn('new_asin', array(
78
+ 'header' => Mage::helper('M2ePro')->__('New ASIN / ISBN'),
79
+ 'align' => 'left',
80
+ 'type' => 'options',
81
+ 'options' => array(
82
+ '1' => Mage::helper('M2ePro')->__('Yes'),
83
+ '0' => Mage::helper('M2ePro')->__('No')
84
+ ),
85
+ 'width' => '50px',
86
+ 'index' => 'is_new_asin_accepted',
87
+ 'filter_index' => 'atd.is_new_asin_accepted'
88
+ ));
89
+
90
+ $this->addColumn('marketplace', array(
91
+ 'header' => Mage::helper('M2ePro')->__('Marketplace'),
92
+ 'align' => 'left',
93
+ 'type' => 'options',
94
+ 'options' => Mage::helper('M2ePro/Component_Amazon')->getMarketplacesAvailableForAsinCreation()
95
+ ->toOptionHash(),
96
+ 'width' => '100px',
97
+ 'index' => 'marketplace_id',
98
+ 'filter_index' => 'atd.marketplace_id'
99
+ ));
100
+
101
+ $this->addColumn('update_date', array(
102
+ 'header' => Mage::helper('M2ePro')->__('Update Date'),
103
+ 'align' => 'left',
104
+ 'width' => '80px',
105
+ 'type' => 'datetime',
106
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
107
+ 'index' => 'update_date',
108
+ 'filter_index' => 'main_table.update_date'
109
+ ));
110
+
111
+ $this->addColumn('create_date', array(
112
+ 'header' => Mage::helper('M2ePro')->__('Creation Date'),
113
+ 'align' => 'left',
114
+ 'width' => '80px',
115
+ 'type' => 'datetime',
116
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
117
+ 'index' => 'create_date',
118
+ 'filter_index' => 'main_table.create_date'
119
+ ));
120
+
121
+ $this->addColumn('actions', array(
122
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
123
+ 'align' => 'left',
124
+ 'width' => '100px',
125
+ 'type' => 'action',
126
+ 'index' => 'actions',
127
+ 'filter' => false,
128
+ 'sortable' => false,
129
+ 'getter' => 'getId',
130
+ 'actions' => array(
131
+ array(
132
+ 'caption' => Mage::helper('M2ePro')->__('Edit'),
133
+ 'url' => array('base'=> '*/*/edit'),
134
+ 'field' => 'id'
135
+ ),
136
+ array(
137
+ 'caption' => Mage::helper('M2ePro')->__('Delete'),
138
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
139
+ 'url' => array('base' => '*/*/delete'),
140
+ 'field' => 'ids'
141
+ ),
142
+ )
143
+ ));
144
+ }
145
+
146
+ // ####################################
147
+
148
+ protected function _prepareMassaction()
149
+ {
150
+ // Set massaction identifiers
151
+ //--------------------------------
152
+ $this->setMassactionIdField('main_table.id');
153
+ $this->getMassactionBlock()->setFormFieldName('ids');
154
+ //--------------------------------
155
+
156
+ // Set delete action
157
+ //--------------------------------
158
+ $this->getMassactionBlock()->addItem('delete', array(
159
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
160
+ 'url' => $this->getUrl('*/*/delete'),
161
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
162
+ ));
163
+ //--------------------------------
164
+
165
+ return parent::_prepareMassaction();
166
+ }
167
+
168
+ // ####################################
169
+
170
+ public function callbackColumnId($value, $row, $column, $isExport)
171
+ {
172
+ return $value.'&nbsp;';
173
+ }
174
+
175
+ //--------------------------------
176
+
177
+ public function callbackColumnTitle($value, $row, $column, $isExport)
178
+ {
179
+ $titleWord = Mage::helper('M2ePro')->__('Title');
180
+ $title = Mage::helper('M2ePro')->escapeHtml($value);
181
+
182
+ $categoryWord = Mage::helper('M2ePro')->__('Category');
183
+ $categoryPath = !empty($row['category_path']) ? "{$row['category_path']} ({$row['browsenode_id']})"
184
+ : Mage::helper('M2ePro')->__('Not Set');
185
+ return <<<HTML
186
+ <span style="font-weight: bold">{$titleWord}</span>: {$title}
187
+ <div>
188
+ <span style="font-weight: bold">{$categoryWord}</span>: <span style="color: #505050">{$categoryPath}</span><br/>
189
+ </div>
190
+ HTML;
191
+ }
192
+
193
+ // ####################################
194
+
195
+ protected function callbackFilterTitle($collection, $column)
196
+ {
197
+ $value = $column->getFilter()->getValue();
198
+
199
+ if ($value == null) {
200
+ return;
201
+ }
202
+
203
+ $collection->getSelect()->where(
204
+ "`atd`.`category_path` LIKE '%{$value}%' OR
205
+ `atd`.`browsenode_id` LIKE '%{$value}%' OR
206
+ `main_table`.`title` LIKE '%{$value}%'"
207
+ );
208
+ }
209
+
210
+ // ####################################
211
+
212
+ public function getGridUrl()
213
+ {
214
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/grid', array('_current'=>true));
215
+ }
216
+
217
+ public function getRowUrl($row)
218
+ {
219
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array('id' => $row->getData('id')));
220
+ }
221
+
222
+ // ####################################
223
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Help.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+ $this->setTemplate('M2ePro/common/amazon/template/description/help.phtml');
15
+ }
16
+
17
+ // ########################################
18
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_SellingFormat_Edit
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSellingFormatEdit');
17
+ $this->_blockGroup = 'M2ePro';
18
+ $this->_controller = 'adminhtml_common_amazon_template_sellingFormat';
19
+ $this->_mode = 'edit';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $helper = Mage::helper('M2ePro');
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
27
+ $headerTextEdit = $helper->__("Edit %component_name% Selling Format Policy", $componentName);
28
+ $headerTextAdd = $helper->__("Add %component_name% Selling Format Policy", $componentName);
29
+ } else {
30
+ $headerTextEdit = $helper->__("Edit Selling Format Policy");
31
+ $headerTextAdd = $helper->__("Add Selling Format Policy" );
32
+ }
33
+
34
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
35
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
36
+ ) {
37
+ $this->_headerText = $headerTextEdit;
38
+ $this->_headerText .= ' "'.$this->escapeHtml(
39
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
40
+ } else {
41
+ $this->_headerText = $headerTextAdd;
42
+ }
43
+ //------------------------------
44
+
45
+ // Set buttons actions
46
+ //------------------------------
47
+ $this->removeButton('back');
48
+ $this->removeButton('reset');
49
+ $this->removeButton('delete');
50
+ $this->removeButton('add');
51
+ $this->removeButton('save');
52
+ $this->removeButton('edit');
53
+ //------------------------------
54
+
55
+ //------------------------------
56
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
57
+ $this->_addButton('back', array(
58
+ 'label' => Mage::helper('M2ePro')->__('Back'),
59
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.back_click(\'' . $url . '\')',
60
+ 'class' => 'back'
61
+ ));
62
+ //------------------------------
63
+
64
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
65
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
66
+ ) {
67
+ //------------------------------
68
+ $this->_addButton('duplicate', array(
69
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
70
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.duplicate_click'
71
+ .'(\'common-amazon-template-sellingFormat\')',
72
+ 'class' => 'add M2ePro_duplicate_button'
73
+ ));
74
+ //------------------------------
75
+
76
+ //------------------------------
77
+ $this->_addButton('delete', array(
78
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
79
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.delete_click()',
80
+ 'class' => 'delete M2ePro_delete_button'
81
+ ));
82
+ //------------------------------
83
+ }
84
+
85
+ //------------------------------
86
+ $this->_addButton('save', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Save'),
88
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.save_click()',
89
+ 'class' => 'save'
90
+ ));
91
+ //------------------------------
92
+
93
+ //------------------------------
94
+ $this->_addButton('save_and_continue', array(
95
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
96
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.save_and_edit_click()',
97
+ 'class' => 'save'
98
+ ));
99
+ //------------------------------
100
+ }
101
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit/Form.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_SellingFormat_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ const QTY_MODE_PRODUCT_FIXED_VIRTUAL_ATTRIBUTE_VALUE = 'qty_mode_product_fixed';
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonTemplateSellingFormatEditForm');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/template/selling_format/form.phtml');
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/*/save'),
28
+ 'method' => 'post',
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ protected function _beforeToHtml()
39
+ {
40
+ //------------------------------
41
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
42
+ //------------------------------
43
+
44
+ //------------------------------
45
+ $this->setData('currencies', Mage::helper('M2ePro/Component_Amazon')->getCurrencies());
46
+ //------------------------------
47
+
48
+ //------------------------------
49
+ $this->customerGroups = Mage::getModel('customer/group')->getCollection()->toOptionArray();
50
+ //------------------------------
51
+
52
+ return parent::_beforeToHtml();
53
+ }
54
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSynchronizationEdit');
17
+ $this->_blockGroup = 'M2ePro';
18
+ $this->_controller = 'adminhtml_common_amazon_template_synchronization';
19
+ $this->_mode = 'edit';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
25
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
26
+ $headerTextEdit = Mage::helper('M2ePro')->__(
27
+ "Edit %component_name% Synchronization Policy",
28
+ $componentName
29
+ );
30
+ $headerTextAdd = Mage::helper('M2ePro')->__(
31
+ "Add %component_name% Synchronization Policy",
32
+ $componentName);
33
+ } else {
34
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit Synchronization Policy");
35
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add Synchronization Policy");
36
+ }
37
+
38
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
39
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
40
+ ) {
41
+ $this->_headerText = $headerTextEdit;
42
+ $this->_headerText .= ' "'.$this->escapeHtml(
43
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
44
+ } else {
45
+ $this->_headerText = $headerTextAdd;
46
+ }
47
+ //------------------------------
48
+
49
+ // Set buttons actions
50
+ //------------------------------
51
+ $this->removeButton('back');
52
+ $this->removeButton('reset');
53
+ $this->removeButton('delete');
54
+ $this->removeButton('add');
55
+ $this->removeButton('save');
56
+ $this->removeButton('edit');
57
+ //------------------------------
58
+
59
+ //------------------------------
60
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
61
+ $this->_addButton('back', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Back'),
63
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.back_click(\'' . $url . '\')',
64
+ 'class' => 'back'
65
+ ));
66
+ //------------------------------
67
+
68
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
69
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
70
+ ) {
71
+ //------------------------------
72
+ $this->_addButton('duplicate', array(
73
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
74
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.duplicate_click'
75
+ .'(\'common-amazon-template-synchronization\')',
76
+ 'class' => 'add M2ePro_duplicate_button'
77
+ ));
78
+ //------------------------------
79
+
80
+ //------------------------------
81
+ $this->_addButton('delete', array(
82
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
83
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.delete_click()',
84
+ 'class' => 'delete M2ePro_delete_button'
85
+ ));
86
+ //------------------------------
87
+ }
88
+
89
+ //------------------------------
90
+ $this->_addButton('save', array(
91
+ 'label' => Mage::helper('M2ePro')->__('Save'),
92
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.save_click()',
93
+ 'class' => 'save'
94
+ ));
95
+ //------------------------------
96
+
97
+ //------------------------------
98
+ $this->_addButton('save_and_continue', array(
99
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
100
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.save_and_edit_click'
101
+ .'(\'\',\'amazonTemplateSynchronizationEditTabs\')',
102
+ 'class' => 'save'
103
+ ));
104
+ //------------------------------
105
+ }
106
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Form.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Form
8
+ extends Mage_Adminhtml_Block_Widget_Form
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSynchronizationEditForm');
17
+ //------------------------------
18
+ }
19
+
20
+ protected function _prepareForm()
21
+ {
22
+ $form = new Varien_Data_Form(array(
23
+ 'id' => 'edit_form',
24
+ 'action' => $this->getUrl('*/*/save'),
25
+ 'method' => 'post',
26
+ 'enctype' => 'multipart/form-data'
27
+ ));
28
+
29
+ $form->setUseContainer(true);
30
+ $this->setForm($form);
31
+
32
+ return parent::_prepareForm();
33
+ }
34
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs
8
+ extends Mage_Adminhtml_Block_Widget_Tabs
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSynchronizationEditTabs');
17
+ //------------------------------
18
+
19
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
20
+ $this->setDestElementId('edit_form');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ $this->addTab('list',array(
26
+ 'label' => Mage::helper('M2ePro')->__('List Rules'),
27
+ 'title' => Mage::helper('M2ePro')->__('List Rules'),
28
+ 'content' => $this->getLayout()
29
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_list')
30
+ ->toHtml()
31
+ ));
32
+
33
+ $this->addTab('revise',array(
34
+ 'label' => Mage::helper('M2ePro')->__('Revise Rules'),
35
+ 'title' => Mage::helper('M2ePro')->__('Revise Rules'),
36
+ 'content' => $this->getLayout()
37
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_revise')
38
+ ->toHtml()
39
+ ));
40
+
41
+ $this->addTab('relist',array(
42
+ 'label' => Mage::helper('M2ePro')->__('Relist Rules'),
43
+ 'title' => Mage::helper('M2ePro')->__('Relist Rules'),
44
+ 'content' => $this->getLayout()
45
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_relist')
46
+ ->toHtml()
47
+ ));
48
+
49
+ $this->addTab('stop',array(
50
+ 'label' => Mage::helper('M2ePro')->__('Stop Rules'),
51
+ 'title' => Mage::helper('M2ePro')->__('Stop Rules'),
52
+ 'content' => $this->getLayout()
53
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_stop')
54
+ ->toHtml()
55
+ ));
56
+
57
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'list'));
58
+
59
+ return parent::_beforeToHtml();
60
+ }
61
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/List.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_List
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSynchronizationEditTabsList');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/list.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Relist.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_Relist
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSynchronizationEditTabsRelist');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/relist.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Revise.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_Revise
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSynchronizationEditTabsRevise');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/revise.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Stop.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_Stop
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('amazonTemplateSynchronizationEditTabsStop');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/stop.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyAccountEdit');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_buy_account';
18
+ $this->_mode = 'edit';
19
+ //------------------------------
20
+
21
+ // Set header text
22
+ //------------------------------
23
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
24
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
25
+ $headerTextEdit = $this->_headerText = Mage::helper('M2ePro')->__(
26
+ "Edit %component_name% Account",
27
+ $componentName
28
+ );
29
+ $headerTextAdd = $this->_headerText = Mage::helper('M2ePro')->__(
30
+ "Add %component_name% Account",
31
+ $componentName
32
+ );
33
+ } else {
34
+ $headerTextEdit = $this->_headerText = Mage::helper('M2ePro')->__("Edit Account");
35
+ $headerTextAdd = $this->_headerText = Mage::helper('M2ePro')->__("Add Account");
36
+ }
37
+
38
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
39
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
40
+ ) {
41
+ $this->_headerText = $headerTextEdit;
42
+ $this->_headerText .= ' "'.$this->escapeHtml(
43
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()
44
+ ).'"';
45
+ } else {
46
+ $this->_headerText = $headerTextAdd;
47
+ }
48
+ //------------------------------
49
+
50
+ // Set buttons actions
51
+ //------------------------------
52
+ $this->removeButton('back');
53
+ $this->removeButton('reset');
54
+ $this->removeButton('delete');
55
+ $this->removeButton('add');
56
+ $this->removeButton('save');
57
+ $this->removeButton('edit');
58
+
59
+ /* @var $wizardHelper Ess_M2ePro_Helper_Module_Wizard */
60
+ $wizardHelper = Mage::helper('M2ePro/Module_Wizard');
61
+
62
+ if ($wizardHelper->isActive('buy') &&
63
+ $wizardHelper->getStep('buy') == 'account'
64
+ ) {
65
+
66
+ //------------------------------
67
+ $this->_addButton('save_and_continue', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
69
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
70
+ 'class' => 'save'
71
+ ));
72
+ //------------------------------
73
+
74
+ if ($this->getRequest()->getParam('id')) {
75
+ //------------------------------
76
+ $url = $this->getUrl('*/adminhtml_common_buy_account/new', array('wizard' => true));
77
+ $this->_addButton('add_new_account', array(
78
+ 'label' => Mage::helper('M2ePro')->__('Add New Account'),
79
+ 'onclick' => 'setLocation(\''. $url .'\')',
80
+ 'class' => 'add_new_account'
81
+ ));
82
+ //------------------------------
83
+
84
+ //------------------------------
85
+ $this->_addButton('close', array(
86
+ 'label' => Mage::helper('M2ePro')->__('Complete This Step'),
87
+ 'onclick' => 'BuyAccountHandlerObj.completeStep();',
88
+ 'class' => 'close'
89
+ ));
90
+ //------------------------------
91
+ }
92
+ } else {
93
+
94
+ if ((bool)$this->getRequest()->getParam('close_on_save',false)) {
95
+
96
+ if ($this->getRequest()->getParam('id')) {
97
+ $this->_addButton('save', array(
98
+ 'label' => Mage::helper('M2ePro')->__('Save And Close'),
99
+ 'onclick' => 'BuyAccountHandlerObj.saveAndClose()',
100
+ 'class' => 'save'
101
+ ));
102
+ } else {
103
+ $this->_addButton('save_and_continue', array(
104
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
105
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
106
+ 'class' => 'save'
107
+ ));
108
+ }
109
+ return;
110
+ }
111
+
112
+ //------------------------------
113
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
114
+ $this->_addButton('back', array(
115
+ 'label' => Mage::helper('M2ePro')->__('Back'),
116
+ 'onclick' => 'BuyAccountHandlerObj.back_click(\'' . $url .'\')',
117
+ 'class' => 'back'
118
+ ));
119
+ //------------------------------
120
+
121
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
122
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
123
+ ) {
124
+ //------------------------------
125
+ $this->_addButton('delete', array(
126
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
127
+ 'onclick' => 'BuyAccountHandlerObj.delete_click()',
128
+ 'class' => 'delete M2ePro_delete_button'
129
+ ));
130
+ //------------------------------
131
+ }
132
+
133
+ //------------------------------
134
+ $this->_addButton('save', array(
135
+ 'label' => Mage::helper('M2ePro')->__('Save'),
136
+ 'onclick' => 'BuyAccountHandlerObj.save_click()',
137
+ 'class' => 'save'
138
+ ));
139
+ //------------------------------
140
+
141
+ //------------------------------
142
+ $this->_addButton('save_and_continue', array(
143
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
144
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
145
+ 'class' => 'save'
146
+ ));
147
+ //------------------------------
148
+ }
149
+ }
150
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Form.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyAccountEditForm');
16
+ //------------------------------
17
+ }
18
+
19
+ protected function _prepareForm()
20
+ {
21
+ $form = new Varien_Data_Form(array(
22
+ 'id' => 'edit_form',
23
+ 'action' => $this->getUrl('*/*/save'),
24
+ 'method' => 'post',
25
+ 'enctype' => 'multipart/form-data'
26
+ ));
27
+
28
+ $form->setUseContainer(true);
29
+ $this->setForm($form);
30
+
31
+ return parent::_prepareForm();
32
+ }
33
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyAccountEditTabs');
16
+ //------------------------------
17
+
18
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
19
+ $this->setDestElementId('edit_form');
20
+ }
21
+
22
+ protected function _beforeToHtml()
23
+ {
24
+ $this->addTab('general', array(
25
+ 'label' => Mage::helper('M2ePro')->__('General'),
26
+ 'title' => Mage::helper('M2ePro')->__('General'),
27
+ 'content' => $this->getLayout()
28
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_general')
29
+ ->toHtml(),
30
+ ));
31
+
32
+ $this->addTab('listingOther', array(
33
+ 'label' => Mage::helper('M2ePro')->__('3rd Party Listings'),
34
+ 'title' => Mage::helper('M2ePro')->__('3rd Party Listings'),
35
+ 'content' => $this->getLayout()
36
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_listingOther')
37
+ ->toHtml(),
38
+ ));
39
+
40
+ $this->addTab('orders', array(
41
+ 'label' => Mage::helper('M2ePro')->__('Orders'),
42
+ 'title' => Mage::helper('M2ePro')->__('Orders'),
43
+ 'content' => $this->getLayout()
44
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_order')
45
+ ->toHtml(),
46
+ ));
47
+
48
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
49
+
50
+ return parent::_beforeToHtml();
51
+ }
52
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/General.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs_General extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyAccountEditTabsGeneral');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/account/tabs/general.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
24
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
25
+ ) {
26
+
27
+ /** @var $accountObj Ess_M2ePro_Model_Account */
28
+ $accountObj = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
29
+
30
+ $this->synchronizeProcessing = $accountObj->isLockedObject('server_synchronize');
31
+
32
+ if (!$this->synchronizeProcessing) {
33
+ $accountId = $accountObj->getId();
34
+
35
+ Mage::helper('M2ePro/Data_Global')->unsetValue('temp_data');
36
+ Mage::helper('M2ePro/Data_Global')->setValue(
37
+ 'temp_data',
38
+ Mage::helper('M2ePro/Component_Buy')->getCachedObject('Account',$accountId)
39
+ );
40
+ }
41
+ } else {
42
+ $this->synchronizeProcessing = false;
43
+ }
44
+
45
+ $marketplaces = Mage::helper('M2ePro/Component_Buy')->getCollection('Marketplace')
46
+ ->addFieldToFilter('status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
47
+
48
+ $this->marketplace = true;
49
+ if ($marketplaces->getSize() <= 0) {
50
+ $this->marketplace = false;
51
+ }
52
+ //var_dump($this->marketplace); exit();
53
+
54
+ //------------------------------
55
+ $data = array(
56
+ 'label' => Mage::helper('M2ePro')->__('Update FTP Password'),
57
+ 'onclick' => 'BuyAccountHandlerObj.update_password(\'ftp\')',
58
+ 'class' => 'scalable'
59
+ );
60
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
61
+ $this->setChild('buy_update_ftp_password', $buttonBlock);
62
+ //------------------------------
63
+
64
+ //------------------------------
65
+ $data = array(
66
+ 'label' => Mage::helper('M2ePro')->__('Update Web Password'),
67
+ 'onclick' => 'BuyAccountHandlerObj.update_password(\'web\')',
68
+ 'class' => 'scalable'
69
+ );
70
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
71
+ $this->setChild('buy_update_web_password', $buttonBlock);
72
+ //------------------------------
73
+
74
+ return parent::_beforeToHtml();
75
+ }
76
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/ListingOther.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs_ListingOther extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyAccountEditTabsListingOther');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/account/tabs/listing_other.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
24
+
25
+ return parent::_beforeToHtml();
26
+ }
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/Order.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs_Order extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ protected $_possibleMagentoStatuses = null;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyAccountEditTabsOrder');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/account/tabs/order.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
26
+ $magentoOrdersSettings = !empty($data['magento_orders_settings'])
27
+ ? json_decode($data['magento_orders_settings'], true) : array();
28
+
29
+ //----------------------------
30
+ $temp = Mage::getModel('core/website')->getCollection()->setOrder('sort_order','ASC')->toArray();
31
+ $this->websites = $temp['items'];
32
+ //----------------------------
33
+
34
+ //----------------------------
35
+ $temp = Mage::getModel('customer/group')->getCollection()->toArray();
36
+ $this->groups = $temp['items'];
37
+ //----------------------------
38
+
39
+ //----------------------------
40
+ $selectedStore = !empty($magentoOrdersSettings['listing']['store_id'])
41
+ ? $magentoOrdersSettings['listing']['store_id'] : '';
42
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
43
+ 'id' => 'magento_orders_listings_store_id',
44
+ 'name' => 'magento_orders_settings[listing][store_id]',
45
+ 'selected' => $selectedStore
46
+ ));
47
+ $blockStoreSwitcher->hasDefaultOption(false);
48
+ $this->setChild('magento_orders_listings_store_id', $blockStoreSwitcher);
49
+ //----------------------------
50
+
51
+ //----------------------------
52
+ $selectedStore = !empty($magentoOrdersSettings['listing_other']['store_id'])
53
+ ? $magentoOrdersSettings['listing_other']['store_id'] : '';
54
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
55
+ 'id' => 'magento_orders_listings_other_store_id',
56
+ 'name' => 'magento_orders_settings[listing_other][store_id]',
57
+ 'selected' => $selectedStore
58
+ ));
59
+ $blockStoreSwitcher->hasDefaultOption(false);
60
+ $this->setChild('magento_orders_listings_other_store_id', $blockStoreSwitcher);
61
+ //----------------------------
62
+
63
+ //----------------------------
64
+ $productTaxClasses = Mage::getModel('tax/class')->getCollection()
65
+ ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)
66
+ ->toOptionArray();
67
+
68
+ $none = array('value' => Ess_M2ePro_Model_Magento_Product::TAX_CLASS_ID_NONE, 'label' => 'None');
69
+ array_unshift($productTaxClasses, $none);
70
+
71
+ $this->productTaxClasses = $productTaxClasses;
72
+ //----------------------------
73
+
74
+ return parent::_beforeToHtml();
75
+ }
76
+
77
+ public function getMagentoOrderStatusList()
78
+ {
79
+ if (is_null($this->_possibleMagentoStatuses)) {
80
+ $this->_possibleMagentoStatuses = Mage::getSingleton('sales/order_config')->getStatuses();
81
+ }
82
+
83
+ return $this->_possibleMagentoStatuses;
84
+ }
85
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListing');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_listing';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $this->_headerText = '';
25
+ //------------------------------
26
+
27
+ // Set buttons actions
28
+ //------------------------------
29
+ $this->removeButton('back');
30
+ $this->removeButton('reset');
31
+ $this->removeButton('delete');
32
+ $this->removeButton('add');
33
+ $this->removeButton('save');
34
+ $this->removeButton('edit');
35
+ //------------------------------
36
+
37
+ //------------------------------
38
+
39
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
40
+ '*/adminhtml_common_listing/index',
41
+ array(
42
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
43
+ )
44
+ );
45
+
46
+ //------------------------------
47
+ $url = $this->getUrl(
48
+ '*/adminhtml_common_log/listing',
49
+ array(
50
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_BUY
51
+ )
52
+ );
53
+ $this->_addButton('view_log', array(
54
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
55
+ 'onclick' => 'window.open(\''.$url.'\')',
56
+ 'class' => 'button_link'
57
+ ));
58
+ //------------------------------
59
+
60
+ //------------------------------
61
+ $url = $this->getUrl('*/adminhtml_common_buy_listing/search', array('back' => $backUrl));
62
+ $this->_addButton('search_buy_products', array(
63
+ 'label' => Mage::helper('M2ePro')->__('Search'),
64
+ 'onclick' => 'setLocation(\''.$url.'\')',
65
+ 'class' => 'button_link search'
66
+ ));
67
+ //------------------------------
68
+
69
+ //------------------------------
70
+ $url = $this->getUrl('*/adminhtml_common_listing_create/index', array(
71
+ 'step' => '1',
72
+ 'clear' => 'yes',
73
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK
74
+ ));
75
+ $this->_addButton('add', array(
76
+ 'label' => Mage::helper('M2ePro')->__('Add Listing'),
77
+ 'onclick' => 'setLocation(\'' .$url.'\')',
78
+ 'class' => 'add'
79
+ ));
80
+ //------------------------------
81
+ }
82
+
83
+ // ####################################
84
+
85
+ public function getTemplatesButtonJavascript()
86
+ {
87
+ $data = array(
88
+ 'target_css_class' => 'buy-templates-drop-down',
89
+ 'items' => $this->getTemplatesButtonDropDownItems()
90
+ );
91
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
92
+ $dropDownBlock->setData($data);
93
+
94
+ return $dropDownBlock->toHtml();
95
+ }
96
+
97
+ protected function getTemplatesButtonDropDownItems()
98
+ {
99
+ $items = array();
100
+
101
+ $filter = base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Buy::NICK);
102
+
103
+ //------------------------------
104
+ $url = $this->getUrl(
105
+ '*/adminhtml_common_template_sellingFormat/index',
106
+ array(
107
+ 'filter' => $filter
108
+ )
109
+ );
110
+ $items[] = array(
111
+ 'url' => $url,
112
+ 'label' => Mage::helper('M2ePro')->__('Selling Format Policies'),
113
+ 'target' => '_blank'
114
+ );
115
+ //------------------------------
116
+
117
+ //------------------------------
118
+ $url = $this->getUrl(
119
+ '*/adminhtml_common_template_synchronization/index',
120
+ array(
121
+ 'filter' => $filter
122
+ )
123
+ );
124
+ $items[] = array(
125
+ 'url' => $url,
126
+ 'label' => Mage::helper('M2ePro')->__('Synchronization Policies'),
127
+ 'target' => '_blank'
128
+ );
129
+ //------------------------------
130
+
131
+ return $items;
132
+ }
133
+
134
+ // ####################################
135
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Form.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Form
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Form
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->component = Ess_M2ePro_Helper_Component_Buy::NICK;
17
+ $this->setId('buyListingEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ // ########################################
22
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/General.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Tabs_General
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_General
9
+ {
10
+ // #############################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->sessionKey = 'buy_listing_create';
19
+ $this->setId('buyListingAddTabsGeneral');
20
+ $this->setTemplate('M2ePro/common/buy/listing/add/tabs/general.phtml');
21
+ //------------------------------
22
+ }
23
+
24
+ // #############################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Search.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Tabs_Search
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Search
9
+ {
10
+ // #############################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->sessionKey = 'buy_listing_create';
19
+ $this->setId('buyListingAddTabsGeneral');
20
+ $this->setTemplate('M2ePro/common/buy/listing/add/tabs/search.phtml');
21
+ //------------------------------
22
+ }
23
+
24
+ // #############################################
25
+
26
+ protected function getDefaults()
27
+ {
28
+ return self::getDefaultFieldsValues();
29
+ }
30
+
31
+ static function getDefaultFieldsValues()
32
+ {
33
+ return array(
34
+ 'general_id_mode' => Ess_M2ePro_Model_Buy_Listing::GENERAL_ID_MODE_NOT_SET,
35
+ 'general_id_custom_attribute' => '',
36
+
37
+ 'search_by_magento_title_mode' => Ess_M2ePro_Model_Buy_Listing::SEARCH_BY_MAGENTO_TITLE_MODE_NONE
38
+ );
39
+ }
40
+
41
+ // #############################################
42
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Selling.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Tabs_Selling
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Selling
9
+ {
10
+ // #############################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->component = Ess_M2ePro_Helper_Component_Buy::NICK;
19
+ $this->sessionKey = 'buy_listing_create';
20
+ $this->setId('buyListingAddTabsSelling');
21
+ $this->setTemplate('M2ePro/common/buy/listing/add/tabs/selling.phtml');
22
+ //------------------------------
23
+ }
24
+
25
+ // #############################################
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ $buttonBlock = $this->getLayout()
30
+ ->createBlock('adminhtml/widget_button')
31
+ ->setData( array(
32
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
33
+ 'onclick' => "BuyListingChannelSettingsHandlerObj.appendToText"
34
+ ."('condition_note_custom_attribute', 'condition_note_value');",
35
+ 'class' => 'condition_note_value_insert_button'
36
+ ) );
37
+ $this->setChild('condition_note_value_insert_button',$buttonBlock);
38
+
39
+ return parent::_beforeToHtml();
40
+ }
41
+
42
+ // #############################################
43
+
44
+ protected function getDefaults()
45
+ {
46
+ return self::getDefaultFieldsValues();
47
+ }
48
+
49
+ static function getDefaultFieldsValues()
50
+ {
51
+ return array(
52
+ 'sku_mode' => Ess_M2ePro_Model_Buy_Listing::SKU_MODE_DEFAULT,
53
+ 'sku_custom_attribute' => '',
54
+ 'generate_sku_mode' => Ess_M2ePro_Model_Buy_Listing::GENERATE_SKU_MODE_NO,
55
+
56
+ 'template_selling_format_id' => '',
57
+ 'template_synchronization_id' => '',
58
+
59
+ 'shipping_standard_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
60
+ 'shipping_standard_value' => 0,
61
+ 'shipping_standard_custom_attribute' => '',
62
+
63
+ 'shipping_expedited_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
64
+ 'shipping_expedited_value' => 0,
65
+ 'shipping_expedited_custom_attribute' => '',
66
+
67
+ 'shipping_two_day_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
68
+ 'shipping_two_day_value' => 0,
69
+ 'shipping_two_day_custom_attribute' => '',
70
+
71
+ 'shipping_one_day_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
72
+ 'shipping_one_day_value' => 0,
73
+ 'shipping_one_day_custom_attribute' => '',
74
+
75
+ 'condition_mode' => Ess_M2ePro_Model_Buy_Listing::CONDITION_MODE_DEFAULT,
76
+ 'condition_value' => Ess_M2ePro_Model_Buy_Listing::CONDITION_NEW,
77
+ 'condition_custom_attribute' => '',
78
+ 'condition_note_mode' => Ess_M2ePro_Model_Buy_Listing::CONDITION_NOTE_MODE_NONE,
79
+ 'condition_note_value' => ''
80
+ );
81
+ }
82
+
83
+ // ####################################
84
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode
9
+ {
10
+
11
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Category
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category
9
+ {
10
+ // ####################################
11
+
12
+ protected function prepareGroupsGrid()
13
+ {
14
+ $groupGrid = $this->getLayout()
15
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_autoAction_mode_category_group_grid');
16
+ $groupGrid->prepareGrid();
17
+ $this->setChild('group_grid', $groupGrid);
18
+
19
+ return $groupGrid;
20
+ }
21
+
22
+ // ####################################
23
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Form.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Category_Form
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Form
9
+ {
10
+
11
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Group/Grid.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Category_Group_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Group_Grid
9
+ {
10
+
11
+ public function getGridUrl()
12
+ {
13
+ return $this->getUrl('*/adminhtml_common_listing_autoAction/getCategoryGroupGrid', array('_current' => true));
14
+ }
15
+
16
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Global.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Global
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Global
9
+ {
10
+
11
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Website.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Website
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Website
9
+ {
10
+
11
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('buyListingEdit');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_buy_listing';
21
+ $this->_mode = 'edit';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+
28
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
29
+ $headerText = Mage::helper('M2ePro')->__(
30
+ 'Edit %component_name% Listing Settings "%listing_title%"',
31
+ Mage::helper('M2ePro/Component_Buy')->getTitle(),
32
+ $this->escapeHtml($listingData['title'])
33
+ );
34
+ } else {
35
+ $headerText =Mage::helper('M2ePro')->__(
36
+ 'Edit Listing Settings "%listing_title%"',
37
+ $this->escapeHtml($listingData['title'])
38
+ );
39
+ }
40
+
41
+ $this->_headerText = $headerText;
42
+ //------------------------------
43
+
44
+ // Set buttons actions
45
+ //------------------------------
46
+ $this->removeButton('back');
47
+ $this->removeButton('reset');
48
+ $this->removeButton('delete');
49
+ $this->removeButton('add');
50
+ $this->removeButton('save');
51
+ $this->removeButton('edit');
52
+ //------------------------------
53
+
54
+ if (!is_null($this->getRequest()->getParam('back'))) {
55
+ //------------------------------
56
+ $url = Mage::helper('M2ePro')->getBackUrl(
57
+ '*/adminhtml_common_listing/index',
58
+ array(
59
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
60
+ )
61
+ );
62
+ $this->_addButton('back', array(
63
+ 'label' => Mage::helper('M2ePro')->__('Back'),
64
+ 'onclick' => 'CommonListingSettingsHandlerObj.back_click(\''.$url.'\')',
65
+ 'class' => 'back'
66
+ ));
67
+ //------------------------------
68
+ }
69
+
70
+ //------------------------------
71
+ $this->_addButton('auto_action', array(
72
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
73
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
74
+ ));
75
+ //------------------------------
76
+
77
+ $backUrl = Mage::helper('M2ePro')->getBackUrlParam('list');
78
+
79
+ //------------------------------
80
+ $url = $this->getUrl(
81
+ '*/adminhtml_common_buy_listing/save',
82
+ array(
83
+ 'id' => $listingData['id'],
84
+ 'back' => Mage::helper('M2ePro')->getBackUrlParam('list')
85
+ )
86
+ );
87
+ $this->_addButton('save', array(
88
+ 'label' => Mage::helper('M2ePro')->__('Save'),
89
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_click(\'' . $url . '\')',
90
+ 'class' => 'save'
91
+ ));
92
+ //------------------------------
93
+
94
+ //------------------------------
95
+ $this->_addButton('save_and_continue', array(
96
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
97
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_and_edit_click(\''.$url.'\', 1)',
98
+ 'class' => 'save'
99
+ ));
100
+ //------------------------------
101
+ }
102
+
103
+ // ####################################
104
+
105
+ protected function _beforeToHtml()
106
+ {
107
+ parent::_beforeToHtml();
108
+
109
+ //------------------------------
110
+ $tabs = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_edit_tabs');
111
+ $this->setChild('tabs', $tabs);
112
+ //------------------------------
113
+
114
+ return $this;
115
+ }
116
+
117
+ // ####################################
118
+
119
+ public function getFormHtml()
120
+ {
121
+ $listing = Mage::helper('M2ePro/Component_Buy')->getCachedObject(
122
+ 'Listing', $this->getRequest()->getParam('id')
123
+ );
124
+
125
+ $viewHeaderBlock = $this->getLayout()->createBlock(
126
+ 'M2ePro/adminhtml_listing_view_header','',
127
+ array('listing' => $listing)
128
+ );
129
+
130
+ $tabs = $this->getChild('tabs');
131
+
132
+ $urls = Mage::helper('M2ePro')->getControllerActions(
133
+ 'adminhtml_common_listing_autoAction',
134
+ array(
135
+ 'listing_id' => $this->getRequest()->getParam('id'),
136
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK
137
+ )
138
+ );
139
+ $urls = json_encode($urls);
140
+
141
+ /** @var $helper Ess_M2ePro_Helper_Data */
142
+ $helper = Mage::helper('M2ePro');
143
+
144
+ $translations = json_encode(array(
145
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
146
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
147
+ 'You must select at least 1 category.' => $helper->__('You must select at least 1 category.'),
148
+ 'Rule with the same title already exists.' => $helper->__('Rule with the same title already exists.')
149
+ ));
150
+
151
+ $js = <<<HTML
152
+ <script type="text/javascript">
153
+
154
+ M2ePro.url.add({$urls});
155
+ M2ePro.translator.add({$translations});
156
+
157
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
158
+
159
+ </script>
160
+ HTML;
161
+
162
+ return $viewHeaderBlock->toHtml() . $tabs->toHtml() . parent::getFormHtml() . $js;
163
+ }
164
+
165
+ // ####################################
166
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Form.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyListingEditForm');
16
+ //------------------------------
17
+ }
18
+
19
+ protected function _prepareForm()
20
+ {
21
+ $form = new Varien_Data_Form(array(
22
+ 'id' => 'edit_form',
23
+ 'action' => $this->getUrl('*/adminhtml_common_buy_listing/save'),
24
+ 'method' => 'post',
25
+ 'enctype' => 'multipart/form-data'
26
+ ));
27
+
28
+ $form->setUseContainer(true);
29
+ $this->setForm($form);
30
+
31
+ return parent::_prepareForm();
32
+ }
33
+
34
+ // ####################################
35
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Tabs.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyListingEditTabs');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('widget/tabshoriz.phtml');
19
+ $this->setDestElementId('edit_form');
20
+ }
21
+
22
+ protected function _beforeToHtml()
23
+ {
24
+ $this->addTab('selling', array(
25
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
26
+ 'title' => Mage::helper('M2ePro')->__('Selling Settings'),
27
+ 'content' => $this->getLayout()
28
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_add_tabs_selling')
29
+ ->toHtml(),
30
+ ));
31
+
32
+ $this->addTab('search', array(
33
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
34
+ 'title' => Mage::helper('M2ePro')->__('Search Settings'),
35
+ 'content' => $this->getLayout()
36
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_add_tabs_search')
37
+ ->toHtml(),
38
+ ));
39
+
40
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'selling'));
41
+
42
+ return parent::_beforeToHtml();
43
+ }
44
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Filter.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Filter extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyListingFilter');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/listing/filter.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ //-------------------------------
24
+ $maxRecordsQuantity = Mage::helper('M2ePro/View_Common')->getAutocompleteMaxItems();
25
+ //-------------------------------
26
+
27
+ //-------------------------------
28
+ $this->selectedSellingFormatTemplate = (int)$this->getRequest()
29
+ ->getParam('filter_buy_selling_format_template');
30
+ $sellingFormatTemplatesCollection = Mage::helper('M2ePro/Component_Buy')
31
+ ->getCollection('Template_SellingFormat')
32
+ ->setOrder('title', 'ASC');
33
+
34
+ if ($sellingFormatTemplatesCollection->getSize() < $maxRecordsQuantity) {
35
+ $this->sellingFormatTemplatesDropDown = true;
36
+ $sellingFormatTemplates = array();
37
+
38
+ foreach ($sellingFormatTemplatesCollection->getItems() as $item) {
39
+ $sellingFormatTemplates[$item->getId()] = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
40
+ }
41
+ $this->sellingFormatTemplates = $sellingFormatTemplates;
42
+ } else {
43
+ $this->sellingFormatTemplatesDropDown = false;
44
+ $this->sellingFormatTemplates = array();
45
+
46
+ if ($this->selectedSellingFormatTemplate > 0) {
47
+ $this->selectedSellingFormatTemplateValue = Mage::helper('M2ePro/Component_Buy')
48
+ ->getCachedObject('Template_SellingFormat',
49
+ $this->selectedSellingFormatTemplate, NULL,
50
+ array('template'))
51
+ ->getTitle();
52
+ } else {
53
+ $this->selectedSellingFormatTemplateValue = '';
54
+ }
55
+ }
56
+
57
+ $this->sellingFormatTemplateUrl = $this->makeCutUrlForTemplate('filter_buy_selling_format_template');
58
+ //-------------------------------
59
+
60
+ //-------------------------------
61
+ $this->selectedSynchronizationTemplate = (int)$this->getRequest()
62
+ ->getParam('filter_buy_synchronization_template');
63
+ $synchronizationsTemplatesCollection = Mage::helper('M2ePro/Component_Buy')
64
+ ->getCollection('Template_Synchronization')
65
+ ->setOrder('title', 'ASC');
66
+
67
+ if ($synchronizationsTemplatesCollection->getSize() < $maxRecordsQuantity) {
68
+ $this->synchronizationsTemplatesDropDown = true;
69
+ $synchronizationsTemplates = array();
70
+
71
+ foreach ($synchronizationsTemplatesCollection->getItems() as $item) {
72
+ $synchronizationsTemplates[$item->getId()] = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
73
+ }
74
+ $this->synchronizationsTemplates = $synchronizationsTemplates;
75
+ } else {
76
+ $this->synchronizationsTemplatesDropDown = false;
77
+ $this->synchronizationsTemplates = array();
78
+
79
+ if ($this->selectedSynchronizationTemplate > 0) {
80
+ $this->selectedSynchronizationTemplateValue = Mage::helper('M2ePro/Component_Buy')
81
+ ->getCachedObject('Template_Synchronization',
82
+ $this->selectedSynchronizationTemplate, NULL,
83
+ array('template'))
84
+ ->getTitle();
85
+ } else {
86
+ $this->selectedSynchronizationTemplateValue = '';
87
+ }
88
+ }
89
+
90
+ $this->synchronizationTemplateUrl = $this->makeCutUrlForTemplate('filter_buy_synchronization_template');
91
+ //-------------------------------
92
+
93
+ return parent::_beforeToHtml();
94
+ }
95
+
96
+ protected function makeCutUrlForTemplate($templateUrlParamName)
97
+ {
98
+ $paramsFilters = array(
99
+ 'filter_buy_selling_format_template',
100
+ 'filter_buy_synchronization_template'
101
+ );
102
+
103
+ $params = array();
104
+ foreach ($paramsFilters as $value) {
105
+ if ($value != $templateUrlParamName) {
106
+ $params[$value] = $this->getRequest()->getParam($value);
107
+ }
108
+ }
109
+
110
+ $params['tab'] = Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY;
111
+
112
+ return $this->getUrl('*/adminhtml_common_listing/*',$params);
113
+ }
114
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Grid.php ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Grid
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingGrid');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareCollection()
22
+ {
23
+ // Update statistic table values
24
+ Mage::getResourceModel('M2ePro/Listing')->updateStatisticColumns();
25
+ Mage::getResourceModel('M2ePro/Buy_Listing')->updateStatisticColumns();
26
+
27
+ // Get collection of listings
28
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing');
29
+
30
+ // Set global filters
31
+ //--------------------------
32
+ $filterSellingFormatTemplate = $this->getRequest()->getParam('filter_buy_selling_format_template');
33
+ $filterSynchronizationTemplate = $this->getRequest()->getParam('filter_buy_synchronization_template');
34
+
35
+ if ($filterSellingFormatTemplate != 0) {
36
+ $collection->addFieldToFilter(
37
+ 'second_table.template_selling_format_id', (int)$filterSellingFormatTemplate
38
+ );
39
+ }
40
+
41
+ if ($filterSynchronizationTemplate != 0) {
42
+ $collection->addFieldToFilter(
43
+ 'second_table.template_synchronization_id', (int)$filterSynchronizationTemplate
44
+ );
45
+ }
46
+ //--------------------------
47
+
48
+ // join accounts
49
+ //--------------------------
50
+ $collection->getSelect()
51
+ ->join(array('a'=>Mage::getResourceModel('M2ePro/Account')->getMainTable()),
52
+ '(`a`.`id` = `main_table`.`account_id`)',
53
+ array('account_title'=>'title'));
54
+ //--------------------------
55
+
56
+ //exit($collection->getSelect()->__toString());
57
+
58
+ // Set collection to grid
59
+ $this->setCollection($collection);
60
+
61
+ return parent::_prepareCollection();
62
+ }
63
+
64
+ // ####################################
65
+
66
+ protected function _prepareMassaction()
67
+ {
68
+ // Set massaction identifiers
69
+ //--------------------------------
70
+ $this->setMassactionIdField('main_table.id');
71
+ $this->getMassactionBlock()->setFormFieldName('ids');
72
+ //--------------------------------
73
+
74
+ // Set clear log action
75
+ //--------------------------------
76
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
77
+ '*/adminhtml_common_listing/index',
78
+ array(
79
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
80
+ )
81
+ );
82
+
83
+ $this->getMassactionBlock()->addItem('clear_logs', array(
84
+ 'label' => Mage::helper('M2ePro')->__('Clear Log(s)'),
85
+ 'url' => $this->getUrl('*/adminhtml_listing/clearLog', array('back' => $backUrl)),
86
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
87
+ ));
88
+ //--------------------------------
89
+
90
+ // Set remove listings action
91
+ //--------------------------------
92
+ $this->getMassactionBlock()->addItem('delete_listings', array(
93
+ 'label' => Mage::helper('M2ePro')->__('Delete Listing(s)'),
94
+ 'url' => $this->getUrl('*/adminhtml_common_buy_listing/delete'),
95
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
96
+ ));
97
+ //--------------------------------
98
+
99
+ return parent::_prepareMassaction();
100
+ }
101
+
102
+ // ####################################
103
+
104
+ protected function getColumnActionsItems()
105
+ {
106
+ $helper = Mage::helper('M2ePro');
107
+ $backUrl = $helper->makeBackUrlParam(
108
+ '*/adminhtml_common_listing/index',
109
+ array(
110
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
111
+ )
112
+ );
113
+
114
+ $actions = array(
115
+ 'manageProducts' => array(
116
+ 'caption' => $helper->__('Manage'),
117
+ 'group' => 'products_actions',
118
+ 'field' => 'id',
119
+ 'url' => array(
120
+ 'base' => '*/adminhtml_common_buy_listing/view',
121
+ 'params' => array('back' => $backUrl)
122
+ )
123
+ ),
124
+
125
+ 'addProductsFromProductsList' => array(
126
+ 'caption' => $helper->__('Add From Products List'),
127
+ 'group' => 'products_actions',
128
+ 'field' => 'id',
129
+ 'url' => array(
130
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
131
+ 'params' => array(
132
+ 'back' => $backUrl,
133
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
134
+ 'step' => 2,
135
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
136
+ )
137
+ )
138
+ ),
139
+
140
+ 'addProductsFromCategories' => array(
141
+ 'caption' => $helper->__('Add From Categories'),
142
+ 'group' => 'products_actions',
143
+ 'field' => 'id',
144
+ 'url' => array(
145
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
146
+ 'params' => array(
147
+ 'back' => $backUrl,
148
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
149
+ 'step' => 2,
150
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
151
+ )
152
+ )
153
+ ),
154
+
155
+ 'automaticActions' => array(
156
+ 'caption' => $helper->__('Auto Add/Remove Rules'),
157
+ 'group' => 'products_actions',
158
+ 'field' => 'id',
159
+ 'url' => array(
160
+ 'base' => '*/adminhtml_common_buy_listing/view',
161
+ 'params' => array(
162
+ 'back' => $backUrl,
163
+ 'auto_actions' => 1
164
+ )
165
+ )
166
+ ),
167
+
168
+ 'viewLog' => array(
169
+ 'caption' => $helper->__('View Log'),
170
+ 'group' => 'other',
171
+ 'field' => 'id',
172
+ 'url' => array(
173
+ 'base' => '*/adminhtml_common_log/listing',
174
+ 'params' => array(
175
+ 'back' => $backUrl,
176
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_BUY
177
+ )
178
+ )
179
+ ),
180
+
181
+ 'clearLogs' => array(
182
+ 'caption' => $helper->__('Clear Log'),
183
+ 'confirm' => $helper->__('Are you sure?'),
184
+ 'group' => 'other',
185
+ 'field' => 'id',
186
+ 'url' => array(
187
+ 'base' => '*/adminhtml_listing/clearLog',
188
+ 'params' => array(
189
+ 'back' => $backUrl
190
+ )
191
+ )
192
+ ),
193
+
194
+ 'deleteListing' => array(
195
+ 'caption' => $helper->__('Delete Listing'),
196
+ 'confirm' => $helper->__('Are you sure?'),
197
+ 'group' => 'other',
198
+ 'field' => 'id',
199
+ 'url' => array(
200
+ 'base' => '*/adminhtml_common_buy_listing/delete',
201
+ )
202
+ ),
203
+
204
+ 'editListingTitle' => array(
205
+ 'caption' => $helper->__('Title'),
206
+ 'group' => 'edit_actions',
207
+ 'confirm' => $helper->__('Are you sure?'),
208
+ 'field' => 'id',
209
+ 'onclick_action' => 'editListingTitle'
210
+ ),
211
+
212
+ 'sellingSetting' => array(
213
+ 'caption' => $helper->__('Selling'),
214
+ 'group' => 'edit_actions',
215
+ 'field' => 'id',
216
+ 'url' => array(
217
+ 'base' => '*/adminhtml_common_buy_listing/edit',
218
+ 'params' => array(
219
+ 'back' => $backUrl,
220
+ 'tab' => 'selling'
221
+ )
222
+ )
223
+ ),
224
+
225
+ 'searchSetting' => array(
226
+ 'caption' => $helper->__('Search'),
227
+ 'group' => 'edit_actions',
228
+ 'field' => 'id',
229
+ 'url' => array(
230
+ 'base' => '*/adminhtml_common_buy_listing/edit',
231
+ 'params' => array(
232
+ 'back' => $backUrl,
233
+ 'tab' => 'search'
234
+ )
235
+ )
236
+ )
237
+ );
238
+
239
+ return $actions;
240
+ }
241
+
242
+ // ####################################
243
+
244
+ public function callbackColumnSoldProducts($value, $row, $column, $isExport)
245
+ {
246
+ return $this->getColumnValue($value);
247
+ }
248
+
249
+ public function callbackColumnTitle($value, $row, $column, $isExport)
250
+ {
251
+ $value = '<span id="listing_title_'.$row->getId().'">' .
252
+ Mage::helper('M2ePro')->escapeHtml($value) .
253
+ '</span>';
254
+
255
+ /* @var $row Ess_M2ePro_Model_Listing */
256
+ $accountTitle = $row->getData('account_title');
257
+
258
+ $storeModel = Mage::getModel('core/store')->load($row->getStoreId());
259
+ $storeView = $storeModel->getWebsite()->getName();
260
+ if (strtolower($storeView) != 'admin') {
261
+ $storeView .= ' > '.$storeModel->getGroup()->getName();
262
+ $storeView .= ' > '.$storeModel->getName();
263
+ } else {
264
+ $storeView = Mage::helper('M2ePro')->__('Admin (Default Values)');
265
+ }
266
+
267
+ $account = Mage::helper('M2ePro')->__('Account');
268
+ $store = Mage::helper('M2ePro')->__('Magento Store View');
269
+
270
+ $value .= <<<HTML
271
+ <div>
272
+ <span style="font-weight: bold">{$account}</span>: <span style="color: #505050">{$accountTitle}</span><br/>
273
+ <span style="font-weight: bold">{$store}</span>: <span style="color: #505050">{$storeView}</span>
274
+ </div>
275
+ HTML;
276
+
277
+ return $value;
278
+ }
279
+
280
+ // ####################################
281
+
282
+ protected function callbackFilterTitle($collection, $column)
283
+ {
284
+ $value = $column->getFilter()->getValue();
285
+
286
+ if ($value == null) {
287
+ return;
288
+ }
289
+
290
+ $where = "main_table.title LIKE '%{$value}%' OR a.title LIKE '%{$value}%'";
291
+ $collection->getSelect()->where($where);
292
+ }
293
+
294
+ // ####################################
295
+
296
+ public function getGridUrl()
297
+ {
298
+ return $this->getUrl('*/adminhtml_common_buy_listing/listingGrid', array('_current'=>true));
299
+ }
300
+
301
+ public function getRowUrl($row)
302
+ {
303
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
304
+ '*/adminhtml_common_listing/index',
305
+ array(
306
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
307
+ )
308
+ );
309
+
310
+ return $this->getUrl(
311
+ '*/adminhtml_common_buy_listing/view',
312
+ array(
313
+ 'id' => $row->getId(),
314
+ 'back' => $backUrl
315
+ )
316
+ );
317
+ }
318
+
319
+ // ####################################
320
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/Grid.php ADDED
@@ -0,0 +1,530 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ /** @var $this->connRead Varien_Db_Adapter_Pdo_Mysql */
16
+ $this->connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('buyListingOtherGrid');
21
+ //------------------------------
22
+
23
+ // Set default values
24
+ //------------------------------
25
+ $this->setDefaultSort('id');
26
+ $this->setDefaultDir('DESC');
27
+ $this->setSaveParametersInSession(true);
28
+ $this->setUseAjax(true);
29
+ //------------------------------
30
+ }
31
+
32
+ public function getMassactionBlockName()
33
+ {
34
+ return 'M2ePro/adminhtml_grid_massaction';
35
+ }
36
+
37
+ // ####################################
38
+
39
+ protected function _prepareCollection()
40
+ {
41
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
42
+
43
+ $collection->getSelect()->joinLeft(
44
+ array('mp' => Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
45
+ 'mp.id = main_table.marketplace_id',
46
+ array('marketplace_title' => 'mp.title')
47
+ );
48
+
49
+ // Add Filter By Account
50
+ $accountFilter = $this->getRequest()->getParam('buyAccount');
51
+ if (!empty($accountFilter)) {
52
+ $collection->addFieldToFilter('account_id', $accountFilter);
53
+ }
54
+
55
+ //var_dump($collection->getSelect()->__toString()); exit();
56
+
57
+ $this->setCollection($collection);
58
+
59
+ return parent::_prepareCollection();
60
+ }
61
+
62
+ protected function _prepareColumns()
63
+ {
64
+ $this->addColumn('product_id', array(
65
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
66
+ 'align' => 'left',
67
+ 'width' => '80px',
68
+ 'type' => 'number',
69
+ 'index' => 'product_id',
70
+ 'filter_index' => 'product_id',
71
+ 'frame_callback' => array($this, 'callbackColumnProductId')
72
+ ));
73
+
74
+ $this->addColumn('title', array(
75
+ 'header' => Mage::helper('M2ePro')->__('Title / Reference ID'),
76
+ 'align' => 'left',
77
+ 'type' => 'text',
78
+ 'index' => 'title',
79
+ 'filter_index' => 'second_table.title',
80
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
81
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
82
+ ));
83
+
84
+ $this->addColumn('general_id', array(
85
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
86
+ 'align' => 'left',
87
+ 'width' => '100px',
88
+ 'type' => 'text',
89
+ 'index' => 'general_id',
90
+ 'filter_index' => 'general_id',
91
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
92
+ ));
93
+
94
+ $this->addColumn('online_qty', array(
95
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
96
+ 'align' => 'right',
97
+ 'width' => '100px',
98
+ 'type' => 'number',
99
+ 'index' => 'online_qty',
100
+ 'filter_index' => 'online_qty',
101
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
102
+ ));
103
+
104
+ $this->addColumn('online_price', array(
105
+ 'header' => Mage::helper('M2ePro')->__('Price'),
106
+ 'align' => 'right',
107
+ 'width' => '100px',
108
+ 'type' => 'number',
109
+ 'index' => 'online_price',
110
+ 'filter_index' => 'online_price',
111
+ 'frame_callback' => array($this, 'callbackColumnPrice')
112
+ ));
113
+
114
+ $this->addColumn('status', array(
115
+ 'header' => Mage::helper('M2ePro')->__('Status'),
116
+ 'width' => '60px',
117
+ 'index' => 'status',
118
+ 'filter_index' => 'main_table.status',
119
+ 'type' => 'options',
120
+ 'sortable' => false,
121
+ 'options' => array(
122
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
123
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive')
124
+ ),
125
+ 'frame_callback' => array($this, 'callbackColumnStatus')
126
+ ));
127
+
128
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
129
+ '*/adminhtml_common_listing_other/index',
130
+ array(
131
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
132
+ )
133
+ );
134
+
135
+ $this->addColumn('actions', array(
136
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
137
+ 'align' => 'left',
138
+ 'width' => '70px',
139
+ 'type' => 'action',
140
+ 'index' => 'actions',
141
+ 'filter' => false,
142
+ 'sortable' => false,
143
+ 'getter' => 'getId',
144
+ 'actions' => array(
145
+ array(
146
+ 'caption' => Mage::helper('M2ePro')->__('View Log'),
147
+ 'field' => 'id',
148
+ 'url' => array(
149
+ 'base' => '*/adminhtml_common_log/listingOther',
150
+ 'params' => array(
151
+ 'back' => $backUrl,
152
+ 'channel' => Ess_M2ePro_Helper_Component_Buy::NICK
153
+ )
154
+ )
155
+ ),
156
+ array(
157
+ 'caption' => Mage::helper('M2ePro')->__('Clear Log'),
158
+ 'url' => array(
159
+ 'base' => '*/adminhtml_listing_other/clearLog',
160
+ 'params' => array(
161
+ 'back' => $backUrl
162
+ )
163
+ ),
164
+ 'field' => 'id',
165
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
166
+ )
167
+ )
168
+ ));
169
+
170
+ return parent::_prepareColumns();
171
+ }
172
+
173
+ protected function _prepareMassaction()
174
+ {
175
+ // Set mass-action identifiers
176
+ //--------------------------------
177
+ $this->setMassactionIdField('`main_table`.id');
178
+ $this->getMassactionBlock()->setFormFieldName('ids');
179
+ //--------------------------------
180
+
181
+ $this->getMassactionBlock()->setGroups(array(
182
+ 'mapping' => Mage::helper('M2ePro')->__('Mapping'),
183
+ 'other' => Mage::helper('M2ePro')->__('Other')
184
+ ));
185
+
186
+ // Set mass-action
187
+ //--------------------------------
188
+ $this->getMassactionBlock()->addItem('autoMapping', array(
189
+ 'label' => Mage::helper('M2ePro')->__('Map Item(s) Automatically'),
190
+ 'url' => '',
191
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
192
+ ), 'mapping');
193
+ $this->getMassactionBlock()->addItem('moving', array(
194
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) To Listing'),
195
+ 'url' => '',
196
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
197
+ ), 'other');
198
+ $this->getMassactionBlock()->addItem('removing', array(
199
+ 'label' => Mage::helper('M2ePro')->__('Remove Item(s)'),
200
+ 'url' => '',
201
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
202
+ ), 'other');
203
+ $this->getMassactionBlock()->addItem('unmapping', array(
204
+ 'label' => Mage::helper('M2ePro')->__('Unmap Item(s)'),
205
+ 'url' => '',
206
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
207
+ ), 'mapping');
208
+ //--------------------------------
209
+
210
+ return parent::_prepareMassaction();
211
+ }
212
+
213
+ // ####################################
214
+
215
+ public function callbackColumnProductId($value, $row, $column, $isExport)
216
+ {
217
+ if (empty($value)) {
218
+ $productTitle = $row->getData('title');
219
+
220
+ if (is_null($productTitle) || $productTitle === '') {
221
+ $productTitle = Mage::helper('M2ePro')->__('N/A');
222
+ } else {
223
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
224
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
225
+ if (strlen($productTitle) > 60) {
226
+ $productTitle = substr($productTitle, 0, 60) . '...';
227
+ }
228
+ }
229
+
230
+ $htmlValue = '&nbsp;<a href="javascript:void(0);"
231
+ onclick="BuyListingOtherMappingHandlerObj.openPopUp(\''
232
+ .$productTitle
233
+ .'\','
234
+ .(int)$row->getId()
235
+ .');">'
236
+ .Mage::helper('M2ePro')->__('Map').'</a>';
237
+
238
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
239
+ $htmlValue .= '<br/>' . $row->getId();
240
+ }
241
+
242
+ return $htmlValue;
243
+ }
244
+
245
+ $htmlValue = '&nbsp<a href="'
246
+ .$this->getUrl('adminhtml/catalog_product/edit',
247
+ array('id' => $row->getData('product_id')))
248
+ .'" target="_blank">'
249
+ .$row->getData('product_id')
250
+ .'</a>';
251
+
252
+ $htmlValue .= '&nbsp&nbsp&nbsp<a href="javascript:void(0);"'
253
+ .' onclick="BuyListingOtherGridHandlerObj.movingHandler.getGridHtml('
254
+ .json_encode(array((int)$row->getData('id')))
255
+ .')">'
256
+ .Mage::helper('M2ePro')->__('Move')
257
+ .'</a>';
258
+
259
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
260
+ $htmlValue .= '<br/>' . $row->getId();
261
+ }
262
+
263
+ return $htmlValue;
264
+ }
265
+
266
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
267
+ {
268
+ if (is_null($value) || $value === '') {
269
+ $value = '<i style="color:gray;">receiving...</i>';
270
+ } else {
271
+ $value = '<span>' . Mage::helper('M2ePro')->escapeHtml($value) . '</span>';
272
+ }
273
+
274
+ $tempSku = $row->getData('sku');
275
+ is_null($tempSku) && $tempSku = Mage::helper('M2ePro')->__('N/A');
276
+
277
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('Reference ID').':</strong> '
278
+ .Mage::helper('M2ePro')->escapeHtml($tempSku);
279
+
280
+ return $value;
281
+ }
282
+
283
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
284
+ {
285
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
286
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
287
+ }
288
+
289
+ public function callbackColumnSku($value, $row, $column, $isExport)
290
+ {
291
+ return $value;
292
+ }
293
+
294
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
295
+ {
296
+ if (is_null($value) || $value === '') {
297
+ return Mage::helper('M2ePro')->__('N/A');
298
+ }
299
+
300
+ if ($value <= 0) {
301
+ return '<span style="color: red;">0</span>';
302
+ }
303
+
304
+ return $value;
305
+ }
306
+
307
+ public function callbackColumnPrice($value, $row, $column, $isExport)
308
+ {
309
+ if (is_null($value) || $value === '') {
310
+ return Mage::helper('M2ePro')->__('N/A');
311
+ }
312
+
313
+ if ((float)$value <= 0) {
314
+ return '<span style="color: #f00;">0</span>';
315
+ }
316
+
317
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
318
+ }
319
+
320
+ public function callbackColumnStatus($value, $row, $column, $isExport)
321
+ {
322
+ switch ($row->getData('status')) {
323
+
324
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
325
+ $value = '<span style="color: gray;">' . $value . '</span>';
326
+ break;
327
+
328
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
329
+ $value = '<span style="color: green;">' . $value . '</span>';
330
+ break;
331
+
332
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
333
+ $value = '<span style="color: red;">' . $value . '</span>';
334
+ break;
335
+
336
+ default:
337
+ break;
338
+ }
339
+
340
+ return $value.$this->getViewLogIconHtml($row->getId());
341
+ }
342
+
343
+ protected function callbackFilterTitle($collection, $column)
344
+ {
345
+ $value = $column->getFilter()->getValue();
346
+
347
+ if ($value == null) {
348
+ return;
349
+ }
350
+
351
+ $collection->getSelect()->where('second_table.title LIKE ? OR second_table.sku LIKE ?', '%'.$value.'%');
352
+ }
353
+
354
+ // ####################################
355
+
356
+ public function getViewLogIconHtml($listingOtherId)
357
+ {
358
+ $listingOtherId = (int)$listingOtherId;
359
+
360
+ // Get last messages
361
+ //--------------------------
362
+ $dbSelect = $this->connRead->select()
363
+ ->from(
364
+ Mage::getResourceModel('M2ePro/Listing_Other_Log')->getMainTable(),
365
+ array('action_id','action','type','description','create_date','initiator')
366
+ )
367
+ ->where('`listing_other_id` = ?', $listingOtherId)
368
+ ->where('`action_id` IS NOT NULL')
369
+ ->order(array('id DESC'))
370
+ ->limit(30);
371
+
372
+ $logRows = $this->connRead->fetchAll($dbSelect);
373
+ //--------------------------
374
+
375
+ // Get grouped messages by action_id
376
+ //--------------------------
377
+ $actionsRows = array();
378
+ $tempActionRows = array();
379
+ $lastActionId = false;
380
+
381
+ foreach ($logRows as $row) {
382
+
383
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
384
+
385
+ if ($row['action_id'] !== $lastActionId) {
386
+ if (count($tempActionRows) > 0) {
387
+ $actionsRows[] = array(
388
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
389
+ 'date' => $this->getMainDateForActionId($tempActionRows),
390
+ 'action' => $this->getActionForAction($tempActionRows[0]),
391
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
392
+ 'items' => $tempActionRows
393
+ );
394
+ $tempActionRows = array();
395
+ }
396
+ $lastActionId = $row['action_id'];
397
+ }
398
+ $tempActionRows[] = $row;
399
+ }
400
+
401
+ if (count($tempActionRows) > 0) {
402
+ $actionsRows[] = array(
403
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
404
+ 'date' => $this->getMainDateForActionId($tempActionRows),
405
+ 'action' => $this->getActionForAction($tempActionRows[0]),
406
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
407
+ 'items' => $tempActionRows
408
+ );
409
+ }
410
+
411
+ if (count($actionsRows) <= 0) {
412
+ return '';
413
+ }
414
+
415
+ $tips = array(
416
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last action was completed successfully.',
417
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last action was completed with error(s).',
418
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last action was completed with warning(s).'
419
+ );
420
+
421
+ $icons = array(
422
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
423
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
424
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
425
+ );
426
+
427
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
428
+ 'entity_id' => $listingOtherId,
429
+ 'rows' => $actionsRows,
430
+ 'tips' => $tips,
431
+ 'icons' => $icons,
432
+ 'view_help_handler' => 'BuyListingOtherGridHandlerObj.viewItemHelp',
433
+ 'hide_help_handler' => 'BuyListingOtherGridHandlerObj.hideItemHelp',
434
+ ));
435
+
436
+ return $summary->toHtml();
437
+ }
438
+
439
+ public function getActionForAction($actionRows)
440
+ {
441
+ $string = '';
442
+
443
+ switch ((int)$actionRows['action']) {
444
+ case Ess_M2ePro_Model_Listing_Other_Log::ACTION_CHANGE_STATUS_ON_CHANNEL:
445
+ $string = Mage::helper('M2ePro')->__('Status Change');
446
+ break;
447
+ }
448
+
449
+ return $string;
450
+ }
451
+
452
+ public function getInitiatorForAction($actionRows)
453
+ {
454
+ $string = '';
455
+
456
+ switch ($actionRows['initiator']) {
457
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
458
+ $string = '';
459
+ break;
460
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
461
+ $string = Mage::helper('M2ePro')->__('Manual');
462
+ break;
463
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
464
+ $string = Mage::helper('M2ePro')->__('Automatic');
465
+ break;
466
+ }
467
+
468
+ return $string;
469
+ }
470
+
471
+ public function getMainTypeForActionId($actionRows)
472
+ {
473
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
474
+
475
+ foreach ($actionRows as $row) {
476
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
477
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
478
+ break;
479
+ }
480
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
481
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
482
+ }
483
+ }
484
+
485
+ return $type;
486
+ }
487
+
488
+ public function getMainDateForActionId($actionRows)
489
+ {
490
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
491
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
492
+ }
493
+
494
+ // ####################################
495
+
496
+ protected function _toHtml()
497
+ {
498
+ $javascriptsMain = <<<JAVASCRIPT
499
+ <script type="text/javascript">
500
+
501
+ if (typeof BuyListingOtherGridHandlerObj != 'undefined') {
502
+ BuyListingOtherGridHandlerObj.afterInitPage();
503
+ }
504
+
505
+ Event.observe(window, 'load', function() {
506
+ setTimeout(function() {
507
+ BuyListingOtherGridHandlerObj.afterInitPage();
508
+ }, 350);
509
+ });
510
+
511
+ </script>
512
+ JAVASCRIPT;
513
+
514
+ return parent::_toHtml().$javascriptsMain;
515
+ }
516
+
517
+ // ####################################
518
+
519
+ public function getGridUrl()
520
+ {
521
+ return $this->getUrl('*/adminhtml_common_buy_listing_other/grid', array('_current' => true));
522
+ }
523
+
524
+ public function getRowUrl($row)
525
+ {
526
+ return false;
527
+ }
528
+
529
+ // ####################################
530
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Product extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyListingProduct');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_buy_listing_product';
18
+ //------------------------------
19
+
20
+ // Set header text
21
+ //------------------------------
22
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
23
+
24
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
25
+ $headerText = Mage::helper('M2ePro')->__(
26
+ 'Add Products To %component_name% Listing "%listing_title%"',
27
+ Mage::helper('M2ePro/Component_Buy')->getTitle(),
28
+ $this->escapeHtml($listingData['title'])
29
+ );
30
+ } else {
31
+ $headerText = Mage::helper('M2ePro')->__('Add Products To Listing "%listing_title%"',
32
+ $this->escapeHtml($listingData['title'])
33
+ );
34
+ }
35
+
36
+ $this->_headerText = $headerText;
37
+ //------------------------------
38
+
39
+ // Set buttons actions
40
+ //------------------------------
41
+ $this->removeButton('back');
42
+ $this->removeButton('reset');
43
+ $this->removeButton('delete');
44
+ $this->removeButton('add');
45
+ $this->removeButton('save');
46
+ $this->removeButton('edit');
47
+ //------------------------------
48
+
49
+ //------------------------------
50
+ if (is_null($this->getRequest()->getParam('back'))) {
51
+ $url = $this->getUrl(
52
+ '*/adminhtml_common_buy_listing/categoryProduct',
53
+ array(
54
+ 'id' => $listingData['id'],
55
+ 'save_categories' => $this->getRequest()->getParam('save_categories', 1),
56
+ 'selected_categories' => $this->getRequest()->getParam('selected_categories')
57
+ )
58
+ );
59
+ } else {
60
+ $url = Mage::helper('M2ePro')->getBackUrl(
61
+ '*/adminhtml_common_listing/index',
62
+ array(
63
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
64
+ )
65
+ );
66
+ }
67
+ $this->_addButton('back', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Back'),
69
+ 'onclick' => 'ProductGridHandlerObj.back_click(\''.$url.'\')',
70
+ 'class' => 'back'
71
+ ));
72
+ //------------------------------
73
+
74
+ //------------------------------
75
+ $this->_addButton('save', array(
76
+ 'label' => Mage::helper('M2ePro')->__('Save'),
77
+ 'onclick' => 'ProductGridHandlerObj.save_click(\'view\')',
78
+ 'class' => 'save'
79
+ ));
80
+ //------------------------------
81
+ }
82
+
83
+ public function getGridHtml()
84
+ {
85
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_product_help');
86
+ return $helpBlock->toHtml() . parent::getGridHtml();
87
+ }
88
+
89
+ protected function _toHtml()
90
+ {
91
+ return '<div id="add_products_progress_bar"></div>'.
92
+ '<div id="add_products_container">'.
93
+ parent::_toHtml().
94
+ '</div>';
95
+ }
96
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Product_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyListingProductHelp');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/listing/product/help.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Grid.php ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_ProductSearch_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ private $productId;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ $this->productId = Mage::helper('M2ePro/Data_Global')->getValue('product_id');
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('buyProductSearchGrid');
20
+ //------------------------------
21
+
22
+ // Set default values
23
+ //------------------------------
24
+ $this->setFilterVisibility(false);
25
+ $this->setPagerVisibility(false);
26
+ $this->setDefaultSort('id');
27
+ $this->setDefaultDir('ASC');
28
+ $this->setSaveParametersInSession(true);
29
+ $this->setUseAjax(true);
30
+ //------------------------------
31
+ }
32
+
33
+ protected function _prepareCollection()
34
+ {
35
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
36
+
37
+ $results = new Varien_Data_Collection();
38
+ foreach ($data as $index => $item) {
39
+ $temp = array(
40
+ 'id' => $index,
41
+ 'general_id' => isset($item['general_id']) ? $item['general_id'] : null,
42
+ 'title' => $item['title'],
43
+ 'image_url' => $item['image_url'],
44
+ 'price' => isset($item['price']) ? $item['price'] : null,
45
+ 'variations' => isset($item['variations']) ? $item['variations'] : null
46
+ );
47
+
48
+ $results->addItem(new Varien_Object($temp));
49
+ }
50
+
51
+ $this->setCollection($results);
52
+
53
+ return parent::_prepareCollection();
54
+ }
55
+
56
+ protected function _prepareColumns()
57
+ {
58
+ $this->addColumn('image', array(
59
+ 'header' => Mage::helper('M2ePro')->__('Image'),
60
+ 'align' => 'center',
61
+ 'type' => 'text',
62
+ 'width' => '80px',
63
+ 'index' => 'image_url',
64
+ 'filter' => false,
65
+ 'sortable' => false,
66
+ 'frame_callback' => array($this, 'callbackColumnImage')
67
+ ));
68
+
69
+ $this->addColumn('general_id', array(
70
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
71
+ 'align' => 'center',
72
+ 'type' => 'text',
73
+ 'width' => '75px',
74
+ 'index' => 'general_id',
75
+ 'filter' => false,
76
+ 'sortable' => false,
77
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
78
+ ));
79
+
80
+ $this->addColumn('title', array(
81
+ 'header' => Mage::helper('M2ePro')->__('Product Title'),
82
+ 'align' => 'left',
83
+ 'type' => 'text',
84
+ 'width' => '375px',
85
+ 'string_limit' => 10000,
86
+ 'index' => 'title',
87
+ 'filter' => false,
88
+ 'sortable' => false,
89
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
90
+ ));
91
+
92
+ $this->addColumn('price',array(
93
+ 'header' => Mage::helper('catalog')->__('Price'),
94
+ 'width' => '60px',
95
+ 'align' => 'right',
96
+ 'index' => 'price',
97
+ 'filter' => false,
98
+ 'sortable' => false,
99
+ 'type' => 'text',
100
+ 'frame_callback' => array($this, 'callbackColumnPrice')
101
+ ));
102
+
103
+ $this->addColumn('actions', array(
104
+ 'header' => Mage::helper('M2ePro')->__('Action'),
105
+ 'align' => 'left',
106
+ 'type' => 'text',
107
+ 'width' => '78px',
108
+ 'filter' => false,
109
+ 'sortable' => false,
110
+ 'frame_callback' => array($this, 'callbackColumnActions'),
111
+ ));
112
+
113
+ }
114
+
115
+ // ####################################
116
+
117
+ public function callbackColumnImage($value, $product, $column, $isExport)
118
+ {
119
+ return '<img width="75px" src="'.$value.'" />';
120
+ }
121
+
122
+ public function callbackColumnGeneralId($value, $product, $column, $isExport)
123
+ {
124
+ if (empty($value)) {
125
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl('%general_id%');
126
+ $templateHtml = '<a href="'.$url.'" target="_blank">%general_id%</a>';
127
+ return '<span id="buy_link_'.$product->getId().'">' . Mage::helper('M2ePro')->__('N/A') . '</span>' .
128
+ '<div id="template_buy_link_'.$product->getId().'" style="display: none;">'.$templateHtml.'</div>';
129
+ }
130
+
131
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
132
+
133
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
134
+ }
135
+
136
+ public function callbackColumnTitle($value, $row, $column, $isExport)
137
+ {
138
+ $value = '<div style="margin-left: 3px; margin-bottom: 10px;">'.
139
+ Mage::helper('M2ePro')->escapeHtml($value)."</div>";
140
+
141
+ $variations = $row->getData('variations');
142
+ if (is_null($variations)) {
143
+ return $value;
144
+ }
145
+
146
+ $specificsHtml = '';
147
+ $id = $row->getId();
148
+ foreach ($variations['set'] as $specificName => $specific) {
149
+ $specificsHtml .= '<span style="margin-left: 10px;
150
+ font-size: 11px;
151
+ color: #808080;
152
+ display: inline-block;
153
+ width: 100px;">'.
154
+ ucfirst(strtolower($specificName)).
155
+ ':</span>';
156
+ $specificsHtml .= '<select class="specifics_'.$id.'"
157
+ onchange="ListingGridHandlerObj.productSearchHandler.specificsChange(this)"
158
+ style="width: 150px; margin-left: 5px; margin-bottom: 5px; font-size: 10px;"
159
+ id="specific_'.$specificName.'_'.$id.'">';
160
+ $specificsHtml .= '<option value=""></option>';
161
+ foreach ($specific as $option) {
162
+ $specificsHtml .= '<option value="'.$option.'">'.$option.'</option>';
163
+ }
164
+ $specificsHtml .= '</select><br/>';
165
+ }
166
+
167
+ $specificsJsonContainer = '<div id="skus_'.$id.'" style="display: none;">'.
168
+ json_encode($variations['skus']).'</div>';
169
+
170
+ return $value . $specificsHtml . $specificsJsonContainer;
171
+ }
172
+
173
+ public function callbackColumnPrice($value, $row, $column, $isExport)
174
+ {
175
+ if (empty($value)) {
176
+ $value = Mage::helper('M2ePro')->__('N/A');
177
+ }
178
+
179
+ return '<div id="price_'.$row->getId().'" style="margin-right: 5px;">'.$value.'</div>';
180
+ }
181
+
182
+ public function callbackColumnActions($value, $row, $column, $isExport)
183
+ {
184
+ $assignText = Mage::helper('M2ePro')->__('Assign Rakuten.com SKU');
185
+ //->__('There is no such variation on Rakuten.com. Please, choose another variation.');
186
+ $naMessage = 'There is no such variation on Rakuten.com. Please, choose another variation.';
187
+ $naMessage = Mage::helper('M2ePro')->__($naMessage);
188
+
189
+ if (!is_null($row->getData('variations'))) {
190
+ $templateMapHtml =
191
+ '<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId('
192
+ .$this->productId
193
+ .', \'%general_id%\');">'.$assignText.'</a>';
194
+
195
+ $templateNaHtml = '<a href="javascript:void(0);" onclick="alert(\''.$naMessage.'\')">'.$assignText.'</a>';
196
+
197
+ return '<span id="map_link_'.$row->getId().'"><span style="color: #808080">'.$assignText.'</span></span>
198
+ <div id="template_map_link_'.$row->getId().'" style="display: none;">'.$templateMapHtml.'</div>
199
+ <div id="template_na_link_'.$row->getId().'" style="display: none;">'.$templateNaHtml.'</div>';
200
+ }
201
+
202
+ return '<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId('
203
+ .$this->productId
204
+ .', \''
205
+ .$row->getData('general_id')
206
+ .'\');">'.$assignText.'</a>';
207
+ }
208
+
209
+ // ####################################
210
+
211
+ protected function _toHtml()
212
+ {
213
+ $javascriptsMain = <<<JAVASCRIPT
214
+ <script type="text/javascript">
215
+
216
+ $$('#buyProductSearchGrid div.grid th').each(function(el){
217
+ el.style.padding = '2px 2px';
218
+ });
219
+
220
+ $$('#buyProductSearchGrid div.grid td').each(function(el){
221
+ el.style.padding = '2px 2px';
222
+ });
223
+
224
+ </script>
225
+ JAVASCRIPT;
226
+
227
+ //------------------------------
228
+ $data = array(
229
+ 'id' => 'productSearch_cleanSuggest_button',
230
+ 'label' => Mage::helper('M2ePro')->__('Clear Search Results'),
231
+ 'class' => 'productSearch_cleanSuggest_button'
232
+ );
233
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
234
+ //------------------------------
235
+
236
+ $buttonBlockHtml = Mage::helper('M2ePro/Data_Global')->getValue('is_suggestion') ? $buttonBlock->toHtml() : '';
237
+
238
+ return $buttonBlockHtml . parent::_toHtml() . $javascriptsMain;
239
+ }
240
+
241
+ // ####################################
242
+
243
+ public function getGridUrl()
244
+ {
245
+ return $this->getUrl('*/adminhtml_common_buy_listing/getSuggestedBuyComSkuGrid', array('_current'=>true));
246
+ }
247
+
248
+ public function getRowUrl($row)
249
+ {
250
+ return false;
251
+ }
252
+
253
+ // ####################################
254
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Main.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_ProductSearch_Main extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ $this->setTemplate('M2ePro/common/buy/listing/product_search/main.phtml');
14
+ }
15
+
16
+ protected function _beforeToHtml()
17
+ {
18
+ //------------------------------
19
+ $data = array(
20
+ 'id' => 'productSearch_submit_button',
21
+ 'label' => Mage::helper('M2ePro')->__('Search'),
22
+ 'class' => 'productSearch_submit_button submit'
23
+ );
24
+ $buttonSubmitBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
25
+ $this->setChild('productSearch_submit_button', $buttonSubmitBlock);
26
+ //------------------------------
27
+
28
+ //------------------------------
29
+ $data = array(
30
+ 'id' => 'productSearch_back_button',
31
+ 'label' => Mage::helper('M2ePro')->__('Back'),
32
+ 'class' => 'productSearch_back_button'
33
+ );
34
+ $buttonBackBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
35
+ $this->setChild('productSearch_back_button', $buttonBackBlock);
36
+ //------------------------------
37
+
38
+ //------------------------------
39
+ $data = array(
40
+ 'id' => 'productSearch_cancel_button',
41
+ 'label' => Mage::helper('M2ePro')->__('Close'),
42
+ 'class' => 'productSearch_cancel_button'
43
+ );
44
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
45
+ $this->setChild('productSearch_cancel_button', $buttonCancelBlock);
46
+ //------------------------------
47
+
48
+ parent::_beforeToHtml();
49
+ }
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Menu.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_ProductSearch_Menu extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ $this->setTemplate('M2ePro/common/buy/listing/product_search/menu.phtml');
14
+ }
15
+
16
+ protected function _beforeToHtml()
17
+ {
18
+ //------------------------------
19
+ $data = array(
20
+ 'id' => 'productSearchMenu_cancel_button',
21
+ 'label' => Mage::helper('M2ePro')->__('Close'),
22
+ 'class' => 'productSearchMenu_cancel_button'
23
+ );
24
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
25
+ $this->setChild('productSearchMenu_cancel_button', $buttonCancelBlock);
26
+ //------------------------------
27
+
28
+ parent::_beforeToHtml();
29
+ }
30
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Search extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingBuySearch');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_listing_search';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
25
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
26
+ $headerText = Mage::helper('M2ePro')->__("Search %component_name% Listings Items", $componentName);
27
+ } else {
28
+ $headerText = Mage::helper('M2ePro')->__("Search Listings Items");
29
+ }
30
+
31
+ $this->_headerText = $headerText;
32
+ //------------------------------
33
+
34
+ // Set buttons actions
35
+ //------------------------------
36
+ $this->removeButton('back');
37
+ $this->removeButton('reset');
38
+ $this->removeButton('delete');
39
+ $this->removeButton('add');
40
+ $this->removeButton('save');
41
+ $this->removeButton('edit');
42
+ //------------------------------
43
+
44
+ //------------------------------
45
+ if (!is_null($this->getRequest()->getParam('back'))) {
46
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_buy_listing/search');
47
+ $this->_addButton('back', array(
48
+ 'label' => Mage::helper('M2ePro')->__('Back'),
49
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
50
+ 'class' => 'back'
51
+ ));
52
+ }
53
+ //------------------------------
54
+
55
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/search');
56
+
57
+ //------------------------------
58
+ $url = $this->getUrl(
59
+ '*/adminhtml_common_listing/index',
60
+ array(
61
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY,
62
+ 'back'=> $backUrl
63
+ )
64
+ );
65
+ $this->_addButton('goto_listings', array(
66
+ 'label' => Mage::helper('M2ePro')->__('Listings'),
67
+ 'onclick' => 'setLocation(\'' . $url . '\')',
68
+ 'class' => 'button_link'
69
+ ));
70
+ //------------------------------
71
+
72
+ //------------------------------
73
+ $this->_addButton('goto_templates', array(
74
+ 'label' => Mage::helper('M2ePro')->__('Policies'),
75
+ 'onclick' => '',
76
+ 'class' => 'button_link drop_down templates-drop-down'
77
+ ));
78
+ //------------------------------
79
+
80
+ //------------------------------
81
+ $url = $this->getUrl(
82
+ '*/adminhtml_common_log/listing',
83
+ array(
84
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_BUY
85
+ )
86
+ );
87
+ $this->_addButton('view_log', array(
88
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
89
+ 'onclick' => 'window.open(\'' . $url . '\')',
90
+ 'class' => 'button_link'
91
+ ));
92
+ //------------------------------
93
+ }
94
+
95
+ // ########################################
96
+
97
+ protected function _toHtml()
98
+ {
99
+ return $this->getTemplatesButtonJavascript() . parent::_toHtml();
100
+ }
101
+
102
+ public function getGridHtml()
103
+ {
104
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_listing_search_help');
105
+ return $helpBlock->toHtml() . parent::getGridHtml();
106
+ }
107
+
108
+ // ########################################
109
+
110
+ protected function getTemplatesButtonJavascript()
111
+ {
112
+ $data = array(
113
+ 'target_css_class' => 'templates-drop-down',
114
+ 'items' => $this->getTemplatesButtonDropDownItems()
115
+ );
116
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
117
+ $dropDownBlock->setData($data);
118
+
119
+ return $dropDownBlock->toHtml();
120
+ }
121
+
122
+ protected function getTemplatesButtonDropDownItems()
123
+ {
124
+ $items = array();
125
+
126
+ $filter = base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Buy::NICK);
127
+
128
+ //------------------------------
129
+ $url = $this->getUrl(
130
+ '*/adminhtml_common_template_sellingFormat/index',
131
+ array(
132
+ 'filter' => $filter
133
+ )
134
+ );
135
+ $items[] = array(
136
+ 'url' => $url,
137
+ 'label' => Mage::helper('M2ePro')->__('Selling Format Policies'),
138
+ 'target' => '_blank'
139
+ );
140
+ //------------------------------
141
+
142
+ //------------------------------
143
+ $url = $this->getUrl(
144
+ '*/adminhtml_common_template_synchronization/index',
145
+ array(
146
+ 'filter' => $filter
147
+ )
148
+ );
149
+ $items[] = array(
150
+ 'url' => $url,
151
+ 'label' => Mage::helper('M2ePro')->__('Synchronization Policies'),
152
+ 'target' => '_blank'
153
+ );
154
+ //------------------------------
155
+
156
+ return $items;
157
+ }
158
+
159
+ // ########################################
160
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search/Grid.php ADDED
@@ -0,0 +1,458 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Search_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingSearchGrid');
18
+ //------------------------------
19
+
20
+ // Set default values
21
+ //------------------------------
22
+ $this->setDefaultSort('id');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setUseAjax(true);
26
+ //------------------------------
27
+ }
28
+
29
+ // ####################################
30
+
31
+ protected function _prepareCollection()
32
+ {
33
+ // Get collection products in listing
34
+ //--------------------------------
35
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Product');
36
+ $collection->getSelect()->distinct();
37
+ $collection->getSelect()
38
+ ->join(array('l'=>Mage::getResourceModel('M2ePro/Listing')->getMainTable()),
39
+ '(`l`.`id` = `main_table`.`listing_id`)',
40
+ array('listing_title'=>'title','store_id'))
41
+ ->join(array('bl'=>Mage::getResourceModel('M2ePro/Buy_Listing')->getMainTable()),
42
+ '(`bl`.`listing_id` = `l`.`id`)',
43
+ array('template_selling_format_id'));
44
+ //--------------------------------
45
+
46
+ // Communicate with magento product table
47
+ //--------------------------------
48
+ $dbSelect = Mage::getResourceModel('core/config')->getReadConnection()
49
+ ->select()
50
+ ->from(Mage::getSingleton('core/resource')
51
+ ->getTableName('catalog_product_entity_varchar'),
52
+ new Zend_Db_Expr('MAX(`store_id`)'))
53
+ ->where("`entity_id` = `main_table`.`product_id`")
54
+ ->where("`attribute_id` = `ea`.`attribute_id`")
55
+ ->where("`store_id` = 0 OR `store_id` = `l`.`store_id`");
56
+
57
+ $collection->getSelect()
58
+ //->join(array('csi'=>Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
59
+ // '(csi.product_id = `main_table`.product_id)',array('qty'))
60
+ ->join(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
61
+ '(cpe.entity_id = `main_table`.product_id)',
62
+ array('magento_sku'=>'sku'))
63
+ ->join(array('cisi'=>Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
64
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
65
+ array('is_in_stock'))
66
+ ->join(array('cpev'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')),
67
+ "(`cpev`.`entity_id` = `main_table`.product_id)",
68
+ array('value'))
69
+ ->join(array('ea'=>Mage::getSingleton('core/resource')->getTableName('eav_attribute')),
70
+ '(`cpev`.`attribute_id` = `ea`.`attribute_id` AND `ea`.`attribute_code` = \'name\')',
71
+ array())
72
+ ->where('`cpev`.`store_id` = ('.$dbSelect->__toString().')');
73
+ //--------------------------------
74
+
75
+ //exit($collection->getSelect()->__toString());
76
+
77
+ // Set collection to grid
78
+ $this->setCollection($collection);
79
+
80
+ return parent::_prepareCollection();
81
+ }
82
+
83
+ protected function _prepareColumns()
84
+ {
85
+ $this->addColumn('product_id', array(
86
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
87
+ 'align' => 'right',
88
+ 'width' => '100px',
89
+ 'type' => 'number',
90
+ 'index' => 'product_id',
91
+ 'filter_index' => 'main_table.product_id',
92
+ 'frame_callback' => array($this, 'callbackColumnProductId')
93
+ ));
94
+
95
+ $this->addColumn('name', array(
96
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Listing / Product SKU'),
97
+ 'align' => 'left',
98
+ //'width' => '300px',
99
+ 'type' => 'text',
100
+ 'index' => 'value',
101
+ 'filter_index' => 'cpev.value',
102
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
103
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
104
+ ));
105
+
106
+ $this->addColumn('stock_availability',
107
+ array(
108
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
109
+ 'width' => '100px',
110
+ 'index' => 'is_in_stock',
111
+ 'filter_index' => 'cisi.is_in_stock',
112
+ 'type' => 'options',
113
+ 'sortable' => false,
114
+ 'options' => array(
115
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
116
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
117
+ ),
118
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
119
+ ));
120
+
121
+ $this->addColumn('sku', array(
122
+ 'header' => Mage::helper('M2ePro')->__('Reference ID'),
123
+ 'align' => 'left',
124
+ 'width' => '150px',
125
+ 'type' => 'text',
126
+ 'index' => 'sku',
127
+ 'filter_index' => 'second_table.sku',
128
+ 'frame_callback' => array($this, 'callbackColumnSku')
129
+ ));
130
+
131
+ $this->addColumn('general_id', array(
132
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
133
+ 'align' => 'left',
134
+ 'width' => '90px',
135
+ 'type' => 'text',
136
+ 'index' => 'general_id',
137
+ 'filter_index' => 'second_table.general_id',
138
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
139
+ ));
140
+
141
+ $this->addColumn('online_qty', array(
142
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
143
+ 'align' => 'right',
144
+ 'width' => '70px',
145
+ 'type' => 'number',
146
+ 'index' => 'online_qty',
147
+ 'filter_index' => 'second_table.online_qty',
148
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
149
+ ));
150
+
151
+ $this->addColumn('online_price', array(
152
+ 'header' => Mage::helper('M2ePro')->__('Price'),
153
+ 'align' => 'right',
154
+ 'width' => '70px',
155
+ 'type' => 'number',
156
+ 'index' => 'online_price',
157
+ 'filter_index' => 'second_table.online_price',
158
+ 'frame_callback' => array($this, 'callbackColumnPrice')
159
+ ));
160
+
161
+ $this->addColumn('status', array(
162
+ 'header' => Mage::helper('M2ePro')->__('Status'),
163
+ 'width' => '125px',
164
+ 'index' => 'status',
165
+ 'filter_index' => 'main_table.status',
166
+ 'type' => 'options',
167
+ 'sortable' => false,
168
+ 'options' => array(
169
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
170
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
171
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive')
172
+ ),
173
+ 'frame_callback' => array($this, 'callbackColumnStatus')
174
+ ));
175
+
176
+ $this->addColumn('goto_listing_item', array(
177
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
178
+ 'align' => 'center',
179
+ 'width' => '50px',
180
+ 'type' => 'text',
181
+ 'filter' => false,
182
+ 'sortable' => false,
183
+ 'frame_callback' => array($this, 'callbackColumnActions')
184
+ ));
185
+
186
+ return parent::_prepareColumns();
187
+ }
188
+
189
+ // ####################################
190
+
191
+ public function callbackColumnProductId($value, $row, $column, $isExport)
192
+ {
193
+ $productId = (int)$row->getData('product_id');
194
+ $storeId = (int)$row->getData('store_id');
195
+
196
+ $withoutImageHtml = '<a href="'
197
+ .$this->getUrl('adminhtml/catalog_product/edit',
198
+ array('id' => $productId))
199
+ .'" target="_blank">'
200
+ .$productId
201
+ .'</a>';
202
+
203
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
204
+ ->getGroupValue('/view/','show_products_thumbnails');
205
+ if (!$showProductsThumbnails) {
206
+ return $withoutImageHtml;
207
+ }
208
+
209
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
210
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
211
+ $magentoProduct->setProductId($productId);
212
+ $magentoProduct->setStoreId($storeId);
213
+
214
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
215
+ if (is_null($imageUrlResized)) {
216
+ return $withoutImageHtml;
217
+ }
218
+
219
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
220
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
221
+
222
+ return $withImageHtml;
223
+ }
224
+
225
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
226
+ {
227
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
228
+
229
+ $urlParams = array();
230
+ $urlParams['id'] = $row->getData('listing_id');
231
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/search');
232
+
233
+ $listingUrl = $this->getUrl('*/adminhtml_common_buy_listing/view',$urlParams);
234
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
235
+
236
+ if (strlen($listingTitle) > 50) {
237
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
238
+ }
239
+
240
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
241
+ $value .= '<strong>'
242
+ .Mage::helper('M2ePro')->__('Listing')
243
+ .': </strong> <a href="'
244
+ .$listingUrl
245
+ .'">'
246
+ .$listingTitle
247
+ .'</a>';
248
+
249
+ $tempSku = $row->getData('magento_sku');
250
+ is_null($tempSku)
251
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('product_id'))->getSku();
252
+
253
+ $value .= '<br/><strong>'
254
+ .Mage::helper('M2ePro')->__('SKU')
255
+ .':</strong> '
256
+ .Mage::helper('M2ePro')->escapeHtml($tempSku);
257
+
258
+ if ($row->getChildObject()->getVariationManager()->isVariationProduct() &&
259
+ $row->getChildObject()->getVariationManager()->isVariationProductMatched()
260
+ ) {
261
+ $productOptions = $row->getChildObject()->getVariationManager()->getProductOptions();
262
+
263
+ $value .= '<br/>';
264
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
265
+ foreach ($productOptions as $attribute => $option) {
266
+ !$option && $option = '--';
267
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
268
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
269
+ }
270
+ $value .= '</div>';
271
+ $value .= '<br/>';
272
+ }
273
+
274
+ return $value;
275
+ }
276
+
277
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
278
+ {
279
+ if ((int)$row->getData('is_in_stock') <= 0) {
280
+ return '<span style="color: red;">'.$value.'</span>';
281
+ }
282
+
283
+ return $value;
284
+ }
285
+
286
+ public function callbackColumnSku($value, $row, $column, $isExport)
287
+ {
288
+ if (is_null($value) || $value === '') {
289
+ return Mage::helper('M2ePro')->__('N/A');
290
+ }
291
+ return $value;
292
+ }
293
+
294
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
295
+ {
296
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
297
+ if (is_null($value) || $value === '') {
298
+ return Mage::helper('M2ePro')->__('N/A');
299
+ }
300
+ } else {
301
+ if (is_null($value) || $value === '') {
302
+ return '<i style="color:gray;">receiving...</i>';
303
+ }
304
+ }
305
+
306
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
307
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
308
+ }
309
+
310
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
311
+ {
312
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
313
+ if (is_null($value) || $value === '') {
314
+ return Mage::helper('M2ePro')->__('N/A');
315
+ }
316
+ } else {
317
+ if (is_null($value) || $value === '') {
318
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
319
+ }
320
+ }
321
+
322
+ if ($value <= 0) {
323
+ return '<span style="color: red;">0</span>';
324
+ }
325
+
326
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
327
+ }
328
+
329
+ public function callbackColumnPrice($value, $row, $column, $isExport)
330
+ {
331
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
332
+ if (is_null($value) || $value === '') {
333
+ return Mage::helper('M2ePro')->__('N/A');
334
+ }
335
+ } else {
336
+ if (is_null($value) || $value === '') {
337
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
338
+ }
339
+ }
340
+
341
+ if ((float)$value <= 0) {
342
+ return '<span style="color: #f00;">0</span>';
343
+ }
344
+
345
+ return $value;
346
+ }
347
+
348
+ public function callbackColumnStatus($value, $row, $column, $isExport)
349
+ {
350
+ switch ($row->getData('status')) {
351
+
352
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
353
+ $value = '<span style="color: gray;">' . $value . '</span>';
354
+ break;
355
+
356
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
357
+ $value = '<span style="color: green;">' . $value . '</span>';
358
+ break;
359
+
360
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
361
+ $value = '<span style="color: red;">'.$value.'</span>';
362
+ break;
363
+
364
+ default:
365
+ break;
366
+ }
367
+
368
+ $tempLocks = $row->getObjectLocks();
369
+
370
+ foreach ($tempLocks as $lock) {
371
+
372
+ switch ($lock->getTag()) {
373
+
374
+ case 'new_sku_action':
375
+ $title = Mage::helper('M2ePro')->__('Add New SKU in Progress...');
376
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
377
+ break;
378
+
379
+ case 'list_action':
380
+ $title = Mage::helper('M2ePro')->__('List in Progress...');
381
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
382
+ break;
383
+
384
+ case 'relist_action':
385
+ $title = Mage::helper('M2ePro')->__('Relist in Progress...');
386
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
387
+ break;
388
+
389
+ case 'revise_action':
390
+ $title = Mage::helper('M2ePro')->__('Revise in Progress...');
391
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
392
+ break;
393
+
394
+ case 'stop_action':
395
+ $title = Mage::helper('M2ePro')->__('Stop in Progress...');
396
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
397
+ break;
398
+
399
+ case 'stop_and_remove_action':
400
+ $title = Mage::helper('M2ePro')->__('Stop And Remove in Progress...');
401
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
402
+ break;
403
+
404
+ default:
405
+ break;
406
+
407
+ }
408
+ }
409
+
410
+ return $value;
411
+ }
412
+
413
+ public function callbackColumnActions($value, $row, $column, $isExport)
414
+ {
415
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to listing'));
416
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
417
+ $url = $this->getUrl('*/adminhtml_common_buy_listing/view/', array(
418
+ 'id'=>$row->getData('listing_id'),
419
+ 'filter'=>base64_encode(
420
+ 'product_id[from]='.(int)$row->getData('product_id')
421
+ .'&product_id[to]='.(int)$row->getData('product_id')
422
+ )
423
+ ));
424
+
425
+ $html = <<<HTML
426
+ <div style="float:right; margin:5px 15px 0 0;">
427
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" /></a>
428
+ </div>
429
+ HTML;
430
+
431
+ return $html;
432
+ }
433
+
434
+ protected function callbackFilterTitle($collection, $column)
435
+ {
436
+ $value = $column->getFilter()->getValue();
437
+
438
+ if ($value == null) {
439
+ return;
440
+ }
441
+
442
+ $collection->getSelect()->where('cpev.value LIKE ? OR cpe.sku LIKE ? OR l.title LIKE ?', '%'.$value.'%');
443
+ }
444
+
445
+ // ####################################
446
+
447
+ public function getGridUrl()
448
+ {
449
+ return $this->getUrl('*/adminhtml_common_buy_listing/searchGrid', array('_current'=>true));
450
+ }
451
+
452
+ public function getRowUrl($row)
453
+ {
454
+ return false;
455
+ }
456
+
457
+ // ####################################
458
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View.php ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_View extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyListingView');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_buy_listing_view';
18
+ //------------------------------
19
+
20
+ // Set header text
21
+ //------------------------------
22
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
23
+
24
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
25
+ $headerText = Mage::helper('M2ePro')->__(
26
+ 'View %component_name% Listing',
27
+ Mage::helper('M2ePro/Component_Buy')->getTitle()
28
+ );
29
+ } else {
30
+ $headerText = Mage::helper('M2ePro')->__('View Listing ');
31
+ }
32
+
33
+ $this->_headerText = $headerText;
34
+ //------------------------------
35
+
36
+ // Set buttons actions
37
+ //------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ //------------------------------
45
+
46
+ //------------------------------
47
+ $url = $this->getUrl('*/adminhtml_common_log/listing', array(
48
+ 'id' => $listingData['id'],
49
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_BUY
50
+ ));
51
+ $this->_addButton('view_log', array(
52
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
53
+ 'onclick' => 'window.open(\'' . $url . '\')',
54
+ 'class' => 'button_link'
55
+ ));
56
+ //------------------------------
57
+
58
+ //------------------------------
59
+ $this->_addButton('edit_settings', array(
60
+ 'label' => Mage::helper('M2ePro')->__('Edit Settings'),
61
+ 'onclick' => '',
62
+ 'class' => 'drop_down edit_settings_drop_down'
63
+ ));
64
+ //------------------------------
65
+
66
+ //------------------------------
67
+ $this->_addButton('add_products', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Add Products'),
69
+ 'onclick' => '',
70
+ 'class' => 'add drop_down add_products_drop_down'
71
+ ));
72
+ //------------------------------
73
+ }
74
+
75
+ protected function _toHtml()
76
+ {
77
+ return '<div id="listing_view_progress_bar"></div>' .
78
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
79
+ '<div id="listing_view_content_container">'.
80
+ parent::_toHtml() .
81
+ '</div>';
82
+ }
83
+
84
+ public function getGridHtml()
85
+ {
86
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
87
+
88
+ /** @var $helper Ess_M2ePro_Helper_Data */
89
+ $helper = Mage::helper('M2ePro');
90
+
91
+ //------------------------------
92
+ $urls = $helper->getControllerActions(
93
+ 'adminhtml_common_listing_autoAction', array(
94
+ 'listing_id' => $this->getRequest()->getParam('id'),
95
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK
96
+ )
97
+ );
98
+ $showAutoAction = json_encode((bool)$this->getRequest()->getParam('auto_actions'));
99
+
100
+ $path = 'adminhtml_common_log/listingProduct';
101
+ $urls[$path] = $this->getUrl('*/' . $path, array(
102
+ 'channel' => Ess_M2ePro_Helper_Component_Buy::NICK,
103
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array('id' =>$listingData['id']))
104
+ ));
105
+
106
+ $path = 'adminhtml_common_listing/duplicateProducts';
107
+ $urls[$path] = $this->getUrl('*/' . $path);
108
+
109
+ $urls = json_encode($urls);
110
+ //------------------------------
111
+
112
+ $component = Ess_M2ePro_Helper_Component_Buy::NICK;
113
+ $layout = $this->getLayout();
114
+
115
+ $temp = Mage::helper('M2ePro/Data_Session')->getValue('products_ids_for_list', true);
116
+ $productsIdsForList = empty($temp) ? '' : $temp;
117
+
118
+ $gridId = 'buyListingViewGrid' . $listingData['id'];
119
+ $ignoreListings = json_encode(array($listingData['id']));
120
+
121
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing', array(
122
+ 'id' => $listingData['id'],
123
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_BUY,
124
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array('id' =>$listingData['id']))
125
+ ));
126
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
127
+
128
+ $runListProducts = $this->getUrl('*/adminhtml_common_buy_listing/runListProducts');
129
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_buy_listing/runReviseProducts');
130
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_buy_listing/runRelistProducts');
131
+ $runStopProducts = $this->getUrl('*/adminhtml_common_buy_listing/runStopProducts');
132
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_buy_listing/runStopAndRemoveProducts');
133
+
134
+ $prepareData = $this->getUrl('*/adminhtml_listing_moving/prepareMoveToListing');
135
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_moving/moveToListingGrid');
136
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_moving/getFailedProductsGrid');
137
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_moving/tryToMoveToListing');
138
+ $moveToListing = $this->getUrl('*/adminhtml_listing_moving/moveToListing');
139
+
140
+ $getVariationEditPopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationEditPopup');
141
+ $getVariationManagePopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationManagePopup');
142
+
143
+ $variationEditActionUrl = $this->getUrl('*/adminhtml_common_listing/variationEdit');
144
+ $variationManageActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManage');
145
+ $variationManageGenerateActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManageGenerate');
146
+
147
+ $popupTitle = $helper->escapeJs($helper->__('Moving Rakuten.com Items'));
148
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Rakuten.com Item'));
149
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
150
+
151
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
152
+ $taskCompletedSuccessMessage = $helper->escapeJs(
153
+ $helper->__('"%task_title%" task has successfully submitted to be processed.')
154
+ );
155
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
156
+ '"%task_title%" task has completed with warnings. <a target="_blank" href="%url%">View log</a> for details.'
157
+ ));
158
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
159
+ '"%task_title%" task has completed with errors. <a target="_blank" href="%url%">View log</a> for details.'
160
+ ));
161
+
162
+ $lockedObjNoticeMessage = $helper->escapeJs(
163
+ $helper->__('Some Rakuten.com request(s) are being processed now.')
164
+ );
165
+ $sendingDataToBuyMessage = $helper->escapeJs($helper->__(
166
+ 'Sending %product_title% Product(s) data on Rakuten.com.'
167
+ ));
168
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
169
+
170
+ $listingLockedMessage = $helper->escapeJs(
171
+ $helper->__('The Listing was locked by another process. Please try again later.')
172
+ );
173
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
174
+
175
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
176
+ ->__('Listing All Items On Rakuten.com'));
177
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
178
+ ->__('Listing Selected Items On Rakuten.com'));
179
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
180
+ ->__('Revising Selected Items On Rakuten.com'));
181
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
182
+ ->__('Relisting Selected Items On Rakuten.com'));
183
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
184
+ ->__('Stopping Selected Items On Rakuten.com'));
185
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
186
+ ->escapeJs(Mage::helper('M2ePro')
187
+ ->__('Stopping On Rakuten.com And Removing From Listing Selected Items'));
188
+ $addNewSkuSelectedItemsMessage = Mage::helper('M2ePro')
189
+ ->escapeJs(Mage::helper('M2ePro')
190
+ ->__('Adding New SKU On Rakuten.com'));
191
+
192
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully moved.'));
193
+ $productsWereNotMovedMessage = $helper->escapeJs(
194
+ $helper->__('Product(s) was not moved. <a target="_blank" href="%url%">View log</a> for details.')
195
+ );
196
+ $someProductsWereNotMovedMessage = $helper->escapeJs(
197
+ $helper->__('Some Product(s) was not moved. <a target="_blank" href="%url%">View log</a> for details.')
198
+ );
199
+
200
+ $selectItemsMessage = $helper->escapeJs(
201
+ $helper->__('Please select the Products you want to perform the action on.')
202
+ );
203
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select action.'));
204
+
205
+ $successWord = $helper->escapeJs($helper->__('Success'));
206
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
207
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
208
+ $errorWord = $helper->escapeJs($helper->__('Error'));
209
+ $closeWord = $helper->escapeJs($helper->__('Close'));
210
+
211
+ $naString = Mage::helper('M2ePro')->__('N/A');
212
+ $assignString = Mage::helper('M2ePro')->__('Assign Rakuten.com SKU');
213
+
214
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
215
+
216
+ $searchBuyComSkuManual = $this->getUrl('*/adminhtml_common_buy_listing/searchBuyComSkuManual');
217
+ $suggestedBuyComSkuGridHmtl = $this->getUrl('*/adminhtml_common_buy_listing/getSuggestedBuyComSkuGrid');
218
+ $searchBuyComSkuAuto = $this->getUrl('*/adminhtml_common_buy_listing/searchBuyComSkuAuto');
219
+ $mapToBuyComSku = $this->getUrl('*/adminhtml_common_buy_listing/mapToBuyComSku');
220
+ $unmapFromBuyComSku = $this->getUrl('*/adminhtml_common_buy_listing/unmapFromBuyComSku');
221
+
222
+ $newGeneralId = $this->getUrl('*/adminhtml_common_buy_template_newProduct');
223
+
224
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
225
+ $marketplaceInstance = Mage::helper('M2ePro/Component_Buy')->getCachedObject('Marketplace',$marketplaceId);
226
+ $marketplace = json_encode($marketplaceInstance->getData());
227
+
228
+ $isMarketplaceSynchronized = json_encode($marketplaceInstance->getChildObject()->isSynchronized());
229
+ $marketplaceSynchUrl = $this->getUrl(
230
+ '*/adminhtml_common_marketplace/index',
231
+ array('tab' => Ess_M2ePro_Block_Adminhtml_Common_Marketplace::TAB_ID_RAKUTEN)
232
+ );
233
+ $notSynchronizedMarketplace = $helper->escapeJs(
234
+ $helper->__(
235
+ 'In order to use New SKU functionality, please re-synchronize Marketplace data.'
236
+ ).' '.
237
+ $helper->__(
238
+ 'Press "Save And Update" button after redirect on Marketplace page.'
239
+ )
240
+ );
241
+
242
+ $enterProductSearchQueryMessage = $helper->escapeJs(
243
+ $helper->__('Please enter Product Title or Rakuten.com SKU/ISBN/UPC.')
244
+ );
245
+ $autoMapBuyComSkuProgressTitle = $helper->escapeJs($helper->__('Assign Rakuten.com SKU to Item(s)'));
246
+ $autoMapBuyComSkuErrorMessage = $helper->escapeJs(
247
+ $helper->__('Server is currently unavailable. Please try again later.')
248
+ );
249
+
250
+ $noVariationsLeftText = $helper->__('All variations are already added.');
251
+
252
+ $translations = json_encode(array(
253
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
254
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
255
+ 'You must select at least 1 category.' => $helper->__('You must select at least 1 category.'),
256
+ 'Rule with the same title already exists.' => $helper->__('Rule with the same title already exists.')
257
+ ));
258
+
259
+ $javascriptsMain = <<<JAVASCRIPT
260
+ <script type="text/javascript">
261
+
262
+ if (typeof M2ePro == 'undefined') {
263
+ M2ePro = {};
264
+ M2ePro.url = {};
265
+ M2ePro.formData = {};
266
+ M2ePro.customData = {};
267
+ M2ePro.text = {};
268
+ }
269
+
270
+ M2ePro.url.add({$urls});
271
+ M2ePro.translator.add({$translations});
272
+
273
+ M2ePro.productsIdsForList = '{$productsIdsForList}';
274
+
275
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
276
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
277
+
278
+ M2ePro.url.runListProducts = '{$runListProducts}';
279
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
280
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
281
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
282
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
283
+
284
+ M2ePro.url.searchBuyComSkuManual = '{$searchBuyComSkuManual}';
285
+ M2ePro.url.searchBuyComSkuAuto = '{$searchBuyComSkuAuto}';
286
+ M2ePro.url.suggestedBuyComSkuGrid = '{$suggestedBuyComSkuGridHmtl}';
287
+ M2ePro.url.mapToBuyComSku = '{$mapToBuyComSku}';
288
+ M2ePro.url.unmapFromBuyComSku = '{$unmapFromBuyComSku}';
289
+
290
+ M2ePro.url.prepareData = '{$prepareData}';
291
+ M2ePro.url.getGridHtml = '{$getMoveToListingGridHtml}';
292
+ M2ePro.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
293
+ M2ePro.url.tryToMoveToListing = '{$tryToMoveToListing}';
294
+ M2ePro.url.moveToListing = '{$moveToListing}';
295
+
296
+ M2ePro.url.get_variation_edit_popup = '{$getVariationEditPopupUrl}';
297
+ M2ePro.url.get_variation_manage_popup = '{$getVariationManagePopupUrl}';
298
+
299
+ M2ePro.url.variation_edit_action = '{$variationEditActionUrl}';
300
+ M2ePro.url.variation_manage_action = '{$variationManageActionUrl}';
301
+ M2ePro.url.variation_manage_generate_action = '{$variationManageGenerateActionUrl}';
302
+
303
+ M2ePro.url.newGeneralId = '{$newGeneralId}';
304
+ M2ePro.url.marketplace_synch = '{$marketplaceSynchUrl}';
305
+
306
+ M2ePro.text.popup_title = '{$popupTitle}';
307
+ M2ePro.text.popup_title_single = '{$popupTitleSingle}';
308
+ M2ePro.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
309
+
310
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
311
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
312
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
313
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
314
+
315
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
316
+ M2ePro.text.sending_data_message = '{$sendingDataToBuyMessage}';
317
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
318
+
319
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
320
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
321
+
322
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
323
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
324
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
325
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
326
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
327
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
328
+ M2ePro.text.add_new_sku_selected_items_message = '{$addNewSkuSelectedItemsMessage}';
329
+
330
+ M2ePro.text.successfully_moved = '{$successfullyMovedMessage}';
331
+ M2ePro.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
332
+ M2ePro.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
333
+
334
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
335
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
336
+
337
+ M2ePro.text.success_word = '{$successWord}';
338
+ M2ePro.text.notice_word = '{$noticeWord}';
339
+ M2ePro.text.warning_word = '{$warningWord}';
340
+ M2ePro.text.error_word = '{$errorWord}';
341
+ M2ePro.text.close_word = '{$closeWord}';
342
+
343
+ M2ePro.text.na = '{$naString}';
344
+ M2ePro.text.assign = '{$assignString}';
345
+
346
+ M2ePro.text.confirm = '{$textConfirm}';
347
+
348
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
349
+ M2ePro.text.automap_buy_com_sku_progress_title = '{$autoMapBuyComSkuProgressTitle}';
350
+ M2ePro.text.automap_error_message = '{$autoMapBuyComSkuErrorMessage}';
351
+
352
+ M2ePro.text.no_variations_left = '{$noVariationsLeftText}';
353
+
354
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
355
+
356
+ M2ePro.customData.componentMode = '{$component}';
357
+ M2ePro.customData.gridId = '{$gridId}';
358
+ M2ePro.customData.ignoreListings = '{$ignoreListings}';
359
+
360
+ M2ePro.customData.marketplace = {$marketplace};
361
+ M2ePro.customData.isMarketplaceSynchronized = {$isMarketplaceSynchronized};
362
+
363
+ Event.observe(window, 'load', function() {
364
+
365
+ ListingGridHandlerObj = new BuyListingGridHandler(
366
+ 'buyListingViewGrid{$listingData['id']}',
367
+ {$listingData['id']}
368
+ );
369
+
370
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
371
+ ListingGridHandlerObj.movingHandler.setOptions(M2ePro);
372
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
373
+
374
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
375
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
376
+
377
+ ListingProductVariationHandlerObj = new ListingProductVariationHandler(M2ePro,
378
+ ListingGridHandlerObj);
379
+
380
+ if (M2ePro.productsIdsForList) {
381
+ ListingGridHandlerObj.getGridMassActionObj().checkedString = M2ePro.productsIdsForList;
382
+ ListingGridHandlerObj.actionHandler.listAction();
383
+ }
384
+
385
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
386
+ if ({$showAutoAction}) {
387
+ ListingAutoActionHandlerObj.loadAutoActionHtml();
388
+ }
389
+
390
+ });
391
+
392
+ </script>
393
+ JAVASCRIPT;
394
+
395
+ $helpBlock = $layout->createBlock('M2ePro/adminhtml_common_buy_listing_view_help');
396
+ $productSearchMenuBlock = $layout->createBlock('M2ePro/adminhtml_common_buy_listing_productSearch_menu');
397
+ $productSearchBlock = $layout->createBlock('M2ePro/adminhtml_common_buy_listing_productSearch_main');
398
+
399
+ //------------------------------
400
+ $data = array(
401
+ 'target_css_class' => 'edit_settings_drop_down',
402
+ 'items' => $this->getTemplatesButtonDropDownItems()
403
+ );
404
+ $templatesDropDownBlock = $layout->createBlock('M2ePro/adminhtml_widget_button_dropDown');
405
+ $templatesDropDownBlock->setData($data);
406
+ //------------------------------
407
+
408
+ //------------------------------
409
+ $data = array(
410
+ 'target_css_class' => 'add_products_drop_down',
411
+ 'items' => $this->getAddProductsDropDownItems()
412
+ );
413
+ $addProductsDropDownBlock = $layout->createBlock('M2ePro/adminhtml_widget_button_dropDown');
414
+ $addProductsDropDownBlock->setData($data);
415
+ //------------------------------
416
+
417
+ //------------------------------
418
+ $listingSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_view_listingSwitcher');
419
+ //------------------------------
420
+
421
+ //------------------------------
422
+ $viewHeaderBlock = $this->getLayout()->createBlock(
423
+ 'M2ePro/adminhtml_listing_view_header','',
424
+ array('listing' => Mage::helper('M2ePro/Component_Buy')->getCachedObject('Listing',$listingData['id']))
425
+ );
426
+ //------------------------------
427
+
428
+ return $javascriptsMain
429
+ . $templatesDropDownBlock->toHtml()
430
+ . $listingSwitcher->toHtml()
431
+ . $addProductsDropDownBlock->toHtml()
432
+ . $helpBlock->toHtml()
433
+ . $viewHeaderBlock->toHtml()
434
+ . $productSearchMenuBlock->toHtml()
435
+ . $productSearchBlock->toHtml()
436
+ . parent::getGridHtml();
437
+ }
438
+
439
+ public function getHeaderHtml()
440
+ {
441
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
442
+
443
+ //------------------------------
444
+ $collection = Mage::getModel('M2ePro/Listing')->getCollection();
445
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Buy::NICK);
446
+ $collection->addFieldToFilter('id', array('neq' => $listingData['id']));
447
+ $collection->setPageSize(200);
448
+ $collection->setOrder('title', 'ASC');
449
+
450
+ $items = array();
451
+ foreach ($collection->getItems() as $item) {
452
+ $items[] = array(
453
+ 'label' => $item->getTitle(),
454
+ 'url' => $this->getUrl('*/*/view', array('id' => $item->getId()))
455
+ );
456
+ }
457
+ //------------------------------
458
+
459
+ if (count($items) == 0) {
460
+ return parent::getHeaderHtml();
461
+ }
462
+
463
+ //------------------------------
464
+ $data = array(
465
+ 'target_css_class' => 'listing-profile-title',
466
+ 'style' => 'max-height: 120px; overflow: auto; width: 200px;',
467
+ 'items' => $items
468
+ );
469
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
470
+ $dropDownBlock->setData($data);
471
+ //------------------------------
472
+
473
+ return parent::getHeaderHtml() . $dropDownBlock->toHtml();
474
+ }
475
+
476
+ public function getHeaderText()
477
+ {
478
+ //------------------------------
479
+ $changeProfile = Mage::helper('M2ePro')->__('Change Listing');
480
+ $headerText = parent::getHeaderText();
481
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
482
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($listingData['title']);
483
+ //------------------------------
484
+
485
+ return <<<HTML
486
+ {$headerText} <a href="javascript: void(0);"
487
+ id="listing-profile-title"
488
+ class="listing-profile-title"
489
+ style="font-weight: bold;"
490
+ title="{$changeProfile}"><span class="drop_down_header">"{$listingTitle}"</span></a>
491
+ HTML;
492
+ }
493
+
494
+ protected function getTemplatesButtonDropDownItems()
495
+ {
496
+ $items = array();
497
+
498
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
499
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
500
+ '*/adminhtml_common_buy_listing/view',
501
+ array(
502
+ 'id' => $listingData['id']
503
+ )
504
+ );
505
+
506
+ //------------------------------
507
+ $url = $this->getUrl(
508
+ '*/adminhtml_common_buy_listing/edit',
509
+ array(
510
+ 'id' => $listingData['id'],
511
+ 'back' => $backUrl,
512
+ 'tab' => 'selling'
513
+ )
514
+ );
515
+ $items[] = array(
516
+ 'url' => $url,
517
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
518
+ 'target' => '_blank'
519
+ );
520
+ //------------------------------
521
+
522
+ //------------------------------
523
+ $url = $this->getUrl(
524
+ '*/adminhtml_common_buy_listing/edit',
525
+ array(
526
+ 'id' => $listingData['id'],
527
+ 'back' => $backUrl,
528
+ 'tab' => 'search'
529
+ )
530
+ );
531
+ $items[] = array(
532
+ 'url' => $url,
533
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
534
+ 'target' => '_blank'
535
+ );
536
+ //------------------------------
537
+
538
+ //------------------------------
539
+ $items[] = array(
540
+ 'url' => 'javascript: void(0);',
541
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();',
542
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules')
543
+ );
544
+ //------------------------------
545
+
546
+ return $items;
547
+ }
548
+
549
+ public function getAddProductsDropDownItems()
550
+ {
551
+ $items = array();
552
+
553
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
554
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array(
555
+ 'id' => $listingData['id']
556
+ ));
557
+
558
+ //------------------------------
559
+ $url = $this->getUrl(
560
+ '*/adminhtml_common_listing_productAdd/index',
561
+ array(
562
+ 'id' => $listingData['id'],
563
+ 'back' => $backUrl,
564
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
565
+ 'clear' => 1,
566
+ 'step' => 2,
567
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
568
+ )
569
+ );
570
+ $items[] = array(
571
+ 'url' => $url,
572
+ 'label' => Mage::helper('M2ePro')->__('From Products List')
573
+ );
574
+ //------------------------------
575
+
576
+ //------------------------------
577
+ $url = $this->getUrl(
578
+ '*/adminhtml_common_listing_productAdd/index',
579
+ array(
580
+ 'id' => $listingData['id'],
581
+ 'back' => $backUrl,
582
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
583
+ 'clear' => 1,
584
+ 'step' => 2,
585
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
586
+ )
587
+ );
588
+ $items[] = array(
589
+ 'url' => $url,
590
+ 'label' => Mage::helper('M2ePro')->__('From Categories')
591
+ );
592
+ //------------------------------
593
+
594
+ return $items;
595
+ }
596
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Grid.php ADDED
@@ -0,0 +1,972 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_View_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
9
+ {
10
+ public $hideMassactionColumn = false;
11
+
12
+ /** @var $sellingFormatTemplate Ess_M2ePro_Model_Buy_Template_SellingFormat */
13
+ private $sellingFormatTemplate = NULL;
14
+
15
+ private $lockedDataCache = array();
16
+
17
+ // ####################################
18
+
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+
23
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
24
+
25
+ // Initialization block
26
+ //------------------------------
27
+ $this->setId('buyListingViewGrid'.$listingData['id']);
28
+ //------------------------------
29
+
30
+ $this->showAdvancedFilterProductsOption = false;
31
+
32
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Buy')->getCachedObject(
33
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
34
+ array('template')
35
+ );
36
+ }
37
+
38
+ // ####################################
39
+
40
+ protected function _prepareCollection()
41
+ {
42
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
43
+
44
+ // Get collection
45
+ //----------------------------
46
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
47
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
48
+ Mage::getModel('catalog/product')->getResource());
49
+ $collection
50
+ ->setListingProductModeOn()
51
+ ->addAttributeToSelect('name')
52
+ ->addAttributeToSelect('sku')
53
+ ->joinTable(
54
+ array('cisi' => 'cataloginventory/stock_item'),
55
+ 'product_id=entity_id',
56
+ array('qty' => 'qty'),
57
+ '{{table}}.stock_id=1',
58
+ 'left'
59
+ );
60
+
61
+ //----------------------------
62
+
63
+ $collection->joinTable(
64
+ array('lp' => 'M2ePro/Listing_Product'),
65
+ 'product_id=entity_id',
66
+ array(
67
+ 'id' => 'id',
68
+ 'component_mode' => 'component_mode',
69
+ 'buy_status' => 'status',
70
+ 'additional_data' => 'additional_data'
71
+ ),
72
+ array(
73
+ 'listing_id' => (int)$listingData['id']
74
+ )
75
+ );
76
+ $collection->joinTable(
77
+ array('blp' => 'M2ePro/Buy_Listing_Product'),
78
+ 'listing_product_id=id',
79
+ array(
80
+ 'general_id' => 'general_id',
81
+ 'buy_sku' => 'sku',
82
+ 'online_price' => 'online_price',
83
+ 'online_qty' => 'online_qty',
84
+ 'search_settings_status' => 'search_settings_status',
85
+ 'search_settings_data' => 'search_settings_data'
86
+ ),
87
+ null
88
+ );
89
+ //----------------------------
90
+
91
+ //exit($collection->getSelect()->__toString());
92
+
93
+ // Set collection to grid
94
+ $this->setCollection($collection);
95
+
96
+ return parent::_prepareCollection();
97
+ }
98
+
99
+ protected function _prepareColumns()
100
+ {
101
+ $this->addColumn('product_id', array(
102
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
103
+ 'align' => 'right',
104
+ 'width' => '100px',
105
+ 'type' => 'number',
106
+ 'index' => 'entity_id',
107
+ 'filter_index' => 'entity_id',
108
+ 'frame_callback' => array($this, 'callbackColumnProductId')
109
+ ));
110
+
111
+ $this->addColumn('name', array(
112
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
113
+ 'align' => 'left',
114
+ //'width' => '300px',
115
+ 'type' => 'text',
116
+ 'index' => 'name',
117
+ 'filter_index' => 'name',
118
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
119
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
120
+ ));
121
+
122
+ $this->addColumn('sku', array(
123
+ 'header' => Mage::helper('M2ePro')->__('Reference ID'),
124
+ 'align' => 'left',
125
+ 'width' => '150px',
126
+ 'type' => 'text',
127
+ 'index' => 'buy_sku',
128
+ 'filter_index' => 'buy_sku',
129
+ 'frame_callback' => array($this, 'callbackColumnSku')
130
+ ));
131
+
132
+ $this->addColumn('general_id', array(
133
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
134
+ 'align' => 'left',
135
+ 'width' => '80px',
136
+ 'type' => 'text',
137
+ 'index' => 'general_id',
138
+ 'filter_index' => 'general_id',
139
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
140
+ ));
141
+
142
+ $this->addColumn('online_qty', array(
143
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
144
+ 'align' => 'right',
145
+ 'width' => '70px',
146
+ 'type' => 'number',
147
+ 'index' => 'online_qty',
148
+ 'filter_index' => 'online_qty',
149
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
150
+ ));
151
+
152
+ $this->addColumn('online_price', array(
153
+ 'header' => Mage::helper('M2ePro')->__('Price'),
154
+ 'align' => 'right',
155
+ 'width' => '70px',
156
+ 'type' => 'number',
157
+ 'index' => 'online_price',
158
+ 'filter_index' => 'online_price',
159
+ 'frame_callback' => array($this, 'callbackColumnPrice')
160
+ ));
161
+
162
+ $this->addColumn('status', array(
163
+ 'header' => Mage::helper('M2ePro')->__('Status'),
164
+ 'width' => '125px',
165
+ 'index' => 'buy_status',
166
+ 'filter_index' => 'buy_status',
167
+ 'type' => 'options',
168
+ 'sortable' => false,
169
+ 'options' => array(
170
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
171
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
172
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
173
+ ),
174
+ 'frame_callback' => array($this, 'callbackColumnStatus')
175
+ ));
176
+
177
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
178
+ $this->addColumn('developer_action', array(
179
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
180
+ 'align' => 'left',
181
+ 'width' => '120px',
182
+ 'type' => 'text',
183
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
184
+ 'index' => 'value',
185
+ 'filter' => false,
186
+ 'sortable' => false,
187
+ 'js_handler' => 'ListingGridHandlerObj'
188
+ ));
189
+ }
190
+
191
+ return parent::_prepareColumns();
192
+ }
193
+
194
+ protected function _prepareMassaction()
195
+ {
196
+ // Set massaction identifiers
197
+ //--------------------------------
198
+ $this->setMassactionIdField('id');
199
+ $this->setMassactionIdFieldOnlyIndexValue(true);
200
+ //--------------------------------
201
+
202
+ // Set mass-action
203
+ //--------------------------------
204
+ $groups = array(
205
+ 'actions' => Mage::helper('M2ePro')->__('Actions'),
206
+ 'rekuten_sku' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
207
+ 'other' => Mage::helper('M2ePro')->__('Other')
208
+ );
209
+
210
+ $this->getMassactionBlock()->setGroups($groups);
211
+
212
+ $this->getMassactionBlock()->addItem('list', array(
213
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
214
+ 'url' => '',
215
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
216
+ ), 'actions');
217
+
218
+ $this->getMassactionBlock()->addItem('revise', array(
219
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
220
+ 'url' => '',
221
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
222
+ ), 'actions');
223
+
224
+ $this->getMassactionBlock()->addItem('relist', array(
225
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
226
+ 'url' => '',
227
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
228
+ ), 'actions');
229
+
230
+ $this->getMassactionBlock()->addItem('stop', array(
231
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
232
+ 'url' => '',
233
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
234
+ ), 'actions');
235
+
236
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
237
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
238
+ 'url' => '',
239
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
240
+ ), 'actions');
241
+
242
+ $this->getMassactionBlock()->addItem('newGeneralId', array(
243
+ 'label' => Mage::helper('M2ePro')->__('Add New'),
244
+ 'url' => '',
245
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
246
+ ), 'rekuten_sku');
247
+
248
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
249
+ 'label' => Mage::helper('M2ePro')->__('Assign'),
250
+ 'url' => '',
251
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
252
+ ), 'rekuten_sku');
253
+
254
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
255
+ 'label' => Mage::helper('M2ePro')->__('Unassign'),
256
+ 'url' => '',
257
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
258
+ ), 'rekuten_sku');
259
+
260
+ $this->getMassactionBlock()->addItem('moving', array(
261
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Another Listing'),
262
+ 'url' => '',
263
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
264
+ ), 'other');
265
+
266
+ $this->getMassactionBlock()->addItem('duplicate', array(
267
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
268
+ 'url' => '',
269
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
270
+ ), 'other');
271
+ //--------------------------------
272
+
273
+ return parent::_prepareMassaction();
274
+ }
275
+
276
+ public function getMassactionBlockName()
277
+ {
278
+ return 'M2ePro/adminhtml_grid_massaction';
279
+ }
280
+
281
+ // ####################################
282
+
283
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
284
+ {
285
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
286
+
287
+ $value = '<span>'.$productTitle.'</span>';
288
+
289
+ $tempSku = $row->getData('sku');
290
+ is_null($tempSku)
291
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
292
+
293
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
294
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
295
+
296
+ $listingProductId = (int)$row->getData('id');
297
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
298
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product', $listingProductId);
299
+
300
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
301
+ return $value;
302
+ }
303
+
304
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()->getProductOptions();
305
+
306
+ if (!empty($productOptions)) {
307
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
308
+ foreach ($productOptions as $attribute => $option) {
309
+ !$option && $option = '--';
310
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
311
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
312
+ }
313
+ $value .= '</div>';
314
+ }
315
+
316
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProductMatched()) {
317
+
318
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
319
+ Mage::helper('M2ePro')->__('Manage "%product_title%" Options', $productTitle))
320
+ );
321
+ $linkTitle = Mage::helper('M2ePro')->__('Manage Options');
322
+ $linkContent = '<img height="12" width="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
323
+
324
+ $value.= <<<HTML
325
+ <div style="clear: both"></div>
326
+ <div style="float: left; margin: 0 0 0 5px">
327
+ <a href="javascript:"
328
+ onclick="ListingProductVariationHandlerObj
329
+ .setListingProductId({$listingProductId})
330
+ .showManagePopup('{$popupTitle}');"
331
+ title="{$linkTitle}">{$linkContent}</a>
332
+ </div>
333
+ HTML;
334
+
335
+ $linkContent = Mage::helper('M2ePro')->__('Manage Options');
336
+
337
+ $value .= <<<HTML
338
+ <div style="float: left; margin: 0 0 0 5px">
339
+ <a href="javascript:"
340
+ onclick="ListingProductVariationHandlerObj
341
+ .setListingProductId({$listingProductId})
342
+ .showManagePopup('{$popupTitle}');"
343
+ title="{$linkTitle}">{$linkContent}</a>
344
+ </div>
345
+ HTML;
346
+
347
+ return $value;
348
+ }
349
+
350
+ // ---------------------------------
351
+ $hasInActionLock = $this->getLockedData($row);
352
+ $hasInActionLock = $hasInActionLock['in_action'];
353
+ // ---------------------------------
354
+
355
+ if (!$hasInActionLock) {
356
+
357
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
358
+ Mage::helper('M2ePro')->__('Edit "%product_title%" Variation', $productTitle))
359
+ );
360
+ $linkTitle = Mage::helper('M2ePro')->__('Edit Variation');
361
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/pencil.png').'">';
362
+
363
+ $value .= <<<HTML
364
+ <div style="clear: both"></div>
365
+ <div style="margin: 0 0 0 7px; float: left;">
366
+ <a href="javascript:"
367
+ onclick="ListingProductVariationHandlerObj
368
+ .setListingProductId({$listingProductId})
369
+ .showEditPopup('{$popupTitle}');"
370
+ title="{$linkTitle}">{$linkContent}</a>
371
+ </div>
372
+ HTML;
373
+ }
374
+
375
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
376
+ Mage::helper('M2ePro')->__('Add Another "%product_title%" Variations', $productTitle))
377
+ );
378
+ $linkTitle = Mage::helper('M2ePro')->__('Add Another Variation(s)');
379
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
380
+
381
+ $value.= <<<HTML
382
+ <div style="margin: 0 0 0 5px; float: left;">
383
+ <a href="javascript:"
384
+ onclick="ListingProductVariationHandlerObj
385
+ .setListingProductId({$listingProductId})
386
+ .showManagePopup('{$popupTitle}');"
387
+ title="{$linkTitle}">{$linkContent}</a>
388
+ </div>
389
+ HTML;
390
+
391
+ return $value;
392
+ }
393
+
394
+ public function callbackColumnSku($value, $row, $column, $isExport)
395
+ {
396
+ if (is_null($value) || $value === '') {
397
+ return Mage::helper('M2ePro')->__('N/A');
398
+ }
399
+ return $value;
400
+ }
401
+
402
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
403
+ {
404
+ if (empty($generalId)) {
405
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
406
+ }
407
+
408
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
409
+ }
410
+
411
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
412
+ {
413
+ if ((int)$row->getData('buy_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
414
+ if (is_null($value) || $value === '') {
415
+ return Mage::helper('M2ePro')->__('N/A');
416
+ }
417
+ } else {
418
+ if (is_null($value) || $value === '') {
419
+ return '<i style="color:gray;">receiving...</i>';
420
+ }
421
+ }
422
+
423
+ if ($value <= 0) {
424
+ return '<span style="color: red;">0</span>';
425
+ }
426
+
427
+ return $value;
428
+ }
429
+
430
+ public function callbackColumnPrice($value, $row, $column, $isExport)
431
+ {
432
+ if ((int)$row->getData('buy_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
433
+ if (is_null($value) || $value === '') {
434
+ return Mage::helper('M2ePro')->__('N/A');
435
+ }
436
+ } else {
437
+ if (is_null($value) || $value === '') {
438
+ return '<i style="color:gray;">receiving...</i>';
439
+ }
440
+ }
441
+
442
+ if ((float)$value <= 0) {
443
+ return '<span style="color: #f00;">0</span>';
444
+ }
445
+
446
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
447
+ }
448
+
449
+ public function callbackColumnStatus($value, $row, $column, $isExport)
450
+ {
451
+ $listingProductId = (int)$row->getData('id');
452
+
453
+ $html = $this->getViewLogIconHtml($listingProductId);
454
+
455
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
456
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
457
+
458
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
459
+ if (!empty($synchNote)) {
460
+
461
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
462
+
463
+ if (empty($html)) {
464
+ $html = <<<HTML
465
+ <span style="float:right;">
466
+ <img id="map_link_error_icon_{$row->getId()}"
467
+ class="tool-tip-image"
468
+ style="vertical-align: middle;"
469
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
470
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
471
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
472
+ <span>{$synchNote}</span>
473
+ </span>
474
+ </span>
475
+ HTML;
476
+ } else {
477
+ $html .= <<<HTML
478
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
479
+ HTML;
480
+ }
481
+ }
482
+
483
+ switch ($row->getData('buy_status')) {
484
+
485
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
486
+ $html .= '<span style="color: gray;">' . $value . '</span>';
487
+ break;
488
+
489
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
490
+ $html .= '<span style="color: green;">' . $value . '</span>';
491
+ break;
492
+
493
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
494
+ $html .= '<span style="color: red;">'.$value.'</span>';
495
+ break;
496
+
497
+ default:
498
+ break;
499
+ }
500
+
501
+ $tempLocks = $this->getLockedData($row);
502
+ $tempLocks = $tempLocks['object_locks'];
503
+
504
+ foreach ($tempLocks as $lock) {
505
+
506
+ switch ($lock->getTag()) {
507
+
508
+ case 'new_sku_action':
509
+ $html .= '<br/><span style="color: #605fff">[Add New SKU in Progress...]</span>';
510
+ break;
511
+
512
+ case 'list_action':
513
+ $html .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
514
+ break;
515
+
516
+ case 'relist_action':
517
+ $html .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
518
+ break;
519
+
520
+ case 'revise_action':
521
+ $html .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
522
+ break;
523
+
524
+ case 'stop_action':
525
+ $html .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
526
+ break;
527
+
528
+ case 'stop_and_remove_action':
529
+ $html .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
530
+ break;
531
+
532
+ default:
533
+ break;
534
+ }
535
+ }
536
+
537
+ return $html;
538
+ }
539
+
540
+ protected function callbackFilterTitle($collection, $column)
541
+ {
542
+ $value = $column->getFilter()->getValue();
543
+
544
+ if ($value == null) {
545
+ return;
546
+ }
547
+
548
+ $collection->addFieldToFilter(
549
+ array(
550
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
551
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
552
+ )
553
+ );
554
+ }
555
+
556
+ // ############################################
557
+
558
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
559
+ {
560
+ // ---------------------------------
561
+ if ((int)$row->getData('buy_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
562
+ return <<<HTML
563
+ <i style="color:gray;">receiving...</i>
564
+ HTML;
565
+ }
566
+ // ---------------------------------
567
+
568
+ // ---------------------------------
569
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
570
+ // ---------------------------------
571
+
572
+ // ---------------------------------
573
+ $lpId = $row->getData('id');
574
+
575
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('value'));
576
+ if (strlen($productTitle) > 60) {
577
+ $productTitle = substr($productTitle, 0, 60) . '...';
578
+ }
579
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
580
+ // ---------------------------------
581
+
582
+ // ---------------------------------
583
+ $hasInActionLock = $this->getLockedData($row);
584
+ $hasInActionLock = $hasInActionLock['in_action'];
585
+ // ---------------------------------
586
+
587
+ $na = Mage::helper('M2ePro')->__('N/A');
588
+
589
+ $templateNewProductId = $row->getData('template_new_product_id');
590
+ if (!empty($templateNewProductId)) {
591
+
592
+ $newSkuTemplateUrl = $this->getUrl(
593
+ '*/adminhtml_common_buy_template_newProduct/edit/',
594
+ array(
595
+ 'id' => $templateNewProductId,
596
+ 'listing_product_id' => $lpId,
597
+ 'save_and_assign' => 0,
598
+ 'back' => Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/view',array(
599
+ 'id' => $row->getData('listing_id'),
600
+ ))
601
+ )
602
+ );
603
+
604
+ $newSkuTemplateTitle = Mage::getModel('M2ePro/Buy_Template_NewProduct')
605
+ ->load($templateNewProductId)
606
+ ->getData('title');
607
+
608
+ if ($hasInActionLock) {
609
+ return $newSkuTemplateTitle;
610
+ }
611
+
612
+ $tip = Mage::helper('M2ePro')->__('Unassign New SKU Policy');
613
+ $iconSrc = $iconPath.'unassign.png';
614
+
615
+ return <<<HTML
616
+ &nbsp;
617
+ <a href="{$newSkuTemplateUrl}">{$newSkuTemplateTitle}</a>
618
+ <a href="javascript:;" title="{$tip}"
619
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt('{$lpId}');">
620
+ <img src="{$iconSrc}" alt="" width="16" height="16">
621
+ </a>
622
+ HTML;
623
+ }
624
+ // ---------------------------------
625
+
626
+ // ---------------------------------
627
+ $searchSettingsData = $row->getData('search_settings_data');
628
+
629
+ if (!is_null($searchSettingsData)) {
630
+ $searchSettingsData = @json_decode($searchSettingsData,true);
631
+ }
632
+ // ---------------------------------
633
+
634
+ if (!empty($searchSettingsData['data'])) {
635
+
636
+ $tip = Mage::helper('M2ePro')->__('Choose Rakuten.com SKU from the list');
637
+ $iconSrc = $iconPath.'list.png';
638
+
639
+ return <<<HTML
640
+ {$na} &nbsp;
641
+ <a href="javascript:;" title="{$tip}"
642
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">
643
+ <img src="{$iconSrc}" alt="" width="16" height="16">
644
+ </a>
645
+ HTML;
646
+ }
647
+
648
+ $searchSettingsStatus = $row->getData('search_settings_status');
649
+
650
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Buy_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND) {
651
+
652
+ $tip = Mage::helper('M2ePro')->__(
653
+ 'There were no Products found on Rakuten.com according to the listing search settings.'
654
+ );
655
+ $tip = Mage::helper('M2ePro')->escapeJs($tip);
656
+
657
+ $iconSrc = $iconPath.'error.png';
658
+
659
+ return <<<HTML
660
+ {$na} &nbsp;
661
+ <a href="javascript: void(0);" title="{$tip}"
662
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId},'{$tip}');">
663
+ <img src="{$iconSrc}" alt="" width="16" height="16">
664
+ </a>
665
+ HTML;
666
+ }
667
+
668
+ $tip = Mage::helper('M2ePro')->__('Search for Rakuten.com SKU');
669
+ $iconSrc = $iconPath.'search.png';
670
+
671
+ return <<<HTML
672
+ {$na} &nbsp;
673
+ <a href="javascript:;" title="{$tip}"
674
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId});">
675
+ <img src="{$iconSrc}" alt="" width="16" height="16">
676
+ </a>
677
+ HTML;
678
+ }
679
+
680
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
681
+ {
682
+ $generalId = $row->getData('general_id');
683
+
684
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($generalId);
685
+
686
+ if ((int)$row->getData('buy_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
687
+ $conditionTitle = '';
688
+ switch ((int)$row->getData('condition')) {
689
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_NEW:
690
+ $conditionTitle = Mage::helper('M2ePro')->__('New');
691
+ break;
692
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_LIKE_NEW:
693
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Like New');
694
+ break;
695
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_VERY_GOOD:
696
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Very Good');
697
+ break;
698
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_GOOD:
699
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Good');
700
+ break;
701
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_ACCEPTABLE:
702
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Acceptable');
703
+ break;
704
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_REFURBISHED:
705
+ $conditionTitle = Mage::helper('M2ePro')->__('Refurbished');
706
+ break;
707
+ }
708
+ return <<<HTML
709
+ <a href="{$url}" target="_blank">{$generalId}</a><br/>
710
+ <span style="color:gray;">{$conditionTitle}</span>
711
+ HTML;
712
+ }
713
+
714
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
715
+
716
+ $generalIdSearchInfo = @json_decode($row->getData('general_id_search_info'), true);
717
+
718
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
719
+
720
+ $tip = Mage::helper('M2ePro')->__('Rakuten.com SKU was found automatically');
721
+
722
+ $text = <<<HTML
723
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
724
+ HTML;
725
+
726
+ } else {
727
+
728
+ $text = <<<HTML
729
+ <a href="{$url}" target="_blank">{$generalId}</a>
730
+ HTML;
731
+
732
+ }
733
+
734
+ // ---------------------------------
735
+ $hasInActionLock = $this->getLockedData($row);
736
+ $hasInActionLock = $hasInActionLock['in_action'];
737
+ // ---------------------------------
738
+
739
+ if ($hasInActionLock) {
740
+ return $text;
741
+ }
742
+
743
+ $tip = Mage::helper('M2ePro')->__('Unassign Rakuten.com SKU');
744
+ $iconSrc = $iconPath.'unassign.png';
745
+
746
+ $id = $row->getData('id');
747
+
748
+ $text .= <<<HTML
749
+ <a href="javascript:;" onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$id});"
750
+ title="{$tip}">
751
+ <img src="{$iconSrc}" width="16" height="16"/>
752
+ </a>
753
+ HTML;
754
+
755
+ return $text;
756
+ }
757
+
758
+ // ############################################
759
+
760
+ public function getViewLogIconHtml($listingProductId)
761
+ {
762
+ $listingProductId = (int)$listingProductId;
763
+
764
+ // Get last messages
765
+ //--------------------------
766
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
767
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
768
+
769
+ $dbSelect = $connRead->select()
770
+ ->from(
771
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
772
+ array('action_id','action','type','description','create_date','initiator')
773
+ )
774
+ ->where('`listing_product_id` = ?',$listingProductId)
775
+ ->where('`action_id` IS NOT NULL')
776
+ ->order(array('id DESC'))
777
+ ->limit(30);
778
+
779
+ $logRows = $connRead->fetchAll($dbSelect);
780
+ //--------------------------
781
+
782
+ // Get grouped messages by action_id
783
+ //--------------------------
784
+ $actionsRows = array();
785
+ $tempActionRows = array();
786
+ $lastActionId = false;
787
+
788
+ foreach ($logRows as $row) {
789
+
790
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
791
+
792
+ if ($row['action_id'] !== $lastActionId) {
793
+ if (count($tempActionRows) > 0) {
794
+ $actionsRows[] = array(
795
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
796
+ 'date' => $this->getMainDateForActionId($tempActionRows),
797
+ 'action' => $this->getActionForAction($tempActionRows[0]),
798
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
799
+ 'items' => $tempActionRows
800
+ );
801
+ $tempActionRows = array();
802
+ }
803
+ $lastActionId = $row['action_id'];
804
+ }
805
+ $tempActionRows[] = $row;
806
+ }
807
+
808
+ if (count($tempActionRows) > 0) {
809
+ $actionsRows[] = array(
810
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
811
+ 'date' => $this->getMainDateForActionId($tempActionRows),
812
+ 'action' => $this->getActionForAction($tempActionRows[0]),
813
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
814
+ 'items' => $tempActionRows
815
+ );
816
+ }
817
+
818
+ if (count($actionsRows) <= 0) {
819
+ return '';
820
+ }
821
+
822
+ $tips = array(
823
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last action was completed successfully.',
824
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last action was completed with error(s).',
825
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last action was completed with warning(s).'
826
+ );
827
+
828
+ $icons = array(
829
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
830
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
831
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
832
+ );
833
+
834
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
835
+ 'entity_id' => $listingProductId,
836
+ 'rows' => $actionsRows,
837
+ 'tips' => $tips,
838
+ 'icons' => $icons,
839
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
840
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
841
+ ));
842
+
843
+ return $summary->toHtml();
844
+ }
845
+
846
+ public function getActionForAction($actionRows)
847
+ {
848
+ $string = '';
849
+
850
+ switch ($actionRows['action']) {
851
+ case Ess_M2ePro_Model_Listing_Log::ACTION_NEW_SKU_PRODUCT_ON_COMPONENT:
852
+ $string = Mage::helper('M2ePro')->__('New SKU');
853
+ break;
854
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
855
+ $string = Mage::helper('M2ePro')->__('List');
856
+ break;
857
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
858
+ $string = Mage::helper('M2ePro')->__('Relist');
859
+ break;
860
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
861
+ $string = Mage::helper('M2ePro')->__('Revise');
862
+ break;
863
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
864
+ $string = Mage::helper('M2ePro')->__('Stop');
865
+ break;
866
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
867
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
868
+ break;
869
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANGE_STATUS_ON_CHANNEL:
870
+ $string = Mage::helper('M2ePro')->__('Status Change');
871
+ break;
872
+ }
873
+
874
+ return $string;
875
+ }
876
+
877
+ public function getInitiatorForAction($actionRows)
878
+ {
879
+ $string = '';
880
+
881
+ switch ((int)$actionRows['initiator']) {
882
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
883
+ $string = '';
884
+ break;
885
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
886
+ $string = Mage::helper('M2ePro')->__('Manual');
887
+ break;
888
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
889
+ $string = Mage::helper('M2ePro')->__('Automatic');
890
+ break;
891
+ }
892
+
893
+ return $string;
894
+ }
895
+
896
+ public function getMainTypeForActionId($actionRows)
897
+ {
898
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
899
+
900
+ foreach ($actionRows as $row) {
901
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
902
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
903
+ break;
904
+ }
905
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
906
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
907
+ }
908
+ }
909
+
910
+ return $type;
911
+ }
912
+
913
+ public function getMainDateForActionId($actionRows)
914
+ {
915
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
916
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
917
+ }
918
+
919
+ // ####################################
920
+
921
+ public function getGridUrl()
922
+ {
923
+ return $this->getUrl('*/adminhtml_common_buy_listing/viewGrid', array('_current'=>true));
924
+ }
925
+
926
+ public function getRowUrl($row)
927
+ {
928
+ return false;
929
+ }
930
+
931
+ // ####################################
932
+
933
+ protected function _toHtml()
934
+ {
935
+ $javascriptsMain = <<<JAVASCRIPT
936
+ <script type="text/javascript">
937
+
938
+ if (typeof ListingGridHandlerObj != 'undefined') {
939
+ ListingGridHandlerObj.afterInitPage();
940
+ }
941
+
942
+ Event.observe(window, 'load', function() {
943
+ setTimeout(function() {
944
+ ListingGridHandlerObj.afterInitPage();
945
+ }, 350);
946
+ });
947
+
948
+ </script>
949
+ JAVASCRIPT;
950
+
951
+ return parent::_toHtml().$javascriptsMain;
952
+ }
953
+
954
+ // ####################################
955
+
956
+ private function getLockedData($row)
957
+ {
958
+ $listingProductId = $row->getData('id');
959
+ if (!isset($this->lockedDataCache[$listingProductId])) {
960
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($listingProductId)->getObjectLocks();
961
+ $tempArray = array(
962
+ 'object_locks' => $objectLocks,
963
+ 'in_action' => !empty($objectLocks),
964
+ );
965
+ $this->lockedDataCache[$listingProductId] = $tempArray;
966
+ }
967
+
968
+ return $this->lockedDataCache[$listingProductId];
969
+ }
970
+
971
+ // ####################################
972
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_View_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyListingViewHelp');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/listing/view/help.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/ListingSwitcher.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_View_ListingSwitcher
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_View_ListingSwitcher_Abstract
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+
16
+ $this->setAddListingUrl('*/adminhtml_common_buy_listing/add/step/1/');
17
+ }
18
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Order_Edit_ShippingAddress
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('buyOrderEditShippingAddress');
17
+ $this->_blockGroup = 'M2ePro';
18
+ $this->_controller = 'adminhtml_common_buy_order_edit';
19
+ $this->_mode = 'shippingAddress';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $this->_headerText = Mage::helper('M2ePro')->__('Edit Shipping Address');
25
+ //------------------------------
26
+
27
+ // Set buttons actions
28
+ //------------------------------
29
+ $this->removeButton('back');
30
+ $this->removeButton('reset');
31
+ $this->removeButton('delete');
32
+ $this->removeButton('add');
33
+ $this->removeButton('save');
34
+ $this->removeButton('edit');
35
+ //------------------------------
36
+
37
+ if (!is_null($this->getRequest()->getParam('back'))) {
38
+ //------------------------------
39
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
40
+ $this->_addButton('back', array(
41
+ 'label' => Mage::helper('M2ePro')->__('Back'),
42
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
43
+ 'class' => 'back'
44
+ ));
45
+ //------------------------------
46
+ } else {
47
+ //------------------------------
48
+ $url = $this->getUrl('*/*/view', array('id' => $this->getRequest()->getParam('id')));
49
+ $this->_addButton('back', array(
50
+ 'label' => Mage::helper('M2ePro')->__('Back'),
51
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
52
+ 'class' => 'back'
53
+ ));
54
+ //------------------------------
55
+ }
56
+
57
+ //------------------------------
58
+ $this->_addButton('save', array(
59
+ 'label' => Mage::helper('M2ePro')->__('Save Order Address'),
60
+ 'onclick' => 'CommonHandlerObj.save_click()',
61
+ 'class' => 'save'
62
+ ));
63
+ //------------------------------
64
+ }
65
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress/Form.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Order_Edit_ShippingAddress_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ private $order;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyOrderEditShippingAddressForm');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/order/edit/shipping_address.phtml');
21
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
22
+ }
23
+
24
+ protected function _prepareForm()
25
+ {
26
+ $form = new Varien_Data_Form(array(
27
+ 'id' => 'edit_form',
28
+ 'action' => $this->getUrl('*/*/save'),
29
+ 'method' => 'post',
30
+ 'enctype' => 'multipart/form-data'
31
+ ));
32
+
33
+ $form->setUseContainer(true);
34
+ $this->setForm($form);
35
+
36
+ return parent::_prepareForm();
37
+ }
38
+
39
+ protected function _beforeToHtml()
40
+ {
41
+ try {
42
+ $regionCode = $this->order->getShippingAddress()->getRegionCode();
43
+ } catch (Exception $e) {
44
+ $regionCode = null;
45
+ }
46
+
47
+ $this->setData('buyer_name', $this->order->getData('buyer_name'));
48
+ $this->setData('buyer_email', $this->order->getData('buyer_email'));
49
+ $this->setData('address', $this->order->getShippingAddress()->getData());
50
+ $this->setData('region_code', $regionCode);
51
+ $this->setData('company', $this->order->getChildObject()->getBillingAddress()->getData('company'));
52
+ $this->setData('phone', $this->order->getChildObject()->getBillingAddress()->getData('phone'));
53
+
54
+ return parent::_beforeToHtml();
55
+ }
56
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Grid.php ADDED
@@ -0,0 +1,434 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ /** @var $itemsCollection Ess_M2ePro_Model_Mysql4_Order_Item_Collection */
10
+ private $itemsCollection = NULL;
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('buyOrderGrid');
19
+ //------------------------------
20
+
21
+ // Set default values
22
+ //------------------------------
23
+ $this->setDefaultSort('purchase_create_date');
24
+ $this->setDefaultDir('DESC');
25
+ $this->setSaveParametersInSession(true);
26
+ $this->setUseAjax(true);
27
+ //------------------------------
28
+ }
29
+
30
+ public function getMassactionBlockName()
31
+ {
32
+ return 'M2ePro/adminhtml_grid_massaction';
33
+ }
34
+
35
+ protected function _prepareCollection()
36
+ {
37
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Order');
38
+
39
+ $collection->getSelect()->joinLeft(
40
+ array('so' => Mage::getSingleton('core/resource')->getTableName('sales/order')),
41
+ '(so.entity_id = `main_table`.magento_order_id)',
42
+ array('magento_order_num' => 'increment_id')
43
+ );
44
+
45
+ // Add Filter By Account
46
+ //------------------------------
47
+ if ($accountId = $this->getRequest()->getParam('buyAccount')) {
48
+ $collection->addFieldToFilter('`main_table`.account_id', $accountId);
49
+ }
50
+ //------------------------------
51
+
52
+ // Add Not Created Magento Orders Filter
53
+ //------------------------------
54
+ if ($this->getRequest()->getParam('not_created_only')) {
55
+ $collection->addFieldToFilter('magento_order_id', array('null' => true));
56
+ }
57
+ //------------------------------
58
+
59
+ $this->setCollection($collection);
60
+
61
+ return parent::_prepareCollection();
62
+ }
63
+
64
+ protected function _afterLoadCollection()
65
+ {
66
+ $this->itemsCollection = Mage::helper('M2ePro/Component_Buy')
67
+ ->getCollection('Order_Item')
68
+ ->addFieldToFilter('order_id', array('in' => $this->getCollection()->getColumnValues('id')));
69
+
70
+ return parent::_afterLoadCollection();
71
+ }
72
+
73
+ protected function _prepareColumns()
74
+ {
75
+ $this->addColumn('purchase_create_date', array(
76
+ 'header' => Mage::helper('M2ePro')->__('Sale Date'),
77
+ 'align' => 'left',
78
+ 'type' => 'datetime',
79
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
80
+ 'index' => 'purchase_create_date',
81
+ 'width' => '170px'
82
+ ));
83
+
84
+ $this->addColumn('magento_order_num', array(
85
+ 'header' => Mage::helper('M2ePro')->__('Magento Order #'),
86
+ 'align' => 'left',
87
+ 'index' => 'so.increment_id',
88
+ 'width' => '110px',
89
+ 'frame_callback' => array($this, 'callbackColumnMagentoOrder')
90
+ ));
91
+
92
+ $this->addColumn('buy_order_id', array(
93
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com Order #'),
94
+ 'align' => 'left',
95
+ 'width' => '110px',
96
+ 'index' => 'buy_order_id',
97
+ ));
98
+
99
+ $this->addColumn('buy_order_items', array(
100
+ 'header' => Mage::helper('M2ePro')->__('Items'),
101
+ 'align' => 'left',
102
+ 'index' => 'buy_order_items',
103
+ 'sortable' => false,
104
+ 'width' => '*',
105
+ 'frame_callback' => array($this, 'callbackColumnItems'),
106
+ 'filter_condition_callback' => array($this, 'callbackFilterItems')
107
+ ));
108
+
109
+ $this->addColumn('buyer', array(
110
+ 'header' => Mage::helper('M2ePro')->__('Buyer'),
111
+ 'align' => 'left',
112
+ 'index' => 'buyer_name',
113
+ 'frame_callback' => array($this, 'callbackColumnBuyer'),
114
+ 'filter_condition_callback' => array($this, 'callbackFilterBuyer'),
115
+ 'width' => '170px'
116
+ ));
117
+
118
+ $this->addColumn('paid_amount', array(
119
+ 'header' => Mage::helper('M2ePro')->__('Total Paid'),
120
+ 'align' => 'left',
121
+ 'width' => '110px',
122
+ 'index' => 'paid_amount',
123
+ 'type' => 'number',
124
+ 'frame_callback' => array($this, 'callbackColumnTotal')
125
+ ));
126
+
127
+ $back = Mage::helper('M2ePro')->makeBackUrlParam(
128
+ '*/adminhtml_common_order/index',
129
+ array(
130
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
131
+ )
132
+ );
133
+
134
+ $this->addColumn('action', array(
135
+ 'header' => Mage::helper('M2ePro')->__('Action'),
136
+ 'width' => '80px',
137
+ 'type' => 'action',
138
+ 'getter' => 'getId',
139
+ 'actions' => array(
140
+ array(
141
+ 'caption' => Mage::helper('M2ePro')->__('View'),
142
+ 'url' => array('base' => '*/adminhtml_common_buy_order/view'),
143
+ 'field' => 'id'
144
+ ),
145
+ array(
146
+ 'caption' => Mage::helper('M2ePro')->__('Edit Shipping Address'),
147
+ 'url' => array(
148
+ 'base' => '*/adminhtml_common_buy_order/editShippingAddress/',
149
+ 'params' => array('back' => $back)
150
+ ),
151
+ 'field' => 'id'
152
+ ),
153
+ array(
154
+ 'caption' => Mage::helper('M2ePro')->__('Create Order'),
155
+ 'url' => array('base' => '*/adminhtml_common_buy_order/createMagentoOrder'),
156
+ 'field' => 'id'
157
+ )
158
+ ),
159
+ 'filter' => false,
160
+ 'sortable' => false,
161
+ 'is_system' => true
162
+ ));
163
+
164
+ return parent::_prepareColumns();
165
+ }
166
+
167
+ protected function _prepareMassaction()
168
+ {
169
+ // Set massaction identifiers
170
+ //--------------------------------
171
+ $this->setMassactionIdField('main_table.id');
172
+ $this->getMassactionBlock()->setFormFieldName('ids');
173
+ //--------------------------------
174
+
175
+ // Set mass-action
176
+ //--------------------------------
177
+ $this->getMassactionBlock()->addItem('resend_shipping', array(
178
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
179
+ 'url' => $this->getUrl('*/adminhtml_order/resubmitShippingInfo'),
180
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
181
+ ));
182
+ //--------------------------------
183
+
184
+ return parent::_prepareMassaction();
185
+ }
186
+
187
+ //##############################################################
188
+
189
+ public function callbackColumnMagentoOrder($value, $row, $column, $isExport)
190
+ {
191
+ $magentoOrderId = $row['magento_order_id'];
192
+ $magentoOrderNumber = Mage::helper('M2ePro')->escapeHtml($row['magento_order_num']);
193
+
194
+ $returnString = Mage::helper('M2ePro')->__('N/A');
195
+
196
+ if ($row['magento_order_id']) {
197
+ if ($row['magento_order_num']) {
198
+ $orderUrl = $this->getUrl('adminhtml/sales_order/view', array('order_id' => $magentoOrderId));
199
+ $returnString = '<a href="' . $orderUrl . '" target="_blank">' . $magentoOrderNumber . '</a>';
200
+ } else {
201
+ $returnString = '<span style="color: red;">'.Mage::helper('M2ePro')->__('Deleted').'</span>';
202
+ }
203
+ }
204
+
205
+ return $returnString.$this->getViewLogIconHtml($row->getId());
206
+ }
207
+
208
+ private function getViewLogIconHtml($orderId)
209
+ {
210
+ $orderId = (int)$orderId;
211
+
212
+ // Prepare collection
213
+ // --------------------------------
214
+ $orderLogsCollection = Mage::getModel('M2ePro/Order_Log')->getCollection()
215
+ ->addFieldToFilter('order_id', $orderId)
216
+ ->setOrder('id', 'DESC');
217
+ $orderLogsCollection->getSelect()
218
+ ->limit(3);
219
+ // --------------------------------
220
+
221
+ // Prepare logs data
222
+ // --------------------------------
223
+ if ($orderLogsCollection->getSize() <= 0) {
224
+ return '';
225
+ }
226
+
227
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
228
+
229
+ $logRows = array();
230
+ foreach ($orderLogsCollection as $log) {
231
+ $logRows[] = array(
232
+ 'type' => $log->getData('type'),
233
+ 'text' => Mage::helper('M2ePro/View')->getModifiedLogMessage($log->getData('message')),
234
+ 'initiator' => $this->getInitiatorForAction($log->getData('initiator')),
235
+ 'date' => Mage::app()->getLocale()->date(strtotime($log->getData('create_date')))->toString($format)
236
+ );
237
+ }
238
+ // --------------------------------
239
+
240
+ $tips = array(
241
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last order action was completed successfully.',
242
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last order action was completed with error(s).',
243
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last order action was completed with warning(s).'
244
+ );
245
+
246
+ $icons = array(
247
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
248
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
249
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
250
+ );
251
+
252
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
253
+ 'entity_id' => $orderId,
254
+ 'rows' => $logRows,
255
+ 'tips' => $tips,
256
+ 'icons' => $icons,
257
+ 'view_help_handler' => 'OrderHandlerObj.viewOrderHelp',
258
+ 'hide_help_handler' => 'OrderHandlerObj.hideOrderHelp',
259
+ ));
260
+
261
+ return $summary->toHtml();
262
+ }
263
+
264
+ public function getInitiatorForAction($initiator)
265
+ {
266
+ $string = '';
267
+
268
+ switch ((int)$initiator) {
269
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
270
+ $string = '';
271
+ break;
272
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
273
+ $string = Mage::helper('M2ePro')->__('Manual');
274
+ break;
275
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
276
+ $string = Mage::helper('M2ePro')->__('Automatic');
277
+ break;
278
+ }
279
+
280
+ return $string;
281
+ }
282
+
283
+ //--------------------------------------------------------------
284
+
285
+ public function callbackColumnItems($value, $row, $column, $isExport)
286
+ {
287
+ /** @var $items Ess_M2ePro_Model_Order_Item[] */
288
+ $items = $this->itemsCollection->getItemsByColumnValue('order_id', $row->getData('id'));
289
+
290
+ $html = '';
291
+ $gridId = $this->getId();
292
+
293
+ foreach ($items as $item) {
294
+ if ($html != '') {
295
+ $html .= '<br/>';
296
+ }
297
+
298
+ $isShowEditLink = false;
299
+
300
+ $product = $item->getProduct();
301
+ if (!is_null($product)) {
302
+ /** @var Ess_M2ePro_Model_Magento_Product $magentoProduct */
303
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
304
+ $magentoProduct->setProduct($product);
305
+
306
+ $associatedProducts = $item->getAssociatedProducts();
307
+ $associatedOptions = $item->getAssociatedOptions();
308
+
309
+ if ($magentoProduct->isProductWithVariations()
310
+ && empty($associatedOptions)
311
+ && empty($associatedProducts)
312
+ ) {
313
+ $isShowEditLink = true;
314
+ }
315
+ }
316
+
317
+ $editItemHtml = '';
318
+ if ($isShowEditLink) {
319
+ $orderItemId = $item->getId();
320
+ $orderItemEditLabel = Mage::helper('M2ePro')->__('edit');
321
+
322
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
323
+
324
+ $editItemHtml = <<<HTML
325
+ <span>&nbsp;<a href="javascript:void(0);" onclick="{$js}">[{$orderItemEditLabel}]</a></span>
326
+ HTML;
327
+ }
328
+
329
+ $skuHtml = '';
330
+ if ($item->getSku()) {
331
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
332
+ $sku = Mage::helper('M2ePro')->escapeHtml($item->getSku());
333
+
334
+ $skuHtml = <<<HTML
335
+ <span style="padding-left: 10px;"><b>{$skuLabel}:</b>&nbsp;{$sku}</span><br/>
336
+ HTML;
337
+ }
338
+
339
+ $generalId = $item->getGeneralId();
340
+
341
+ $itemLabel = Mage::helper('M2ePro')->__('Item');
342
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
343
+ $itemUrl = Mage::helper('M2ePro/Component_Buy')->getItemUrl($generalId);
344
+
345
+ $qtyLabel = Mage::helper('M2ePro')->__('QTY');
346
+ $qty = (int)$item->getQtyPurchased();
347
+ $qtyHtml = <<<HTML
348
+ <span style="padding-left: 10px;"><b>{$qtyLabel}:&nbsp;</b>{$qty}</span>
349
+ HTML;
350
+
351
+ $html .= <<<HTML
352
+ <b>{$itemLabel}:&nbsp;#</b>&nbsp;<a href="{$itemUrl}" target="_blank">{$generalId}</a><br/>
353
+ {$itemTitle}&nbsp;{$editItemHtml}<br/>
354
+ <small>{$skuHtml}{$qtyHtml}</small>
355
+ HTML;
356
+ }
357
+
358
+ return $html;
359
+ }
360
+
361
+ public function callbackColumnBuyer($value, $row, $column, $isExport)
362
+ {
363
+ $html = Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_name')) . '<br/>';
364
+
365
+ $buyerEmail = $row->getData('buyer_email');
366
+ if ($buyerEmail) {
367
+ $html .= '&lt;' . $buyerEmail . '&gt;<br/>';
368
+ }
369
+
370
+ return $html;
371
+ }
372
+
373
+ public function callbackColumnTotal($value, $row, $column, $isExport)
374
+ {
375
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
376
+ $row->getData('currency'), $row->getData('paid_amount')
377
+ );
378
+ }
379
+
380
+ //##############################################################
381
+
382
+ protected function callbackFilterItems(Varien_Data_Collection_Db $collection, $column)
383
+ {
384
+ $value = $column->getFilter()->getValue();
385
+ if ($value == null) {
386
+ return;
387
+ }
388
+
389
+ /** @var $orderItemsCollection Varien_Data_Collection_Db */
390
+ $orderItemsCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Order_Item');
391
+
392
+ $orderItemsCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
393
+ $orderItemsCollection->getSelect()->columns('order_id');
394
+ $orderItemsCollection->getSelect()->distinct(true);
395
+
396
+ $orderItemsCollection->getSelect()
397
+ ->where('general_id LIKE ? OR sku LIKE ? OR title LIKE ?', '%'.$value.'%');
398
+
399
+ $ordersIds = $orderItemsCollection->getColumnValues('order_id');
400
+ $collection->addFieldToFilter('`main_table`.id', array('in' => $ordersIds));
401
+ }
402
+
403
+ protected function callbackFilterBuyer(Varien_Data_Collection_Db $collection, $column)
404
+ {
405
+ $value = $column->getFilter()->getValue();
406
+ if ($value == null) {
407
+ return;
408
+ }
409
+
410
+ $collection->getSelect()
411
+ ->where('buyer_email LIKE ? OR buyer_name LIKE ?', '%'.$value.'%');
412
+ }
413
+
414
+ //##############################################################
415
+
416
+ public function getGridUrl()
417
+ {
418
+ return $this->getUrl('*/adminhtml_common_buy_order/grid', array('_current' => true));
419
+ }
420
+
421
+ public function getRowUrl($row)
422
+ {
423
+ $back = Mage::helper('M2ePro')->makeBackUrlParam(
424
+ '*/adminhtml_common_order/index',
425
+ array(
426
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
427
+ )
428
+ );
429
+
430
+ return $this->getUrl('*/adminhtml_common_buy_order/view', array('id' => $row->getId(), 'back' => $back));
431
+ }
432
+
433
+ //##############################################################
434
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyOrderView');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_buy_order';
18
+ $this->_mode = 'view';
19
+ //------------------------------
20
+
21
+ // Set header text
22
+ //------------------------------
23
+ $this->_headerText = Mage::helper('M2ePro')->__('View Order Details');
24
+ //------------------------------
25
+
26
+ /** @var $order Ess_M2ePro_Model_Order */
27
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
28
+
29
+ // Set buttons actions
30
+ //------------------------------
31
+ $this->removeButton('back');
32
+ $this->removeButton('reset');
33
+ $this->removeButton('delete');
34
+ $this->removeButton('add');
35
+ $this->removeButton('save');
36
+ $this->removeButton('edit');
37
+ //------------------------------
38
+
39
+ //------------------------------
40
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
41
+ $this->_addButton('back', array(
42
+ 'label' => Mage::helper('M2ePro')->__('Back'),
43
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
44
+ 'class' => 'back'
45
+ ));
46
+ //------------------------------
47
+
48
+ if (is_null($this->order->getMagentoOrderId())) {
49
+ //------------------------------
50
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId()));
51
+ $this->_addButton('order', array(
52
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
53
+ 'onclick' => "setLocation('".$url."');",
54
+ 'class' => 'scalable'
55
+ ));
56
+ //------------------------------
57
+ } else if (is_null($this->order->getMagentoOrder()) || $this->order->getMagentoOrder()->isCanceled()) {
58
+ //------------------------------
59
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId(), 'force' => 'yes'));
60
+ $confirm = Mage::helper('M2ePro')->escapeJs(
61
+ Mage::helper('M2ePro')->__('Are you sure that you want to create new Magento Order?')
62
+ );
63
+
64
+ $this->_addButton('order', array(
65
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
66
+ 'onclick' => "confirmSetLocation('".$confirm."','".$url."');",
67
+ 'class' => 'scalable'
68
+ ));
69
+ //------------------------------
70
+ }
71
+ }
72
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Form.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Order_View_Form extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ public $shippingAddress = array();
10
+
11
+ public $realMagentoOrderId = NULL;
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('buyOrderViewForm');
20
+ $this->setTemplate('M2ePro/common/buy/order.phtml');
21
+ //------------------------------
22
+
23
+ /** @var $order Ess_M2ePro_Model_Order */
24
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
25
+ }
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ // Magento order data
30
+ // ---------------
31
+ $this->realMagentoOrderId = NULL;
32
+
33
+ $magentoOrder = $this->order->getMagentoOrder();
34
+ if (!is_null($magentoOrder)) {
35
+ $this->realMagentoOrderId = $magentoOrder->getRealOrderId();
36
+ }
37
+ // ---------------
38
+
39
+ // ---------------
40
+ if (!is_null($magentoOrder) && $magentoOrder->hasShipments()) {
41
+ $url = $this->getUrl('*/adminhtml_order/resubmitShippingInfo', array('id' => $this->order->getId()));
42
+ $data = array(
43
+ 'class' => '',
44
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
45
+ 'onclick' => 'setLocation(\''.$url.'\');',
46
+ );
47
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
48
+ $this->setChild('resubmit_shipping_info', $buttonBlock);
49
+ }
50
+ // ---------------
51
+
52
+ // Shipping data
53
+ // ---------------
54
+ /** @var $shippingAddress Ess_M2ePro_Model_Buy_Order_ShippingAddress */
55
+ $shippingAddress = $this->order->getShippingAddress();
56
+
57
+ $this->shippingAddress = $shippingAddress->getData();
58
+ $this->shippingAddress['country_name'] = $shippingAddress->getCountryName();
59
+ $this->shippingAddress['phone'] = $this->order->getChildObject()->getBillingAddress()->getData('phone');
60
+ $this->shippingAddress['company'] = $this->order->getChildObject()->getBillingAddress()->getData('company');
61
+ // ---------------
62
+
63
+ $this->setChild('item', $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_order_view_item'));
64
+ $this->setChild('item_edit', $this->getLayout()->createBlock('M2ePro/adminhtml_order_item_edit'));
65
+ $this->setChild('log', $this->getLayout()->createBlock('M2ePro/adminhtml_order_view_log_grid'));
66
+
67
+ return parent::_beforeToHtml();
68
+ }
69
+
70
+ private function getStore()
71
+ {
72
+ if (is_null($this->order->getData('store_id'))) {
73
+ return null;
74
+ }
75
+
76
+ try {
77
+ $store = Mage::app()->getStore($this->order->getData('store_id'));
78
+ } catch (Exception $e) {
79
+ return null;
80
+ }
81
+
82
+ return $store;
83
+ }
84
+
85
+ public function isCurrencyAllowed()
86
+ {
87
+ $store = $this->getStore();
88
+
89
+ if (is_null($store)) {
90
+ return true;
91
+ }
92
+
93
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
94
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
95
+
96
+ return $currencyHelper->isAllowed($this->order->getChildObject()->getCurrency(), $store);
97
+ }
98
+
99
+ public function hasCurrencyConversionRate()
100
+ {
101
+ $store = $this->getStore();
102
+
103
+ if (is_null($store)) {
104
+ return true;
105
+ }
106
+
107
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
108
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
109
+
110
+ return $currencyHelper->getConvertRateFromBase($this->order->getChildObject()->getCurrency(), $store) != 0;
111
+ }
112
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Item.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Order_View_Item extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyOrderViewItem');
16
+ //------------------------------
17
+
18
+ // Set default values
19
+ //------------------------------
20
+ $this->setDefaultSort('id');
21
+ $this->setDefaultDir('DESC');
22
+ $this->setPagerVisibility(false);
23
+ $this->setFilterVisibility(false);
24
+ $this->setUseAjax(true);
25
+ $this->_defaultLimit = 200;
26
+ //------------------------------
27
+
28
+ /** @var $order Ess_M2ePro_Model_Order */
29
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
30
+ }
31
+
32
+ protected function _prepareCollection()
33
+ {
34
+ $collection = Mage::helper('M2ePro/Component_Buy')
35
+ ->getCollection('Order_Item')
36
+ ->addFieldToFilter('order_id', $this->order->getId());
37
+
38
+ $collection->getSelect()->joinLeft(
39
+ array('cisi' => Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
40
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
41
+ array('is_in_stock')
42
+ );
43
+
44
+ $this->setCollection($collection);
45
+
46
+ return parent::_prepareCollection();
47
+ }
48
+
49
+ protected function _prepareColumns()
50
+ {
51
+ $this->addColumn('product_id', array(
52
+ 'header' => Mage::helper('M2ePro')->__('Product'),
53
+ 'align' => 'left',
54
+ 'width' => '*',
55
+ 'index' => 'product_id',
56
+ 'frame_callback' => array($this, 'callbackColumnProduct')
57
+ ));
58
+
59
+ $this->addColumn('stock_availability', array(
60
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
61
+ 'width' => '100px',
62
+ 'index' => 'is_in_stock',
63
+ 'filter_index' => 'cisi.is_in_stock',
64
+ 'type' => 'options',
65
+ 'sortable' => false,
66
+ 'options' => array(
67
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
68
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
69
+ ),
70
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
71
+ ));
72
+
73
+ $this->addColumn('original_price', array(
74
+ 'header' => Mage::helper('M2ePro')->__('Original Price'),
75
+ 'align' => 'left',
76
+ 'width' => '80px',
77
+ 'filter' => false,
78
+ 'sortable' => false,
79
+ 'frame_callback' => array($this, 'callbackColumnOriginalPrice')
80
+ ));
81
+
82
+ $this->addColumn('qty', array(
83
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
84
+ 'align' => 'left',
85
+ 'width' => '80px',
86
+ 'index' => 'qty'
87
+ ));
88
+
89
+ $this->addColumn('price', array(
90
+ 'header' => Mage::helper('M2ePro')->__('Price'),
91
+ 'align' => 'left',
92
+ 'width' => '80px',
93
+ 'index' => 'price',
94
+ 'frame_callback' => array($this, 'callbackColumnPrice')
95
+ ));
96
+
97
+ $this->addColumn('row_total', array(
98
+ 'header' => Mage::helper('M2ePro')->__('Row Total'),
99
+ 'align' => 'left',
100
+ 'width' => '80px',
101
+ 'frame_callback' => array($this, 'callbackColumnRowTotal')
102
+ ));
103
+
104
+ return parent::_prepareColumns();
105
+ }
106
+
107
+ //##############################################################
108
+
109
+ /**
110
+ * @param $value
111
+ * @param $row Ess_M2ePro_Model_Order_Item
112
+ * @param $column
113
+ * @param $isExport
114
+ *
115
+ * @return string
116
+ */
117
+ public function callbackColumnProduct($value, $row, $column, $isExport)
118
+ {
119
+ $skuHtml = '';
120
+ if ($row->getSku()) {
121
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
122
+ $sku = Mage::helper('M2ePro')->escapeHtml($row->getSku());
123
+
124
+ $skuHtml = <<<HTML
125
+ <b>{$skuLabel}:</b> {$sku}<br/>
126
+ HTML;
127
+ }
128
+
129
+ // $referenceIdLabel = Mage::helper('M2ePro')->__('Reference ID');
130
+ // $referenceId = Mage::helper('M2ePro')->escapeHtml($row->getGeneralId());
131
+ //
132
+ // $generalIdHtml = <<<HTML
133
+ //<b>{$referenceIdLabel}:</b> {$referenceId}<br/>
134
+ //HTML;
135
+
136
+ $itemUrl = Mage::helper('M2ePro/Component_Buy')->getItemUrl($row->getGeneralId());
137
+ $itemLinkText = Mage::helper('M2ePro')->__('View on Rakuten.com');
138
+
139
+ $buyLink = <<<HTML
140
+ <a href="{$itemUrl}" target="_blank">{$itemLinkText}</a>
141
+ HTML;
142
+
143
+ $productLink = '';
144
+ if ($productId = $row->getData('product_id')) {
145
+ $productUrl = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
146
+ $productLink = ' | <a href="'.$productUrl.'" target="_blank">'.Mage::helper('M2ePro')->__('View').'</a>';
147
+ }
148
+
149
+ $orderItemId = (int)$row->getId();
150
+ $gridId = $this->getId();
151
+
152
+ $editLink = '';
153
+ if (!$row->getProductId() || $row->getMagentoProduct()->hasRequiredOptions()) {
154
+
155
+ if (!$row->getProductId()) {
156
+ $action = Mage::helper('M2ePro')->__('Map to Magento Product');
157
+ } else {
158
+ $action = Mage::helper('M2ePro')->__('Set Options');
159
+ }
160
+
161
+ $class = 'class="gray"';
162
+
163
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
164
+ $editLink = '<a href="javascript:void(0);" onclick="'.$js.'" '.$class.'>'.$action.'</a>';
165
+ }
166
+
167
+ $discardLink = '';
168
+ if ($row->getProductId()) {
169
+ $action = Mage::helper('M2ePro')->__('Unmap');
170
+
171
+ $js = "{OrderEditItemHandlerObj.unassignProduct('{$gridId}', {$orderItemId});}";
172
+ $discardLink = '<a href="javascript:void(0);" onclick="'.$js.'" class="gray">'.$action.'</a>';
173
+
174
+ if ($editLink) {
175
+ $discardLink = '&nbsp;|&nbsp;' . $discardLink;
176
+ }
177
+ }
178
+
179
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($row->getTitle());
180
+
181
+ return <<<HTML
182
+ <b>{$itemTitle}</b><br/>
183
+ <div style="padding-left: 10px;">
184
+ {$skuHtml}
185
+ </div>
186
+ <div style="float: left;">{$buyLink}{$productLink}</div>
187
+ <div style="float: right;">{$editLink}{$discardLink}</div>
188
+ HTML;
189
+ }
190
+
191
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
192
+ {
193
+ if (is_null($row->getData('is_in_stock'))) {
194
+ return Mage::helper('M2ePro')->__('N/A');
195
+ }
196
+
197
+ if ((int)$row->getData('is_in_stock') <= 0) {
198
+ return '<span style="color: red;">'.$value.'</span>';
199
+ }
200
+
201
+ return $value;
202
+ }
203
+
204
+ public function callbackColumnOriginalPrice($value, $row, $column, $isExport)
205
+ {
206
+ $productId = $row->getData('product_id');
207
+ $formattedPrice = Mage::helper('M2ePro')->__('N/A');
208
+
209
+ if ($productId && $product = Mage::getModel('catalog/product')->load($productId)) {
210
+ $formattedPrice = $product->getFormatedPrice();
211
+ }
212
+
213
+ return $formattedPrice;
214
+ }
215
+
216
+ public function callbackColumnPrice($value, $row, $column, $isExport)
217
+ {
218
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($row->getData('currency'), $row->getData('price'));
219
+ }
220
+
221
+ public function callbackColumnRowTotal($value, $row, $column, $isExport)
222
+ {
223
+ $price = (float)$row->getData('price');
224
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
225
+ $row->getData('currency'), $price * $row->getData('qty')
226
+ );
227
+ }
228
+
229
+ public function getRowUrl($row)
230
+ {
231
+ return '';
232
+ }
233
+
234
+ public function getGridUrl()
235
+ {
236
+ return $this->getUrl('*/*/orderItemGrid', array('_current' => true));
237
+ }
238
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Synchronization/Form.php ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Synchronization_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ private $component = Ess_M2ePro_Helper_Component_Buy::NICK;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buySynchronizationForm');
18
+ $this->setContainerId('magento_block_buy_synchronization');
19
+ $this->setTemplate('M2ePro/common/buy/synchronization.phtml');
20
+ //------------------------------
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ //----------------------------
26
+ $this->templatesMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
27
+ ->getGroupValue('/buy/templates/', 'mode');
28
+ $this->ordersMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
29
+ ->getGroupValue('/buy/orders/', 'mode');
30
+ $this->otherListingsMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
31
+ ->getGroupValue('/buy/other_listings/', 'mode');
32
+ //----------------------------
33
+
34
+ //----------------------------
35
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
36
+
37
+ $this->reviseAllInProcessingState = !is_null(
38
+ Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
39
+ '/buy/templates/revise/total/', 'last_listing_product_id'
40
+ )
41
+ );
42
+
43
+ $this->reviseAllStartDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
44
+ '/buy/templates/revise/total/', 'start_date'
45
+ );
46
+ $this->reviseAllStartDate && $this->reviseAllStartDate = Mage::app()->getLocale()
47
+ ->date(strtotime($this->reviseAllStartDate))
48
+ ->toString($format);
49
+
50
+ $this->reviseAllEndDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
51
+ '/buy/templates/revise/total/', 'end_date'
52
+ );
53
+ $this->reviseAllEndDate && $this->reviseAllEndDate = Mage::app()->getLocale()
54
+ ->date(strtotime($this->reviseAllEndDate))
55
+ ->toString($format);
56
+ //----------------------------
57
+
58
+ //----------------------------
59
+ $component = Ess_M2ePro_Helper_Component_Buy::NICK;
60
+ $data = array(
61
+ 'class' => 'ok_button',
62
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
63
+ 'onclick' => "Windows.getFocusedWindow().close(); SynchronizationHandlerObj.runReviseAll('{$component}');",
64
+ );
65
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
66
+ $this->setChild('revise_all_confirm_popup_ok_button', $buttonBlock);
67
+ //------------------------------
68
+
69
+ //-------------------------------
70
+ $data = array(
71
+ 'label' => Mage::helper('M2ePro')->__('Run Now'),
72
+ 'onclick' =>
73
+ 'SynchronizationHandlerObj.saveSettings(\'runNowTemplates\', \'' . $this->component . '\');',
74
+ 'class' => 'templates_run_now'
75
+ );
76
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
77
+ $this->setChild('buy_templates_run_now', $buttonBlock);
78
+ //-------------------------------
79
+
80
+ //-------------------------------
81
+ $areYouSure = Mage::helper('adminhtml')->__('Are you sure?');
82
+
83
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
84
+ '*/adminhtml_common_synchronization/index',
85
+ array(
86
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
87
+ )
88
+ );
89
+ //-------------------------------
90
+
91
+ //-------------------------------
92
+ $url = $this->getUrl(
93
+ '*/adminhtml_common_synchronization/clearLog',
94
+ array(
95
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_TEMPLATES,
96
+ 'component' => $this->component,
97
+ 'back' => $backUrl
98
+ )
99
+ );
100
+ $data = array(
101
+ 'label' => Mage::helper('M2ePro')->__('Clear Log'),
102
+ 'onclick' => 'deleteConfirm(\'' . $areYouSure . '\', \'' . $url . '\')',
103
+ 'class' => 'templates_clear_log'
104
+ );
105
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
106
+ $this->setChild('buy_templates_clear_log', $buttonBlock);
107
+ //-------------------------------
108
+
109
+ //-------------------------------
110
+ $url = $this->getUrl(
111
+ '*/adminhtml_common_log/synchronization',
112
+ array(
113
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_TEMPLATES,
114
+ 'channel' => $this->component
115
+ )
116
+ );
117
+ $data = array(
118
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
119
+ 'onclick' => 'window.open(\'' . $url . '\')',
120
+ 'class' => 'button_link'
121
+ );
122
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
123
+ $this->setChild('buy_templates_view_log', $buttonBlock);
124
+ //-------------------------------
125
+
126
+ //-------------------------------
127
+ $data = array(
128
+ 'label' => Mage::helper('M2ePro')->__('Run Now'),
129
+ 'onclick' =>
130
+ 'SynchronizationHandlerObj.saveSettings(\'runNowOrders\', \'' . $this->component . '\');',
131
+ 'class' => 'orders_run_now'
132
+ );
133
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
134
+ $this->setChild('buy_orders_run_now', $buttonBlock);
135
+ //-------------------------------
136
+
137
+ //-------------------------------
138
+ $url = $this->getUrl(
139
+ '*/adminhtml_common_synchronization/clearLog',
140
+ array(
141
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_ORDERS,
142
+ 'component' => $this->component,
143
+ 'back' => $backUrl
144
+ )
145
+ );
146
+ $data = array(
147
+ 'label' => Mage::helper('M2ePro')->__('Clear Log'),
148
+ 'onclick' => 'deleteConfirm(\'' . $areYouSure . '\', \'' . $url . '\')',
149
+ 'class' => 'orders_clear_log'
150
+ );
151
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
152
+ $this->setChild('buy_orders_clear_log', $buttonBlock);
153
+ //-------------------------------
154
+
155
+ //-------------------------------
156
+ $url = $this->getUrl(
157
+ '*/adminhtml_common_log/synchronization',
158
+ array(
159
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_ORDERS,
160
+ 'channel' => $this->component,
161
+ )
162
+ );
163
+ $data = array(
164
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
165
+ 'onclick' => 'window.open(\'' . $url . '\')',
166
+ 'class' => 'button_link'
167
+ );
168
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
169
+ $this->setChild('buy_orders_view_log', $buttonBlock);
170
+ //-------------------------------
171
+
172
+ //-------------------------------
173
+ $data = array(
174
+ 'label' => Mage::helper('M2ePro')->__('Run Now'),
175
+ 'onclick' => 'SynchronizationHandlerObj.saveSettings(\'runNowOtherListings\',\''.$this->component.'\');',
176
+ 'class' => 'other_listings_run_now'
177
+ );
178
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
179
+ $this->setChild('buy_other_listings_run_now', $buttonBlock);
180
+ //-------------------------------
181
+
182
+ //-------------------------------
183
+ $url = $this->getUrl(
184
+ '*/adminhtml_common_synchronization/clearLog',
185
+ array(
186
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_OTHER_LISTINGS,
187
+ 'component' => $this->component,
188
+ 'back' => $backUrl
189
+ )
190
+ );
191
+ $data = array(
192
+ 'label' => Mage::helper('M2ePro')->__('Clear Log'),
193
+ 'onclick' => 'deleteConfirm(\'' . $areYouSure . '\', \'' . $url . '\')',
194
+ 'class' => 'orders_clear_log'
195
+ );
196
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
197
+ $this->setChild('buy_other_listings_clear_log', $buttonBlock);
198
+ //-------------------------------
199
+
200
+ //-------------------------------
201
+ $url = $this->getUrl(
202
+ '*/adminhtml_common_log/synchronization',
203
+ array(
204
+ 'task' => Ess_M2ePro_Model_Synchronization_Log::TASK_OTHER_LISTINGS,
205
+ 'channel' => $this->component,
206
+ )
207
+ );
208
+ $data = array(
209
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
210
+ 'onclick' => 'window.open(\'' . $url . '\')',
211
+ 'class' => 'button_link'
212
+ );
213
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
214
+ $this->setChild('buy_other_listings_view_log', $buttonBlock);
215
+ //-------------------------------
216
+
217
+ //-------------------------------
218
+ $this->inspectorMode = (int)Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
219
+ '/defaults/inspector/','mode'
220
+ );
221
+ //-------------------------------
222
+
223
+ return parent::_beforeToHtml();
224
+ }
225
+
226
+ // ####################################
227
+
228
+ public function isShowReviseAll()
229
+ {
230
+ return Mage::helper('M2ePro/Module')->getConfig()->getGroupValue(
231
+ '/view/synchronization/revise_total/','show'
232
+ );
233
+ }
234
+
235
+ // ####################################
236
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct extends Mage_Adminhtml_Block_Widget_Grid_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateNewProduct');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_buy_template_newProduct';
18
+ //------------------------------
19
+
20
+ // Set header text
21
+ //------------------------------
22
+ $this->_headerText = Mage::helper('M2ePro')->__('New SKU Policies For Rakuten.com (Beta)');
23
+ //------------------------------
24
+
25
+ // Set buttons actions
26
+ //------------------------------
27
+ $this->removeButton('back');
28
+ $this->removeButton('reset');
29
+ $this->removeButton('delete');
30
+ $this->removeButton('add');
31
+ $this->removeButton('save');
32
+ $this->removeButton('edit');
33
+
34
+ $listingProductIds = Mage::helper('M2ePro/Data_Session')->getValue('buy_listing_product_ids');
35
+
36
+ $listingId = Mage::helper('M2ePro/Component_Buy')
37
+ ->getObject('Listing_Product',reset($listingProductIds))
38
+ ->getListingId();
39
+
40
+ //------------------------------
41
+ $url = $this->getUrl(
42
+ '*/adminhtml_common_buy_listing/view',
43
+ array(
44
+ 'id' => $listingId
45
+ )
46
+ );
47
+ $this->_addButton('back', array(
48
+ 'label' => Mage::helper('M2ePro')->__('Back'),
49
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
50
+ 'class' => 'back'
51
+ ));
52
+ //------------------------------
53
+
54
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_template_newProduct');
55
+
56
+ //------------------------------
57
+ $url = $this->getUrl(
58
+ '*/adminhtml_common_buy_template_newProduct/add',
59
+ array(
60
+ 'back' => $backUrl
61
+ )
62
+ );
63
+ $this->_addButton('new', array(
64
+ 'label' => Mage::helper('M2ePro')->__('Add New SKU Policy'),
65
+ 'onclick' => 'setLocation(\''.$url.'\')',
66
+ 'class' => 'add'
67
+ ));
68
+ //------------------------------
69
+ }
70
+
71
+ public function getGridHtml()
72
+ {
73
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_template_newProduct_help');
74
+
75
+ return $helpBlock->toHtml() . parent::getGridHtml();
76
+ }
77
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateNewProductEdit');
16
+ $this->_blockGroup = 'M2ePro';
17
+ $this->_controller = 'adminhtml_common_buy_template_newProduct';
18
+ $this->_mode = 'edit';
19
+ //------------------------------
20
+
21
+ // Set header text
22
+ //------------------------------
23
+ $templateId = $this->getRequest()->getParam('id');
24
+
25
+ $this->_headerText = $templateId
26
+ ? Mage::helper('M2ePro')->__('Edit New SKU Policy For Rakuten.com (Beta)')
27
+ : Mage::helper('M2ePro')->__('Add New SKU Policy For Rakuten.com (Beta)');
28
+ //------------------------------
29
+
30
+ // Set buttons actions
31
+ //------------------------------
32
+ $this->removeButton('back');
33
+ $this->removeButton('reset');
34
+ $this->removeButton('delete');
35
+ $this->removeButton('add');
36
+ $this->removeButton('save');
37
+ $this->removeButton('edit');
38
+
39
+ $back = $this->getRequest()->getParam('back');
40
+ $buyListingProductIds = Mage::helper('M2ePro/Data_Session')->getValue('buy_listing_product_ids');
41
+ $listingProductId = $this->getRequest()->getParam('listing_product_id');
42
+
43
+ if ($back && ($buyListingProductIds || $listingProductId)) {
44
+ //------------------------------
45
+ $url = Mage::helper('M2ePro')->getBackUrl();
46
+ $this->_addButton('back', array(
47
+ 'label' => Mage::helper('M2ePro')->__('Back'),
48
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url .'\')',
49
+ 'class' => 'back'
50
+ ));
51
+ //------------------------------
52
+ }
53
+
54
+ //------------------------------
55
+ $params = array();
56
+ $listingProductId && $params['listing_product_id'] = $listingProductId;
57
+ $templateId && $params['id'] = $listingProductId;
58
+
59
+ $url = $this->getUrl('*/adminhtml_common_buy_template_newProduct/add', $params);
60
+ $this->_addButton('save', array(
61
+ 'label' => Mage::helper('M2ePro')->__('Save'),
62
+ 'onclick' => 'CommonHandlerObj.save_click(\''.$url.'\')',
63
+ 'class' => 'save'
64
+ ));
65
+ //------------------------------
66
+
67
+ $saveAndAssign = (int)$this->getRequest()->getParam('save_and_assign', 1);
68
+
69
+ if ($saveAndAssign && $buyListingProductIds) {
70
+ //------------------------------
71
+ $url = $this->getUrl(
72
+ '*/adminhtml_common_buy_template_newProduct/add',
73
+ array(
74
+ 'do_map' => true
75
+ )
76
+ );
77
+ $this->_addButton('save_and_map', array(
78
+ 'label' => Mage::helper('M2ePro')->__('Save And Assign'),
79
+ 'onclick' => 'CommonHandlerObj.save_click(\''.$url.'\')',
80
+ 'class' => 'save'
81
+ ));
82
+ //------------------------------
83
+ }
84
+ }
85
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Form.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateNewProductEditForm');
16
+ //------------------------------
17
+ }
18
+
19
+ protected function _prepareForm()
20
+ {
21
+ $form = new Varien_Data_Form(array(
22
+ 'id' => 'edit_form',
23
+ 'method' => 'post',
24
+ 'enctype' => 'multipart/form-data'
25
+ ));
26
+
27
+ $form->setUseContainer(true);
28
+ $this->setForm($form);
29
+
30
+ return parent::_prepareForm();
31
+ }
32
+
33
+ protected function _beforeToHtml()
34
+ {
35
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
36
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
37
+
38
+ $this->nodes = $connRead->select()
39
+ ->from(Mage::getSingleton('core/resource')->getTableName('m2epro_buy_dictionary_category'))
40
+ ->where('parent_category_id = ?', 0)
41
+ ->query()
42
+ ->fetchAll();
43
+
44
+ //------------------------------
45
+ $data = array(
46
+ 'id' => 'category_confirm_button',
47
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
48
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.confirmCategory();',
49
+ );
50
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
51
+ $this->setChild('category_confirm_button',$buttonBlock);
52
+ //------------------------------
53
+
54
+ //------------------------------
55
+ $data = array(
56
+ 'id' => 'category_change_button',
57
+ 'label' => Mage::helper('M2ePro')->__('Change Category'),
58
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.changeCategory();',
59
+ );
60
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
61
+ $this->setChild('category_change_button',$buttonBlock);
62
+ //------------------------------
63
+
64
+ return parent::_beforeToHtml();
65
+ }
66
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateNewProductEditTabs');
16
+ //------------------------------
17
+
18
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
19
+ $this->setDestElementId('edit_form');
20
+ }
21
+
22
+ protected function _beforeToHtml()
23
+ {
24
+ $this->addTab('general', array(
25
+ 'label' => Mage::helper('M2ePro')->__('General'),
26
+ 'title' => Mage::helper('M2ePro')->__('General'),
27
+ 'content' => $this->getLayout()->createBlock(
28
+ 'M2ePro/adminhtml_common_buy_template_newProduct_edit_tabs_general'
29
+ )->toHtml(),
30
+ ));
31
+
32
+ $this->addTab('core', array(
33
+ 'label' => Mage::helper('M2ePro')->__('Description'),
34
+ 'title' => Mage::helper('M2ePro')->__('Description'),
35
+ 'content' => $this->getLayout()->createBlock(
36
+ 'M2ePro/adminhtml_common_buy_template_newProduct_edit_tabs_description'
37
+ )->toHtml(),
38
+ ));
39
+
40
+ $this->addTab('attribute', array(
41
+ 'label' => Mage::helper('M2ePro')->__('Specifics'),
42
+ 'title' => Mage::helper('M2ePro')->__('Specifics'),
43
+ 'content' => $this->getLayout()->createBlock(
44
+ 'M2ePro/adminhtml_common_buy_template_newProduct_edit_tabs_attributes'
45
+ )->toHtml(),
46
+ ));
47
+
48
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
49
+
50
+ return parent::_beforeToHtml();
51
+ }
52
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Attributes.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Edit_Tabs_Attributes extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateNewProductEditTabsAttributes');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/template/newProduct/tabs/attributes.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Description.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Edit_Tabs_Description
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('buyTemplateNewProductEditTabsDescription');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/buy/template/newProduct/tabs/description.phtml');
20
+ }
21
+
22
+ protected function _beforeToHtml()
23
+ {
24
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getAll();
25
+
26
+ //------------------------------
27
+ $data = array(
28
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
29
+ 'onclick' => "AttributeHandlerObj.appendToText('select_attributes_for_title', 'title_template');",
30
+ 'class' => 'select_attributes_for_title_button'
31
+ );
32
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
33
+ $this->setChild('select_attributes_for_title_button',$buttonBlock);
34
+ //------------------------------
35
+
36
+ //------------------------------
37
+ $data = array(
38
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
39
+ 'onclick' => "AttributeHandlerObj.appendToText(".
40
+ "'select_attributes_for_mfg_name'," . " 'manufacturer_template'".
41
+ ");",
42
+ 'class' => 'select_attributes_for_mfg_name_template_button'
43
+ );
44
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
45
+ $this->setChild('select_attributes_for_mfg_name_template_button',$buttonBlock);
46
+ //------------------------------
47
+
48
+ //------------------------------
49
+ $data = array(
50
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
51
+ 'onclick' => "AttributeHandlerObj.appendToTextarea('#' + $('select_attributes').value + '#');",
52
+ 'class' => 'add_product_attribute_button',
53
+ );
54
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
55
+ $this->setChild('add_product_attribute_button',$buttonBlock);
56
+ //------------------------------
57
+
58
+ //------------------------------
59
+ for ($i = 0; $i < Ess_M2ePro_Model_Buy_Template_NewProduct_Core::FEATURES_COUNT; $i++) {
60
+ $data = array(
61
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
62
+ 'onclick' => "AttributeHandlerObj.appendToText('select_attributes_for_features_{$i}',"
63
+ . " 'features_{$i}');BuyTemplateNewProductHandlerObj.allowAddFeature(this);",
64
+ 'class' => "select_attributes_for_features_{$i}_button"
65
+ );
66
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
67
+ $this->setChild("select_attributes_for_features_{$i}_button",$buttonBlock);
68
+ }
69
+ //------------------------------
70
+
71
+ return parent::_beforeToHtml();
72
+ }
73
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/General.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Edit_Tabs_General extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateNewProductEditTabsGeneral');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/template/newProduct/tabs/general.phtml');
21
+ }
22
+
23
+ // ########################################
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
28
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
29
+
30
+ $this->nodes = $connRead->select()
31
+ ->from(Mage::getSingleton('core/resource')->getTableName('m2epro_buy_dictionary_category'))
32
+ ->where('parent_category_id = ?', 0)
33
+ ->query()
34
+ ->fetchAll();
35
+ !is_array($this->nodes) && $this->nodes = array();
36
+
37
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
38
+
39
+ //------------------------------
40
+ $data = array(
41
+ 'id' => 'category_confirm_button',
42
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
43
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.confirmCategory();',
44
+ );
45
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
46
+ $this->setChild('category_confirm_button',$buttonBlock);
47
+ //------------------------------
48
+
49
+ //------------------------------
50
+ $data = array(
51
+ 'id' => 'category_change_button',
52
+ 'label' => Mage::helper('M2ePro')->__('Change Category'),
53
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.changeCategory();',
54
+ );
55
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
56
+ $this->setChild('category_change_button',$buttonBlock);
57
+ //------------------------------
58
+
59
+ //------------------------------
60
+ $data = array(
61
+ 'id' => 'browse_category_button',
62
+ 'label' => Mage::helper('M2ePro')->__('Browse'),
63
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.browse_category.showCenter(true)'
64
+ );
65
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
66
+ $this->setChild('browse_category_button',$buttonBlock);
67
+ //------------------------------
68
+
69
+ //------------------------------
70
+ $data = array(
71
+ 'id' => 'search_category_button',
72
+ 'label' => Mage::helper('M2ePro')->__('Search By Keywords'),
73
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.search_category.showCenter(true)',
74
+ );
75
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
76
+ $this->setChild('search_category_button',$buttonBlock);
77
+ //------------------------------
78
+
79
+ //------------------------------
80
+ $data = array(
81
+ 'id' => 'search_category_popup_button',
82
+ 'label' => Mage::helper('M2ePro')->__('Search'),
83
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.searchClick()',
84
+ );
85
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
86
+ $this->setChild('search_category_popup_button',$buttonBlock);
87
+ //------------------------------
88
+
89
+ //------------------------------
90
+ $data = array(
91
+ 'id' => 'close_browse_popup_button',
92
+ 'label' => Mage::helper('M2ePro')->__('Close'),
93
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.closeBrowseCategoryPopup()',
94
+ );
95
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
96
+ $this->setChild('close_browse_popup_button',$buttonBlock);
97
+ //------------------------------
98
+
99
+ //------------------------------
100
+ $data = array(
101
+ 'id' => 'close_search_popup_button',
102
+ 'label' => Mage::helper('M2ePro')->__('Close'),
103
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.closeSearchCategoryPopup()',
104
+ );
105
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
106
+ $this->setChild('close_search_popup_button',$buttonBlock);
107
+ //------------------------------
108
+
109
+ return parent::_beforeToHtml();
110
+ }
111
+
112
+ // ########################################
113
+
114
+ public function isAllowedUpcExemption($formData)
115
+ {
116
+ $isAllowedUpcExemption = Ess_M2ePro_Model_Buy_Template_NewProduct::isAllowedUpcExemption();
117
+ $gtinMode = $formData['category']['gtin_mode'];
118
+ return $isAllowedUpcExemption || $gtinMode == Ess_M2ePro_Model_Buy_Template_NewProduct_Core::GTIN_MODE_NONE;
119
+ }
120
+
121
+ // ########################################
122
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Grid.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('templateNewProductGrid');
16
+ //------------------------------
17
+
18
+ // Set default values
19
+ //------------------------------
20
+ $this->setDefaultSort('id');
21
+ $this->setDefaultDir('ASC');
22
+ $this->setSaveParametersInSession(true);
23
+ $this->setUseAjax(true);
24
+ //------------------------------
25
+ }
26
+
27
+ protected function _prepareCollection()
28
+ {
29
+ $collection = Mage::getModel('M2ePro/Buy_Template_NewProduct')->getCollection();
30
+ $this->setCollection($collection);
31
+ return parent::_prepareCollection();
32
+ }
33
+
34
+ protected function _prepareColumns()
35
+ {
36
+ $this->addColumn('id', array(
37
+ 'header' => Mage::helper('M2ePro')->__('ID'),
38
+ 'align' => 'right',
39
+ 'type' => 'number',
40
+ 'width' => '50px',
41
+ 'index' => 'id',
42
+ 'filter_index' => 'id',
43
+ 'frame_callback' => array($this, 'callbackColumnId')
44
+ ));
45
+
46
+ $this->addColumn('title', array(
47
+ 'header' => Mage::helper('M2ePro')->__('Title'),
48
+ 'align' => 'left',
49
+ 'type' => 'text',
50
+ 'width' => '100px',
51
+ 'index' => 'title',
52
+ 'filter_index' => 'title',
53
+ 'frame_callback' => array($this, 'callbackColumnTitle')
54
+ ));
55
+
56
+ $this->addColumn('node_title', array(
57
+ 'header' => Mage::helper('M2ePro')->__('Department'),
58
+ 'align' => 'left',
59
+ 'type' => 'text',
60
+ 'width' => '100px',
61
+ 'index' => 'node_title',
62
+ 'filter_index' => 'node_title',
63
+ 'frame_callback' => array($this, 'callbackColumnNodeTitle')
64
+ ));
65
+
66
+ $this->addColumn('category_path', array(
67
+ 'header' => Mage::helper('M2ePro')->__('Category'),
68
+ 'align' => 'left',
69
+ 'type' => 'text',
70
+ 'width' => '350px',
71
+ 'index' => 'category_path',
72
+ 'filter_index' => 'category_path',
73
+ 'frame_callback' => array($this, 'callbackColumnCategoryPath')
74
+ ));
75
+
76
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_template_newProduct');
77
+
78
+ $this->addColumn('assignment', array(
79
+ 'header' => Mage::helper('M2ePro')->__('Assignment'),
80
+ 'align' => 'left',
81
+ 'type' => 'text',
82
+ 'width' => '130px',
83
+ 'filter' => false,
84
+ 'sortable' => false,
85
+ 'frame_callback' => array($this, 'callbackColumnActions'),
86
+ ));
87
+
88
+ $this->addColumn('actions', array(
89
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
90
+ 'align' => 'left',
91
+ 'width' => '100px',
92
+ 'type' => 'action',
93
+ 'index' => 'actions',
94
+ 'filter' => false,
95
+ 'sortable' => false,
96
+ 'getter' => 'getId',
97
+ 'actions' => array(
98
+ array(
99
+ 'caption' => Mage::helper('M2ePro')->__('Edit'),
100
+ 'url' => array('base'=> '*/adminhtml_common_buy_template_newProduct/edit/back/'.$back),
101
+ 'field' => 'id'
102
+ ),
103
+ array(
104
+ 'caption' => Mage::helper('M2ePro')->__('Delete Policy'),
105
+ 'url' => array('base'=> '*/adminhtml_common_buy_template_newProduct/delete/back/'
106
+ .$this->getRequest()->getParam('back')),
107
+ 'field' => 'ids',
108
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
109
+ ),
110
+ )
111
+ ));
112
+ }
113
+
114
+ // ####################################
115
+
116
+ protected function _prepareMassaction()
117
+ {
118
+ // Set massaction identifiers
119
+ //--------------------------------
120
+ $this->setMassactionIdField('id');
121
+ $this->getMassactionBlock()->setFormFieldName('ids');
122
+ //--------------------------------
123
+
124
+ // Set delete action
125
+ //--------------------------------
126
+ $this->getMassactionBlock()->addItem('delete', array(
127
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
128
+ 'url' => $this->getUrl('*/*/delete'),
129
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
130
+ ));
131
+ //--------------------------------
132
+
133
+ return parent::_prepareMassaction();
134
+ }
135
+
136
+ // ####################################
137
+
138
+ public function callbackColumnId($value, $row, $column, $isExport)
139
+ {
140
+ return $value.'&nbsp;';
141
+ }
142
+
143
+ public function callbackColumnTitle($value, $row, $column, $isExport)
144
+ {
145
+ return '&nbsp'.$value;
146
+ }
147
+
148
+ public function callbackColumnNodeTitle($value, $row, $column, $isExport)
149
+ {
150
+ return '&nbsp'.$value;
151
+ }
152
+
153
+ public function callbackColumnCategoryPath($value, $row, $column, $isExport)
154
+ {
155
+ return '&nbsp;'.$value;
156
+ }
157
+
158
+ public function callbackColumnActions($value, $row, $column, $isExport)
159
+ {
160
+ $url = $this->getUrl(
161
+ '*/adminhtml_common_buy_template_newProduct/map/',
162
+ array(
163
+ 'id' => $row->getId(),
164
+ )
165
+ );
166
+
167
+ $confirmMessage = Mage::helper('M2ePro')->__('Are you sure?');
168
+ $actions = '&nbsp;<a href="javascript:;" onclick="confirm(\''.$confirmMessage.'\') && ';
169
+ $actions .= 'setLocation(\''.$url.'\');">';
170
+ $actions .= Mage::helper('M2ePro')->__('Assign To This Policy');
171
+ $actions .= '</a>';
172
+
173
+ return $actions;
174
+ }
175
+
176
+ // ####################################
177
+
178
+ public function getGridUrl()
179
+ {
180
+ return $this->getUrl('*/adminhtml_common_buy_template_newProduct/templateNewProductGrid',
181
+ array('_current'=>true));
182
+ }
183
+
184
+ public function getRowUrl($row)
185
+ {
186
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_template_newProduct');
187
+
188
+ return $this->getUrl('*/adminhtml_common_buy_template_newProduct/edit', array(
189
+ 'id' => $row->getId(),
190
+ 'back' => $back
191
+ ));
192
+ }
193
+
194
+ // ####################################
195
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateNewProductHelp');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/template/newProduct/help.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Search/Grid.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_NewProduct_Search_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateNewProductSearchGrid');
16
+ //------------------------------
17
+
18
+ // Set default values
19
+ //------------------------------
20
+ $this->setFilterVisibility(false);
21
+ $this->setPagerVisibility(false);
22
+ $this->setDefaultSort('id');
23
+ $this->setDefaultDir('ASC');
24
+ $this->setSaveParametersInSession(true);
25
+ $this->setUseAjax(true);
26
+ //------------------------------
27
+ }
28
+
29
+ protected function _prepareCollection()
30
+ {
31
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
32
+
33
+ $results = new Varien_Data_Collection();
34
+ foreach ($data as $index => $item) {
35
+ $temp = array(
36
+ 'id' => $item['category_id'],
37
+ 'title' => $item['title'],
38
+ 'path' => $item['path'],
39
+ 'node_id' => $item['node_id'],
40
+ 'native_id' => $item['native_id']
41
+ );
42
+
43
+ $results->addItem(new Varien_Object($temp));
44
+ }
45
+
46
+ $this->setCollection($results);
47
+
48
+ return parent::_prepareCollection();
49
+ }
50
+
51
+ protected function _prepareColumns()
52
+ {
53
+ $this->addColumn('title', array(
54
+ 'header' => Mage::helper('M2ePro')->__('Category'),
55
+ 'align' => 'left',
56
+ 'type' => 'text',
57
+ 'index' => 'title',
58
+ 'filter' => false,
59
+ 'sortable' => false,
60
+ 'frame_callback' => array($this, 'callbackColumnTitle')
61
+ ));
62
+
63
+ $this->addColumn('actions', array(
64
+ 'header' => Mage::helper('M2ePro')->__('Action'),
65
+ 'align' => 'center',
66
+ 'type' => 'text',
67
+ 'width' => '80px',
68
+ 'filter' => false,
69
+ 'sortable' => false,
70
+ 'frame_callback' => array($this, 'callbackColumnActions'),
71
+ ));
72
+
73
+ }
74
+
75
+ // ####################################
76
+
77
+ public function callbackColumnTitle($title, $row, $column, $isExport)
78
+ {
79
+ $categoryInfo = json_encode($row->getData());
80
+ $categoryInfo = Mage::helper('M2ePro')->escapeHtml($categoryInfo);
81
+ $categoryInfo = Mage::helper('M2ePro')->escapeJs($categoryInfo);
82
+
83
+ $path = $row->getData('path');
84
+ (strlen($path) != strlen($title)) && $path = substr($path,0,strlen($path) - strlen($title)-2);
85
+ $path = str_replace('->',' > ',$path);
86
+
87
+ $title = Mage::helper('M2ePro')->escapeHtml($title);
88
+ if (strlen($title) > 60) {
89
+ $title = substr($title, 0, 60) . '...';
90
+ }
91
+ $foundIn = Mage::helper('M2ePro')->__('Found In: ');
92
+
93
+ $fullPath = $path;
94
+ if (strlen($path) > 135) {
95
+ $path = substr($path, 0, 135) . '...';
96
+ }
97
+
98
+ $html = <<<HTML
99
+ <div style="margin-left: 3px">
100
+ <a href="javascript:;" onclick="BuyTemplateNewProductHandlerObj.confirmSearchClick($categoryInfo)">$title</a>
101
+ <br/>
102
+ <span style="font-weight: bold;">$foundIn</span>
103
+ &nbsp;
104
+ <span title="$fullPath">$path</span><br/>
105
+ </div>
106
+ HTML;
107
+
108
+ return $html;
109
+ }
110
+
111
+ public function callbackColumnActions($value, $row, $column, $isExport)
112
+ {
113
+ $categoryInfo = json_encode($row->getData());
114
+ $categoryInfo = Mage::helper('M2ePro')->escapeHtml($categoryInfo);
115
+ $categoryInfo = Mage::helper('M2ePro')->escapeJs($categoryInfo);
116
+
117
+ $select = Mage::helper('M2ePro')->__('Select');
118
+ $html = <<<HTML
119
+ <a href="javascript:;" onclick="BuyTemplateNewProductHandlerObj.confirmSearchClick($categoryInfo)">$select</a>
120
+ HTML;
121
+
122
+ return $html;
123
+ }
124
+
125
+ // ####################################
126
+
127
+ protected function _toHtml()
128
+ {
129
+ $javascriptsMain = <<<JAVASCRIPT
130
+ <script type="text/javascript">
131
+
132
+ $$('#buyTemplateNewProductSearchGrid div.grid th').each(function(el){
133
+ el.style.padding = '2px 2px';
134
+ });
135
+
136
+ $$('#buyTemplateNewProductSearchGrid div.grid td').each(function(el){
137
+ el.style.padding = '2px 2px';
138
+ });
139
+
140
+ $$('#buyTemplateNewProductSearchGrid div.grid table').each(function(el){
141
+ el.style.width = '99.9%';
142
+ });
143
+
144
+ </script>
145
+ JAVASCRIPT;
146
+
147
+ return parent::_toHtml() . $javascriptsMain;
148
+ }
149
+
150
+ // ####################################
151
+
152
+ public function getRowUrl($row)
153
+ {
154
+ return false;
155
+ }
156
+
157
+ // ####################################
158
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_SellingFormat_Edit
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('buyTemplateSellingFormatEdit');
17
+ $this->_blockGroup = 'M2ePro';
18
+ $this->_controller = 'adminhtml_common_buy_template_sellingFormat';
19
+ $this->_mode = 'edit';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $helper = Mage::helper('M2ePro');
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
27
+ $headerTextEdit = $helper->__("Edit %component_name% Selling Format Policy", $componentName);
28
+ $headerTextAdd = $helper->__("Add %component_name% Selling Format Policy", $componentName);
29
+ } else {
30
+ $headerTextEdit = $helper->__("Edit Selling Format Policy");
31
+ $headerTextAdd = $helper->__("Add Selling Format Policy");
32
+ }
33
+
34
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
35
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
36
+ ) {
37
+ $this->_headerText = $headerTextEdit;
38
+ $this->_headerText .= ' "'.$this->escapeHtml(
39
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
40
+ } else {
41
+ $this->_headerText = $headerTextAdd;
42
+ }
43
+ //------------------------------
44
+
45
+ // Set buttons actions
46
+ //------------------------------
47
+ $this->removeButton('back');
48
+ $this->removeButton('reset');
49
+ $this->removeButton('delete');
50
+ $this->removeButton('add');
51
+ $this->removeButton('save');
52
+ $this->removeButton('edit');
53
+ //------------------------------
54
+
55
+ //------------------------------
56
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
57
+ $this->_addButton('back', array(
58
+ 'label' => Mage::helper('M2ePro')->__('Back'),
59
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.back_click(\'' . $url . '\')',
60
+ 'class' => 'back'
61
+ ));
62
+ //------------------------------
63
+
64
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
65
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
66
+ ) {
67
+ //------------------------------
68
+ $this->_addButton('duplicate', array(
69
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
70
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.duplicate_click'
71
+ .'(\'common-buy-template-sellingFormat\')',
72
+ 'class' => 'add M2ePro_duplicate_button'
73
+ ));
74
+ //------------------------------
75
+
76
+ //------------------------------
77
+ $this->_addButton('delete', array(
78
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
79
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.delete_click()',
80
+ 'class' => 'delete M2ePro_delete_button'
81
+ ));
82
+ //------------------------------
83
+ }
84
+
85
+ //------------------------------
86
+ $this->_addButton('save', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Save'),
88
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.save_click()',
89
+ 'class' => 'save'
90
+ ));
91
+ //------------------------------
92
+
93
+ //------------------------------
94
+ $this->_addButton('save_and_continue', array(
95
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
96
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.save_and_edit_click()',
97
+ 'class' => 'save'
98
+ ));
99
+ //------------------------------
100
+ }
101
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit/Form.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_SellingFormat_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ const QTY_MODE_PRODUCT_FIXED_VIRTUAL_ATTRIBUTE_VALUE = 'qty_mode_product_fixed';
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateSellingFormatEditForm');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/template/selling_format/form.phtml');
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/*/save'),
28
+ 'method' => 'post',
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ protected function _beforeToHtml()
39
+ {
40
+ //------------------------------
41
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
42
+ //------------------------------
43
+
44
+ //------------------------------
45
+ $this->customerGroups = Mage::getModel('customer/group')->getCollection()->toOptionArray();
46
+ //------------------------------
47
+
48
+ return parent::_beforeToHtml();
49
+ }
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_Synchronization_Edit
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('buyTemplateSynchronizationEdit');
17
+ $this->_blockGroup = 'M2ePro';
18
+ $this->_controller = 'adminhtml_common_buy_template_synchronization';
19
+ $this->_mode = 'edit';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $helper = Mage::helper('M2ePro');
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
27
+ $headerTextEdit = $helper->__("Edit %component_name% Synchronization Policy", $componentName);
28
+ $headerTextAdd = $helper->__("Add %component_name% Synchronization Policy", $componentName);
29
+ } else {
30
+ $headerTextEdit = $helper->__("Edit Synchronization Policy");
31
+ $headerTextAdd = $helper->__("Add Synchronization Policy");
32
+ }
33
+
34
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
35
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
36
+ ) {
37
+ $this->_headerText = $headerTextEdit;
38
+ $this->_headerText .= ' "'.$this->escapeHtml(
39
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
40
+ } else {
41
+ $this->_headerText = $headerTextAdd;
42
+ }
43
+ //------------------------------
44
+
45
+ // Set buttons actions
46
+ //------------------------------
47
+ $this->removeButton('back');
48
+ $this->removeButton('reset');
49
+ $this->removeButton('delete');
50
+ $this->removeButton('add');
51
+ $this->removeButton('save');
52
+ $this->removeButton('edit');
53
+ //------------------------------
54
+
55
+ //------------------------------
56
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
57
+ $this->_addButton('back', array(
58
+ 'label' => Mage::helper('M2ePro')->__('Back'),
59
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.back_click(\'' . $url . '\')',
60
+ 'class' => 'back'
61
+ ));
62
+ //------------------------------
63
+
64
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
65
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
66
+ ) {
67
+ //------------------------------
68
+ $this->_addButton('duplicate', array(
69
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
70
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.duplicate_click'
71
+ .'(\'common-buy-template-synchronization\')',
72
+ 'class' => 'add M2ePro_duplicate_button'
73
+ ));
74
+ //------------------------------
75
+
76
+ //------------------------------
77
+ $this->_addButton('delete', array(
78
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
79
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.delete_click()',
80
+ 'class' => 'delete M2ePro_delete_button'
81
+ ));
82
+ //------------------------------
83
+ }
84
+
85
+ //------------------------------
86
+ $this->_addButton('save', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Save'),
88
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.save_click()',
89
+ 'class' => 'save'
90
+ ));
91
+ //------------------------------
92
+
93
+ //------------------------------
94
+ $this->_addButton('save_and_continue', array(
95
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
96
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.save_and_edit_click'
97
+ .'(\'\',\'buyTemplateSynchronizationEditTabs\')',
98
+ 'class' => 'save'
99
+ ));
100
+ //------------------------------
101
+ }
102
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Form.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_Synchronization_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateSynchronizationEditForm');
16
+ //------------------------------
17
+ }
18
+
19
+ protected function _prepareForm()
20
+ {
21
+ $form = new Varien_Data_Form(array(
22
+ 'id' => 'edit_form',
23
+ 'action' => $this->getUrl('*/*/save'),
24
+ 'method' => 'post',
25
+ 'enctype' => 'multipart/form-data'
26
+ ));
27
+
28
+ $form->setUseContainer(true);
29
+ $this->setForm($form);
30
+
31
+ return parent::_prepareForm();
32
+ }
33
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_Synchronization_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateSynchronizationEditTabs');
16
+ //------------------------------
17
+
18
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
19
+ $this->setDestElementId('edit_form');
20
+ }
21
+
22
+ protected function _beforeToHtml()
23
+ {
24
+ $this->addTab('list', array(
25
+ 'label' => Mage::helper('M2ePro')->__('List Rules'),
26
+ 'title' => Mage::helper('M2ePro')->__('List Rules'),
27
+ 'content' => $this->getLayout()
28
+ ->createBlock('M2ePro/adminhtml_common_buy_template_synchronization_edit_tabs_list')
29
+ ->toHtml(),
30
+ ))
31
+ ->addTab('revise', array(
32
+ 'label' => Mage::helper('M2ePro')->__('Revise Rules'),
33
+ 'title' => Mage::helper('M2ePro')->__('Revise Rules'),
34
+ 'content' => $this->getLayout()
35
+ ->createBlock('M2ePro/adminhtml_common_buy_template_synchronization_edit_tabs_revise')
36
+ ->toHtml(),
37
+ ))
38
+ ->addTab('relist', array(
39
+ 'label' => Mage::helper('M2ePro')->__('Relist Rules'),
40
+ 'title' => Mage::helper('M2ePro')->__('Relist Rules'),
41
+ 'content' => $this->getLayout()
42
+ ->createBlock('M2ePro/adminhtml_common_buy_template_synchronization_edit_tabs_relist')
43
+ ->toHtml(),
44
+ ))
45
+ ->addTab('stop', array(
46
+ 'label' => Mage::helper('M2ePro')->__('Stop Rules'),
47
+ 'title' => Mage::helper('M2ePro')->__('Stop Rules'),
48
+ 'content' => $this->getLayout()
49
+ ->createBlock('M2ePro/adminhtml_common_buy_template_synchronization_edit_tabs_stop')
50
+ ->toHtml(),
51
+ ))
52
+ ->setActiveTab($this->getRequest()->getParam('tab', 'list'));
53
+
54
+ return parent::_beforeToHtml();
55
+ }
56
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/List.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_Synchronization_Edit_Tabs_List extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateSynchronizationEditTabsList');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/list.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Relist.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_Synchronization_Edit_Tabs_Relist
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('buyTemplateSynchronizationEditTabsRelist');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/relist.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Revise.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_Synchronization_Edit_Tabs_Revise
8
+ extends Mage_Adminhtml_Block_Widget
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ // Initialization block
15
+ //------------------------------
16
+ $this->setId('buyTemplateSynchronizationEditTabsRevise');
17
+ //------------------------------
18
+
19
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/revise.phtml');
20
+ }
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Stop.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template_Synchronization_Edit_Tabs_Stop extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('buyTemplateSynchronizationEditTabsStop');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/stop.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Abstract.php ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ abstract class Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ // ########################################
10
+
11
+ const TAB_ID_AMAZON = 'amazon';
12
+ const TAB_ID_BUY = 'buy';
13
+ const TAB_ID_PLAY = 'play';
14
+
15
+ // ########################################
16
+
17
+ protected $tabs = array();
18
+
19
+ protected $enabledTab = NULL;
20
+
21
+ protected $tabsContainerBlock = NULL;
22
+
23
+ protected $tabsContainerId = 'components_container';
24
+
25
+ protected $useAjax = false;
26
+
27
+ protected $tabsAjaxUrls = array();
28
+
29
+ // ########################################
30
+
31
+ static public function getTabIdByComponent($component)
32
+ {
33
+ $tabId = null;
34
+
35
+ switch ($component) {
36
+ case Ess_M2ePro_Helper_Component_Amazon::NICK:
37
+ $tabId = self::TAB_ID_AMAZON;
38
+ break;
39
+ case Ess_M2ePro_Helper_Component_Buy::NICK:
40
+ $tabId = self::TAB_ID_BUY;
41
+ break;
42
+ case Ess_M2ePro_Helper_Component_Play::NICK:
43
+ $tabId = self::TAB_ID_PLAY;
44
+ break;
45
+ }
46
+
47
+ return $tabId;
48
+ }
49
+
50
+ // ########################################
51
+
52
+ public function enableAmazonTab()
53
+ {
54
+ $this->setEnabledTab(self::TAB_ID_AMAZON);
55
+ }
56
+
57
+ public function enableBuyTab()
58
+ {
59
+ $this->setEnabledTab(self::TAB_ID_BUY);
60
+ }
61
+
62
+ public function enablePlayTab()
63
+ {
64
+ $this->setEnabledTab(self::TAB_ID_PLAY);
65
+ }
66
+
67
+ // ########################################
68
+
69
+ public function setEnabledTab($id)
70
+ {
71
+ $this->enabledTab = $id;
72
+ }
73
+
74
+ // ----------------------------------------
75
+
76
+ protected function isTabEnabled($id)
77
+ {
78
+ if (is_null($this->enabledTab)) {
79
+ return true;
80
+ }
81
+
82
+ return $id == $this->enabledTab;
83
+ }
84
+
85
+ // ----------------------------------------
86
+
87
+ protected function canUseAjax()
88
+ {
89
+ if (count($this->tabs) < 2) {
90
+ return false;
91
+ }
92
+
93
+ return $this->useAjax;
94
+ }
95
+
96
+ // ########################################
97
+
98
+ protected function initializeTabs()
99
+ {
100
+ $this->initializeAmazon();
101
+ $this->initializeBuy();
102
+ $this->initializePlay();
103
+ }
104
+
105
+ protected function initializeTab($id)
106
+ {
107
+ if ($this->isTabEnabled($id) && !in_array($id, $this->tabs)) {
108
+ $this->tabs[] = $id;
109
+ }
110
+ }
111
+
112
+ protected function initializeAmazon()
113
+ {
114
+ if (Mage::helper('M2ePro/Component_Amazon')->isActive()) {
115
+ $this->initializeTab(self::TAB_ID_AMAZON);
116
+ }
117
+ }
118
+
119
+ protected function initializeBuy()
120
+ {
121
+ if (Mage::helper('M2ePro/Component_Buy')->isActive()) {
122
+ $this->initializeTab(self::TAB_ID_BUY);
123
+ }
124
+ }
125
+
126
+ protected function initializePlay()
127
+ {
128
+ if (Mage::helper('M2ePro/Component_Play')->isActive()) {
129
+ $this->initializeTab(self::TAB_ID_PLAY);
130
+ }
131
+ }
132
+
133
+ // ########################################
134
+
135
+ protected function getTabBlockById($id)
136
+ {
137
+ $id = ucfirst($id);
138
+ $method = "get{$id}TabBlock";
139
+
140
+ if (method_exists($this, $method)) {
141
+ return $this->$method();
142
+ }
143
+
144
+ return NULL;
145
+ }
146
+
147
+ protected function getTabHtmlById($id)
148
+ {
149
+ $id = ucfirst($id);
150
+ $method = "get{$id}TabHtml";
151
+
152
+ if (method_exists($this, $method)) {
153
+ return $this->$method();
154
+ }
155
+
156
+ return '';
157
+ }
158
+
159
+ protected function getTabLabelById($id)
160
+ {
161
+ $id = ucfirst($id);
162
+ $label = @constant("Ess_M2ePro_Helper_Component_{$id}::TITLE");
163
+
164
+ return $label ? Mage::helper('M2ePro')->__($label) : Mage::helper('M2ePro')->__('N/A');
165
+ }
166
+
167
+ protected function getTabUrlById($id)
168
+ {
169
+ return isset($this->tabsAjaxUrls[$id]) ? $this->tabsAjaxUrls[$id] : '';
170
+ }
171
+
172
+ // ########################################
173
+
174
+ protected function _prepareLayout()
175
+ {
176
+ if (count(Mage::helper('M2ePro/View_Common_Component')->getActiveComponents()) == 0) {
177
+ throw new LogicException('At least 1 channel should be enabled.');
178
+ }
179
+
180
+ $this->initializeTabs();
181
+
182
+ parent::_prepareLayout();
183
+ }
184
+
185
+ // ########################################
186
+
187
+ protected function _toHtml()
188
+ {
189
+ return parent::_toHtml() . $this->_componentsToHtml();
190
+ }
191
+
192
+ protected function _componentsToHtml()
193
+ {
194
+ $tabsCount = count($this->tabs);
195
+
196
+ if ($tabsCount <= 0) {
197
+ return '';
198
+ }
199
+
200
+ if ($tabsCount == 1) {
201
+ $tabId = reset($this->tabs);
202
+
203
+ return $this->getTabHtmlById($tabId);
204
+ }
205
+
206
+ $tabsContainer = $this->getTabsContainerBlock();
207
+ $tabsContainer->setDestElementId($this->tabsContainerId);
208
+
209
+ foreach ($this->tabs as $tabId) {
210
+ $tab = $this->prepareTabById($tabId);
211
+ $tabsContainer->addTab($tabId, $tab);
212
+ }
213
+
214
+ $tabsContainer->setActiveTab($this->getActiveTab());
215
+
216
+ return $tabsContainer->toHtml() . $this->getTabsContainerDestinationHtml();
217
+ }
218
+
219
+ // ########################################
220
+
221
+ protected function prepareTabById($id)
222
+ {
223
+ $label = $this->getTabLabelById($id);
224
+
225
+ $tab = array(
226
+ 'label' => $label,
227
+ 'title' => $label
228
+ );
229
+
230
+ if ($this->canUseAjax() && $this->getActiveTab() != $id) {
231
+ $tab['class'] = 'ajax';
232
+ $tab['url'] = $this->getTabUrlById($id);
233
+ } else {
234
+ $tab['content'] = $this->getTabHtmlById($id);
235
+ }
236
+
237
+ return $tab;
238
+ }
239
+
240
+ // ########################################
241
+
242
+ protected function getSingleBlock()
243
+ {
244
+ if (count($this->tabs) != 1) {
245
+ return NULL;
246
+ }
247
+
248
+ $tabId = reset($this->tabs);
249
+
250
+ return $this->getTabBlockById($tabId);
251
+ }
252
+
253
+ // ########################################
254
+
255
+ /**
256
+ * @abstract
257
+ * @return Mage_Core_Block_Abstract
258
+ */
259
+ abstract protected function getAmazonTabBlock();
260
+
261
+ public function getAmazonTabHtml()
262
+ {
263
+ return $this->getAmazonTabBlock()->toHtml();
264
+ }
265
+
266
+ /**
267
+ * @abstract
268
+ * @return Mage_Core_Block_Abstract
269
+ */
270
+ abstract protected function getBuyTabBlock();
271
+
272
+ public function getBuyTabHtml()
273
+ {
274
+ return $this->getBuyTabBlock()->toHtml();
275
+ }
276
+
277
+ /**
278
+ * @abstract
279
+ * @return Mage_Core_Block_Abstract
280
+ */
281
+ abstract protected function getPlayTabBlock();
282
+
283
+ public function getPlayTabHtml()
284
+ {
285
+ return $this->getPlayTabBlock()->toHtml();
286
+ }
287
+
288
+ // ########################################
289
+
290
+ /**
291
+ * @return Ess_M2ePro_Block_Adminhtml_Common_Component_Tabs
292
+ */
293
+ protected function getTabsContainerBlock()
294
+ {
295
+ if (is_null($this->tabsContainerBlock)) {
296
+ $this->tabsContainerBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_component_tabs');
297
+ }
298
+
299
+ return $this->tabsContainerBlock;
300
+ }
301
+
302
+ protected function getTabsContainerDestinationHtml()
303
+ {
304
+ return '<div id="'.$this->tabsContainerId.'"></div>';
305
+ }
306
+
307
+ // ########################################
308
+
309
+ protected function getActiveTab()
310
+ {
311
+ $activeTab = $this->getRequest()->getParam('tab');
312
+ if (is_null($activeTab)) {
313
+ Mage::helper('M2ePro/View_Common_Component')->isAmazonDefault() && $activeTab = self::TAB_ID_AMAZON;
314
+ Mage::helper('M2ePro/View_Common_Component')->isBuyDefault() && $activeTab = self::TAB_ID_BUY;
315
+ Mage::helper('M2ePro/View_Common_Component')->isPlayDefault() && $activeTab = self::TAB_ID_PLAY;
316
+ }
317
+
318
+ return $activeTab;
319
+ }
320
+
321
+ // ########################################
322
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Grid/Container.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ abstract class Ess_M2ePro_Block_Adminhtml_Common_Component_Grid_Container
8
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ // ########################################
11
+
12
+ abstract protected function getAmazonNewUrl();
13
+
14
+ abstract protected function getBuyNewUrl();
15
+
16
+ abstract protected function getPlayNewUrl();
17
+
18
+ // ########################################
19
+
20
+ protected function getAddButtonOnClickAction()
21
+ {
22
+ $components = Mage::helper('M2ePro/View_Common_Component')->getActiveComponents();
23
+ $action = '';
24
+
25
+ if (count($components) == 1) {
26
+ $component = reset($components);
27
+ $action = 'setLocation(\''.$this->getNewUrl($component).'\');';
28
+ }
29
+
30
+ return $action;
31
+ }
32
+
33
+ // ########################################
34
+
35
+ protected function _toHtml()
36
+ {
37
+ return $this->getAddButtonJavascript() . parent::_toHtml();
38
+ }
39
+
40
+ // ----------------------------------------
41
+
42
+ protected function getAddButtonJavascript()
43
+ {
44
+ if (count(Mage::helper('M2ePro/View_Common_Component')->getActiveComponents()) < 2) {
45
+ return '';
46
+ }
47
+
48
+ $data = array(
49
+ 'target_css_class' => 'add-button-drop-down',
50
+ 'items' => $this->getAddButtonDropDownItems()
51
+ );
52
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
53
+ $dropDownBlock->setData($data);
54
+
55
+ return $dropDownBlock->toHtml();
56
+ }
57
+
58
+ protected function getAddButtonDropDownItems()
59
+ {
60
+ $items = array();
61
+
62
+ $activeComponents = Mage::helper('M2ePro/View_Common_Component')->getActiveComponentsTitles();
63
+
64
+ //------------------------------
65
+ foreach ($activeComponents as $component => $title) {
66
+ $items[] = array(
67
+ 'url' => $this->getNewUrl($component),
68
+ 'label' => $title
69
+ );
70
+ }
71
+ //------------------------------
72
+
73
+ return $items;
74
+ }
75
+
76
+ // ########################################
77
+
78
+ protected function getNewUrl($component)
79
+ {
80
+ $component = ucfirst(strtolower($component));
81
+ $method = "get{$component}NewUrl";
82
+
83
+ if (!method_exists($this, $method)) {
84
+ throw new Exception('Method of adding a new entity is not defined.');
85
+ }
86
+
87
+ return $this->$method();
88
+ }
89
+
90
+ // ########################################
91
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Tabs.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Component_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+ $this->setTemplate('widget/tabshoriz.phtml');
15
+ }
16
+
17
+ // ########################################
18
+
19
+ public function addTabAfterAmazon($tabId, $tab)
20
+ {
21
+ return $this->addTabAfter($tabId, $tab, Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON);
22
+ }
23
+
24
+ public function addTabAfterBuy($tabId, $tab)
25
+ {
26
+ return $this->addTabAfter($tabId, $tab, Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY);
27
+ }
28
+
29
+ public function addTabAfterPlay($tabId, $tab)
30
+ {
31
+ return $this->addTabAfter($tabId, $tab, Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_PLAY);
32
+ }
33
+
34
+ // ########################################
35
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Tabs/Container.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ abstract class Ess_M2ePro_Block_Adminhtml_Common_Component_Tabs_Container
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract
9
+ {
10
+ // ########################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+ $this->setTemplate('M2ePro/common/component/container.phtml');
16
+ }
17
+
18
+ // ########################################
19
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing.php ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing extends Ess_M2ePro_Block_Adminhtml_Common_Component_Tabs_Container
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Set header text
16
+ //------------------------------
17
+ $this->_headerText = Mage::helper('M2ePro')->__('Listings');
18
+ //------------------------------
19
+
20
+ //------------------------------
21
+ if (!is_null($this->getRequest()->getParam('back'))) {
22
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_listing/index');
23
+ $this->_addButton('back', array(
24
+ 'label' => Mage::helper('M2ePro')->__('Back'),
25
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
26
+ 'class' => 'back'
27
+ ));
28
+ }
29
+ //------------------------------
30
+
31
+ //------------------------------
32
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_listing/index');
33
+ //------------------------------
34
+
35
+ //------------------------------
36
+ $url = $this->getUrl('*/adminhtml_common_listing/search', array('back' => $backUrl));
37
+ $this->_addButton('search_products', array(
38
+ 'label' => Mage::helper('M2ePro')->__('Search'),
39
+ 'onclick' => 'setLocation(\'' . $url . '\')',
40
+ 'class' => 'button_link search'
41
+ ));
42
+ //------------------------------
43
+
44
+ //------------------------------
45
+ $this->useAjax = true;
46
+ $this->tabsAjaxUrls = array(
47
+ self::TAB_ID_AMAZON => $this->getUrl('*/adminhtml_common_amazon_listing/index'),
48
+ self::TAB_ID_BUY => $this->getUrl('*/adminhtml_common_buy_listing/index'),
49
+ self::TAB_ID_PLAY => $this->getUrl('*/adminhtml_common_play_listing/index'),
50
+ );
51
+ //------------------------------
52
+ }
53
+
54
+ // ########################################
55
+
56
+ protected function getTabsContainerBlock()
57
+ {
58
+ return parent::getTabsContainerBlock()->setId('listing');
59
+ }
60
+
61
+ // ########################################
62
+
63
+ protected function _toHtml()
64
+ {
65
+ $urls = json_encode(array(
66
+ 'adminhtml_common_listing/saveTitle' => Mage::helper('adminhtml')
67
+ ->getUrl('M2ePro/adminhtml_common_listing/saveTitle')
68
+ ));
69
+
70
+ $translations = json_encode(array(
71
+ 'Cancel' => Mage::helper('M2ePro')->__('Cancel'),
72
+ 'Save' => Mage::helper('M2ePro')->__('Save'),
73
+ 'Edit Listing Title' => Mage::helper('M2ePro')->__('Edit Listing Title'),
74
+ ));
75
+
76
+ $uniqueTitleTxt = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
77
+ ->__('The specified title is already used for other listing. Listing title must be unique.'));
78
+
79
+ $constants = Mage::helper('M2ePro')
80
+ ->getClassConstantAsJson('Ess_M2ePro_Helper_Component_'.ucfirst($this->getActiveTab()));
81
+
82
+ $javascripts = <<<HTML
83
+
84
+ <script type="text/javascript">
85
+
86
+ Event.observe(window, 'load', function() {
87
+ M2ePro.url.add({$urls});
88
+ M2ePro.translator.add({$translations});
89
+ });
90
+
91
+ M2ePro.text.title_not_unique_error = '{$uniqueTitleTxt}';
92
+
93
+ M2ePro.php.setConstants(
94
+ {$constants},
95
+ 'Ess_M2ePro_Helper_Component'
96
+ );
97
+
98
+ var editListingTitle = function(el)
99
+ {
100
+ EditListingTitleObj.gridId = listingJsTabs.activeTab.id.replace('listing_', '') + 'ListingGrid';
101
+ EditListingTitleObj.openPopup(el);
102
+ }
103
+
104
+ EditListingTitleObj = new EditListingTitle();
105
+
106
+ </script>
107
+
108
+ HTML;
109
+
110
+ return parent::_toHtml().$javascripts;
111
+ }
112
+
113
+ // ########################################
114
+
115
+ protected function getAmazonTabBlock()
116
+ {
117
+ if (!$this->getChild('amazon_tab')) {
118
+ $block = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing');
119
+
120
+ $this->setChild('amazon_tab', $block);
121
+ }
122
+
123
+ return $this->getChild('amazon_tab');
124
+ }
125
+
126
+ public function getAmazonTabHtml()
127
+ {
128
+ return $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_filter')->toHtml() .
129
+ parent::getAmazonTabHtml();
130
+ }
131
+
132
+ // ########################################
133
+
134
+ protected function getBuyTabBlock()
135
+ {
136
+ if (!$this->getChild('buy_tab')) {
137
+ $block = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing');
138
+
139
+ $this->setChild('buy_tab', $block);
140
+ }
141
+
142
+ return $this->getChild('buy_tab');
143
+ }
144
+
145
+ public function getBuyTabHtml()
146
+ {
147
+ return $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_filter')->toHtml() .
148
+ parent::getBuyTabHtml();
149
+ }
150
+
151
+ // ########################################
152
+
153
+ protected function getPlayTabBlock()
154
+ {
155
+ if (!$this->getChild('play_tab')) {
156
+ $block = $this->getLayout()->createBlock('M2ePro/adminhtml_common_play_listing');
157
+
158
+ $this->setChild('play_tab', $block);
159
+ }
160
+
161
+ return $this->getChild('play_tab');
162
+ }
163
+
164
+ public function getPlayTabHtml()
165
+ {
166
+ return $this->getLayout()->createBlock('M2ePro/adminhtml_common_play_listing_filter')->toHtml() .
167
+ parent::getPlayTabHtml();
168
+ }
169
+
170
+ // ########################################
171
+
172
+ protected function getTabHtmlById($id)
173
+ {
174
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
175
+ return parent::getTabHtmlById($id);
176
+ }
177
+
178
+ /** @var $singleBlock Mage_Core_Block_Abstract|Mage_Adminhtml_Block_Widget_Grid_Container */
179
+ $singleBlock = $this->getSingleBlock();
180
+
181
+ if (is_object($singleBlock) && $singleBlock instanceof Mage_Adminhtml_Block_Widget_Grid_Container) {
182
+ return $singleBlock->getGridHtml();
183
+ }
184
+
185
+ return parent::getTabHtmlById($id);
186
+ }
187
+
188
+ protected function _componentsToHtml()
189
+ {
190
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_listing_help');
191
+ $floatingToolbarFixer = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_floatingToolbarFixer');
192
+
193
+ return $helpBlock->toHtml() . $floatingToolbarFixer->toHtml() . parent::_componentsToHtml();
194
+ }
195
+
196
+ // ########################################
197
+
198
+ public function getButtonsHtml($area = null)
199
+ {
200
+ $javascript = $this->getButtonsJavascript();
201
+
202
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
203
+ return $javascript . parent::getButtonsHtml($area);
204
+ }
205
+
206
+ return $javascript . $this->getSingleBlock()->getButtonsHtml();
207
+ }
208
+
209
+ private function getButtonsJavascript()
210
+ {
211
+ if (count($this->tabs) <= 0) {
212
+ return '';
213
+ }
214
+
215
+ if (count($this->tabs) == 1) {
216
+ return $this->getSingleBlock()->getTemplatesButtonJavascript();
217
+ }
218
+
219
+ $javascript = '';
220
+
221
+ return $javascript;
222
+ }
223
+
224
+ private function getAmazonButtonsJavascript()
225
+ {
226
+ if (!Mage::helper('M2ePro/Component_Amazon')->isActive()) {
227
+ return '';
228
+ }
229
+
230
+ if ($this->getActiveTab() != self::TAB_ID_AMAZON) {
231
+ return '';
232
+ }
233
+
234
+ return $this->getAmazonTabBlock()->getTemplatesButtonJavascript();
235
+ }
236
+
237
+ private function getBuyButtonsJavascript()
238
+ {
239
+ if (!Mage::helper('M2ePro/Component_Buy')->isActive()) {
240
+ return '';
241
+ }
242
+
243
+ if ($this->getActiveTab() != self::TAB_ID_BUY) {
244
+ return '';
245
+ }
246
+
247
+ return $this->getBuyTabBlock()->getTemplatesButtonJavascript();
248
+ }
249
+
250
+ private function getPlayButtonsJavascript()
251
+ {
252
+ if (!Mage::helper('M2ePro/Component_Play')->isActive()) {
253
+ return '';
254
+ }
255
+
256
+ if ($this->getActiveTab() != self::TAB_ID_PLAY) {
257
+ return '';
258
+ }
259
+
260
+ return $this->getPlayTabBlock()->getTemplatesButtonJavascript();
261
+ }
262
+
263
+ // ########################################
264
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Form.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ protected $component;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareForm()
22
+ {
23
+ // Prepare action
24
+ // -------------------
25
+ $step = $this->getRequest()->getParam('step');
26
+
27
+ if (is_null($step)) {
28
+ // Edit listing mode
29
+ $action = $this->getUrl('*/adminhtml_common_' . $this->component . '_listing/save');
30
+ } else {
31
+ // Add listing mode
32
+ $action = $this->getUrl('*/adminhtml_common_' . $this->component . '_listing/add', array(
33
+ 'step' => (int)$step
34
+ ));
35
+ }
36
+ // -------------------
37
+
38
+ $form = new Varien_Data_Form(array(
39
+ 'id' => 'edit_form',
40
+ 'action' => $action,
41
+ 'method' => 'post',
42
+ 'enctype' => 'multipart/form-data'
43
+ ));
44
+
45
+ $form->setUseContainer(true);
46
+ $this->setForm($form);
47
+
48
+ return parent::_prepareForm();
49
+ }
50
+
51
+ protected function _beforeToHtml()
52
+ {
53
+ // Add listing mode
54
+ // -------------------
55
+ $child = NULL;
56
+ $step = $this->getRequest()->getParam('step');
57
+
58
+ if ($step == 1) {
59
+ $child = $this->getLayout()
60
+ ->createBlock('M2ePro/adminhtml_common_' . $this->component . '_listing_add_tabs_general');
61
+ } else if ($step == 2) {
62
+ $child = $this->getLayout()
63
+ ->createBlock('M2ePro/adminhtml_common_' . $this->component . '_listing_add_tabs_selling');
64
+ } elseif ($step == 3) {
65
+ $child = $this->getLayout()
66
+ ->createBlock('M2ePro/adminhtml_common_' . $this->component . '_listing_add_tabs_search');
67
+ }
68
+
69
+ if (!is_null($child)) {
70
+ $this->setTemplate('M2ePro/common/listing/add.phtml');
71
+ $this->setChild('main', $this->getLayout()
72
+ ->createBlock('M2ePro/adminhtml_common_listing_add_main'));
73
+ $this->setChild('content', $child);
74
+ }
75
+ // -------------------
76
+
77
+ return parent::_beforeToHtml();
78
+ }
79
+
80
+ // ########################################
81
+
82
+ protected function _toHtml()
83
+ {
84
+ $breadcrumb = $this->getLayout()->createBlock(
85
+ 'M2ePro/adminhtml_common_listing_breadcrumb','',
86
+ array('step' => $this->getRequest()->getParam('step', 1))
87
+ );
88
+
89
+ return $breadcrumb->_toHtml() . parent::_toHtml();
90
+ }
91
+
92
+ // ########################################
93
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Main.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Main extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('listingEditTabsChannelGeneral');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/listing/add/main.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Review.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Review extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingProductReview');
18
+ //------------------------------
19
+
20
+ $this->_headerText = Mage::helper('M2ePro')->__('Congratulations');
21
+
22
+ $this->setTemplate('M2ePro/common/listing/add/review.phtml');
23
+ }
24
+
25
+ // ####################################
26
+
27
+ public function getHeaderCssClass()
28
+ {
29
+ return 'icon-head ' . parent::getHeaderCssClass();
30
+ }
31
+
32
+ public function getHeaderWidth()
33
+ {
34
+ return 'width:50%;';
35
+ }
36
+
37
+ // ####################################
38
+
39
+ protected function _beforeToHtml()
40
+ {
41
+ parent::_beforeToHtml();
42
+
43
+ // --------------------------------------
44
+
45
+ $listing = Mage::helper('M2ePro/Component')->getCachedUnknownObject(
46
+ 'Listing', $this->getRequest()->getParam('id')
47
+ );
48
+
49
+ $viewHeaderBlock = $this->getLayout()->createBlock(
50
+ 'M2ePro/adminhtml_listing_view_header','',
51
+ array('listing' => $listing)
52
+ );
53
+
54
+ $this->setChild('view_header', $viewHeaderBlock);
55
+
56
+ // --------------------------------------
57
+
58
+ // --------------------------------------
59
+ $url = $this->getUrl('*/*/viewListing', array(
60
+ '_current' => true,
61
+ 'id' => $this->getRequest()->getParam('id')
62
+ ));
63
+
64
+ $buttonBlock = $this->getLayout()
65
+ ->createBlock('adminhtml/widget_button')
66
+ ->setData( array(
67
+ 'label' => Mage::helper('M2ePro')->__('Review Your Products'),
68
+ 'onclick' => 'setLocation(\''.$url.'\');',
69
+ 'class' => 'save'
70
+ ) );
71
+ $this->setChild('review', $buttonBlock);
72
+ // --------------------------------------
73
+
74
+ // --------------------------------------
75
+ $url = $this->getUrl('*/*/viewListingAndList', array(
76
+ '_current' => true,
77
+ 'id' => $this->getRequest()->getParam('id')
78
+ ));
79
+
80
+ $buttonBlock = $this->getLayout()
81
+ ->createBlock('adminhtml/widget_button')
82
+ ->setData( array(
83
+ 'label' => Mage::helper('M2ePro')->__('List Added Products Now'),
84
+ 'onclick' => 'setLocation(\''.$url.'\');',
85
+ 'class' => 'save'
86
+ ) );
87
+ $this->setChild('list', $buttonBlock);
88
+ // --------------------------------------
89
+ }
90
+
91
+ // ####################################
92
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceCategory.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceCategory
8
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct($attributes)
11
+ {
12
+ parent::__construct($attributes);
13
+
14
+ $this->setData($attributes);
15
+ $component = $this->getData('component');
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId($component.'ListingAddStepFourCategory');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_listing_product_category';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $this->_headerText = Mage::helper('M2ePro')->__("Select Products");
27
+ //------------------------------
28
+
29
+ // Set buttons actions
30
+ //------------------------------
31
+ $this->removeButton('back');
32
+ $this->removeButton('reset');
33
+ $this->removeButton('delete');
34
+ $this->removeButton('add');
35
+ $this->removeButton('save');
36
+ $this->removeButton('edit');
37
+ //------------------------------
38
+
39
+ //------------------------------
40
+ if (is_null($this->getRequest()->getParam('back'))) {
41
+ $url = $this->getUrl('*/adminhtml_common_listing_productAdd/index', array(
42
+ 'id' => $this->getRequest()->getParam('id'),
43
+ 'component' => $component
44
+ ));
45
+ } else {
46
+ $tab = constant('Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_'.strtoupper($component));
47
+ $url = Mage::helper('M2ePro')->getBackUrl(
48
+ '*/adminhtml_common_listing/index',
49
+ array(
50
+ 'tab' => $tab
51
+ )
52
+ );
53
+ }
54
+ $this->_addButton('back', array(
55
+ 'label' => Mage::helper('M2ePro')->__('Back'),
56
+ 'onclick' => 'ProductGridHandlerObj.back_click(\'' . $url . '\')',
57
+ 'class' => 'back'
58
+ ));
59
+ //------------------------------
60
+
61
+ //------------------------------
62
+ $this->_addButton('auto_action', array(
63
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
64
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
65
+ ));
66
+ //------------------------------
67
+
68
+ //------------------------------
69
+ $this->_addButton('save_and_go_to_listing_view', array(
70
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
71
+ 'onclick' => 'add_category_products()',
72
+ 'class' => 'scalable next'
73
+ ));
74
+ //------------------------------
75
+ }
76
+
77
+ public function getGridHtml()
78
+ {
79
+ $listing = Mage::helper('M2ePro/Component')
80
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
81
+
82
+ $viewHeaderBlock = $this->getLayout()->createBlock(
83
+ 'M2ePro/adminhtml_listing_view_header','',
84
+ array('listing' => $listing)
85
+ );
86
+
87
+ $urls = Mage::helper('M2ePro')->getControllerActions(
88
+ 'adminhtml_common_listing_autoAction',
89
+ array(
90
+ 'listing_id' => $this->getRequest()->getParam('id'),
91
+ 'component' => $this->getData('component')
92
+ )
93
+ );
94
+ $urls = json_encode($urls);
95
+
96
+ /** @var $helper Ess_M2ePro_Helper_Data */
97
+ $helper = Mage::helper('M2ePro');
98
+
99
+ $translations = json_encode(array(
100
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
101
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
102
+ 'You must select at least 1 category.' => $helper->__('You must select at least 1 category.'),
103
+ 'Rule with the same title already exists.' => $helper->__('Rule with the same title already exists.')
104
+ ));
105
+
106
+ $js = <<<HTML
107
+ <script type="text/javascript">
108
+
109
+ M2ePro.url.add({$urls});
110
+ M2ePro.translator.add({$translations});
111
+
112
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
113
+
114
+ </script>
115
+ HTML;
116
+
117
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml() . $js;
118
+ }
119
+
120
+ protected function _toHtml()
121
+ {
122
+ return '<div id="add_products_progress_bar"></div>'.
123
+ '<div id="add_products_container">'.
124
+ parent::_toHtml() .
125
+ '</div>';
126
+ }
127
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceMode.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode
8
+ extends Mage_Adminhtml_Block_Widget_Form_Container
9
+ {
10
+ const SOURCE_LIST = 'list';
11
+ const SOURCE_CATEGORIES = 'categories';
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('amazonListingSourceMode');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_listing_add';
22
+ $this->_mode = 'sourceMode';
23
+ //------------------------------
24
+
25
+ // Set header text
26
+ //------------------------------
27
+ $this->_headerText = Mage::helper('M2ePro')->__('Add Products');
28
+ //------------------------------
29
+
30
+ // Set buttons actions
31
+ //------------------------------
32
+ $this->removeButton('back');
33
+ $this->removeButton('reset');
34
+ $this->removeButton('delete');
35
+ $this->removeButton('add');
36
+ $this->removeButton('save');
37
+ $this->removeButton('edit');
38
+ //------------------------------
39
+
40
+ //------------------------------
41
+ $url = $this->getUrl('*/*/*',array('_current' => true));
42
+ $this->_addButton('next', array(
43
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
44
+ 'onclick' => 'CommonHandlerObj.submitForm(\''.$url.'\');',
45
+ 'class' => 'scalable next'
46
+ ));
47
+ //------------------------------
48
+ }
49
+
50
+ protected function _toHtml()
51
+ {
52
+ $listing = Mage::helper('M2ePro/Component')
53
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
54
+
55
+ $viewHeaderBlock = $this->getLayout()->createBlock(
56
+ 'M2ePro/adminhtml_listing_view_header','',
57
+ array('listing' => $listing)
58
+ );
59
+
60
+ $this->setChild('view_header', $viewHeaderBlock);
61
+
62
+ return parent::_toHtml();
63
+ }
64
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceMode/Form.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingSourceMode');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/listing/add/source_mode/source_mode.phtml');
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/*/*'),
28
+ 'method' => 'post',
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ protected function _beforeToHtml()
39
+ {
40
+ //------------------------------
41
+ $this->setData('source',
42
+ $this->getRequest()->getParam('source', Ess_M2ePro_Model_Listing::SOURCE_PRODUCTS_CUSTOM));
43
+ //------------------------------
44
+
45
+ return parent::_beforeToHtml();
46
+ }
47
+
48
+ // ########################################
49
+
50
+ protected function _toHtml()
51
+ {
52
+ return parent::_toHtml();
53
+ }
54
+
55
+ // ########################################
56
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/SourceProduct.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceProduct
8
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct($attributes)
11
+ {
12
+ parent::__construct($attributes);
13
+
14
+ $this->setData($attributes);
15
+ $component = $this->getData('component');
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId($component.'ListingAddFromProductList');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_listing_product';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $this->_headerText = Mage::helper('M2ePro')->__("Select Products");
27
+ //------------------------------
28
+
29
+ // Set buttons actions
30
+ //------------------------------
31
+ $this->removeButton('back');
32
+ $this->removeButton('reset');
33
+ $this->removeButton('delete');
34
+ $this->removeButton('add');
35
+ $this->removeButton('save');
36
+ $this->removeButton('edit');
37
+ //------------------------------
38
+
39
+ //------------------------------
40
+ if (is_null($this->getRequest()->getParam('back'))) {
41
+ $url = $this->getUrl('*/adminhtml_common_listing_productAdd/index', array(
42
+ 'id' => $this->getRequest()->getParam('id'),
43
+ 'component' => $component
44
+ ));
45
+ } else {
46
+ $tab = constant('Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_'.strtoupper($component));
47
+ $url = Mage::helper('M2ePro')->getBackUrl(
48
+ '*/adminhtml_common_listing/index',
49
+ array(
50
+ 'tab' => $tab
51
+ )
52
+ );
53
+ }
54
+ $this->_addButton('back', array(
55
+ 'label' => Mage::helper('M2ePro')->__('Back'),
56
+ 'onclick' => 'ProductGridHandlerObj.back_click(\'' . $url . '\')',
57
+ 'class' => 'back'
58
+ ));
59
+
60
+ //------------------------------
61
+ $this->_addButton('auto_action', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
63
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
64
+ ));
65
+ //------------------------------
66
+
67
+ //------------------------------
68
+ $this->_addButton('save_and_go_to_listing_view', array(
69
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
70
+ 'onclick' => 'ProductGridHandlerObj.save_click(\'view\')',
71
+ 'class' => 'scalable next'
72
+ ));
73
+ //------------------------------
74
+ }
75
+
76
+ public function getGridHtml()
77
+ {
78
+ $listing = Mage::helper('M2ePro/Component')
79
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
80
+
81
+ $viewHeaderBlock = $this->getLayout()->createBlock(
82
+ 'M2ePro/adminhtml_listing_view_header','',
83
+ array('listing' => $listing)
84
+ );
85
+
86
+ $urls = Mage::helper('M2ePro')->getControllerActions(
87
+ 'adminhtml_common_listing_autoAction',
88
+ array(
89
+ 'listing_id' => $this->getRequest()->getParam('id'),
90
+ 'component' => $this->getData('component')
91
+ )
92
+ );
93
+ $urls = json_encode($urls);
94
+
95
+ /** @var $helper Ess_M2ePro_Helper_Data */
96
+ $helper = Mage::helper('M2ePro');
97
+
98
+ $translations = json_encode(array(
99
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
100
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
101
+ 'You must select at least 1 category.' => $helper->__('You must select at least 1 category.'),
102
+ 'Rule with the same title already exists.' => $helper->__('Rule with the same title already exists.')
103
+ ));
104
+
105
+ $js = <<<HTML
106
+ <script type="text/javascript">
107
+
108
+ M2ePro.url.add({$urls});
109
+ M2ePro.translator.add({$translations});
110
+
111
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
112
+
113
+ </script>
114
+ HTML;
115
+
116
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml() . $js;
117
+ }
118
+
119
+ protected function _toHtml()
120
+ {
121
+ return '<div id="add_products_progress_bar"></div>'.
122
+ '<div id="add_products_container">'.
123
+ parent::_toHtml().
124
+ '</div>';
125
+ }
126
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/StepOne.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_StepOne extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ public function __construct($attributes)
10
+ {
11
+ parent::__construct();
12
+
13
+ $this->setData($attributes);
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId($this->getData('component').'ListingAddStepOne');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_'.$this->getData('component').'_listing';
20
+ $this->_mode = 'add';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $titleConst = constant('Ess_M2ePro_Helper_Component_'.ucfirst($this->getData('component')).'::TITLE');
27
+ $componentName = Mage::helper('M2ePro')->__($titleConst);
28
+ $headerText = Mage::helper('M2ePro')
29
+ ->__("Creating A New %component_name% M2E Pro Listing", $componentName);
30
+ } else {
31
+ $headerText = Mage::helper('M2ePro')->__("Creating A New M2E Pro Listing");
32
+ }
33
+ $this->_headerText = $headerText;
34
+ //------------------------------
35
+
36
+ // Set buttons actions
37
+ //------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ //------------------------------
45
+
46
+ //------------------------------
47
+ $url = $this->getUrl('*/adminhtml_common_listing_create/index', array(
48
+ '_current' => true
49
+ ));
50
+ $this->_addButton('save_and_next', array(
51
+ 'label' => Mage::helper('M2ePro')->__('Next Step'),
52
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_click(\'' . $url . '\')',
53
+ 'class' => 'next'
54
+ ));
55
+ //------------------------------
56
+ }
57
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/StepThree.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_StepThree extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ public function __construct($attributes)
10
+ {
11
+ parent::__construct();
12
+
13
+ $this->setData($attributes);
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId($this->getData('component').'ListingAddStepThree');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_'.$this->getData('component').'_listing';
20
+ $this->_mode = 'add';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $titleConst = constant('Ess_M2ePro_Helper_Component_'.ucfirst($this->getData('component')).'::TITLE');
27
+ $componentName = Mage::helper('M2ePro')->__($titleConst);
28
+ $headerText = Mage::helper('M2ePro')
29
+ ->__("Creating A New %component_name% M2E Pro Listing", $componentName);
30
+ } else {
31
+ $headerText = Mage::helper('M2ePro')->__("Creating A New M2E Pro Listing");
32
+ }
33
+ $this->_headerText = $headerText;
34
+ //------------------------------
35
+
36
+ // Set buttons actions
37
+ //------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ //------------------------------
45
+
46
+ //------------------------------
47
+ $url = $this->getUrl('*/adminhtml_common_listing_create/index', array(
48
+ '_current' => true,
49
+ 'step' => '2',
50
+ 'component' => $this->getData('component')
51
+ ));
52
+ $this->_addButton('back', array(
53
+ 'label' => Mage::helper('M2ePro')->__('Previous Step'),
54
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
55
+ 'class' => 'back'
56
+ ));
57
+ //------------------------------
58
+
59
+ //------------------------------
60
+ $url = $this->getUrl('*/adminhtml_common_listing_create/index', array(
61
+ '_current' => true
62
+ ));
63
+ $this->_addButton('save_and_next', array(
64
+ 'label' => Mage::helper('M2ePro')->__('Next Step'),
65
+ 'onclick' => 'CommonHandlerObj.save_click(\'' . $url . '\')',
66
+ 'class' => 'next'
67
+ ));
68
+ //------------------------------
69
+ }
70
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/StepTwo.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_StepTwo extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ public function __construct($attributes)
10
+ {
11
+ parent::__construct();
12
+
13
+ $this->setData($attributes);
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId($this->getData('component').'ListingAddStepTwo');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_'.$this->getData('component').'_listing';
20
+ $this->_mode = 'add';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $titleConst = constant('Ess_M2ePro_Helper_Component_'.ucfirst($this->getData('component')).'::TITLE');
27
+ $componentName = Mage::helper('M2ePro')->__($titleConst);
28
+ $headerText = Mage::helper('M2ePro')
29
+ ->__("Creating A New %component_name% M2E Pro Listing", $componentName);
30
+ } else {
31
+ $headerText = Mage::helper('M2ePro')->__("Creating A New M2E Pro Listing");
32
+ }
33
+ $this->_headerText = $headerText;
34
+ //------------------------------
35
+
36
+ // Set buttons actions
37
+ //------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ //------------------------------
45
+
46
+ //------------------------------
47
+ $url = $this->getUrl('*/adminhtml_common_listing_create/index', array(
48
+ '_current' => true,
49
+ 'step' => '1',
50
+ 'component' => $this->getData('component')
51
+ ));
52
+ $this->_addButton('back', array(
53
+ 'label' => Mage::helper('M2ePro')->__('Previous Step'),
54
+ 'onclick' => ucfirst($this->getData('component')) .
55
+ 'ListingChannelSettingsHandlerObj.back_click(\'' . $url . '\')',
56
+ 'class' => 'back'
57
+ ));
58
+ //------------------------------
59
+
60
+ //------------------------------
61
+ $url = $this->getUrl('*/adminhtml_common_listing_create/index', array(
62
+ '_current' => true
63
+ ));
64
+ $this->_addButton('save_and_next', array(
65
+ 'label' => Mage::helper('M2ePro')->__('Next Step'),
66
+ 'onclick' => ucfirst($this->getData('component')) .
67
+ 'ListingChannelSettingsHandlerObj.save_click(\'' . $url . '\')',
68
+ 'class' => 'next'
69
+ ));
70
+ //------------------------------
71
+ }
72
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Tabs/General.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_General extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ protected $sessionKey = 'listing_create';
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingAddTabsGeneral');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ //------------------------------
24
+ $sessionData = Mage::helper('M2ePro/Data_Session')->getValue($this->sessionKey);
25
+
26
+ isset($sessionData['title']) && $this->setData('title',$sessionData['title']);
27
+ isset($sessionData['account_id']) && $this->setData('account_id',$sessionData['account_id']);
28
+ isset($sessionData['store_id']) && $this->setData('store_id',$sessionData['store_id']);
29
+ //------------------------------
30
+
31
+ //------------------------------
32
+ $buttonBlock = $this->getLayout()
33
+ ->createBlock('adminhtml/widget_button')
34
+ ->setData( array(
35
+ 'label' => 'Add',
36
+ 'onclick' => '',
37
+ 'id' => 'add_account_button',
38
+ ) );
39
+
40
+ $this->setChild('add_account_button',$buttonBlock);
41
+ //------------------------------
42
+
43
+ //------------------------------
44
+ $this->setChild(
45
+ 'store_switcher',
46
+ $this->getLayout()->createBlock(
47
+ 'M2ePro/adminhtml_storeSwitcher', '', array('id'=>'store_id','selected' => $this->getData('store_id'))
48
+ )
49
+ );
50
+ //------------------------------
51
+
52
+ return parent::_beforeToHtml();
53
+ }
54
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Tabs/Search.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Search extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ protected $sessionKey = 'listing_create';
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingAddTabsGeneral');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ //-------------------------------
24
+ $data = $this->getListingData();
25
+
26
+ $this->setData(
27
+ 'general_attributes',
28
+ Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets()
29
+ );
30
+
31
+ foreach ($data as $key=>$value) {
32
+ $this->setData($key, $value);
33
+ }
34
+ //-------------------------------
35
+
36
+ return parent::_beforeToHtml();
37
+ }
38
+
39
+ // #############################################
40
+
41
+ protected function getListingData()
42
+ {
43
+ if (!is_null($this->getRequest()->getParam('id'))) {
44
+ $data = $this->getListing()->getData();
45
+ } else {
46
+ $data = Mage::helper('M2ePro/Data_Session')->getValue($this->sessionKey);
47
+ $data = array_merge($this->getDefaults(), $data);
48
+ }
49
+
50
+ return $data;
51
+ }
52
+
53
+ protected function getDefaults()
54
+ {
55
+ return array();
56
+ }
57
+
58
+ protected function getListing()
59
+ {
60
+ if (!$listingId = $this->getRequest()->getParam('id')) {
61
+ throw new Exception('Listing is not defined');
62
+ }
63
+
64
+ if (is_null($this->listing)) {
65
+ $this->listing = Mage::helper('M2ePro/Component')
66
+ ->getCachedUnknownObject('Listing', $listingId);
67
+ }
68
+
69
+ return $this->listing;
70
+ }
71
+
72
+ // ####################################
73
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Add/Tabs/Selling.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Selling extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ protected $sessionKey = 'listing_create';
10
+ protected $component = null;
11
+ protected $listing = null;
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('listingAddTabsSelling');
20
+ //------------------------------
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ //-------------------------------
26
+ $data = $this->getListingData();
27
+
28
+ $this->setData(
29
+ 'general_attributes',
30
+ Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets()
31
+ );
32
+
33
+ $this->setData(
34
+ 'all_attributes',
35
+ Mage::helper('M2ePro/Magento_Attribute')->getAll()
36
+ );
37
+
38
+ foreach ($data as $key=>$value) {
39
+ $this->setData($key, $value);
40
+ }
41
+ //-------------------------------
42
+
43
+ //-------------------------------
44
+ $maxRecordsQuantity = Mage::helper('M2ePro/View_Common')->getAutocompleteMaxItems();
45
+ //-------------------------------
46
+
47
+ //----------------------------
48
+ $templates = $this->getSellingFormatTemplates();
49
+ if (count($templates) < $maxRecordsQuantity) {
50
+ $this->sellingFormatTemplatesDropDown = true;
51
+ $this->sellingFormatTemplates = $templates;
52
+ } else {
53
+ $this->sellingFormatTemplatesDropDown = false;
54
+ $this->sellingFormatTemplates = array();
55
+ }
56
+ //----------------------------
57
+
58
+ //----------------------------
59
+ $synchronizationTemplatesCollection = Mage::helper('M2ePro/Component')
60
+ ->getComponentCollection($this->component, 'Template_Synchronization')
61
+ ->setOrder('title', 'ASC');
62
+
63
+ if ($synchronizationTemplatesCollection->getSize() < $maxRecordsQuantity) {
64
+ $this->synchronizationsTemplatesDropDown = true;
65
+ $templates = $synchronizationTemplatesCollection->toArray();
66
+
67
+ foreach ($templates['items'] as $key => $value) {
68
+ $templates['items'][$key]['title'] = Mage::helper('M2ePro')
69
+ ->escapeHtml($templates['items'][$key]['title']);
70
+ }
71
+
72
+ $this->synchronizationsTemplates = $templates['items'];
73
+ } else {
74
+ $this->synchronizationsTemplatesDropDown = false;
75
+ $this->synchronizationsTemplates = array();
76
+ }
77
+ //----------------------------
78
+
79
+ return parent::_beforeToHtml();
80
+ }
81
+
82
+ protected function getSellingFormatTemplates()
83
+ {
84
+ $collection = Mage::getModel('M2ePro/Template_SellingFormat')->getCollection();
85
+ $collection->addFieldToFilter('component_mode', $this->component);
86
+
87
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS)
88
+ ->columns(array('id', 'title'));
89
+
90
+ $collection->setOrder('main_table.title', 'ASC');
91
+
92
+ $data = $collection->toArray();
93
+
94
+ foreach ($data['items'] as $key => $value) {
95
+ $data['items'][$key]['title'] = Mage::helper('M2ePro')->escapeHtml($data['items'][$key]['title']);
96
+ }
97
+
98
+ return $data['items'];
99
+ }
100
+
101
+ // #############################################
102
+
103
+ protected function getListingData()
104
+ {
105
+ if (!is_null($this->getRequest()->getParam('id'))) {
106
+ $data = $this->getListing()->getData();
107
+ } else {
108
+ $data = Mage::helper('M2ePro/Data_Session')->getValue($this->sessionKey);
109
+ $data = array_merge($this->getDefaults(), $data);
110
+ }
111
+
112
+ return $data;
113
+ }
114
+
115
+ // ####################################
116
+
117
+ protected function getDefaults()
118
+ {
119
+ return array();
120
+ }
121
+
122
+ // ####################################
123
+
124
+ protected function getListing()
125
+ {
126
+ if (!$listingId = $this->getRequest()->getParam('id')) {
127
+ throw new Exception('Listing is not defined');
128
+ }
129
+
130
+ if (is_null($this->listing)) {
131
+ $this->listing = Mage::helper('M2ePro/Component')
132
+ ->getCachedUnknownObject('Listing', $listingId);
133
+ }
134
+
135
+ return $this->listing;
136
+ }
137
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Breadcrumb.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Breadcrumb extends Mage_Adminhtml_Block_Template
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('commonListingBreadcrumb');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/listing/breadcrumb.phtml');
19
+ }
20
+
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Category/Tree.php ADDED
@@ -0,0 +1,379 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Category_Tree extends Mage_Adminhtml_Block_Catalog_Category_Abstract
8
+ {
9
+ // #############################################
10
+
11
+ protected $listing;
12
+
13
+ protected $selectedIds = array();
14
+
15
+ /* @var string */
16
+ protected $gridId = NULL;
17
+
18
+ /* @var Varien_Data_Tree_Node */
19
+ protected $currentNode = NULL;
20
+
21
+ // #############################################
22
+
23
+ public function setSelectedIds(array $ids)
24
+ {
25
+ $this->selectedIds = $ids;
26
+ return $this;
27
+ }
28
+
29
+ public function getSelectedIds()
30
+ {
31
+ return $this->selectedIds;
32
+ }
33
+
34
+ public function setCurrentNodeById($categoryId)
35
+ {
36
+ $category = Mage::getModel('catalog/category')->load($categoryId);
37
+ $node = $this->getRoot($category, 1)->getTree()->getNodeById($categoryId);
38
+ return $this->setCurrentNode($node);
39
+ }
40
+
41
+ public function setCurrentNode(Varien_Data_Tree_Node $currentNode)
42
+ {
43
+ $this->currentNode = $currentNode;
44
+ return $this;
45
+ }
46
+
47
+ public function getCurrentNode()
48
+ {
49
+ return $this->currentNode;
50
+ }
51
+
52
+ public function getCurrentNodeId()
53
+ {
54
+ return $this->currentNode ? $this->currentNode->getId() : NULL;
55
+ }
56
+
57
+ // #############################################
58
+
59
+ public function setGridId($gridId)
60
+ {
61
+ $this->gridId = $gridId;
62
+ return $this;
63
+ }
64
+
65
+ public function getGridId()
66
+ {
67
+ return $this->gridId;
68
+ }
69
+
70
+ // #############################################
71
+
72
+ public function getLoadTreeUrl()
73
+ {
74
+ return $this->getUrl('*/*/getCategoriesJson', array('_current'=>true));
75
+ }
76
+
77
+ // #############################################
78
+
79
+ public function getCategoryCollection()
80
+ {
81
+ $collection = $this->getData('category_collection');
82
+
83
+ if (!$collection) {
84
+ $collection = Mage::getModel('catalog/category')
85
+ ->getCollection()
86
+ ->addAttributeToSelect('name')
87
+ ->addAttributeToSelect('is_active');
88
+
89
+ $this->loadProductsCount($collection);
90
+
91
+ $this->setData('category_collection', $collection);
92
+ }
93
+
94
+ return $collection;
95
+ }
96
+
97
+ // #############################################
98
+
99
+ public function __construct()
100
+ {
101
+ parent::__construct();
102
+
103
+ // Initialization block
104
+ //------------------------------
105
+ $this->setId('listingCategoryTree');
106
+ //------------------------------
107
+
108
+ $this->setTemplate('M2ePro/common/listing/category/tree.phtml');
109
+
110
+ $this->_isAjax = $this->getRequest()->isXmlHttpRequest();
111
+ }
112
+
113
+ // #############################################
114
+
115
+ public function getTreeJson($parentNodeCategory=null)
116
+ {
117
+ $rootArray = $this->_getNodeJson($this->getRoot($parentNodeCategory));
118
+ $json = Zend_Json::encode(isset($rootArray['children']) ? $rootArray['children'] : array());
119
+ return $json;
120
+ }
121
+
122
+ // #############################################
123
+
124
+ protected function _getNodeJson($node, $level = 0)
125
+ {
126
+ // create a node from data array
127
+ if (is_array($node)) {
128
+ $node = new Varien_Data_Tree_Node($node, 'entity_id', new Varien_Data_Tree);
129
+ }
130
+
131
+ $item = array();
132
+ $item['text'] = $this->buildNodeName($node);
133
+ $item['id'] = $node->getId();
134
+ $item['cls'] = 'folder ' . ($node->getIsActive() ? 'active-category' : 'no-active-category');
135
+ $item['path'] = $node->getData('path');
136
+ $item['allowDrop'] = false;
137
+ $item['allowDrag'] = false;
138
+
139
+ $isParent = $this->_isParentSelectedCategory($node);
140
+
141
+ if ((int)$node->getChildrenCount() > 0) {
142
+ $item['children'] = array();
143
+ }
144
+
145
+ if ($node->hasChildren()) {
146
+
147
+ $item['children'] = array();
148
+
149
+ if (!($node->getLevel() > 1 && !$isParent)) {
150
+ foreach ($node->getChildren() as $child) {
151
+ $item['children'][] = $this->_getNodeJson($child, $level+1);
152
+ }
153
+ }
154
+ }
155
+
156
+ if ($isParent || $node->getLevel() < 2) {
157
+ $item['expanded'] = true;
158
+ }
159
+
160
+ return $item;
161
+ }
162
+
163
+ protected function _isParentSelectedCategory($node)
164
+ {
165
+ if ($node && $this->getCurrentNode()) {
166
+ $pathIds = explode('/', $this->getCurrentNode()->getData('path'));
167
+ if (in_array($node->getId(), $pathIds)) {
168
+ return true;
169
+ }
170
+ }
171
+
172
+ return false;
173
+ }
174
+
175
+ // #############################################
176
+
177
+ public function buildNodeName($node)
178
+ {
179
+ $treeSettings = $this->getData('tree_settings');
180
+ $result = $this->escapeHtml($node->getName());
181
+
182
+ $ccpTable = Mage::getSingleton('core/resource')->getTableName('catalog_category_product');
183
+ $cpeTable = Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
184
+
185
+ $dbSelect = $this->getReadConnection()
186
+ ->select()
187
+ ->from(array('ccp'=>$ccpTable),new Zend_Db_Expr('DISTINCT `ccp`.`product_id`'))
188
+ ->join(array('cpe'=>$cpeTable),'`cpe`.`entity_id` = `ccp`.`product_id`',array())
189
+ ->where('`ccp`.`category_id` = ?',(int)$node->getId());
190
+
191
+ //----------------------------
192
+ if ($treeSettings['show_products_amount'] != false) {
193
+ if ($treeSettings['hide_products_this_listing']) {
194
+ $fields = new Zend_Db_Expr('DISTINCT `product_id`');
195
+ $dbSelect3 = $this->getReadConnection()
196
+ ->select()
197
+ ->from(Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable(),$fields)
198
+ ->where('`component_mode` = ?',$this->getData('component'))
199
+ ->where('`listing_id` = ?', $this->getRequest()->getParam('id'));
200
+
201
+ $dbSelect->where('`ccp`.`product_id` NOT IN ('.$dbSelect3->__toString().')');
202
+ }
203
+ $sqlQuery = " SELECT count(`rez`.`product_id`) as `count_products`
204
+ FROM ( ".$dbSelect->__toString()." ) as `rez` ";
205
+
206
+ $countProducts = $this->getReadConnection()
207
+ ->fetchOne($sqlQuery);
208
+
209
+ $helper = Mage::helper('M2ePro');
210
+ $result .= <<<HTML
211
+ <span category_id="{$node->getId()}">(0</span>{$helper->__('of')} {$countProducts})
212
+ HTML;
213
+ }
214
+ //----------------------------
215
+
216
+ return $result;
217
+
218
+ }
219
+
220
+ // #############################################
221
+
222
+ public function getCategoryChildrenJson($categoryId)
223
+ {
224
+ $this->setCurrentNodeById($categoryId);
225
+ return $this->getTreeJson(Mage::getModel('catalog/category')->load($categoryId));
226
+ }
227
+
228
+ // #############################################
229
+
230
+ public function getAffectedCategoriesCount()
231
+ {
232
+ if (!is_null($this->getData('affected_categories_count'))) {
233
+ return $this->getData('affected_categories_count');
234
+ }
235
+
236
+ $dbSelect = Mage::getResourceModel('core/config')->getReadConnection()
237
+ ->select()
238
+ ->from(Mage::getSingleton('core/resource')->getTableName('catalog/category_product'),
239
+ 'category_id')
240
+ ->where('`product_id` IN(?)',$this->getSelectedIds());
241
+
242
+ $affectedCategoriesCount = Mage::getModel('catalog/category')->getCollection()
243
+ ->getSelectCountSql()
244
+ ->where('entity_id IN ('.$dbSelect->__toString().')')
245
+ ->query()
246
+ ->fetchColumn();
247
+
248
+ $this->setData('affected_categories_count', (int)$affectedCategoriesCount);
249
+
250
+ return $this->getData('affected_categories_count');
251
+ }
252
+
253
+ // #############################################
254
+
255
+ public function getProductsForEachCategory()
256
+ {
257
+ if (!is_null($this->getData('products_for_each_category'))) {
258
+ return $this->getData('products_for_each_category');
259
+ }
260
+
261
+ $ids = array_map('intval',$this->selectedIds);
262
+ $ids = implode(',',$ids);
263
+ !$ids && $ids = 0;
264
+
265
+ /* @var $select Varien_Db_Select */
266
+ $select = Mage::getModel('catalog/category')->getCollection()->getSelect();
267
+ $select->joinLeft(
268
+ Mage::getSingleton('core/resource')->getTableName('catalog/category_product'),
269
+ "entity_id = category_id AND product_id IN ({$ids})",
270
+ array('product_id')
271
+ );
272
+
273
+ $productsForEachCategory = array();
274
+ foreach ($select->query() as $row) {
275
+ if (!isset($productsForEachCategory[$row['entity_id']])) {
276
+ $productsForEachCategory[$row['entity_id']] = array();
277
+ }
278
+ $row['product_id'] && $productsForEachCategory[$row['entity_id']][] = $row['product_id'];
279
+ }
280
+
281
+ $this->setData('products_for_each_category', $productsForEachCategory);
282
+
283
+ return $this->getData('products_for_each_category');
284
+ }
285
+
286
+ public function getProductsCountForEachCategory()
287
+ {
288
+ if (!is_null($this->getData('products_count_for_each_category'))) {
289
+ return $this->getData('products_count_for_each_category');
290
+ }
291
+
292
+ $productsCountForEachCategory = $this->getProductsForEachCategory();
293
+ $productsCountForEachCategory = array_map('count',$productsCountForEachCategory);
294
+
295
+ $this->setData('products_count_for_each_category', $productsCountForEachCategory);
296
+
297
+ return $this->getData('products_count_for_each_category');
298
+ }
299
+
300
+ // #############################################
301
+
302
+ public function getInfoJson()
303
+ {
304
+ return json_encode(array(
305
+ 'category_products' => $this->getProductsCountForEachCategory(),
306
+ 'total_products_count' => count($this->getSelectedIds()),
307
+ 'total_categories_count' => $this->getAffectedCategoriesCount()
308
+ ));
309
+ }
310
+
311
+ // #############################################
312
+
313
+ protected function loadProductsCount($collection)
314
+ {
315
+ $items = $collection->getItems();
316
+
317
+ if (!$items) {
318
+ return;
319
+ }
320
+
321
+ $readConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
322
+
323
+ //----------------------------
324
+ $excludeProductsSelect = $readConnection->select()->from(
325
+ Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable(),
326
+ new Zend_Db_Expr('DISTINCT `product_id`')
327
+ );
328
+
329
+ $excludeProductsSelect->where('`listing_id` = ?',(int)$this->getRequest()->getParam('id'));
330
+
331
+ $select = $readConnection->select();
332
+ $select->from(
333
+ array('main_table' => $collection->getTable('catalog/category_product')),
334
+ array('category_id', new Zend_Db_Expr('COUNT(main_table.product_id)'))
335
+ )
336
+ ->where($readConnection->quoteInto('main_table.category_id IN(?)', array_keys($items)))
337
+ ->where('main_table.product_id NOT IN ('.$excludeProductsSelect.')')
338
+ ->group('main_table.category_id');
339
+
340
+ $counts = $readConnection->fetchPairs($select);
341
+
342
+ foreach ($items as $item) {
343
+ if (isset($counts[$item->getId()])) {
344
+ $item->setProductCount($counts[$item->getId()]);
345
+ } else {
346
+ $item->setProductCount(0);
347
+ }
348
+ }
349
+ }
350
+
351
+ // #############################################
352
+
353
+ private function getListing()
354
+ {
355
+ if (!$listingId = $this->getRequest()->getParam('id')) {
356
+ throw new Exception('Listing is not defined');
357
+ }
358
+
359
+ if (is_null($this->listing)) {
360
+ $this->listing = Mage::helper('M2ePro/Component_' . ucfirst($this->getData('component')))
361
+ ->getCachedObject('Listing',$listingId)->getChildObject();
362
+ }
363
+
364
+ return $this->listing;
365
+ }
366
+
367
+ // ####################################
368
+
369
+ private function getReadConnection()
370
+ {
371
+ if (is_null($this->readConnection)) {
372
+ $this->readConnection = Mage::getResourceModel('core/config')->getReadConnection();
373
+ }
374
+
375
+ return $this->readConnection;
376
+ }
377
+
378
+ // ####################################
379
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Help.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Help extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setTemplate('M2ePro/common/listing/help.phtml');
13
+ }
14
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Log.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Log extends Mage_Adminhtml_Block_Widget_Container
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('listingLog');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_listing_log';
20
+ //------------------------------
21
+
22
+ //------------------------------
23
+ $this->setTemplate('M2ePro/common/log/log.phtml');
24
+ //------------------------------
25
+
26
+ // Set buttons actions
27
+ //------------------------------
28
+ $this->removeButton('back');
29
+ $this->removeButton('reset');
30
+ $this->removeButton('delete');
31
+ $this->removeButton('add');
32
+ $this->removeButton('save');
33
+ $this->removeButton('edit');
34
+
35
+ if (!is_null($this->getRequest()->getParam('back'))) {
36
+ //------------------------------
37
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_listing/index');
38
+ $this->_addButton('back', array(
39
+ 'label' => Mage::helper('M2ePro')->__('Back'),
40
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
41
+ 'class' => 'back'
42
+ ));
43
+ //------------------------------
44
+ }
45
+
46
+ //------------------------------
47
+ $this->_addButton('goto_listings', array(
48
+ 'label' => Mage::helper('M2ePro')->__('Listings'),
49
+ 'onclick' => 'setLocation(\'' .$this->getUrl('*/adminhtml_common_listing/index').'\')',
50
+ 'class' => 'button_link'
51
+ ));
52
+ //------------------------------
53
+
54
+ //------------------------------
55
+ if (isset($listingData['id'])) {
56
+ //------------------------------
57
+ $url = Mage::helper('M2ePro/View')->getUrl(
58
+ new Varien_Object($listingData), 'listing', 'edit', array('id' => $listingData['id'])
59
+ );
60
+ $this->_addButton('goto_listing_settings', array(
61
+ 'label' => Mage::helper('M2ePro')->__('Listing Settings'),
62
+ 'onclick' => 'setLocation(\'' .$url.'\')',
63
+ 'class' => 'button_link'
64
+ ));
65
+ //------------------------------
66
+
67
+ //------------------------------
68
+ $url = Mage::helper('M2ePro/View')->getUrl(
69
+ new Varien_Object($listingData), 'listing', 'view', array('id' => $listingData['id'])
70
+ );
71
+ $this->_addButton('goto_listing_items', array(
72
+ 'label' => Mage::helper('M2ePro')->__('Listing Items'),
73
+ 'onclick' => 'setLocation(\'' .$url.'\')',
74
+ 'class' => 'button_link'
75
+ ));
76
+ //------------------------------
77
+ }
78
+
79
+ if (isset($listingData['id'])) {
80
+ //------------------------------
81
+ $url = $this->getUrl('*/*/*');
82
+ $this->_addButton('show_general_log', array(
83
+ 'label' => Mage::helper('M2ePro')->__('Show General Log'),
84
+ 'onclick' => 'setLocation(\'' . $url .'\')',
85
+ 'class' => 'show_general_log'
86
+ ));
87
+ //------------------------------
88
+ }
89
+ }
90
+
91
+ // ########################################
92
+
93
+ public function getListingId()
94
+ {
95
+ return $this->getRequest()->getParam('id', false);
96
+ }
97
+
98
+ // ----------------------------------------
99
+
100
+ /** @var Ess_M2ePro_Model_Listing $listing */
101
+ protected $listing = NULL;
102
+
103
+ /**
104
+ * @return Ess_M2ePro_Model_Listing|null
105
+ */
106
+ public function getListing()
107
+ {
108
+ if (is_null($this->listing)) {
109
+ $this->listing = Mage::helper('M2ePro/Component')
110
+ ->getCachedUnknownObject('Listing', $this->getListingId());
111
+ }
112
+
113
+ return $this->listing;
114
+ }
115
+
116
+ // ########################################
117
+
118
+ public function getListingProductId()
119
+ {
120
+ return $this->getRequest()->getParam('listing_product_id', false);
121
+ }
122
+
123
+ // ----------------------------------------
124
+
125
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
126
+ protected $listingProduct = NULL;
127
+
128
+ /**
129
+ * @return Ess_M2ePro_Model_Listing_Product|null
130
+ */
131
+ public function getListingProduct()
132
+ {
133
+ if (is_null($this->listingProduct)) {
134
+ $this->listingProduct = Mage::helper('M2ePro/Component')
135
+ ->getUnknownObject('Listing_Product', $this->getListingProductId());
136
+ }
137
+
138
+ return $this->listingProduct;
139
+ }
140
+
141
+ // ########################################
142
+
143
+ protected function _beforeToHtml()
144
+ {
145
+ // Set header text
146
+ //------------------------------
147
+ $this->_headerText = '';
148
+
149
+ if ($this->getListingId()) {
150
+
151
+ $listing = $this->getListing();
152
+
153
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
154
+ $component = Mage::helper('M2ePro/Component')->getComponentTitle($listing->getComponentMode());
155
+ $this->_headerText = Mage::helper('M2ePro')->__(
156
+ 'Log For %component_name% Listing "%listing_title%"',
157
+ $component, $this->escapeHtml($listing->getTitle())
158
+ );
159
+ } else {
160
+ $this->_headerText = Mage::helper('M2ePro')->__(
161
+ 'Log For Listing "%listing_title%"',
162
+ $this->escapeHtml($listing->getTitle())
163
+ );
164
+ }
165
+
166
+ } else if ($this->getListingProductId()) {
167
+
168
+ $listingProduct = $this->getListingProduct();
169
+ $listing = $listingProduct->getListing();
170
+
171
+ $onlineTitle = $listingProduct->getOnlineTitle();
172
+ if (empty($onlineTitle)) {
173
+ $onlineTitle = $listingProduct->getMagentoProduct()->getName();
174
+ }
175
+
176
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
177
+ $component = Mage::helper('M2ePro/Component')->getComponentTitle($listing->getComponentMode());
178
+ $this->_headerText = Mage::helper('M2ePro')->__(
179
+ 'Log For Product "%product_name%" (ID:%product_id%) Of %component_name% Listing "%listing_title%"',
180
+ $this->escapeHtml($onlineTitle),
181
+ $listingProduct->getProductId(),
182
+ $component,
183
+ $this->escapeHtml($listing->getTitle())
184
+ );
185
+ } else {
186
+ $this->_headerText = Mage::helper('M2ePro')->__(
187
+ 'Log For Product "%product_name%" (ID:%product_id%) Of Listing "%listing_title%"',
188
+ $this->escapeHtml($onlineTitle),
189
+ $listingProduct->getProductId(),
190
+ $this->escapeHtml($listing->getTitle())
191
+ );
192
+ }
193
+
194
+ } else {
195
+ $this->_headerText = Mage::helper('M2ePro')->__('Listings Log');
196
+ }
197
+ //------------------------------
198
+ }
199
+
200
+ // ########################################
201
+
202
+ protected function _toHtml()
203
+ {
204
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_listing_log_help')->toHtml();
205
+
206
+ $logBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_log_tabs', '',
207
+ array(
208
+ 'channel' => $this->getRequest()->getParam('channel'),
209
+ 'log_type' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::LOG_TYPE_ID_LISTING
210
+ )
211
+ )->toHtml();
212
+
213
+ $translations = json_encode(array(
214
+ 'Description' => Mage::helper('M2ePro')->__('Description')
215
+ ));
216
+
217
+ $hideTabs = '';
218
+ if ($this->getListingId() || $this->getListingProductId()) {
219
+ $hideTabs = '$("commonLogTabs").hide();';
220
+ }
221
+
222
+ $javascript = <<<JAVASCIRPT
223
+
224
+ <script type="text/javascript">
225
+
226
+ M2ePro.translator.add({$translations});
227
+
228
+ Event.observe(window, 'load', function() {
229
+ LogHandlerObj = new LogHandler();
230
+ {$hideTabs}
231
+ });
232
+
233
+ </script>
234
+
235
+ JAVASCIRPT;
236
+
237
+ return $javascript . parent::_toHtml() . $helpBlock . $logBlock;
238
+ }
239
+
240
+ // ########################################
241
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Log/Grid.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Log_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Log_Grid
8
+ {
9
+ // ########################################
10
+
11
+ protected function getActionTitles()
12
+ {
13
+ $allActions = Mage::getModel('M2ePro/Listing_Log')->getActionsTitles();
14
+
15
+ $excludeActions = array(
16
+ Ess_M2ePro_Model_Listing_Log::ACTION_TRANSLATE_PRODUCT => ''
17
+ );
18
+
19
+ if ($this->getChannel() != Ess_M2ePro_Helper_Component_Buy::NICK) {
20
+ $excludeActions[Ess_M2ePro_Model_Listing_Log::ACTION_NEW_SKU_PRODUCT_ON_COMPONENT] = '';
21
+ }
22
+
23
+ return array_diff_key($allActions, $excludeActions);
24
+ }
25
+
26
+ // ########################################
27
+
28
+ public function callbackColumnListingTitleID($value, $row, $column, $isExport)
29
+ {
30
+ if (strlen($value) > 50) {
31
+ $value = substr($value, 0, 50) . '...';
32
+ }
33
+
34
+ $value = Mage::helper('M2ePro')->escapeHtml($value);
35
+
36
+ if ($row->getData('listing_id')) {
37
+ $url = $this->getUrl(
38
+ '*/adminhtml_common_'.$row->getData('component_mode').'_listing/view',
39
+ array('id' => $row->getData('listing_id'))
40
+ );
41
+
42
+ $value = '<a target="_blank" href="'.$url.'">' .
43
+ Mage::helper('M2ePro')->escapeHtml($value) .
44
+ '</a><br/>ID: '.$row->getData('listing_id');
45
+ }
46
+
47
+ return $value;
48
+ }
49
+
50
+ // ########################################
51
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Log/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Log_Help extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('commonListingLogHelp');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/listing/log/help.phtml');
19
+ }
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Listing/Other.php ADDED
@@ -0,0 +1,712 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Listing_Other extends Ess_M2ePro_Block_Adminhtml_Common_Component_Tabs_Container
8
+ {
9
+ // ########################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Set header text
16
+ //------------------------------
17
+ $this->_headerText = Mage::helper('M2ePro')->__('3rd Party Listings');
18
+ //------------------------------
19
+
20
+ // Set buttons actions
21
+ //------------------------------
22
+ $this->removeButton('back');
23
+ $this->removeButton('reset');
24
+ $this->removeButton('delete');
25
+ $this->removeButton('add');
26
+ $this->removeButton('save');
27
+ $this->removeButton('edit');
28
+
29
+ if (!is_null($this->getRequest()->getParam('back'))) {
30
+ //------------------------------
31
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_listing/index');
32
+ $this->_addButton('back', array(
33
+ 'label' => Mage::helper('M2ePro')->__('Back'),
34
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
35
+ 'class' => 'back'
36
+ ));
37
+ //------------------------------
38
+ }
39
+
40
+ //------------------------------
41
+ $url = $this->getUrl('*/adminhtml_common_log/listingOther');
42
+ $this->_addButton('view_log', array(
43
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
44
+ 'onclick' => 'window.open(\''.$url.'\')',
45
+ 'class' => 'button_link'
46
+ ));
47
+ //------------------------------
48
+
49
+ //------------------------------
50
+ $this->useAjax = true;
51
+ $this->tabsAjaxUrls = array(
52
+ self::TAB_ID_AMAZON => $this->getUrl('*/adminhtml_common_amazon_listing_other/index'),
53
+ self::TAB_ID_BUY => $this->getUrl('*/adminhtml_common_buy_listing_other/index'),
54
+ self::TAB_ID_PLAY => $this->getUrl('*/adminhtml_common_play_listing_other/index'),
55
+ );
56
+
57
+ $this->isAjax = json_encode($this->getRequest()->isXmlHttpRequest());
58
+ //------------------------------
59
+ }
60
+
61
+ // ########################################
62
+
63
+ protected function getAmazonTabBlock()
64
+ {
65
+ if (!$this->getChild('amazon_tab')) {
66
+ $this->setChild(
67
+ 'amazon_tab', $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_other_grid')
68
+ );
69
+ }
70
+ return $this->getChild('amazon_tab');
71
+ }
72
+
73
+ public function getAmazonTabHtml()
74
+ {
75
+ /** @var $helper Ess_M2ePro_Helper_Data */
76
+ $helper = Mage::helper('M2ePro');
77
+ $componentMode = Ess_M2ePro_Helper_Component_Amazon::NICK;
78
+
79
+ $prepareData = $this->getUrl('*/adminhtml_listing_other_moving/prepareMoveToListing');
80
+ $createDefaultListingUrl = $this->getUrl('*/adminhtml_listing_other_moving/createDefaultListing');
81
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/moveToListingGrid');
82
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/getFailedProductsGrid');
83
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_other_moving/tryToMoveToListing');
84
+ $moveToListing = $this->getUrl('*/adminhtml_listing_other_moving/moveToListing');
85
+
86
+ $mapAutoToProductUrl = $this->getUrl('*/adminhtml_listing_other_mapping/autoMap');
87
+
88
+ $removingProductsUrl = $this->getUrl('*/adminhtml_common_listing_other/removing');
89
+ $unmappingProductsUrl = $this->getUrl('*/adminhtml_listing_other_mapping/unmapping');
90
+
91
+ $someProductsWereNotMappedMessage = 'No matches were found. Please change the mapping attributes in <strong>';
92
+ $someProductsWereNotMappedMessage .= 'Configuration > Account > 3rd Party Listings</strong> ';
93
+ $someProductsWereNotMappedMessage .= 'or try to map manually.';
94
+ $someProductsWereNotMappedMessage = $helper->escapeJs($helper->__($someProductsWereNotMappedMessage));
95
+
96
+ $successfullyMappedMessage = $helper->escapeJs($helper->__('Product was successfully mapped.'));
97
+
98
+ $createListing = $helper->escapeJs($helper->__(
99
+ 'Listings, which have the same Marketplace and Account were not found.'
100
+ ));
101
+ $createListing .= $helper->escapeJs($helper->__('Would you like to create one with default settings ?'));
102
+ $popupTitle = $helper->escapeJs($helper->__('Moving Amazon Items'));
103
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Amazon Item'));
104
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
105
+
106
+ $confirmMessage = $helper->escapeJs($helper->__('Are you sure?'));
107
+
108
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully moved.'));
109
+ $productsWereNotMovedMessage = $helper->escapeJs(
110
+ $helper->__('Products were not moved. <a target="_blank" href="%url%">View log</a> for details.')
111
+ );
112
+ $someProductsWereNotMovedMessage = $helper->escapeJs($helper->__(
113
+ 'Some of the Products were not moved. <a target="_blank" href="%url%">View log</a> for details.'
114
+ ));
115
+
116
+ $notEnoughDataMessage = $helper->escapeJs($helper->__('Not enough data'));
117
+ $successfullyUnmappedMessage = $helper->escapeJs($helper->__('Product(s) was successfully unmapped.'));
118
+ $successfullyRemovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully removed.'));
119
+
120
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
121
+
122
+ $selectItemsMessage = $helper->escapeJs(
123
+ $helper->__('Please select the Products you want to perform the action on.')
124
+ );
125
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select action.'));
126
+
127
+ $processingDataMessage = $helper->escapeJs($helper->__('Processing %product_title% Product(s).'));
128
+
129
+ $autoMapProgressTitle = $helper->escapeJs($helper->__('Map Item(s) to Products'));
130
+ $selectOnlyMapped = $helper->escapeJs($helper->__('Only mapped Products must be selected.'));
131
+ $selectTheSameTypeProducts = $helper->escapeJs(
132
+ $helper->__('Selected Items must belong to the same Account and Marketplace.')
133
+ );
134
+
135
+ $successWord = $helper->escapeJs($helper->__('Success'));
136
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
137
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
138
+ $errorWord = $helper->escapeJs($helper->__('Error'));
139
+ $closeWord = $helper->escapeJs($helper->__('Close'));
140
+
141
+ $javascriptsMain = <<<JAVASCRIPT
142
+ <script type="text/javascript">
143
+
144
+ M2eProAmazon = {};
145
+ M2eProAmazon.url = {};
146
+ M2eProAmazon.formData = {};
147
+ M2eProAmazon.customData = {};
148
+ M2eProAmazon.text = {};
149
+
150
+ M2eProAmazon.url.prepareData = '{$prepareData}';
151
+ M2eProAmazon.url.createDefaultListing = '{$createDefaultListingUrl}';
152
+ M2eProAmazon.url.getGridHtml = '{$getMoveToListingGridHtml}';
153
+ M2eProAmazon.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
154
+ M2eProAmazon.url.tryToMoveToListing = '{$tryToMoveToListing}';
155
+ M2eProAmazon.url.moveToListing = '{$moveToListing}';
156
+
157
+ M2eProAmazon.url.mapAutoToProduct = '{$mapAutoToProductUrl}';
158
+
159
+ M2eProAmazon.url.removingProducts = '{$removingProductsUrl}';
160
+ M2eProAmazon.url.unmappingProducts = '{$unmappingProductsUrl}';
161
+
162
+ M2eProAmazon.text.create_listing = '{$createListing}';
163
+ M2eProAmazon.text.popup_title = '{$popupTitle}';
164
+ M2eProAmazon.text.popup_title_single = '{$popupTitleSingle}';
165
+ M2eProAmazon.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
166
+ M2eProAmazon.text.confirm = '{$confirmMessage}';
167
+ M2eProAmazon.text.successfully_moved = '{$successfullyMovedMessage}';
168
+ M2eProAmazon.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
169
+ M2eProAmazon.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
170
+ M2eProAmazon.text.not_enough_data = '{$notEnoughDataMessage}';
171
+ M2eProAmazon.text.successfully_unmapped = '{$successfullyUnmappedMessage}';
172
+ M2eProAmazon.text.successfully_removed = '{$successfullyRemovedMessage}';
173
+
174
+ M2eProAmazon.text.select_items_message = '{$selectItemsMessage}';
175
+ M2eProAmazon.text.select_action_message = '{$selectActionMessage}';
176
+
177
+ M2eProAmazon.text.automap_progress_title = '{$autoMapProgressTitle}';
178
+ M2eProAmazon.text.processing_data_message = '{$processingDataMessage}';
179
+ M2eProAmazon.text.successfully_mapped = '{$successfullyMappedMessage}';
180
+ M2eProAmazon.text.failed_mapped = '{$someProductsWereNotMappedMessage}';
181
+
182
+ M2eProAmazon.text.select_only_mapped_products = '{$selectOnlyMapped}';
183
+ M2eProAmazon.text.select_the_same_type_products = '{$selectTheSameTypeProducts}';
184
+
185
+ M2eProAmazon.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
186
+
187
+ M2eProAmazon.text.success_word = '{$successWord}';
188
+ M2eProAmazon.text.notice_word = '{$noticeWord}';
189
+ M2eProAmazon.text.warning_word = '{$warningWord}';
190
+ M2eProAmazon.text.error_word = '{$errorWord}';
191
+ M2eProAmazon.text.close_word = '{$closeWord}';
192
+
193
+ M2eProAmazon.customData.componentMode = '{$componentMode}';
194
+ M2eProAmazon.customData.gridId = 'amazonListingOtherGrid';
195
+
196
+ var init = function () {
197
+ AmazonListingOtherGridHandlerObj = new AmazonListingOtherGridHandler('amazonListingOtherGrid');
198
+ AmazonListingOtherMappingHandlerObj = new ListingOtherMappingHandler(
199
+ AmazonListingOtherGridHandlerObj,
200
+ 'amazon'
201
+ );
202
+
203
+ // todo next (temp solution)
204
+ AmazonListingOtherGridHandlerObj.movingHandler.setOptions(M2eProAmazon);
205
+ AmazonListingOtherGridHandlerObj.autoMappingHandler.setOptions(M2eProAmazon);
206
+ AmazonListingOtherGridHandlerObj.removingHandler.setOptions(M2eProAmazon);
207
+ AmazonListingOtherGridHandlerObj.unmappingHandler.setOptions(M2eProAmazon);
208
+ }
209
+
210
+ if ($$('.tabs-horiz').first()) {
211
+ var amazonTabId = $$('.tabs-horiz').first().id + '_amazon';
212
+ $(amazonTabId).observe('click', init);
213
+ }
214
+
215
+ {$this->isAjax} ? init()
216
+ : Event.observe(window, 'load', init);
217
+
218
+ </script>
219
+ JAVASCRIPT;
220
+
221
+ return $javascriptsMain .
222
+ $this->getAmazonTabBlockFilterHtml() .