m2epro_ebay_magento - Version 6.3.4

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 Magento Core Team
Extension m2epro_ebay_magento
Version 6.3.4
Comparing to
See all releases


Code changes from version 1.0.3 to 6.3.4

Files changed (174) 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 +71 -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 +58 -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 +148 -0
  8. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Form.php +37 -0
  9. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs.php +53 -0
  10. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/General.php +54 -0
  11. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/ListingOther.php +31 -0
  12. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Order.php +89 -0
  13. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing.php +42 -0
  14. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Form.php +24 -0
  15. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin.php +124 -0
  16. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category.php +160 -0
  17. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category/Grid.php +344 -0
  18. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual.php +162 -0
  19. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/Grid.php +358 -0
  20. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/SkipPopup.php +41 -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 +286 -0
  23. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php +686 -0
  24. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Help.php +24 -0
  25. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NewAsinPopup.php +41 -0
  26. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NotCompleted.php +31 -0
  27. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/SearchSettings.php +73 -0
  28. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/General.php +25 -0
  29. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Search.php +45 -0
  30. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Selling.php +90 -0
  31. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode.php +13 -0
  32. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category.php +23 -0
  33. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Form.php +34 -0
  34. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Group/Grid.php +18 -0
  35. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Global.php +20 -0
  36. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Website.php +20 -0
  37. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit.php +165 -0
  38. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Form.php +37 -0
  39. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Tabs.php +48 -0
  40. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Grid.php +331 -0
  41. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/Grid.php +162 -0
  42. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View.php +260 -0
  43. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View/Grid.php +575 -0
  44. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product.php +101 -0
  45. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product/Help.php +24 -0
  46. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Grid.php +662 -0
  47. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Main.php +79 -0
  48. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Menu.php +93 -0
  49. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/SuggestedAsinGridHelp.php +25 -0
  50. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search.php +162 -0
  51. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search/Grid.php +869 -0
  52. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Grid.php +459 -0
  53. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Main.php +70 -0
  54. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs.php +148 -0
  55. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php +563 -0
  56. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations.php +40 -0
  57. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Child/Form.php +399 -0
  58. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Grid.php +1592 -0
  59. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Help.php +25 -0
  60. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToIndividualPopup.php +50 -0
  61. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToParentPopup.php +50 -0
  62. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyAttributesPopup.php +49 -0
  63. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyOptionsPopup.php +49 -0
  64. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View.php +756 -0
  65. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php +1596 -0
  66. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Help.php +24 -0
  67. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ListingSwitcher.php +22 -0
  68. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Magento/Grid.php +347 -0
  69. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.php +44 -0
  70. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php +1002 -0
  71. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Marketplace/Form.php +97 -0
  72. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress.php +69 -0
  73. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress/Form.php +59 -0
  74. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Grid.php +571 -0
  75. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View.php +109 -0
  76. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Form.php +114 -0
  77. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Item.php +341 -0
  78. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Synchronization/Form.php +86 -0
  79. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template.php +25 -0
  80. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description.php +48 -0
  81. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Edit.php +99 -0
  82. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs.php +71 -0
  83. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Browse.php +28 -0
  84. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Recent.php +42 -0
  85. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Search.php +28 -0
  86. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add.php +71 -0
  87. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add/Grid.php +248 -0
  88. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit.php +103 -0
  89. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Form.php +39 -0
  90. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs.php +58 -0
  91. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Definition.php +135 -0
  92. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/General.php +60 -0
  93. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Specifics.php +36 -0
  94. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Grid.php +222 -0
  95. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Help.php +18 -0
  96. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Grid.php +39 -0
  97. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit.php +105 -0
  98. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit/Form.php +58 -0
  99. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit.php +110 -0
  100. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Form.php +38 -0
  101. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs.php +65 -0
  102. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/List.php +25 -0
  103. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Relist.php +25 -0
  104. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Revise.php +25 -0
  105. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Stop.php +25 -0
  106. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit.php +154 -0
  107. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Form.php +37 -0
  108. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs.php +56 -0
  109. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/General.php +80 -0
  110. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/ListingOther.php +31 -0
  111. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/Order.php +89 -0
  112. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing.php +41 -0
  113. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Form.php +24 -0
  114. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/General.php +25 -0
  115. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Search.php +42 -0
  116. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Selling.php +86 -0
  117. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode.php +13 -0
  118. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category.php +23 -0
  119. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Form.php +13 -0
  120. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Group/Grid.php +18 -0
  121. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Global.php +13 -0
  122. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Website.php +13 -0
  123. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit.php +165 -0
  124. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Form.php +37 -0
  125. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Tabs.php +48 -0
  126. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Grid.php +325 -0
  127. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/Grid.php +85 -0
  128. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View.php +266 -0
  129. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View/Grid.php +534 -0
  130. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product.php +100 -0
  131. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product/Help.php +24 -0
  132. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Grid.php +245 -0
  133. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Main.php +66 -0
  134. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Menu.php +35 -0
  135. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search.php +160 -0
  136. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search/Grid.php +608 -0
  137. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View.php +598 -0
  138. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Grid.php +974 -0
  139. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Help.php +24 -0
  140. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/ListingSwitcher.php +22 -0
  141. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress.php +69 -0
  142. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress/Form.php +60 -0
  143. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Grid.php +436 -0
  144. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View.php +76 -0
  145. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Form.php +116 -0
  146. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Item.php +242 -0
  147. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Synchronization/Form.php +86 -0
  148. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template.php +24 -0
  149. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Grid.php +39 -0
  150. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct.php +82 -0
  151. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit.php +91 -0
  152. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Form.php +71 -0
  153. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs.php +56 -0
  154. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Attributes.php +43 -0
  155. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Description.php +77 -0
  156. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/General.php +123 -0
  157. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Grid.php +197 -0
  158. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Help.php +24 -0
  159. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Search/Grid.php +160 -0
  160. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit.php +105 -0
  161. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit/Form.php +54 -0
  162. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit.php +106 -0
  163. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Form.php +37 -0
  164. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs.php +60 -0
  165. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/List.php +24 -0
  166. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Relist.php +25 -0
  167. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Revise.php +25 -0
  168. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Stop.php +24 -0
  169. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Abstract.php +294 -0
  170. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Grid/Container.php +89 -0
  171. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Tabs.php +30 -0
  172. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Tabs/Container.php +19 -0
  173. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Configuration.php +65 -0
  174. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Configuration/Tabs.php +109 -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,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ($this->getData('component_mode') == Ess_M2ePro_Helper_Component_Ebay::NICK) {
16
+ return Mage::helper('M2ePro')->__('eBay User ID');
17
+ }
18
+
19
+ return Mage::helper('M2ePro')->__($this->getComponentLabel('%component% Account'));
20
+ }
21
+
22
+ public function getItems()
23
+ {
24
+ $collection = Mage::getModel('M2ePro/Account')->getCollection()
25
+ ->setOrder('component_mode', 'ASC')
26
+ ->setOrder('title', 'ASC');
27
+
28
+ if (!is_null($this->getData('component_mode'))) {
29
+ $collection->addFieldToFilter('component_mode', $this->getData('component_mode'));
30
+ }
31
+
32
+ if ($collection->getSize() < 2) {
33
+ return array();
34
+ }
35
+
36
+ $items = array();
37
+
38
+ foreach ($collection as $account) {
39
+ /** @var $account Ess_M2ePro_Model_Account */
40
+
41
+ if (!isset($items[$account->getComponentMode()]['label'])) {
42
+ $label = '';
43
+ if (isset($componentTitles[$account->getComponentMode()])) {
44
+ $label = $componentTitles[$account->getComponentMode()];
45
+ }
46
+
47
+ $items[$account->getComponentMode()]['label'] = $label;
48
+ }
49
+
50
+ $items[$account->getComponentMode()]['value'][] = array(
51
+ 'value' => $account->getId(),
52
+ 'label' => $account->getTitle()
53
+ );
54
+ }
55
+
56
+ return $items;
57
+ }
58
+
59
+ // ########################################
60
+
61
+ public function getDefaultOptionName()
62
+ {
63
+ if ($this->getData('component_mode') == Ess_M2ePro_Helper_Component_Ebay::NICK) {
64
+ return Mage::helper('M2ePro')->__('All Users');
65
+ }
66
+
67
+ return Mage::helper('M2ePro')->__('All Accounts');
68
+ }
69
+
70
+ // ########################################
71
+ }
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,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = '';
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
+ // ########################################
58
+ }
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
+
11
+ protected function _prepareCollection()
12
+ {
13
+ // Get collection of accounts
14
+ $collection = Mage::getModel('M2ePro/Account')->getCollection();
15
+
16
+ $collection->getSelect()
17
+ ->joinLeft(array('aa'=>Mage::getResourceModel('M2ePro/Amazon_Account')->getMainTable()),
18
+ '(`aa`.`account_id` = `main_table`.`id`)',
19
+ array())
20
+ ->joinLeft(array('m'=>Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
21
+ '(`m`.`id` = `aa`.`marketplace_id`)',
22
+ array('marketplace_title'=>'title'));
23
+
24
+ // Set collection to grid
25
+ $this->setCollection($collection);
26
+
27
+ return parent::_prepareCollection();
28
+ }
29
+
30
+ // ####################################
31
+
32
+ protected function _prepareColumns()
33
+ {
34
+ $this->addColumn('id', array(
35
+ 'header' => Mage::helper('M2ePro')->__('ID'),
36
+ 'align' => 'right',
37
+ 'width' => '100px',
38
+ 'type' => 'number',
39
+ 'index' => 'id',
40
+ 'filter_index' => 'main_table.id'
41
+ ));
42
+
43
+ $this->addColumn('title', array(
44
+ 'header' => Mage::helper('M2ePro')->__('Title / Info'),
45
+ 'align' => 'left',
46
+ //'width' => '200px',
47
+ 'type' => 'text',
48
+ 'index' => 'title',
49
+ 'escape' => true,
50
+ 'filter_index' => 'main_table.title',
51
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
52
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
53
+ ));
54
+
55
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
56
+ $this->addColumn('component_mode', array(
57
+ 'header' => Mage::helper('M2ePro')->__('Channel'),
58
+ 'align' => 'left',
59
+ 'width' => '120px',
60
+ 'type' => 'options',
61
+ 'index' => 'component_mode',
62
+ 'filter_index' => 'main_table.component_mode',
63
+ 'sortable' => false,
64
+ 'options' => Mage::helper('M2ePro/View_Common_Component')->getActiveComponentsTitles()
65
+ ));
66
+ }
67
+
68
+ return parent::_prepareColumns();
69
+ }
70
+
71
+ // ####################################
72
+
73
+ public function callbackColumnTitle($value, $row, $column, $isExport)
74
+ {
75
+ if ($row->isComponentModeAmazon()) {
76
+ $account = Mage::helper('M2ePro')->__('Account');
77
+ $marketplace = Mage::helper('M2ePro')->__('Marketplace');
78
+
79
+ $marketplaceTitle = $row->getData('marketplace_title');
80
+ $value = <<<HTML
81
+ <div>
82
+ {$value}<br/>
83
+ <span style="font-weight: bold">{$marketplace}</span>: <span style="color: #505050">{$marketplaceTitle}</span><br/>
84
+ </div>
85
+ HTML;
86
+ }
87
+
88
+ return $value;
89
+ }
90
+
91
+ // ####################################
92
+
93
+ protected function callbackFilterTitle($collection, $column)
94
+ {
95
+ $value = $column->getFilter()->getValue();
96
+
97
+ if ($value == null) {
98
+ return;
99
+ }
100
+
101
+ $collection->getSelect()->where('main_table.title LIKE ? OR m.title LIKE ?', '%'. $value .'%');
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,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonAccountEdit');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_amazon_account';
20
+ $this->_mode = 'edit';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
27
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit %component_name% Account", $componentName);
28
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add %component_name% Account", $componentName);
29
+ } else {
30
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit Account");
31
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add Account");
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(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
39
+ ->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
+ /* @var $wizardHelper Ess_M2ePro_Helper_Module_Wizard */
56
+ $wizardHelper = Mage::helper('M2ePro/Module_Wizard');
57
+
58
+ if ($wizardHelper->isActive('amazon') &&
59
+ $wizardHelper->getStep('amazon') == 'account') {
60
+
61
+ //------------------------------
62
+ $this->_addButton('save_and_continue', array(
63
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
64
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
65
+ 'class' => 'save'
66
+ ));
67
+ //------------------------------
68
+
69
+ if ($this->getRequest()->getParam('id')) {
70
+ //------------------------------
71
+ $url = $this->getUrl('*/adminhtml_common_amazon_account/new', array('wizard' => true));
72
+ $this->_addButton('add_new_account', array(
73
+ 'label' => Mage::helper('M2ePro')->__('Add New Account'),
74
+ 'onclick' => 'setLocation(\''. $url .'\')',
75
+ 'class' => 'add_new_account'
76
+ ));
77
+ //------------------------------
78
+
79
+ //------------------------------
80
+ $this->_addButton('close', array(
81
+ 'label' => Mage::helper('M2ePro')->__('Complete This Step'),
82
+ 'onclick' => 'AmazonAccountHandlerObj.completeStep();',
83
+ 'class' => 'close'
84
+ ));
85
+ //------------------------------
86
+ }
87
+ } else {
88
+
89
+ if ((bool)$this->getRequest()->getParam('close_on_save',false)) {
90
+
91
+ if ($this->getRequest()->getParam('id')) {
92
+ $this->_addButton('save', array(
93
+ 'label' => Mage::helper('M2ePro')->__('Save And Close'),
94
+ 'onclick' => 'AmazonAccountHandlerObj.saveAndClose()',
95
+ 'class' => 'save'
96
+ ));
97
+ } else {
98
+ $this->_addButton('save_and_continue', array(
99
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
100
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
101
+ 'class' => 'save'
102
+ ));
103
+ }
104
+ return;
105
+ }
106
+
107
+ //------------------------------
108
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
109
+ $this->_addButton('back', array(
110
+ 'label' => Mage::helper('M2ePro')->__('Back'),
111
+ 'onclick' => 'AmazonAccountHandlerObj.back_click(\''. $url .'\')',
112
+ 'class' => 'back'
113
+ ));
114
+ //------------------------------
115
+
116
+ //------------------------------
117
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
118
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
119
+ ) {
120
+ //------------------------------
121
+ $this->_addButton('delete', array(
122
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
123
+ 'onclick' => 'AmazonAccountHandlerObj.delete_click()',
124
+ 'class' => 'delete M2ePro_delete_button'
125
+ ));
126
+ //------------------------------
127
+ }
128
+
129
+ //------------------------------
130
+ $this->_addButton('save', array(
131
+ 'label' => Mage::helper('M2ePro')->__('Save'),
132
+ 'onclick' => 'AmazonAccountHandlerObj.save_click()',
133
+ 'class' => 'save'
134
+ ));
135
+ //------------------------------
136
+
137
+ //------------------------------
138
+ $this->_addButton('save_and_continue', array(
139
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
140
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
141
+ 'class' => 'save'
142
+ ));
143
+ //------------------------------
144
+ }
145
+ }
146
+
147
+ // ####################################
148
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Form.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_Account_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('amazonAccountEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareForm()
22
+ {
23
+ $form = new Varien_Data_Form(array(
24
+ 'id' => 'edit_form',
25
+ 'action' => $this->getUrl('*/*/save'),
26
+ 'method' => 'post',
27
+ 'enctype' => 'multipart/form-data'
28
+ ));
29
+
30
+ $form->setUseContainer(true);
31
+ $this->setForm($form);
32
+
33
+ return parent::_prepareForm();
34
+ }
35
+
36
+ // ####################################
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonAccountEditTabs');
18
+ //------------------------------
19
+
20
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
21
+ $this->setDestElementId('edit_form');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ $this->addTab('general', array(
27
+ 'label' => Mage::helper('M2ePro')->__('General'),
28
+ 'title' => Mage::helper('M2ePro')->__('General'),
29
+ 'content' => $this->getLayout()
30
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_general')->toHtml(),
31
+ ));
32
+
33
+ $this->addTab('listingOther', array(
34
+ 'label' => Mage::helper('M2ePro')->__('3rd Party Listings'),
35
+ 'title' => Mage::helper('M2ePro')->__('3rd Party Listings'),
36
+ 'content' => $this->getLayout()
37
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_listingOther')->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_amazon_account_edit_tabs_order')->toHtml(),
45
+ ));
46
+
47
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
48
+
49
+ return parent::_beforeToHtml();
50
+ }
51
+
52
+ // ####################################
53
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/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_Amazon_Account_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('amazonAccountEditTabsGeneral');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/general.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ $this->synchronizeProcessing = false;
26
+
27
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
28
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) {
29
+
30
+ /** @var $accountObj Ess_M2ePro_Model_Account */
31
+ $accountObj = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
32
+
33
+ $this->synchronizeProcessing = $accountObj->isLockedObject('server_synchronize');
34
+
35
+ if (!$this->synchronizeProcessing) {
36
+ $accountId = $accountObj->getId();
37
+
38
+ Mage::helper('M2ePro/Data_Global')->unsetValue('temp_data');
39
+ Mage::helper('M2ePro/Data_Global')->setValue(
40
+ 'temp_data',
41
+ Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Account',$accountId)
42
+ );
43
+ }
44
+ }
45
+
46
+ $marketplaces = Mage::helper('M2ePro/Component_Amazon')->getMarketplacesAvailableForApiCreation();
47
+ $marketplaces = $marketplaces->toArray();
48
+ $this->marketplaces = $marketplaces['items'];
49
+
50
+ return parent::_beforeToHtml();
51
+ }
52
+
53
+ // ####################################
54
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/ListingOther.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonAccountEditTabsListingOther');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/listing_other.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
26
+
27
+ return parent::_beforeToHtml();
28
+ }
29
+
30
+ // ####################################
31
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Order.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('amazonAccountEditTabsOrder');
20
+ //------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/order.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
28
+ $magentoOrdersSettings = !empty($data['magento_orders_settings'])
29
+ ? json_decode($data['magento_orders_settings'], true) : array();
30
+
31
+ //----------------------------
32
+ $temp = Mage::getModel('core/website')->getCollection()->setOrder('sort_order','ASC')->toArray();
33
+ $this->websites = $temp['items'];
34
+ //----------------------------
35
+
36
+ //----------------------------
37
+ $temp = Mage::getModel('customer/group')->getCollection()->toArray();
38
+ $this->groups = $temp['items'];
39
+ //----------------------------
40
+
41
+ //----------------------------
42
+ $selectedStore = !empty($magentoOrdersSettings['listing']['store_id'])
43
+ ? $magentoOrdersSettings['listing']['store_id'] : '';
44
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
45
+ 'id' => 'magento_orders_listings_store_id',
46
+ 'name' => 'magento_orders_settings[listing][store_id]',
47
+ 'selected' => $selectedStore
48
+ ));
49
+ $blockStoreSwitcher->hasDefaultOption(false);
50
+ $this->setChild('magento_orders_listings_store_id', $blockStoreSwitcher);
51
+ //----------------------------
52
+
53
+ //----------------------------
54
+ $selectedStore = !empty($magentoOrdersSettings['listing_other']['store_id'])
55
+ ? $magentoOrdersSettings['listing_other']['store_id'] : '';
56
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
57
+ 'id' => 'magento_orders_listings_other_store_id',
58
+ 'name' => 'magento_orders_settings[listing_other][store_id]',
59
+ 'selected' => $selectedStore
60
+ ));
61
+ $blockStoreSwitcher->hasDefaultOption(false);
62
+ $this->setChild('magento_orders_listings_other_store_id', $blockStoreSwitcher);
63
+ //----------------------------
64
+
65
+ //----------------------------
66
+ $productTaxClasses = Mage::getModel('tax/class')->getCollection()
67
+ ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)
68
+ ->toOptionArray();
69
+
70
+ $none = array('value' => Ess_M2ePro_Model_Magento_Product::TAX_CLASS_ID_NONE, 'label' => 'None');
71
+ array_unshift($productTaxClasses, $none);
72
+
73
+ $this->productTaxClasses = $productTaxClasses;
74
+ //----------------------------
75
+
76
+ return parent::_beforeToHtml();
77
+ }
78
+
79
+ public function getMagentoOrderStatusList()
80
+ {
81
+ if (is_null($this->_possibleMagentoStatuses)) {
82
+ $this->_possibleMagentoStatuses = Mage::getSingleton('sales/order_config')->getStatuses();
83
+ }
84
+
85
+ return $this->_possibleMagentoStatuses;
86
+ }
87
+
88
+ // ####################################
89
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing.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_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
+ $this->setTemplate('M2ePro/widget/grid/container/only_content.phtml');
38
+
39
+ }
40
+
41
+ // ####################################
42
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Form.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
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->setId('amazonListingEditForm');
20
+ //------------------------------
21
+ }
22
+
23
+ // ########################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Ess_M2ePro_Block_Adminhtml_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 getHeaderWidth()
44
+ {
45
+ return 'width:50%;';
46
+ }
47
+
48
+ // ####################################
49
+
50
+ protected function _beforeToHtml()
51
+ {
52
+ parent::_beforeToHtml();
53
+
54
+ $listing = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
55
+ 'Listing', $this->getRequest()->getParam('id')
56
+ );
57
+
58
+ $viewHeaderBlock = $this->getLayout()->createBlock(
59
+ 'M2ePro/adminhtml_listing_view_header','',
60
+ array('listing' => $listing)
61
+ );
62
+
63
+ $this->setChild('view_header', $viewHeaderBlock);
64
+
65
+ // ------------------------------------------------
66
+ $buttonBlock = $this->getLayout()
67
+ ->createBlock('adminhtml/widget_button')
68
+ ->setData( array(
69
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
70
+ 'onclick' => '',
71
+ ) );
72
+ $this->setChild('mode_same_remember_pop_up_confirm_button',$buttonBlock);
73
+ }
74
+
75
+ // ####################################
76
+
77
+ /**
78
+ * @return Ess_M2ePro_Model_Listing
79
+ * @throws Exception
80
+ */
81
+ public function getListing()
82
+ {
83
+ if (!$listingId = $this->getRequest()->getParam('id')) {
84
+ throw new Exception('Listing is not defined');
85
+ }
86
+
87
+ if (is_null($this->listing)) {
88
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
89
+ ->getObject('Listing', $listingId);
90
+ }
91
+
92
+ return $this->listing;
93
+ }
94
+
95
+ // ####################################
96
+
97
+ public function getProductsIds()
98
+ {
99
+ return $this->getListing()->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
100
+ }
101
+
102
+ // ####################################
103
+
104
+ public function getDescriptionTemplateMode()
105
+ {
106
+ $listingAdditionalData = $this->getListing()->getData('additional_data');
107
+ $listingAdditionalData = json_decode($listingAdditionalData, true);
108
+
109
+ $mode = 'same';
110
+
111
+ $sessionMode = Mage::helper('M2ePro/Data_Session')->getValue('products_source');
112
+ if ($sessionMode == 'category') {
113
+ $mode = $sessionMode;
114
+ }
115
+
116
+ if (!empty($listingAdditionalData['new_asin_mode'])) {
117
+ $mode = $listingAdditionalData['new_asin_mode'];
118
+ }
119
+
120
+ return $mode;
121
+ }
122
+
123
+ // ####################################
124
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category.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_Amazon_Listing_Add_NewAsin_Category
8
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('newAsinDescriptionTemplateCategory');
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_category';
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
+
49
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
50
+ //------------------------------
51
+ $this->_addButton('save_and_go_to_listing_view', array(
52
+ 'id' => 'save_and_go_to_listing_view',
53
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
54
+ 'onclick' => 'ListingGridHandlerObj.checkCategoryProducts(\''.$url.'\')',
55
+ 'class' => 'scalable next'
56
+ ));
57
+ //------------------------------
58
+ }
59
+
60
+ public function getGridHtml()
61
+ {
62
+ $listing = Mage::helper('M2ePro/Component')
63
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
64
+
65
+ $viewHeaderBlock = $this->getLayout()->createBlock(
66
+ 'M2ePro/adminhtml_listing_view_header','',
67
+ array('listing' => $listing)
68
+ );
69
+
70
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml();
71
+ }
72
+
73
+ protected function _toHtml()
74
+ {
75
+ $helper = Mage::helper('M2ePro');
76
+
77
+ // --------TEXT------------------
78
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
79
+ // -------------------------------
80
+
81
+ // ---------URL-------------------
82
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
83
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
84
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
85
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
86
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/*/viewTemplateDescriptionsGrid');
87
+
88
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
89
+ $unmapFromNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
90
+
91
+ $checkNewAsinCategoryProducts = $this->getUrl('*/*/checkNewAsinCategoryProducts', array('_current' => true));
92
+ // -------------------------------
93
+
94
+ $javascript = <<<HTML
95
+ <script type="text/javascript">
96
+ selectTemplateDescription = function (el, templateId, mapToGeneralId)
97
+ {
98
+ ListingGridHandlerObj.mapToTemplateDescription(el, templateId, mapToGeneralId);
99
+ };
100
+
101
+ if (typeof M2ePro == 'undefined') {
102
+ M2ePro = {};
103
+ M2ePro.url = {};
104
+ M2ePro.formData = {};
105
+ M2ePro.customData = {};
106
+ M2ePro.text = {};
107
+ }
108
+
109
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
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.checkNewAsinCategoryProducts = '{$checkNewAsinCategoryProducts}';
120
+
121
+ Event.observe(window, 'load', function() {
122
+
123
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
124
+
125
+ ListingGridHandlerObj = new CommonAmazonListingNewAsinTemplateDescriptionGridHandler(
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
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category/Grid.php ADDED
@@ -0,0 +1,344 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ //------------------------------
21
+ $this->setId('newAsinCategoryGrid');
22
+ //------------------------------
23
+
24
+ // Set default values
25
+ //------------------------------
26
+ $this->setDefaultSort('id');
27
+ $this->setDefaultDir('DESC');
28
+ $this->setUseAjax(true);
29
+ //------------------------------
30
+
31
+ $this->prepareDataByCategories();
32
+ }
33
+
34
+ // ####################################
35
+
36
+ protected function _prepareCollection()
37
+ {
38
+ /* @var $collection Mage_Catalog_Model_Resource_Category_Collection */
39
+ $collection = Mage::getModel('catalog/category')->getCollection();
40
+ $collection->addAttributeToSelect('name');
41
+
42
+ $collection->addFieldToFilter(array(
43
+ array('attribute' => 'entity_id', 'in' => array_keys($this->getData('categories_data')))
44
+ ));
45
+
46
+ $this->setCollection($collection);
47
+
48
+ return parent::_prepareCollection();
49
+ }
50
+
51
+ // ####################################
52
+
53
+ protected function _prepareColumns()
54
+ {
55
+ $this->addColumn('magento_category', array(
56
+ 'header' => Mage::helper('M2ePro')->__('Magento Category'),
57
+ 'align' => 'left',
58
+ 'width' => '500px',
59
+ 'type' => 'text',
60
+ 'index' => 'name',
61
+ 'filter' => false,
62
+ 'sortable' => false,
63
+ 'frame_callback' => array($this, 'callbackColumnMagentoCategory')
64
+ ));
65
+
66
+ $this->addColumn('description_template', array(
67
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
68
+ 'align' => 'left',
69
+ 'width' => '*',
70
+ 'sortable' => false,
71
+ 'type' => 'options',
72
+ 'index' => 'description_template_id',
73
+ 'filter_index' => 'description_template_id',
74
+ 'options' => array(
75
+ 1 => Mage::helper('M2ePro')->__('Description Policy Selected'),
76
+ 0 => Mage::helper('M2ePro')->__('Description Policy Not Selected')
77
+ ),
78
+ 'frame_callback' => array($this, 'callbackColumnDescriptionTemplateCallback'),
79
+ 'filter_condition_callback' => array($this, 'callbackColumnDescriptionTemplateFilterCallback')
80
+ ));
81
+
82
+ $actionsColumn = array(
83
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
84
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
85
+ 'align' => 'center',
86
+ 'width' => '130px',
87
+ 'type' => 'text',
88
+ 'sortable' => false,
89
+ 'filter' => false,
90
+ 'actions' => array()
91
+ );
92
+
93
+ $actions = array(
94
+ array(
95
+ 'caption' => Mage::helper('M2ePro')->__('Set Description Policy'),
96
+ 'field' => 'entity_id',
97
+ 'onclick_action' => 'ListingGridHandlerObj.setDescriptionTemplateByCategoryRowAction'
98
+ ),
99
+ array(
100
+ 'caption' => Mage::helper('M2ePro')->__('Reset Description Policy'),
101
+ 'field' => 'entity_id',
102
+ 'onclick_action' => 'ListingGridHandlerObj.resetDescriptionTemplateByCategoryRowAction'
103
+ )
104
+ );
105
+
106
+ $actionsColumn['actions'] = $actions;
107
+
108
+ $this->addColumn('actions', $actionsColumn);
109
+
110
+ return parent::_prepareColumns();
111
+ }
112
+
113
+ // ####################################
114
+
115
+ protected function _prepareMassaction()
116
+ {
117
+ $this->setMassactionIdField('entity_id');
118
+ $this->setMassactionIdFieldOnlyIndexValue(true);
119
+
120
+ //--------------------------------
121
+ $this->getMassactionBlock()->addItem('setDescriptionTemplateByCategory', array(
122
+ 'label' => Mage::helper('M2ePro')->__('Set Description Policy'),
123
+ 'url' => ''
124
+ ));
125
+
126
+ $this->getMassactionBlock()->addItem('resetDescriptionTemplateByCategory', array(
127
+ 'label' => Mage::helper('M2ePro')->__('Reset Description Policy'),
128
+ 'url' => ''
129
+ ));
130
+ //--------------------------------
131
+
132
+ return parent::_prepareMassaction();
133
+ }
134
+
135
+ // ########################################
136
+
137
+ public function callbackColumnDescriptionTemplateCallback($value, $row, $column, $isExport)
138
+ {
139
+ $categoriesData = $this->getData('categories_data');
140
+ $productsIds = implode(',', $categoriesData[$row->getData('entity_id')]);
141
+
142
+ $descriptionTemplatesData = $this->getData('description_templates_data');
143
+ $descriptionTemplatesIds = array();
144
+ foreach ($categoriesData[$row->getData('entity_id')] as $productId) {
145
+ if (empty($descriptionTemplatesIds[$descriptionTemplatesData[$productId]])) {
146
+ $descriptionTemplatesIds[$descriptionTemplatesData[$productId]] = 0;
147
+ }
148
+ $descriptionTemplatesIds[$descriptionTemplatesData[$productId]]++;
149
+ }
150
+
151
+ arsort($descriptionTemplatesIds);
152
+
153
+ reset($descriptionTemplatesIds);
154
+ $descriptionTemplateId = key($descriptionTemplatesIds);
155
+
156
+ if (empty($descriptionTemplateId)) {
157
+ $iconSrc = $this->getSkinUrl('M2ePro/images/warning.png');
158
+ $label = Mage::helper('M2ePro')->__('Not Selected');
159
+
160
+ return <<<HTML
161
+ <img src="{$iconSrc}" alt="">&nbsp;<span style="color: gray; font-style: italic;">{$label}</span>
162
+ <input type="hidden" id="products_ids_{$row->getData('entity_id')}" value="{$productsIds}">
163
+ HTML;
164
+ }
165
+
166
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
167
+ 'id' => $descriptionTemplateId
168
+ ));
169
+
170
+ /** @var Ess_M2ePro_Model_Amazon_Template_Description $descriptionTemplate */
171
+ $descriptionTemplate = Mage::helper('M2ePro/Component_Amazon')
172
+ ->getModel('Template_Description')->load($descriptionTemplateId);
173
+
174
+ $title = Mage::helper('M2ePro')->escapeHtml($descriptionTemplate->getData('title'));
175
+
176
+ return <<<HTML
177
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
178
+ <input type="hidden" id="products_ids_{$row->getData('entity_id')}" value="{$productsIds}">
179
+ HTML;
180
+ }
181
+
182
+ // ########################################
183
+
184
+ protected function callbackColumnDescriptionTemplateFilterCallback($collection, $column)
185
+ {
186
+ $value = $column->getFilter()->getValue();
187
+
188
+ if ($value == null) {
189
+ return;
190
+ }
191
+
192
+ $filteredProductsCategories = array();
193
+ $filteredListingProductsIds = array();
194
+
195
+ $categoriesData = $this->getData('categories_data');
196
+ $descriptionTemplatesIds = $this->getData('description_templates_data');
197
+
198
+ foreach ($descriptionTemplatesIds as $listingProductId => $descriptionTemplateId) {
199
+ if ($descriptionTemplateId !== NULL) {
200
+ $filteredListingProductsIds[] = $listingProductId;
201
+ }
202
+ }
203
+
204
+ foreach ($categoriesData as $categoryId => $listingProducts) {
205
+ foreach ($filteredListingProductsIds as $listingProductId) {
206
+ if (in_array($listingProductId, $listingProducts)) {
207
+ $filteredProductsCategories[] = $categoryId;
208
+ }
209
+ }
210
+ }
211
+
212
+ $filteredProductsCategories = array_unique($filteredProductsCategories);
213
+
214
+ if ($value) {
215
+ $collection->addFieldToFilter('entity_id', array('in' => $filteredProductsCategories));
216
+ } else if (!empty($filteredProductsCategories)){
217
+ $collection->addFieldToFilter('entity_id', array('nin' => $filteredProductsCategories));
218
+ }
219
+ }
220
+
221
+ // ########################################
222
+
223
+ public function getRowUrl($row)
224
+ {
225
+ return false;
226
+ }
227
+
228
+ // ####################################
229
+
230
+ protected function _toHtml()
231
+ {
232
+ $addErrorJs = '';
233
+
234
+ if (count($this->getData('categories_data')) === 0) {
235
+ $msg = Mage::helper('M2ePro')
236
+ ->__('Magento Categories are not specified for Products you are adding.');
237
+
238
+ $addErrorJs = <<<JS
239
+ MagentoMessageObj['addError']('{$msg}');
240
+ $('save_and_go_to_listing_view').addClassName('disabled').onclick = function() {
241
+ return null;
242
+ };
243
+ JS;
244
+
245
+ }
246
+
247
+ $javascriptsMain = <<<JAVASCRIPT
248
+ <script type="text/javascript">
249
+
250
+ if (typeof ListingGridHandlerObj != 'undefined') {
251
+ ListingGridHandlerObj.afterInitPage();
252
+ }
253
+
254
+ {$addErrorJs}
255
+
256
+ Event.observe(window, 'load', function() {
257
+ setTimeout(function() {
258
+ ListingGridHandlerObj.afterInitPage();
259
+ }, 350);
260
+ });
261
+
262
+ </script>
263
+ JAVASCRIPT;
264
+
265
+ return parent::_toHtml() . $javascriptsMain;
266
+ }
267
+
268
+ // ####################################
269
+
270
+ /**
271
+ * @return Ess_M2ePro_Model_Amazon_Listing
272
+ * @throws Exception
273
+ */
274
+ public function getListing()
275
+ {
276
+ if (!$listingId = $this->getRequest()->getParam('id')) {
277
+ throw new Exception('Listing is not defined');
278
+ }
279
+
280
+ if (is_null($this->listing)) {
281
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
282
+ ->getObject('Listing', $listingId);
283
+ }
284
+
285
+ return $this->listing;
286
+ }
287
+
288
+ // ####################################
289
+
290
+ private function prepareDataByCategories()
291
+ {
292
+ $listingProductsIds = $this->getListing()
293
+ ->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
294
+
295
+ $listingProductCollection = Mage::helper('M2ePro/Component_Amazon')
296
+ ->getCollection('Listing_Product')
297
+ ->addFieldToFilter('id',array('in' => $listingProductsIds));
298
+
299
+ $productsIds = array();
300
+ $descriptionTemplatesIds = array();
301
+ foreach ($listingProductCollection->getData() as $item) {
302
+ $productsIds[$item['id']] = $item['product_id'];
303
+ $descriptionTemplatesIds[$item['id']] = $item['template_description_id'];
304
+ }
305
+ $productsIds = array_unique($productsIds);
306
+
307
+ $categoriesIds = Mage::helper('M2ePro/Magento_Category')->getLimitedCategoriesByProducts(
308
+ $productsIds,
309
+ $this->getListing()->getStoreId()
310
+ );
311
+
312
+ $categoriesData = array();
313
+
314
+ foreach ($categoriesIds as $categoryId) {
315
+ /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
316
+ $collection = Mage::getModel('catalog/product')->getCollection();
317
+ $collection->addFieldToFilter('entity_id', array('in' => $productsIds));
318
+
319
+ $collection->joinTable(
320
+ array('ccp' => 'catalog/category_product'),
321
+ 'product_id=entity_id',
322
+ array('category_id' => 'category_id')
323
+ );
324
+ $collection->addFieldToFilter('category_id', $categoryId);
325
+
326
+ $data = $collection->getData();
327
+
328
+ foreach ($data as $item) {
329
+ $categoriesData[$categoryId][] = array_search($item['entity_id'], $productsIds);
330
+ }
331
+
332
+ $categoriesData[$categoryId] = array_unique($categoriesData[$categoryId]);
333
+ }
334
+
335
+ $this->setData('categories_data', $categoriesData);
336
+ $this->setData('description_templates_data', $descriptionTemplatesIds);
337
+
338
+ $this->getListing()
339
+ ->setSetting('additional_data', 'adding_new_asin_description_templates_data', $descriptionTemplatesIds);
340
+ $this->getListing()->save();
341
+ }
342
+
343
+ // ####################################
344
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $listingId = $this->getRequest()->getParam('id');
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('newAsinDescriptionTemplateManual');
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ $this->_headerText = Mage::helper('M2ePro')->__("Set Description Policy for New ASIN/ISBN Creation");
26
+ $this->_blockGroup = 'M2ePro';
27
+ $this->_controller = 'adminhtml_common_amazon_listing_add_newAsin_manual';
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('*/*/resetNewAsin', array(
42
+ '_current' => true
43
+ ));
44
+ $this->_addButton('back', array(
45
+ 'label' => Mage::helper('M2ePro')->__('Back'),
46
+ 'onclick' => 'ListingGridHandlerObj.back_click(\'' . $url . '\')',
47
+ 'class' => 'back'
48
+ ));
49
+
50
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
51
+ //------------------------------
52
+ $this->_addButton('save_and_go_to_listing_view', array(
53
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
54
+ 'onclick' => 'ListingGridHandlerObj.checkManualProducts(\''.$url.'\')',
55
+ 'class' => 'scalable next'
56
+ ));
57
+ //------------------------------
58
+ }
59
+
60
+ public function getGridHtml()
61
+ {
62
+ $listing = Mage::helper('M2ePro/Component')
63
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
64
+
65
+ $viewHeaderBlock = $this->getLayout()->createBlock(
66
+ 'M2ePro/adminhtml_listing_view_header','',
67
+ array('listing' => $listing)
68
+ );
69
+
70
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml();
71
+ }
72
+
73
+ protected function _toHtml()
74
+ {
75
+ $helper = Mage::helper('M2ePro');
76
+
77
+ // --------TEXT------------------
78
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
79
+ $setDescriptionPolicy = $helper->escapeJs($helper->__('Set Description Policy.'));
80
+ // -------------------------------
81
+
82
+ // ---------URL-------------------
83
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
84
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
85
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
86
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
87
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/*/viewTemplateDescriptionsGrid');
88
+
89
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
90
+ $unmapFromNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
91
+
92
+ $checkNewAsinManualProducts = $this->getUrl('*/*/checkNewAsinManualProducts', array('_current' => true));
93
+ // -------------------------------
94
+
95
+ $javascript = <<<HTML
96
+ <script type="text/javascript">
97
+ selectTemplateDescription = function (el, templateId, mapToGeneralId)
98
+ {
99
+ ListingGridHandlerObj.mapToTemplateDescription(el, templateId, mapToGeneralId);
100
+ };
101
+
102
+ if (typeof M2ePro == 'undefined') {
103
+ M2ePro = {};
104
+ M2ePro.url = {};
105
+ M2ePro.formData = {};
106
+ M2ePro.customData = {};
107
+ M2ePro.text = {};
108
+ }
109
+
110
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
111
+ M2ePro.text.setDescriptionPolicy = '{$setDescriptionPolicy}';
112
+
113
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
114
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
115
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
116
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
117
+
118
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
119
+ M2ePro.url.unmapFromNewAsin = '{$unmapFromNewAsin}';
120
+
121
+ M2ePro.url.checkNewAsinManualProducts = '{$checkNewAsinManualProducts}';
122
+
123
+ Event.observe(window, 'load', function() {
124
+
125
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
126
+
127
+ ListingGridHandlerObj = new CommonAmazonListingNewAsinTemplateDescriptionGridHandler(
128
+ '{$this->getChild('grid')->getId()}',
129
+ {$this->getListing()->getId()}
130
+ );
131
+
132
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
133
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
134
+ });
135
+
136
+ </script>
137
+ HTML;
138
+
139
+ return $javascript .
140
+ '<div id="search_asin_products_container">' .
141
+ parent::_toHtml() .
142
+ '</div>';
143
+ }
144
+
145
+ // ####################################
146
+
147
+ public function getListing()
148
+ {
149
+ if (!$listingId = $this->getRequest()->getParam('id')) {
150
+ throw new Exception('Listing is not defined');
151
+ }
152
+
153
+ if (is_null($this->listing)) {
154
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
155
+ ->getObject('Listing', $listingId)->getChildObject();
156
+ }
157
+
158
+ return $this->listing;
159
+ }
160
+
161
+ // ####################################
162
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/Grid.php ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ //------------------------------
21
+ $this->setId('newAsinManualGrid');
22
+ //------------------------------
23
+
24
+ // Set default values
25
+ //------------------------------
26
+ $this->setDefaultSort('product_id');
27
+ $this->setDefaultDir('DESC');
28
+ $this->setUseAjax(true);
29
+ //------------------------------
30
+ }
31
+
32
+ // ####################################
33
+
34
+ protected function _prepareCollection()
35
+ {
36
+ // Get collection
37
+ //----------------------------
38
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
39
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
40
+ Mage::getModel('catalog/product')->getResource())
41
+ ->setStoreId($this->getListing()->getData('store_id'))
42
+ ->setListingProductModeOn()
43
+ ->addAttributeToSelect('name')
44
+ ->addAttributeToSelect('sku');
45
+ //----------------------------
46
+
47
+ //------------------------------
48
+ $listingProductsIds = $this->getListing()
49
+ ->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
50
+
51
+ $collection->joinTable(
52
+ array('lp' => 'M2ePro/Listing_Product'),
53
+ 'product_id=entity_id',
54
+ array(
55
+ 'id' => 'id'
56
+ ),
57
+ '{{table}}.listing_id='.(int)$this->getListing()->getId()
58
+ );
59
+ $collection->joinTable(
60
+ array('elp' => 'M2ePro/Amazon_Listing_Product'),
61
+ 'listing_product_id=id',
62
+ array(
63
+ 'listing_product_id' => 'listing_product_id',
64
+ 'template_description_id' => 'template_description_id'
65
+ )
66
+ );
67
+
68
+ $collection->getSelect()->where('lp.id IN (?)', $listingProductsIds);
69
+ $collection->getSelect()->where('elp.search_settings_status != ? OR elp.search_settings_status IS NULL',
70
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS);
71
+ $collection->getSelect()->where('elp.general_id IS NULL');
72
+ //------------------------------
73
+
74
+ //exit($collection->getSelect()->__toString());
75
+
76
+ // Set collection to grid
77
+ $this->setCollection($collection);
78
+
79
+ parent::_prepareCollection();
80
+
81
+ return $this;
82
+ }
83
+
84
+ protected function _prepareColumns()
85
+ {
86
+ $this->addColumn('product_id', array(
87
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
88
+ 'align' => 'right',
89
+ 'width' => '100px',
90
+ 'type' => 'number',
91
+ 'index' => 'entity_id',
92
+ 'filter_index' => 'entity_id',
93
+ 'frame_callback' => array($this, 'callbackColumnProductId')
94
+ ));
95
+
96
+ $this->addColumn('name', array(
97
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
98
+ 'align' => 'left',
99
+ 'width' => '400px',
100
+ 'type' => 'text',
101
+ 'index' => 'name',
102
+ 'filter_index' => 'name',
103
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
104
+ 'filter_condition_callback' => array($this, 'callbackFilterProductTitle')
105
+ ));
106
+
107
+ $this->addColumn('description_template', array(
108
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
109
+ 'align' => 'left',
110
+ 'width' => '*',
111
+ 'sortable' => false,
112
+ 'type' => 'options',
113
+ 'index' => 'description_template_id',
114
+ 'filter_index' => 'description_template_id',
115
+ 'options' => array(
116
+ 1 => Mage::helper('M2ePro')->__('Description Policy Selected'),
117
+ 0 => Mage::helper('M2ePro')->__('Description Policy Not Selected')
118
+ ),
119
+ 'frame_callback' => array($this, 'callbackColumnDescriptionTemplateCallback'),
120
+ 'filter_condition_callback' => array($this, 'callbackColumnDescriptionTemplateFilterCallback')
121
+ ));
122
+
123
+ $actionsColumn = array(
124
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
125
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
126
+ 'align' => 'center',
127
+ 'width' => '130px',
128
+ 'type' => 'text',
129
+ 'field' => 'id',
130
+ 'sortable' => false,
131
+ 'filter' => false,
132
+ 'actions' => array()
133
+ );
134
+
135
+ $actions = array(
136
+ array(
137
+ 'caption' => Mage::helper('M2ePro')->__('Set Description Policy'),
138
+ 'field' => 'id',
139
+ 'onclick_action' => 'ListingGridHandlerObj.setDescriptionTemplateRowAction'
140
+ ),
141
+ array(
142
+ 'caption' => Mage::helper('M2ePro')->__('Reset Description Policy'),
143
+ 'field' => 'id',
144
+ 'onclick_action' => 'ListingGridHandlerObj.resetDescriptionTemplateRowAction'
145
+ )
146
+ );
147
+
148
+ $actionsColumn['actions'] = $actions;
149
+
150
+ $this->addColumn('actions', $actionsColumn);
151
+
152
+ return parent::_prepareColumns();
153
+ }
154
+
155
+ protected function _prepareMassaction()
156
+ {
157
+ $this->setMassactionIdField('listing_product_id');
158
+ $this->setMassactionIdFieldOnlyIndexValue(true);
159
+
160
+ //--------------------------------
161
+ $this->getMassactionBlock()->addItem('setDescriptionTemplate', array(
162
+ 'label' => Mage::helper('M2ePro')->__('Set Description Policy'),
163
+ 'url' => ''
164
+ ));
165
+
166
+ $this->getMassactionBlock()->addItem('resetDescriptionTemplate', array(
167
+ 'label' => Mage::helper('M2ePro')->__('Reset Description Policy'),
168
+ 'url' => ''
169
+ ));
170
+ //--------------------------------
171
+
172
+ return parent::_prepareMassaction();
173
+ }
174
+
175
+ // ########################################
176
+
177
+ public function callbackColumnProductId($value, $row, $column, $isExport)
178
+ {
179
+ $productId = (int)$row->getData('entity_id');
180
+ $storeId = (int)$this->listing->getData('store_id');
181
+
182
+ $url = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
183
+ $htmlWithoutThumbnail = '<a href="' . $url . '" target="_blank">'.$productId.'</a>';
184
+
185
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
186
+ ->getGroupValue('/view/','show_products_thumbnails');
187
+
188
+ if (!$showProductsThumbnails) {
189
+ return $htmlWithoutThumbnail;
190
+ }
191
+
192
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
193
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
194
+ $magentoProduct->setProductId($productId);
195
+ $magentoProduct->setStoreId($storeId);
196
+
197
+ $thumbnail = $magentoProduct->getThumbnailImageLink();
198
+ if (is_null($thumbnail)) {
199
+ return $htmlWithoutThumbnail;
200
+ }
201
+
202
+ return <<<HTML
203
+ <a href="{$url}" target="_blank">
204
+ {$productId}
205
+ <hr style="border: 1px solid silver; border-bottom: none;">
206
+ <img src="{$thumbnail}" />
207
+ </a>
208
+ HTML;
209
+ }
210
+
211
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
212
+ {
213
+ if (strlen($productTitle) > 60) {
214
+ $productTitle = substr($productTitle, 0, 60) . '...';
215
+ }
216
+
217
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
218
+
219
+ $value = '<span>'.$productTitle.'</span>';
220
+
221
+ $sku = $row->getData('sku');
222
+
223
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
224
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($sku) . '<br/>';
225
+
226
+ $listingProductId = (int)$row->getData('id');
227
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
228
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
229
+
230
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
231
+ return $value;
232
+ }
233
+
234
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
235
+ ->getTypeModel()->getProductAttributes();
236
+
237
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
238
+ $value .= implode(', ', $productOptions);
239
+ $value .= '</div>';
240
+
241
+ return $value;
242
+ }
243
+
244
+ public function callbackColumnDescriptionTemplateCallback($value, $row, $column, $isExport)
245
+ {
246
+ $descriptionTemplateId = $row->getData('template_description_id');
247
+
248
+ if (empty($descriptionTemplateId)) {
249
+ $iconSrc = $this->getSkinUrl('M2ePro/images/warning.png');
250
+ $label = Mage::helper('M2ePro')->__('Not Selected');
251
+
252
+ return <<<HTML
253
+ <img src="{$iconSrc}" alt="">&nbsp;<span style="color: gray; font-style: italic;">{$label}</span>
254
+ HTML;
255
+ }
256
+
257
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
258
+ 'id' => $descriptionTemplateId
259
+ ));
260
+
261
+ /** @var Ess_M2ePro_Model_Amazon_Template_Description $descriptionTemplate */
262
+ $descriptionTemplate = Mage::helper('M2ePro/Component_Amazon')
263
+ ->getModel('Template_Description')->load($descriptionTemplateId);
264
+
265
+ $title = Mage::helper('M2ePro')->escapeHtml($descriptionTemplate->getData('title'));
266
+
267
+ return <<<HTML
268
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
269
+ HTML;
270
+ }
271
+
272
+ // ########################################
273
+
274
+ protected function callbackFilterProductTitle($collection, $column)
275
+ {
276
+ $value = $column->getFilter()->getValue();
277
+
278
+ if ($value == null) {
279
+ return;
280
+ }
281
+
282
+ $collection->addFieldToFilter(
283
+ array(
284
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
285
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
286
+ )
287
+ );
288
+ }
289
+
290
+ // ----------------------------------------
291
+
292
+ protected function callbackColumnDescriptionTemplateFilterCallback($collection, $column)
293
+ {
294
+ $value = $column->getFilter()->getValue();
295
+
296
+ if ($value == null) {
297
+ return;
298
+ }
299
+
300
+ if ($value) {
301
+ $collection->addFieldToFilter('template_description_id', array('notnull' => null));
302
+ } else {
303
+ $collection->addFieldToFilter('template_description_id', array('null' => null));
304
+ }
305
+ }
306
+
307
+ // ########################################
308
+
309
+ public function getRowUrl($row)
310
+ {
311
+ return false;
312
+ }
313
+
314
+ // ####################################
315
+
316
+ protected function _toHtml()
317
+ {
318
+ $javascriptsMain = <<<JAVASCRIPT
319
+ <script type="text/javascript">
320
+
321
+ if (typeof ListingGridHandlerObj != 'undefined') {
322
+ ListingGridHandlerObj.afterInitPage();
323
+ }
324
+
325
+ Event.observe(window, 'load', function() {
326
+ setTimeout(function() {
327
+ ListingGridHandlerObj.afterInitPage();
328
+ }, 350);
329
+ });
330
+
331
+ </script>
332
+ JAVASCRIPT;
333
+
334
+ return parent::_toHtml() . $javascriptsMain;
335
+ }
336
+
337
+ // ####################################
338
+
339
+ /**
340
+ * @return Ess_M2ePro_Model_Amazon_Listing
341
+ * @throws Exception
342
+ */
343
+ public function getListing()
344
+ {
345
+ if (!$listingId = $this->getRequest()->getParam('id')) {
346
+ throw new Exception('Listing is not defined');
347
+ }
348
+
349
+ if (is_null($this->listing)) {
350
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
351
+ ->getObject('Listing', $listingId)->getChildObject();
352
+ }
353
+
354
+ return $this->listing;
355
+ }
356
+
357
+ // ####################################
358
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/SkipPopup.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonListingAddNewAsinManualPopup');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/manual/skip_popup.phtml');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ parent::_beforeToHtml();
27
+
28
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
29
+
30
+ $data = array(
31
+ 'class' => 'next',
32
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
33
+ 'onclick' => 'setLocation(\''.$url.'\')',
34
+ );
35
+ $this->setChild('continue_button',$this->getLayout()->createBlock('adminhtml/widget_button')->setData($data));
36
+
37
+ return $this;
38
+ }
39
+
40
+ // ####################################
41
+ }
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,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $listingId = $this->getRequest()->getParam('id');
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('searchAsinForListingProducts');
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ $this->_headerText = Mage::helper('M2ePro')->__("Search Existing Amazon Products (ASIN/ISBN)");
26
+ $this->_blockGroup = 'M2ePro';
27
+ $this->_controller = 'adminhtml_common_amazon_listing_add_searchAsin';
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('*/*/removeAddedProducts', array(
42
+ 'id' => $listingId,
43
+ '_current' => true
44
+ ));
45
+ $this->_addButton('back', array(
46
+ 'label' => Mage::helper('M2ePro')->__('Back'),
47
+ 'onclick' => 'ListingGridHandlerObj.back_click(\'' . $url . '\')',
48
+ 'class' => 'back'
49
+ ));
50
+
51
+ //------------------------------
52
+ $this->_addButton('auto_action', array(
53
+ 'label' => Mage::helper('M2ePro')->__('Edit Search Settings'),
54
+ 'onclick' => 'ListingGridHandlerObj.editSearchSettings(\'' .
55
+ Mage::helper('M2ePro')->__('Listing Search Settings') . '\' ,' .
56
+ $this->getListing()->getId() .
57
+ ');'
58
+ ));
59
+ //------------------------------
60
+
61
+ //------------------------------
62
+ $this->_addButton('save_and_go_to_listing_view', array(
63
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
64
+ 'onclick' => 'ListingGridHandlerObj.checkSearchResults('.$listingId.')',
65
+ 'class' => 'scalable next'
66
+ ));
67
+ //------------------------------
68
+ }
69
+
70
+ public function getGridHtml()
71
+ {
72
+ $listing = Mage::helper('M2ePro/Component')
73
+ ->getCachedUnknownObject('Listing', $this->getRequest()->getParam('id'));
74
+
75
+ $viewHeaderBlock = $this->getLayout()->createBlock(
76
+ 'M2ePro/adminhtml_listing_view_header','',
77
+ array('listing' => $listing)
78
+ );
79
+
80
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_add_searchAsin_help');
81
+
82
+ $productSearchBlock = $this->getLayout()
83
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_productSearch_main');
84
+
85
+ return $helpBlock->toHtml()
86
+ . $viewHeaderBlock->toHtml()
87
+ . $productSearchBlock->toHtml()
88
+ . parent::getGridHtml();
89
+ }
90
+
91
+ protected function _toHtml()
92
+ {
93
+ $helper = Mage::helper('M2ePro');
94
+
95
+ // --------TEXT------------------
96
+ $createEmptyListingMessage = $helper->escapeJs($helper->__('Are you sure you want to create empty Listing?'));
97
+
98
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
99
+ $taskCompletedSuccessMessage = $helper->escapeJs(
100
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
101
+ );
102
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
103
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
104
+ ));
105
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
106
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
107
+ ));
108
+
109
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
110
+ 'Sending %product_title% Product(s) data on Amazon.')
111
+ );
112
+
113
+ $selectItemsMessage = $helper->escapeJs(
114
+ $helper->__('Please select the Products you want to perform the Action on.')
115
+ );
116
+
117
+ $assignString = Mage::helper('M2ePro')->__('Assign');
118
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
119
+
120
+ $enterProductSearchQueryMessage = $helper->escapeJs(
121
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
122
+ );
123
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
124
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
125
+ $autoMapAsinErrorMessage = $helper->escapeJs(
126
+ $helper->__('Server is currently unavailable. Please try again later.')
127
+ );
128
+ $newAsinNotAvailable = $helper->escapeJs(
129
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
130
+ );
131
+ $notSynchronizedMarketplace = $helper->escapeJs(
132
+ $helper->__(
133
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
134
+ ).' '.
135
+ $helper->__(
136
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
137
+ )
138
+ );
139
+
140
+ $newAsinPopupTitle = $helper->escapeJs($helper->__('New ASIN/ISBN creation'));
141
+ $notCompletedPopupTitle = $helper->escapeJs(
142
+ $helper->__('Adding of New Products to the Listing was not competed')
143
+ );
144
+ // -------------------------------
145
+
146
+ // ---------URL-------------------
147
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
148
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
149
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
150
+ $getCategoriesByAsin = $this->getUrl('*/adminhtml_common_amazon_listing/getCategoriesByAsin');
151
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
152
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
153
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
154
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
155
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
156
+
157
+ $viewSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/viewSearchSettings');
158
+ $saveSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/saveSearchSettings');
159
+
160
+ $checkSearchResults = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/checkSearchResults', array(
161
+ 'id' => $this->getListing()->getId()
162
+ ));
163
+
164
+ $showNewAsinStep = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/showNewAsinStep', array(
165
+ 'id' => $this->getListing()->getId()
166
+ ));
167
+
168
+ $addProductsUrl = $this->getUrl(
169
+ '*/adminhtml_common_listing_productAdd/addProducts', array(
170
+ 'component' => $this->getData('component')
171
+ )
172
+ );
173
+ $backUrl = $this->getUrl('*/*/index');
174
+ // -------------------------------
175
+
176
+ $showNotCompletedPopup = '';
177
+ if ($this->getRequest()->getParam('not_completed', false)) {
178
+ $showNotCompletedPopup = 'ListingGridHandlerObj.showNotCompletedPopup();';
179
+ }
180
+
181
+ $javascript = <<<JAVASCRIPT
182
+ <script type="text/javascript">
183
+ if (typeof M2ePro == 'undefined') {
184
+ M2ePro = {};
185
+ M2ePro.url = {};
186
+ M2ePro.formData = {};
187
+ M2ePro.customData = {};
188
+ M2ePro.text = {};
189
+ }
190
+
191
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
192
+ M2ePro.text.create_empty_listing_message = '{$createEmptyListingMessage}';
193
+
194
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
195
+
196
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
197
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
198
+
199
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
200
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
201
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
202
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
203
+
204
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
205
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
206
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
207
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
208
+
209
+ M2ePro.text.assign = '{$assignString}';
210
+ M2ePro.text.confirm = '{$textConfirm}';
211
+
212
+ M2ePro.text.new_asin_popup_title = '{$newAsinPopupTitle}';
213
+ M2ePro.text.not_completed_popup_title = '{$notCompletedPopupTitle}';
214
+
215
+ M2ePro.url.add_products = '{$addProductsUrl}';
216
+ M2ePro.url.back = '{$backUrl}';
217
+
218
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
219
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
220
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
221
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
222
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
223
+ M2ePro.url.getCategoriesByAsin = '{$getCategoriesByAsin}';
224
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
225
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
226
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
227
+
228
+ M2ePro.url.viewSearchSettings = '{$viewSearchSettings}';
229
+ M2ePro.url.saveSearchSettings = '{$saveSearchSettings}';
230
+
231
+ M2ePro.url.checkSearchResults = '{$checkSearchResults}';
232
+ M2ePro.url.showNewAsinStep = '{$showNewAsinStep}';
233
+
234
+ Event.observe(window, 'load', function() {
235
+
236
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
237
+
238
+ ListingGridHandlerObj = new CommonAmazonListingSearchAsinGridHandler(
239
+ '{$this->getChild('grid')->getId()}',
240
+ {$this->getListing()->getId()}
241
+ );
242
+
243
+ // todo next (temp solution)
244
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
245
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
246
+
247
+ ListingProgressBarObj = new ProgressBar('search_asin_progress_bar');
248
+ GridWrapperObj = new AreaWrapper('search_asin_products_container');
249
+
250
+ {$showNotCompletedPopup}
251
+ });
252
+
253
+ </script>
254
+ JAVASCRIPT;
255
+
256
+ //------------------------------
257
+ $notCompletedPopup = $this->getLayout()->createBlock(
258
+ 'M2ePro/adminhtml_common_amazon_listing_add_searchAsin_notCompleted');
259
+ //------------------------------
260
+
261
+ return $notCompletedPopup->toHtml() .
262
+ $javascript .
263
+ '<div id="search_asin_progress_bar"></div>' .
264
+ '<div id="search_asin_products_container">' .
265
+ parent::_toHtml() .
266
+ '</div>';
267
+ }
268
+
269
+ // ####################################
270
+
271
+ public function getListing()
272
+ {
273
+ if (!$listingId = $this->getRequest()->getParam('id')) {
274
+ throw new Exception('Listing is not defined');
275
+ }
276
+
277
+ if (is_null($this->listing)) {
278
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
279
+ ->getObject('Listing', $listingId)->getChildObject();
280
+ }
281
+
282
+ return $this->listing;
283
+ }
284
+
285
+ // ####################################
286
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php ADDED
@@ -0,0 +1,686 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+
22
+ $listingData = $this->getListing()->getData();
23
+
24
+ // Initialization block
25
+ //------------------------------
26
+ $this->setId('searchAsinForListingProductsGrid'.$listingData['id']);
27
+ //------------------------------
28
+
29
+ // Set default values
30
+ //------------------------------
31
+ $this->setDefaultSort('product_id');
32
+ $this->setDefaultDir('DESC');
33
+ $this->setUseAjax(true);
34
+ //------------------------------
35
+ }
36
+
37
+ // ####################################
38
+
39
+ protected function _prepareCollection()
40
+ {
41
+ $listingProductsIds = $this->getListing()->getSetting('additional_data', 'adding_listing_products_ids');
42
+ $listingData = $this->getListing()->getData();
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->setStoreId($listingData['store_id'])
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
+ 'amazon_status' => 'status',
70
+ 'additional_data' => 'additional_data'
71
+ ),
72
+ array(
73
+ 'listing_id' => (int)$listingData['id']
74
+ )
75
+ );
76
+ $collection->joinTable(
77
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
78
+ 'listing_product_id=id',
79
+ array(
80
+ 'general_id' => 'general_id',
81
+ 'general_id_search_info' => 'general_id_search_info',
82
+ 'search_settings_status' => 'search_settings_status',
83
+ 'search_settings_data' => 'search_settings_data',
84
+ 'variation_child_statuses' => 'variation_child_statuses',
85
+ 'amazon_sku' => 'sku',
86
+ 'online_qty' => 'online_qty',
87
+ 'online_price' => 'online_price',
88
+ 'online_sale_price' => 'online_sale_price',
89
+ 'is_afn_channel' => 'is_afn_channel',
90
+ 'is_general_id_owner' => 'is_general_id_owner',
91
+ 'is_variation_parent' => 'is_variation_parent',
92
+ ),
93
+ '{{table}}.variation_parent_id is NULL'
94
+ );
95
+
96
+ $collection->getSelect()->where('id IN (?)', $listingProductsIds);
97
+
98
+ //----------------------------
99
+ // exit($collection->getSelect()->__toString());
100
+
101
+ // Set collection to grid
102
+ $this->setCollection($collection);
103
+
104
+ return parent::_prepareCollection();
105
+ }
106
+
107
+ protected function _prepareColumns()
108
+ {
109
+ $this->addColumn('product_id', array(
110
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
111
+ 'align' => 'right',
112
+ 'width' => '100px',
113
+ 'type' => 'number',
114
+ 'index' => 'entity_id',
115
+ 'filter_index' => 'entity_id',
116
+ 'frame_callback' => array($this, 'callbackColumnProductId')
117
+ ));
118
+
119
+ $this->addColumn('name', array(
120
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
121
+ 'align' => 'left',
122
+ 'type' => 'text',
123
+ 'index' => 'name',
124
+ 'filter_index' => 'name',
125
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
126
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
127
+ ));
128
+
129
+ $this->addColumn('general_id', array(
130
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
131
+ 'align' => 'left',
132
+ 'width' => '140px',
133
+ 'type' => 'text',
134
+ 'index' => 'general_id',
135
+ 'filter_index' => 'general_id',
136
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
137
+ ));
138
+
139
+ if ($this->getListing()->getChildObject()->isGeneralIdAttributeMode() ||
140
+ $this->getListing()->getChildObject()->isWorldwideIdAttributeMode()) {
141
+
142
+ $this->addColumn('settings', array(
143
+ 'header' => Mage::helper('M2ePro')->__('Search Settings Values'),
144
+ 'align' => 'left',
145
+ 'width' => '240px',
146
+ 'filter' => false,
147
+ 'sortable' => false,
148
+ 'type' => 'text',
149
+ 'index' => 'id',
150
+ 'frame_callback' => array($this, 'callbackColumnSettings')
151
+ ));
152
+ }
153
+
154
+ $this->addColumn('status', array(
155
+ 'header' => Mage::helper('M2ePro')->__('Status'),
156
+ 'width' => '200px',
157
+ 'index' => 'search_settings_status',
158
+ 'filter_index' => 'search_settings_status',
159
+ 'sortable' => false,
160
+ 'type' => 'options',
161
+ 'options' => array(
162
+ self::SEARCH_SETTINGS_STATUS_NONE => Mage::helper('M2ePro')->__('None'),
163
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS =>
164
+ Mage::helper('M2ePro')->__('In Progress'),
165
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND =>
166
+ Mage::helper('M2ePro')->__('Not Found'),
167
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_ACTION_REQUIRED =>
168
+ Mage::helper('M2ePro')->__('Action Required'),
169
+ self::SEARCH_SETTINGS_STATUS_COMPLETED => Mage::helper('M2ePro')->__('Completed')
170
+ ),
171
+ 'frame_callback' => array($this, 'callbackColumnStatus'),
172
+ 'filter_condition_callback' => array($this, 'callbackFilterStatus')
173
+ ));
174
+
175
+ return parent::_prepareColumns();
176
+ }
177
+
178
+ protected function _prepareMassaction()
179
+ {
180
+ $this->setMassactionIdField('id');
181
+ $this->setMassactionIdFieldOnlyIndexValue(true);
182
+
183
+ //--------------------------------
184
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
185
+ 'label' => Mage::helper('M2ePro')->__('Search ASIN/ISBN automatically'),
186
+ 'url' => '',
187
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
188
+ ));
189
+
190
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
191
+ 'label' => Mage::helper('M2ePro')->__('Reset ASIN/ISBN information'),
192
+ 'url' => '',
193
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
194
+ ));
195
+ //--------------------------------
196
+
197
+ return parent::_prepareMassaction();
198
+ }
199
+
200
+ // ####################################
201
+
202
+ public function callbackColumnProductId($value, $row, $column, $isExport)
203
+ {
204
+ $listingData = $this->getListing()->getData();
205
+
206
+ $productId = (int)$value;
207
+ $storeId = (int)$listingData['store_id'];
208
+
209
+ $withoutImageHtml = '<a href="'
210
+ .$this->getUrl('adminhtml/catalog_product/edit',
211
+ array('id' => $productId))
212
+ .'" target="_blank">'
213
+ .$productId
214
+ .'</a>';
215
+
216
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')
217
+ ->getConfig()
218
+ ->getGroupValue('/view/','show_products_thumbnails');
219
+ if (!$showProductsThumbnails) {
220
+ return $withoutImageHtml;
221
+ }
222
+
223
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
224
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
225
+ $magentoProduct->setProductId($productId);
226
+ $magentoProduct->setStoreId($storeId);
227
+
228
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
229
+ if (is_null($imageUrlResized)) {
230
+ return $withoutImageHtml;
231
+ }
232
+
233
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
234
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
235
+
236
+ return $withImageHtml;
237
+ }
238
+
239
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
240
+ {
241
+ if (strlen($productTitle) > 60) {
242
+ $productTitle = substr($productTitle, 0, 60) . '...';
243
+ }
244
+
245
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
246
+
247
+ $value = '<span>'.$productTitle.'</span>';
248
+
249
+ $tempSku = $row->getData('sku');
250
+ is_null($tempSku)
251
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
252
+
253
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
254
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
255
+
256
+ $listingProductId = (int)$row->getData('id');
257
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
258
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
259
+
260
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
261
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
262
+
263
+ if (!$variationManager->isRelationParentType()) {
264
+ return $value;
265
+ }
266
+
267
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
268
+
269
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
270
+ $value .= implode(', ', $productAttributes);
271
+ $value .= '</div>';
272
+
273
+ return $value;
274
+ }
275
+
276
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
277
+ {
278
+ if (empty($generalId)) {
279
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
280
+ }
281
+
282
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
283
+ }
284
+
285
+ public function callbackColumnSettings($id, $row, $column, $isExport)
286
+ {
287
+ $value = '';
288
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $listingProduct */
289
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $id)->getChildObject();
290
+
291
+ if ($this->getListing()->getChildObject()->isGeneralIdAttributeMode()) {
292
+ $attrValue = $listingProduct->getListingSource()->getSearchGeneralId();
293
+
294
+ if (empty($attrValue)) {
295
+ $attrValue = Mage::helper('M2ePro')->__('Not set');
296
+ } else if (!Mage::helper('M2ePro/Component_Amazon')->isASIN($attrValue) &&
297
+ !Mage::helper('M2ePro')->isISBN($attrValue)) {
298
+ $attrValue = Mage::helper('M2ePro')->__('Inappropriate value');
299
+ }
300
+
301
+ $value .= '<b>' . Mage::helper('M2ePro')->__('ASIN/ISBN') . '</b>: ' . $attrValue . '<br/>';
302
+ }
303
+
304
+ if ($this->getListing()->getChildObject()->isWorldwideIdAttributeMode()) {
305
+ $attrValue = $listingProduct->getListingSource()->getSearchWorldwideId();
306
+
307
+ if (empty($attrValue)) {
308
+ $attrValue = Mage::helper('M2ePro')->__('Not Set');
309
+ } else if (!Mage::helper('M2ePro')->isUPC($attrValue) && !Mage::helper('M2ePro')->isEAN($attrValue)) {
310
+ $attrValue = Mage::helper('M2ePro')->__('Inappropriate value');
311
+ }
312
+
313
+ $value .= '<b>' . Mage::helper('M2ePro')->__('UPC/EAN') . '</b>: ' . $attrValue;
314
+ }
315
+
316
+ return $value;
317
+ }
318
+
319
+ public function callbackColumnStatus($value, $row, $column, $isExport)
320
+ {
321
+ $generalId = $row->getData('general_id');
322
+ $searchSettingsStatus = $row->getData('search_settings_status');
323
+ $skinUrl = $this->getSkinUrl('M2ePro');
324
+ $style = 'display: inline-block; vertical-align: middle;';
325
+
326
+ if (empty($generalId) && empty($searchSettingsStatus)) {
327
+
328
+ $msg = Mage::helper('M2ePro')->__('None');
329
+ $tip = Mage::helper('M2ePro')->__('The Search of Product was not performed yet');
330
+
331
+ return <<<HTML
332
+ <span style="color: gray; {$style}">{$msg}</span>&nbsp;
333
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
334
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
335
+ <img src="{$skinUrl}/images/help.png">
336
+ <span>{$tip}</span>
337
+ </span><br/>
338
+ HTML;
339
+ }
340
+
341
+ switch ($searchSettingsStatus) {
342
+ case Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS:
343
+ $searchData = json_decode($row->getData('search_settings_data'), true);
344
+
345
+ $msg = Mage::helper('M2ePro')->__('In Progress');
346
+ $tip = Mage::helper('M2ePro')->__(
347
+ 'The Search is being performed now by %type% "%value%"',
348
+ $this->prepareSearchType($searchData['type']), $searchData['value']
349
+ );
350
+
351
+ return <<<HTML
352
+ <span style="color: orange; {$style}">{$msg}</span>&nbsp;
353
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
354
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
355
+ <img src="{$skinUrl}/images/help.png">
356
+ <span>{$tip}</span>
357
+ </span><br/>
358
+ HTML;
359
+
360
+ case Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND:
361
+
362
+ $msg = Mage::helper('M2ePro')->__('Product was not found');
363
+ $tip = Mage::helper('M2ePro')->__('There are no Products found on Amazon after the Automatic Search
364
+ was performed according to Listing Search Settings.');
365
+
366
+ return <<<HTML
367
+ <span style="color: red; {$style}">{$msg}</span>&nbsp;
368
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
369
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
370
+ <img src="{$skinUrl}/images/help.png">
371
+ <span>{$tip}</span>
372
+ </span><br/>
373
+ HTML;
374
+ case Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_ACTION_REQUIRED:
375
+
376
+ $searchData = json_decode($row->getData('search_settings_data'), true);
377
+
378
+ $lpId = $row->getData('id');
379
+
380
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
381
+ if (strlen($productTitle) > 60) {
382
+ $productTitle = substr($productTitle, 0, 60) . '...';
383
+ }
384
+ $productTitle = Mage::helper('M2ePro')->__(
385
+ 'Search ASIN/ISBN For &quot;%product_title%&quot;',
386
+ $productTitle
387
+ );
388
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
389
+
390
+ $linkTxt = Mage::helper('M2ePro')->__('Choose ASIN/ISBN');
391
+
392
+ $msg = Mage::helper('M2ePro')->__('Action Required');
393
+ $tip = Mage::helper('M2ePro')->__(
394
+ 'Please choose one of the Results that were found by %type% "%value%"',
395
+ $this->prepareSearchType($searchData['type']), $searchData['value']
396
+ );
397
+
398
+ return <<<HTML
399
+ <span style="color: orange; {$style}">{$msg}</span>&nbsp;
400
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
401
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
402
+ <img src="{$skinUrl}/images/help.png">
403
+ <span>{$tip}</span>
404
+ </span><br/>
405
+ <a href="javascript:;" title="{$linkTxt}"
406
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">{$linkTxt}</a>
407
+ HTML;
408
+ }
409
+
410
+ $searchInfo = json_decode($row->getData('general_id_search_info'), true);
411
+
412
+ $msg = Mage::helper('M2ePro')->__('Completed');
413
+ $tip = Mage::helper('M2ePro')->__(
414
+ 'Product was found by %type% "%value%"',
415
+ $this->prepareSearchType($searchInfo['type']), $searchInfo['value']
416
+ );
417
+
418
+ return <<<HTML
419
+ <span style="color: green; {$style}">{$msg}</span>&nbsp;
420
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
421
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
422
+ <img src="{$skinUrl}/images/help.png">
423
+ <span>{$tip}</span>
424
+ </span><br/>
425
+ HTML;
426
+ }
427
+
428
+ private function prepareSearchType($searchType)
429
+ {
430
+ if ($searchType == 'string') {
431
+ return 'query';
432
+ }
433
+
434
+ return strtoupper($searchType);
435
+ }
436
+
437
+ // ####################################
438
+
439
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
440
+ {
441
+ // ---------------------------------
442
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
443
+ // ---------------------------------
444
+
445
+ // ---------------------------------
446
+ $lpId = $row->getData('id');
447
+
448
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
449
+ if (strlen($productTitle) > 60) {
450
+ $productTitle = substr($productTitle, 0, 60) . '...';
451
+ }
452
+ $productTitle = Mage::helper('M2ePro')->__('Search ASIN/ISBN For &quot;%product_title%&quot;', $productTitle);
453
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
454
+ // ---------------------------------
455
+
456
+ // ---------------------------------
457
+
458
+ $searchSettingsStatus = $row->getData('search_settings_status');
459
+
460
+ // ---------------------------------
461
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
462
+
463
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN Search in Progress.');
464
+ $iconSrc = $iconPath.'processing.gif';
465
+
466
+ return <<<HTML
467
+ &nbsp;
468
+ <a href="javascript: void(0);" title="{$tip}">
469
+ <img src="{$iconSrc}" alt="">
470
+ </a>
471
+ HTML;
472
+ }
473
+ // ---------------------------------
474
+
475
+ $na = Mage::helper('M2ePro')->__('N/A');
476
+ $tip = Mage::helper('M2ePro')->__('Search for ASIN/ISBN');
477
+ $iconSrc = $iconPath.'search.png';
478
+
479
+ return <<<HTML
480
+ {$na} &nbsp;
481
+ <a href="javascript:;" title="{$tip}"
482
+ onclick="ListingGridHandlerObj.productSearchHandler.showSearchManualPrompt('{$productTitle}',{$lpId});">
483
+ <img src="{$iconSrc}" alt="" width="16" height="16">
484
+ </a>
485
+ HTML;
486
+ }
487
+
488
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
489
+ {
490
+ $generalId = $row->getData('general_id');
491
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
492
+
493
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
494
+ $generalId,
495
+ $marketplaceId
496
+ );
497
+
498
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
499
+
500
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
501
+
502
+ if (!empty($generalIdSearchInfo)) {
503
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
504
+ }
505
+
506
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
507
+
508
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
509
+
510
+ $text = <<<HTML
511
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
512
+ HTML;
513
+
514
+ } else {
515
+
516
+ $text = <<<HTML
517
+ <a href="{$url}" target="_blank">{$generalId}</a>
518
+ HTML;
519
+
520
+ }
521
+
522
+ // ---------------------------------
523
+ $hasInActionLock = $this->getLockedData($row);
524
+ $hasInActionLock = $hasInActionLock['in_action'];
525
+ // ---------------------------------
526
+
527
+ if ($hasInActionLock) {
528
+ return $text;
529
+ }
530
+
531
+ $listingProductId = (int)$row->getData('id');
532
+
533
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
534
+ $iconSrc = $iconPath.'unassign.png';
535
+
536
+ $text .= <<<HTML
537
+ <a href="javascript:;"
538
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$listingProductId});"
539
+ title="{$tip}">
540
+ <img src="{$iconSrc}" width="16" height="16"/>
541
+ </a>
542
+ HTML;
543
+
544
+ return $text;
545
+ }
546
+
547
+ // ####################################
548
+
549
+ protected function callbackFilterTitle($collection, $column)
550
+ {
551
+ $value = $column->getFilter()->getValue();
552
+
553
+ if ($value == null) {
554
+ return;
555
+ }
556
+
557
+ $collection->addFieldToFilter(
558
+ array(
559
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
560
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
561
+ )
562
+ );
563
+ }
564
+
565
+ protected function callbackFilterStatus($collection, $column)
566
+ {
567
+ $value = $column->getFilter()->getValue();
568
+
569
+ if ($value == null) {
570
+ return;
571
+ }
572
+
573
+ if ($value == self::SEARCH_SETTINGS_STATUS_NONE) {
574
+ $collection->addFieldToFilter('general_id', array('null' => NULL));
575
+ $collection->addFieldToFilter('search_settings_status', array('null' => NULL));
576
+ return;
577
+ }
578
+
579
+ if ($value == self::SEARCH_SETTINGS_STATUS_COMPLETED) {
580
+ $collection->addFieldToFilter(
581
+ array(
582
+ array('attribute'=>'general_id', 'notnull' => NULL)
583
+ )
584
+ );
585
+
586
+ return;
587
+ }
588
+
589
+ $collection->addFieldToFilter(
590
+ array(
591
+ array('attribute' => 'search_settings_status', 'eq' => $value)
592
+ )
593
+ );
594
+ }
595
+
596
+ // ####################################
597
+
598
+ public function getRowUrl($row)
599
+ {
600
+ return false;
601
+ }
602
+
603
+ // ####################################
604
+
605
+ protected function _toHtml()
606
+ {
607
+ $disableMassactionSearch = '';
608
+ $startSearch = '';
609
+
610
+ $listing = $this->getListing();
611
+
612
+ if (!$listing->getChildObject()->isGeneralIdAttributeMode() &&
613
+ !$listing->getChildObject()->isWorldwideIdAttributeMode()) {
614
+
615
+ if (!$listing->getChildObject()->isSearchByMagentoTitleModeEnabled()) {
616
+ $gridId = $this->getId();
617
+
618
+ $disableMassactionSearch = <<<JS
619
+ var mmassActionEl = $("{$gridId}_massaction-select");
620
+
621
+ if (mmassActionEl && mmassActionEl.select('option[value="assignGeneralId"]').length > 0) {
622
+ var assignGeneralIdOption = mmassActionEl.select('option[value="assignGeneralId"]')[0];
623
+ assignGeneralIdOption.disabled = true;
624
+
625
+ mmassActionEl.insert({bottom: assignGeneralIdOption.remove()});
626
+ }
627
+ JS;
628
+ }
629
+
630
+ } else {
631
+ $autoSearchSetting = $listing->getSetting('additional_data', 'auto_search_was_performed');
632
+
633
+ if (!$autoSearchSetting) {
634
+ $listing->setSetting('additional_data', 'auto_search_was_performed', 1);
635
+ $listing->save();
636
+
637
+ $startSearch = <<<JS
638
+ ListingGridHandlerObj.getGridMassActionObj().selectAll();
639
+ ListingGridHandlerObj.productSearchHandler.searchGeneralIdAuto(ListingGridHandlerObj.getSelectedProductsString());
640
+ JS;
641
+ }
642
+ }
643
+
644
+ $javascriptsMain = <<<JAVASCRIPT
645
+ <script type="text/javascript">
646
+
647
+ if (typeof ListingGridHandlerObj != 'undefined') {
648
+ ListingGridHandlerObj.afterInitPage();
649
+ {$disableMassactionSearch}
650
+ }
651
+
652
+ Event.observe(window, 'load', function() {
653
+ setTimeout(function() {
654
+ ListingGridHandlerObj.afterInitPage();
655
+ {$disableMassactionSearch}
656
+ {$startSearch}
657
+ }, 350);
658
+ });
659
+
660
+ </script>
661
+ JAVASCRIPT;
662
+
663
+ return parent::_toHtml() . $javascriptsMain;
664
+ }
665
+
666
+ // ####################################
667
+
668
+ /**
669
+ * @return Ess_M2ePro_Model_Amazon_Listing
670
+ * @throws Exception
671
+ */
672
+ public function getListing()
673
+ {
674
+ if (!$listingId = $this->getRequest()->getParam('id')) {
675
+ throw new Exception('Listing is not defined');
676
+ }
677
+
678
+ if (is_null($this->listing)) {
679
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing', $listingId);
680
+ }
681
+
682
+ return $this->listing;
683
+ }
684
+
685
+ // ####################################
686
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Help.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingViewHelp');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/help.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NewAsinPopup.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_Add_SearchAsin_NewAsinPopup extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('searchAsinNewAsinPopup');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/new_asin_popup.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ $data = array(
26
+ 'label' => Mage::helper('M2ePro')->__('Yes'),
27
+ 'onclick' => 'ListingGridHandlerObj.newAsinPopupYesClick()'
28
+ );
29
+ $yesButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
30
+ $this->setChild('yesBtn', $yesButton);
31
+
32
+ $data = array(
33
+ 'label' => Mage::helper('M2ePro')->__('No'),
34
+ 'onclick' => 'ListingGridHandlerObj.noAsinPopupNoClick()'
35
+ );
36
+ $noButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
37
+ $this->setChild('noBtn', $noButton);
38
+ }
39
+
40
+ // ####################################
41
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NotCompleted.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_NotCompleted extends Mage_Adminhtml_Block_Widget
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+
13
+ // Initialization block
14
+ //------------------------------
15
+ $this->setId('searchAsinNotCompletedPopup');
16
+ //------------------------------
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/not_completed.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ $data = array(
24
+ 'label' => Mage::helper('M2ePro')->__('Close'),
25
+ 'onclick' => 'Windows.getFocusedWindow().close();'
26
+ );
27
+ $closeButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
28
+ $this->setChild('closeBtn', $closeButton);
29
+ }
30
+
31
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/SearchSettings.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_Amazon_Listing_Add_SearchAsin_SearchSettings
8
+ extends Mage_Adminhtml_Block_Widget_Form
9
+ {
10
+ protected $component;
11
+
12
+ // ####################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('searchSettings');
21
+ //------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/search_settings.phtml');
24
+ }
25
+
26
+ protected function _prepareForm()
27
+ {
28
+ // Prepare action
29
+ // -------------------
30
+ $action = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/saveSearchSettings', array(
31
+ 'id' => (int)$this->getRequest()->getParam('id')
32
+ ));
33
+ // -------------------
34
+
35
+ $form = new Varien_Data_Form(array(
36
+ 'id' => 'search_settings_form',
37
+ 'action' => $action,
38
+ 'method' => 'post'
39
+ ));
40
+
41
+ $form->setUseContainer(true);
42
+ $this->setForm($form);
43
+
44
+ return parent::_prepareForm();
45
+ }
46
+
47
+ protected function _beforeToHtml()
48
+ {
49
+ $child = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_search');
50
+
51
+ $this->setChild('content', $child);
52
+
53
+ return parent::_beforeToHtml();
54
+ }
55
+
56
+ // ########################################
57
+
58
+ protected function _toHtml()
59
+ {
60
+ $buttonSave = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
61
+ 'id' => 'save_search_settings',
62
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
63
+ 'style' => 'float: right; margin: 0 0 7px 5px;',
64
+ 'onclick' => 'ListingGridHandlerObj.saveSearchSettings()'
65
+ ));
66
+
67
+ $this->setChild('save_search_settings', $buttonSave);
68
+
69
+ return parent::_toHtml();
70
+ }
71
+
72
+ // ########################################
73
+ }
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,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'sku_modification_mode' => Ess_M2ePro_Model_Amazon_Listing::SKU_MODIFICATION_MODE_NONE,
55
+ 'sku_modification_custom_value' => '',
56
+ 'generate_sku_mode' => Ess_M2ePro_Model_Amazon_Listing::GENERATE_SKU_MODE_NO,
57
+
58
+ 'template_selling_format_id' => '',
59
+ 'template_synchronization_id' => '',
60
+
61
+ 'condition_mode' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_MODE_DEFAULT,
62
+ 'condition_value' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_NEW,
63
+ 'condition_custom_attribute' => '',
64
+ 'condition_note_mode' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_NOTE_MODE_NONE,
65
+ 'condition_note_value' => '',
66
+
67
+ 'image_main_mode' => Ess_M2ePro_Model_Amazon_Listing::IMAGE_MAIN_MODE_NONE,
68
+ 'image_main_attribute' => '',
69
+ 'gallery_images_mode' => Ess_M2ePro_Model_Amazon_Listing::GALLERY_IMAGES_MODE_NONE,
70
+ 'gallery_images_limit' => '',
71
+ 'gallery_images_attribute' => '',
72
+
73
+ 'gift_wrap_mode' => Ess_M2ePro_Model_Amazon_Listing::GIFT_WRAP_MODE_NO,
74
+ 'gift_wrap_attribute' => '',
75
+
76
+ 'gift_message_mode' => Ess_M2ePro_Model_Amazon_Listing::GIFT_MESSAGE_MODE_NO,
77
+ 'gift_message_attribute' => '',
78
+
79
+ 'handling_time_mode' => Ess_M2ePro_Model_Amazon_Listing::HANDLING_TIME_MODE_NONE,
80
+ 'handling_time_value' => '',
81
+ 'handling_time_custom_attribute' => '',
82
+
83
+ 'restock_date_mode' => Ess_M2ePro_Model_Amazon_Listing::RESTOCK_DATE_MODE_NONE,
84
+ 'restock_date_value' => Mage::helper('M2ePro')->getCurrentTimezoneDate(),
85
+ 'restock_date_custom_attribute' => ''
86
+ );
87
+ }
88
+
89
+ // ####################################
90
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ // ####################################
13
+ }
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,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setTemplate('M2ePro/common/amazon/listing/auto_action/mode/category/form.phtml');
17
+ }
18
+
19
+ // ####################################
20
+
21
+ public function getDefault()
22
+ {
23
+ return array(
24
+ 'id' => NULL,
25
+ 'title' => NULL,
26
+ 'category_id' => NULL,
27
+ 'adding_mode' => Ess_M2ePro_Model_Listing::ADDING_MODE_NONE,
28
+ 'deleting_mode' => Ess_M2ePro_Model_Listing::DELETING_MODE_NONE,
29
+ 'adding_description_template_id' => NULL
30
+ );
31
+ }
32
+
33
+ // ####################################
34
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Group/Grid.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_Listing_AutoAction_Mode_Category_Group_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Group_Grid
9
+ {
10
+ // ####################################
11
+
12
+ public function getGridUrl()
13
+ {
14
+ return $this->getUrl('*/adminhtml_common_listing_autoAction/getCategoryGroupGrid', array('_current' => true));
15
+ }
16
+
17
+ // ####################################
18
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Global.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Website.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingEdit');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_amazon_listing';
20
+ $this->_mode = 'edit';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
26
+
27
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
28
+ $headerText = Mage::helper('M2ePro')->__(
29
+ 'Edit %component_name% Listing Settings "%listing_title%"',
30
+ Mage::helper('M2ePro/Component_Amazon')->getTitle(),
31
+ $this->escapeHtml($listingData['title'])
32
+ );
33
+ } else {
34
+ $headerText = Mage::helper('M2ePro')->__(
35
+ 'Edit Listing Settings "%listing_title%"',
36
+ $this->escapeHtml($listingData['title'])
37
+ );
38
+ }
39
+
40
+ $this->_headerText = $headerText;
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
54
+ //------------------------------
55
+ $url = Mage::helper('M2ePro')->getBackUrl(
56
+ '*/adminhtml_common_listing/index',
57
+ array(
58
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
59
+ )
60
+ );
61
+ $this->_addButton('back', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Back'),
63
+ 'onclick' => 'CommonListingSettingsHandlerObj.back_click(\''.$url.'\')',
64
+ 'class' => 'back'
65
+ ));
66
+ //------------------------------
67
+ }
68
+
69
+ //------------------------------
70
+ $this->_addButton('auto_action', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
72
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
73
+ ));
74
+ //------------------------------
75
+
76
+ $backUrl = Mage::helper('M2ePro')->getBackUrlParam('list');
77
+
78
+ //------------------------------
79
+ $url = $this->getUrl(
80
+ '*/adminhtml_common_amazon_listing/save',
81
+ array(
82
+ 'id' => $listingData['id'],
83
+ 'back' => $backUrl
84
+ )
85
+ );
86
+ $this->_addButton('save', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Save'),
88
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_click(\'' . $url . '\')',
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' => 'CommonListingSettingsHandlerObj.save_and_edit_click(\''.$url.'\', 1)',
97
+ 'class' => 'save'
98
+ ));
99
+ //------------------------------
100
+ }
101
+
102
+ // ####################################
103
+
104
+ protected function _beforeToHtml()
105
+ {
106
+ parent::_beforeToHtml();
107
+
108
+ //------------------------------
109
+ $tabs = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_edit_tabs');
110
+ $this->setChild('tabs', $tabs);
111
+ //------------------------------
112
+
113
+ return $this;
114
+ }
115
+
116
+ // ####################################
117
+
118
+ public function getFormHtml()
119
+ {
120
+ $listing = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
121
+ 'Listing', $this->getRequest()->getParam('id')
122
+ );
123
+
124
+ $viewHeaderBlock = $this->getLayout()->createBlock(
125
+ 'M2ePro/adminhtml_listing_view_header','',
126
+ array('listing' => $listing)
127
+ );
128
+
129
+ $tabs = $this->getChild('tabs');
130
+
131
+ $urls = Mage::helper('M2ePro')->getControllerActions(
132
+ 'adminhtml_common_listing_autoAction',
133
+ array(
134
+ 'listing_id' => $this->getRequest()->getParam('id'),
135
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
136
+ )
137
+ );
138
+ $urls = json_encode($urls);
139
+
140
+ /** @var $helper Ess_M2ePro_Helper_Data */
141
+ $helper = Mage::helper('M2ePro');
142
+
143
+ $translations = json_encode(array(
144
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
145
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
146
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
147
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
148
+ ));
149
+
150
+ $js = <<<HTML
151
+ <script type="text/javascript">
152
+
153
+ M2ePro.url.add({$urls});
154
+ M2ePro.translator.add({$translations});
155
+
156
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
157
+
158
+ </script>
159
+ HTML;
160
+
161
+ return $viewHeaderBlock->toHtml() . $tabs->toHtml() . parent::getFormHtml() . $js;
162
+ }
163
+
164
+ // ####################################
165
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Form.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_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('amazonListingEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareForm()
22
+ {
23
+ $form = new Varien_Data_Form(array(
24
+ 'id' => 'edit_form',
25
+ 'action' => $this->getUrl('*/adminhtml_common_amazon_listing/save'),
26
+ 'method' => 'post',
27
+ 'enctype' => 'multipart/form-data'
28
+ ));
29
+
30
+ $form->setUseContainer(true);
31
+ $this->setForm($form);
32
+
33
+ return parent::_prepareForm();
34
+ }
35
+
36
+ // ####################################
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Tabs.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingEditTabs');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('widget/tabshoriz.phtml');
21
+ $this->setDestElementId('edit_form');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ $this->addTab('selling', array(
27
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
28
+ 'title' => Mage::helper('M2ePro')->__('Selling Settings'),
29
+ 'content' => $this->getLayout()
30
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_selling')
31
+ ->toHtml(),
32
+ ));
33
+
34
+ $this->addTab('search', array(
35
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
36
+ 'title' => Mage::helper('M2ePro')->__('Search Settings'),
37
+ 'content' => $this->getLayout()
38
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_search')
39
+ ->toHtml(),
40
+ ));
41
+
42
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'selling'));
43
+
44
+ return parent::_beforeToHtml();
45
+ }
46
+
47
+ // ####################################
48
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Grid.php ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_ManageListings::TAB_ID_LISTING,
82
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
83
+ )
84
+ );
85
+
86
+ $this->getMassactionBlock()->addItem('clear_logs', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Clear Log(s)'),
88
+ 'url' => $this->getUrl('*/adminhtml_listing/clearLog', array('back' => $backUrl)),
89
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
90
+ ));
91
+ //--------------------------------
92
+
93
+ // Set remove listings action
94
+ //--------------------------------
95
+ $this->getMassactionBlock()->addItem('delete_listings', array(
96
+ 'label' => Mage::helper('M2ePro')->__('Delete Listing(s)'),
97
+ 'url' => $this->getUrl('*/adminhtml_common_amazon_listing/delete', array('back' => $backUrl)),
98
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
99
+ ));
100
+ //--------------------------------
101
+
102
+ return parent::_prepareMassaction();
103
+ }
104
+
105
+ // ####################################
106
+
107
+ protected function getColumnActionsItems()
108
+ {
109
+ $helper = Mage::helper('M2ePro');
110
+ $backUrl = $helper->makeBackUrlParam(
111
+ '*/adminhtml_common_listing/index',
112
+ array(
113
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
114
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
115
+ )
116
+ );
117
+
118
+ $actions = array(
119
+ 'manageProducts' => array(
120
+ 'caption' => $helper->__('Manage'),
121
+ 'group' => 'products_actions',
122
+ 'field' => 'id',
123
+ 'url' => array(
124
+ 'base' => '*/adminhtml_common_amazon_listing/view',
125
+ 'params' => array('back' => $backUrl)
126
+ )
127
+ ),
128
+
129
+ 'addProductsFromProductsList' => array(
130
+ 'caption' => $helper->__('Add From Products List'),
131
+ 'group' => 'products_actions',
132
+ 'field' => 'id',
133
+ 'url' => array(
134
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
135
+ 'params' => array(
136
+ 'back' => $backUrl,
137
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
138
+ 'step' => 2,
139
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
140
+ )
141
+ )
142
+ ),
143
+
144
+ 'addProductsFromCategories' => array(
145
+ 'caption' => $helper->__('Add From Categories'),
146
+ 'group' => 'products_actions',
147
+ 'field' => 'id',
148
+ 'url' => array(
149
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
150
+ 'params' => array(
151
+ 'back' => $backUrl,
152
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
153
+ 'step' => 2,
154
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
155
+ )
156
+ )
157
+ ),
158
+
159
+ 'automaticActions' => array(
160
+ 'caption' => $helper->__('Auto Add/Remove Rules'),
161
+ 'group' => 'products_actions',
162
+ 'field' => 'id',
163
+ 'url' => array(
164
+ 'base' => '*/adminhtml_common_amazon_listing/view',
165
+ 'params' => array(
166
+ 'back' => $backUrl,
167
+ 'auto_actions' => 1
168
+ )
169
+ )
170
+ ),
171
+
172
+ 'viewLog' => array(
173
+ 'caption' => $helper->__('View Log'),
174
+ 'group' => 'other',
175
+ 'field' => 'id',
176
+ 'url' => array(
177
+ 'base' => '*/adminhtml_common_log/listing',
178
+ 'params' => array(
179
+ 'back' => $backUrl,
180
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON
181
+ )
182
+ )
183
+ ),
184
+
185
+ 'clearLogs' => array(
186
+ 'caption' => $helper->__('Clear Log'),
187
+ 'confirm' => $helper->__('Are you sure?'),
188
+ 'group' => 'other',
189
+ 'field' => 'id',
190
+ 'url' => array(
191
+ 'base' => '*/adminhtml_listing/clearLog',
192
+ 'params' => array(
193
+ 'back' => $backUrl
194
+ )
195
+ )
196
+ ),
197
+
198
+ 'deleteListing' => array(
199
+ 'caption' => $helper->__('Delete Listing'),
200
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
201
+ 'group' => 'other',
202
+ 'field' => 'id',
203
+ 'url' => array(
204
+ 'base' => '*/adminhtml_common_amazon_listing/delete',
205
+ 'params' => array(
206
+ 'back' => $backUrl
207
+ )
208
+ )
209
+ ),
210
+
211
+ 'editListingTitle' => array(
212
+ 'caption' => $helper->__('Title'),
213
+ 'group' => 'edit_actions',
214
+ 'confirm' => $helper->__('Are you sure?'),
215
+ 'field' => 'id',
216
+ 'onclick_action' => 'editListingTitle'
217
+ ),
218
+
219
+ 'sellingSetting' => array(
220
+ 'caption' => $helper->__('Selling'),
221
+ 'group' => 'edit_actions',
222
+ 'field' => 'id',
223
+ 'url' => array(
224
+ 'base' => '*/adminhtml_common_amazon_listing/edit',
225
+ 'params' => array(
226
+ 'back' => $backUrl,
227
+ 'tab' => 'selling'
228
+ )
229
+ )
230
+ ),
231
+
232
+ 'searchSetting' => array(
233
+ 'caption' => $helper->__('Search'),
234
+ 'group' => 'edit_actions',
235
+ 'field' => 'id',
236
+ 'url' => array(
237
+ 'base' => '*/adminhtml_common_amazon_listing/edit',
238
+ 'params' => array(
239
+ 'back' => $backUrl,
240
+ 'tab' => 'search'
241
+ )
242
+ )
243
+ )
244
+ );
245
+
246
+ return $actions;
247
+ }
248
+
249
+ // ####################################
250
+
251
+ public function callbackColumnSoldProducts($value, $row, $column, $isExport)
252
+ {
253
+ return $this->getColumnValue($value);
254
+ }
255
+
256
+ public function callbackColumnTitle($value, $row, $column, $isExport)
257
+ {
258
+ $value = '<span id="listing_title_'.$row->getId().'">' .
259
+ Mage::helper('M2ePro')->escapeHtml($value) .
260
+ '</span>';
261
+
262
+ /* @var $row Ess_M2ePro_Model_Listing */
263
+ $accountTitle = $row->getData('account_title');
264
+ $marketplaceTitle = $row->getData('marketplace_title');
265
+
266
+ $storeModel = Mage::getModel('core/store')->load($row->getStoreId());
267
+ $storeView = $storeModel->getWebsite()->getName();
268
+ if (strtolower($storeView) != 'admin') {
269
+ $storeView .= ' > '.$storeModel->getGroup()->getName();
270
+ $storeView .= ' > '.$storeModel->getName();
271
+ } else {
272
+ $storeView = Mage::helper('M2ePro')->__('Admin (Default Values)');
273
+ }
274
+
275
+ $account = Mage::helper('M2ePro')->__('Account');
276
+ $marketplace = Mage::helper('M2ePro')->__('Marketplace');
277
+ $store = Mage::helper('M2ePro')->__('Magento Store View');
278
+
279
+ $value .= <<<HTML
280
+ <div>
281
+ <span style="font-weight: bold">{$account}</span>: <span style="color: #505050">{$accountTitle}</span><br/>
282
+ <span style="font-weight: bold">{$marketplace}</span>: <span style="color: #505050">{$marketplaceTitle}</span><br/>
283
+ <span style="font-weight: bold">{$store}</span>: <span style="color: #505050">{$storeView}</span>
284
+ </div>
285
+ HTML;
286
+
287
+ return $value;
288
+ }
289
+
290
+ // ####################################
291
+
292
+ protected function callbackFilterTitle($collection, $column)
293
+ {
294
+ $value = $column->getFilter()->getValue();
295
+
296
+ if ($value == null) {
297
+ return;
298
+ }
299
+
300
+ $collection->getSelect()->where('main_table.title LIKE ? OR m.title LIKE ? OR a.title LIKE ?',
301
+ '%'. $value .'%');
302
+ }
303
+
304
+ // ####################################
305
+
306
+ public function getGridUrl()
307
+ {
308
+ return $this->getUrl('*/adminhtml_common_amazon_listing/listingGrid', array('_current'=>true));
309
+ }
310
+
311
+ public function getRowUrl($row)
312
+ {
313
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
314
+ '*/adminhtml_common_listing/index',
315
+ array(
316
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
317
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
318
+ )
319
+ );
320
+
321
+ return $this->getUrl(
322
+ '*/adminhtml_common_amazon_listing/view',
323
+ array(
324
+ 'id' => $row->getId(),
325
+ 'back' => $backUrl
326
+ )
327
+ );
328
+ }
329
+
330
+ // ####################################
331
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/Grid.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Other_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Other_Grid
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setId('amazonListingOtherGrid');
17
+ }
18
+
19
+ // ####################################
20
+
21
+ protected function _prepareCollection()
22
+ {
23
+ $this->prepareCacheData();
24
+
25
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
26
+ $collection->getSelect()->group(array('account_id','marketplace_id'));
27
+
28
+ // exit($collection->getSelect()->__toString());
29
+
30
+ // Set collection to grid
31
+ $this->setCollection($collection);
32
+
33
+ return parent::_prepareCollection();
34
+ }
35
+
36
+ protected function _prepareColumns()
37
+ {
38
+ $this->addColumnAfter('marketplace', array(
39
+ 'header' => Mage::helper('M2ePro')->__('Marketplace'),
40
+ 'align' => 'left',
41
+ //'width' => '200px',
42
+ 'type' => 'text',
43
+ 'sortable' => false,
44
+ 'frame_callback' => array($this, 'callbackColumnMarketplace')
45
+ ), 'account');
46
+
47
+ return parent::_prepareColumns();
48
+ }
49
+
50
+ // ####################################
51
+
52
+ public function callbackColumnMarketplace($value, $row, $column, $isExport)
53
+ {
54
+ $marketplaceTitle = Mage::helper('M2ePro/Component_Amazon')
55
+ ->getCachedObject('Marketplace',$row->getData('marketplace_id'))
56
+ ->getTitle();
57
+ return Mage::helper('M2ePro')->escapeHtml($marketplaceTitle);
58
+ }
59
+
60
+ public function callbackColumnTotalProducts($value, $row, $column, $isExport)
61
+ {
62
+ $accountId = $row->getAccountId();
63
+ $marketplaceId = $row->getMarketplaceId();
64
+ $key = $accountId . ',' . $marketplaceId;
65
+
66
+ $value = $this->cacheData[$key]['total_items'];
67
+
68
+ if (is_null($value) || $value === '') {
69
+ $value = Mage::helper('M2ePro')->__('N/A');
70
+ } else if ($value <= 0) {
71
+ $value = '<span style="color: red;">0</span>';
72
+ }
73
+
74
+ return $value;
75
+ }
76
+
77
+ public function callbackColumnListedProducts($value, $row, $column, $isExport)
78
+ {
79
+ $accountId = $row->getAccountId();
80
+ $marketplaceId = $row->getMarketplaceId();
81
+ $key = $accountId . ',' . $marketplaceId;
82
+
83
+ $value = $this->cacheData[$key]['active_items'];
84
+
85
+ if (is_null($value) || $value === '') {
86
+ $value = Mage::helper('M2ePro')->__('N/A');
87
+ } else if ($value <= 0) {
88
+ $value = '<span style="color: red;">0</span>';
89
+ }
90
+
91
+ return $value;
92
+ }
93
+
94
+ public function callbackColumnInactiveProducts($value, $row, $column, $isExport)
95
+ {
96
+ $accountId = $row->getAccountId();
97
+ $marketplaceId = $row->getMarketplaceId();
98
+ $key = $accountId . ',' . $marketplaceId;
99
+
100
+ $value = $this->cacheData[$key]['inactive_items'];
101
+
102
+ if (is_null($value) || $value === '') {
103
+ $value = Mage::helper('M2ePro')->__('N/A');
104
+ } else if ($value <= 0) {
105
+ $value = '<span style="color: red;">0</span>';
106
+ }
107
+
108
+ return $value;
109
+ }
110
+
111
+ // ####################################
112
+
113
+ public function getRowUrl($row)
114
+ {
115
+ return $this->getUrl('*/adminhtml_common_amazon_listing_other/view', array(
116
+ 'account' => $row->getData('account_id'),
117
+ 'marketplace' => $row->getData('marketplace_id'),
118
+ 'back'=>Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_listing/index', array(
119
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING_OTHER,
120
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Other::TAB_ID_AMAZON
121
+ ))
122
+ ));
123
+ }
124
+
125
+ // ####################################
126
+
127
+ protected function prepareCacheData()
128
+ {
129
+ $this->cacheData = array();
130
+
131
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
132
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
133
+ $collection->getSelect()->columns(
134
+ array('account_id', 'marketplace_id', 'status')
135
+ );
136
+
137
+ /* @var $item Ess_M2ePro_Model_Listing_Other */
138
+ foreach ($collection->getItems() as $item) {
139
+
140
+ $accountId = $item->getAccountId();
141
+ $marketplaceId = $item->getMarketplaceId();
142
+ $key = $accountId . ',' . $marketplaceId;
143
+
144
+ empty($this->cacheData[$key]) && ($this->cacheData[$key] = array(
145
+ 'total_items' => 0,
146
+ 'active_items' => 0,
147
+ 'inactive_items' => 0
148
+ ));
149
+
150
+ ++$this->cacheData[$key]['total_items'];
151
+
152
+ if ($item->getStatus() == Ess_M2ePro_Model_Listing_Product::STATUS_LISTED) {
153
+ ++$this->cacheData[$key]['active_items'];
154
+ } else {
155
+ ++$this->cacheData[$key]['inactive_items'];
156
+ }
157
+ }
158
+
159
+ }
160
+
161
+ // ####################################
162
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Other_View extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ // ####################################
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+
11
+ // Initialization block
12
+ //------------------------------
13
+ $this->setId('amazonListing');
14
+ $this->_blockGroup = 'M2ePro';
15
+ $this->_controller = 'adminhtml_common_amazon_listing_other_view';
16
+ //------------------------------
17
+
18
+ // Set header text
19
+ //------------------------------
20
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
21
+ $this->_headerText = Mage::helper('M2ePro')->__(
22
+ '3rd Party %channel_title% Listings',
23
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()
24
+ );
25
+ } else {
26
+ $this->_headerText = Mage::helper('M2ePro')->__('3rd Party Listings');
27
+ }
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
42
+ $url = Mage::helper('M2ePro')->getBackUrl();
43
+ $this->_addButton('back', array(
44
+ 'label' => Mage::helper('M2ePro')->__('Back'),
45
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
46
+ 'class' => 'back'
47
+ ));
48
+ }
49
+ //------------------------------
50
+
51
+ }
52
+
53
+ // ####################################
54
+
55
+ public function getGridHtml()
56
+ {
57
+ $accountId = $this->getRequest()->getParam('account');
58
+ $marketplaceId = $this->getRequest()->getParam('marketplace');
59
+
60
+ //------------------------------
61
+ $viewHeaderBlock = $this->getLayout()->createBlock(
62
+ 'M2ePro/adminhtml_listing_other_view_header','',
63
+ array(
64
+ 'account' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Account', $accountId),
65
+ 'marketplace' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Marketplace', $marketplaceId)
66
+ )
67
+ );
68
+ //------------------------------
69
+
70
+ $mapToProductBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_listing_other_mapping');
71
+
72
+ return $viewHeaderBlock->toHtml() . $mapToProductBlock->toHtml() . parent::getGridHtml();
73
+ }
74
+
75
+ // ####################################
76
+
77
+ protected function _toHtml()
78
+ {
79
+ /** @var $helper Ess_M2ePro_Helper_Data */
80
+ $helper = Mage::helper('M2ePro');
81
+ $componentMode = Ess_M2ePro_Helper_Component_Amazon::NICK;
82
+
83
+ $prepareData = $this->getUrl('*/adminhtml_listing_other_moving/prepareMoveToListing');
84
+ $createDefaultListingUrl = $this->getUrl('*/adminhtml_listing_other_moving/createDefaultListing');
85
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/moveToListingGrid');
86
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/getFailedProductsGrid');
87
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_other_moving/tryToMoveToListing');
88
+ $moveToListing = $this->getUrl('*/adminhtml_listing_other_moving/moveToListing');
89
+
90
+ $mapAutoToProductUrl = $this->getUrl('*/adminhtml_listing_other_mapping/autoMap');
91
+
92
+ $removingProductsUrl = $this->getUrl('*/adminhtml_common_listing_other/removing');
93
+ $unmappingProductsUrl = $this->getUrl('*/adminhtml_listing_other_mapping/unmapping');
94
+
95
+ $someProductsWereNotMappedMessage = 'No matches were found. Please change the Mapping Attributes in <strong>';
96
+ $someProductsWereNotMappedMessage .= 'Configuration > Account > 3rd Party Listings</strong> ';
97
+ $someProductsWereNotMappedMessage .= 'or try to map manually.';
98
+ $someProductsWereNotMappedMessage = $helper->escapeJs($helper->__($someProductsWereNotMappedMessage));
99
+
100
+ $successfullyMappedMessage = $helper->escapeJs($helper->__('Product was successfully Mapped.'));
101
+
102
+ $createListing = $helper->escapeJs($helper->__(
103
+ 'Listings, which have the same Marketplace and Account were not found.'
104
+ ));
105
+ $createListing .= $helper->escapeJs($helper->__('Would you like to create one with Default Settings ?'));
106
+ $popupTitle = $helper->escapeJs($helper->__('Moving Amazon Items'));
107
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Amazon Item'));
108
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
109
+
110
+ $confirmMessage = $helper->escapeJs($helper->__('Are you sure?'));
111
+
112
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
113
+ $productsWereNotMovedMessage = $helper->escapeJs(
114
+ $helper->__('Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
115
+ );
116
+ $someProductsWereNotMovedMessage = $helper->escapeJs($helper->__(
117
+ 'Some of the Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.'
118
+ ));
119
+
120
+ $notEnoughDataMessage = $helper->escapeJs($helper->__('Not enough data'));
121
+ $successfullyUnmappedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Unmapped.'));
122
+ $successfullyRemovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Removed.'));
123
+
124
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
125
+
126
+ $selectItemsMessage = $helper->escapeJs(
127
+ $helper->__('Please select the Products you want to perform the Action on.')
128
+ );
129
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
130
+
131
+ $processingDataMessage = $helper->escapeJs($helper->__('Processing %product_title% Product(s).'));
132
+
133
+ $autoMapProgressTitle = $helper->escapeJs($helper->__('Map Item(s) to Products'));
134
+ $selectOnlyMapped = $helper->escapeJs($helper->__('Only Mapped Products must be selected.'));
135
+ $selectTheSameTypeProducts = $helper->escapeJs(
136
+ $helper->__('Selected Items must belong to the same Account and Marketplace.')
137
+ );
138
+
139
+ $successWord = $helper->escapeJs($helper->__('Success'));
140
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
141
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
142
+ $errorWord = $helper->escapeJs($helper->__('Error'));
143
+ $closeWord = $helper->escapeJs($helper->__('Close'));
144
+
145
+ $translations = json_encode(array(
146
+
147
+ 'Mapping Product' => $helper->__('Mapping Product'),
148
+ 'Product does not exist.' => $helper->__('Product does not exist.'),
149
+ 'Please enter correct Product ID.' => $helper->__('Please enter correct Product ID.'),
150
+ 'Product(s) was successfully Mapped.' => $helper->__('Product(s) was successfully Mapped.'),
151
+ 'Please enter correct Product ID or SKU' => $helper->__('Please enter correct Product ID or SKU'),
152
+
153
+ 'Current version only supports Simple Products. Please, choose Simple Product.' => $helper->__(
154
+ 'Current version only supports Simple Products. Please, choose Simple Product.'
155
+ ),
156
+
157
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.' => $helper->__(
158
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.'
159
+ )
160
+
161
+ ));
162
+
163
+ $urls = json_encode(array(
164
+
165
+ 'adminhtml_common_log/listingOther' => $this->getUrl('*/adminhtml_common_log/listingOther',array(
166
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_listing_other/index')
167
+ )),
168
+
169
+ 'adminhtml_listing_other_mapping/map' => $this->getUrl('*/adminhtml_listing_other_mapping/map'),
170
+
171
+ ));
172
+
173
+ $javascriptsMain = <<<JAVASCRIPT
174
+ <script type="text/javascript">
175
+
176
+ M2eProAmazon = {};
177
+ M2eProAmazon.url = {};
178
+ M2eProAmazon.formData = {};
179
+ M2eProAmazon.customData = {};
180
+ M2eProAmazon.text = {};
181
+
182
+ M2ePro.url.add({$urls});
183
+ M2ePro.translator.add({$translations});
184
+
185
+ M2eProAmazon.url.prepareData = '{$prepareData}';
186
+ M2eProAmazon.url.createDefaultListing = '{$createDefaultListingUrl}';
187
+ M2eProAmazon.url.getGridHtml = '{$getMoveToListingGridHtml}';
188
+ M2eProAmazon.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
189
+ M2eProAmazon.url.tryToMoveToListing = '{$tryToMoveToListing}';
190
+ M2eProAmazon.url.moveToListing = '{$moveToListing}';
191
+
192
+ M2eProAmazon.url.mapAutoToProduct = '{$mapAutoToProductUrl}';
193
+
194
+ M2eProAmazon.url.removingProducts = '{$removingProductsUrl}';
195
+ M2eProAmazon.url.unmappingProducts = '{$unmappingProductsUrl}';
196
+
197
+ M2eProAmazon.text.create_listing = '{$createListing}';
198
+ M2eProAmazon.text.popup_title = '{$popupTitle}';
199
+ M2eProAmazon.text.popup_title_single = '{$popupTitleSingle}';
200
+ M2eProAmazon.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
201
+ M2eProAmazon.text.confirm = '{$confirmMessage}';
202
+ M2eProAmazon.text.successfully_moved = '{$successfullyMovedMessage}';
203
+ M2eProAmazon.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
204
+ M2eProAmazon.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
205
+ M2eProAmazon.text.not_enough_data = '{$notEnoughDataMessage}';
206
+ M2eProAmazon.text.successfully_unmapped = '{$successfullyUnmappedMessage}';
207
+ M2eProAmazon.text.successfully_removed = '{$successfullyRemovedMessage}';
208
+
209
+ M2eProAmazon.text.select_items_message = '{$selectItemsMessage}';
210
+ M2eProAmazon.text.select_action_message = '{$selectActionMessage}';
211
+
212
+ M2eProAmazon.text.automap_progress_title = '{$autoMapProgressTitle}';
213
+ M2eProAmazon.text.processing_data_message = '{$processingDataMessage}';
214
+ M2eProAmazon.text.successfully_mapped = '{$successfullyMappedMessage}';
215
+ M2eProAmazon.text.failed_mapped = '{$someProductsWereNotMappedMessage}';
216
+
217
+ M2eProAmazon.text.select_only_mapped_products = '{$selectOnlyMapped}';
218
+ M2eProAmazon.text.select_the_same_type_products = '{$selectTheSameTypeProducts}';
219
+
220
+ M2eProAmazon.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
221
+
222
+ M2eProAmazon.text.success_word = '{$successWord}';
223
+ M2eProAmazon.text.notice_word = '{$noticeWord}';
224
+ M2eProAmazon.text.warning_word = '{$warningWord}';
225
+ M2eProAmazon.text.error_word = '{$errorWord}';
226
+ M2eProAmazon.text.close_word = '{$closeWord}';
227
+
228
+ M2eProAmazon.customData.componentMode = '{$componentMode}';
229
+ M2eProAmazon.customData.gridId = 'amazonListingOtherGrid';
230
+
231
+ Event.observe(window,'load',function() {
232
+ ListingProgressBarObj = new ProgressBar('listing_other_progress_bar');
233
+ GridWrapperObj = new AreaWrapper('listing_other_content_container');
234
+
235
+ AmazonListingOtherGridHandlerObj = new CommonAmazonListingOtherGridHandler('amazonListingOtherGrid');
236
+ AmazonListingOtherMappingHandlerObj = new ListingOtherMappingHandler(
237
+ AmazonListingOtherGridHandlerObj,
238
+ 'amazon'
239
+ );
240
+
241
+ // todo next (temp solution)
242
+ AmazonListingOtherGridHandlerObj.movingHandler.setOptions(M2eProAmazon);
243
+ AmazonListingOtherGridHandlerObj.autoMappingHandler.setOptions(M2eProAmazon);
244
+ AmazonListingOtherGridHandlerObj.removingHandler.setOptions(M2eProAmazon);
245
+ AmazonListingOtherGridHandlerObj.unmappingHandler.setOptions(M2eProAmazon);
246
+ });
247
+
248
+ </script>
249
+ JAVASCRIPT;
250
+
251
+ return $javascriptsMain.
252
+ '<div id="listing_other_progress_bar"></div>' .
253
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
254
+ '<div id="listing_other_content_container">' .
255
+ parent::_toHtml() .
256
+ '</div>';
257
+ }
258
+
259
+ // ####################################
260
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View/Grid.php ADDED
@@ -0,0 +1,575 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Other_View_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('account')) {
54
+ $collection->addFieldToFilter('main_table.account_id',
55
+ $this->getRequest()->getParam('account'));
56
+ }
57
+
58
+ // Add Filter By Marketplace
59
+ if ($this->getRequest()->getParam('marketplace')) {
60
+ $collection->addFieldToFilter('main_table.marketplace_id',
61
+ $this->getRequest()->getParam('marketplace'));
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_amazon_listing_other/view',
155
+ array(
156
+ 'account' => $this->getRequest()->getParam('account'),
157
+ 'marketplace' => $this->getRequest()->getParam('marketplace'),
158
+ 'back' => $this->getRequest()->getParam('back', null)
159
+ )
160
+ );
161
+
162
+ $this->addColumn('actions', array(
163
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
164
+ 'align' => 'left',
165
+ 'width' => '70px',
166
+ 'type' => 'action',
167
+ 'index' => 'actions',
168
+ 'filter' => false,
169
+ 'sortable' => false,
170
+ 'getter' => 'getId',
171
+ 'actions' => array(
172
+ array(
173
+ 'caption' => Mage::helper('M2ePro')->__('View Log'),
174
+ 'field' => 'id',
175
+ 'url' => array(
176
+ 'base' => '*/adminhtml_common_log/listingOther',
177
+ 'params' => array(
178
+ 'back' => $backUrl,
179
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK
180
+ )
181
+ )
182
+ ),
183
+ array(
184
+ 'caption' => Mage::helper('M2ePro')->__('Clear Log'),
185
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
186
+ 'field' => 'id',
187
+ 'url' => array(
188
+ 'base' => '*/adminhtml_listing_other/clearLog',
189
+ 'params' => array(
190
+ 'back' => $backUrl
191
+ )
192
+ )
193
+ )
194
+ )
195
+ ));
196
+
197
+ return parent::_prepareColumns();
198
+ }
199
+
200
+ protected function _prepareMassaction()
201
+ {
202
+ // Set mass-action identifiers
203
+ //--------------------------------
204
+ $this->setMassactionIdField('`main_table`.id');
205
+ $this->getMassactionBlock()->setFormFieldName('ids');
206
+ //--------------------------------
207
+
208
+ $this->getMassactionBlock()->setGroups(array(
209
+ 'mapping' => Mage::helper('M2ePro')->__('Mapping'),
210
+ 'other' => Mage::helper('M2ePro')->__('Other')
211
+ ));
212
+
213
+ // Set mass-action
214
+ //--------------------------------
215
+ $this->getMassactionBlock()->addItem('autoMapping', array(
216
+ 'label' => Mage::helper('M2ePro')->__('Map Item(s) Automatically'),
217
+ 'url' => '',
218
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
219
+ ), 'mapping');
220
+ $this->getMassactionBlock()->addItem('moving', array(
221
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Listing'),
222
+ 'url' => '',
223
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
224
+ ), 'other');
225
+ $this->getMassactionBlock()->addItem('removing', array(
226
+ 'label' => Mage::helper('M2ePro')->__('Remove Item(s)'),
227
+ 'url' => '',
228
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
229
+ ), 'other');
230
+ $this->getMassactionBlock()->addItem('unmapping', array(
231
+ 'label' => Mage::helper('M2ePro')->__('Unmap Item(s)'),
232
+ 'url' => '',
233
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
234
+ ), 'mapping');
235
+ //--------------------------------
236
+
237
+ return parent::_prepareMassaction();
238
+ }
239
+
240
+ // ####################################
241
+
242
+ public function callbackColumnProductId($value, $row, $column, $isExport)
243
+ {
244
+ if (empty($value)) {
245
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('title'));
246
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
247
+ if (strlen($productTitle) > 60) {
248
+ $productTitle = substr($productTitle, 0, 60) . '...';
249
+ }
250
+ $htmlValue = '&nbsp;<a href="javascript:void(0);"
251
+ onclick="AmazonListingOtherMappingHandlerObj.openPopUp(\''.
252
+ $productTitle.
253
+ '\','.
254
+ (int)$row->getId().
255
+ ');">' . Mage::helper('M2ePro')->__('Map') . '</a>';
256
+
257
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
258
+ $htmlValue .= '<br/>' . $row->getId();
259
+ }
260
+ return $htmlValue;
261
+ }
262
+
263
+ $htmlValue = '&nbsp<a href="'
264
+ .$this->getUrl('adminhtml/catalog_product/edit',
265
+ array('id' => $row->getData('product_id')))
266
+ .'" target="_blank">'
267
+ .$row->getData('product_id')
268
+ .'</a>';
269
+
270
+ $htmlValue .= '&nbsp&nbsp&nbsp<a href="javascript:void(0);"'
271
+ .' onclick="AmazonListingOtherGridHandlerObj.movingHandler.getGridHtml('
272
+ .json_encode(array((int)$row->getData('id')))
273
+ .')">'
274
+ .Mage::helper('M2ePro')->__('Move')
275
+ .'</a>';
276
+
277
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
278
+ $htmlValue .= '<br/>' . $row->getId();
279
+ }
280
+
281
+ return $htmlValue;
282
+ }
283
+
284
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
285
+ {
286
+ if (is_null($value)) {
287
+ $value = '<i style="color:gray;">receiving...</i>';
288
+ } elseif ($value == '') {
289
+ $value = '<i style="color:gray;">none</i>';
290
+ } else {
291
+ $value = '<span>' . Mage::helper('M2ePro')->escapeHtml($value) . '</span>';
292
+ }
293
+
294
+ $tempSku = $row->getData('sku');
295
+ empty($tempSku) && $tempSku = 'N/A';
296
+
297
+ $value .= '<br/><strong>'
298
+ .Mage::helper('M2ePro')->__('SKU')
299
+ .':</strong> '
300
+ .Mage::helper('M2ePro')->escapeHtml($tempSku);
301
+
302
+ return $value;
303
+ }
304
+
305
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
306
+ {
307
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($value, $row->getData('marketplace_id'));
308
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
309
+ }
310
+
311
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
312
+ {
313
+ if (is_null($value) || $value === '') {
314
+ return Mage::helper('M2ePro')->__('N/A');
315
+ }
316
+
317
+ if ((bool)$row->getData('is_afn_channel')) {
318
+ return '--';
319
+ }
320
+
321
+ if ($value <= 0) {
322
+ return '<span style="color: red;">0</span>';
323
+ }
324
+
325
+ return $value;
326
+ }
327
+
328
+ public function callbackColumnPrice($value, $row, $column, $isExport)
329
+ {
330
+ if (is_null($value) || $value === '') {
331
+ return Mage::helper('M2ePro')->__('N/A');
332
+ }
333
+
334
+ if ((float)$value <= 0) {
335
+ return '<span style="color: #f00;">0</span>';
336
+ }
337
+
338
+ $currency = Mage::helper('M2ePro/Component_Amazon')
339
+ ->getCachedObject('Marketplace',$row->getData('marketplace_id'))
340
+ ->getChildObject()
341
+ ->getDefaultCurrency();
342
+
343
+ return Mage::app()->getLocale()->currency($currency)->toCurrency($value);
344
+ }
345
+
346
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
347
+ {
348
+ switch ($row->getData('is_afn_channel')) {
349
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
350
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
351
+ break;
352
+
353
+ default:
354
+ break;
355
+ }
356
+
357
+ return $value;
358
+ }
359
+
360
+ public function callbackColumnStatus($value, $row, $column, $isExport)
361
+ {
362
+ switch ($row->getData('status')) {
363
+
364
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
365
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
366
+ $value = '<span style="color: gray;">' . $value . '</span>';
367
+ break;
368
+
369
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
370
+ $value = '<span style="color: green;">' . $value . '</span>';
371
+ break;
372
+
373
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
374
+ $value = '<span style="color: red;">' . $value . '</span>';
375
+ break;
376
+
377
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
378
+ $value = '<span style="color: orange; font-weight: bold;">' . $value . '</span>';
379
+ break;
380
+
381
+ default:
382
+ break;
383
+ }
384
+
385
+ return $value.$this->getViewLogIconHtml($row->getId());
386
+ }
387
+
388
+ protected function callbackFilterTitle($collection, $column)
389
+ {
390
+ $value = $column->getFilter()->getValue();
391
+
392
+ if ($value == null) {
393
+ return;
394
+ }
395
+
396
+ $collection->getSelect()->where('second_table.title LIKE ? OR second_table.sku LIKE ?', '%'.$value.'%');
397
+ }
398
+
399
+ // ####################################
400
+
401
+ public function getViewLogIconHtml($listingOtherId)
402
+ {
403
+ $listingOtherId = (int)$listingOtherId;
404
+
405
+ // Get last messages
406
+ //--------------------------
407
+ $dbSelect = $this->connRead->select()
408
+ ->from(
409
+ Mage::getResourceModel('M2ePro/Listing_Other_Log')->getMainTable(),
410
+ array('action_id','action','type','description','create_date','initiator')
411
+ )
412
+ ->where('`listing_other_id` = ?', $listingOtherId)
413
+ ->where('`action_id` IS NOT NULL')
414
+ ->order(array('id DESC'))
415
+ ->limit(30);
416
+
417
+ $logRows = $this->connRead->fetchAll($dbSelect);
418
+ //--------------------------
419
+
420
+ // Get grouped messages by action_id
421
+ //--------------------------
422
+ $actionsRows = array();
423
+ $tempActionRows = array();
424
+ $lastActionId = false;
425
+
426
+ foreach ($logRows as $row) {
427
+
428
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
429
+
430
+ if ($row['action_id'] !== $lastActionId) {
431
+ if (count($tempActionRows) > 0) {
432
+ $actionsRows[] = array(
433
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
434
+ 'date' => $this->getMainDateForActionId($tempActionRows),
435
+ 'action' => $this->getActionForAction($tempActionRows[0]),
436
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
437
+ 'items' => $tempActionRows
438
+ );
439
+ $tempActionRows = array();
440
+ }
441
+ $lastActionId = $row['action_id'];
442
+ }
443
+ $tempActionRows[] = $row;
444
+ }
445
+
446
+ if (count($tempActionRows) > 0) {
447
+ $actionsRows[] = array(
448
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
449
+ 'date' => $this->getMainDateForActionId($tempActionRows),
450
+ 'action' => $this->getActionForAction($tempActionRows[0]),
451
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
452
+ 'items' => $tempActionRows
453
+ );
454
+ }
455
+
456
+ if (count($actionsRows) <= 0) {
457
+ return '';
458
+ }
459
+
460
+ $tips = array(
461
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
462
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
463
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
464
+ );
465
+
466
+ $icons = array(
467
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
468
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
469
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
470
+ );
471
+
472
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
473
+ 'entity_id' => $listingOtherId,
474
+ 'rows' => $actionsRows,
475
+ 'tips' => $tips,
476
+ 'icons' => $icons,
477
+ 'view_help_handler' => 'AmazonListingOtherGridHandlerObj.viewItemHelp',
478
+ 'hide_help_handler' => 'AmazonListingOtherGridHandlerObj.hideItemHelp',
479
+ ));
480
+
481
+ return $summary->toHtml();
482
+ }
483
+
484
+ public function getActionForAction($actionRows)
485
+ {
486
+ $string = '';
487
+
488
+ switch ((int)$actionRows['action']) {
489
+ case Ess_M2ePro_Model_Listing_Other_Log::ACTION_CHANNEL_CHANGE:
490
+ $string = Mage::helper('M2ePro')->__('Channel Change');
491
+ break;
492
+ }
493
+
494
+ return $string;
495
+ }
496
+
497
+ public function getInitiatorForAction($actionRows)
498
+ {
499
+ $string = '';
500
+
501
+ switch ($actionRows['initiator']) {
502
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
503
+ $string = '';
504
+ break;
505
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
506
+ $string = Mage::helper('M2ePro')->__('Manual');
507
+ break;
508
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
509
+ $string = Mage::helper('M2ePro')->__('Automatic');
510
+ break;
511
+ }
512
+
513
+ return $string;
514
+ }
515
+
516
+ public function getMainTypeForActionId($actionRows)
517
+ {
518
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
519
+
520
+ foreach ($actionRows as $row) {
521
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
522
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
523
+ break;
524
+ }
525
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
526
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
527
+ }
528
+ }
529
+
530
+ return $type;
531
+ }
532
+
533
+ public function getMainDateForActionId($actionRows)
534
+ {
535
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
536
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
537
+ }
538
+
539
+ // ####################################
540
+
541
+ protected function _toHtml()
542
+ {
543
+ $javascriptsMain = <<<JAVASCRIPT
544
+ <script type="text/javascript">
545
+
546
+ if (typeof AmazonListingOtherGridHandlerObj != 'undefined') {
547
+ AmazonListingOtherGridHandlerObj.afterInitPage();
548
+ }
549
+
550
+ Event.observe(window, 'load', function() {
551
+ setTimeout(function() {
552
+ AmazonListingOtherGridHandlerObj.afterInitPage();
553
+ }, 350);
554
+ });
555
+
556
+ </script>
557
+ JAVASCRIPT;
558
+
559
+ return parent::_toHtml().$javascriptsMain;
560
+ }
561
+
562
+ // ####################################
563
+
564
+ public function getGridUrl()
565
+ {
566
+ return $this->getUrl('*/adminhtml_common_amazon_listing_other/grid', array('_current' => true));
567
+ }
568
+
569
+ public function getRowUrl($row)
570
+ {
571
+ return false;
572
+ }
573
+
574
+ // ####################################
575
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product.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_Listing_Product 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('amazonListingProduct');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_amazon_listing_product';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
25
+
26
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
27
+ $headerText = Mage::helper('M2ePro')->__(
28
+ 'Add Products To %component_name% Listing "%listing_title%"',
29
+ Mage::helper('M2ePro/Component_Amazon')->getTitle(),
30
+ $this->escapeHtml($listingData['title'])
31
+ );
32
+ } else {
33
+ $headerText = Mage::helper('M2ePro')->__(
34
+ 'Add Products To Listing "%listing_title%"',
35
+ $this->escapeHtml($listingData['title'])
36
+ );
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
+ if (is_null($this->getRequest()->getParam('back'))) {
54
+ $url = $this->getUrl(
55
+ '*/adminhtml_common_amazon_listing/categoryProduct',
56
+ array(
57
+ 'id' => $listingData['id'],
58
+ 'save_categories' => $this->getRequest()->getParam('save_categories', 1),
59
+ 'selected_categories' => $this->getRequest()->getParam('selected_categories')
60
+ )
61
+ );
62
+ } else {
63
+ $url = Mage::helper('M2ePro')->getBackUrl(
64
+ '*/adminhtml_common_listing/index',
65
+ array(
66
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
67
+ )
68
+ );
69
+ }
70
+ $this->_addButton('back', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Back'),
72
+ 'onclick' => 'ProductGridHandlerObj.back_click(\''.$url.'\')',
73
+ 'class' => 'back'
74
+ ));
75
+ //------------------------------
76
+
77
+ //------------------------------
78
+ $this->_addButton('save', array(
79
+ 'label' => Mage::helper('M2ePro')->__('Save'),
80
+ 'onclick' => 'ProductGridHandlerObj.save_click(\'view\')',
81
+ 'class' => 'save'
82
+ ));
83
+ //------------------------------
84
+ }
85
+
86
+ public function getGridHtml()
87
+ {
88
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_product_help');
89
+ return $helpBlock->toHtml() . parent::getGridHtml();
90
+ }
91
+
92
+ protected function _toHtml()
93
+ {
94
+ return '<div id="add_products_progress_bar"></div>'.
95
+ '<div id="add_products_container">'.
96
+ parent::_toHtml().
97
+ '</div>';
98
+ }
99
+
100
+ // ####################################
101
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product/Help.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingProductHelp');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/product/help.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Grid.php ADDED
@@ -0,0 +1,662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
20
+
21
+ public function __construct()
22
+ {
23
+ parent::__construct();
24
+
25
+ $this->productId = Mage::helper('M2ePro/Data_Global')->getValue('product_id');
26
+ $this->listingProduct = Mage::getModel('M2ePro/Listing_Product')->load($this->productId);
27
+
28
+ $this->matcherAttributes = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Attribute');
29
+ $this->matcherOptions = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Option');
30
+
31
+ $this->currency = Mage::helper('M2ePro/Component_Amazon')
32
+ ->getCachedObject('Marketplace', Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'))
33
+ ->getChildObject()
34
+ ->getDefaultCurrency();
35
+
36
+ // Initialization block
37
+ //------------------------------
38
+ $this->setId('amazonProductSearchGrid');
39
+ //------------------------------
40
+
41
+ // Set default values
42
+ //------------------------------
43
+ $this->setFilterVisibility(false);
44
+ $this->setPagerVisibility(false);
45
+ $this->setDefaultSort('id');
46
+ $this->setDefaultDir('ASC');
47
+ $this->setSaveParametersInSession(true);
48
+ $this->setUseAjax(true);
49
+ //------------------------------
50
+ }
51
+
52
+ protected function _prepareCollection()
53
+ {
54
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
55
+
56
+ $results = new Varien_Data_Collection();
57
+ foreach ($data['data'] as $index => $item) {
58
+ $temp = array(
59
+ 'id' => $index,
60
+ 'general_id' => $item['general_id'],
61
+ 'brand' => $item['brand'],
62
+ 'title' => $item['title'],
63
+ 'image_url' => $item['image_url'],
64
+ 'price' => isset($item['list_price']['amount']) ? $item['list_price']['amount'] : null,
65
+ 'is_variation_product' => $item['is_variation_product']
66
+ );
67
+
68
+ if ($temp['is_variation_product']) {
69
+ if(!$item['bad_parent']) {
70
+ $temp += array(
71
+ 'parentage' => $item['parentage'],
72
+ 'variations' => $item['variations'],
73
+ 'bad_parent' => $item['bad_parent']
74
+ );
75
+ } else {
76
+ $temp['bad_parent'] = $item['bad_parent'];
77
+ }
78
+
79
+ if (!empty($item['requested_child_id'])) {
80
+ $temp['requested_child_id'] = $item['requested_child_id'];
81
+ }
82
+ }
83
+
84
+ $results->addItem(new Varien_Object($temp));
85
+ }
86
+
87
+ $this->setCollection($results);
88
+
89
+ return parent::_prepareCollection();
90
+ }
91
+
92
+ protected function _prepareColumns()
93
+ {
94
+ $this->addColumn('image', array(
95
+ 'header' => Mage::helper('M2ePro')->__('Image'),
96
+ 'align' => 'center',
97
+ 'type' => 'text',
98
+ 'width' => '80px',
99
+ 'index' => 'image_url',
100
+ 'filter' => false,
101
+ 'sortable' => false,
102
+ 'frame_callback' => array($this, 'callbackColumnImage')
103
+ ));
104
+
105
+ $this->addColumn('title', array(
106
+ 'header' => Mage::helper('M2ePro')->__('Title'),
107
+ 'align' => 'left',
108
+ 'type' => 'text',
109
+ 'string_limit' => 10000,
110
+ 'width' => '375px',
111
+ 'index' => 'title',
112
+ 'filter' => false,
113
+ 'sortable' => false,
114
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
115
+ ));
116
+
117
+ $this->addColumn('price',array(
118
+ 'header' => Mage::helper('catalog')->__('Price'),
119
+ 'width' => '60px',
120
+ 'align' => 'right',
121
+ 'index' => 'price',
122
+ 'filter' => false,
123
+ 'sortable' => false,
124
+ 'type' => 'number',
125
+ 'frame_callback' => array($this, 'callbackColumnPrice')
126
+ ));
127
+
128
+ $this->addColumn('general_id', array(
129
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
130
+ 'align' => 'center',
131
+ 'type' => 'text',
132
+ 'width' => '75px',
133
+ 'index' => 'general_id',
134
+ 'filter' => false,
135
+ 'sortable' => false,
136
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
137
+ ));
138
+
139
+ $this->addColumn('actions', array(
140
+ 'header' => Mage::helper('M2ePro')->__('Action'),
141
+ 'align' => 'center',
142
+ 'type' => 'text',
143
+ 'width' => '78px',
144
+ 'filter' => false,
145
+ 'sortable' => false,
146
+ 'frame_callback' => array($this, 'callbackColumnActions'),
147
+ ));
148
+
149
+ }
150
+
151
+ // ####################################
152
+
153
+ public function callbackColumnImage($value, $product, $column, $isExport)
154
+ {
155
+ return '<img src="'.$value.'" />';
156
+ }
157
+
158
+ public function callbackColumnGeneralId($value, $product, $column, $isExport)
159
+ {
160
+ $url = Mage::helper('M2ePro/Component_Amazon')
161
+ ->getItemUrl($value, Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'));
162
+
163
+ $parentAsinText = Mage::helper('M2ePro')->__('parent ASIN/ISBN');
164
+
165
+ return <<<HTML
166
+ <a id="asin_link_{$product->getData('id')}" href="{$url}" target="_blank">{$value}</a>
167
+ <div id="parent_asin_text_{$product->getData('id')}" style="font-size: 9px; color: grey; display: none">
168
+ {$parentAsinText}
169
+ </div>
170
+ HTML;
171
+
172
+ }
173
+
174
+ public function callbackColumnTitle($value, $row, $column, $isExport)
175
+ {
176
+ $value = '<div style="margin-left: 3px; margin-bottom: 3px;">'.
177
+ Mage::helper('M2ePro')->escapeHtml($value)."</div>";
178
+
179
+ $id = $row->getId();
180
+ $generalId = $row->getData('general_id');
181
+ $categoryLinkTitle = Mage::helper('M2ePro')->escapeHtml('Show Categories');
182
+ $notFoundText = Mage::helper('M2ePro')->__('Categories Not Found');
183
+
184
+ $value .= <<<HTML
185
+ <div style="margin-left: 3px; margin-bottom: 10px; font-size:10px; line-height: 1.1em">
186
+ <a href="javascript:void(0)"
187
+ onclick="ListingGridHandlerObj.productSearchHandler.showAsinCategories(
188
+ this, {$id}, '{$generalId}', {$this->productId})">
189
+ {$categoryLinkTitle}
190
+ </a>
191
+ <div id="asin_categories_{$id}"></div>
192
+ <div id="asin_categories_not_found_{$id}" style="display: none; font-style: italic">{$notFoundText}</div>
193
+ </div>
194
+ HTML;
195
+
196
+ if(!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct()
197
+ || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
198
+ if(!$row->getData('is_variation_product')) {
199
+ return $value;
200
+ }
201
+ } else {
202
+ if(!$row->getData('is_variation_product')) {
203
+ return $value;
204
+ }
205
+ }
206
+
207
+ if($row->getData('is_variation_product') && $row->getData('bad_parent')) {
208
+ return $value;
209
+ }
210
+
211
+ $variations = $row->getData('variations');
212
+
213
+ if($this->listingProduct->getChildObject()->getVariationManager()->isRelationParentType()) {
214
+
215
+ $magentoProductAttributesHtml = '';
216
+ $magentoProductAttributesJs = '';
217
+
218
+ $destinationAttributes = array_keys($variations['set']);
219
+
220
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
221
+ $this->matcherAttributes->setDestinationAttributes($destinationAttributes);
222
+
223
+ if($this->matcherAttributes->isAmountEqual()) {
224
+ $magentoProductAttributesJs .= '<script type="text/javascript">';
225
+ $magentoProductAttributesHtml .= '<div><span style="margin-left: 10px;
226
+ font-size: 11px;
227
+ font-weight: bold;
228
+ color: #808080;
229
+ display: inline-block;
230
+ width: 170px;">' .
231
+ Mage::helper('M2ePro')->__('Magento Attributes') .
232
+ '</span><span style="margin-left: 10px;
233
+ font-size: 11px;
234
+ font-weight: bold;
235
+ color: #808080;
236
+ display: inline-block;">' .
237
+ Mage::helper('M2ePro')->__('Amazon Attributes') .
238
+ '</span></div>';
239
+
240
+ $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
241
+ $attributeId = 0;
242
+ foreach($matchedAttributes as $magentoAttr => $amazonAttr){
243
+
244
+ $magentoProductAttributesHtml .= '<span style="margin-left: 10px;
245
+ font-size: 11px;
246
+ color: #808080;
247
+ display: inline-block;
248
+ width: 170px;">'.
249
+ ucfirst(strtolower($magentoAttr)).
250
+ '</span>';
251
+ $magentoProductAttributesHtml .= '<input type="hidden" value="' .
252
+ Mage::helper('M2ePro')->escapeHtml($magentoAttr) . '"
253
+ id="magento_product_attribute_'.$attributeId.'_'.$id.'">';
254
+ $magentoProductAttributesHtml .= '<select class="amazon_product_attribute_'.$id.'"
255
+ onchange="ListingGridHandlerObj.productSearchHandler.attributesChange(this)"
256
+ style="width: 170px; margin-left: 5px; margin-right: 5px;
257
+ margin-bottom: 7px; font-size: 10px;"
258
+ id="amazon_product_attribute_'.$attributeId.'_'.$id.'">';
259
+
260
+ if (!array_key_exists($amazonAttr,$variations['set']))
261
+ {
262
+ $magentoProductAttributesHtml .= '<option class="empty" value=""></option>';
263
+ }
264
+
265
+ foreach ($variations['set'] as $attrKey => $attrData) {
266
+
267
+ $selected = '';
268
+ if ($attrKey == $amazonAttr) {
269
+ $selected = 'selected';
270
+ $magentoProductAttributesJs .= <<<JS
271
+ ListingGridHandlerObj.productSearchHandler.attributesChange({id:"magento_product_attribute_{$magentoAttr}_{$id}"});
272
+ JS;
273
+ }
274
+
275
+ $attrKey = Mage::helper('M2ePro')->escapeHtml($attrKey);
276
+ $magentoProductAttributesHtml .= '<option value="'.$attrKey.'" '.$selected.'>'
277
+ .$attrKey.'</option>';
278
+ }
279
+ $magentoProductAttributesHtml .= '</select><br/>';
280
+ $attributeId++;
281
+ }
282
+
283
+ $magentoProductAttributesJs .= '</script>';
284
+
285
+ $magentoProductAttributesHtml .= '<div id="variations_'.$id.'" style="display: none;">'.
286
+ json_encode($variations).
287
+ '</div>';
288
+ } else {
289
+ $value .= '<div style="font-size:11px;font-weight: bold;color: grey;margin-left: 7px;margin-top: 5px">';
290
+ $value .= implode(', ', $destinationAttributes);
291
+ $value .= '</div>';
292
+ }
293
+
294
+ return $value . $magentoProductAttributesHtml . $magentoProductAttributesJs;
295
+ }
296
+
297
+ $specificsHtml = '';
298
+ $specificsJs = '<script type="text/javascript">';
299
+
300
+ //match options for individual
301
+ if ($this->listingProduct->getChildObject()->getVariationManager()->isIndividualType() &&
302
+ $this->listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()
303
+ ) {
304
+ $channelVariations = array();
305
+ foreach($variations['asins'] as $asin => $asinAttributes) {
306
+ $channelVariations[$asin] = $asinAttributes['specifics'];
307
+ }
308
+
309
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
310
+ $this->matcherAttributes->setDestinationAttributes(array_keys($variations['set']));
311
+
312
+ if ($this->matcherAttributes->isAmountEqual() && $this->matcherAttributes->isFullyMatched()) {
313
+ $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
314
+
315
+ $this->matcherOptions->setMagentoProduct($this->listingProduct->getMagentoProduct());
316
+ $this->matcherOptions->setDestinationOptions($channelVariations);
317
+ $this->matcherOptions->setMatchedAttributes($matchedAttributes);
318
+
319
+ $productOptions = $this->listingProduct->getChildObject()->getVariationManager()
320
+ ->getTypeModel()->getProductOptions();
321
+
322
+ $requestedChildAsin = $this->matcherOptions->getMatchedOptionGeneralId($productOptions);
323
+ }
324
+ }
325
+
326
+ if (empty($requestedChildAsin)) {
327
+ $requestedChildAsin = $row->getData('requested_child_id');
328
+ }
329
+
330
+ $selectedOptions = array();
331
+ if ($requestedChildAsin) {
332
+ $selectedOptions = $variations['asins'][$requestedChildAsin]['specifics'];
333
+ }
334
+
335
+ $specificsHtml .= '<form action="javascript:void(0);">';
336
+
337
+ $attributesNames = '<span style="margin-left: 10px;
338
+ min-width: 100px;
339
+ max-width: 170px;
340
+ font-size: 11px;
341
+ color: #808080;
342
+ display: inline-block;">';
343
+ $attributeValues = '<span style="margin-left: 5px; display: inline-block;">';
344
+ foreach ($variations['set'] as $specificName => $specific) {
345
+ $attributesNames .= '<span style="margin-bottom: 5px; display: inline-block;">'.
346
+ ucfirst(strtolower($specificName)).
347
+ '</span><br/>';
348
+ $attributeValues .= '<input type="hidden" value="' . Mage::helper('M2ePro')->escapeHtml($specificName) .
349
+ '" class="specifics_name_'.$id.'">';
350
+ $attributeValues .= '<select class="specifics_'.$id.'"
351
+ onchange="ListingGridHandlerObj.productSearchHandler.specificsChange(this)"
352
+ style="width: 170px; margin-bottom: 5px; font-size: 10px;"
353
+ id="specific_'.$specificName.'_'.$id.'">';
354
+ $attributeValues .= '<option class="empty" value=""></option>';
355
+
356
+ if (!empty($requestedChildAsin)) {
357
+ foreach ($specific as $option) {
358
+
359
+ $selected = '';
360
+ if ($selectedOptions[$specificName] == $option) {
361
+ $selected = 'selected';
362
+ }
363
+
364
+ $option = Mage::helper('M2ePro')->escapeHtml($option);
365
+ $attributeValues .= '<option value="'.$option.'" '.$selected.'>'.$option.'</option>';
366
+ }
367
+ }
368
+
369
+ $attributeValues .= '</select><br/>';
370
+
371
+ $specificsJs .= <<<JS
372
+ ListingGridHandlerObj.productSearchHandler.specificsChange({id:"specific_{$specificName}_{$id}"});
373
+ JS;
374
+ }
375
+
376
+ $specificsHtml .= $attributesNames . '</span>';
377
+ $specificsHtml .= $attributeValues . '</span>';
378
+ $specificsHtml .= '</form>';
379
+
380
+ $specificsJs .= '</script>';
381
+
382
+ $variationAsins = json_encode($variations['asins']);
383
+ $variationTree = json_encode($this->getChannelVariationsTree($variations));
384
+
385
+ $specificsJsonContainer = <<<HTML
386
+ <div id="parent_asin_{$id}" style="display: none">{$generalId}</div>
387
+ <div id="asins_{$id}" style="display: none;">{$variationAsins}</div>
388
+ <div id="channel_variations_tree_{$id}" style="display: none;">{$variationTree}</div>
389
+ HTML;
390
+
391
+ return $value . $specificsHtml . $specificsJsonContainer . $specificsJs;
392
+ }
393
+
394
+ public function callbackColumnPrice($value, $row, $column, $isExport)
395
+ {
396
+ if (empty($value) || $row->getData('is_variation_product')) {
397
+ $value = Mage::helper('M2ePro')->__('N/A');
398
+ } else {
399
+ $value = Mage::app()->getLocale()->currency($this->currency)->toCurrency($value);
400
+ }
401
+
402
+ return '<div style="margin-right: 5px;">'.$value.'</div>';
403
+ }
404
+
405
+ public function callbackColumnActions($value, $row, $column, $isExport)
406
+ {
407
+ $assignText = Mage::helper('M2ePro')->__('Assign');
408
+ $iconWarningPath = $this->getSkinUrl('M2ePro/images/warning.png');
409
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_notice.gif');
410
+
411
+ if(!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct()
412
+ || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
413
+ if (!$row->getData('is_variation_product')) {
414
+
415
+ return <<<HTML
416
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
417
+ {$this->productId}, '{$row->getData('general_id')}');">{$assignText}</a>
418
+ HTML;
419
+ }
420
+
421
+ if(!$row->getData('bad_parent')) {
422
+
423
+ $msg = Mage::helper('M2ePro')->__(
424
+ 'Please select necessary Options for this Amazon Product to be able to assign ASIN/ISBN.'
425
+ );
426
+
427
+ return <<<HTML
428
+ <span>
429
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
430
+ <img id="map_link_error_icon_{$row->getId()}"
431
+ class="tool-tip-image"
432
+ style="vertical-align: middle; display: none;"
433
+ src="{$iconWarningPath}">
434
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
435
+ <img src="{$iconHelpPath}">
436
+ <span>{$msg}</span>
437
+ </span>
438
+ </span>
439
+ <div id="template_map_link_{$row->getId()}" style="display: none;">
440
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
441
+ {$this->productId}, '%general_id%', '%options_data%'
442
+ );">{$assignText}</a>
443
+ </div>
444
+ HTML;
445
+ }
446
+ }
447
+
448
+ if($row->getData('is_variation_product') && !$row->getData('bad_parent')) {
449
+
450
+ $msg = Mage::helper('M2ePro')->__(
451
+ 'Please map Amazon and Magento Attributes for this Amazon Product to be able to assign ASIN/ISBN.'
452
+ );
453
+
454
+ $variations = $row->getData('variations');
455
+ $amazonAttributes = array_keys($variations['set']);
456
+
457
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
458
+ $this->matcherAttributes->setDestinationAttributes($amazonAttributes);
459
+
460
+ if(!$this->matcherAttributes->isAmountEqual()) {
461
+ $magentoAttributes = implode(',', $this->listingProduct->getChildObject()->getVariationManager()
462
+ ->getTypeModel()->getProductAttributes());
463
+ $amazonAttributes = implode(',', $amazonAttributes);
464
+
465
+ $msg = Mage::helper('M2ePro')->__(
466
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product.<br/>
467
+ The number of Magento Attributes is different from Amazon Attributes.<br/>
468
+ Magento Attributes: %magento_attributes%<br/>
469
+ Amazon Attributes: %amazon_attributes%<br/>',
470
+ $magentoAttributes,
471
+ $amazonAttributes
472
+ );
473
+ }
474
+
475
+ return <<<HTML
476
+ <span>
477
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
478
+ <img id="map_link_error_icon_{$row->getId()}"
479
+ class="tool-tip-image"
480
+ style="vertical-align: middle;"
481
+ src="{$iconWarningPath}">
482
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
483
+ <img src="{$iconHelpPath}">
484
+ <span>{$msg}</span>
485
+ </span>
486
+ </span>
487
+ <div id="template_map_link_{$row->getId()}" style="display: none;">
488
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
489
+ {$this->productId}, '{$row->getData('general_id')}', '%options_data%'
490
+ );">{$assignText}</a>
491
+ </div>
492
+ HTML;
493
+
494
+ }
495
+
496
+ $msg = Mage::helper('M2ePro')->__(
497
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
498
+ This Amazon Product has no Variations. <br/>
499
+ Only Amazon Parent/Child Products can be assigned in "All Variations" Mode.'
500
+ );
501
+
502
+ if ($row->getData('is_variation_product') && $row->getData('bad_parent')) {
503
+ $msg = Mage::helper('M2ePro')->__(
504
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
505
+ Amazon Service (API) does not return all required information about this Amazon Product.'
506
+ );
507
+ }
508
+
509
+ return <<<HTML
510
+ <span>
511
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
512
+ <img id="map_link_error_icon_{$row->getId()}"
513
+ class="tool-tip-image"
514
+ style="vertical-align: middle;"
515
+ src="{$iconWarningPath}">
516
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
517
+ <img src="{$iconHelpPath}">
518
+ <span>{$msg}</span>
519
+ </span>
520
+ </span>
521
+ HTML;
522
+ }
523
+
524
+ // ####################################
525
+
526
+ protected function _toHtml()
527
+ {
528
+ $javascriptsMain = <<<JAVASCRIPT
529
+ <script type="text/javascript">
530
+
531
+ $$('#amazonProductSearchGrid div.grid th').each(function(el){
532
+ el.style.padding = '2px 2px';
533
+ });
534
+
535
+ $$('#amazonProductSearchGrid div.grid td').each(function(el){
536
+ el.style.padding = '2px 2px';
537
+ });
538
+
539
+ </script>
540
+ JAVASCRIPT;
541
+
542
+ $searchData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
543
+
544
+ $searchParamsHtml = <<<HTML
545
+ <input id="amazon_asin_search_type" type="hidden" value="{$searchData['type']}">
546
+ <input id="amazon_asin_search_value" type="hidden" value="{$searchData['value']}">
547
+ HTML;
548
+
549
+ return parent::_toHtml() . $javascriptsMain . $searchParamsHtml;
550
+ }
551
+
552
+ // ####################################
553
+
554
+ public function getGridUrl()
555
+ {
556
+ return $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid', array('_current'=>true));
557
+ }
558
+
559
+ public function getRowUrl($row)
560
+ {
561
+ return false;
562
+ }
563
+
564
+ // ####################################
565
+
566
+ private function getChannelVariationsTree($variations)
567
+ {
568
+ $channelVariations = array();
569
+ foreach($variations['asins'] as $asin => $asinAttributes) {
570
+ $channelVariations[$asin] = $asinAttributes['specifics'];
571
+ }
572
+
573
+ if (empty($channelVariations)) {
574
+ return new stdClass();
575
+ }
576
+
577
+ $firstAttribute = key($variations['set']);
578
+
579
+ return $this->prepareVariations(
580
+ $firstAttribute, $channelVariations, $variations['set']
581
+ );
582
+ }
583
+
584
+ private function prepareVariations($currentAttribute, $variations, $variationsSets,$filters = array())
585
+ {
586
+ $return = false;
587
+
588
+ $temp = array_flip(array_keys($variationsSets));
589
+
590
+ $lastAttributePosition = count($variationsSets) - 1;
591
+ $currentAttributePosition = $temp[$currentAttribute];
592
+
593
+ if ($currentAttributePosition != $lastAttributePosition) {
594
+
595
+ $temp = array_keys($variationsSets);
596
+ $nextAttribute = $temp[$currentAttributePosition + 1];
597
+
598
+ foreach ($variationsSets[$currentAttribute] as $option) {
599
+
600
+ $filters[$currentAttribute] = $option;
601
+
602
+ $result = $this->prepareVariations(
603
+ $nextAttribute,$variations,$variationsSets,$filters
604
+ );
605
+
606
+ if (!$result) {
607
+ continue;
608
+ }
609
+
610
+ $return[$currentAttribute][$option] = $result;
611
+ }
612
+
613
+ ksort($return[$currentAttribute]);
614
+
615
+ return $return;
616
+ }
617
+
618
+ $return = false;
619
+ foreach ($variations as $key => $magentoVariation) {
620
+ foreach ($magentoVariation as $attribute => $option) {
621
+
622
+ if ($attribute == $currentAttribute) {
623
+
624
+ if (count($variationsSets) != 1) {
625
+ continue;
626
+ }
627
+
628
+ $values = array_flip($variationsSets[$currentAttribute]);
629
+ $return = array($currentAttribute => $values);
630
+
631
+ foreach ($return[$currentAttribute] as &$option) {
632
+ $option = true;
633
+ }
634
+
635
+ return $return;
636
+ }
637
+
638
+ if ($option != $filters[$attribute]) {
639
+ unset($variations[$key]);
640
+ continue;
641
+ }
642
+
643
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
644
+ if ($tempAttribute == $currentAttribute) {
645
+ $option = $tempOption;
646
+ $return[$currentAttribute][$option] = true;
647
+ }
648
+ }
649
+ }
650
+ }
651
+
652
+ if (count($variations) < 1) {
653
+ return false;
654
+ }
655
+
656
+ ksort($return[$currentAttribute]);
657
+
658
+ return $return;
659
+ }
660
+
661
+ // ####################################
662
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/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_ProductSearch_Main
8
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/main.phtml');
17
+ }
18
+
19
+ protected function _beforeToHtml()
20
+ {
21
+ //------------------------------
22
+ $data = array(
23
+ 'id' => 'productSearch_submit_button',
24
+ 'label' => Mage::helper('M2ePro')->__('Search'),
25
+ 'class' => 'productSearch_submit_button submit'
26
+ );
27
+ $buttonSubmitBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
28
+ $this->setChild('productSearch_submit_button', $buttonSubmitBlock);
29
+ //------------------------------
30
+
31
+ //------------------------------
32
+ $data = array(
33
+ 'id' => 'productSearch_back_button',
34
+ 'label' => Mage::helper('M2ePro')->__('Back'),
35
+ 'class' => 'productSearch_back_button'
36
+ );
37
+ $buttonBackBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
38
+ $this->setChild('productSearch_back_button', $buttonBackBlock);
39
+ //------------------------------
40
+
41
+ //------------------------------
42
+ $data = array(
43
+ 'id' => 'productSearch_cancel_button',
44
+ 'label' => Mage::helper('M2ePro')->__('Close'),
45
+ 'class' => 'productSearch_cancel_button'
46
+ );
47
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
48
+ $this->setChild('productSearch_cancel_button', $buttonCancelBlock);
49
+ //------------------------------
50
+
51
+ //------------------------------
52
+ $data = array(
53
+ 'id' => 'productSearch_cleanSuggest_button',
54
+ 'label' => Mage::helper('M2ePro')->__('Clear Search Results'),
55
+ 'class' => 'productSearch_cleanSuggest_button',
56
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndOpenSearchMenu()'
57
+ );
58
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
59
+ $this->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
60
+ //------------------------------
61
+
62
+ parent::_beforeToHtml();
63
+ }
64
+
65
+ protected function _toHtml()
66
+ {
67
+ $vocabularyAttributesBlock = $this->getLayout()->createBlock(
68
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyAttributesPopup'
69
+ );
70
+
71
+ $vocabularyOptionsBlock = $this->getLayout()->createBlock(
72
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyOptionsPopup'
73
+ );
74
+
75
+ return $vocabularyAttributesBlock->toHtml() . $vocabularyOptionsBlock->toHtml() . parent::_toHtml();
76
+ }
77
+
78
+ // ####################################
79
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Menu.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_Amazon_Listing_ProductSearch_Menu
8
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
9
+ {
10
+ protected $listingProductId;
11
+
12
+ // ####################################
13
+
14
+ /**
15
+ * @param mixed $listingProductId
16
+ * @return $this
17
+ */
18
+ public function setListingProductId($listingProductId)
19
+ {
20
+ $this->listingProductId = $listingProductId;
21
+
22
+ return $this;
23
+ }
24
+ /**
25
+ * @return mixed
26
+ */
27
+ public function getListingProductId()
28
+ {
29
+ return $this->listingProductId;
30
+ }
31
+
32
+ //------------------------------
33
+
34
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
35
+ protected $listingProduct = null;
36
+
37
+ /**
38
+ * @return Ess_M2ePro_Model_Listing_Product|null
39
+ */
40
+ public function getListingProduct()
41
+ {
42
+ if(is_null($this->listingProduct)) {
43
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
44
+ ->getObject('Listing_Product', $this->getListingProductId());
45
+ }
46
+
47
+ return $this->listingProduct;
48
+ }
49
+
50
+ public function isIndividualFromBundleOrSimpleWithCustome()
51
+ {
52
+ if (!$this->getListingProduct()->getChildObject()->getVariationManager()->isIndividualType()) {
53
+ return false;
54
+ }
55
+
56
+ return $this->getListingProduct()->getMagentoProduct()->isBundleType() ||
57
+ $this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
58
+ }
59
+
60
+ public function isParentFromBundleOrSimpleWithCustome()
61
+ {
62
+ if (!$this->getListingProduct()->getChildObject()->getVariationManager()->isRelationParentType()) {
63
+ return false;
64
+ }
65
+
66
+ return $this->getListingProduct()->getMagentoProduct()->isBundleType() ||
67
+ $this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
68
+ }
69
+
70
+ public function __construct()
71
+ {
72
+ parent::__construct();
73
+
74
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/menu.phtml');
75
+ }
76
+
77
+ protected function _beforeToHtml()
78
+ {
79
+ //------------------------------
80
+ $data = array(
81
+ 'id' => 'productSearchMenu_cancel_button',
82
+ 'label' => Mage::helper('M2ePro')->__('Close'),
83
+ 'class' => 'productSearchMenu_cancel_button'
84
+ );
85
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
86
+ $this->setChild('productSearchMenu_cancel_button', $buttonCancelBlock);
87
+ //------------------------------
88
+
89
+ parent::_beforeToHtml();
90
+ }
91
+
92
+ // ####################################
93
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/SuggestedAsinGridHelp.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_ProductSearch_SuggestedAsinGridHelp
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('amazonSuggestedAsinGridHelp');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/suggested_asin_grid_help.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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::CHANNEL_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
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()),
154
+ 'target' => '_blank'
155
+ );
156
+ //------------------------------
157
+
158
+ return $items;
159
+ }
160
+
161
+ // ########################################
162
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search/Grid.php ADDED
@@ -0,0 +1,869 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $listingProductCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
36
+ $listingProductCollection->getSelect()->distinct();
37
+ $listingProductCollection->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
+ $listingProductCollection->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
+ $listingProductCollection->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
+ $listingProductCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
81
+ $listingProductCollection->getSelect()->columns(
82
+ array(
83
+ 'is_m2epro_listing' => new Zend_Db_Expr('1'),
84
+ 'magento_sku' => 'cpe.sku',
85
+ 'is_in_stock' => 'cisi.is_in_stock',
86
+ 'product_name' => 'cpev.value',
87
+ 'listing_title' => 'l.title',
88
+ 'store_id' => 'l.store_id',
89
+ 'account_id' => 'l.account_id',
90
+ 'marketplace_id' => 'l.marketplace_id',
91
+ 'template_selling_format_id' => 'al.template_selling_format_id',
92
+ 'listing_product_id' => 'main_table.id',
93
+ 'product_id' => 'main_table.product_id',
94
+ 'listing_id' => 'main_table.listing_id',
95
+ 'status' => 'main_table.status',
96
+ 'general_id' => 'second_table.general_id',
97
+ 'is_afn_channel' => 'second_table.is_afn_channel',
98
+ 'is_variation_parent' => 'second_table.is_variation_parent',
99
+ 'online_sku' => 'second_table.sku',
100
+ 'online_qty' => 'second_table.online_qty',
101
+ 'online_price' => 'second_table.online_price',
102
+ 'online_sale_price' => 'second_table.online_sale_price',
103
+ 'online_sale_price_start_date' => 'second_table.online_sale_price_start_date',
104
+ 'online_sale_price_end_date' => 'second_table.online_sale_price_end_date',
105
+ 'min_online_price' => 'IF(
106
+ (`t`.`variation_min_price` IS NULL),
107
+ IF(
108
+ `second_table`.`online_sale_price_start_date` IS NOT NULL AND
109
+ `second_table`.`online_sale_price_end_date` IS NOT NULL AND
110
+ `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND
111
+ `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(),
112
+ `second_table`.`online_sale_price`,
113
+ `second_table`.`online_price`
114
+ ),
115
+ `t`.`variation_min_price`
116
+ )',
117
+ 'max_online_price' => 'IF(
118
+ (`t`.`variation_max_price` IS NULL),
119
+ IF(
120
+ `second_table`.`online_sale_price_start_date` IS NOT NULL AND
121
+ `second_table`.`online_sale_price_end_date` IS NOT NULL AND
122
+ `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND
123
+ `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(),
124
+ `second_table`.`online_sale_price`,
125
+ `second_table`.`online_price`
126
+ ),
127
+ `t`.`variation_max_price`
128
+ )'
129
+ )
130
+ );
131
+ $listingProductCollection->getSelect()->joinLeft(
132
+ new Zend_Db_Expr('(
133
+ SELECT
134
+ `malp`.`variation_parent_id`,
135
+ MIN(
136
+ IF(
137
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
138
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
139
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
140
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
141
+ `malp`.`online_sale_price`,
142
+ `malp`.`online_price`
143
+ )
144
+ ) as variation_min_price,
145
+ MAX(
146
+ IF(
147
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
148
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
149
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
150
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
151
+ `malp`.`online_sale_price`,
152
+ `malp`.`online_price`
153
+ )
154
+ ) as variation_max_price
155
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
156
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
157
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
158
+ WHERE `mlp`.`status` IN (
159
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
160
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
161
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
162
+ GROUP BY `malp`.`variation_parent_id`
163
+ )'),
164
+ 'second_table.listing_product_id=t.variation_parent_id',
165
+ array(
166
+ 'variation_min_price' => 'variation_min_price',
167
+ 'variation_max_price' => 'variation_max_price',
168
+ )
169
+ );
170
+
171
+ //------------------------------
172
+ $listingOtherCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
173
+ $listingOtherCollection->getSelect()->distinct();
174
+
175
+ // add stock availability, type id, status & visibility to select
176
+ //------------------------------
177
+ $listingOtherCollection->getSelect()
178
+ ->joinLeft(
179
+ array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()),
180
+ '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)',
181
+ array('is_in_stock'))
182
+ ->joinLeft(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
183
+ '(cpe.entity_id = `main_table`.product_id)',
184
+ array('magento_sku'=>'sku'));
185
+ //------------------------------
186
+
187
+ $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
188
+ $listingOtherCollection->getSelect()->columns(
189
+ array(
190
+ 'is_m2epro_listing' => new Zend_Db_Expr(0),
191
+ 'magento_sku' => 'cpe.sku',
192
+ 'is_in_stock' => 'cisi.is_in_stock',
193
+ 'product_name' => 'second_table.title',
194
+ 'listing_title' => new Zend_Db_Expr('NULL'),
195
+ 'store_id' => new Zend_Db_Expr(0),
196
+ 'account_id' => 'main_table.account_id',
197
+ 'marketplace_id' => 'main_table.marketplace_id',
198
+ 'template_selling_format_id' => new Zend_Db_Expr('NULL'),
199
+ 'listing_product_id' => new Zend_Db_Expr('NULL'),
200
+ 'product_id' => 'main_table.product_id',
201
+ 'listing_id' => new Zend_Db_Expr('NULL'),
202
+ 'status' => 'main_table.status',
203
+ 'general_id' => 'second_table.general_id',
204
+ 'is_afn_channel' => 'second_table.is_afn_channel',
205
+ 'is_variation_parent' => new Zend_Db_Expr('NULL'),
206
+ 'online_sku' => 'second_table.sku',
207
+ 'online_qty' => 'second_table.online_qty',
208
+ 'online_price' => 'second_table.online_price',
209
+ 'online_sale_price' => new Zend_Db_Expr('NULL'),
210
+ 'online_sale_price_start_date' => new Zend_Db_Expr('NULL'),
211
+ 'online_sale_price_end_date' => new Zend_Db_Expr('NULL'),
212
+ 'min_online_price' => 'second_table.online_price',
213
+ 'max_online_price' => 'second_table.online_price',
214
+ 'variation_min_price' => new Zend_Db_Expr('NULL'),
215
+ 'variation_max_price' => new Zend_Db_Expr('NULL')
216
+ )
217
+ );
218
+ //------------------------------
219
+
220
+ //------------------------------
221
+ $selects = array(
222
+ $listingProductCollection->getSelect(),
223
+ $listingOtherCollection->getSelect()
224
+ );
225
+
226
+ $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
227
+ $unionSelect->union($selects);
228
+
229
+ $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
230
+ $resultCollection->getSelect()->reset()->from(
231
+ array('main_table' => $unionSelect),
232
+ array(
233
+ 'is_m2epro_listing',
234
+ 'magento_sku',
235
+ 'is_in_stock',
236
+ 'product_name',
237
+ 'listing_title',
238
+ 'store_id',
239
+ 'account_id',
240
+ 'marketplace_id',
241
+ 'template_selling_format_id',
242
+ 'listing_product_id',
243
+ 'product_id',
244
+ 'listing_id',
245
+ 'status',
246
+ 'general_id',
247
+ 'is_afn_channel',
248
+ 'is_variation_parent',
249
+ 'online_sku',
250
+ 'online_qty',
251
+ 'online_price',
252
+ 'online_sale_price',
253
+ 'online_sale_price_start_date',
254
+ 'online_sale_price_end_date',
255
+ 'min_online_price',
256
+ 'max_online_price',
257
+ 'variation_min_price',
258
+ 'variation_max_price'
259
+ )
260
+ );
261
+
262
+ // exit($resultCollection->getSelect()->__toString());
263
+
264
+ // Set collection to grid
265
+ $this->setCollection($resultCollection);
266
+
267
+ return parent::_prepareCollection();
268
+ }
269
+
270
+ protected function _prepareColumns()
271
+ {
272
+ $this->addColumn('product_id', array(
273
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
274
+ 'align' => 'right',
275
+ 'width' => '100px',
276
+ 'type' => 'number',
277
+ 'index' => 'product_id',
278
+ 'filter_index' => 'product_id',
279
+ 'frame_callback' => array($this, 'callbackColumnProductId')
280
+ ));
281
+
282
+ $this->addColumn('name', array(
283
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Listing / Product SKU'),
284
+ 'align' => 'left',
285
+ //'width' => '300px',
286
+ 'type' => 'text',
287
+ 'index' => 'product_name',
288
+ 'filter_index' => 'product_name',
289
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
290
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
291
+ ));
292
+
293
+ $this->addColumn('stock_availability',
294
+ array(
295
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
296
+ 'width' => '100px',
297
+ 'index' => 'is_in_stock',
298
+ 'filter_index' => 'is_in_stock',
299
+ 'type' => 'options',
300
+ 'sortable' => false,
301
+ 'options' => array(
302
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
303
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
304
+ ),
305
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
306
+ ));
307
+
308
+ if (Mage::helper('M2ePro/View_Common')->is3rdPartyShouldBeShown(Ess_M2ePro_Helper_Component_Amazon::NICK)) {
309
+ $this->addColumn('is_m2epro_listing', array(
310
+ 'header' => Mage::helper('M2ePro')->__('Listing Type'),
311
+ 'align' => 'left',
312
+ 'width' => '100px',
313
+ 'type' => 'options',
314
+ 'sortable' => false,
315
+ 'index' => 'is_m2epro_listing',
316
+ 'options' => array(
317
+ 1 => Mage::helper('M2ePro')->__('M2E Pro'),
318
+ 0 => Mage::helper('M2ePro')->__('3rd Party')
319
+ )
320
+ ));
321
+ }
322
+
323
+ $this->addColumn('sku', array(
324
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
325
+ 'align' => 'left',
326
+ 'width' => '150px',
327
+ 'type' => 'text',
328
+ 'index' => 'online_sku',
329
+ 'filter_index' => 'online_sku',
330
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
331
+ ));
332
+
333
+ $this->addColumn('general_id', array(
334
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
335
+ 'align' => 'left',
336
+ 'width' => '90px',
337
+ 'type' => 'text',
338
+ 'index' => 'general_id',
339
+ 'filter_index' => 'general_id',
340
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
341
+ ));
342
+
343
+ $this->addColumn('online_qty', array(
344
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
345
+ 'align' => 'right',
346
+ 'width' => '70px',
347
+ 'type' => 'number',
348
+ 'index' => 'online_qty',
349
+ 'filter_index' => 'online_qty',
350
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
351
+ ));
352
+
353
+ $dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
354
+
355
+ if ($dir == 'desc') {
356
+ $priceSortField = 'max_online_price';
357
+ } else {
358
+ $priceSortField = 'min_online_price';
359
+ }
360
+
361
+ $this->addColumn('online_price', array(
362
+ 'header' => Mage::helper('M2ePro')->__('Price'),
363
+ 'align' => 'right',
364
+ 'width' => '70px',
365
+ 'type' => 'number',
366
+ 'index' => $priceSortField,
367
+ 'filter_index' => $priceSortField,
368
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
369
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
370
+ ));
371
+
372
+ $this->addColumn('is_afn_channel', array(
373
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
374
+ 'width' => '90px',
375
+ 'index' => 'is_afn_channel',
376
+ 'filter_index' => 'is_afn_channel',
377
+ 'type' => 'options',
378
+ 'sortable' => false,
379
+ 'options' => array(
380
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
381
+ 1 => Mage::helper('M2ePro')->__('Amazon')
382
+ ),
383
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
384
+ ));
385
+
386
+ $this->addColumn('status', array(
387
+ 'header' => Mage::helper('M2ePro')->__('Status'),
388
+ 'width' => '125px',
389
+ 'index' => 'status',
390
+ 'filter_index' => 'status',
391
+ 'type' => 'options',
392
+ 'sortable' => false,
393
+ 'options' => array(
394
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
395
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
396
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
397
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
398
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
399
+ ),
400
+ 'frame_callback' => array($this, 'callbackColumnStatus')
401
+ ));
402
+
403
+ $this->addColumn('goto_listing_item', array(
404
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
405
+ 'align' => 'center',
406
+ 'width' => '50px',
407
+ 'type' => 'text',
408
+ 'filter' => false,
409
+ 'sortable' => false,
410
+ 'frame_callback' => array($this, 'callbackColumnActions')
411
+ ));
412
+
413
+ return parent::_prepareColumns();
414
+ }
415
+
416
+ // ####################################
417
+
418
+ public function callbackColumnProductId($value, $row, $column, $isExport)
419
+ {
420
+ if (is_null($row->getData('product_id'))) {
421
+ return Mage::helper('M2ePro')->__('N/A');
422
+ }
423
+
424
+ $productId = (int)$row->getData('product_id');
425
+ $storeId = (int)$row->getData('store_id');
426
+
427
+ $withoutImageHtml = '<a href="'
428
+ .$this->getUrl('adminhtml/catalog_product/edit',
429
+ array('id' => $productId))
430
+ .'" target="_blank">'
431
+ .$productId
432
+ .'</a>';
433
+
434
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
435
+ ->getGroupValue('/view/',
436
+ 'show_products_thumbnails');
437
+ if (!$showProductsThumbnails) {
438
+ return $withoutImageHtml;
439
+ }
440
+
441
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
442
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
443
+ $magentoProduct->setProductId($productId);
444
+ $magentoProduct->setStoreId($storeId);
445
+
446
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
447
+ if (is_null($imageUrlResized)) {
448
+ return $withoutImageHtml;
449
+ }
450
+
451
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
452
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
453
+
454
+ return $withImageHtml;
455
+ }
456
+
457
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
458
+ {
459
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
460
+
461
+ if (!is_null($row->getData('listing_id'))) {
462
+ $urlParams = array();
463
+ $urlParams['id'] = $row->getData('listing_id');
464
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/search');
465
+
466
+ $listingUrl = $this->getUrl('*/adminhtml_common_amazon_listing/view',$urlParams);
467
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
468
+
469
+ if (strlen($listingTitle) > 50) {
470
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
471
+ }
472
+
473
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
474
+ $value .= '<strong>'
475
+ .Mage::helper('M2ePro')->__('Listing')
476
+ .': </strong> <a href="'
477
+ .$listingUrl
478
+ .'">'
479
+ .$listingTitle
480
+ .'</a>';
481
+ }
482
+
483
+ if (!is_null($row->getData('magento_sku'))) {
484
+ $tempSku = $row->getData('magento_sku');
485
+
486
+ $value .= '<br/><strong>'
487
+ . Mage::helper('M2ePro')->__('SKU')
488
+ . ':</strong> '
489
+ . Mage::helper('M2ePro')->escapeHtml($tempSku);
490
+ }
491
+
492
+ if (is_null($row->getData('listing_product_id'))) {
493
+ return $value;
494
+ }
495
+
496
+ $listingProductId = (int)$row->getData('listing_product_id');
497
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
498
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
499
+
500
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
501
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
502
+ ->getTypeModel()->getProductAttributes();
503
+
504
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey;"><br/>';
505
+ $value .= implode(', ', $productOptions);
506
+ $value .= '</div>';
507
+ }
508
+
509
+ if ($listingProduct->getChildObject()->getVariationManager()->isIndividualType() &&
510
+ $listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()
511
+ ) {
512
+ $productOptions = $listingProduct->getChildObject()
513
+ ->getVariationManager()->getTypeModel()->getProductOptions();
514
+
515
+ $value .= '<br/>';
516
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
517
+ foreach ($productOptions as $attribute => $option) {
518
+ !$option && $option = '--';
519
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
520
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
521
+ }
522
+ $value .= '</div>';
523
+ $value .= '<br/>';
524
+ }
525
+
526
+ return $value;
527
+ }
528
+
529
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
530
+ {
531
+ if (is_null($row->getData('is_in_stock'))) {
532
+ return Mage::helper('M2ePro')->__('N/A');
533
+ }
534
+
535
+ if ((int)$row->getData('is_in_stock') <= 0) {
536
+ return '<span style="color: red;">'.$value.'</span>';
537
+ }
538
+
539
+ return $value;
540
+ }
541
+
542
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
543
+ {
544
+ if (is_null($value) || $value === '') {
545
+ return Mage::helper('M2ePro')->__('N/A');
546
+ }
547
+ return $value;
548
+ }
549
+
550
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
551
+ {
552
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
553
+ if (is_null($value) || $value === '') {
554
+ return Mage::helper('M2ePro')->__('N/A');
555
+ }
556
+ } else {
557
+ if (is_null($value) || $value === '') {
558
+ return '<i style="color:gray;">receiving...</i>';
559
+ }
560
+ }
561
+
562
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($value, $row->getData('marketplace_id'));
563
+
564
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
565
+ }
566
+
567
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
568
+ {
569
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
570
+ if (is_null($value) || $value === '') {
571
+ return Mage::helper('M2ePro')->__('N/A');
572
+ }
573
+ } else {
574
+ if (is_null($value) || $value === '') {
575
+ return '<i style="color:gray;">receiving...</i>';
576
+ }
577
+ }
578
+
579
+ if ((bool)$row->getData('is_afn_channel')) {
580
+ return '--';
581
+ }
582
+
583
+ if ($value <= 0) {
584
+ return '<span style="color: red;">0</span>';
585
+ }
586
+
587
+ return $value;
588
+ }
589
+
590
+ public function callbackColumnPrice($value, $row, $column, $isExport)
591
+ {
592
+ $onlineMinPrice = $row->getData('min_online_price');
593
+ $onlineMaxPrice = $row->getData('max_online_price');
594
+
595
+ if (is_null($onlineMinPrice) || $onlineMinPrice === '') {
596
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
597
+ $row->getData('is_variation_parent')
598
+ ) {
599
+ return Mage::helper('M2ePro')->__('N/A');
600
+ } else {
601
+ return '<i style="color:gray;">receiving...</i>';
602
+ }
603
+ }
604
+
605
+ $marketplaceId = $row->getData('marketplace_id');
606
+ $currency = Mage::helper('M2ePro/Component_Amazon')
607
+ ->getCachedObject('Marketplace',$marketplaceId)
608
+ ->getChildObject()
609
+ ->getDefaultCurrency();
610
+
611
+ if ($row->getData('is_variation_parent')) {
612
+ $onlineMinPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMinPrice);
613
+ $onlineMaxPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMaxPrice);
614
+
615
+ return $onlineMinPriceStr . (($onlineMinPrice != $onlineMaxPrice) ? ' - ' . $onlineMaxPriceStr : '');
616
+ }
617
+
618
+ $onlinePrice = $row->getData('online_price');
619
+ if ((float)$onlinePrice <= 0) {
620
+ $priceValue = '<span style="color: #f00;">0</span>';
621
+ } else {
622
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
623
+ }
624
+
625
+ $resultHtml = '';
626
+
627
+ $salePrice = $row->getData('online_sale_price');
628
+ if (!$row->getData('is_variation_parent') && (float)$salePrice > 0) {
629
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
630
+
631
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
632
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
633
+
634
+ if ($currentTimestamp <= $endDateTimestamp) {
635
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
636
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
637
+
638
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
639
+
640
+ $fromDate = Mage::app()->getLocale()->date(
641
+ $row->getData('online_sale_price_start_date'), $dateFormat
642
+ )->toString($dateFormat);
643
+ $toDate = Mage::app()->getLocale()->date(
644
+ $row->getData('online_sale_price_end_date'), $dateFormat
645
+ )->toString($dateFormat);
646
+
647
+ $intervalHtml = '<img class="tool-tip-image"
648
+ style="vertical-align: middle;"
649
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
650
+ text-align: left;
651
+ width: 110px;
652
+ background: #E3E3E3;">
653
+ <img src="'.$iconHelpPath.'">
654
+ <span style="color:gray;">
655
+ <strong>From:</strong> '.$fromDate.'<br/>
656
+ <strong>To:</strong> '.$toDate.'
657
+ </span>
658
+ </span>';
659
+
660
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
661
+
662
+ if ($currentTimestamp >= $startDateTimestamp &&
663
+ $currentTimestamp <= $endDateTimestamp &&
664
+ $salePrice < (float)$onlinePrice
665
+ ) {
666
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
667
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
668
+ } else {
669
+ $resultHtml .= $priceValue;
670
+ $resultHtml .= '<br/>'.$intervalHtml.
671
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
672
+ }
673
+ }
674
+ }
675
+
676
+ if (empty($resultHtml)) {
677
+ $resultHtml = $priceValue;
678
+ }
679
+
680
+ return $resultHtml;
681
+ }
682
+
683
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
684
+ {
685
+ if (is_null($value) || $value === '') {
686
+ return Mage::helper('M2ePro')->__('N/A');
687
+ }
688
+
689
+ switch ($row->getData('is_afn_channel')) {
690
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
691
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
692
+ break;
693
+
694
+ default:
695
+ break;
696
+ }
697
+
698
+ return $value;
699
+ }
700
+
701
+ public function callbackColumnStatus($value, $row, $column, $isExport)
702
+ {
703
+ switch ($row->getData('status')) {
704
+
705
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
706
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
707
+ $value = '<span style="color: gray;">' . $value . '</span>';
708
+ break;
709
+
710
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
711
+ $value = '<span style="color: green;">' . $value . '</span>';
712
+ break;
713
+
714
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
715
+ $value = '<span style="color: red;">'.$value.'</span>';
716
+ break;
717
+
718
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
719
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
720
+ break;
721
+
722
+ default:
723
+ break;
724
+ }
725
+
726
+ if (is_null($row->getData('listing_product_id'))) {
727
+ return $value;
728
+ }
729
+
730
+ $listingProductId = (int)$row->getData('listing_product_id');
731
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
732
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
733
+
734
+ $tempLocks = $listingProduct->getObjectLocks();
735
+
736
+ foreach ($tempLocks as $lock) {
737
+
738
+ switch ($lock->getTag()) {
739
+
740
+ case 'list_action':
741
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
742
+ break;
743
+
744
+ case 'relist_action':
745
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
746
+ break;
747
+
748
+ case 'revise_action':
749
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
750
+ break;
751
+
752
+ case 'stop_action':
753
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
754
+ break;
755
+
756
+ case 'stop_and_remove_action':
757
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
758
+ break;
759
+
760
+ case 'delete_and_remove_action':
761
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
762
+ break;
763
+
764
+ default:
765
+ break;
766
+
767
+ }
768
+ }
769
+
770
+ return $value;
771
+ }
772
+
773
+ public function callbackColumnActions($value, $row, $column, $isExport)
774
+ {
775
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to Listing'));
776
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
777
+
778
+ if ($row->getData('is_m2epro_listing')) {
779
+ $url = $this->getUrl('*/adminhtml_common_amazon_listing/view/',array(
780
+ 'id' => $row->getData('listing_id'),
781
+ 'filter' => base64_encode(
782
+ 'product_id[from]='.(int)$row->getData('product_id')
783
+ .'&product_id[to]='.(int)$row->getData('product_id')
784
+ )
785
+ ));
786
+ } else {
787
+ $url = $this->getUrl('*/adminhtml_common_amazon_listing_other/view/', array(
788
+ 'account' => $row->getData('account_id'),
789
+ 'marketplace' => $row->getData('marketplace_id'),
790
+ 'filter' => base64_encode(
791
+ 'title='.$row->getData('online_sku')
792
+ )
793
+ ));
794
+ }
795
+
796
+ $html = <<<HTML
797
+ <div style="float:right; margin:5px 15px 0 0;">
798
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" alt="{$altTitle}" /></a>
799
+ </div>
800
+ HTML;
801
+
802
+ return $html;
803
+ }
804
+
805
+ // ####################################
806
+
807
+ protected function callbackFilterTitle($collection, $column)
808
+ {
809
+ $value = $column->getFilter()->getValue();
810
+
811
+ if ($value == null) {
812
+ return;
813
+ }
814
+
815
+ $collection->getSelect()
816
+ ->where('product_name LIKE ? OR magento_sku LIKE ? OR listing_title LIKE ?', '%'.$value.'%');
817
+ }
818
+
819
+ protected function callbackFilterPrice($collection, $column)
820
+ {
821
+ $value = $column->getFilter()->getValue();
822
+
823
+ if (empty($value)) {
824
+ return;
825
+ }
826
+
827
+ $condition = '';
828
+
829
+ if (!empty($value['from'])) {
830
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
831
+ }
832
+ if (!empty($value['to'])) {
833
+ if (!empty($value['from'])) {
834
+ $condition .= ' AND ';
835
+ }
836
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
837
+ }
838
+
839
+ $condition = '(' . $condition . ') OR (';
840
+
841
+ if (!empty($value['from'])) {
842
+ $condition .= 'max_online_price >= \''.$value['from'].'\'';
843
+ }
844
+ if (!empty($value['to'])) {
845
+ if (!empty($value['from'])) {
846
+ $condition .= ' AND ';
847
+ }
848
+ $condition .= 'max_online_price <= \''.$value['to'].'\'';
849
+ }
850
+
851
+ $condition .= ')';
852
+
853
+ $collection->getSelect()->where($condition);
854
+ }
855
+
856
+ // ####################################
857
+
858
+ public function getGridUrl()
859
+ {
860
+ return $this->getUrl('*/adminhtml_common_amazon_listing/searchGrid', array('_current'=>true));
861
+ }
862
+
863
+ public function getRowUrl($row)
864
+ {
865
+ return false;
866
+ }
867
+
868
+ // ####################################
869
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Grid.php ADDED
@@ -0,0 +1,459 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
10
+ const ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED = 1;
11
+ const ACTION_STATUS_VARIATIONS_NOT_SUPPORTED = 2;
12
+ const ACTION_STATUS_ATTRIBUTES_COUNT_MISMATCH = 3;
13
+ const ACTION_STATUS_READY_TO_BE_ASSIGNED = 4;
14
+
15
+ protected $attributesSetsIds;
16
+ protected $marketplaceId;
17
+ protected $listingProduct;
18
+ protected $productsAttributesCountVariations;
19
+
20
+ protected $checkNewAsinAccepted = false;
21
+ protected $productsIds;
22
+ protected $mapToTemplateJsFn = 'ListingGridHandlerObj.templateDescriptionHandler.mapToTemplateDescription';
23
+
24
+ // ####################################
25
+
26
+ /**
27
+ * @return string
28
+ */
29
+ public function getMapToTemplateJsFn()
30
+ {
31
+ return $this->mapToTemplateJsFn;
32
+ }
33
+
34
+ /**
35
+ * @param string $mapToTemplateLink
36
+ */
37
+ public function setMapToTemplateJsFn($mapToTemplateLink)
38
+ {
39
+ $this->mapToTemplateJsFn = $mapToTemplateLink;
40
+ }
41
+
42
+ //------------------------------
43
+
44
+ /**
45
+ * @param boolean $checkNewAsinAccepted
46
+ */
47
+ public function setCheckNewAsinAccepted($checkNewAsinAccepted)
48
+ {
49
+ $this->checkNewAsinAccepted = $checkNewAsinAccepted;
50
+ }
51
+
52
+ /**
53
+ * @return boolean
54
+ */
55
+ public function getCheckNewAsinAccepted()
56
+ {
57
+ return (bool) $this->checkNewAsinAccepted;
58
+ }
59
+
60
+ //------------------------------
61
+
62
+ /**
63
+ * @param mixed $productsIds
64
+ */
65
+ public function setProductsIds($productsIds)
66
+ {
67
+ $this->productsIds = $productsIds;
68
+ }
69
+
70
+ /**
71
+ * @return mixed
72
+ */
73
+ public function getProductsIds()
74
+ {
75
+ return $this->productsIds;
76
+ }
77
+
78
+ //------------------------------
79
+
80
+ public function __construct()
81
+ {
82
+ parent::__construct();
83
+
84
+ $this->setId('amazonTemplateDescriptionGrid');
85
+
86
+ // Set default values
87
+ //------------------------------
88
+ $this->setFilterVisibility(false);
89
+ //$this->setPagerVisibility(false);
90
+ $this->setDefaultSort('id');
91
+ $this->setDefaultDir('ASC');
92
+ $this->setSaveParametersInSession(false);
93
+ $this->setUseAjax(true);
94
+ //------------------------------
95
+ }
96
+
97
+ //------------------------------
98
+
99
+ protected function _prepareCollection()
100
+ {
101
+ $this->setNoTemplatesText();
102
+
103
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Template_Description_Collection $collection */
104
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Template_Description');
105
+ $collection->addFieldToFilter('marketplace_id', $this->getMarketplaceId());
106
+
107
+ $this->setCollection($this->prepareCollection($collection));
108
+
109
+ return parent::_prepareCollection();
110
+ }
111
+
112
+ protected function _prepareColumns()
113
+ {
114
+ $this->addColumn('title', array(
115
+ 'header' => Mage::helper('M2ePro')->__('Title'),
116
+ 'align' => 'left',
117
+ 'type' => 'text',
118
+ 'index' => 'title',
119
+ 'filter' => false,
120
+ 'sortable' => false,
121
+ 'frame_callback' => array($this, 'callbackColumnTitle')
122
+ ));
123
+
124
+ $this->addColumn('status', array(
125
+ 'header' => Mage::helper('M2ePro')->__('Status/Reason'),
126
+ 'align' => 'left',
127
+ 'type' => 'text',
128
+ 'width' => '140px',
129
+ 'index' => 'title',
130
+ 'filter' => false,
131
+ 'sortable' => false,
132
+ 'frame_callback' => array($this, 'callbackColumnStatus')
133
+ ));
134
+
135
+ $this->addColumn('action', array(
136
+ 'header' => Mage::helper('M2ePro')->__('Action'),
137
+ 'align' => 'left',
138
+ 'type' => 'number',
139
+ 'width' => '55px',
140
+ 'index' => 'id',
141
+ 'filter' => false,
142
+ 'sortable' => false,
143
+ 'frame_callback' => array($this, 'callbackColumnAction')
144
+ ));
145
+ }
146
+
147
+ protected function _prepareLayout()
148
+ {
149
+ $this->setChild('refresh_button',
150
+ $this->getLayout()->createBlock('adminhtml/widget_button')
151
+ ->setData(array(
152
+ 'id' => 'description_template_refresh_btn',
153
+ 'label' => Mage::helper('M2ePro')->__('Refresh'),
154
+ 'onclick' => $this->getJsObjectName().'.reload()'
155
+ ))
156
+ );
157
+
158
+ return parent::_prepareLayout();
159
+ }
160
+
161
+ // ####################################
162
+
163
+ public function getRefreshButtonHtml()
164
+ {
165
+ return $this->getChildHtml('refresh_button');
166
+ }
167
+
168
+ // ####################################
169
+
170
+ public function getMainButtonsHtml()
171
+ {
172
+ return $this->getRefreshButtonHtml() . parent::getMainButtonsHtml();
173
+ }
174
+
175
+ // ####################################
176
+
177
+ public function callbackColumnTitle($value, $row, $column, $isExport)
178
+ {
179
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
180
+ 'id' => $row->getData('id')
181
+ ));
182
+
183
+ $title = Mage::helper('M2ePro')->escapeHtml($row->getData('title'));
184
+
185
+ $categoryWord = Mage::helper('M2ePro')->__('Category');
186
+ $categoryPath = !empty($row['category_path']) ? "{$row['category_path']} ({$row['browsenode_id']})"
187
+ : Mage::helper('M2ePro')->__('N/A');
188
+
189
+ return <<<HTML
190
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
191
+ <div>
192
+ <span style="font-weight: bold">{$categoryWord}</span>: <span style="color: #505050">{$categoryPath}</span><br/>
193
+ </div>
194
+ HTML;
195
+
196
+ }
197
+
198
+ public function callbackColumnStatus($value, $row, $column, $isExport)
199
+ {
200
+ switch($row->getData('description_template_action_status')) {
201
+ case self::ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED:
202
+ return '<span style="color: #808080;">' .
203
+ Mage::helper('M2ePro')->__('New ASIN/ISBN feature is disabled') . '</span>';
204
+ break;
205
+ case self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED:
206
+ return '<span style="color: #808080;">' .
207
+ Mage::helper('M2ePro')->__(
208
+ 'Selected Category doesn\'t support Variational Products'
209
+ ) . '</span>';
210
+ break;
211
+ case self::ACTION_STATUS_ATTRIBUTES_COUNT_MISMATCH:
212
+ return '<span style="color: #808080;">' .
213
+ Mage::helper('M2ePro')->__(
214
+ 'This number of Variation Attributes cannot be used in chosen Category'
215
+ ) . '</span>';
216
+ break;
217
+ }
218
+
219
+ return '<span style="color: green;">' . Mage::helper('M2ePro')->__('Ready to be assigned') . '</span>';
220
+ }
221
+
222
+ public function callbackColumnAction($value, $row, $column, $isExport)
223
+ {
224
+ $assignText = Mage::helper('M2ePro')->__('Assign');
225
+ $mapToAsin = '';
226
+
227
+ if ($this->getCheckNewAsinAccepted()) {
228
+ $mapToAsin = ',1';
229
+ }
230
+
231
+ switch($row->getData('description_template_action_status')) {
232
+ case self::ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED:
233
+ return '<span style="color: #808080;">' . $assignText . '</span>';
234
+ break;
235
+ case self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED:
236
+ return '<span style="color: #808080;">' . $assignText . '</span>';
237
+ break;
238
+ case self::ACTION_STATUS_ATTRIBUTES_COUNT_MISMATCH:
239
+ return '<span style="color: #808080;">' . $assignText . '</span>';
240
+ break;
241
+ }
242
+
243
+ return '<a href="javascript:void(0);"'
244
+ . 'onclick="' . $this->getMapToTemplateJsFn() . '(this, '
245
+ . $value . $mapToAsin .');">'.$assignText.'</a>';
246
+ }
247
+
248
+ // ####################################
249
+
250
+ protected function _toHtml()
251
+ {
252
+ $productsIdsStr = implode(',', $this->getProductsIds());
253
+
254
+ $javascriptsMain = <<<JAVASCRIPT
255
+ <script type="text/javascript">
256
+
257
+ $$('#amazonTemplateDescriptionGrid div.grid th').each(function(el){
258
+ el.style.padding = '5px 5px';
259
+ });
260
+
261
+ $$('#amazonTemplateDescriptionGrid div.grid td').each(function(el){
262
+ el.style.padding = '5px 5px';
263
+ });
264
+
265
+ {$this->getJsObjectName()}.reloadParams = {$this->getJsObjectName()}.reloadParams || {};
266
+ {$this->getJsObjectName()}.reloadParams['products_ids'] = '{$productsIdsStr}';
267
+
268
+ </script>
269
+ JAVASCRIPT;
270
+
271
+ //------------------------------
272
+ $templateDescriptionNewUrl = $this->getNewTemplateDescriptionUrl();
273
+
274
+ $data = array(
275
+ 'id' => 'templateDescription_addNew_button',
276
+ 'label' => Mage::helper('M2ePro')->__('Add New Description Policy'),
277
+ 'class' => 'templateDescription_addNew_button',
278
+ 'style' => 'float: right;',
279
+ 'onclick' => 'ListingGridHandlerObj.templateDescriptionHandler'
280
+ . '.createTemplateDescriptionInNewTab(\'' . $templateDescriptionNewUrl . '\')'
281
+ );
282
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
283
+ //------------------------------
284
+
285
+ $buttonBlockHtml = ($this->canDisplayContainer()) ? $buttonBlock->toHtml(): '';
286
+
287
+ return parent::_toHtml() . $buttonBlockHtml . $javascriptsMain;
288
+ }
289
+
290
+ // ####################################
291
+
292
+ public function getGridUrl()
293
+ {
294
+ return $this->getUrl('*/*/viewTemplateDescriptionsGrid', array(
295
+ '_current' => true,
296
+ '_query' => array(
297
+ 'check_is_new_asin_accepted' => $this->getCheckNewAsinAccepted()
298
+ )
299
+ ));
300
+ }
301
+
302
+ public function getRowUrl($row)
303
+ {
304
+ return false;
305
+ }
306
+
307
+ // ####################################
308
+
309
+ protected function getMarketplaceId()
310
+ {
311
+ if(empty($this->marketplaceId)) {
312
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
313
+ $productsIds = $this->getProductsIds();
314
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $productsIds[0]);
315
+ $this->marketplaceId = $listingProduct->getListing()->getMarketplaceId();
316
+ }
317
+
318
+ return $this->marketplaceId;
319
+ }
320
+
321
+ //---------------------------------------
322
+
323
+ protected function setNoTemplatesText()
324
+ {
325
+ $templateDescriptionEditUrl = $this->getNewTemplateDescriptionUrl();
326
+
327
+ $messageTxt = Mage::helper('M2ePro')->__('Description Policies are not found for current Marketplace.');
328
+ $linkTitle = Mage::helper('M2ePro')->__('Create New Description Policy.');
329
+
330
+ $message = <<<HTML
331
+ <p>{$messageTxt} <a href="javascript:void(0);"
332
+ id="templateDescription_addNew_link"
333
+ onclick="ListingGridHandlerObj.templateDescriptionHandler.createTemplateDescriptionInNewTab(
334
+ '{$templateDescriptionEditUrl}');">{$linkTitle}</a>
335
+ </p>
336
+ HTML;
337
+
338
+ $this->setEmptyText($message);
339
+ }
340
+
341
+ protected function getNewTemplateDescriptionUrl()
342
+ {
343
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/new', array(
344
+ 'is_new_asin_accepted' => $this->getCheckNewAsinAccepted(),
345
+ 'marketplace_id' => $this->getMarketplaceId()
346
+ ));
347
+ }
348
+
349
+ //---------------------------------------
350
+
351
+ protected function getParentListingProduct()
352
+ {
353
+ $productIds = $this->getProductsIds();
354
+ if (count($productIds) == 1 && empty($this->listingProduct)) {
355
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $productIds[0]);
356
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
357
+ $this->listingProduct = $listingProduct;
358
+ }
359
+ }
360
+ return $this->listingProduct;
361
+ }
362
+
363
+ //---------------------------------------
364
+
365
+ protected function getProductAttributesCountVariations()
366
+ {
367
+ if (is_null($this->productsAttributesCountVariations)) {
368
+ $this->productsAttributesCountVariations = array();
369
+
370
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Listing_Product_Collection $collection */
371
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
372
+ $collection->addFieldToFilter('additional_data', array('notnull' => true));
373
+ $collection->addFieldToFilter('id', array('in' => $this->getProductsIds()));
374
+ $collection->addFieldToFilter('is_variation_parent', 1);
375
+
376
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
377
+ $collection->addFieldToSelect('additional_data');
378
+
379
+ foreach ($collection->getData() as $row) {
380
+ $data = json_decode($row['additional_data'], true);
381
+
382
+ $count = count($data['variation_product_attributes']);
383
+ if (!in_array($count, $this->productsAttributesCountVariations)) {
384
+ $this->productsAttributesCountVariations[] = $count;
385
+ }
386
+ }
387
+ }
388
+
389
+ return $this->productsAttributesCountVariations;
390
+ }
391
+
392
+ // ####################################
393
+
394
+ private function prepareCollection($collection)
395
+ {
396
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Template_Description_Collection $preparedCollection */
397
+ $preparedCollection = new Varien_Data_Collection();
398
+
399
+ $data = $collection->getData();
400
+ $preparedData = array();
401
+ foreach ($data as $item) {
402
+ if (!$this->getCheckNewAsinAccepted()) {
403
+ $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED;
404
+ $preparedData[] = $item;
405
+ continue;
406
+ }
407
+
408
+ if (!$item['is_new_asin_accepted']) {
409
+ $item['description_template_action_status'] = self::ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED;
410
+ $preparedData[] = $item;
411
+ continue;
412
+ }
413
+
414
+ $productAttrCounts = $this->getProductAttributesCountVariations();
415
+
416
+ if (!empty($productAttrCounts)) {
417
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
418
+ $detailsModel->setMarketplaceId($this->getMarketplaceId());
419
+ $themes = $detailsModel->getVariationThemes($item['product_data_nick']);
420
+
421
+ if (empty($themes)) {
422
+ $item['description_template_action_status'] = self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED;
423
+ $preparedData[] = $item;
424
+ continue;
425
+ }
426
+
427
+ $themeAttrCounts = array();
428
+ foreach ($themes as $theme) {
429
+ $themeAttrCounts[] = count($theme['attributes']);
430
+ }
431
+
432
+ if (count(array_intersect($productAttrCounts, $themeAttrCounts)) !== count($productAttrCounts)) {
433
+ $item['description_template_action_status'] = self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED;
434
+ $preparedData[] = $item;
435
+ continue;
436
+ }
437
+ }
438
+
439
+ $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED;
440
+ $preparedData[] = $item;
441
+ continue;
442
+ }
443
+
444
+ if (!empty($preparedData)) {
445
+ usort($preparedData, function($a, $b)
446
+ {
447
+ return $a["description_template_action_status"] < $b["description_template_action_status"];
448
+ });
449
+
450
+ foreach ($preparedData as $item) {
451
+ $preparedCollection->addItem(new Varien_Object($item));
452
+ }
453
+ }
454
+
455
+ return $preparedCollection;
456
+ }
457
+
458
+ // ####################################
459
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Main.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_Listing_TemplateDescription_Main
8
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
9
+ {
10
+ protected $newAsin = false;
11
+ protected $messages = array();
12
+
13
+ // ####################################
14
+
15
+ /**
16
+ * @param array $messages
17
+ */
18
+ public function setMessages($messages)
19
+ {
20
+ $this->messages = $messages;
21
+ }
22
+
23
+ /**
24
+ * @return array
25
+ */
26
+ public function getMessages()
27
+ {
28
+ return $this->messages;
29
+ }
30
+
31
+ /**
32
+ * @return boolean
33
+ */
34
+ public function isNewAsin()
35
+ {
36
+ return $this->newAsin;
37
+ }
38
+
39
+ /**
40
+ * @param boolean $newAsin
41
+ */
42
+ public function setNewAsin($newAsin)
43
+ {
44
+ $this->newAsin = $newAsin;
45
+ }
46
+
47
+ public function __construct()
48
+ {
49
+ parent::__construct();
50
+
51
+ $this->setTemplate('M2ePro/common/amazon/listing/template_description/main.phtml');
52
+ }
53
+
54
+ public function getWarnings()
55
+ {
56
+ $warnings = '';
57
+ foreach ($this->getMessages() as $message) {
58
+ $warnings .= <<<HTML
59
+ <ul class="messages">
60
+ <li class="{$message['type']}-msg">
61
+ <ul>
62
+ <li>{$message['text']}</li>
63
+ </ul>
64
+ </li>
65
+ </ul>
66
+ HTML;
67
+ }
68
+ return $warnings;
69
+ }
70
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
13
+
14
+ /**
15
+ * @param mixed $listingProductId
16
+ */
17
+ public function setListingProductId($listingProductId)
18
+ {
19
+ $this->listingProductId = $listingProductId;
20
+ }
21
+
22
+ /**
23
+ * @return mixed
24
+ */
25
+ public function getListingProductId()
26
+ {
27
+ return $this->listingProductId;
28
+ }
29
+
30
+ //------------------------------
31
+
32
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
33
+ protected $listingProduct;
34
+
35
+ /**
36
+ * @return Ess_M2ePro_Model_Listing_Product|null
37
+ */
38
+ public function getListingProduct()
39
+ {
40
+ if(empty($this->listingProduct)) {
41
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
42
+ ->getObject('Listing_Product', $this->getListingProductId());
43
+ }
44
+
45
+ return $this->listingProduct;
46
+ }
47
+
48
+ //------------------------------
49
+
50
+ public function __construct()
51
+ {
52
+ parent::__construct();
53
+
54
+ // Initialization block
55
+ //------------------------------
56
+ $this->setId('amazonVariationProductManageTabs');
57
+ //------------------------------
58
+
59
+ $this->setTemplate('widget/tabshoriz.phtml');
60
+ $this->setDestElementId('variation_product_manage_tabs_container');
61
+ }
62
+
63
+ //------------------------------
64
+
65
+ protected function _beforeToHtml()
66
+ {
67
+ $this->addTab('variations', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Child Products'),
69
+ 'title' => Mage::helper('M2ePro')->__('Child Products'),
70
+ 'content' => $this->getLayout()
71
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_variations')
72
+ ->setListingProductId($this->getListingProductId())
73
+ ->toHtml()
74
+ ));
75
+
76
+ $settingsBlock = $this->getLayout()
77
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_settings')
78
+ ->setListingProductId($this->getListingProductId());
79
+ $settingsBlock->calculateWarnings();
80
+
81
+ $settingsBlockLabel = Mage::helper('M2ePro')->__('Settings');
82
+ $settingsBlockTitle = Mage::helper('M2ePro')->__('Settings');
83
+
84
+ if(count($settingsBlock->getMessages()) > 0) {
85
+ $iconPath = $this->getSkinUrl('M2ePro/images/'. $settingsBlock->getMessagesType() .'.png');
86
+ $problemIcon = '<img style="vertical-align: middle;" src="'
87
+ . $iconPath . '" alt="" width="16" height="15"> ';
88
+ $settingsBlockLabel = $problemIcon.$settingsBlockLabel;
89
+ $settingsBlockTitle = Mage::helper('M2ePro')->__(
90
+ 'Action required.'
91
+ );
92
+ }
93
+
94
+ $this->addTab('settings', array(
95
+ 'label' => $settingsBlockLabel,
96
+ 'title' => $settingsBlockTitle,
97
+ 'content' => $this->getLayout()
98
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_settings')
99
+ ->setListingProductId($this->getListingProductId())
100
+ ->toHtml()
101
+ ));
102
+
103
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
104
+ if(empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner()) {
105
+ $this->setActiveTab('settings');
106
+ } else {
107
+ $this->setActiveTab('variations');
108
+ }
109
+
110
+ return parent::_beforeToHtml();
111
+ }
112
+
113
+ protected function _toHtml()
114
+ {
115
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
116
+
117
+ $showMask = 0;
118
+ if(!(empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner())) {
119
+ $showMask = 1;
120
+ }
121
+
122
+ $data = array(
123
+ 'style' => 'float: right; margin-top: 7px; ',
124
+ 'label' => Mage::helper('M2ePro')->__('Close'),
125
+ 'onclick' => 'ListingGridHandlerObj.variationProductManageHandler.closeManageVariationsPopup()'
126
+ );
127
+ $closeBtn = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
128
+
129
+ $additionalJavascript = <<<JAVASCRIPT
130
+ <script type="text/javascript">
131
+ amazonVariationProductManageTabsJsTabs.moveTabContentInDest();
132
+
133
+ if (!{$showMask}) {
134
+ amazonVariationProductManageTabsJsTabs.tabs[0].hide();
135
+ }
136
+
137
+ ListingGridHandlerObj.variationProductManageHandler.loadVariationsGrid({$showMask});
138
+ </script>
139
+ JAVASCRIPT;
140
+
141
+ return parent::_toHtml() .
142
+ '<div id="variation_product_manage_tabs_container"></div>' .
143
+ $additionalJavascript .
144
+ $closeBtn->toHtml();
145
+ }
146
+
147
+ // ####################################
148
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php ADDED
@@ -0,0 +1,563 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Ess_M2ePro_Block_Adminhtml_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
+
28
+ /**
29
+ * @param mixed $listingProductId
30
+ * @return $this
31
+ */
32
+ public function setListingProductId($listingProductId)
33
+ {
34
+ $this->listingProductId = $listingProductId;
35
+
36
+ return $this;
37
+ }
38
+ /**
39
+ * @return mixed
40
+ */
41
+ public function getListingProductId()
42
+ {
43
+ return $this->listingProductId;
44
+ }
45
+
46
+ //------------------------------
47
+
48
+ protected $messages = array();
49
+ /**
50
+ * @param array $message
51
+ */
52
+ public function addMessage($message, $type = self::MESSAGE_TYPE_ERROR)
53
+ {
54
+ $this->messages[] = array(
55
+ 'type' => $type,
56
+ 'msg' => $message
57
+ );
58
+ }
59
+ /**
60
+ * @param array $messages
61
+ */
62
+ public function setMessages($messages)
63
+ {
64
+ $this->messages = $messages;
65
+ }
66
+ /**
67
+ * @return array
68
+ */
69
+ public function getMessages()
70
+ {
71
+ return $this->messages;
72
+ }
73
+
74
+ public function getMessagesType()
75
+ {
76
+ $type = self::MESSAGE_TYPE_WARNING;
77
+ foreach ($this->messages as $message) {
78
+ if($message['type'] === self::MESSAGE_TYPE_ERROR) {
79
+ $type = $message['type'];
80
+ break;
81
+ }
82
+ }
83
+
84
+ return $type;
85
+ }
86
+
87
+ //------------------------------
88
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
89
+ protected $listingProduct;
90
+
91
+ /**
92
+ * @return Ess_M2ePro_Model_Listing_Product|null
93
+ */
94
+ public function getListingProduct()
95
+ {
96
+ if(empty($this->listingProduct)) {
97
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
98
+ ->getObject('Listing_Product', $this->getListingProductId());
99
+ }
100
+
101
+ return $this->listingProduct;
102
+ }
103
+
104
+ //------------------------------
105
+
106
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute $matcherAttribute */
107
+ protected $matcherAttributes;
108
+
109
+ /**
110
+ * @return Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute
111
+ */
112
+ public function getMatcherAttributes()
113
+ {
114
+ if (empty($this->matcherAttributes)) {
115
+ $this->matcherAttributes = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Attribute');
116
+ $this->matcherAttributes->setMagentoProduct($this->getListingProduct()->getMagentoProduct());
117
+ $this->matcherAttributes->setDestinationAttributes($this->getDestinationAttributes());
118
+ }
119
+
120
+ return $this->matcherAttributes;
121
+ }
122
+
123
+ public function __construct()
124
+ {
125
+ parent::__construct();
126
+
127
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/settings.phtml');
128
+ }
129
+
130
+ //------------------------------
131
+
132
+ public function getWarnings()
133
+ {
134
+ $warnings = '';
135
+ foreach ($this->getMessages() as $message) {
136
+ $warnings .= <<<HTML
137
+ <li class="{$message['type']}-msg">
138
+ <ul>
139
+ <li>{$message['msg']}</li>
140
+ </ul>
141
+ </li>
142
+ HTML;
143
+ }
144
+ return $warnings;
145
+ }
146
+
147
+ public function calculateWarnings()
148
+ {
149
+ if(!$this->warningsCalculated) {
150
+
151
+ $this->warningsCalculated = true;
152
+
153
+ if (!$this->hasGeneralId() && $this->isGeneralIdOwner()) {
154
+ if(!$this->hasChannelTheme() || !$this->hasMatchedAttributes()) {
155
+ $this->addMessage(
156
+ Mage::helper('M2ePro')
157
+ ->__('Creation of New Parent-Child Product is impossible because Variation Theme
158
+ or correspondence between Magento Product Attributes and Amazon Product Attributes
159
+ was not set. Please, specify a Variation Theme or correspondence between
160
+ Variation Attributes.'),
161
+ self::MESSAGE_TYPE_ERROR
162
+ );
163
+ }
164
+ } elseif ($this->hasGeneralId()) {
165
+ if (!$this->hasMatchedAttributes()) {
166
+ $this->addMessage(
167
+ Mage::helper('M2ePro')->__(
168
+ 'Selling of existing Child Products on Amazon is impossible because correspondence
169
+ between Magento Product Attributes and Amazon Product Attributes was not set.
170
+ Please, specify correspondence between Variation Attributes.'
171
+ ),
172
+ self::MESSAGE_TYPE_ERROR
173
+ );
174
+ }
175
+ if ($this->isGeneralIdOwner() && !$this->hasChannelTheme()) {
176
+ $this->addMessage(
177
+ Mage::helper('M2ePro')->__(
178
+ 'Creation of New Amazon Child Products feature is temporary unavailable because
179
+ Variation Theme was not set. Please, specify Variation Theme.'
180
+ ),
181
+ self::MESSAGE_TYPE_WARNING
182
+ );
183
+ }
184
+ }
185
+
186
+ }
187
+ }
188
+
189
+ //------------------------------
190
+
191
+ protected function _beforeToHtml()
192
+ {
193
+ $this->calculateWarnings();
194
+
195
+ return parent::_beforeToHtml();
196
+ }
197
+
198
+ protected function _toHtml()
199
+ {
200
+ $vocabularyAttributesBlock = $this->getLayout()->createBlock(
201
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyAttributesPopup'
202
+ );
203
+
204
+ $vocabularyOptionsBlock = $this->getLayout()->createBlock(
205
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyOptionsPopup'
206
+ );
207
+
208
+ return $vocabularyAttributesBlock->toHtml() . $vocabularyOptionsBlock->toHtml() . parent::_toHtml();
209
+ }
210
+
211
+ // ###########################################
212
+
213
+ public function isInAction()
214
+ {
215
+ $lockedObjects = $this->getListingProduct()->getObjectLocks();
216
+ return !empty($lockedObjects);
217
+ }
218
+
219
+ // -------------------------------------------
220
+
221
+ public function getProductAttributes()
222
+ {
223
+ return $this->getListingProduct()->getChildObject()
224
+ ->getVariationManager()->getTypeModel()->getProductAttributes();
225
+ }
226
+
227
+ // -------------------------------------------
228
+
229
+ public function showGeneralIdActions()
230
+ {
231
+ return !$this->getListingProduct()->getMagentoProduct()->isBundleType() &&
232
+ !$this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
233
+ }
234
+
235
+ // -------------------------------------------
236
+
237
+ public function hasGeneralId()
238
+ {
239
+ return $this->getListingProduct()->getChildObject()->getGeneralId() !== NULL;
240
+ }
241
+
242
+ public function getGeneralId()
243
+ {
244
+ return $this->getListingProduct()->getChildObject()->getGeneralId();
245
+ }
246
+
247
+ public function getGeneralIdLink()
248
+ {
249
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
250
+ $this->getGeneralId(),
251
+ $this->getListingProduct()->getListing()->getMarketplaceId()
252
+ );
253
+
254
+ return <<<HTML
255
+ <a href="{$url}" target="_blank" title="{$this->getGeneralId()}" >{$this->getGeneralId()}</a>
256
+ HTML;
257
+ }
258
+
259
+ public function isGeneralIdOwner()
260
+ {
261
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
262
+ }
263
+
264
+ // -------------------------------------------
265
+
266
+ public function getDescriptionTemplateLink()
267
+ {
268
+ $url = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
269
+ 'id' => $this->getListingProduct()->getChildObject()->getTemplateDescriptionId()
270
+ ));
271
+
272
+ $templateTitle = $this->getListingProduct()->getChildObject()->getDescriptionTemplate()->getTitle();
273
+
274
+ return <<<HTML
275
+ <a href="{$url}" target="_blank" title="{$templateTitle}" >{$templateTitle}</a>
276
+ HTML;
277
+ }
278
+
279
+ // -------------------------------------------
280
+
281
+ public function hasChannelTheme()
282
+ {
283
+ return $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel()->hasChannelTheme();
284
+ }
285
+
286
+ public function getChannelTheme()
287
+ {
288
+ return $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel()->getChannelTheme();
289
+ }
290
+
291
+ public function getChannelThemes()
292
+ {
293
+ if (!is_null($this->channelThemes)) {
294
+ return $this->channelThemes;
295
+ }
296
+
297
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
298
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
299
+ $descriptionTemplate = $amazonListingProduct->getAmazonDescriptionTemplate();
300
+
301
+ if (!$descriptionTemplate) {
302
+ return array();
303
+ }
304
+
305
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
306
+ $detailsModel->setMarketplaceId($this->getListingProduct()->getListing()->getMarketplaceId());
307
+
308
+ return $this->channelThemes = $detailsModel->getVariationThemes($descriptionTemplate->getProductDataNick());
309
+ }
310
+
311
+ public function getChannelThemeAttr()
312
+ {
313
+ $theme = $this->getChannelTheme();
314
+ $themes = $this->getChannelThemes();
315
+
316
+ if(!empty($themes[$theme])) {
317
+ return $themes[$theme]['attributes'];
318
+ }
319
+
320
+ return null;
321
+ }
322
+
323
+ public function getChannelThemeNote()
324
+ {
325
+ $theme = $this->getChannelTheme();
326
+ $themes = $this->getChannelThemes();
327
+
328
+ if(!empty($themes[$theme])) {
329
+ return $themes[$theme]['note'];
330
+ }
331
+
332
+ return null;
333
+ }
334
+
335
+ public function getChannelThemeAttrString()
336
+ {
337
+ $themesAttributes = $this->getChannelThemeAttr();
338
+
339
+ if(!empty($themesAttributes)) {
340
+ return implode(', ', $themesAttributes);
341
+ }
342
+
343
+ return Mage::helper('M2ePro')->__('Variation Theme not found.');
344
+ }
345
+
346
+ // ----------------------------------------
347
+
348
+ public function hasMatchedAttributes()
349
+ {
350
+ return $this->getListingProduct()->getChildObject()
351
+ ->getVariationManager()->getTypeModel()->hasMatchedAttributes();
352
+ }
353
+
354
+ public function getMatchedAttributes()
355
+ {
356
+ if($this->hasMatchedAttributes()) {
357
+ return $this->getListingProduct()->getChildObject()
358
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
359
+ }
360
+ return $this->getMatcherAttributes()->getMatchedAttributes();
361
+ }
362
+
363
+ public function getDestinationAttributes()
364
+ {
365
+ if(!$this->hasGeneralId() && $this->isGeneralIdOwner() && $this->hasChannelTheme()) {
366
+ return $this->getChannelThemeAttr();
367
+ }
368
+ return array_keys($this->getListingProduct()->getChildObject()
369
+ ->getVariationManager()->getTypeModel()->getChannelAttributesSets());
370
+ }
371
+
372
+ // ###########################################
373
+
374
+ public function getChildListingProducts()
375
+ {
376
+ if (!is_null($this->childListingProducts)) {
377
+ return $this->childListingProducts;
378
+ }
379
+
380
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
381
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
382
+ }
383
+
384
+ public function getCurrentProductVariations()
385
+ {
386
+ if (!is_null($this->currentProductVariations)) {
387
+ return $this->currentProductVariations;
388
+ }
389
+
390
+ $magentoProductVariations = $this->getListingProduct()
391
+ ->getMagentoProduct()
392
+ ->getVariationInstance()
393
+ ->getVariationsTypeStandard();
394
+
395
+ $productVariations = array();
396
+
397
+ foreach ($magentoProductVariations['variations'] as $option) {
398
+ $productOption = array();
399
+
400
+ foreach ($option as $attribute) {
401
+ $productOption[$attribute['attribute']] = $attribute['option'];
402
+ }
403
+
404
+ $productVariations[] = $productOption;
405
+ }
406
+
407
+ return $this->currentProductVariations = $productVariations;
408
+ }
409
+
410
+ public function getChannelVariations()
411
+ {
412
+ if (!is_null($this->childListingProducts)) {
413
+ return $this->childListingProducts;
414
+ }
415
+
416
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
417
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
418
+ }
419
+
420
+ public function getCurrentChannelVariations()
421
+ {
422
+ return $this->getListingProduct()->getChildObject()
423
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
424
+ }
425
+
426
+ // ------------------------------------------
427
+
428
+ public function getUsedChannelVariations()
429
+ {
430
+ $usedOptions = array();
431
+
432
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
433
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
434
+
435
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
436
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
437
+
438
+ if (!$childTypeModel->isVariationChannelMatched()) {
439
+ continue;
440
+ }
441
+
442
+ $usedOptions[] = $childTypeModel->getChannelOptions();
443
+ }
444
+
445
+ return $usedOptions;
446
+ }
447
+
448
+ public function getUsedProductVariations()
449
+ {
450
+ $usedOptions = array();
451
+
452
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
453
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
454
+
455
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
456
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
457
+
458
+ if (!$childTypeModel->isVariationProductMatched()) {
459
+ continue;
460
+ }
461
+
462
+ $usedOptions[] = $childTypeModel->getProductOptions();
463
+ }
464
+
465
+ return $usedOptions;
466
+ }
467
+
468
+ // ------------------------------------------
469
+
470
+ public function getUnusedProductVariations()
471
+ {
472
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
473
+ }
474
+
475
+ public function getUnusedChannelVariations()
476
+ {
477
+ return $this->getUnusedVariations($this->getCurrentChannelVariations(), $this->getUsedChannelVariations());
478
+ }
479
+
480
+ private function getUnusedVariations($currentVariations, $usedVariations)
481
+ {
482
+ if (empty($currentVariations)) {
483
+ return array();
484
+ }
485
+
486
+ if (empty($usedVariations)) {
487
+ return $currentVariations;
488
+ }
489
+
490
+ $unusedOptions = array();
491
+
492
+ foreach ($currentVariations as $id => $currentOption) {
493
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
494
+ continue;
495
+ }
496
+
497
+ $unusedOptions[$id] = $currentOption;
498
+ }
499
+
500
+ return $unusedOptions;
501
+ }
502
+
503
+ private function isVariationExistsInArray(array $needle, array $haystack)
504
+ {
505
+ foreach ($haystack as $option) {
506
+ if ($option != $needle) {
507
+ continue;
508
+ }
509
+
510
+ return true;
511
+ }
512
+
513
+ return false;
514
+ }
515
+
516
+ // ------------------------------------------
517
+
518
+ public function hasUnusedProductVariation()
519
+ {
520
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
521
+ }
522
+
523
+ public function hasUnusedChannelVariations()
524
+ {
525
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
526
+ }
527
+
528
+ // ------------------------------------------
529
+
530
+ public function hasChildWithEmptyProductOptions()
531
+ {
532
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
533
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
534
+
535
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
536
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
537
+
538
+ if (!$childTypeModel->isVariationProductMatched()) {
539
+ return true;
540
+ }
541
+ }
542
+
543
+ return false;
544
+ }
545
+
546
+ public function hasChildWithEmptyChannelOptions()
547
+ {
548
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
549
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
550
+
551
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
552
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
553
+
554
+ if (!$childTypeModel->isVariationChannelMatched()) {
555
+ return true;
556
+ }
557
+ }
558
+
559
+ return false;
560
+ }
561
+
562
+ // ###########################################
563
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Ess_M2ePro_Block_Adminhtml_Widget_Container
9
+ {
10
+ protected $listingProductId;
11
+
12
+ // ####################################
13
+
14
+ /**
15
+ * @param mixed $listingProductId
16
+ * @return $this
17
+ */
18
+ public function setListingProductId($listingProductId)
19
+ {
20
+ $this->listingProductId = $listingProductId;
21
+
22
+ return $this;
23
+ }
24
+ /**
25
+ * @return mixed
26
+ */
27
+ public function getListingProductId()
28
+ {
29
+ return $this->listingProductId;
30
+ }
31
+
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+
36
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations.phtml');
37
+
38
+ return $this;
39
+ }
40
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Child/Form.php ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ /**
20
+ * @param mixed $listingProductId
21
+ * @return $this
22
+ */
23
+ public function setListingProductId($listingProductId)
24
+ {
25
+ $this->listingProductId = $listingProductId;
26
+
27
+ return $this;
28
+ }
29
+ /**
30
+ * @return mixed
31
+ */
32
+ public function getListingProductId()
33
+ {
34
+ return $this->listingProductId;
35
+ }
36
+
37
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
38
+ protected $listingProduct;
39
+
40
+ public function __construct()
41
+ {
42
+ parent::__construct();
43
+
44
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations/child/form.phtml');
45
+ }
46
+
47
+ // ----------------------------------------
48
+ /**
49
+ * @return Ess_M2ePro_Model_Listing_Product|null
50
+ */
51
+ public function getListingProduct()
52
+ {
53
+ if(empty($this->listingProduct)) {
54
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
55
+ ->getObject('Listing_Product', $this->getListingProductId());
56
+ }
57
+
58
+ return $this->listingProduct;
59
+ }
60
+
61
+ // ########################################
62
+
63
+ public function isGeneralIdOwner()
64
+ {
65
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
66
+ }
67
+
68
+ // ----------------------------------------
69
+
70
+ public function hasChannelTheme()
71
+ {
72
+ return $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel()->hasChannelTheme();
73
+ }
74
+
75
+ public function hasUnusedChannelVariations()
76
+ {
77
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
78
+ }
79
+
80
+ // ----------------------------------------
81
+
82
+ public function getMatchedAttributes()
83
+ {
84
+ return $this->getListingProduct()->getChildObject()
85
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
86
+ }
87
+
88
+ // ----------------------------------------
89
+
90
+ public function getUnusedProductVariations()
91
+ {
92
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
93
+ }
94
+
95
+ public function getUnusedChannelVariations()
96
+ {
97
+ return $this->getUnusedVariations($this->getCurrentChannelVariations(), $this->getUsedChannelVariations());
98
+ }
99
+
100
+ private function getUnusedVariations($currentVariations, $usedVariations)
101
+ {
102
+ if (empty($currentVariations)) {
103
+ return array();
104
+ }
105
+
106
+ if (empty($usedVariations)) {
107
+ return $currentVariations;
108
+ }
109
+
110
+ $unusedOptions = array();
111
+
112
+ foreach ($currentVariations as $id => $currentOption) {
113
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
114
+ continue;
115
+ }
116
+
117
+ $unusedOptions[$id] = $currentOption;
118
+ }
119
+
120
+ return $unusedOptions;
121
+ }
122
+
123
+ private function isVariationExistsInArray(array $needle, array $haystack)
124
+ {
125
+ foreach ($haystack as $option) {
126
+ if ($option != $needle) {
127
+ continue;
128
+ }
129
+
130
+ return true;
131
+ }
132
+
133
+ return false;
134
+ }
135
+
136
+ // ----------------------------------------
137
+
138
+ public function getChildListingProducts()
139
+ {
140
+ if (!is_null($this->childListingProducts)) {
141
+ return $this->childListingProducts;
142
+ }
143
+
144
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
145
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
146
+ }
147
+
148
+ public function getCurrentProductVariations()
149
+ {
150
+ if (!is_null($this->currentProductVariations)) {
151
+ return $this->currentProductVariations;
152
+ }
153
+
154
+ $magentoProductVariations = $this->getListingProduct()
155
+ ->getMagentoProduct()
156
+ ->getVariationInstance()
157
+ ->getVariationsTypeStandard();
158
+
159
+ $productVariations = array();
160
+
161
+ foreach ($magentoProductVariations['variations'] as $option) {
162
+ $productOption = array();
163
+
164
+ foreach ($option as $attribute) {
165
+ $productOption[$attribute['attribute']] = $attribute['option'];
166
+ }
167
+
168
+ $productVariations[] = $productOption;
169
+ }
170
+
171
+ return $this->currentProductVariations = $productVariations;
172
+ }
173
+
174
+ public function getCurrentChannelVariations()
175
+ {
176
+ return $this->getListingProduct()->getChildObject()
177
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
178
+ }
179
+
180
+ // ----------------------------------------
181
+
182
+ public function getAttributesOptionsFromVariations($variations)
183
+ {
184
+ $attributesOptions = array();
185
+
186
+ foreach ($variations as $variation) {
187
+ foreach ($variation as $attr => $option) {
188
+ if (!isset($attributesOptions[$attr])) {
189
+ $attributesOptions[$attr] = array();
190
+ }
191
+ if (!in_array($option, $attributesOptions[$attr])) {
192
+ $attributesOptions[$attr][] = $option;
193
+ }
194
+ }
195
+ }
196
+
197
+ ksort($attributesOptions);
198
+
199
+ return $attributesOptions;
200
+ }
201
+
202
+ // ----------------------------------------
203
+
204
+ public function getUsedChannelVariations()
205
+ {
206
+ $usedOptions = array();
207
+
208
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
209
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
210
+
211
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
212
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
213
+
214
+ if (!$childTypeModel->isVariationChannelMatched()) {
215
+ continue;
216
+ }
217
+
218
+ $usedOptions[] = $childTypeModel->getChannelOptions();
219
+ }
220
+
221
+ return $usedOptions;
222
+ }
223
+
224
+ public function getUsedProductVariations()
225
+ {
226
+ $usedOptions = array();
227
+
228
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
229
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
230
+
231
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
232
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
233
+
234
+ if (!$childTypeModel->isVariationProductMatched()) {
235
+ continue;
236
+ }
237
+
238
+ $usedOptions[] = $childTypeModel->getProductOptions();
239
+ }
240
+
241
+ return $usedOptions;
242
+ }
243
+
244
+ // ----------------------------------------
245
+
246
+ public function getProductVariationsTree()
247
+ {
248
+ if (empty($this->productVariationsTree)) {
249
+
250
+ $matchedAttributes = $this->getMatchedAttributes();
251
+ $unusedVariations = $this->sortVariationsAttributes(
252
+ $this->getUnusedProductVariations(),
253
+ array_keys($matchedAttributes)
254
+ );
255
+ $variationsSets = $this->sortVariationAttributes(
256
+ $this->getAttributesOptionsFromVariations($unusedVariations),
257
+ array_keys($matchedAttributes)
258
+ );
259
+
260
+ $firstAttribute = key($matchedAttributes);
261
+
262
+ $this->productVariationsTree = $this->prepareVariations(
263
+ $firstAttribute,$unusedVariations,$variationsSets
264
+ );
265
+ }
266
+
267
+ return $this->productVariationsTree;
268
+ }
269
+
270
+ public function getChannelVariationsTree()
271
+ {
272
+ if (empty($this->channelVariationsTree)) {
273
+
274
+ $matchedAttributes = $this->getMatchedAttributes();
275
+ $unusedVariations = $this->sortVariationsAttributes(
276
+ $this->getUnusedChannelVariations(),
277
+ array_values($matchedAttributes)
278
+ );
279
+
280
+ if (empty($unusedVariations)) {
281
+ $this->channelVariationsTree = new stdClass();
282
+
283
+ return $this->channelVariationsTree;
284
+ }
285
+
286
+ $variationsSets = $this->sortVariationAttributes(
287
+ $this->getAttributesOptionsFromVariations($unusedVariations),
288
+ array_values($matchedAttributes)
289
+ );
290
+
291
+ $firstAttribute = $matchedAttributes[key($matchedAttributes)];
292
+
293
+ $this->channelVariationsTree = $this->prepareVariations(
294
+ $firstAttribute,$unusedVariations,$variationsSets
295
+ );
296
+ }
297
+
298
+ return $this->channelVariationsTree;
299
+ }
300
+
301
+ private function sortVariationsAttributes($variations, $sortTemplate)
302
+ {
303
+ foreach ($variations as $key => $variation) {
304
+ $variations[$key] = $this->sortVariationAttributes($variation, $sortTemplate);
305
+ }
306
+
307
+ return $variations;
308
+ }
309
+
310
+ private function sortVariationAttributes($variation, $sortTemplate)
311
+ {
312
+ $sortedData = array();
313
+
314
+ foreach ($sortTemplate as $attr) {
315
+ $sortedData[$attr] = $variation[$attr];
316
+ }
317
+
318
+ return $sortedData;
319
+ }
320
+
321
+ private function prepareVariations($currentAttribute,$magentoVariations,$variationsSets,$filters = array())
322
+ {
323
+ $return = false;
324
+
325
+ $temp = array_flip(array_keys($variationsSets));
326
+
327
+ $lastAttributePosition = count($variationsSets) - 1;
328
+ $currentAttributePosition = $temp[$currentAttribute];
329
+
330
+ if ($currentAttributePosition != $lastAttributePosition) {
331
+
332
+ $temp = array_keys($variationsSets);
333
+ $nextAttribute = $temp[$currentAttributePosition + 1];
334
+
335
+ foreach ($variationsSets[$currentAttribute] as $option) {
336
+
337
+ $filters[$currentAttribute] = $option;
338
+
339
+ $result = $this->prepareVariations(
340
+ $nextAttribute,$magentoVariations,$variationsSets,$filters
341
+ );
342
+
343
+ if (!$result) {
344
+ continue;
345
+ }
346
+
347
+ $return[$currentAttribute][$option] = $result;
348
+ }
349
+
350
+ ksort($return[$currentAttribute]);
351
+
352
+ return $return;
353
+ }
354
+
355
+ $return = false;
356
+ foreach ($magentoVariations as $key => $magentoVariation) {
357
+ foreach ($magentoVariation as $attribute => $option) {
358
+
359
+ if ($attribute == $currentAttribute) {
360
+
361
+ if (count($variationsSets) != 1) {
362
+ continue;
363
+ }
364
+
365
+ $values = array_flip($variationsSets[$currentAttribute]);
366
+ $return = array($currentAttribute => $values);
367
+
368
+ foreach ($return[$currentAttribute] as &$option) {
369
+ $option = true;
370
+ }
371
+
372
+ return $return;
373
+ }
374
+
375
+ if ($option != $filters[$attribute]) {
376
+ unset($magentoVariations[$key]);
377
+ continue;
378
+ }
379
+
380
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
381
+ if ($tempAttribute == $currentAttribute) {
382
+ $option = $tempOption;
383
+ $return[$currentAttribute][$option] = true;
384
+ }
385
+ }
386
+ }
387
+ }
388
+
389
+ if (count($magentoVariations) < 1) {
390
+ return false;
391
+ }
392
+
393
+ ksort($return[$currentAttribute]);
394
+
395
+ return $return;
396
+ }
397
+
398
+ // ####################################
399
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Grid.php ADDED
@@ -0,0 +1,1592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ protected $childListingProducts = null;
11
+ protected $currentProductVariations = null;
12
+ protected $usedProductVariations = null;
13
+
14
+ protected $listingProductId;
15
+
16
+ // ####################################
17
+
18
+ /**
19
+ * @param mixed $listingProductId
20
+ */
21
+ public function setListingProductId($listingProductId)
22
+ {
23
+ $this->listingProductId = $listingProductId;
24
+ }
25
+ /**
26
+ * @return mixed
27
+ */
28
+ public function getListingProductId()
29
+ {
30
+ return $this->listingProductId;
31
+ }
32
+
33
+ //------------------------------
34
+
35
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
36
+ protected $listingProduct;
37
+
38
+ protected function getListingProduct()
39
+ {
40
+ if(empty($this->listingProduct)) {
41
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
42
+ ->getObject('Listing_Product', $this->getListingProductId());
43
+ }
44
+
45
+ return $this->listingProduct;
46
+ }
47
+
48
+ //------------------------------
49
+
50
+ private $lockedDataCache = array();
51
+
52
+ // ####################################
53
+
54
+ public function __construct()
55
+ {
56
+ parent::__construct();
57
+
58
+ // Initialization block
59
+ //------------------------------
60
+ $this->setId('amazonVariationProductManageGrid');
61
+ $this->setDefaultSort('id');
62
+ $this->setDefaultDir('ASC');
63
+ $this->setUseAjax(true);
64
+ //------------------------------
65
+ }
66
+
67
+ // ####################################
68
+
69
+ protected function _prepareCollection()
70
+ {
71
+ // Get collection
72
+ //----------------------------
73
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Listing_Product_Collection $collection */
74
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
75
+ $collection->getSelect()->distinct();
76
+ $collection->getSelect()->where("`second_table`.`variation_parent_id` = ?",(int)$this->getListingProductId());
77
+ //----------------------------
78
+
79
+ // Set collection to grid
80
+ $this->setCollection($collection);
81
+
82
+ return parent::_prepareCollection();
83
+ }
84
+
85
+ protected function _prepareColumns()
86
+ {
87
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
88
+ $parentType = $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel();
89
+
90
+ $channelAttributesSets = $parentType->getChannelAttributesSets();
91
+
92
+ if ($parentType->hasMatchedAttributes()) {
93
+ $channelAttributes = array_values($parentType->getMatchedAttributes());
94
+ } else if (!empty($channelAttributesSets)) {
95
+ $channelAttributes = array_keys($channelAttributesSets);
96
+ } else {
97
+ $channelAttributes = array();
98
+ }
99
+
100
+ $this->addColumn('product_options', array(
101
+ 'header' => Mage::helper('M2ePro')->__('Magento Variation'),
102
+ 'align' => 'left',
103
+ 'width' => '210px',
104
+ 'sortable' => false,
105
+ 'index' => 'additional_data',
106
+ 'filter_index' => 'additional_data',
107
+ 'frame_callback' => array($this, 'callbackColumnProductOptions'),
108
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
109
+ 'options' => $parentType->getProductAttributes(),
110
+ 'filter_condition_callback' => array($this, 'callbackProductOptions')
111
+ ));
112
+
113
+ $this->addColumn('channel_options', array(
114
+ 'header' => Mage::helper('M2ePro')->__('Amazon Variation'),
115
+ 'align' => 'left',
116
+ 'width' => '210px',
117
+ 'sortable' => false,
118
+ 'index' => 'additional_data',
119
+ 'filter_index' => 'additional_data',
120
+ 'frame_callback' => array($this, 'callbackColumnChannelOptions'),
121
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
122
+ 'options' => $channelAttributes,
123
+ 'filter_condition_callback' => array($this, 'callbackChannelOptions')
124
+ ));
125
+
126
+ $this->addColumn('sku', array(
127
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
128
+ 'align' => 'left',
129
+ 'type' => 'text',
130
+ 'index' => 'sku',
131
+ 'filter_index' => 'sku',
132
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
133
+ ));
134
+
135
+ $this->addColumn('general_id', array(
136
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
137
+ 'align' => 'left',
138
+ 'width' => '100px',
139
+ 'type' => 'text',
140
+ 'index' => 'general_id',
141
+ 'filter_index' => 'general_id',
142
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
143
+ ));
144
+
145
+ $this->addColumn('online_qty', array(
146
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
147
+ 'align' => 'right',
148
+ 'width' => '70px',
149
+ 'type' => 'number',
150
+ 'index' => 'online_qty',
151
+ 'filter_index' => 'online_qty',
152
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
153
+ ));
154
+
155
+ $this->addColumn('online_price', array(
156
+ 'header' => Mage::helper('M2ePro')->__('Price'),
157
+ 'align' => 'right',
158
+ 'width' => '70px',
159
+ 'type' => 'number',
160
+ 'index' => 'online_price',
161
+ 'filter_index' => 'online_price',
162
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
163
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
164
+ ));
165
+
166
+ $this->addColumn('status', array(
167
+ 'header' => Mage::helper('M2ePro')->__('Status'),
168
+ 'width' => '100px',
169
+ 'index' => 'status',
170
+ 'filter_index' => 'status',
171
+ 'type' => 'options',
172
+ 'sortable' => false,
173
+ 'options' => array(
174
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
175
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
176
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
177
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
178
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
179
+ ),
180
+ 'frame_callback' => array($this, 'callbackColumnStatus')
181
+ ));
182
+
183
+ return parent::_prepareColumns();
184
+ }
185
+
186
+ protected function _prepareMassaction()
187
+ {
188
+ // Set massaction identifiers
189
+ //--------------------------------
190
+ $this->setMassactionIdField('id');
191
+ $this->setMassactionIdFieldOnlyIndexValue(true);
192
+ //--------------------------------
193
+
194
+ // Set mass-action
195
+ //--------------------------------
196
+ $this->getMassactionBlock()->addItem('list', array(
197
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
198
+ 'url' => '',
199
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
200
+ ));
201
+
202
+ $this->getMassactionBlock()->addItem('revise', array(
203
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
204
+ 'url' => '',
205
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
206
+ ));
207
+
208
+ $this->getMassactionBlock()->addItem('relist', array(
209
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
210
+ 'url' => '',
211
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
212
+ ));
213
+
214
+ $this->getMassactionBlock()->addItem('stop', array(
215
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
216
+ 'url' => '',
217
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
218
+ ));
219
+
220
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
221
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
222
+ 'url' => '',
223
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
224
+ ));
225
+
226
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
227
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
228
+ 'url' => '',
229
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
230
+ ));
231
+
232
+ //--------------------------------
233
+
234
+ return parent::_prepareMassaction();
235
+ }
236
+
237
+ // ####################################
238
+
239
+ public function callbackColumnProductOptions($additionalData, $row, $column, $isExport)
240
+ {
241
+ $html = '';
242
+
243
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $typeModel */
244
+ $typeModel = $row->getChildObject()->getVariationManager()->getTypeModel();
245
+
246
+ $html .= '<div class="product-options-main" style="font-size: 11px; color: grey; margin-left: 7px">';
247
+ $productOptions = $typeModel->getProductOptions();
248
+ if (!empty($productOptions)) {
249
+ $html .= '<div class="product-options-list">';
250
+ foreach ($productOptions as $attribute => $option) {
251
+ !$option && $option = '--';
252
+ $html .= '<span class="attribute-row"><span class="attribute"><strong>' .
253
+ Mage::helper('M2ePro')->escapeHtml($attribute) .
254
+ '</strong></span>:&nbsp;<span class="value">' . Mage::helper('M2ePro')->escapeHtml($option) .
255
+ '</span></span><br/>';
256
+ }
257
+ $html .= '</div>';
258
+ }
259
+
260
+ if ($this->canChangeProductVariation($row)) {
261
+
262
+ $listingProductId = $row->getId();
263
+ $attributes = $this->getListingProduct()->getChildObject()
264
+ ->getVariationManager()->getTypeModel()->getProductAttributes();
265
+ $variationsTree = $this->getProductVariationsTree($row);
266
+
267
+ sort($attributes);
268
+
269
+ $linkTitle = Mage::helper('M2ePro')->__('Change Variation');
270
+ $linkContent = Mage::helper('M2ePro')->__('Change Variation');
271
+
272
+ $attributes = Mage::helper('M2ePro')->escapeHtml(json_encode($attributes));
273
+ $variationsTree = Mage::helper('M2ePro')->escapeHtml(json_encode($variationsTree));
274
+
275
+ $html .= <<<HTML
276
+ <form action="javascript:void(0);" class="product-options-edit"></form>
277
+ <a href="javascript:"
278
+ onclick="ListingGridHandlerObj.editProductOptions(this, {$attributes}, {$variationsTree}, {$listingProductId})"
279
+ title="{$linkTitle}">{$linkContent}</a>
280
+ HTML;
281
+ }
282
+
283
+ $html .= '</div>';
284
+
285
+ return $html;
286
+ }
287
+
288
+ public function callbackColumnChannelOptions($additionalData, $row, $column, $isExport)
289
+ {
290
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
291
+ $amazonListingProduct = $row->getChildObject();
292
+
293
+ $typeModel = $amazonListingProduct->getVariationManager()->getTypeModel();
294
+
295
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $parentAmazonListingProduct */
296
+ $parentAmazonListingProduct = $typeModel->getParentListingProduct()->getChildObject();
297
+
298
+ $matchedAttributes = $parentAmazonListingProduct->getVariationManager()
299
+ ->getTypeModel()
300
+ ->getMatchedAttributes();
301
+
302
+ if (!$typeModel->isVariationChannelMatched()) {
303
+ if (!$typeModel->isVariationProductMatched() || !$amazonListingProduct->isGeneralIdOwner()) {
304
+ return '';
305
+ }
306
+
307
+ if (empty($matchedAttributes)) {
308
+ return '';
309
+ }
310
+
311
+ $options = array();
312
+
313
+ foreach ($typeModel->getProductOptions() as $attribute => $value) {
314
+ $options[$matchedAttributes[$attribute]] = $value;
315
+ }
316
+ } else {
317
+ $options = $typeModel->getChannelOptions();
318
+
319
+ if (!empty($matchedAttributes)) {
320
+
321
+ $sortedOptions = array();
322
+
323
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
324
+ $sortedOptions[$amazonAttr] = $options[$amazonAttr];
325
+ }
326
+
327
+ $options = $sortedOptions;
328
+ }
329
+ }
330
+
331
+ if (empty($options)) {
332
+ return '';
333
+ }
334
+
335
+ $generalId = $amazonListingProduct->getGeneralId();
336
+
337
+ $html = '<div style="font-size: 11px; color: grey; margin-left: 7px">';
338
+
339
+ foreach ($options as $attribute => $option) {
340
+ !$option && $option = '--';
341
+
342
+ $attrName = Mage::helper('M2ePro')->escapeHtml($attribute);
343
+ $optionName = Mage::helper('M2ePro')->escapeHtml($option);
344
+
345
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
346
+ $html .= <<<HTML
347
+ {$attrName}:&nbsp;{$optionName}<br/>
348
+ HTML;
349
+ } else {
350
+ $html .= <<<HTML
351
+ <b>{$attrName}</b>:&nbsp;{$optionName}<br/>
352
+ HTML;
353
+ }
354
+
355
+ }
356
+
357
+ $html .= '</div>';
358
+
359
+ return $html;
360
+ }
361
+
362
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
363
+ {
364
+ if (is_null($value) || $value === '') {
365
+ $value = Mage::helper('M2ePro')->__('N/A');
366
+ }
367
+
368
+ if ($row->getData('defected_messages')) {
369
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
370
+
371
+ $msg = '';
372
+ foreach ($defectedMessages as $message) {
373
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
374
+ if (!empty($message['value'])) {
375
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
376
+ }
377
+ $msg .= '</p>';
378
+ }
379
+
380
+ $value .= <<<HTML
381
+ <span style="float:right;">
382
+ <img id="map_link_defected_message_icon_{$row->getId()}"
383
+ class="tool-tip-image"
384
+ style="vertical-align: middle;"
385
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
386
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
387
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
388
+ <span>{$msg}</span>
389
+ </span>
390
+ </span>
391
+ HTML;
392
+ }
393
+
394
+ return $value;
395
+ }
396
+
397
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
398
+ {
399
+ if (is_null($generalId) || $generalId === '') {
400
+
401
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
402
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
403
+ if ($amazonListingProduct->isGeneralIdOwner()) {
404
+ return Mage::helper('M2ePro')->__('New ASIN/ISBN');
405
+ }
406
+
407
+ return Mage::helper('M2ePro')->__('N/A');
408
+ }
409
+ return $this->getGeneralIdLink($generalId);
410
+ }
411
+
412
+ public function callbackColumnAvailableQty($qty, $row, $column, $isExport)
413
+ {
414
+ if (is_null($qty) || $qty === '') {
415
+ return Mage::helper('M2ePro')->__('N/A');
416
+ }
417
+ return $qty;
418
+ }
419
+
420
+ public function callbackColumnPrice($value, $row, $column, $isExport)
421
+ {
422
+ if (is_null($value) || $value === '') {
423
+ return Mage::helper('M2ePro')->__('N/A');
424
+ }
425
+
426
+ $marketplaceId = $this->getListingProduct()->getListing()->getMarketplaceId();
427
+ $currency = Mage::helper('M2ePro/Component_Amazon')
428
+ ->getCachedObject('Marketplace',$marketplaceId)
429
+ ->getChildObject()
430
+ ->getDefaultCurrency();
431
+
432
+ if ((float)$value <= 0) {
433
+ $priceValue = '<span style="color: #f00;">0</span>';
434
+ } else {
435
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($value);
436
+ }
437
+
438
+ $resultHtml = '';
439
+
440
+ $salePrice = $row->getData('online_sale_price');
441
+ if ((float)$salePrice > 0) {
442
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
443
+
444
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
445
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
446
+
447
+ if ($currentTimestamp <= $endDateTimestamp) {
448
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
449
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
450
+
451
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
452
+
453
+ $fromDate = Mage::app()->getLocale()->date(
454
+ $row->getData('online_sale_price_start_date'), $dateFormat
455
+ )->toString($dateFormat);
456
+ $toDate = Mage::app()->getLocale()->date(
457
+ $row->getData('online_sale_price_end_date'), $dateFormat
458
+ )->toString($dateFormat);
459
+
460
+ $intervalHtml = '<img class="tool-tip-image"
461
+ style="vertical-align: middle;"
462
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
463
+ text-align: left;
464
+ width: 120px;
465
+ background: #E3E3E3;">
466
+ <img src="'.$iconHelpPath.'">
467
+ <span style="color:gray;">
468
+ <strong>From:</strong> '.$fromDate.'<br/>
469
+ <strong>To:</strong> '.$toDate.'
470
+ </span>
471
+ </span>';
472
+
473
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
474
+
475
+ if ($currentTimestamp >= $startDateTimestamp &&
476
+ $currentTimestamp <= $endDateTimestamp &&
477
+ $salePrice < (float)$value
478
+ ) {
479
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
480
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
481
+ } else {
482
+ $resultHtml .= $priceValue;
483
+ $resultHtml .= '<br/>'.$intervalHtml.
484
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
485
+ }
486
+ }
487
+ }
488
+
489
+ if (empty($resultHtml)) {
490
+ $resultHtml = $priceValue;
491
+ }
492
+
493
+ return $resultHtml;
494
+ }
495
+
496
+ public function callbackColumnStatus($value, $row, $column, $isExport)
497
+ {
498
+ $listingProductId = (int)$row->getData('id');
499
+
500
+ $html = $this->getViewLogIconHtml($row);
501
+
502
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
503
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
504
+
505
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
506
+ if (!empty($synchNote)) {
507
+
508
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
509
+
510
+ if (empty($html)) {
511
+ $html = <<<HTML
512
+ <span style="float:right;">
513
+ <img id="map_link_error_icon_{$row->getId()}"
514
+ class="tool-tip-image"
515
+ style="vertical-align: middle;"
516
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
517
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
518
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
519
+ <span>{$synchNote}</span>
520
+ </span>
521
+ </span>
522
+ HTML;
523
+ } else {
524
+ $html .= <<<HTML
525
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
526
+ HTML;
527
+ }
528
+ }
529
+
530
+ switch ($row->getData('status')) {
531
+
532
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
533
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
534
+ $html .= '<span style="color: gray;">' . $value . '</span>';
535
+ break;
536
+
537
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
538
+ $html .= '<span style="color: green;">' . $value . '</span>';
539
+ break;
540
+
541
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
542
+ $html .= '<span style="color: red;">'.$value.'</span>';
543
+ break;
544
+
545
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
546
+ $html .= '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
547
+ break;
548
+
549
+ default:
550
+ break;
551
+ }
552
+
553
+ $tempLocks = $this->getLockedData($row);
554
+ $tempLocks = $tempLocks['object_locks'];
555
+
556
+ foreach ($tempLocks as $lock) {
557
+
558
+ switch ($lock->getTag()) {
559
+
560
+ case 'list_action':
561
+ $html .= '<br/><span style="color: #605fff">[Listing...]</span>';
562
+ break;
563
+
564
+ case 'relist_action':
565
+ $html .= '<br/><span style="color: #605fff">[Relisting...]</span>';
566
+ break;
567
+
568
+ case 'revise_action':
569
+ $html .= '<br/><span style="color: #605fff">[Revising...]</span>';
570
+ break;
571
+
572
+ case 'stop_action':
573
+ $html .= '<br/><span style="color: #605fff">[Stopping...]</span>';
574
+ break;
575
+
576
+ case 'stop_and_remove_action':
577
+ $html .= '<br/><span style="color: #605fff">[Stopping...]</span>';
578
+ break;
579
+
580
+ case 'delete_and_remove_action':
581
+ $html .= '<br/><span style="color: #605fff">[Removing...]</span>';
582
+ break;
583
+
584
+ default:
585
+ break;
586
+
587
+ }
588
+ }
589
+
590
+ return $html;
591
+ }
592
+
593
+ public function callbackProductOptions($collection, $column)
594
+ {
595
+ $values = $column->getFilter()->getValue();
596
+
597
+ if ($values == null && !is_array($values)) {
598
+ return;
599
+ }
600
+
601
+ foreach ($values as $value) {
602
+ if(is_array($value) && isset($value['value'])) {
603
+ $collection->addFieldToFilter(
604
+ 'additional_data',
605
+ array('regexp'=> '"variation_product_options":[^}]*'.$value['attr'].'":"' .
606
+ // trying to screen slashes that in json
607
+ addslashes(addslashes($value['value'])))
608
+ );
609
+ }
610
+ }
611
+ }
612
+
613
+ public function callbackChannelOptions($collection, $column)
614
+ {
615
+ $values = $column->getFilter()->getValue();
616
+
617
+ if ($values == null && !is_array($values)) {
618
+ return;
619
+ }
620
+
621
+ foreach ($values as $value) {
622
+ if(is_array($value) && isset($value['value'])) {
623
+ $collection->addFieldToFilter(
624
+ 'additional_data',
625
+ array('regexp'=> '"variation_channel_options":[^}]*'.$value['attr'].'":"' .
626
+ // trying to screen slashes that in json
627
+ addslashes(addslashes($value['value'])))
628
+ );
629
+ }
630
+ }
631
+ }
632
+
633
+ protected function callbackFilterPrice($collection, $column)
634
+ {
635
+ $value = $column->getFilter()->getValue();
636
+
637
+ if (empty($value)) {
638
+ return;
639
+ }
640
+
641
+ $from = $value['from'];
642
+ $to = $value['to'];
643
+
644
+ $collection->getSelect()->where(
645
+ '(online_price >= \''.$from.'\' AND online_price <= \''.$to.'\' AND
646
+ (
647
+ online_sale_price IS NULL OR
648
+ online_sale_price_start_date > NOW() OR
649
+ online_sale_price_end_date < NOW()
650
+ )) OR (online_sale_price >= \''.$from.'\' AND online_sale_price <= \''.$to.'\' AND
651
+ (
652
+ online_sale_price IS NOT NULL AND
653
+ online_sale_price_start_date < NOW() AND
654
+ online_sale_price_end_date > NOW()
655
+ ))'
656
+ );
657
+ }
658
+
659
+ // ####################################
660
+
661
+ /**
662
+ * @param Ess_M2ePro_Model_Listing_Product $listingProduct
663
+ * @return string
664
+ */
665
+ public function getViewLogIconHtml($listingProduct)
666
+ {
667
+ $listingProductId = (int)$listingProduct->getId();
668
+
669
+ // Get last messages
670
+ //--------------------------
671
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
672
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
673
+
674
+ $dbSelect = $connRead->select()
675
+ ->from(
676
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
677
+ array('action_id','action','type','description','create_date','initiator')
678
+ )
679
+ ->where('`listing_product_id` = ?', $listingProductId)
680
+ ->where('`action_id` IS NOT NULL')
681
+ ->order(array('id DESC'))
682
+ ->limit(30);
683
+
684
+ $logRows = $connRead->fetchAll($dbSelect);
685
+ //--------------------------
686
+
687
+ // Get grouped messages by action_id
688
+ //--------------------------
689
+ $actionsRows = array();
690
+ $tempActionRows = array();
691
+ $lastActionId = false;
692
+
693
+ foreach ($logRows as $row) {
694
+
695
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
696
+
697
+ if ($row['action_id'] !== $lastActionId) {
698
+ if (count($tempActionRows) > 0) {
699
+ $actionsRows[] = array(
700
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
701
+ 'date' => $this->getMainDateForActionId($tempActionRows),
702
+ 'action' => $this->getActionForAction($tempActionRows[0]),
703
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
704
+ 'items' => $tempActionRows
705
+ );
706
+ $tempActionRows = array();
707
+ }
708
+ $lastActionId = $row['action_id'];
709
+ }
710
+ $tempActionRows[] = $row;
711
+ }
712
+
713
+ if (count($tempActionRows) > 0) {
714
+ $actionsRows[] = array(
715
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
716
+ 'date' => $this->getMainDateForActionId($tempActionRows),
717
+ 'action' => $this->getActionForAction($tempActionRows[0]),
718
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
719
+ 'items' => $tempActionRows
720
+ );
721
+ }
722
+
723
+ if (count($actionsRows) <= 0) {
724
+ return '';
725
+ }
726
+
727
+ foreach ($actionsRows as &$actionsRow) {
728
+ usort($actionsRow['items'], function($a, $b)
729
+ {
730
+ $sortOrder = array(
731
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
732
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
733
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
734
+ );
735
+
736
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
737
+ });
738
+ }
739
+
740
+ $tips = array(
741
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
742
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
743
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
744
+ );
745
+
746
+ $icons = array(
747
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
748
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
749
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
750
+ );
751
+
752
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
753
+ 'entity_id' => (int)$listingProduct->getId(),
754
+ 'rows' => $actionsRows,
755
+ 'tips' => $tips,
756
+ 'icons' => $icons,
757
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
758
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
759
+ ));
760
+
761
+ return $summary->toHtml();
762
+ }
763
+
764
+ public function getActionForAction($actionRows)
765
+ {
766
+ $string = '';
767
+
768
+ switch ($actionRows['action']) {
769
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
770
+ $string = Mage::helper('M2ePro')->__('List');
771
+ break;
772
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
773
+ $string = Mage::helper('M2ePro')->__('Relist');
774
+ break;
775
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
776
+ $string = Mage::helper('M2ePro')->__('Revise');
777
+ break;
778
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
779
+ $string = Mage::helper('M2ePro')->__('Stop');
780
+ break;
781
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
782
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
783
+ break;
784
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
785
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
786
+ break;
787
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
788
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
789
+ break;
790
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
791
+ $string = Mage::helper('M2ePro')->__('Channel Change');
792
+ break;
793
+ }
794
+
795
+ return $string;
796
+ }
797
+
798
+ public function getInitiatorForAction($actionRows)
799
+ {
800
+ $string = '';
801
+
802
+ switch ((int)$actionRows['initiator']) {
803
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
804
+ $string = '';
805
+ break;
806
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
807
+ $string = Mage::helper('M2ePro')->__('Manual');
808
+ break;
809
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
810
+ $string = Mage::helper('M2ePro')->__('Automatic');
811
+ break;
812
+ }
813
+
814
+ return $string;
815
+ }
816
+
817
+ public function getMainTypeForActionId($actionRows)
818
+ {
819
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
820
+
821
+ foreach ($actionRows as $row) {
822
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
823
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
824
+ break;
825
+ }
826
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
827
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
828
+ }
829
+ }
830
+
831
+ return $type;
832
+ }
833
+
834
+ public function getMainDateForActionId($actionRows)
835
+ {
836
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
837
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
838
+ }
839
+
840
+ // ####################################
841
+
842
+ public function getMainButtonsHtml()
843
+ {
844
+ $html = '';
845
+ if($this->getFilterVisibility()){
846
+ $html.= $this->getAddNewChildButtonsHtml();
847
+ $html.= $this->getResetFilterButtonHtml();
848
+ $html.= $this->getSearchButtonHtml();
849
+ }
850
+ return $html;
851
+ }
852
+
853
+ public function getMassactionBlockHtml()
854
+ {
855
+ if ($this->isNewChildAllowed()) {
856
+ $blockName = 'adminhtml_common_amazon_listing_variation_product_manage_tabs_variations_child_form';
857
+ $form = $this->getLayout()->createBlock('M2ePro/'.$blockName);
858
+ $form->setListingProductId($this->getListingProductId());
859
+
860
+ return $form->toHtml() . parent::getMassactionBlockHtml();
861
+ }
862
+
863
+ return parent::getMassactionBlockHtml();
864
+ }
865
+
866
+ private function getAddNewChildButtonsHtml()
867
+ {
868
+ if ($this->isNewChildAllowed()) {
869
+
870
+ //------------------------------
871
+ $data = array(
872
+ 'label' => Mage::helper('adminhtml')->__('Add New Child Product'),
873
+ 'onclick' => 'ListingGridHandlerObj.showNewChildForm('. !$this->hasUnusedChannelVariations() .')',
874
+ 'class' => 'task',
875
+ 'id' => 'add_new_child_button'
876
+ );
877
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
878
+ $this->setChild('add_new_child_button', $buttonBlock);
879
+ //------------------------------
880
+
881
+ }
882
+
883
+ return $this->getChildHtml('add_new_child_button');
884
+ }
885
+
886
+ protected function isNewChildAllowed()
887
+ {
888
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
889
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
890
+
891
+ if (!$amazonListingProduct->getGeneralId()) {
892
+ return false;
893
+ }
894
+
895
+ if (!$amazonListingProduct->getVariationManager()->getTypeModel()->hasMatchedAttributes()) {
896
+ return false;
897
+ }
898
+
899
+ if (!$this->hasUnusedProductVariation()) {
900
+ return false;
901
+ }
902
+
903
+ if ($this->hasChildWithEmptyProductOptions()) {
904
+ return false;
905
+ }
906
+
907
+ if (!$this->isGeneralIdOwner() && !$this->hasUnusedChannelVariations()) {
908
+ return false;
909
+ }
910
+
911
+ if (!$this->isGeneralIdOwner() && $this->hasChildWithEmptyChannelOptions()) {
912
+ return false;
913
+ }
914
+
915
+ return true;
916
+ }
917
+
918
+ public function isGeneralIdOwner()
919
+ {
920
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
921
+ }
922
+
923
+ public function getCurrentChannelVariations()
924
+ {
925
+ return $this->getListingProduct()->getChildObject()
926
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
927
+ }
928
+
929
+ public function hasUnusedProductVariation()
930
+ {
931
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
932
+ }
933
+
934
+ public function hasUnusedChannelVariations()
935
+ {
936
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
937
+ }
938
+
939
+ public function hasChildWithEmptyProductOptions()
940
+ {
941
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
942
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
943
+
944
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
945
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
946
+
947
+ if (!$childTypeModel->isVariationProductMatched()) {
948
+ return true;
949
+ }
950
+ }
951
+
952
+ return false;
953
+ }
954
+
955
+ public function hasChildWithEmptyChannelOptions()
956
+ {
957
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
958
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
959
+
960
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
961
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
962
+
963
+ if (!$childTypeModel->isVariationChannelMatched()) {
964
+ return true;
965
+ }
966
+ }
967
+
968
+ return false;
969
+ }
970
+
971
+ public function getUsedChannelVariations()
972
+ {
973
+ $usedOptions = array();
974
+
975
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
976
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
977
+
978
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
979
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
980
+
981
+ if (!$childTypeModel->isVariationChannelMatched()) {
982
+ continue;
983
+ }
984
+
985
+ $usedOptions[] = $childTypeModel->getChannelOptions();
986
+ }
987
+
988
+ return $usedOptions;
989
+ }
990
+
991
+ // ------------------------------------
992
+
993
+ public function getGridUrl()
994
+ {
995
+ return $this->getUrl('*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsGridAjax', array(
996
+ '_current' => true
997
+ ));
998
+ }
999
+
1000
+ public function getRowUrl($row)
1001
+ {
1002
+ return false;
1003
+ }
1004
+
1005
+ // ####################################
1006
+
1007
+ protected function _toHtml()
1008
+ {
1009
+ $listingId = $this->getListingProduct()->getListingId();
1010
+
1011
+ /** @var $helper Ess_M2ePro_Helper_Data */
1012
+ $helper = Mage::helper('M2ePro');
1013
+
1014
+ //------------------------------
1015
+ $urls = array();
1016
+
1017
+ $path = 'adminhtml_common_log/listingProduct';
1018
+ $urls[$path] = $this->getUrl('*/' . $path, array(
1019
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
1020
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array('id' => $listingId))
1021
+ ));
1022
+
1023
+ $urls['adminhtml_common_amazon_listing_variation_product_manage/createNewChild'] = $this->getUrl(
1024
+ '*/adminhtml_common_amazon_listing_variation_product_manage/createNewChild');
1025
+
1026
+ $urls = json_encode($urls);
1027
+ //------------------------------
1028
+
1029
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
1030
+
1031
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing', array(
1032
+ 'id' =>$listingId,
1033
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON,
1034
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array('id' => $listingId))
1035
+ ));
1036
+
1037
+ $checkLockListing = $this->getUrl('*/adminhtml_listing/checkLockListing', array('component' => $component));
1038
+ $lockListingNow = $this->getUrl('*/adminhtml_listing/lockListingNow', array('component' => $component));
1039
+ $unlockListingNow = $this->getUrl('*/adminhtml_listing/unlockListingNow', array('component' => $component));
1040
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
1041
+
1042
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
1043
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
1044
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
1045
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
1046
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopAndRemoveProducts');
1047
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
1048
+
1049
+ $setChildListingProductOptions = $this->getUrl(
1050
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setChildListingProductOptions');
1051
+
1052
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
1053
+ $taskCompletedSuccessMessage = $helper->escapeJs(
1054
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
1055
+ );
1056
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
1057
+ '"%task_title%" Task has completed with warnings.
1058
+ <a target="_blank" href="%url%">View Log</a> for details.'
1059
+ ));
1060
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
1061
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
1062
+ ));
1063
+
1064
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
1065
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
1066
+ 'Sending %product_title% Product(s) data on Amazon.'
1067
+ ));
1068
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
1069
+
1070
+ $listingLockedMessage = $helper->escapeJs(
1071
+ $helper->__('The Listing was locked by another process. Please try again later.')
1072
+ );
1073
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
1074
+
1075
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1076
+ ->__('Listing All Items On Amazon'));
1077
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1078
+ ->__('Listing Selected Items On Amazon'));
1079
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1080
+ ->__('Revising Selected Items On Amazon'));
1081
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1082
+ ->__('Relisting Selected Items On Amazon'));
1083
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1084
+ ->__('Stopping Selected Items On Amazon'));
1085
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
1086
+ ->escapeJs(Mage::helper('M2ePro')
1087
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
1088
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
1089
+ ->escapeJs(Mage::helper('M2ePro')
1090
+ ->__('Removing From Amazon And Listing Selected Items'));
1091
+
1092
+ $selectItemsMessage = $helper->escapeJs($helper->__('Please select Items.'));
1093
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
1094
+
1095
+ $errorChangingProductOptions = $helper->escapeJs($helper->__('Please Select Product Options.'));
1096
+
1097
+ $successWord = $helper->escapeJs($helper->__('Success'));
1098
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
1099
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
1100
+ $errorWord = $helper->escapeJs($helper->__('Error'));
1101
+ $closeWord = $helper->escapeJs($helper->__('Close'));
1102
+ $confirmWord = $helper->escapeJs($helper->__('Confirm'));
1103
+ $cancelWord = $helper->escapeJs($helper->__('Cancel'));
1104
+
1105
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
1106
+
1107
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
1108
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
1109
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
1110
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
1111
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
1112
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy for Products'));
1113
+
1114
+ $generalId = $this->getListingProduct()->getGeneralId();
1115
+ $hideMassAction = empty($generalId) ?
1116
+ '$(\'amazonVariationProductManageGrid_massaction-form\').hide();' : '';
1117
+
1118
+ $javascriptMain = <<<JAVASCRIPT
1119
+ <script type="text/javascript">
1120
+
1121
+ if (typeof M2ePro == 'undefined') {
1122
+ M2ePro = {};
1123
+ M2ePro.url = {};
1124
+ M2ePro.formData = {};
1125
+ M2ePro.customData = {};
1126
+ M2ePro.text = {};
1127
+ }
1128
+
1129
+ M2ePro.url.add({$urls});
1130
+
1131
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
1132
+
1133
+ M2ePro.url.checkLockListing = '{$checkLockListing}';
1134
+ M2ePro.url.lockListingNow = '{$lockListingNow}';
1135
+ M2ePro.url.unlockListingNow = '{$unlockListingNow}';
1136
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
1137
+
1138
+ M2ePro.url.runListProducts = '{$runListProducts}';
1139
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
1140
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
1141
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
1142
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
1143
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
1144
+ M2ePro.url.setChildListingProductOptions = '{$setChildListingProductOptions}';
1145
+
1146
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
1147
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
1148
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
1149
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
1150
+
1151
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
1152
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
1153
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
1154
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
1155
+
1156
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
1157
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
1158
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
1159
+
1160
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
1161
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
1162
+
1163
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
1164
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
1165
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
1166
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
1167
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
1168
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
1169
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
1170
+
1171
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
1172
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
1173
+
1174
+ M2ePro.text.error_changing_product_options = '{$errorChangingProductOptions}';
1175
+
1176
+ M2ePro.text.success_word = '{$successWord}';
1177
+ M2ePro.text.notice_word = '{$noticeWord}';
1178
+ M2ePro.text.warning_word = '{$warningWord}';
1179
+ M2ePro.text.error_word = '{$errorWord}';
1180
+ M2ePro.text.close_word = '{$closeWord}';
1181
+ M2ePro.text.confirm_word = '{$confirmWord}';
1182
+ M2ePro.text.cancel_word = '{$cancelWord}';
1183
+
1184
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
1185
+
1186
+ M2ePro.text.confirm = '{$textConfirm}';
1187
+
1188
+ M2ePro.customData.componentMode = '{$component}';
1189
+ M2ePro.customData.gridId = 'amazonVariationProductManageGrid';
1190
+
1191
+ // fix for tool tip position in iframe
1192
+ MagentoFieldTip.prototype.changeToolTipPosition = function(element)
1193
+ {
1194
+ var toolTip = element.up().select('.tool-tip-message')[0];
1195
+
1196
+ var settings = {
1197
+ setHeight: false,
1198
+ setWidth: false,
1199
+ setLeft: true,
1200
+ offsetTop: 25,
1201
+ offsetLeft: -20
1202
+ };
1203
+
1204
+ if (element.up().getStyle('float') == 'right') {
1205
+ settings.offsetLeft += 18;
1206
+ }
1207
+ if (element.up().match('span')) {
1208
+ settings.offsetLeft += 15;
1209
+ }
1210
+
1211
+ toolTip.clonePosition(element, settings);
1212
+
1213
+ if (toolTip.hasClassName('tip-left')) {
1214
+ toolTip.style.left = (parseInt(toolTip.style.left) - toolTip.getWidth() - 10) + 'px';
1215
+ }
1216
+ };
1217
+
1218
+ Event.observe(window, 'load', function() {
1219
+
1220
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
1221
+
1222
+ ListingGridHandlerObj = new CommonAmazonListingVariationProductManageVariationsGridHandler(
1223
+ 'amazonVariationProductManageGrid',
1224
+ {$listingId}
1225
+ );
1226
+
1227
+ // todo next (temp solution)
1228
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
1229
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
1230
+
1231
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
1232
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
1233
+
1234
+ setTimeout(function() {
1235
+ ListingGridHandlerObj.afterInitPage();
1236
+ }, 350);
1237
+ });
1238
+
1239
+ if (typeof ListingGridHandlerObj != 'undefined') {
1240
+ ListingGridHandlerObj.afterInitPage();
1241
+ }
1242
+
1243
+ {$hideMassAction}
1244
+
1245
+ </script>
1246
+ JAVASCRIPT;
1247
+
1248
+ $additionalCss = <<<HTML
1249
+ <style>
1250
+ body {
1251
+ background: none;
1252
+ }
1253
+
1254
+ .wrapper {
1255
+ min-width: inherit;
1256
+ }
1257
+
1258
+ .footer {
1259
+ display: none;
1260
+ }
1261
+
1262
+ .middle {
1263
+ padding: 0px;
1264
+ background: none;
1265
+ }
1266
+
1267
+ td.help_line .hl_close {
1268
+ margin-top: -6px;
1269
+ }
1270
+
1271
+ td.help_line .hl_header {
1272
+ padding: 0 0 10px !important;
1273
+ }
1274
+
1275
+ </style>
1276
+ HTML;
1277
+
1278
+ return '<div id="messages"></div>' .
1279
+ '<div id="listing_view_progress_bar"></div>' .
1280
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
1281
+ '<div id="listing_view_content_container">'.
1282
+ parent::_toHtml() .
1283
+ '</div>' . $javascriptMain . $additionalCss;
1284
+ }
1285
+
1286
+ // ####################################
1287
+
1288
+ private function canChangeProductVariation(Ess_M2ePro_Model_Listing_Product $childListingProduct)
1289
+ {
1290
+ if (!$this->hasUnusedProductVariation()) {
1291
+ return false;
1292
+ }
1293
+
1294
+ $lockData = $this->getLockedData($childListingProduct);
1295
+ if ($lockData['in_action']) {
1296
+ return false;
1297
+ }
1298
+
1299
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonChildListingProduct */
1300
+ $amazonChildListingProduct = $childListingProduct->getChildObject();
1301
+
1302
+ if (!$amazonChildListingProduct->getGeneralId()) {
1303
+ return false;
1304
+ }
1305
+
1306
+ $childTypeModel = $amazonChildListingProduct->getVariationManager()->getTypeModel();
1307
+
1308
+ if ($childTypeModel->isVariationProductMatched() && $this->hasChildWithEmptyProductOptions()) {
1309
+ return false;
1310
+ }
1311
+
1312
+ return true;
1313
+ }
1314
+
1315
+ private function getLockedData($row)
1316
+ {
1317
+ $listingProductId = $row->getData('id');
1318
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1319
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
1320
+ $tempArray = array(
1321
+ 'object_locks' => $objectLocks,
1322
+ 'in_action' => !empty($objectLocks),
1323
+ );
1324
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1325
+ }
1326
+
1327
+ return $this->lockedDataCache[$listingProductId];
1328
+ }
1329
+
1330
+ // ####################################
1331
+
1332
+ protected function getTemplateDescriptionLinkHtml($listingProduct)
1333
+ {
1334
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
1335
+ 'id' => $listingProduct->getChildObject()->getTemplateDescriptionId()
1336
+ ));
1337
+
1338
+ $helper = Mage::helper('M2ePro');
1339
+ $templateTitle = $listingProduct->getChildObject()->getDescriptionTemplate()->getTitle();
1340
+
1341
+ return <<<HTML
1342
+ <span style="font-size: 9px;">{$helper->__('Description Title')}:&nbsp;
1343
+ <a target="_blank" href="{$templateDescriptionEditUrl}">
1344
+ {$helper->escapeHtml($templateTitle)}</a>
1345
+ </span>
1346
+ <br/>
1347
+ HTML;
1348
+ }
1349
+
1350
+ // ####################################
1351
+
1352
+ public function getProductVariationsTree($childProduct)
1353
+ {
1354
+ $unusedVariations = $this->getUnusedProductVariations();
1355
+
1356
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1357
+ $childTypeModel = $childProduct->getChildObject()->getVariationManager()->getTypeModel();
1358
+
1359
+ if ($childTypeModel->isVariationProductMatched()) {
1360
+ $unusedVariations[] = $childTypeModel->getProductOptions();
1361
+ }
1362
+
1363
+ $variationsSets = $this->getAttributesVariationsSets($unusedVariations);
1364
+ $firstAttribute = key($variationsSets);
1365
+
1366
+ return $this->prepareVariations($firstAttribute,$unusedVariations,$variationsSets);
1367
+ }
1368
+
1369
+ private function prepareVariations($currentAttribute,$unusedVariations,$variationsSets,$filters = array())
1370
+ {
1371
+ $return = false;
1372
+
1373
+ $temp = array_flip(array_keys($variationsSets));
1374
+
1375
+ $lastAttributePosition = count($variationsSets) - 1;
1376
+ $currentAttributePosition = $temp[$currentAttribute];
1377
+
1378
+ if ($currentAttributePosition != $lastAttributePosition) {
1379
+
1380
+ $temp = array_keys($variationsSets);
1381
+ $nextAttribute = $temp[$currentAttributePosition + 1];
1382
+
1383
+ foreach ($variationsSets[$currentAttribute] as $option) {
1384
+
1385
+ $filters[$currentAttribute] = $option;
1386
+
1387
+ $result = $this->prepareVariations(
1388
+ $nextAttribute,$unusedVariations,$variationsSets,$filters
1389
+ );
1390
+
1391
+ if (!$result) {
1392
+ continue;
1393
+ }
1394
+
1395
+ $return[$currentAttribute][$option] = $result;
1396
+ }
1397
+
1398
+ ksort($return[$currentAttribute]);
1399
+
1400
+ return $return;
1401
+ }
1402
+
1403
+ $return = false;
1404
+ foreach ($unusedVariations as $key => $magentoVariation) {
1405
+ foreach ($magentoVariation as $attribute => $option) {
1406
+
1407
+ if ($attribute == $currentAttribute) {
1408
+
1409
+ if (count($variationsSets) != 1) {
1410
+ continue;
1411
+ }
1412
+
1413
+ $values = array_flip($variationsSets[$currentAttribute]);
1414
+ $return = array($currentAttribute => $values);
1415
+
1416
+ foreach ($return[$currentAttribute] as &$option) {
1417
+ $option = true;
1418
+ }
1419
+
1420
+ return $return;
1421
+ }
1422
+
1423
+ if ($option != $filters[$attribute]) {
1424
+ unset($unusedVariations[$key]);
1425
+ continue;
1426
+ }
1427
+
1428
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
1429
+ if ($tempAttribute == $currentAttribute) {
1430
+ $option = $tempOption;
1431
+ $return[$currentAttribute][$option] = true;
1432
+ }
1433
+ }
1434
+ }
1435
+ }
1436
+
1437
+ if (count($unusedVariations) < 1) {
1438
+ return false;
1439
+ }
1440
+
1441
+ ksort($return[$currentAttribute]);
1442
+
1443
+ return $return;
1444
+ }
1445
+
1446
+ // ####################################
1447
+
1448
+ public function getCurrentProductVariations()
1449
+ {
1450
+
1451
+ if (!is_null($this->currentProductVariations)) {
1452
+ return $this->currentProductVariations;
1453
+ }
1454
+
1455
+ $magentoProductVariations = $this->getListingProduct()
1456
+ ->getMagentoProduct()
1457
+ ->getVariationInstance()
1458
+ ->getVariationsTypeStandard();
1459
+
1460
+ $productVariations = array();
1461
+
1462
+ foreach ($magentoProductVariations['variations'] as $option) {
1463
+ $productOption = array();
1464
+
1465
+ foreach ($option as $attribute) {
1466
+ $productOption[$attribute['attribute']] = $attribute['option'];
1467
+ }
1468
+
1469
+ $productVariations[] = $productOption;
1470
+ }
1471
+
1472
+ return $this->currentProductVariations = $productVariations;
1473
+ }
1474
+
1475
+ public function getUsedProductVariations()
1476
+ {
1477
+ if (is_null($this->usedProductVariations)) {
1478
+
1479
+ $usedOptions = array();
1480
+
1481
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1482
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1483
+
1484
+ /**
1485
+ * @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel
1486
+ */
1487
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1488
+
1489
+ if (!$childTypeModel->isVariationProductMatched()) {
1490
+ continue;
1491
+ }
1492
+
1493
+ $usedOptions[] = $childTypeModel->getProductOptions();
1494
+ }
1495
+
1496
+ $this->usedProductVariations = $usedOptions;
1497
+ }
1498
+
1499
+ return $this->usedProductVariations;
1500
+ }
1501
+
1502
+ // ####################################
1503
+
1504
+ public function getUnusedProductVariations()
1505
+ {
1506
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
1507
+ }
1508
+
1509
+ private function getUnusedVariations($currentVariations, $usedVariations)
1510
+ {
1511
+ if (empty($currentVariations)) {
1512
+ return array();
1513
+ }
1514
+
1515
+ if (empty($usedVariations)) {
1516
+ return $currentVariations;
1517
+ }
1518
+
1519
+ $unusedOptions = array();
1520
+
1521
+ foreach ($currentVariations as $id => $currentOption) {
1522
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
1523
+ continue;
1524
+ }
1525
+
1526
+ $unusedOptions[$id] = $currentOption;
1527
+ }
1528
+
1529
+ return $unusedOptions;
1530
+ }
1531
+
1532
+ private function isVariationExistsInArray(array $needle, array $haystack)
1533
+ {
1534
+ foreach ($haystack as $option) {
1535
+ if ($option != $needle) {
1536
+ continue;
1537
+ }
1538
+
1539
+ return true;
1540
+ }
1541
+
1542
+ return false;
1543
+ }
1544
+
1545
+ // ####################################
1546
+
1547
+ public function getChildListingProducts()
1548
+ {
1549
+ if (!is_null($this->childListingProducts)) {
1550
+ return $this->childListingProducts;
1551
+ }
1552
+
1553
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
1554
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
1555
+ }
1556
+
1557
+ public function getAttributesVariationsSets($variations)
1558
+ {
1559
+ $attributesOptions = array();
1560
+
1561
+ foreach ($variations as $variation) {
1562
+ foreach ($variation as $attr => $option) {
1563
+ if (!isset($attributesOptions[$attr])) {
1564
+ $attributesOptions[$attr] = array();
1565
+ }
1566
+ if (!in_array($option, $attributesOptions[$attr])) {
1567
+ $attributesOptions[$attr][] = $option;
1568
+ }
1569
+ }
1570
+ }
1571
+
1572
+ ksort($attributesOptions);
1573
+
1574
+ return $attributesOptions;
1575
+ }
1576
+
1577
+ // ####################################
1578
+
1579
+ protected function getGeneralIdLink($generalId)
1580
+ {
1581
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1582
+ $generalId,
1583
+ $this->getListingProduct()->getListing()->getMarketplaceId()
1584
+ );
1585
+
1586
+ return <<<HTML
1587
+ <a href="{$url}" target="_blank" title="{$generalId}" >{$generalId}</a>
1588
+ HTML;
1589
+ }
1590
+
1591
+ // ####################################
1592
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Help.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_Variation_Product_Manage_Tabs_Variations_Help
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('amazonListingViewHelp');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations/help.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToIndividualPopup.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonListingAddNewAsinManualPopup');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/switch_to_individual_popup.phtml');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ parent::_beforeToHtml();
27
+
28
+ $data = array(
29
+ 'class' => 'switch-to-individual-btn',
30
+ 'label' => Mage::helper('M2ePro')->__('Yes')
31
+ );
32
+ $this->setChild(
33
+ 'yes_btn',
34
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
35
+ );
36
+
37
+ $data = array(
38
+ 'class' => 'switch-to-individual-popup-close',
39
+ 'label' => Mage::helper('M2ePro')->__('No')
40
+ );
41
+ $this->setChild(
42
+ 'no_btn',
43
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
44
+ );
45
+
46
+ return $this;
47
+ }
48
+
49
+ // ####################################
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToParentPopup.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonListingAddNewAsinManualPopup');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/switch_to_parent_popup.phtml');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ parent::_beforeToHtml();
27
+
28
+ $data = array(
29
+ 'class' => 'switch-to-parent-btn',
30
+ 'label' => Mage::helper('M2ePro')->__('Yes')
31
+ );
32
+ $this->setChild(
33
+ 'yes_btn',
34
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
35
+ );
36
+
37
+ $data = array(
38
+ 'class' => 'switch-to-parent-popup-close',
39
+ 'label' => Mage::helper('M2ePro')->__('No')
40
+ );
41
+ $this->setChild(
42
+ 'no_btn',
43
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
44
+ );
45
+
46
+ return $this;
47
+ }
48
+
49
+ // ####################################
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyAttributesPopup.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2015 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_VocabularyAttributesPopup
8
+ extends Mage_Adminhtml_Block_Template
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingVocabularyAttributesPopup');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/vocabulary_attributes_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
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addAttributesToVocabulary(true)',
31
+ );
32
+ $this->setChild(
33
+ 'yes_btn',
34
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
35
+ );
36
+
37
+ $data = array(
38
+ 'class' => 'switch-to-individual-popup-close',
39
+ 'label' => Mage::helper('M2ePro')->__('No'),
40
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addAttributesToVocabulary(false)',
41
+ );
42
+ $this->setChild(
43
+ 'no_btn',
44
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
45
+ );
46
+
47
+ return $this;
48
+ }
49
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyOptionsPopup.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2015 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_VocabularyOptionsPopup
8
+ extends Mage_Adminhtml_Block_Template
9
+ {
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingVocabularyAttributesPopup');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/vocabulary_options_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
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addOptionsToVocabulary(true)',
31
+ );
32
+ $this->setChild(
33
+ 'yes_btn',
34
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
35
+ );
36
+
37
+ $data = array(
38
+ 'class' => 'switch-to-individual-popup-close',
39
+ 'label' => Mage::helper('M2ePro')->__('No'),
40
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addOptionsToVocabulary(false)',
41
+ );
42
+ $this->setChild(
43
+ 'no_btn',
44
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
45
+ );
46
+
47
+ return $this;
48
+ }
49
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View.php ADDED
@@ -0,0 +1,756 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ // Initialization block
22
+ //------------------------------
23
+ $this->setId('amazonListingView');
24
+ $this->_blockGroup = 'M2ePro';
25
+ $this->_controller = 'adminhtml_common_amazon_listing_view_' . $this->getViewMode();
26
+ //------------------------------
27
+
28
+ // Set header text
29
+ //------------------------------
30
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
31
+
32
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
33
+ $headerText = Mage::helper('M2ePro')->__(
34
+ 'View %component_name% Listing',
35
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()
36
+ );
37
+ } else {
38
+ $headerText = Mage::helper('M2ePro')->__('View Listing ');
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
+ //------------------------------
55
+ $url = $this->getUrl('*/adminhtml_common_log/listing', array(
56
+ 'id' => $listingData['id'],
57
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON
58
+ ));
59
+ $this->_addButton('view_log', array(
60
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
61
+ 'onclick' => 'window.open(\'' . $url . '\')',
62
+ 'class' => 'button_link'
63
+ ));
64
+ //------------------------------
65
+
66
+ //------------------------------
67
+ $this->_addButton('edit_settings', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Edit Settings'),
69
+ 'onclick' => '',
70
+ 'class' => 'drop_down edit_settings_drop_down'
71
+ ));
72
+ //------------------------------
73
+
74
+ //------------------------------
75
+ $this->_addButton('add_products', array(
76
+ 'label' => Mage::helper('M2ePro')->__('Add Products'),
77
+ 'onclick' => '',
78
+ 'class' => 'add drop_down add_products_drop_down'
79
+ ));
80
+ //------------------------------
81
+ }
82
+
83
+ // ####################################
84
+
85
+ public function getViewMode()
86
+ {
87
+ $allowedModes = array(self::VIEW_MODE_AMAZON, self::VIEW_MODE_MAGENTO, self::VIEW_MODE_SELLERCENTRAL);
88
+ $mode = $this->getParam('view_mode', self::DEFAULT_VIEW_MODE);
89
+
90
+ if (in_array($mode, $allowedModes)) {
91
+ return $mode;
92
+ }
93
+
94
+ return self::DEFAULT_VIEW_MODE;
95
+ }
96
+
97
+ protected function getParam($paramName, $default = NULL)
98
+ {
99
+ $session = Mage::helper('M2ePro/Data_Session');
100
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
101
+ $sessionParamName = $this->getId() . $listingData['id'] . $paramName;
102
+
103
+ if ($this->getRequest()->has($paramName)) {
104
+ $param = $this->getRequest()->getParam($paramName);
105
+ $session->setValue($sessionParamName, $param);
106
+ return $param;
107
+ } elseif ($param = $session->getValue($sessionParamName)) {
108
+ return $param;
109
+ }
110
+
111
+ return $default;
112
+ }
113
+
114
+ // ####################################
115
+
116
+ protected function _toHtml()
117
+ {
118
+ return '<div id="listing_view_progress_bar"></div>' .
119
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
120
+ '<div id="listing_view_content_container">'.
121
+ parent::_toHtml() .
122
+ '</div>';
123
+ }
124
+
125
+ public function getGridHtml()
126
+ {
127
+ if ($this->getRequest()->isXmlHttpRequest()) {
128
+ return parent::getGridHtml();
129
+ }
130
+
131
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
132
+
133
+ /** @var $helper Ess_M2ePro_Helper_Data */
134
+ $helper = Mage::helper('M2ePro');
135
+
136
+ //------------------------------
137
+ $urls = $helper->getControllerActions(
138
+ 'adminhtml_common_listing_autoAction', array(
139
+ 'listing_id' => $this->getRequest()->getParam('id'),
140
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
141
+ )
142
+ );
143
+ $showAutoAction = json_encode((bool)$this->getRequest()->getParam('auto_actions'));
144
+
145
+ $path = 'adminhtml_common_log/listingProduct';
146
+ $urls[$path] = $this->getUrl('*/' . $path, array(
147
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
148
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array(
149
+ 'id' => $listingData['id']
150
+ ))
151
+ ));
152
+
153
+ $path = 'adminhtml_common_listing/duplicateProducts';
154
+ $urls[$path] = $this->getUrl('*/' . $path);
155
+
156
+ $urls = json_encode($urls);
157
+ //------------------------------
158
+
159
+ // todo next (change)
160
+
161
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
162
+
163
+ $temp = Mage::helper('M2ePro/Data_Session')->getValue('products_ids_for_list', true);
164
+ $productsIdsForList = empty($temp) ? '' : $temp;
165
+
166
+ $gridId = $this->getChild('grid')->getId();
167
+ $ignoreListings = json_encode(array($listingData['id']));
168
+
169
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
170
+ $marketplaceInstance = Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Marketplace',$marketplaceId);
171
+ $marketplace = json_encode($marketplaceInstance->getData());
172
+ $isNewAsinAvailable = json_encode($marketplaceInstance->getChildObject()->isNewAsinAvailable());
173
+
174
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing',array(
175
+ 'id' => $listingData['id'],
176
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON,
177
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',
178
+ array('id' =>$listingData['id']))
179
+ ));
180
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
181
+
182
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
183
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
184
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
185
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
186
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopAndRemoveProducts');
187
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
188
+
189
+ $prepareData = $this->getUrl('*/adminhtml_listing_moving/prepareMoveToListing');
190
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_moving/moveToListingGrid');
191
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_moving/getFailedProductsGrid');
192
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_moving/tryToMoveToListing');
193
+ $moveToListing = $this->getUrl('*/adminhtml_listing_moving/moveToListing');
194
+
195
+ $marketplaceSynchUrl = $this->getUrl(
196
+ '*/adminhtml_common_marketplace/index',
197
+ array('tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON)
198
+ );
199
+
200
+ $getVariationEditPopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationEditPopup');
201
+ $getVariationManagePopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationManagePopup');
202
+
203
+ $variationEditActionUrl = $this->getUrl('*/adminhtml_common_listing/variationEdit');
204
+ $variationManageActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManage');
205
+ $variationManageGenerateActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManageGenerate');
206
+ $variationResetActionUrl = $this->getUrl('*/adminhtml_common_listing/variationReset');
207
+
208
+ $saveListingAdditionalDataActionUrl = $this->getUrl('*/adminhtml_listing/saveListingAdditionalData', array(
209
+ 'id' => $listingData['id']
210
+ ));
211
+
212
+ $popupTitle = $helper->escapeJs($helper->__('Moving Amazon Items'));
213
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Amazon Item'));
214
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
215
+
216
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
217
+ $taskCompletedSuccessMessage = $helper->escapeJs(
218
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
219
+ );
220
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
221
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
222
+ ));
223
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
224
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
225
+ ));
226
+
227
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
228
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
229
+ 'Sending %product_title% Product(s) data on Amazon.')
230
+ );
231
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
232
+
233
+ $listingLockedMessage = $helper->escapeJs(
234
+ $helper->__('The Listing was locked by another process. Please try again later.')
235
+ );
236
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
237
+
238
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
239
+ ->__('Listing All Items On Amazon'));
240
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
241
+ ->__('Listing Selected Items On Amazon'));
242
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
243
+ ->__('Revising Selected Items On Amazon'));
244
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
245
+ ->__('Relisting Selected Items On Amazon'));
246
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
247
+ ->__('Stopping Selected Items On Amazon'));
248
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
249
+ ->escapeJs(Mage::helper('M2ePro')
250
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
251
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
252
+ ->escapeJs(Mage::helper('M2ePro')
253
+ ->__('Removing From Amazon And Listing Selected Items'));
254
+
255
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
256
+ $productsWereNotMovedMessage = $helper->escapeJs(
257
+ $helper->__('Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
258
+ );
259
+ $someProductsWereNotMovedMessage = $helper->escapeJs(
260
+ $helper->__('Some Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
261
+ );
262
+
263
+ $selectItemsMessage = $helper->escapeJs(
264
+ $helper->__('Please select the Products you want to perform the Action on.')
265
+ );
266
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
267
+
268
+ $successWord = $helper->escapeJs($helper->__('Success'));
269
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
270
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
271
+ $errorWord = $helper->escapeJs($helper->__('Error'));
272
+ $closeWord = $helper->escapeJs($helper->__('Close'));
273
+
274
+ $assignString = Mage::helper('M2ePro')->__('Assign');
275
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
276
+
277
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
278
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
279
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
280
+ $getCategoriesByAsin = $this->getUrl('*/adminhtml_common_amazon_listing/getCategoriesByAsin');
281
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
282
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
283
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
284
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
285
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
286
+
287
+ $variationProductManage = $this->getUrl(
288
+ '*/adminhtml_common_amazon_listing_variation_product_manage/index');
289
+ $variationProductSetGeneralIdOwner = $this->getUrl(
290
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setGeneralIdOwner');
291
+ $variationProductSetVariationTheme = $this->getUrl(
292
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setVariationTheme');
293
+ $variationProductSetMatchedAttributes = $this->getUrl(
294
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setMatchedAttributes');
295
+ $variationProductSetListingProductSku = $this->getUrl(
296
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setListingProductSku');
297
+ $manageVariationViewTemplateDescriptionsGrid = $this->getUrl(
298
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewTemplateDescriptionsGrid');
299
+ $manageVariationMapToTemplateDescription = $this->getUrl(
300
+ '*/adminhtml_common_amazon_listing_variation_product_manage/mapToTemplateDescription');
301
+ $addAttributesToVocabularyUrl = $this->getUrl(
302
+ '*/adminhtml_common_amazon_listing_variation_product_manage/addAttributesToVocabulary'
303
+ );
304
+ $addOptionsToVocabularyUrl = $this->getUrl(
305
+ '*/adminhtml_common_amazon_listing_variation_product_manage/addOptionsToVocabulary'
306
+ );
307
+
308
+ $viewVariationsSettingsAjax = $this->getUrl(
309
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsSettingsAjax');
310
+
311
+ $newAsinUrl = $this->getUrl('*/adminhtml_common_amazon_template_newProduct',array(
312
+ 'marketplace_id' => Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'),
313
+ ));
314
+
315
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
316
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
317
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
318
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
319
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
320
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
321
+
322
+ $enterProductSearchQueryMessage = $helper->escapeJs(
323
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
324
+ );
325
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
326
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
327
+ $autoMapAsinErrorMessage = $helper->escapeJs(
328
+ $helper->__('Server is currently unavailable. Please try again later.')
329
+ );
330
+ $newAsinNotAvailable = $helper->escapeJs(
331
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
332
+ );
333
+ $notSynchronizedMarketplace = $helper->escapeJs(
334
+ $helper->__(
335
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
336
+ ).' '.
337
+ $helper->__(
338
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
339
+ )
340
+ );
341
+
342
+ $noVariationsLeftText = $helper->__('All variations are already added.');
343
+
344
+ $variationManageMatchedAttributesError = $helper->__('Please choose valid Attributes.');
345
+ $variationManageMatchedAttributesErrorDuplicateSelection =
346
+ $helper->__('You can not choose the same Attribute twice.');
347
+
348
+ $variationManageSkuPopUpTitle =
349
+ $helper->__('Enter Amazon Parent Product SKU');
350
+
351
+ $switchToIndividualModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
352
+ $switchToParentModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
353
+
354
+ $emptySkuError = $helper->escapeJs($helper->__('Please enter Amazon Parent Product SKU.'));
355
+
356
+ $translations = json_encode(array(
357
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
358
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
359
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
360
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
361
+ ));
362
+
363
+ $javascriptsMain = <<<JAVASCRIPT
364
+ <script type="text/javascript">
365
+
366
+ if (typeof M2ePro == 'undefined') {
367
+ M2ePro = {};
368
+ M2ePro.url = {};
369
+ M2ePro.formData = {};
370
+ M2ePro.customData = {};
371
+ M2ePro.text = {};
372
+ }
373
+
374
+ M2ePro.url.add({$urls});
375
+ M2ePro.translator.add({$translations});
376
+
377
+ M2ePro.productsIdsForList = '{$productsIdsForList}';
378
+
379
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
380
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
381
+
382
+ M2ePro.url.runListProducts = '{$runListProducts}';
383
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
384
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
385
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
386
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
387
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
388
+
389
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
390
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
391
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
392
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
393
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
394
+ M2ePro.url.getCategoriesByAsin = '{$getCategoriesByAsin}';
395
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
396
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
397
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
398
+
399
+ M2ePro.url.variationProductManage = '{$variationProductManage}';
400
+ M2ePro.url.variationProductSetGeneralIdOwner = '{$variationProductSetGeneralIdOwner}';
401
+ M2ePro.url.variationProductSetVariationTheme = '{$variationProductSetVariationTheme}';
402
+ M2ePro.url.variationProductSetMatchedAttributes = '{$variationProductSetMatchedAttributes}';
403
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
404
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
405
+ M2ePro.url.manageVariationViewTemplateDescriptionsGrid = '{$manageVariationViewTemplateDescriptionsGrid}';
406
+ M2ePro.url.manageVariationMapToTemplateDescription = '{$manageVariationMapToTemplateDescription}';
407
+ M2ePro.url.viewVariationsSettingsAjax = '{$viewVariationsSettingsAjax}';
408
+ M2ePro.url.addAttributesToVocabulary = '{$addAttributesToVocabularyUrl}';
409
+ M2ePro.url.addOptionsToVocabulary = '{$addOptionsToVocabularyUrl}';
410
+
411
+ M2ePro.url.newAsin = '{$newAsinUrl}';
412
+
413
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
414
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
415
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
416
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
417
+
418
+ M2ePro.url.prepareData = '{$prepareData}';
419
+ M2ePro.url.getGridHtml = '{$getMoveToListingGridHtml}';
420
+ M2ePro.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
421
+ M2ePro.url.tryToMoveToListing = '{$tryToMoveToListing}';
422
+ M2ePro.url.moveToListing = '{$moveToListing}';
423
+
424
+ M2ePro.url.marketplace_synch = '{$marketplaceSynchUrl}';
425
+
426
+ M2ePro.url.get_variation_edit_popup = '{$getVariationEditPopupUrl}';
427
+ M2ePro.url.get_variation_manage_popup = '{$getVariationManagePopupUrl}';
428
+
429
+ M2ePro.url.variation_edit_action = '{$variationEditActionUrl}';
430
+ M2ePro.url.variation_manage_action = '{$variationManageActionUrl}';
431
+ M2ePro.url.variation_manage_generate_action = '{$variationManageGenerateActionUrl}';
432
+ M2ePro.url.variation_reset_action = '{$variationResetActionUrl}';
433
+
434
+ M2ePro.url.save_listing_additional_data = '{$saveListingAdditionalDataActionUrl}';
435
+
436
+ M2ePro.text.popup_title = '{$popupTitle}';
437
+ M2ePro.text.popup_title_single = '{$popupTitleSingle}';
438
+ M2ePro.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
439
+
440
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
441
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
442
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
443
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
444
+
445
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
446
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
447
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
448
+
449
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
450
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
451
+
452
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
453
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
454
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
455
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
456
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
457
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
458
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
459
+
460
+ M2ePro.text.successfully_moved = '{$successfullyMovedMessage}';
461
+ M2ePro.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
462
+ M2ePro.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
463
+
464
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
465
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
466
+
467
+ M2ePro.text.success_word = '{$successWord}';
468
+ M2ePro.text.notice_word = '{$noticeWord}';
469
+ M2ePro.text.warning_word = '{$warningWord}';
470
+ M2ePro.text.error_word = '{$errorWord}';
471
+ M2ePro.text.close_word = '{$closeWord}';
472
+
473
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
474
+
475
+ M2ePro.text.assign = '{$assignString}';
476
+ M2ePro.text.confirm = '{$textConfirm}';
477
+
478
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
479
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
480
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
481
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
482
+
483
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
484
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
485
+
486
+ M2ePro.text.no_variations_left = '{$noVariationsLeftText}';
487
+
488
+ M2ePro.text.variation_manage_matched_attributes_error = '{$variationManageMatchedAttributesError}';
489
+ M2ePro.text.variation_manage_matched_attributes_error_duplicate =
490
+ '{$variationManageMatchedAttributesErrorDuplicateSelection}';
491
+
492
+ M2ePro.text.variation_manage_matched_sku_popup_title = '{$variationManageSkuPopUpTitle}';
493
+ M2ePro.text.empty_sku_error = '{$emptySkuError}';
494
+
495
+ M2ePro.text.switch_to_individual_mode_popup_title = '{$switchToIndividualModePopUpTitle}';
496
+ M2ePro.text.switch_to_parent_mode_popup_title = '{$switchToParentModePopUpTitle}';
497
+
498
+ M2ePro.customData.componentMode = '{$component}';
499
+ M2ePro.customData.gridId = '{$gridId}';
500
+ M2ePro.customData.ignoreListings = '{$ignoreListings}';
501
+
502
+ M2ePro.customData.marketplace = {$marketplace};
503
+ M2ePro.customData.isNewAsinAvailable = {$isNewAsinAvailable};
504
+
505
+ Event.observe(window, 'load', function() {
506
+
507
+ ListingGridHandlerObj = new CommonAmazonListingGridHandler(
508
+ '{$gridId}',
509
+ {$listingData['id']}
510
+ );
511
+
512
+ // todo next
513
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
514
+ ListingGridHandlerObj.movingHandler.setOptions(M2ePro);
515
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
516
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
517
+ ListingGridHandlerObj.variationProductManageHandler.setOptions(M2ePro);
518
+
519
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
520
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
521
+
522
+ ListingProductVariationHandlerObj = new CommonListingProductVariationHandler(M2ePro,
523
+ ListingGridHandlerObj);
524
+
525
+ if (M2ePro.productsIdsForList) {
526
+ ListingGridHandlerObj.getGridMassActionObj().checkedString = M2ePro.productsIdsForList;
527
+ ListingGridHandlerObj.actionHandler.listAction();
528
+ }
529
+
530
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
531
+ if ({$showAutoAction}) {
532
+ ListingAutoActionHandlerObj.loadAutoActionHtml();
533
+ }
534
+
535
+ });
536
+
537
+ </script>
538
+ JAVASCRIPT;
539
+
540
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_view_help');
541
+ $productSearchBlock = $this->getLayout()
542
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_productSearch_main');
543
+
544
+ //------------------------------
545
+ $data = array(
546
+ 'target_css_class' => 'edit_settings_drop_down',
547
+ 'items' => $this->getTemplatesButtonDropDownItems()
548
+ );
549
+ $templatesDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
550
+ $templatesDropDownBlock->setData($data);
551
+ //------------------------------
552
+
553
+ //------------------------------
554
+ $data = array(
555
+ 'target_css_class' => 'add_products_drop_down',
556
+ 'items' => $this->getAddProductsDropDownItems()
557
+ );
558
+ $addProductsDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
559
+ $addProductsDropDownBlock->setData($data);
560
+ //------------------------------
561
+
562
+ //------------------------------
563
+ $listingSwitcher = $this->getLayout()->createBlock(
564
+ 'M2ePro/adminhtml_common_amazon_listing_view_listingSwitcher'
565
+ );
566
+ //------------------------------
567
+
568
+ //------------------------------
569
+ $viewHeaderBlock = $this->getLayout()->createBlock(
570
+ 'M2ePro/adminhtml_listing_view_header','',
571
+ array('listing' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Listing',$listingData['id']))
572
+ );
573
+ //------------------------------
574
+
575
+ //------------------------------
576
+ $switchToIndividualPopup = $this->getLayout()->createBlock(
577
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToIndividualPopup');
578
+ //------------------------------
579
+
580
+ //------------------------------
581
+ $switchToParentPopup = $this->getLayout()->createBlock(
582
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToParentPopup');
583
+ //------------------------------
584
+
585
+ return $javascriptsMain
586
+ . $templatesDropDownBlock->toHtml()
587
+ . $listingSwitcher->toHtml()
588
+ . $addProductsDropDownBlock->toHtml()
589
+ . $helpBlock->toHtml()
590
+ . $viewHeaderBlock->toHtml()
591
+ . $productSearchBlock->toHtml()
592
+ . $switchToIndividualPopup->toHtml()
593
+ . $switchToParentPopup->toHtml()
594
+ . parent::getGridHtml();
595
+ }
596
+
597
+ public function getHeaderHtml()
598
+ {
599
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
600
+
601
+ //------------------------------
602
+ $collection = Mage::getModel('M2ePro/Listing')->getCollection();
603
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
604
+ $collection->addFieldToFilter('id', array('neq' => $listingData['id']));
605
+ $collection->setPageSize(200);
606
+ $collection->setOrder('title', 'ASC');
607
+
608
+ $items = array();
609
+ foreach ($collection->getItems() as $item) {
610
+ $items[] = array(
611
+ 'label' => $item->getTitle(),
612
+ 'url' => $this->getUrl('*/*/view', array('id' => $item->getId()))
613
+ );
614
+ }
615
+ //------------------------------
616
+
617
+ if (count($items) == 0) {
618
+ return parent::getHeaderHtml();
619
+ }
620
+
621
+ //------------------------------
622
+ $data = array(
623
+ 'target_css_class' => 'listing-profile-title',
624
+ 'style' => 'max-height: 120px; overflow: auto; width: 200px;',
625
+ 'items' => $items
626
+ );
627
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
628
+ $dropDownBlock->setData($data);
629
+ //------------------------------
630
+
631
+ return parent::getHeaderHtml() . $dropDownBlock->toHtml();
632
+ }
633
+
634
+ public function getHeaderText()
635
+ {
636
+ //------------------------------
637
+ $changeProfile = Mage::helper('M2ePro')->__('Change Listing');
638
+ $headerText = parent::getHeaderText();
639
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
640
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($listingData['title']);
641
+ //------------------------------
642
+
643
+ return <<<HTML
644
+ {$headerText} <a href="javascript: void(0);"
645
+ id="listing-profile-title"
646
+ class="listing-profile-title"
647
+ style="font-weight: bold;"
648
+ title="{$changeProfile}"><span class="drop_down_header">"{$listingTitle}"</span></a>
649
+ HTML;
650
+ }
651
+
652
+ protected function getTemplatesButtonDropDownItems()
653
+ {
654
+ $items = array();
655
+
656
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
657
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
658
+ '*/adminhtml_common_amazon_listing/view',
659
+ array(
660
+ 'id' => $listingData['id']
661
+ )
662
+ );
663
+
664
+ //------------------------------
665
+ $url = $this->getUrl(
666
+ '*/adminhtml_common_amazon_listing/edit',
667
+ array(
668
+ 'id'=>$listingData['id'],
669
+ 'back'=>$backUrl,
670
+ 'tab' => 'selling'
671
+ )
672
+ );
673
+ $items[] = array(
674
+ 'url' => $url,
675
+ 'label' => Mage::helper('M2ePro')->__('Selling'),
676
+ 'target' => '_blank'
677
+ );
678
+ //------------------------------
679
+
680
+ //------------------------------
681
+ $url = $this->getUrl(
682
+ '*/adminhtml_common_amazon_listing/edit',
683
+ array(
684
+ 'id'=>$listingData['id'],
685
+ 'back'=>$backUrl,
686
+ 'tab' => 'search'
687
+ )
688
+ );
689
+ $items[] = array(
690
+ 'url' => $url,
691
+ 'label' => Mage::helper('M2ePro')->__('Search'),
692
+ 'target' => '_blank'
693
+ );
694
+ //------------------------------
695
+
696
+ //------------------------------
697
+ $items[] = array(
698
+ 'url' => 'javascript: void(0);',
699
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();',
700
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules')
701
+ );
702
+ //------------------------------
703
+
704
+ return $items;
705
+ }
706
+
707
+ public function getAddProductsDropDownItems()
708
+ {
709
+ $items = array();
710
+
711
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
712
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array(
713
+ 'id' => $listingData['id']
714
+ ));
715
+
716
+ //------------------------------
717
+ $url = $this->getUrl(
718
+ '*/adminhtml_common_listing_productAdd/index',
719
+ array(
720
+ 'id' => $listingData['id'],
721
+ 'back' => $backUrl,
722
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
723
+ 'clear' => 1,
724
+ 'step' => 2,
725
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
726
+ )
727
+ );
728
+ $items[] = array(
729
+ 'url' => $url,
730
+ 'label' => Mage::helper('M2ePro')->__('From Products List')
731
+ );
732
+ //------------------------------
733
+
734
+ //------------------------------
735
+ $url = $this->getUrl(
736
+ '*/adminhtml_common_listing_productAdd/index',
737
+ array(
738
+ 'id' => $listingData['id'],
739
+ 'back' => $backUrl,
740
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
741
+ 'clear' => 1,
742
+ 'step' => 2,
743
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
744
+ )
745
+ );
746
+ $items[] = array(
747
+ 'url' => $url,
748
+ 'label' => Mage::helper('M2ePro')->__('From Categories')
749
+ );
750
+ //------------------------------
751
+
752
+ return $items;
753
+ }
754
+
755
+ // ####################################
756
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php ADDED
@@ -0,0 +1,1596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
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' => 'IF(
113
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
114
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
115
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
116
+ `alp`.`online_sale_price`,
117
+ NULL
118
+ )',
119
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
120
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
121
+ 'is_afn_channel' => 'is_afn_channel',
122
+ 'is_general_id_owner' => 'is_general_id_owner',
123
+ 'is_variation_parent' => 'is_variation_parent',
124
+ 'defected_messages' => 'defected_messages',
125
+ 'min_online_price' => 'IF(
126
+ (`t`.`variation_min_price` IS NULL),
127
+ IF(
128
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
129
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
130
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
131
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
132
+ `alp`.`online_sale_price`,
133
+ `alp`.`online_price`
134
+ ),
135
+ `t`.`variation_min_price`
136
+ )',
137
+ 'max_online_price' => 'IF(
138
+ (`t`.`variation_max_price` IS NULL),
139
+ IF(
140
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
141
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
142
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
143
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
144
+ `alp`.`online_sale_price`,
145
+ `alp`.`online_price`
146
+ ),
147
+ `t`.`variation_max_price`
148
+ )'
149
+ ),
150
+ '{{table}}.variation_parent_id is NULL'
151
+ );
152
+
153
+ $collection->getSelect()->joinLeft(
154
+ new Zend_Db_Expr('(
155
+ SELECT
156
+ `malp`.`variation_parent_id`,
157
+ MIN(
158
+ IF(
159
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
160
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
161
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
162
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
163
+ `malp`.`online_sale_price`,
164
+ `malp`.`online_price`
165
+ )
166
+ ) as variation_min_price,
167
+ MAX(
168
+ IF(
169
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
170
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
171
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
172
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
173
+ `malp`.`online_sale_price`,
174
+ `malp`.`online_price`
175
+ )
176
+ ) as variation_max_price
177
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
178
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
179
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
180
+ WHERE `mlp`.`status` IN (
181
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
182
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
183
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
184
+ GROUP BY `malp`.`variation_parent_id`
185
+ )'),
186
+ 'alp.listing_product_id=t.variation_parent_id',
187
+ array(
188
+ 'variation_min_price' => 'variation_min_price',
189
+ 'variation_max_price' => 'variation_max_price',
190
+ )
191
+ );
192
+
193
+ //----------------------------
194
+ // exit($collection->getSelect()->__toString());
195
+
196
+ // Set collection to grid
197
+ $this->setCollection($collection);
198
+
199
+ return parent::_prepareCollection();
200
+ }
201
+
202
+ protected function _prepareColumns()
203
+ {
204
+ $this->addColumn('product_id', array(
205
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
206
+ 'align' => 'right',
207
+ 'width' => '100px',
208
+ 'type' => 'number',
209
+ 'index' => 'entity_id',
210
+ 'filter_index' => 'entity_id',
211
+ 'frame_callback' => array($this, 'callbackColumnProductId')
212
+ ));
213
+
214
+ $this->addColumn('name', array(
215
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
216
+ 'align' => 'left',
217
+ //'width' => '300px',
218
+ 'type' => 'text',
219
+ 'index' => 'name',
220
+ 'filter_index' => 'name',
221
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
222
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
223
+ ));
224
+
225
+ $this->addColumn('sku', array(
226
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
227
+ 'align' => 'left',
228
+ 'width' => '150px',
229
+ 'type' => 'text',
230
+ 'index' => 'amazon_sku',
231
+ 'filter_index' => 'amazon_sku',
232
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
233
+ ));
234
+
235
+ $this->addColumn('general_id', array(
236
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
237
+ 'align' => 'left',
238
+ 'width' => '140px',
239
+ 'type' => 'text',
240
+ 'index' => 'general_id',
241
+ 'filter_index' => 'general_id',
242
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
243
+ ));
244
+
245
+ $this->addColumn('online_qty', array(
246
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
247
+ 'align' => 'right',
248
+ 'width' => '70px',
249
+ 'type' => 'number',
250
+ 'index' => 'online_qty',
251
+ 'filter_index' => 'online_qty',
252
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
253
+ ));
254
+
255
+ $dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
256
+
257
+ if ($dir == 'desc') {
258
+ $priceSortField = 'max_online_price';
259
+ } else {
260
+ $priceSortField = 'min_online_price';
261
+ }
262
+
263
+ $this->addColumn('online_price', array(
264
+ 'header' => Mage::helper('M2ePro')->__('Price'),
265
+ 'align' => 'right',
266
+ 'width' => '70px',
267
+ 'type' => 'number',
268
+ 'index' => $priceSortField,
269
+ 'filter_index' => $priceSortField,
270
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
271
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
272
+ ));
273
+
274
+ $this->addColumn('is_afn_channel', array(
275
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
276
+ 'align' => 'right',
277
+ 'width' => '90px',
278
+ 'index' => 'is_afn_channel',
279
+ 'filter_index' => 'is_afn_channel',
280
+ 'type' => 'options',
281
+ 'sortable' => false,
282
+ 'options' => array(
283
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
284
+ 1 => Mage::helper('M2ePro')->__('Amazon')
285
+ ),
286
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
287
+ ));
288
+
289
+ $this->addColumn('status', array(
290
+ 'header' => Mage::helper('M2ePro')->__('Status'),
291
+ 'width' => '155px',
292
+ 'index' => 'amazon_status',
293
+ 'filter_index' => 'amazon_status',
294
+ 'type' => 'options',
295
+ 'sortable' => false,
296
+ 'options' => array(
297
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
298
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
299
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
300
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
301
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
302
+ ),
303
+ 'frame_callback' => array($this, 'callbackColumnStatus'),
304
+ 'filter_condition_callback' => array($this, 'callbackFilterStatus')
305
+ ));
306
+
307
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
308
+ $this->addColumn('developer_action', array(
309
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
310
+ 'align' => 'left',
311
+ 'width' => '100px',
312
+ 'type' => 'text',
313
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
314
+ 'index' => 'value',
315
+ 'filter' => false,
316
+ 'sortable' => false,
317
+ 'js_handler' => 'ListingGridHandlerObj'
318
+ ));
319
+ }
320
+
321
+ return parent::_prepareColumns();
322
+ }
323
+
324
+ protected function _prepareMassaction()
325
+ {
326
+ // Set massaction identifiers
327
+ //--------------------------------
328
+ $this->setMassactionIdField('id');
329
+ $this->setMassactionIdFieldOnlyIndexValue(true);
330
+ //--------------------------------
331
+
332
+ // Set mass-action
333
+ //--------------------------------
334
+ $groups = array(
335
+ 'actions' => Mage::helper('M2ePro')->__('Actions'),
336
+ 'asin_isbn' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
337
+ 'description_policy' => Mage::helper('M2ePro')->__('Description Policy'),
338
+ 'other' => Mage::helper('M2ePro')->__('Other'),
339
+ );
340
+
341
+ $this->getMassactionBlock()->setGroups($groups);
342
+
343
+ $this->getMassactionBlock()->addItem('list', array(
344
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
345
+ 'url' => '',
346
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
347
+ ), 'actions');
348
+
349
+ $this->getMassactionBlock()->addItem('revise', array(
350
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
351
+ 'url' => '',
352
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
353
+ ), 'actions');
354
+
355
+ $this->getMassactionBlock()->addItem('relist', array(
356
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
357
+ 'url' => '',
358
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
359
+ ), 'actions');
360
+
361
+ $this->getMassactionBlock()->addItem('stop', array(
362
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
363
+ 'url' => '',
364
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
365
+ ), 'actions');
366
+
367
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
368
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
369
+ 'url' => '',
370
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
371
+ ), 'actions');
372
+
373
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
374
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
375
+ 'url' => '',
376
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
377
+ ), 'actions');
378
+
379
+ $this->getMassactionBlock()->addItem('assignTemplateDescriptionId', array(
380
+ 'label' => Mage::helper('M2ePro')->__('Assign'),
381
+ 'url' => '',
382
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
383
+ ), 'description_policy');
384
+
385
+ $this->getMassactionBlock()->addItem('unassignTemplateDescriptionId', array(
386
+ 'label' => Mage::helper('M2ePro')->__('Unassign'),
387
+ 'url' => '',
388
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
389
+ ), 'description_policy');
390
+
391
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
392
+ 'label' => Mage::helper('M2ePro')->__('Search Automatically'),
393
+ 'url' => '',
394
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
395
+ ), 'asin_isbn');
396
+
397
+ $this->getMassactionBlock()->addItem('newGeneralId', array(
398
+ 'label' => Mage::helper('M2ePro')->__('Assign Settings for New ASIN/ISBN'),
399
+ 'url' => '',
400
+ ), 'asin_isbn');
401
+
402
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
403
+ 'label' => Mage::helper('M2ePro')->__('Reset Information'),
404
+ 'url' => '',
405
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
406
+ ), 'asin_isbn');
407
+
408
+ $this->getMassactionBlock()->addItem('moving', array(
409
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Another Listing'),
410
+ 'url' => '',
411
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
412
+ ), 'other');
413
+
414
+ $this->getMassactionBlock()->addItem('duplicate', array(
415
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
416
+ 'url' => '',
417
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
418
+ ), 'other');
419
+ //--------------------------------
420
+
421
+ return parent::_prepareMassaction();
422
+ }
423
+
424
+ // ####################################
425
+
426
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
427
+ {
428
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
429
+
430
+ $value = '<span>'.$productTitle.'</span>';
431
+
432
+ $tempSku = $row->getData('sku');
433
+ is_null($tempSku)
434
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
435
+
436
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
437
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
438
+
439
+ $listingProductId = (int)$row->getData('id');
440
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
441
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
442
+
443
+ if ($listingProduct->getChildObject()->isExistDescriptionTemplate()) {
444
+ $value .= $this->getTemplateDescriptionLinkHtml($listingProduct);
445
+ }
446
+
447
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
448
+ return $value;
449
+ }
450
+
451
+ $generalId = $row->getData('general_id');
452
+
453
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
454
+ $amazonListingProduct = $listingProduct->getChildObject();
455
+ $variationManager = $amazonListingProduct->getVariationManager();
456
+
457
+ if ($variationManager->isRelationParentType()) {
458
+
459
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
460
+
461
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
462
+ $value .= implode(', ', $productAttributes);
463
+
464
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
465
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
466
+ Mage::helper('M2ePro')->__('Manage Magento Product Variations'))
467
+ );
468
+
469
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
470
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
471
+ );
472
+
473
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
474
+
475
+ $switchToIndividualJsMethod = <<<JS
476
+ ListingProductVariationHandlerObj
477
+ .setListingProductId({$listingProductId})
478
+ .showSwitchToIndividualModePopUp('{$popupTitle}');
479
+ JS;
480
+
481
+ if ($this->hideSwitchToIndividualConfirm) {
482
+ $switchToIndividualJsMethod = <<<JS
483
+ ListingProductVariationHandlerObj
484
+ .setListingProductId({$listingProductId})
485
+ .showManagePopup('{$popupTitle}');
486
+ JS;
487
+ }
488
+
489
+ $value .= <<<HTML
490
+ &nbsp;
491
+ <a href="javascript:"
492
+ onclick="{$switchToIndividualJsMethod}"
493
+ title="{$linkTitle}">
494
+ <img width="12" height="12" style="height: 12px; width: 12px; vertical-align: middle;" src="{$iconSettingsPath}">
495
+ </a>
496
+ HTML;
497
+ }
498
+
499
+ $value .= '</div>';
500
+
501
+ if (!empty($generalId) || $amazonListingProduct->isGeneralIdOwner()) {
502
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
503
+ $parentType = $variationManager->getTypeModel();
504
+
505
+ $linkContent = Mage::helper('M2ePro')->__('Manage Variations');
506
+ $vpmt = Mage::helper('M2ePro')->__('Manage Variations of &quot;%s&quot; ', $productTitle);
507
+ $vpmt = addslashes($vpmt);
508
+
509
+ if (!empty($generalId)) {
510
+ $vpmt .= '('. $generalId .')';
511
+ }
512
+
513
+ $problemStyle = '';
514
+ $problemIcon = '';
515
+
516
+ $linkTitle = Mage::helper('M2ePro')->__('Open Manage Variations Tool');
517
+
518
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
519
+ if (!$parentType->hasChannelTheme() || !$parentType->hasMatchedAttributes()) {
520
+
521
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
522
+ $problemStyle = 'style="font-weight: bold; color: #FF0000;" ';
523
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
524
+ $problemIcon = '<img style="vertical-align: middle;" src="'
525
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
526
+ }
527
+ } elseif (!empty($generalId)) {
528
+ if (!$parentType->hasMatchedAttributes()) {
529
+
530
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
531
+ $problemStyle = 'style="font-weight: bold;color: #FF0000;" ';
532
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
533
+ $problemIcon = '<img style="vertical-align: middle;" src="'
534
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
535
+ } elseif ($listingProduct->getChildObject()->isGeneralIdOwner() &&
536
+ !$parentType->hasChannelTheme()) {
537
+
538
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
539
+ $problemStyle = 'style="font-weight: bold;" ';
540
+ $iconPath = $this->getSkinUrl('M2ePro/images/warning.png');
541
+ $problemIcon = '<img style="vertical-align: middle;" src="'
542
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
543
+ }
544
+ }
545
+
546
+ $value .= <<<HTML
547
+ <div style="float: left; margin: 0 0 0 7px">
548
+ <a {$problemStyle}href="javascript:"
549
+ onclick="ListingGridHandlerObj.variationProductManageHandler.openPopUp({$listingProductId}, '{$vpmt}')"
550
+ title="{$linkTitle}">{$linkContent}</a>&nbsp;{$problemIcon}
551
+ </div>
552
+ HTML;
553
+ }
554
+
555
+ return $value;
556
+ }
557
+
558
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
559
+
560
+ if (!empty($productOptions)) {
561
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
562
+ foreach ($productOptions as $attribute => $option) {
563
+ !$option && $option = '--';
564
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
565
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
566
+ }
567
+ $value .= '</div>';
568
+ }
569
+
570
+ // ---------------------------------
571
+ $hasInActionLock = $this->getLockedData($row);
572
+ $hasInActionLock = $hasInActionLock['in_action'];
573
+ // ---------------------------------
574
+
575
+ if (!$hasInActionLock) {
576
+
577
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variation');
578
+ $linkTitle = Mage::helper('M2ePro')->__('Edit Variation');
579
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/pencil.png').'">';
580
+
581
+ $value .= <<<HTML
582
+ <div style="clear: both"></div>
583
+ <div style="margin: 0 0 0 7px; float: left;">
584
+ <a href="javascript:"
585
+ onclick="ListingProductVariationHandlerObj
586
+ .setListingProductId({$listingProductId})
587
+ .showEditPopup('{$popupTitle}');"
588
+ title="{$linkTitle}">{$linkContent}</a>
589
+ </div>
590
+ HTML;
591
+ }
592
+
593
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variations') ;
594
+ $linkTitle = Mage::helper('M2ePro')->__('Add Another Variation(s)');
595
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
596
+
597
+ $value.= <<<HTML
598
+ <div style="margin: 0 0 0 7px; float: left;">
599
+ <a href="javascript:"
600
+ onclick="ListingProductVariationHandlerObj
601
+ .setListingProductId({$listingProductId})
602
+ .showManagePopup('{$popupTitle}');"
603
+ title="{$linkTitle}">{$linkContent}</a>
604
+ </div>
605
+ HTML;
606
+
607
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
608
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
609
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
610
+ );
611
+
612
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
613
+
614
+ $switchToParentJsMethod = <<<JS
615
+ ListingProductVariationHandlerObj
616
+ .setListingProductId({$listingProductId})
617
+ .showSwitchToParentModePopUp('{$popupTitle}');
618
+ JS;
619
+
620
+ if ($this->hideSwitchToParentConfirm) {
621
+ $switchToParentJsMethod = <<<JS
622
+ ListingProductVariationHandlerObj
623
+ .setListingProductId({$listingProductId})
624
+ .resetListingProductVariation();
625
+ JS;
626
+ }
627
+
628
+ $value .= <<<HTML
629
+ <div style="margin: 0 0 0 7px; float: left;">
630
+ <a href="javascript:"
631
+ onclick="{$switchToParentJsMethod}"
632
+ title="{$linkTitle}">
633
+ <img width="12" height="12" src="{$iconSettingsPath}">
634
+ </a>
635
+ </div>
636
+ HTML;
637
+ }
638
+
639
+ return $value;
640
+ }
641
+
642
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
643
+ {
644
+ if (is_null($value) || $value === '') {
645
+ $value = Mage::helper('M2ePro')->__('N/A');
646
+ }
647
+
648
+ if (!$row->getData('is_variation_parent') && $row->getData('defected_messages')) {
649
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
650
+
651
+ $msg = '';
652
+ foreach ($defectedMessages as $message) {
653
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
654
+ if (!empty($message['value'])) {
655
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
656
+ }
657
+ $msg .= '</p>';
658
+ }
659
+
660
+ $value .= <<<HTML
661
+ <span style="float:right;">
662
+ <img id="map_link_defected_message_icon_{$row->getId()}"
663
+ class="tool-tip-image"
664
+ style="vertical-align: middle;"
665
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
666
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
667
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
668
+ <span>{$msg}</span>
669
+ </span>
670
+ </span>
671
+ HTML;
672
+ }
673
+
674
+ return $value;
675
+ }
676
+
677
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
678
+ {
679
+ if (empty($generalId)) {
680
+ if($row->getData('is_general_id_owner') == 1){
681
+ return $this->getGeneralIdColumnValueGeneralIdOwner($row);
682
+ }
683
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
684
+ }
685
+
686
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
687
+ }
688
+
689
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
690
+ {
691
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
692
+ $row->getData('is_variation_parent')
693
+ ) {
694
+ if (is_null($value) || $value === '') {
695
+ return Mage::helper('M2ePro')->__('N/A');
696
+ }
697
+ } else {
698
+ if (is_null($value) || $value === '') {
699
+ return '<i style="color:gray;">receiving...</i>';
700
+ }
701
+ }
702
+
703
+ if ((bool)$row->getData('is_afn_channel')) {
704
+ return '--';
705
+ }
706
+
707
+ if ($value <= 0) {
708
+ return '<span style="color: red;">0</span>';
709
+ }
710
+
711
+ return $value;
712
+ }
713
+
714
+ public function callbackColumnPrice($value, $row, $column, $isExport)
715
+ {
716
+ $onlineMinPrice = $row->getData('min_online_price');
717
+ $onlineMaxPrice = $row->getData('max_online_price');
718
+
719
+ if (is_null($onlineMinPrice) || $onlineMinPrice === '') {
720
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
721
+ $row->getData('is_variation_parent')
722
+ ) {
723
+ return Mage::helper('M2ePro')->__('N/A');
724
+ } else {
725
+ return '<i style="color:gray;">receiving...</i>';
726
+ }
727
+ }
728
+
729
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
730
+ $currency = Mage::helper('M2ePro/Component_Amazon')
731
+ ->getCachedObject('Marketplace',$marketplaceId)
732
+ ->getChildObject()
733
+ ->getDefaultCurrency();
734
+
735
+ if ($row->getData('is_variation_parent')) {
736
+ $onlineMinPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMinPrice);
737
+ $onlineMaxPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMaxPrice);
738
+
739
+ return $onlineMinPriceStr . (($onlineMinPrice != $onlineMaxPrice) ? ' - ' . $onlineMaxPriceStr : '');
740
+ }
741
+
742
+ $onlinePrice = $row->getData('online_price');
743
+ if ((float)$onlinePrice <= 0) {
744
+ $priceValue = '<span style="color: #f00;">0</span>';
745
+ } else {
746
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
747
+ }
748
+
749
+ $resultHtml = '';
750
+
751
+ $salePrice = $row->getData('online_sale_price');
752
+ if (!$row->getData('is_variation_parent') && (float)$salePrice > 0) {
753
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
754
+
755
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
756
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
757
+
758
+ if ($currentTimestamp <= $endDateTimestamp) {
759
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
760
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
761
+
762
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
763
+
764
+ $fromDate = Mage::app()->getLocale()->date(
765
+ $row->getData('online_sale_price_start_date'), $dateFormat
766
+ )->toString($dateFormat);
767
+ $toDate = Mage::app()->getLocale()->date(
768
+ $row->getData('online_sale_price_end_date'), $dateFormat
769
+ )->toString($dateFormat);
770
+
771
+ $intervalHtml = '<img class="tool-tip-image"
772
+ style="vertical-align: middle;"
773
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
774
+ text-align: left;
775
+ width: 120px;
776
+ background: #E3E3E3;">
777
+ <img src="'.$iconHelpPath.'">
778
+ <span style="color:gray;">
779
+ <strong>From:</strong> '.$fromDate.'<br/>
780
+ <strong>To:</strong> '.$toDate.'
781
+ </span>
782
+ </span>';
783
+
784
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
785
+
786
+ if ($currentTimestamp >= $startDateTimestamp &&
787
+ $currentTimestamp <= $endDateTimestamp &&
788
+ $salePrice < (float)$onlinePrice
789
+ ) {
790
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
791
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
792
+ } else {
793
+ $resultHtml .= $priceValue;
794
+ $resultHtml .= '<br/>'.$intervalHtml.
795
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
796
+ }
797
+ }
798
+ }
799
+
800
+ if (empty($resultHtml)) {
801
+ $resultHtml = $priceValue;
802
+ }
803
+
804
+ return $resultHtml;
805
+ }
806
+
807
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
808
+ {
809
+ if (is_null($value) || $value === '') {
810
+ return Mage::helper('M2ePro')->__('N/A');
811
+ }
812
+
813
+ switch ($row->getData('is_afn_channel')) {
814
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
815
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
816
+ break;
817
+
818
+ default:
819
+ break;
820
+ }
821
+
822
+ return $value;
823
+ }
824
+
825
+ public function callbackColumnStatus($value, $row, $column, $isExport)
826
+ {
827
+ $listingProductId = (int)$row->getData('id');
828
+
829
+ $html = $this->getViewLogIconHtml($listingProductId);
830
+
831
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
832
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
833
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
834
+
835
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
836
+ if (!empty($synchNote)) {
837
+
838
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
839
+
840
+ if (empty($html)) {
841
+ $html = <<<HTML
842
+ <span style="float:right;">
843
+ <img id="map_link_error_icon_{$row->getId()}"
844
+ class="tool-tip-image"
845
+ style="vertical-align: middle;"
846
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
847
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
848
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
849
+ <span>{$synchNote}</span>
850
+ </span>
851
+ </span>
852
+ HTML;
853
+ } else {
854
+ $html .= <<<HTML
855
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
856
+ HTML;
857
+ }
858
+ }
859
+
860
+ if (!$variationManager->isVariationParent()) {
861
+ return $html . $this->getProductStatus($row->getData('amazon_status')). $this->getLockedTag($row);
862
+ } else {
863
+
864
+ $generalId = $listingProduct->getGeneralId();
865
+ $variationChildStatuses = $row->getData('variation_child_statuses');
866
+ if (empty($generalId) || empty($variationChildStatuses)) {
867
+ return $html . $this->getProductStatus(Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) .
868
+ $this->getLockedTag($row);
869
+ }
870
+
871
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
872
+ $variationChildStatuses = array(
873
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED =>
874
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED],
875
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED =>
876
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_LISTED],
877
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED =>
878
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED],
879
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED =>
880
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED]
881
+ );
882
+
883
+ $linkTitle = Mage::helper('M2ePro')->__('Show all Child Products with such Status');
884
+
885
+ foreach ($variationChildStatuses as $status => $productsCount) {
886
+ if (empty($productsCount)) {
887
+ continue;
888
+ }
889
+
890
+ $filter = base64_encode('status=' . $status);
891
+
892
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
893
+ $vpmt = Mage::helper('M2ePro')->__('Manage Variations of &quot;%s&quot; ', $productTitle);
894
+ $vpmt = addslashes($vpmt);
895
+
896
+ $generalId = $row->getData('general_id');
897
+ if (!empty($generalId)) {
898
+ $vpmt .= '('. $generalId .')';
899
+ }
900
+
901
+ $productsCount = <<<HTML
902
+ <a onclick="ListingGridHandlerObj.variationProductManageHandler.openPopUp({$listingProductId}, '{$vpmt}', '{$filter}')"
903
+ class="hover-underline"
904
+ title="{$linkTitle}"
905
+ href="javascript:void(0)">[{$productsCount}]</a>
906
+ HTML;
907
+
908
+ $html .= '' . $this->getProductStatus($status) . '&nbsp;'. $productsCount . '<br/>';
909
+ }
910
+
911
+ $html .= $this->getLockedTag($row);
912
+ }
913
+
914
+ return $html;
915
+ }
916
+
917
+ private function getProductStatus($status)
918
+ {
919
+ switch ($status) {
920
+
921
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
922
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
923
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
924
+
925
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
926
+ return '<span style="color: green;">' . Mage::helper('M2ePro')->__('Active') . '</span>';
927
+
928
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
929
+ return'<span style="color: red;">' . Mage::helper('M2ePro')->__('Inactive') . '</span>';
930
+
931
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
932
+ return'<span style="color: orange; font-weight: bold;">' .
933
+ Mage::helper('M2ePro')->__('Inactive (Blocked)') . '</span>';
934
+ }
935
+
936
+ return '';
937
+ }
938
+
939
+ private function getLockedTag($row)
940
+ {
941
+ $html = '';
942
+
943
+ $tempLocks = $this->getLockedData($row);
944
+ $tempLocks = $tempLocks['object_locks'];
945
+
946
+ $childCount = 0;
947
+
948
+ foreach ($tempLocks as $lock) {
949
+
950
+ switch ($lock->getTag()) {
951
+
952
+ case 'list_action':
953
+ $html .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
954
+ break;
955
+
956
+ case 'relist_action':
957
+ $html .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
958
+ break;
959
+
960
+ case 'revise_action':
961
+ $html .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
962
+ break;
963
+
964
+ case 'stop_action':
965
+ $html .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
966
+ break;
967
+
968
+ case 'stop_and_remove_action':
969
+ $html .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
970
+ break;
971
+
972
+ case 'delete_and_remove_action':
973
+ $html .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
974
+ break;
975
+
976
+ case 'child_products_in_action':
977
+ $childCount++;
978
+ break;
979
+
980
+ default:
981
+ break;
982
+
983
+ }
984
+ }
985
+
986
+ if ($childCount > 0) {
987
+ $html .= '<br/><span style="color: #605fff">[Child(s) in Action...]</span>';
988
+ }
989
+
990
+ return $html;
991
+ }
992
+
993
+ //----------------------------------------
994
+
995
+ protected function callbackFilterTitle($collection, $column)
996
+ {
997
+ $value = $column->getFilter()->getValue();
998
+
999
+ if ($value == null) {
1000
+ return;
1001
+ }
1002
+
1003
+ $collection->addFieldToFilter(
1004
+ array(
1005
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
1006
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
1007
+ )
1008
+ );
1009
+ }
1010
+
1011
+ protected function callbackFilterPrice($collection, $column)
1012
+ {
1013
+ $value = $column->getFilter()->getValue();
1014
+
1015
+ if (empty($value)) {
1016
+ return;
1017
+ }
1018
+
1019
+ $condition = '';
1020
+
1021
+ if (!empty($value['from'])) {
1022
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
1023
+ }
1024
+ if (!empty($value['to'])) {
1025
+ if (!empty($value['from'])) {
1026
+ $condition .= ' AND ';
1027
+ }
1028
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
1029
+ }
1030
+
1031
+ $condition = '(' . $condition . ') OR (';
1032
+
1033
+ if (!empty($value['from'])) {
1034
+ $condition .= 'max_online_price >= \''.$value['from'].'\'';
1035
+ }
1036
+ if (!empty($value['to'])) {
1037
+ if (!empty($value['from'])) {
1038
+ $condition .= ' AND ';
1039
+ }
1040
+ $condition .= 'max_online_price <= \''.$value['to'].'\'';
1041
+ }
1042
+
1043
+ $condition .= ')';
1044
+
1045
+ $collection->getSelect()->having($condition);
1046
+ }
1047
+
1048
+ protected function callbackFilterStatus($collection, $column)
1049
+ {
1050
+ $value = $column->getFilter()->getValue();
1051
+
1052
+ if ($value == null) {
1053
+ return;
1054
+ }
1055
+
1056
+ $collection->getSelect()->where("lp.status = {$value} OR
1057
+ (alp.variation_child_statuses REGEXP '\"{$value}\":[^0]') AND alp.is_variation_parent = 1");
1058
+ }
1059
+
1060
+ //----------------------------------------
1061
+
1062
+ public function getViewLogIconHtml($listingProductId)
1063
+ {
1064
+ $listingProductId = (int)$listingProductId;
1065
+
1066
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
1067
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
1068
+
1069
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
1070
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1071
+
1072
+ // Get last messages
1073
+ //--------------------------
1074
+ $dbSelect = $connRead->select()
1075
+ ->from(
1076
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
1077
+ array('action_id','action','type','description','create_date','initiator','listing_product_id')
1078
+ )
1079
+ ->where('`action_id` IS NOT NULL')
1080
+ ->order(array('id DESC'))
1081
+ ->limit(30);
1082
+
1083
+ if($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
1084
+ $dbSelect->where('listing_product_id = ? OR parent_listing_product_id = ?', $listingProductId);
1085
+ } else {
1086
+ $dbSelect->where('listing_product_id = ?', $listingProductId);
1087
+ }
1088
+
1089
+ $logRows = $connRead->fetchAll($dbSelect);
1090
+ //--------------------------
1091
+
1092
+ // Get grouped messages by action_id
1093
+ //--------------------------
1094
+ $actionsRows = array();
1095
+ $tempActionRows = array();
1096
+ $lastActionId = false;
1097
+
1098
+ foreach ($logRows as $row) {
1099
+
1100
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
1101
+
1102
+ if ($row['action_id'] !== $lastActionId) {
1103
+ if (count($tempActionRows) > 0) {
1104
+ $actionsRows[] = array(
1105
+ 'action_id' => $lastActionId,
1106
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
1107
+ 'date' => $this->getMainDateForActionId($tempActionRows),
1108
+ 'action' => $this->getActionForAction($tempActionRows[0]),
1109
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
1110
+ 'items' => $tempActionRows
1111
+ );
1112
+ $tempActionRows = array();
1113
+ }
1114
+ $lastActionId = $row['action_id'];
1115
+ }
1116
+ $tempActionRows[] = $row;
1117
+ }
1118
+
1119
+ if (count($tempActionRows) > 0) {
1120
+ $actionsRows[] = array(
1121
+ 'action_id' => $lastActionId,
1122
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
1123
+ 'date' => $this->getMainDateForActionId($tempActionRows),
1124
+ 'action' => $this->getActionForAction($tempActionRows[0]),
1125
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
1126
+ 'items' => $tempActionRows
1127
+ );
1128
+ }
1129
+
1130
+ if (count($actionsRows) <= 0) {
1131
+ return '';
1132
+ }
1133
+
1134
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
1135
+ foreach ($actionsRows as &$actionsRow) {
1136
+ if (!empty($actionsRow['items']) && $actionsRow['items'][0]['listing_product_id']==$listingProductId) {
1137
+ continue;
1138
+ }
1139
+ $actionsRow['action_in_progress'] = $this->isActionInProgress($actionsRow['action_id']);
1140
+
1141
+ $descArr = array();
1142
+ foreach ($actionsRow['items'] as $key => &$item) {
1143
+ if (array_key_exists($item['description'], $descArr)) {
1144
+ $descArr[$item['description']]['count']++;
1145
+ unset($actionsRow['items'][$key]);
1146
+ continue;
1147
+ }
1148
+ $item['count'] = 1;
1149
+ $descArr[$item['description']] = $item;
1150
+ }
1151
+ $actionsRow['items'] = array_values($descArr);
1152
+ }
1153
+ }
1154
+
1155
+ foreach ($actionsRows as &$actionsRow) {
1156
+ usort($actionsRow['items'], function($a, $b)
1157
+ {
1158
+ $sortOrder = array(
1159
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
1160
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
1161
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
1162
+ );
1163
+
1164
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
1165
+ });
1166
+ }
1167
+
1168
+ $tips = array(
1169
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
1170
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
1171
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
1172
+ );
1173
+
1174
+ $icons = array(
1175
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
1176
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
1177
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
1178
+ );
1179
+
1180
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
1181
+ 'entity_id' => $listingProductId,
1182
+ 'rows' => $actionsRows,
1183
+ 'tips' => $tips,
1184
+ 'icons' => $icons,
1185
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
1186
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
1187
+ ));
1188
+
1189
+ return $summary->toHtml();
1190
+ }
1191
+
1192
+ public function getActionForAction($actionRows)
1193
+ {
1194
+ $string = '';
1195
+
1196
+ switch ($actionRows['action']) {
1197
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
1198
+ $string = Mage::helper('M2ePro')->__('List');
1199
+ break;
1200
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
1201
+ $string = Mage::helper('M2ePro')->__('Relist');
1202
+ break;
1203
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
1204
+ $string = Mage::helper('M2ePro')->__('Revise');
1205
+ break;
1206
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
1207
+ $string = Mage::helper('M2ePro')->__('Stop');
1208
+ break;
1209
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
1210
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
1211
+ break;
1212
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
1213
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
1214
+ break;
1215
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
1216
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
1217
+ break;
1218
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
1219
+ $string = Mage::helper('M2ePro')->__('Channel Change');
1220
+ break;
1221
+ }
1222
+
1223
+ return $string;
1224
+ }
1225
+
1226
+ public function getInitiatorForAction($actionRows)
1227
+ {
1228
+ $string = '';
1229
+
1230
+ switch ((int)$actionRows['initiator']) {
1231
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
1232
+ $string = '';
1233
+ break;
1234
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
1235
+ $string = Mage::helper('M2ePro')->__('Manual');
1236
+ break;
1237
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
1238
+ $string = Mage::helper('M2ePro')->__('Automatic');
1239
+ break;
1240
+ }
1241
+
1242
+ return $string;
1243
+ }
1244
+
1245
+ public function getMainTypeForActionId($actionRows)
1246
+ {
1247
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
1248
+
1249
+ foreach ($actionRows as $row) {
1250
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
1251
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
1252
+ break;
1253
+ }
1254
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
1255
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
1256
+ }
1257
+ }
1258
+
1259
+ return $type;
1260
+ }
1261
+
1262
+ public function getMainDateForActionId($actionRows)
1263
+ {
1264
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
1265
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
1266
+ }
1267
+
1268
+ public function isActionInProgress($actionId)
1269
+ {
1270
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
1271
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1272
+
1273
+ // Get last messages
1274
+ //--------------------------
1275
+ $dbSelect = $connRead->select()
1276
+ ->from(
1277
+ Mage::getResourceModel('M2ePro/Processing_Request')->getMainTable()
1278
+ )
1279
+ ->where('responser_params REGEXP \'"logs_action_id":'.$actionId.'\'');
1280
+
1281
+ $result = $connRead->fetchAll($dbSelect);
1282
+
1283
+ return !empty($result);
1284
+ }
1285
+
1286
+ // ####################################
1287
+
1288
+ public function getGridUrl()
1289
+ {
1290
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
1291
+ }
1292
+
1293
+ public function getRowUrl($row)
1294
+ {
1295
+ return false;
1296
+ }
1297
+
1298
+ // ####################################
1299
+
1300
+ protected function _getStore()
1301
+ {
1302
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
1303
+
1304
+ // Get store filter
1305
+ //----------------------------
1306
+ $storeId = $listing['store_id'];
1307
+ //----------------------------
1308
+
1309
+ return Mage::app()->getStore((int)$storeId);
1310
+ }
1311
+
1312
+ // ####################################
1313
+
1314
+ protected function _toHtml()
1315
+ {
1316
+ $javascriptsMain = <<<JAVASCRIPT
1317
+ <script type="text/javascript">
1318
+
1319
+ if (typeof ListingGridHandlerObj != 'undefined') {
1320
+ ListingGridHandlerObj.afterInitPage();
1321
+ }
1322
+
1323
+ Event.observe(window, 'load', function() {
1324
+ setTimeout(function() {
1325
+ ListingGridHandlerObj.afterInitPage();
1326
+ }, 350);
1327
+ });
1328
+
1329
+ </script>
1330
+ JAVASCRIPT;
1331
+
1332
+ return parent::_toHtml().$javascriptsMain;
1333
+ }
1334
+
1335
+ // ####################################
1336
+
1337
+ private function getLockedData($row)
1338
+ {
1339
+ $listingProductId = $row->getData('id');
1340
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1341
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($listingProductId)->getObjectLocks();
1342
+ $tempArray = array(
1343
+ 'object_locks' => $objectLocks,
1344
+ 'in_action' => !empty($objectLocks),
1345
+ );
1346
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1347
+ }
1348
+
1349
+ return $this->lockedDataCache[$listingProductId];
1350
+ }
1351
+
1352
+ // ####################################
1353
+
1354
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
1355
+ {
1356
+ // ---------------------------------
1357
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1358
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
1359
+ }
1360
+ // ---------------------------------
1361
+
1362
+ // ---------------------------------
1363
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1364
+ // ---------------------------------
1365
+
1366
+ // ---------------------------------
1367
+ $lpId = $row->getData('id');
1368
+
1369
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
1370
+ if (strlen($productTitle) > 60) {
1371
+ $productTitle = substr($productTitle, 0, 60) . '...';
1372
+ }
1373
+ $productTitle = Mage::helper('M2ePro')->__('Assign ASIN/ISBN For &quot;%product_title%&quot;', $productTitle);
1374
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
1375
+ // ---------------------------------
1376
+
1377
+ // ---------------------------------
1378
+
1379
+ $searchSettingsStatus = $row->getData('search_settings_status');
1380
+
1381
+ // ---------------------------------
1382
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
1383
+
1384
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN Search in Progress.');
1385
+ $iconSrc = $iconPath.'processing.gif';
1386
+
1387
+ return <<<HTML
1388
+ &nbsp;
1389
+ <a href="javascript: void(0);" title="{$tip}">
1390
+ <img src="{$iconSrc}" alt="">
1391
+ </a>
1392
+ HTML;
1393
+ }
1394
+ // ---------------------------------
1395
+
1396
+ // ---------------------------------
1397
+ $searchSettingsData = $row->getData('search_settings_data');
1398
+
1399
+ $suggestData = array();
1400
+ if (!is_null($searchSettingsData)) {
1401
+ $searchSettingsData = @json_decode($searchSettingsData,true);
1402
+ !empty($searchSettingsData['data']) && $suggestData = $searchSettingsData['data'];
1403
+
1404
+ }
1405
+ // ---------------------------------
1406
+
1407
+ $na = Mage::helper('M2ePro')->__('N/A');
1408
+
1409
+ if (!empty($suggestData)) {
1410
+
1411
+ $tip = Mage::helper('M2ePro')->__('Choose ASIN/ISBN from the list');
1412
+ $iconSrc = $iconPath.'list.png';
1413
+
1414
+ return <<<HTML
1415
+ {$na} &nbsp;
1416
+ <a href="javascript:;" title="{$tip}"
1417
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">
1418
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1419
+ </a>
1420
+ HTML;
1421
+ }
1422
+
1423
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND) {
1424
+
1425
+ $tip = Mage::helper('M2ePro')->__(
1426
+ 'There were no Products found on Amazon according to the Listing Search Settings.'
1427
+ );
1428
+ $tip = Mage::helper('M2ePro')->escapeJs($tip);
1429
+
1430
+ $iconSrc = $iconPath.'error.png';
1431
+
1432
+ return <<<HTML
1433
+ {$na} &nbsp;
1434
+ <a href="javascript: void(0);" title="{$tip}"
1435
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId},'{$tip}');">
1436
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1437
+ </a>
1438
+ HTML;
1439
+ }
1440
+
1441
+ $tip = Mage::helper('M2ePro')->__('Search for ASIN/ISBN');
1442
+ $iconSrc = $iconPath.'search.png';
1443
+
1444
+ return <<<HTML
1445
+ {$na} &nbsp;
1446
+ <a href="javascript:;" title="{$tip}"
1447
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId});">
1448
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1449
+ </a>
1450
+ HTML;
1451
+ }
1452
+
1453
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
1454
+ {
1455
+ $generalId = $row->getData('general_id');
1456
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
1457
+
1458
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1459
+ $generalId,
1460
+ $marketplaceId
1461
+ );
1462
+
1463
+ $generalIdOwnerHtml = '';
1464
+ if($row->getData('is_general_id_owner') == Ess_M2ePro_Model_Amazon_Listing_Product::IS_GENERAL_ID_OWNER_YES){
1465
+
1466
+ $generalIdOwnerHtml = '<br/><span style="font-size: 10px; color: grey;">'.
1467
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
1468
+ '</span>';
1469
+ }
1470
+
1471
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1472
+
1473
+ return <<<HTML
1474
+ <a href="{$url}" target="_blank">{$generalId}</a>{$generalIdOwnerHtml}
1475
+ HTML;
1476
+ }
1477
+
1478
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1479
+
1480
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
1481
+
1482
+ if (!empty($generalIdSearchInfo)) {
1483
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
1484
+ }
1485
+
1486
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
1487
+
1488
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
1489
+
1490
+ $text = <<<HTML
1491
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
1492
+ HTML;
1493
+
1494
+ } else {
1495
+
1496
+ $text = <<<HTML
1497
+ <a href="{$url}" target="_blank">{$generalId}</a>
1498
+ HTML;
1499
+
1500
+ }
1501
+
1502
+ // ---------------------------------
1503
+ $hasInActionLock = $this->getLockedData($row);
1504
+ $hasInActionLock = $hasInActionLock['in_action'];
1505
+ // ---------------------------------
1506
+
1507
+ if ($hasInActionLock) {
1508
+ return $text . $generalIdOwnerHtml;
1509
+ }
1510
+
1511
+ $listingProductId = (int)$row->getData('id');
1512
+
1513
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
1514
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
1515
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
1516
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
1517
+ $variationChildStatuses = $row->getData('variation_child_statuses');
1518
+
1519
+ if ($variationManager->isVariationParent() && !empty($variationChildStatuses)) {
1520
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
1521
+ unset($variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED]);
1522
+
1523
+ foreach ($variationChildStatuses as $variationChildStatus) {
1524
+ if (!empty($variationChildStatus)) {
1525
+ return $text . $generalIdOwnerHtml;
1526
+ }
1527
+ }
1528
+ }
1529
+
1530
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1531
+ $iconSrc = $iconPath.'unassign.png';
1532
+
1533
+ $text .= <<<HTML
1534
+ &nbsp;
1535
+ <a href="javascript:;"
1536
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$listingProductId});"
1537
+ title="{$tip}">
1538
+ <img src="{$iconSrc}" width="16" height="16"/>
1539
+ </a>{$generalIdOwnerHtml}
1540
+ HTML;
1541
+
1542
+ return $text;
1543
+ }
1544
+
1545
+ private function getGeneralIdColumnValueGeneralIdOwner($row)
1546
+ {
1547
+ $text = Mage::helper('M2ePro')->__('New ASIN/ISBN');
1548
+
1549
+ // ---------------------------------
1550
+ $hasInActionLock = $this->getLockedData($row);
1551
+ $hasInActionLock = $hasInActionLock['in_action'];
1552
+ // ---------------------------------
1553
+
1554
+ if ($hasInActionLock) {
1555
+ return $text;
1556
+ }
1557
+
1558
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1559
+
1560
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1561
+ $iconSrc = $iconPath.'unassign.png';
1562
+
1563
+ $lpId = $row->getData('id');
1564
+
1565
+ $text .= <<<HTML
1566
+ &nbsp;
1567
+ <a href="javascript:;"
1568
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$lpId});"
1569
+ title="{$tip}"><img src="{$iconSrc}" width="16" height="16"/>
1570
+ </a>
1571
+ HTML;
1572
+ return $text;
1573
+ }
1574
+
1575
+ // ####################################
1576
+
1577
+ protected function getTemplateDescriptionLinkHtml($listingProduct)
1578
+ {
1579
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
1580
+ 'id' => $listingProduct->getChildObject()->getTemplateDescriptionId()
1581
+ ));
1582
+
1583
+ $helper = Mage::helper('M2ePro');
1584
+ $templateTitle = $listingProduct->getChildObject()->getDescriptionTemplate()->getTitle();
1585
+
1586
+ return <<<HTML
1587
+ <span style="font-size: 9px;">{$helper->__('Description Policy')}:&nbsp;
1588
+ <a target="_blank" href="{$templateDescriptionEditUrl}">
1589
+ {$helper->escapeHtml($templateTitle)}</a>
1590
+ </span>
1591
+ <br/>
1592
+ HTML;
1593
+ }
1594
+
1595
+ // ####################################
1596
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Help.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('amazonListingViewHelp');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/amazon/listing/view/help.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ListingSwitcher.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+
18
+ $this->setAddListingUrl('*/adminhtml_common_listing_create/index/step/1/component/amazon/');
19
+ }
20
+
21
+ // ####################################
22
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Magento/Grid.php ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('amazonListingViewMagentoGrid'.$listingData['id']);
21
+ //------------------------------
22
+
23
+ $this->hideMassactionColumn = true;
24
+ $this->hideMassactionDropDown = true;
25
+ $this->showAdvancedFilterProductsOption = false;
26
+ }
27
+
28
+ // ####################################
29
+
30
+ public function getMainButtonsHtml()
31
+ {
32
+ $data = array(
33
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
34
+ );
35
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
36
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
37
+ );
38
+ $viewModeSwitcherBlock->addData($data);
39
+
40
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
41
+ }
42
+
43
+ // ####################################
44
+
45
+ protected function _prepareCollection()
46
+ {
47
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
48
+
49
+ // Get collection
50
+ //----------------------------
51
+ /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
52
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
53
+ Mage::getModel('catalog/product')->getResource());
54
+ $collection->getSelect()->group('e.entity_id');
55
+ $collection
56
+ ->addAttributeToSelect('name')
57
+ ->joinTable(
58
+ array('cisi' => 'cataloginventory/stock_item'),
59
+ 'product_id=entity_id',
60
+ array('qty' => 'qty',
61
+ 'is_in_stock' => 'is_in_stock'),
62
+ '{{table}}.stock_id=1',
63
+ 'left'
64
+ );
65
+
66
+ //----------------------------
67
+
68
+ $collection->joinTable(
69
+ array('lp' => 'M2ePro/Listing_Product'),
70
+ 'product_id=entity_id',
71
+ array(
72
+ 'id' => 'id',
73
+ 'amazon_status' => 'status',
74
+ 'additional_data' => 'additional_data'
75
+ ),
76
+ array(
77
+ 'listing_id' => (int)$listingData['id']
78
+ )
79
+ );
80
+ $collection->joinTable(
81
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
82
+ 'listing_product_id=id',
83
+ array(
84
+ 'general_id' => 'general_id',
85
+ 'amazon_sku' => 'sku',
86
+ 'online_qty' => 'online_qty',
87
+ 'online_price' => 'online_price',
88
+ 'online_sale_price' => 'online_sale_price',
89
+ 'is_afn_channel' => 'is_afn_channel'
90
+ ),
91
+ NULL,
92
+ 'left'
93
+ );
94
+ //----------------------------
95
+
96
+ // Set filter store
97
+ //----------------------------
98
+ $store = $this->_getStore();
99
+
100
+ if ($store->getId()) {
101
+ $collection->joinAttribute(
102
+ 'magento_price', 'catalog_product/price', 'entity_id', NULL, 'left', $store->getId()
103
+ );
104
+ $collection->joinAttribute(
105
+ 'status', 'catalog_product/status', 'entity_id', NULL, 'inner',$store->getId()
106
+ );
107
+ $collection->joinAttribute(
108
+ 'visibility', 'catalog_product/visibility', 'entity_id', NULL, 'inner',$store->getId()
109
+ );
110
+ $collection->joinAttribute(
111
+ 'thumbnail', 'catalog_product/thumbnail', 'entity_id', NULL, 'left',$store->getId()
112
+ );
113
+ } else {
114
+ $collection->addAttributeToSelect('price');
115
+ $collection->addAttributeToSelect('status');
116
+ $collection->addAttributeToSelect('visibility');
117
+ $collection->addAttributeToSelect('thumbnail');
118
+ }
119
+ //----------------------------
120
+
121
+ // exit($collection->getSelect()->__toString());
122
+
123
+ // Set collection to grid
124
+ $this->setCollection($collection);
125
+
126
+ parent::_prepareCollection();
127
+
128
+ $this->getCollection()->addWebsiteNamesToResult();
129
+
130
+ return $this;
131
+ }
132
+
133
+ protected function _prepareColumns()
134
+ {
135
+ $this->addColumn('product_id', array(
136
+ 'header' => Mage::helper('M2ePro')->__('ID'),
137
+ 'align' => 'right',
138
+ 'width' => '100px',
139
+ 'type' => 'number',
140
+ 'index' => 'entity_id',
141
+ 'filter_index' => 'entity_id',
142
+ 'frame_callback' => array($this, 'callbackColumnProductId')
143
+ ));
144
+
145
+ $this->addColumn('name', array(
146
+ 'header' => Mage::helper('M2ePro')->__('Title'),
147
+ 'align' => 'left',
148
+ //'width' => '100px',
149
+ 'type' => 'text',
150
+ 'index' => 'name',
151
+ 'filter_index' => 'name',
152
+ 'frame_callback' => array($this, 'callbackColumnProductTitle')
153
+ ));
154
+
155
+ $tempTypes = Mage::getSingleton('catalog/product_type')->getOptionArray();
156
+ unset($tempTypes['virtual']);
157
+
158
+ $this->addColumn('type', array(
159
+ 'header' => Mage::helper('M2ePro')->__('Type'),
160
+ 'align' => 'left',
161
+ 'width' => '90px',
162
+ 'type' => 'options',
163
+ 'sortable' => false,
164
+ 'index' => 'type_id',
165
+ 'filter_index' => 'type_id',
166
+ 'options' => $tempTypes
167
+ ));
168
+
169
+ $this->addColumn('is_in_stock', array(
170
+ 'header' => Mage::helper('M2ePro')->__('Stock Availability'),
171
+ 'align' => 'left',
172
+ 'width' => '90px',
173
+ 'type' => 'options',
174
+ 'sortable' => false,
175
+ 'index' => 'is_in_stock',
176
+ 'filter_index' => 'is_in_stock',
177
+ 'options' => array(
178
+ '1' => Mage::helper('M2ePro')->__('In Stock'),
179
+ '0' => Mage::helper('M2ePro')->__('Out of Stock')
180
+ ),
181
+ 'frame_callback' => array($this, 'callbackColumnIsInStock')
182
+ ));
183
+
184
+ $this->addColumn('sku', array(
185
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
186
+ 'align' => 'left',
187
+ 'width' => '90px',
188
+ 'type' => 'text',
189
+ 'index' => 'sku',
190
+ 'filter_index' => 'sku'
191
+ ));
192
+
193
+ $store = $this->_getStore();
194
+
195
+ $this->addColumn('magento_price', array(
196
+ 'header' => Mage::helper('M2ePro')->__('Price'),
197
+ 'align' => 'right',
198
+ 'width' => '100px',
199
+ 'type' => 'price',
200
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
201
+ 'index' => 'magento_price',
202
+ 'filter_index' => 'magento_price',
203
+ 'frame_callback' => array($this, 'callbackColumnPrice')
204
+ ));
205
+
206
+ $this->addColumn('qty', array(
207
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
208
+ 'align' => 'right',
209
+ 'width' => '100px',
210
+ 'type' => 'number',
211
+ 'index' => 'qty',
212
+ 'filter_index' => 'qty',
213
+ 'frame_callback' => array($this, 'callbackColumnQty')
214
+ ));
215
+
216
+ $this->addColumn('visibility', array(
217
+ 'header' => Mage::helper('M2ePro')->__('Visibility'),
218
+ 'align' => 'left',
219
+ 'width' => '90px',
220
+ 'type' => 'options',
221
+ 'sortable' => false,
222
+ 'index' => 'visibility',
223
+ 'filter_index' => 'visibility',
224
+ 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray()
225
+ ));
226
+
227
+ $this->addColumn('status', array(
228
+ 'header' => Mage::helper('M2ePro')->__('Status'),
229
+ 'align' => 'left',
230
+ 'width' => '90px',
231
+ 'type' => 'options',
232
+ 'sortable' => false,
233
+ 'index' => 'status',
234
+ 'filter_index' => 'status',
235
+ 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
236
+ 'frame_callback' => array($this, 'callbackColumnStatus')
237
+ ));
238
+
239
+ if (!Mage::app()->isSingleStoreMode()) {
240
+
241
+ $this->addColumn('websites', array(
242
+ 'header' => Mage::helper('M2ePro')->__('Websites'),
243
+ 'align' => 'left',
244
+ 'width' => '90px',
245
+ 'type' => 'options',
246
+ 'sortable' => false,
247
+ 'index' => 'websites',
248
+ 'filter_index' => 'websites',
249
+ 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash()
250
+ ));
251
+ }
252
+
253
+ return parent::_prepareColumns();
254
+ }
255
+
256
+ // ####################################
257
+
258
+ public function callbackColumnPrice($value, $row, $column, $isExport)
259
+ {
260
+ $rowVal = $row->getData();
261
+
262
+ if (!isset($rowVal['magento_price']) || (float)$rowVal['magento_price'] <= 0) {
263
+ $value = 0;
264
+ $value = '<span style="color: red;">'.$value.'</span>';
265
+ }
266
+ return $value;
267
+ }
268
+
269
+ // ####################################
270
+
271
+ public function getGridUrl()
272
+ {
273
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
274
+ }
275
+
276
+ public function getRowUrl($row)
277
+ {
278
+ return false;
279
+ }
280
+
281
+ // ####################################
282
+
283
+ protected function _addColumnFilterToCollection($column)
284
+ {
285
+ if ($this->getCollection()) {
286
+ if ($column->getId() == 'websites') {
287
+ $this->getCollection()->joinField('websites',
288
+ 'catalog/product_website',
289
+ 'website_id',
290
+ 'product_id=entity_id',
291
+ null,
292
+ 'left');
293
+ }
294
+ }
295
+ return parent::_addColumnFilterToCollection($column);
296
+ }
297
+
298
+ // ####################################
299
+
300
+ protected function _getStore()
301
+ {
302
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
303
+
304
+ // Get store filter
305
+ //----------------------------
306
+ $storeId = $listing['store_id'];
307
+ //----------------------------
308
+
309
+ return Mage::app()->getStore((int)$storeId);
310
+ }
311
+
312
+ protected function _toHtml()
313
+ {
314
+ $javascriptsMain = <<<JAVASCRIPT
315
+ <script type="text/javascript">
316
+
317
+ if (typeof ListingGridHandlerObj != 'undefined') {
318
+ ListingGridHandlerObj.afterInitPage();
319
+ }
320
+
321
+ Event.observe(window, 'load', function() {
322
+ setTimeout(function() {
323
+ ListingGridHandlerObj.afterInitPage();
324
+ }, 350);
325
+ });
326
+
327
+ </script>
328
+ JAVASCRIPT;
329
+
330
+ return parent::_toHtml().$javascriptsMain;
331
+ }
332
+
333
+ // ####################################
334
+
335
+ protected function isShowRuleBlock()
336
+ {
337
+ /** @var $ruleModel Ess_M2ePro_Model_Magento_Product_Rule */
338
+ $ruleModel = Mage::helper('M2ePro/Data_Global')->getValue('rule_model');
339
+ if ($ruleModel->isEmpty()) {
340
+ return false;
341
+ }
342
+
343
+ return parent::isShowRuleBlock();
344
+ }
345
+
346
+ // ####################################
347
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.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_View_ModeSwitcher
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_View_ModeSwitcher_Abstract
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonListingViewModeSwitcher');
19
+ //------------------------------
20
+
21
+ $this->setData('component_nick', 'amazon');
22
+ $this->setData('component_label', 'Amazon');
23
+ }
24
+
25
+ protected function getMenuItems()
26
+ {
27
+ return array(
28
+ array(
29
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_AMAZON,
30
+ 'label' => Mage::helper('M2ePro')->__($this->getComponentLabel())
31
+ ),
32
+ array(
33
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_SELLERCENTRAL,
34
+ 'label' => Mage::helper('M2ePro')->__('Seller Сentral')
35
+ ),
36
+ array(
37
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_MAGENTO,
38
+ 'label' => Mage::helper('M2ePro')->__('Magento')
39
+ )
40
+ );
41
+ }
42
+
43
+ // ####################################
44
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php ADDED
@@ -0,0 +1,1002 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
11
+
12
+ /** @var $sellingFormatTemplate Ess_M2ePro_Model_Amazon_Template_SellingFormat */
13
+ private $sellingFormatTemplate = NULL;
14
+
15
+ private $lockedDataCache = array();
16
+
17
+ private $parentAsins;
18
+
19
+ // ####################################
20
+
21
+ public function __construct()
22
+ {
23
+ parent::__construct();
24
+
25
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
26
+
27
+ // Initialization block
28
+ //------------------------------
29
+ $this->setId('amazonListingViewSellercentralGrid'.$listingData['id']);
30
+ //------------------------------
31
+
32
+ $this->showAdvancedFilterProductsOption = false;
33
+
34
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
35
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
36
+ array('template')
37
+ );
38
+ }
39
+
40
+ // ####################################
41
+
42
+ public function getMainButtonsHtml()
43
+ {
44
+ $data = array(
45
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
46
+ );
47
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
48
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
49
+ );
50
+ $viewModeSwitcherBlock->addData($data);
51
+
52
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
53
+ }
54
+
55
+ // ####################################
56
+
57
+ protected function _prepareCollection()
58
+ {
59
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
60
+
61
+ // Get collection
62
+ //----------------------------
63
+ /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
64
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
65
+ Mage::getModel('catalog/product')->getResource());
66
+ $collection
67
+ ->setListingProductModeOn()
68
+ ->addAttributeToSelect('name')
69
+ ->addAttributeToSelect('sku')
70
+ ->joinTable(
71
+ array('cisi' => 'cataloginventory/stock_item'),
72
+ 'product_id=entity_id',
73
+ array(
74
+ 'qty' => 'qty',
75
+ 'is_in_stock' => 'is_in_stock'
76
+ ),
77
+ '{{table}}.stock_id=1',
78
+ 'left'
79
+ );
80
+
81
+ //----------------------------
82
+
83
+ $collection->joinTable(
84
+ array('lp' => 'M2ePro/Listing_Product'),
85
+ 'product_id=entity_id',
86
+ array(
87
+ 'id' => 'id',
88
+ 'amazon_status' => 'status',
89
+ 'component_mode' => 'component_mode',
90
+ 'additional_data' => 'additional_data'
91
+ ),
92
+ array(
93
+ 'listing_id' => (int)$listingData['id'],
94
+ 'status' => array(
95
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED,
96
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED,
97
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED
98
+ )
99
+ )
100
+ );
101
+ $collection->joinTable(
102
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
103
+ 'listing_product_id=id',
104
+ array(
105
+ 'general_id' => 'general_id',
106
+ 'search_settings_status' => 'search_settings_status',
107
+ 'amazon_sku' => 'sku',
108
+ 'online_qty' => 'online_qty',
109
+ 'online_price' => 'online_price',
110
+ 'online_sale_price' => 'IF(
111
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
112
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
113
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
114
+ `alp`.`online_sale_price`,
115
+ NULL
116
+ )',
117
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
118
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
119
+ 'is_afn_channel' => 'is_afn_channel',
120
+ 'is_general_id_owner' => 'is_general_id_owner',
121
+ 'variation_child_statuses' => 'variation_child_statuses',
122
+ 'is_variation_parent' => 'is_variation_parent',
123
+ 'variation_parent_id' => 'variation_parent_id',
124
+ 'defected_messages' => 'defected_messages',
125
+ 'min_online_price' => 'IF(
126
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
127
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
128
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
129
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
130
+ `alp`.`online_sale_price`,
131
+ `alp`.`online_price`
132
+ )'
133
+ ),
134
+ '{{table}}.is_variation_parent = 0'
135
+ );
136
+ //----------------------------
137
+ // exit($collection->getSelect()->__toString());
138
+
139
+ // Set collection to grid
140
+ $this->setCollection($collection);
141
+
142
+ return parent::_prepareCollection();
143
+ }
144
+
145
+ protected function _prepareColumns()
146
+ {
147
+ $this->addColumn('product_id', array(
148
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
149
+ 'align' => 'right',
150
+ 'width' => '100px',
151
+ 'type' => 'number',
152
+ 'index' => 'entity_id',
153
+ 'filter_index' => 'entity_id',
154
+ 'frame_callback' => array($this, 'callbackColumnProductId')
155
+ ));
156
+
157
+ $this->addColumn('name', array(
158
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
159
+ 'align' => 'left',
160
+ //'width' => '300px',
161
+ 'type' => 'text',
162
+ 'index' => 'name',
163
+ 'filter_index' => 'name',
164
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
165
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
166
+ ));
167
+
168
+ $this->addColumn('sku', array(
169
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
170
+ 'align' => 'left',
171
+ 'width' => '150px',
172
+ 'type' => 'text',
173
+ 'index' => 'amazon_sku',
174
+ 'filter_index' => 'amazon_sku',
175
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
176
+ ));
177
+
178
+ $this->addColumn('general_id', array(
179
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
180
+ 'align' => 'left',
181
+ 'width' => '140px',
182
+ 'type' => 'text',
183
+ 'index' => 'general_id',
184
+ 'filter_index' => 'general_id',
185
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
186
+ ));
187
+
188
+ $this->addColumn('online_qty', array(
189
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
190
+ 'align' => 'right',
191
+ 'width' => '70px',
192
+ 'type' => 'number',
193
+ 'index' => 'online_qty',
194
+ 'filter_index' => 'online_qty',
195
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
196
+ ));
197
+
198
+ $this->addColumn('online_price', array(
199
+ 'header' => Mage::helper('M2ePro')->__('Price'),
200
+ 'align' => 'right',
201
+ 'width' => '70px',
202
+ 'type' => 'number',
203
+ 'index' => 'min_online_price',
204
+ 'filter_index' => 'min_online_price',
205
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
206
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
207
+ ));
208
+
209
+ $this->addColumn('is_afn_channel', array(
210
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
211
+ 'align' => 'right',
212
+ 'width' => '90px',
213
+ 'index' => 'is_afn_channel',
214
+ 'filter_index' => 'is_afn_channel',
215
+ 'type' => 'options',
216
+ 'sortable' => false,
217
+ 'options' => array(
218
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
219
+ 1 => Mage::helper('M2ePro')->__('Amazon')
220
+ ),
221
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
222
+ ));
223
+
224
+ $this->addColumn('status', array(
225
+ 'header' => Mage::helper('M2ePro')->__('Status'),
226
+ 'width' => '155px',
227
+ 'index' => 'amazon_status',
228
+ 'filter_index' => 'amazon_status',
229
+ 'type' => 'options',
230
+ 'sortable' => false,
231
+ 'options' => array(
232
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
233
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
234
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
235
+ ),
236
+ 'frame_callback' => array($this, 'callbackColumnStatus')
237
+ ));
238
+
239
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
240
+ $this->addColumn('developer_action', array(
241
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
242
+ 'align' => 'left',
243
+ 'width' => '100px',
244
+ 'type' => 'text',
245
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
246
+ 'index' => 'value',
247
+ 'filter' => false,
248
+ 'sortable' => false,
249
+ 'js_handler' => 'ListingGridHandlerObj'
250
+ ));
251
+ }
252
+
253
+ return parent::_prepareColumns();
254
+ }
255
+
256
+ protected function _prepareMassaction()
257
+ {
258
+ // Set massaction identifiers
259
+ //--------------------------------
260
+ $this->setMassactionIdField('id');
261
+ $this->setMassactionIdFieldOnlyIndexValue(true);
262
+ //--------------------------------
263
+
264
+ // Set mass-action
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
+ ));
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
+ ));
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
+ ));
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
+ ));
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
+ ));
295
+ //--------------------------------
296
+
297
+ return parent::_prepareMassaction();
298
+ }
299
+
300
+ // ####################################
301
+
302
+ public function callbackColumnProductId($value, $row, $column, $isExport)
303
+ {
304
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
305
+
306
+ $storeId = (int)$listingData['store_id'];
307
+
308
+ $withoutImageHtml = '<a href="'
309
+ .$this->getUrl('adminhtml/catalog_product/edit',
310
+ array('id' => $value))
311
+ .'" target="_blank">'.$value.'</a>';
312
+
313
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
314
+ ->getGroupValue('/view/',
315
+ 'show_products_thumbnails');
316
+ if (!$showProductsThumbnails) {
317
+ return $withoutImageHtml;
318
+ }
319
+
320
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
321
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
322
+ $magentoProduct->setProductId($value);
323
+ $magentoProduct->setStoreId($storeId);
324
+
325
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
326
+ if (is_null($imageUrlResized)) {
327
+ return $withoutImageHtml;
328
+ }
329
+
330
+ $imageHtml = $value.'<hr style="border: 1px solid silver; border-bottom: none;"><img src="'.
331
+ $imageUrlResized.'" />';
332
+ $withImageHtml = str_replace('>'.$value.'<','>'.$imageHtml.'<',$withoutImageHtml);
333
+
334
+ return $withImageHtml;
335
+ }
336
+
337
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
338
+ {
339
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
340
+
341
+ $value = '<span>'.$productTitle.'</span>';
342
+
343
+ $tempSku = $row->getData('sku');
344
+ is_null($tempSku)
345
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
346
+
347
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
348
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
349
+
350
+ $listingProduct = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'));
351
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
352
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
353
+
354
+ if (!$variationManager->isVariationProduct()) {
355
+ return $value;
356
+ }
357
+
358
+ if ($variationManager->isRelationChildType()) {
359
+ $typeModel = $variationManager->getTypeModel();
360
+
361
+ $productOptions = $typeModel->getProductOptions();
362
+ $channelOptions = $typeModel->getChannelOptions();
363
+
364
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $parentAmazonListingProduct */
365
+ $parentAmazonListingProduct = $typeModel->getParentListingProduct()->getChildObject();
366
+
367
+ $matchedAttributes = $parentAmazonListingProduct->getVariationManager()
368
+ ->getTypeModel()
369
+ ->getMatchedAttributes();
370
+
371
+ if (!empty($matchedAttributes)) {
372
+
373
+ $sortedOptions = array();
374
+
375
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
376
+ $sortedOptions[$amazonAttr] = $channelOptions[$amazonAttr];
377
+ }
378
+
379
+ $channelOptions = $sortedOptions;
380
+ }
381
+
382
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
383
+ Mage::helper('M2ePro')->__('Magento Variation') . '</div>';
384
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
385
+ foreach ($productOptions as $attribute => $option) {
386
+ !$option && $option = '--';
387
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
388
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
389
+ }
390
+ $value .= '</div>';
391
+
392
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
393
+ Mage::helper('M2ePro')->__('Amazon Variation') . '</div>';
394
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
395
+ foreach ($channelOptions as $attribute => $option) {
396
+ !$option && $option = '--';
397
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
398
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
399
+ }
400
+ $value .= '</div>';
401
+
402
+ return $value;
403
+ }
404
+
405
+ $productOptions = array();
406
+ if ($listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()) {
407
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
408
+ ->getTypeModel()->getProductOptions();
409
+ }
410
+
411
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
412
+ foreach ($productOptions as $attribute => $option) {
413
+ !$option && $option = '--';
414
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
415
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
416
+ }
417
+ $value .= '</div>';
418
+
419
+ return $value;
420
+ }
421
+
422
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
423
+ {
424
+ if (is_null($value) || $value === '') {
425
+ $value = Mage::helper('M2ePro')->__('N/A');
426
+ }
427
+
428
+ if ($row->getData('defected_messages')) {
429
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
430
+
431
+ $msg = '';
432
+ foreach ($defectedMessages as $message) {
433
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
434
+ if (!empty($message['value'])) {
435
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
436
+ }
437
+ $msg .= '</p>';
438
+ }
439
+
440
+ $value .= <<<HTML
441
+ <span style="float:right;">
442
+ <img id="map_link_defected_message_icon_{$row->getId()}"
443
+ class="tool-tip-image"
444
+ style="vertical-align: middle;"
445
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
446
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
447
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
448
+ <span>{$msg}</span>
449
+ </span>
450
+ </span>
451
+ HTML;
452
+ }
453
+
454
+ return $value;
455
+ }
456
+
457
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
458
+ {
459
+ if (is_null($value) || $value === '') {
460
+ return Mage::helper('M2ePro')->__('N/A');
461
+ }
462
+
463
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
464
+
465
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
466
+ $value,
467
+ $marketplaceId
468
+ );
469
+
470
+ $parentAsinHtml = '';
471
+ $variationParentId = $row->getData('variation_parent_id');
472
+ if(!empty($variationParentId)){
473
+ $parentAsinHtml = '<br/><span style="display: block;
474
+ margin-bottom: 5px;
475
+ font-size: 10px;
476
+ color: grey;">'.
477
+ Mage::helper('M2ePro')->__('child ASIN/ISBN<br/>of parent %parent_asin%',
478
+ $this->getParentAsin($row->getData('id'))) . '</span>';
479
+ }
480
+
481
+ $generalIdOwnerHtml = '';
482
+ if($row->getData('is_general_id_owner') == 1){
483
+ $generalIdOwnerHtml = '<span style="font-size: 10px; color: grey; display: block;">'.
484
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
485
+ '</span>';
486
+ }
487
+ return <<<HTML
488
+ <a href="{$url}" target="_blank">{$value}</a>{$parentAsinHtml}{$generalIdOwnerHtml}
489
+ HTML;
490
+ }
491
+
492
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
493
+ {
494
+ if ((int)$row->getData('is_in_stock') <= 0) {
495
+ return '<span style="color: red;">'.$value.'</span>';
496
+ }
497
+
498
+ return $value;
499
+ }
500
+
501
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
502
+ {
503
+ if ((int)$row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
504
+ if (is_null($value) || $value === '') {
505
+ return Mage::helper('M2ePro')->__('N/A');
506
+ }
507
+ } else {
508
+ if (is_null($value) || $value === '') {
509
+ return '<i style="color:gray;">receiving...</i>';
510
+ }
511
+ }
512
+
513
+ if ((bool)$row->getData('is_afn_channel')) {
514
+ return '--';
515
+ }
516
+
517
+ if ($value <= 0) {
518
+ return '<span style="color: red;">0</span>';
519
+ }
520
+
521
+ return $value;
522
+ }
523
+
524
+ public function callbackColumnPrice($value, $row, $column, $isExport)
525
+ {
526
+ $onlinePrice = $row->getData('online_price');
527
+
528
+ if (is_null($onlinePrice) || $onlinePrice === '') {
529
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
530
+ return Mage::helper('M2ePro')->__('N/A');
531
+ } else {
532
+ return '<i style="color:gray;">receiving...</i>';
533
+ }
534
+ }
535
+
536
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
537
+ $currency = Mage::helper('M2ePro/Component_Amazon')
538
+ ->getCachedObject('Marketplace',$marketplaceId)
539
+ ->getChildObject()
540
+ ->getDefaultCurrency();
541
+
542
+ if ((float)$onlinePrice <= 0) {
543
+ $priceValue = '<span style="color: #f00;">0</span>';
544
+ } else {
545
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
546
+ }
547
+
548
+ $resultHtml = '';
549
+
550
+ $salePrice = $row->getData('online_sale_price');
551
+ if ((float)$salePrice > 0) {
552
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
553
+
554
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
555
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
556
+
557
+ if ($currentTimestamp <= $endDateTimestamp) {
558
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
559
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
560
+
561
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
562
+
563
+ $fromDate = Mage::app()->getLocale()->date(
564
+ $row->getData('online_sale_price_start_date'), $dateFormat
565
+ )->toString($dateFormat);
566
+ $toDate = Mage::app()->getLocale()->date(
567
+ $row->getData('online_sale_price_end_date'), $dateFormat
568
+ )->toString($dateFormat);
569
+
570
+ $intervalHtml = '<img class="tool-tip-image"
571
+ style="vertical-align: middle;"
572
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
573
+ text-align: left;
574
+ width: 120px;
575
+ background: #E3E3E3;">
576
+ <img src="'.$iconHelpPath.'">
577
+ <span style="color:gray;">
578
+ <strong>From:</strong> '.$fromDate.'<br/>
579
+ <strong>To:</strong> '.$toDate.'
580
+ </span>
581
+ </span>';
582
+
583
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
584
+
585
+ if ($currentTimestamp >= $startDateTimestamp &&
586
+ $currentTimestamp <= $endDateTimestamp &&
587
+ $salePrice < (float)$onlinePrice
588
+ ) {
589
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
590
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
591
+ } else {
592
+ $resultHtml .= $priceValue;
593
+ $resultHtml .= '<br/>'.$intervalHtml.
594
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
595
+ }
596
+ }
597
+ }
598
+
599
+ if (empty($resultHtml)) {
600
+ $resultHtml = $priceValue;
601
+ }
602
+
603
+ return $resultHtml;
604
+ }
605
+
606
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
607
+ {
608
+ if (is_null($value) || $value === '') {
609
+ return Mage::helper('M2ePro')->__('N/A');
610
+ }
611
+
612
+ switch ($row->getData('is_afn_channel')) {
613
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
614
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
615
+ break;
616
+
617
+ default:
618
+ break;
619
+ }
620
+
621
+ return $value;
622
+ }
623
+
624
+ public function callbackColumnStatus($value, $row, $column, $isExport)
625
+ {
626
+ switch ($row->getData('amazon_status')) {
627
+
628
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
629
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
630
+ $value = '<span style="color: gray;">' . $value . '</span>';
631
+ break;
632
+
633
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
634
+ $value = '<span style="color: green;">' . $value . '</span>';
635
+ break;
636
+
637
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
638
+ $value = '<span style="color: red;">'.$value.'</span>';
639
+ break;
640
+
641
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
642
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
643
+ break;
644
+
645
+ default:
646
+ break;
647
+ }
648
+
649
+ $value .= $this->getViewLogIconHtml($row->getData('id'));
650
+
651
+ $tempLocks = $this->getLockedData($row);
652
+ $tempLocks = $tempLocks['object_locks'];
653
+
654
+ foreach ($tempLocks as $lock) {
655
+
656
+ switch ($lock->getTag()) {
657
+
658
+ case 'list_action':
659
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
660
+ break;
661
+
662
+ case 'relist_action':
663
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
664
+ break;
665
+
666
+ case 'revise_action':
667
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
668
+ break;
669
+
670
+ case 'stop_action':
671
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
672
+ break;
673
+
674
+ case 'stop_and_remove_action':
675
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
676
+ break;
677
+
678
+ case 'delete_and_remove_action':
679
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
680
+ break;
681
+
682
+ default:
683
+ break;
684
+
685
+ }
686
+ }
687
+
688
+ return $value;
689
+ }
690
+
691
+ protected function callbackFilterTitle($collection, $column)
692
+ {
693
+ $value = $column->getFilter()->getValue();
694
+
695
+ if ($value == null) {
696
+ return;
697
+ }
698
+
699
+ $collection->addFieldToFilter(
700
+ array(
701
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
702
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
703
+ )
704
+ );
705
+ }
706
+
707
+ protected function callbackFilterPrice($collection, $column)
708
+ {
709
+ $value = $column->getFilter()->getValue();
710
+
711
+ if (empty($value)) {
712
+ return;
713
+ }
714
+
715
+ $condition = '';
716
+
717
+ if (!empty($value['from'])) {
718
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
719
+ }
720
+ if (!empty($value['to'])) {
721
+ if (!empty($value['from'])) {
722
+ $condition .= ' AND ';
723
+ }
724
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
725
+ }
726
+
727
+ $collection->getSelect()->having($condition);
728
+ }
729
+
730
+ //----------------------------------------
731
+
732
+ public function getViewLogIconHtml($listingProductId)
733
+ {
734
+ $listingProductId = (int)$listingProductId;
735
+
736
+ // Get last messages
737
+ //--------------------------
738
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
739
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
740
+
741
+ $dbSelect = $connRead->select()
742
+ ->from(
743
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
744
+ array('action_id','action','type','description','create_date','initiator')
745
+ )
746
+ ->where('`listing_product_id` = ?',$listingProductId)
747
+ ->where('`action_id` IS NOT NULL')
748
+ ->order(array('id DESC'))
749
+ ->limit(30);
750
+
751
+ $logRows = $connRead->fetchAll($dbSelect);
752
+ //--------------------------
753
+
754
+ // Get grouped messages by action_id
755
+ //--------------------------
756
+ $actionsRows = array();
757
+ $tempActionRows = array();
758
+ $lastActionId = false;
759
+
760
+ foreach ($logRows as $row) {
761
+
762
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
763
+
764
+ if ($row['action_id'] !== $lastActionId) {
765
+ if (count($tempActionRows) > 0) {
766
+ $actionsRows[] = array(
767
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
768
+ 'date' => $this->getMainDateForActionId($tempActionRows),
769
+ 'action' => $this->getActionForAction($tempActionRows[0]),
770
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
771
+ 'items' => $tempActionRows
772
+ );
773
+ $tempActionRows = array();
774
+ }
775
+ $lastActionId = $row['action_id'];
776
+ }
777
+ $tempActionRows[] = $row;
778
+ }
779
+
780
+ if (count($tempActionRows) > 0) {
781
+ $actionsRows[] = array(
782
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
783
+ 'date' => $this->getMainDateForActionId($tempActionRows),
784
+ 'action' => $this->getActionForAction($tempActionRows[0]),
785
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
786
+ 'items' => $tempActionRows
787
+ );
788
+ }
789
+
790
+ if (count($actionsRows) <= 0) {
791
+ return '';
792
+ }
793
+
794
+ foreach ($actionsRows as &$actionsRow) {
795
+ usort($actionsRow['items'], function($a, $b)
796
+ {
797
+ $sortOrder = array(
798
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
799
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
800
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
801
+ );
802
+
803
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
804
+ });
805
+ }
806
+
807
+ $tips = array(
808
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
809
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
810
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
811
+ );
812
+
813
+ $icons = array(
814
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
815
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
816
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
817
+ );
818
+
819
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
820
+ 'entity_id' => $listingProductId,
821
+ 'rows' => $actionsRows,
822
+ 'tips' => $tips,
823
+ 'icons' => $icons,
824
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
825
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
826
+ ));
827
+
828
+ return $summary->toHtml();
829
+ }
830
+
831
+ public function getActionForAction($actionRows)
832
+ {
833
+ $string = '';
834
+
835
+ switch ($actionRows['action']) {
836
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
837
+ $string = Mage::helper('M2ePro')->__('List');
838
+ break;
839
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
840
+ $string = Mage::helper('M2ePro')->__('Relist');
841
+ break;
842
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
843
+ $string = Mage::helper('M2ePro')->__('Revise');
844
+ break;
845
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
846
+ $string = Mage::helper('M2ePro')->__('Stop');
847
+ break;
848
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
849
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
850
+ break;
851
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
852
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
853
+ break;
854
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
855
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
856
+ break;
857
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
858
+ $string = Mage::helper('M2ePro')->__('Channel Change');
859
+ break;
860
+ }
861
+
862
+ return $string;
863
+ }
864
+
865
+ public function getInitiatorForAction($actionRows)
866
+ {
867
+ $string = '';
868
+
869
+ switch ((int)$actionRows['initiator']) {
870
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
871
+ $string = '';
872
+ break;
873
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
874
+ $string = Mage::helper('M2ePro')->__('Manual');
875
+ break;
876
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
877
+ $string = Mage::helper('M2ePro')->__('Automatic');
878
+ break;
879
+ }
880
+
881
+ return $string;
882
+ }
883
+
884
+ public function getMainTypeForActionId($actionRows)
885
+ {
886
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
887
+
888
+ foreach ($actionRows as $row) {
889
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
890
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
891
+ break;
892
+ }
893
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
894
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
895
+ }
896
+ }
897
+
898
+ return $type;
899
+ }
900
+
901
+ public function getMainDateForActionId($actionRows)
902
+ {
903
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
904
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
905
+ }
906
+
907
+ // ####################################
908
+
909
+ public function getGridUrl()
910
+ {
911
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
912
+ }
913
+
914
+ public function getRowUrl($row)
915
+ {
916
+ return false;
917
+ }
918
+
919
+ // ####################################
920
+
921
+ protected function _toHtml()
922
+ {
923
+ $javascriptsMain = <<<JAVASCRIPT
924
+ <script type="text/javascript">
925
+
926
+ if (typeof ListingGridHandlerObj != 'undefined') {
927
+ ListingGridHandlerObj.afterInitPage();
928
+ }
929
+
930
+ Event.observe(window, 'load', function() {
931
+ setTimeout(function() {
932
+ ListingGridHandlerObj.afterInitPage();
933
+ }, 350);
934
+ });
935
+
936
+ </script>
937
+ JAVASCRIPT;
938
+
939
+ return parent::_toHtml().$javascriptsMain;
940
+ }
941
+
942
+ public function getEmptyText()
943
+ {
944
+ return Mage::helper('M2ePro')->__(
945
+ 'Only Simple and Child Products listed on Amazon will be shown in Seller Сentral View Mode.'
946
+ );
947
+ }
948
+
949
+ // ####################################
950
+
951
+ private function getLockedData($row)
952
+ {
953
+ $listingProductId = $row->getData('id');
954
+ if (!isset($this->lockedDataCache[$listingProductId])) {
955
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
956
+ $tempArray = array(
957
+ 'object_locks' => $objectLocks,
958
+ 'in_action' => !empty($objectLocks),
959
+ );
960
+ $this->lockedDataCache[$listingProductId] = $tempArray;
961
+ }
962
+
963
+ return $this->lockedDataCache[$listingProductId];
964
+ }
965
+
966
+ // ####################################
967
+
968
+ private function getParentAsin($childId)
969
+ {
970
+ if (is_null($this->parentAsins)) {
971
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
972
+ $tableAmazonListingProduct = Mage::getSingleton('core/resource')
973
+ ->getTableName('m2epro_amazon_listing_product');
974
+
975
+ $select = $connRead->select();
976
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id','variation_parent_id'))
977
+ ->where('listing_product_id IN (?)', $this->getCollection()->getAllIds())
978
+ ->where('variation_parent_id IS NOT NULL');
979
+
980
+ $parentIds = Mage::getResourceModel('core/config')
981
+ ->getReadConnection()
982
+ ->fetchPairs($select);
983
+
984
+ $select = $connRead->select();
985
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id', 'general_id'))
986
+ ->where('listing_product_id IN (?)', $parentIds);
987
+
988
+ $parentAsins = Mage::getResourceModel('core/config')
989
+ ->getReadConnection()
990
+ ->fetchPairs($select);
991
+
992
+ $this->parentAsins = array();
993
+ foreach ($parentIds as $childId => $parentId) {
994
+ $this->parentAsins[$childId] = $parentAsins[$parentId];
995
+ }
996
+ }
997
+
998
+ return $this->parentAsins[$childId];
999
+ }
1000
+
1001
+ // ####################################
1002
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Marketplace/Form.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_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
+ $idGroup = 1;
42
+
43
+ $groupsOrder = array(
44
+ 'america' => 'America',
45
+ 'europe' => 'Europe',
46
+ 'asia_pacific' => 'Asia / Pacific'
47
+ );
48
+
49
+ foreach ($groupsOrder as $key => $groupOrderTitle) {
50
+ $groups[$key] = array(
51
+ 'id' => $idGroup++,
52
+ 'title' => $groupOrderTitle,
53
+ 'marketplaces' => array()
54
+ );
55
+
56
+ foreach($marketplaces as $marketplace) {
57
+ if ($marketplace->getGroupTitle() != $groupOrderTitle) {
58
+ continue;
59
+ }
60
+
61
+ $storedStatuses[] = array(
62
+ 'marketplace_id' => $marketplace->getId(),
63
+ 'status' => $marketplace->getStatus()
64
+ );
65
+
66
+ $isLocked = (bool)Mage::helper('M2ePro/Component_Amazon')->getCollection('Account')
67
+ ->addFieldToFilter('marketplace_id', $marketplace->getId())
68
+ ->getSize();
69
+
70
+ $marketplace = array(
71
+ 'instance' => $marketplace,
72
+ 'params' => array('locked' => $isLocked)
73
+ );
74
+
75
+ $groups[$key]['marketplaces'][] = $marketplace;
76
+ }
77
+ }
78
+
79
+ $this->groups = $groups;
80
+ $this->storedStatuses = $storedStatuses;
81
+ //----------------------------
82
+
83
+ //------------------------------
84
+ $data = array(
85
+ 'label' => Mage::helper('M2ePro')->__('Update Now'),
86
+ 'onclick' => 'MarketplaceHandlerObj.runSingleSynchronization(this)',
87
+ 'class' => 'run_single_button'
88
+ );
89
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
90
+ $this->setChild('run_single_button', $buttonBlock);
91
+ //------------------------------
92
+
93
+ return parent::_beforeToHtml();
94
+ }
95
+
96
+ // ########################################
97
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonOrderEditShippingAddress');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_amazon_order_edit';
21
+ $this->_mode = 'shippingAddress';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $this->_headerText = Mage::helper('M2ePro')->__('Edit Shipping Address');
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
40
+ //------------------------------
41
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
42
+ $this->_addButton('back', array(
43
+ 'label' => Mage::helper('M2ePro')->__('Back'),
44
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
45
+ 'class' => 'back'
46
+ ));
47
+ //------------------------------
48
+ } else {
49
+ //------------------------------
50
+ $url = $this->getUrl('*/*/view', array('id' => $this->getRequest()->getParam('id')));
51
+ $this->_addButton('back', array(
52
+ 'label' => Mage::helper('M2ePro')->__('Back'),
53
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
54
+ 'class' => 'back'
55
+ ));
56
+ //------------------------------
57
+ }
58
+
59
+ //------------------------------
60
+ $this->_addButton('save', array(
61
+ 'label' => Mage::helper('M2ePro')->__('Save Order Address'),
62
+ 'onclick' => 'CommonHandlerObj.save_click()',
63
+ 'class' => 'save'
64
+ ));
65
+ //------------------------------
66
+ }
67
+
68
+ // ####################################
69
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress/Form.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('amazonOrderEditShippingAddressForm');
20
+ //------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/order/edit/shipping_address.phtml');
23
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
24
+ }
25
+
26
+ protected function _prepareForm()
27
+ {
28
+ $form = new Varien_Data_Form(array(
29
+ 'id' => 'edit_form',
30
+ 'action' => $this->getUrl('*/*/save'),
31
+ 'method' => 'post',
32
+ 'enctype' => 'multipart/form-data'
33
+ ));
34
+
35
+ $form->setUseContainer(true);
36
+ $this->setForm($form);
37
+
38
+ return parent::_prepareForm();
39
+ }
40
+
41
+ protected function _beforeToHtml()
42
+ {
43
+ try {
44
+ $regionCode = $this->order->getShippingAddress()->getRegionCode();
45
+ } catch (Exception $e) {
46
+ $regionCode = null;
47
+ }
48
+
49
+ $this->setData('countries', Mage::helper('M2ePro/Magento')->getCountries());
50
+ $this->setData('buyer_name', $this->order->getData('buyer_name'));
51
+ $this->setData('buyer_email', $this->order->getData('buyer_email'));
52
+ $this->setData('address', $this->order->getShippingAddress()->getData());
53
+ $this->setData('region_code', $regionCode);
54
+
55
+ return parent::_beforeToHtml();
56
+ }
57
+
58
+ // ####################################
59
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Grid.php ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('amazonOrderGrid');
21
+ //------------------------------
22
+
23
+ // Set default values
24
+ //------------------------------
25
+ $this->setDefaultSort('purchase_create_date');
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
+ protected function _prepareCollection()
38
+ {
39
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Order');
40
+
41
+ $collection->getSelect()
42
+ ->joinLeft(
43
+ array('so' => Mage::getSingleton('core/resource')->getTableName('sales/order')),
44
+ '(so.entity_id = `main_table`.magento_order_id)',
45
+ array('magento_order_num' => 'increment_id'));
46
+
47
+ // Add Filter By Account
48
+ //------------------------------
49
+ if ($accountId = $this->getRequest()->getParam('amazonAccount')) {
50
+ $collection->addFieldToFilter('`main_table`.account_id', $accountId);
51
+ }
52
+ //------------------------------
53
+
54
+ // Add Filter By Marketplace
55
+ //------------------------------
56
+ if ($marketplaceId = $this->getRequest()->getParam('amazonMarketplace')) {
57
+ $collection->addFieldToFilter('`main_table`.marketplace_id', $marketplaceId);
58
+ }
59
+ //------------------------------
60
+
61
+ // Add Not Created Magento Orders Filter
62
+ //------------------------------
63
+ if ($this->getRequest()->getParam('not_created_only')) {
64
+ $collection->addFieldToFilter('magento_order_id', array('null' => true));
65
+ }
66
+ //------------------------------
67
+
68
+ $this->setCollection($collection);
69
+ return parent::_prepareCollection();
70
+ }
71
+
72
+ protected function _afterLoadCollection()
73
+ {
74
+ $this->itemsCollection = Mage::helper('M2ePro/Component_Amazon')
75
+ ->getCollection('Order_Item')
76
+ ->addFieldToFilter('order_id', array('in' => $this->getCollection()->getColumnValues('id')));
77
+
78
+ return parent::_afterLoadCollection();
79
+ }
80
+
81
+ protected function _prepareColumns()
82
+ {
83
+ $this->addColumn('purchase_create_date', array(
84
+ 'header' => Mage::helper('M2ePro')->__('Sale Date'),
85
+ 'align' => 'left',
86
+ 'type' => 'datetime',
87
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
88
+ 'index' => 'purchase_create_date',
89
+ 'width' => '170px'
90
+ ));
91
+
92
+ $this->addColumn('magento_order_num', array(
93
+ 'header' => Mage::helper('M2ePro')->__('Magento Order #'),
94
+ 'align' => 'left',
95
+ 'index' => 'so.increment_id',
96
+ 'width' => '110px',
97
+ 'frame_callback' => array($this, 'callbackColumnMagentoOrder')
98
+ ));
99
+
100
+ $this->addColumn('amazon_order_id', array(
101
+ 'header' => Mage::helper('M2ePro')->__('Amazon Order #'),
102
+ 'align' => 'left',
103
+ 'width' => '110px',
104
+ 'index' => 'amazon_order_id',
105
+ 'frame_callback' => array($this, 'callbackColumnAmazonOrderId')
106
+ ));
107
+
108
+ $this->addColumn('amazon_order_items', array(
109
+ 'header' => Mage::helper('M2ePro')->__('Items'),
110
+ 'align' => 'left',
111
+ 'index' => 'amazon_order_items',
112
+ 'sortable' => false,
113
+ 'width' => '*',
114
+ 'frame_callback' => array($this, 'callbackColumnItems'),
115
+ 'filter_condition_callback' => array($this, 'callbackFilterItems')
116
+ ));
117
+
118
+ $this->addColumn('buyer', array(
119
+ 'header' => Mage::helper('M2ePro')->__('Buyer'),
120
+ 'align' => 'left',
121
+ 'index' => 'buyer_name',
122
+ 'width' => '120px',
123
+ 'frame_callback' => array($this, 'callbackColumnBuyer'),
124
+ 'filter_condition_callback' => array($this, 'callbackFilterBuyer')
125
+ ));
126
+
127
+ $this->addColumn('paid_amount', array(
128
+ 'header' => Mage::helper('M2ePro')->__('Total Paid'),
129
+ 'align' => 'left',
130
+ 'width' => '110px',
131
+ 'index' => 'paid_amount',
132
+ 'type' => 'number',
133
+ 'frame_callback' => array($this, 'callbackColumnTotal')
134
+ ));
135
+
136
+ $this->addColumn('is_afn_channel', array(
137
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
138
+ 'width' => '100px',
139
+ 'index' => 'is_afn_channel',
140
+ 'filter_index' => 'second_table.is_afn_channel',
141
+ 'type' => 'options',
142
+ 'sortable' => false,
143
+ 'options' => array(
144
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
145
+ 1 => Mage::helper('M2ePro')->__('Amazon')
146
+ ),
147
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
148
+ ));
149
+
150
+ $this->addColumn('reservation_state', array(
151
+ 'header' => Mage::helper('M2ePro')->__('Reservation'),
152
+ 'align' => 'left',
153
+ 'width' => '50px',
154
+ 'index' => 'reservation_state',
155
+ 'type' => 'options',
156
+ 'options' => array(
157
+ Ess_M2ePro_Model_Order_Reserve::STATE_UNKNOWN => Mage::helper('M2ePro')->__('Not Reserved'),
158
+ Ess_M2ePro_Model_Order_Reserve::STATE_PLACED => Mage::helper('M2ePro')->__('Reserved'),
159
+ Ess_M2ePro_Model_Order_Reserve::STATE_RELEASED => Mage::helper('M2ePro')->__('Released'),
160
+ Ess_M2ePro_Model_Order_Reserve::STATE_CANCELED => Mage::helper('M2ePro')->__('Canceled'),
161
+ )
162
+ ));
163
+
164
+ $helper = Mage::helper('M2ePro');
165
+
166
+ $this->addColumn('status', array(
167
+ 'header' => Mage::helper('M2ePro')->__('Status'),
168
+ 'align' => 'left',
169
+ 'width' => '50px',
170
+ 'index' => 'status',
171
+ 'filter_index' => 'second_table.status',
172
+ 'type' => 'options',
173
+ 'options' => array(
174
+ Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => $helper->__('Pending'),
175
+ Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED => $helper->__('Unshipped'),
176
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED_PARTIALLY => $helper->__('Partially Shipped'),
177
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => $helper->__('Shipped'),
178
+ Ess_M2ePro_Model_Amazon_Order::STATUS_INVOICE_UNCONFIRMED => $helper->__('Invoice Not Confirmed'),
179
+ Ess_M2ePro_Model_Amazon_Order::STATUS_UNFULFILLABLE => $helper->__('Unfulfillable'),
180
+ Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => $helper->__('Canceled')
181
+ ),
182
+ 'frame_callback' => array($this, 'callbackColumnStatus')
183
+ ));
184
+
185
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_order/index', array(
186
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
187
+ ));
188
+
189
+ $this->addColumn('action', array(
190
+ 'header' => Mage::helper('M2ePro')->__('Action'),
191
+ 'width' => '80px',
192
+ 'type' => 'action',
193
+ 'getter' => 'getId',
194
+ 'actions' => array(
195
+ array(
196
+ 'caption' => Mage::helper('M2ePro')->__('View'),
197
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/view'),
198
+ 'field' => 'id'
199
+ ),
200
+ array(
201
+ 'caption' => Mage::helper('M2ePro')->__('Edit Shipping Address'),
202
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/editShippingAddress/back/'.$back.'/'),
203
+ 'field' => 'id'
204
+ ),
205
+ array(
206
+ 'caption' => Mage::helper('M2ePro')->__('Create Order'),
207
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/createMagentoOrder'),
208
+ 'field' => 'id'
209
+ ),
210
+ array(
211
+ 'caption' => Mage::helper('M2ePro')->__('Mark As Shipped'),
212
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/updateShippingStatus'),
213
+ 'field' => 'id'
214
+ )
215
+ ),
216
+ 'filter' => false,
217
+ 'sortable' => false,
218
+ 'is_system' => true
219
+ ));
220
+
221
+ return parent::_prepareColumns();
222
+ }
223
+
224
+ protected function _prepareMassaction()
225
+ {
226
+ // Set massaction identifiers
227
+ //--------------------------------
228
+ $this->setMassactionIdField('main_table.id');
229
+ $this->getMassactionBlock()->setFormFieldName('ids');
230
+ //--------------------------------
231
+
232
+ // Set mass-action
233
+ //--------------------------------
234
+ $this->getMassactionBlock()->addItem('reservation_place', array(
235
+ 'label' => Mage::helper('M2ePro')->__('Reserve QTY'),
236
+ 'url' => $this->getUrl('*/adminhtml_order/reservationPlace'),
237
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
238
+ ));
239
+
240
+ $this->getMassactionBlock()->addItem('reservation_cancel', array(
241
+ 'label' => Mage::helper('M2ePro')->__('Cancel QTY Reserve'),
242
+ 'url' => $this->getUrl('*/adminhtml_order/reservationCancel'),
243
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
244
+ ));
245
+
246
+ $this->getMassactionBlock()->addItem('ship', array(
247
+ 'label' => Mage::helper('M2ePro')->__('Mark Order(s) as Shipped'),
248
+ 'url' => $this->getUrl('*/adminhtml_common_amazon_order/updateShippingStatus'),
249
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
250
+ ));
251
+
252
+ $this->getMassactionBlock()->addItem('resend_shipping', array(
253
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
254
+ 'url' => $this->getUrl('*/adminhtml_order/resubmitShippingInfo'),
255
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
256
+ ));
257
+ //--------------------------------
258
+
259
+ return parent::_prepareMassaction();
260
+ }
261
+
262
+ //##############################################################
263
+
264
+ public function callbackColumnAmazonOrderId($value, $row, $column, $isExport)
265
+ {
266
+ $orderId = Mage::helper('M2ePro')->escapeHtml($row->getData('amazon_order_id'));
267
+ $url = Mage::helper('M2ePro/Component_Amazon')->getOrderUrl($orderId, $row->getData('marketplace_id'));
268
+
269
+ return <<<HTML
270
+ <a href="{$url}" target="_blank">{$orderId}</a>
271
+ HTML;
272
+ }
273
+
274
+ public function callbackColumnMagentoOrder($value, $row, $column, $isExport)
275
+ {
276
+ $magentoOrderId = $row['magento_order_id'];
277
+ $magentoOrderNumber = Mage::helper('M2ePro')->escapeHtml($row['magento_order_num']);
278
+
279
+ $returnString = Mage::helper('M2ePro')->__('N/A');
280
+
281
+ if ($row['magento_order_id']) {
282
+ if ($row['magento_order_num']) {
283
+ $orderUrl = $this->getUrl('adminhtml/sales_order/view', array('order_id' => $magentoOrderId));
284
+ $returnString = '<a href="' . $orderUrl . '" target="_blank">' . $magentoOrderNumber . '</a>';
285
+ } else {
286
+ $returnString = '<span style="color: red;">'.Mage::helper('M2ePro')->__('Deleted').'</span>';
287
+ }
288
+ }
289
+
290
+ return $returnString.$this->getViewLogIconHtml($row->getId());
291
+ }
292
+
293
+ private function getViewLogIconHtml($orderId)
294
+ {
295
+ $orderId = (int)$orderId;
296
+
297
+ // Prepare collection
298
+ // --------------------------------
299
+ $orderLogsCollection = Mage::getModel('M2ePro/Order_Log')->getCollection()
300
+ ->addFieldToFilter('order_id', $orderId)
301
+ ->setOrder('id', 'DESC');
302
+ $orderLogsCollection->getSelect()
303
+ ->limit(3);
304
+ // --------------------------------
305
+
306
+ // Prepare logs data
307
+ // --------------------------------
308
+ if ($orderLogsCollection->count() <= 0) {
309
+ return '';
310
+ }
311
+
312
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
313
+
314
+ $logRows = array();
315
+ foreach ($orderLogsCollection as $log) {
316
+ $logRows[] = array(
317
+ 'type' => $log->getData('type'),
318
+ 'text' => Mage::helper('M2ePro/View')->getModifiedLogMessage($log->getData('message')),
319
+ 'initiator' => $this->getInitiatorForAction($log->getData('initiator')),
320
+ 'date' => Mage::app()->getLocale()->date(strtotime($log->getData('create_date')))->toString($format)
321
+ );
322
+ }
323
+ // --------------------------------
324
+
325
+ $tips = array(
326
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Order Action was completed successfully.',
327
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Order Action was completed with error(s).',
328
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Order Action was completed with warning(s).'
329
+ );
330
+
331
+ $icons = array(
332
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
333
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
334
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
335
+ );
336
+
337
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
338
+ 'entity_id' => $orderId,
339
+ 'rows' => $logRows,
340
+ 'tips' => $tips,
341
+ 'icons' => $icons,
342
+ 'view_help_handler' => 'OrderHandlerObj.viewOrderHelp',
343
+ 'hide_help_handler' => 'OrderHandlerObj.hideOrderHelp',
344
+ ));
345
+
346
+ return $summary->toHtml();
347
+ }
348
+
349
+ public function getInitiatorForAction($initiator)
350
+ {
351
+ $string = '';
352
+
353
+ switch ((int)$initiator) {
354
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
355
+ $string = '';
356
+ break;
357
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
358
+ $string = Mage::helper('M2ePro')->__('Manual');
359
+ break;
360
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
361
+ $string = Mage::helper('M2ePro')->__('Automatic');
362
+ break;
363
+ }
364
+
365
+ return $string;
366
+ }
367
+
368
+ //--------------------------------------------------------------
369
+
370
+ public function callbackColumnItems($value, $row, $column, $isExport)
371
+ {
372
+ /** @var $items Ess_M2ePro_Model_Order_Item[] */
373
+ $items = $this->itemsCollection->getItemsByColumnValue('order_id', $row->getData('id'));
374
+
375
+ $html = '';
376
+ $gridId = $this->getId();
377
+
378
+ foreach ($items as $item) {
379
+ if ($html != '') {
380
+ $html .= '<br/>';
381
+ }
382
+
383
+ $isShowEditLink = false;
384
+
385
+ $product = $item->getProduct();
386
+ if (!is_null($product)) {
387
+ /** @var Ess_M2ePro_Model_Magento_Product $magentoProduct */
388
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
389
+ $magentoProduct->setProduct($product);
390
+
391
+ $associatedProducts = $item->getAssociatedProducts();
392
+ $associatedOptions = $item->getAssociatedOptions();
393
+
394
+ if ($magentoProduct->isProductWithVariations()
395
+ && empty($associatedOptions)
396
+ && empty($associatedProducts)
397
+ ) {
398
+ $isShowEditLink = true;
399
+ }
400
+ }
401
+
402
+ $editItemHtml = '';
403
+ if ($isShowEditLink) {
404
+ $orderItemId = $item->getId();
405
+ $orderItemEditLabel = Mage::helper('M2ePro')->__('edit');
406
+
407
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
408
+
409
+ $editItemHtml = <<<HTML
410
+ <span>&nbsp;<a href="javascript:void(0);" onclick="{$js}">[{$orderItemEditLabel}]</a></span>
411
+ HTML;
412
+ }
413
+
414
+ $skuHtml = '';
415
+ if ($item->getSku()) {
416
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
417
+ $sku = Mage::helper('M2ePro')->escapeHtml($item->getSku());
418
+
419
+ $skuHtml = <<<STRING
420
+ <span style="padding-left: 10px;"><b>{$skuLabel}:</b>&nbsp;{$sku}</span><br/>
421
+ STRING;
422
+ }
423
+
424
+ $generalIdLabel = Mage::helper('M2ePro')->__($item->getIsIsbnGeneralId() ? 'ISBN' : 'ASIN');
425
+ $generalId = Mage::helper('M2ePro')->escapeHtml($item->getGeneralId());
426
+
427
+ $itemUrl = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($item->getGeneralId(),
428
+ $row->getData('marketplace_id'));
429
+
430
+ $itemLink = '<a href="'.$itemUrl.'" target="_blank">'.$generalId.'</a>';
431
+
432
+ $generalIdHtml = <<<STRING
433
+ <span style="padding-left: 10px;"><b>{$generalIdLabel}:</b>&nbsp;{$itemLink}</span><br/>
434
+ STRING;
435
+
436
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
437
+ $qtyLabel = Mage::helper('M2ePro')->__('QTY');
438
+ $qtyHtml = <<<HTML
439
+ <span style="padding-left: 10px;"><b>{$qtyLabel}:</b> {$item->getQtyPurchased()}</span>
440
+ HTML;
441
+
442
+ $html .= <<<HTML
443
+ {$itemTitle}&nbsp;{$editItemHtml}<br/>
444
+ <small>{$generalIdHtml}{$skuHtml}{$qtyHtml}</small>
445
+ HTML;
446
+ }
447
+
448
+ return $html;
449
+ }
450
+
451
+ public function callbackColumnBuyer($value, $row, $column, $isExport)
452
+ {
453
+ if ($row->getData('buyer_name') == '') {
454
+ return Mage::helper('M2ePro')->__('N/A');
455
+ }
456
+
457
+ $html = Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_name'));
458
+
459
+ if ($row->getData('buyer_email') != '') {
460
+ $html .= '<br/>';
461
+ $html .= '&lt;' . Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_email')) . '&gt;';
462
+ }
463
+
464
+ return $html;
465
+ }
466
+
467
+ public function callbackColumnTotal($value, $row, $column, $isExport)
468
+ {
469
+ $currency = $row->getData('currency');
470
+
471
+ if (empty($currency)) {
472
+ /** @var Ess_M2ePro_Model_Marketplace $marketplace */
473
+ $marketplace = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
474
+ 'Marketplace', $row->getData('marketplace_id')
475
+ );
476
+ /** @var Ess_M2ePro_Model_Amazon_Marketplace $amazonMarketplace */
477
+ $amazonMarketplace = $marketplace->getChildObject();
478
+
479
+ $currency = $amazonMarketplace->getDefaultCurrency();
480
+ }
481
+
482
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $row->getData('paid_amount'));
483
+ }
484
+
485
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
486
+ {
487
+ switch ($row->getData('is_afn_channel')) {
488
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
489
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
490
+ break;
491
+
492
+ default:
493
+ break;
494
+ }
495
+
496
+ return $value;
497
+ }
498
+
499
+ public function callbackColumnStatus($value, $row, $column, $isExport)
500
+ {
501
+ $status = $row->getData('status');
502
+
503
+ $statusColors = array(
504
+ Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => 'gray',
505
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => 'green',
506
+ Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => 'red'
507
+ );
508
+
509
+ $color = isset($statusColors[$status]) ? $statusColors[$status] : 'black';
510
+ $value = '<span style="color: '.$color.';">'.$value.'</span>';
511
+
512
+ if ($row->isLockedObject('update_order_status')) {
513
+ $value .= '<br/>';
514
+ $value .= '<span style="color: gray;">['
515
+ .Mage::helper('M2ePro')->__('Status Update in Progress...').']</span>';
516
+ }
517
+
518
+ return $value;
519
+ }
520
+
521
+ //##############################################################
522
+
523
+ protected function callbackFilterItems($collection, $column)
524
+ {
525
+ $value = $column->getFilter()->getValue();
526
+ if ($value == null) {
527
+ return;
528
+ }
529
+
530
+ $orderItemsCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Order_Item');
531
+
532
+ $orderItemsCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
533
+ $orderItemsCollection->getSelect()->columns('order_id');
534
+ $orderItemsCollection->getSelect()->distinct(true);
535
+
536
+ $orderItemsCollection->getSelect()->where('title LIKE ? OR sku LIKE ? or general_id LIKE ?', '%'.$value.'%');
537
+
538
+ $totalResult = $orderItemsCollection->getColumnValues('order_id');
539
+ $collection->addFieldToFilter('`main_table`.id', array('in' => $totalResult));
540
+ }
541
+
542
+ protected function callbackFilterBuyer($collection, $column)
543
+ {
544
+ $value = $column->getFilter()->getValue();
545
+ if ($value == null) {
546
+ return;
547
+ }
548
+
549
+ $collection
550
+ ->getSelect()
551
+ ->where('buyer_email LIKE ? OR buyer_name LIKE ?', '%'.$value.'%');
552
+ }
553
+
554
+ //##############################################################
555
+
556
+ public function getGridUrl()
557
+ {
558
+ return $this->getUrl('*/adminhtml_common_amazon_order/grid', array('_current' => true));
559
+ }
560
+
561
+ public function getRowUrl($row)
562
+ {
563
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_order/index', array(
564
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
565
+ ));
566
+
567
+ return $this->getUrl('*/adminhtml_common_amazon_order/view', array('id' => $row->getId(), 'back' => $back));
568
+ }
569
+
570
+ // ####################################
571
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('amazonOrderView');
21
+ $this->_blockGroup = 'M2ePro';
22
+ $this->_controller = 'adminhtml_common_amazon_order';
23
+ $this->_mode = 'view';
24
+ //------------------------------
25
+
26
+ // Set header text
27
+ //------------------------------
28
+ $this->_headerText = Mage::helper('M2ePro')->__('View Order Details');
29
+ //------------------------------
30
+
31
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
32
+
33
+ // Set buttons actions
34
+ //------------------------------
35
+ $this->removeButton('back');
36
+ $this->removeButton('reset');
37
+ $this->removeButton('delete');
38
+ $this->removeButton('add');
39
+ $this->removeButton('save');
40
+ $this->removeButton('edit');
41
+ //------------------------------
42
+
43
+ //------------------------------
44
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
45
+ $this->_addButton('back', array(
46
+ 'label' => Mage::helper('M2ePro')->__('Back'),
47
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
48
+ 'class' => 'back'
49
+ ));
50
+ //------------------------------
51
+
52
+ if ($this->order->getChildObject()->canUpdateShippingStatus()) {
53
+ //------------------------------
54
+ $url = $this->getUrl('*/*/updateShippingStatus', array('id' => $this->order->getId()));
55
+ $this->_addButton('update_shipping_status', array(
56
+ 'label' => Mage::helper('M2ePro')->__('Mark as Shipped'),
57
+ 'onclick' => "setLocation('".$url."');",
58
+ 'class' => 'scalable'
59
+ ));
60
+ //------------------------------
61
+ }
62
+
63
+ if ($this->order->getReserve()->isPlaced()) {
64
+ //------------------------------
65
+ $url = $this->getUrl('*/adminhtml_order/reservationCancel', array('ids' => $this->order->getId()));
66
+ $this->_addButton('reservation_cancel', array(
67
+ 'label' => Mage::helper('M2ePro')->__('Cancel QTY Reserve'),
68
+ 'onclick' => "confirmSetLocation(M2ePro.translator.translate('Are you sure?'), '".$url."');",
69
+ 'class' => 'scalable'
70
+ ));
71
+ //------------------------------
72
+ } elseif ($this->order->isReservable()) {
73
+ //------------------------------
74
+ $url = $this->getUrl('*/adminhtml_order/reservationPlace', array('ids' => $this->order->getId()));
75
+ $this->_addButton('reservation_place', array(
76
+ 'label' => Mage::helper('M2ePro')->__('Reserve QTY'),
77
+ 'onclick' => "confirmSetLocation(M2ePro.translator.translate('Are you sure?'), '".$url."');",
78
+ 'class' => 'scalable'
79
+ ));
80
+ //------------------------------
81
+ }
82
+
83
+ if (is_null($this->order->getMagentoOrderId())) {
84
+ //------------------------------
85
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId()));
86
+ $this->_addButton('order', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
88
+ 'onclick' => "setLocation('".$url."');",
89
+ 'class' => 'scalable'
90
+ ));
91
+ //------------------------------
92
+ } elseif (is_null($this->order->getMagentoOrder()) || $this->order->getMagentoOrder()->isCanceled()) {
93
+ //------------------------------
94
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId(), 'force' => 'yes'));
95
+ $confirm = Mage::helper('M2ePro')->escapeJs(
96
+ Mage::helper('M2ePro')->__('Are you sure that you want to create new Magento Order?')
97
+ );
98
+
99
+ $this->_addButton('order', array(
100
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
101
+ 'onclick' => "confirmSetLocation('".$confirm."','".$url."');",
102
+ 'class' => 'scalable'
103
+ ));
104
+ //------------------------------
105
+ }
106
+ }
107
+
108
+ // ####################################
109
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Form.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_Order_View_Form extends Ess_M2ePro_Block_Adminhtml_Widget_Container
8
+ {
9
+ public $shippingAddress = array();
10
+
11
+ public $realMagentoOrderId = NULL;
12
+
13
+ // ####################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ //------------------------------
21
+ $this->setId('amazonOrderViewForm');
22
+ $this->setTemplate('M2ePro/common/amazon/order.phtml');
23
+ //------------------------------
24
+
25
+ /** @var $order Ess_M2ePro_Model_Order */
26
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+ }
28
+
29
+ protected function _beforeToHtml()
30
+ {
31
+ // Magento order data
32
+ // ---------------
33
+ $this->realMagentoOrderId = NULL;
34
+
35
+ $magentoOrder = $this->order->getMagentoOrder();
36
+ if (!is_null($magentoOrder)) {
37
+ $this->realMagentoOrderId = $magentoOrder->getRealOrderId();
38
+ }
39
+ // ---------------
40
+
41
+ // ---------------
42
+ if (!is_null($magentoOrder) && $magentoOrder->hasShipments()) {
43
+ $url = $this->getUrl('*/adminhtml_order/resubmitShippingInfo', array('id' => $this->order->getId()));
44
+ $data = array(
45
+ 'class' => '',
46
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
47
+ 'onclick' => 'setLocation(\''.$url.'\');',
48
+ );
49
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
50
+ $this->setChild('resubmit_shipping_info', $buttonBlock);
51
+ }
52
+ // ---------------
53
+
54
+ // Shipping data
55
+ // ---------------
56
+ /** @var $shippingAddress Ess_M2ePro_Model_Amazon_Order_ShippingAddress */
57
+ $shippingAddress = $this->order->getShippingAddress();
58
+
59
+ $this->shippingAddress = $shippingAddress->getData();
60
+ $this->shippingAddress['country_name'] = $shippingAddress->getCountryName();
61
+ // ---------------
62
+
63
+ $this->setChild('item', $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_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
+
113
+ // ####################################
114
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Item.php ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /** @var $order Ess_M2ePro_Model_Order */
10
+ protected $order = null;
11
+
12
+ // ####################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('amazonOrderViewItem');
21
+ //------------------------------
22
+
23
+ // Set default values
24
+ //------------------------------
25
+ $this->setDefaultSort('id');
26
+ $this->setDefaultDir('DESC');
27
+ $this->setPagerVisibility(false);
28
+ $this->setFilterVisibility(false);
29
+ $this->setUseAjax(true);
30
+ $this->_defaultLimit = 200;
31
+ //------------------------------
32
+
33
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
34
+ }
35
+
36
+ protected function _prepareCollection()
37
+ {
38
+ $collection = Mage::helper('M2ePro/Component_Amazon')
39
+ ->getCollection('Order_Item')
40
+ ->addFieldToFilter('order_id', $this->order->getId());
41
+
42
+ $collection->getSelect()->joinLeft(
43
+ array('cisi' => Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
44
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
45
+ array('is_in_stock')
46
+ );
47
+
48
+ $this->setCollection($collection);
49
+
50
+ return parent::_prepareCollection();
51
+ }
52
+
53
+ protected function _prepareColumns()
54
+ {
55
+ $this->addColumn('product_id', array(
56
+ 'header' => Mage::helper('M2ePro')->__('Product'),
57
+ 'align' => 'left',
58
+ 'width' => '*',
59
+ 'index' => 'product_id',
60
+ 'frame_callback' => array($this, 'callbackColumnProduct')
61
+ ));
62
+
63
+ $this->addColumn('stock_availability', array(
64
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
65
+ 'width' => '100px',
66
+ 'index' => 'is_in_stock',
67
+ 'filter_index' => 'cisi.is_in_stock',
68
+ 'type' => 'options',
69
+ 'sortable' => false,
70
+ 'options' => array(
71
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
72
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
73
+ ),
74
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
75
+ ));
76
+
77
+ $this->addColumn('original_price', array(
78
+ 'header' => Mage::helper('M2ePro')->__('Original Price'),
79
+ 'align' => 'left',
80
+ 'width' => '80px',
81
+ 'filter' => false,
82
+ 'sortable' => false,
83
+ 'frame_callback' => array($this, 'callbackColumnOriginalPrice')
84
+ ));
85
+
86
+ $this->addColumn('qty_purchased', array(
87
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
88
+ 'align' => 'left',
89
+ 'width' => '80px',
90
+ 'index' => 'qty_purchased'
91
+ ));
92
+
93
+ $this->addColumn('price', array(
94
+ 'header' => Mage::helper('M2ePro')->__('Price'),
95
+ 'align' => 'left',
96
+ 'width' => '80px',
97
+ 'index' => 'price',
98
+ 'frame_callback' => array($this, 'callbackColumnPrice')
99
+ ));
100
+
101
+ $this->addColumn('discount_amount', array(
102
+ 'header' => Mage::helper('M2ePro')->__('Promotions'),
103
+ 'align' => 'left',
104
+ 'width' => '80px',
105
+ 'filter' => false,
106
+ 'sortable' => false,
107
+ 'frame_callback' => array($this, 'callbackColumnDiscountAmount')
108
+ ));
109
+
110
+ if (Mage::getResourceModel('M2ePro/Amazon_Order')->hasGifts($this->order->getId())) {
111
+ $this->addColumn('gift_price', array(
112
+ 'header' => Mage::helper('M2ePro')->__('Gift Wrap Price'),
113
+ 'align' => 'left',
114
+ 'width' => '80px',
115
+ 'index' => 'gift_price',
116
+ 'frame_callback' => array($this, 'callbackColumnGiftPrice')
117
+ ));
118
+
119
+ $this->addColumn('gift_options', array(
120
+ 'header' => Mage::helper('M2ePro')->__('Gift Options'),
121
+ 'align' => 'left',
122
+ 'width' => '250px',
123
+ 'filter' => false,
124
+ 'sortable' => false,
125
+ 'frame_callback' => array($this, 'callbackColumnGiftOptions')
126
+ ));
127
+ }
128
+
129
+ $this->addColumn('row_total', array(
130
+ 'header' => Mage::helper('M2ePro')->__('Row Total'),
131
+ 'align' => 'left',
132
+ 'width' => '80px',
133
+ 'frame_callback' => array($this, 'callbackColumnRowTotal')
134
+ ));
135
+
136
+ return parent::_prepareColumns();
137
+ }
138
+
139
+ //##############################################################
140
+
141
+ /**
142
+ * @param $value
143
+ * @param $row Ess_M2ePro_Model_Order_Item
144
+ * @param $column
145
+ * @param $isExport
146
+ *
147
+ * @return string
148
+ */
149
+ public function callbackColumnProduct($value, $row, $column, $isExport)
150
+ {
151
+ $skuHtml = '';
152
+ if ($row->getSku()) {
153
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
154
+ $sku = Mage::helper('M2ePro')->escapeHtml($row->getSku());
155
+
156
+ $skuHtml = <<<HTML
157
+ <b>{$skuLabel}:</b> {$sku}<br/>
158
+ HTML;
159
+ }
160
+
161
+ $generalIdLabel = Mage::helper('M2ePro')->__($row->getIsIsbnGeneralId() ? 'ISBN' : 'ASIN');
162
+ $generalId = Mage::helper('M2ePro')->escapeHtml($row->getGeneralId());
163
+
164
+ $generalIdHtml = <<<HTML
165
+ <b>{$generalIdLabel}:</b> {$generalId}<br/>
166
+ HTML;
167
+
168
+ if ($row->getIsIsbnGeneralId() && !Mage::helper('M2ePro')->isISBN($row->getGeneralId())) {
169
+ $amazonLink = '';
170
+ } else {
171
+ $itemLinkText = Mage::helper('M2ePro')->__('View on Amazon');
172
+ $itemUrl = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
173
+ $row->getGeneralId(), $this->order->getData('marketplace_id')
174
+ );
175
+
176
+ $amazonLink = <<<HTML
177
+ <a href="{$itemUrl}" target="_blank">{$itemLinkText}</a>
178
+ HTML;
179
+ }
180
+
181
+ $productLink = '';
182
+ if ($productId = $row->getData('product_id')) {
183
+ $productUrl = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
184
+ $productLink = ' | <a href="'.$productUrl.'" target="_blank">'.Mage::helper('M2ePro')->__('View').'</a>';
185
+ }
186
+
187
+ $orderItemId = (int)$row->getId();
188
+ $gridId = $this->getId();
189
+
190
+ $editLink = '';
191
+ if (!$row->getProductId() || $row->getMagentoProduct()->hasRequiredOptions()) {
192
+
193
+ if (!$row->getProductId()) {
194
+ $action = Mage::helper('M2ePro')->__('Map to Magento Product');
195
+ } else {
196
+ $action = Mage::helper('M2ePro')->__('Set Options');
197
+ }
198
+
199
+ $class = 'class="gray"';
200
+
201
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
202
+ $editLink = '<a href="javascript:void(0);" onclick="'.$js.'" '.$class.'>'.$action.'</a>';
203
+ }
204
+
205
+ $discardLink = '';
206
+ if ($row->getProductId()) {
207
+ $action = Mage::helper('M2ePro')->__('Unmap');
208
+
209
+ $js = "{OrderEditItemHandlerObj.unassignProduct('{$gridId}', {$orderItemId});}";
210
+ $discardLink = '<a href="javascript:void(0);" onclick="'.$js.'" class="gray">'.$action.'</a>';
211
+
212
+ if ($editLink) {
213
+ $discardLink = '&nbsp;|&nbsp;' . $discardLink;
214
+ }
215
+ }
216
+
217
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($row->getTitle());
218
+
219
+ return <<<HTML
220
+ <b>{$itemTitle}</b><br/>
221
+ <div style="padding-left: 10px;">
222
+ {$skuHtml}
223
+ {$generalIdHtml}
224
+ </div>
225
+ <div style="float: left;">{$amazonLink}{$productLink}</div>
226
+ <div style="float: right;">{$editLink}{$discardLink}</div>
227
+ HTML;
228
+ }
229
+
230
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
231
+ {
232
+ if (is_null($row->getData('is_in_stock'))) {
233
+ return Mage::helper('M2ePro')->__('N/A');
234
+ }
235
+
236
+ if ((int)$row->getData('is_in_stock') <= 0) {
237
+ return '<span style="color: red;">'.$value.'</span>';
238
+ }
239
+
240
+ return $value;
241
+ }
242
+
243
+ public function callbackColumnOriginalPrice($value, $row, $column, $isExport)
244
+ {
245
+ $productId = $row->getData('product_id');
246
+ $formattedPrice = Mage::helper('M2ePro')->__('N/A');
247
+
248
+ if ($productId && $product = Mage::getModel('catalog/product')->load($productId)) {
249
+ $formattedPrice = $product->getFormatedPrice();
250
+ }
251
+
252
+ return $formattedPrice;
253
+ }
254
+
255
+ public function callbackColumnPrice($value, $row, $column, $isExport)
256
+ {
257
+ $currency = $row->getData('currency');
258
+ if (empty($currency)) {
259
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
260
+ }
261
+
262
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $row->getData('price'));
263
+ }
264
+
265
+ public function callbackColumnGiftPrice($value, $row, $column, $isExport)
266
+ {
267
+ $currency = $row->getData('currency');
268
+ if (empty($currency)) {
269
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
270
+ }
271
+
272
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $row->getData('gift_price'));
273
+ }
274
+
275
+ public function callbackColumnDiscountAmount($value, $row, $column, $isExport)
276
+ {
277
+ $currency = $row->getData('currency');
278
+ if (empty($currency)) {
279
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
280
+ }
281
+
282
+ $discountDetails = $row->getData('discount_details');
283
+ if (empty($discountDetails)) {
284
+ Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, 0);
285
+ }
286
+
287
+ $discountDetails = @json_decode($row->getData('discount_details'), true);
288
+ if (empty($discountDetails['promotion']['value'])) {
289
+ Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, 0);
290
+ }
291
+
292
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
293
+ $currency, (int)$discountDetails['promotion']['value']
294
+ );
295
+ }
296
+
297
+ public function callbackColumnGiftOptions($value, $row, $column, $isExport)
298
+ {
299
+ if ($row->getData('gift_type') == '' && $row->getData('gift_message') == '') {
300
+ return Mage::helper('M2ePro')->__('N/A');
301
+ }
302
+
303
+ $giftType = Mage::helper('M2ePro')->escapeHtml($row->getData('gift_type'));
304
+ $giftTypeLabel = Mage::helper('M2ePro')->__('Gift Wrap Type');
305
+
306
+ $giftMessage = Mage::helper('M2ePro')->escapeHtml($row->getData('gift_message'));
307
+ $giftMessageLabel = Mage::helper('M2ePro')->__('Gift Message');
308
+
309
+ $resultHtml = '';
310
+ if (!empty($giftType)) {
311
+ $resultHtml .= "<strong>{$giftTypeLabel}: </strong>{$giftType}<br/>";
312
+ }
313
+
314
+ $resultHtml .= "<strong>{$giftMessageLabel}: </strong>{$giftMessage}";
315
+
316
+ return $resultHtml;
317
+ }
318
+
319
+ public function callbackColumnRowTotal($value, $row, $column, $isExport)
320
+ {
321
+ $currency = $row->getData('currency');
322
+ if (empty($currency)) {
323
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
324
+ }
325
+
326
+ $price = (float)$row->getData('price') + (float)$row->getData('gift_price');
327
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $price * $row->getData('qty_purchased'));
328
+ }
329
+
330
+ public function getRowUrl($row)
331
+ {
332
+ return '';
333
+ }
334
+
335
+ public function getGridUrl()
336
+ {
337
+ return $this->getUrl('*/*/orderItemGrid', array('_current' => true));
338
+ }
339
+
340
+ // ####################################
341
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Synchronization/Form.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('amazonSynchronizationForm');
20
+ $this->setContainerId('magento_block_amazon_synchronization');
21
+ $this->setTemplate('M2ePro/common/amazon/synchronization.phtml');
22
+ //------------------------------
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ //----------------------------
28
+ $this->templatesMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
29
+ ->getGroupValue('/amazon/templates/', 'mode');
30
+ //----------------------------
31
+
32
+ //----------------------------
33
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
34
+
35
+ $this->reviseAllInProcessingState = !is_null(
36
+ Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
37
+ '/amazon/templates/revise/total/', 'last_listing_product_id'
38
+ )
39
+ );
40
+
41
+ $this->reviseAllStartDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
42
+ '/amazon/templates/revise/total/', 'start_date'
43
+ );
44
+ $this->reviseAllStartDate && $this->reviseAllStartDate = Mage::app()->getLocale()
45
+ ->date(strtotime($this->reviseAllStartDate))
46
+ ->toString($format);
47
+
48
+ $this->reviseAllEndDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
49
+ '/amazon/templates/revise/total/', 'end_date'
50
+ );
51
+ $this->reviseAllEndDate && $this->reviseAllEndDate = Mage::app()->getLocale()
52
+ ->date(strtotime($this->reviseAllEndDate))
53
+ ->toString($format);
54
+ //----------------------------
55
+
56
+ //----------------------------
57
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
58
+ $data = array(
59
+ 'class' => 'ok_button',
60
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
61
+ 'onclick' => "Windows.getFocusedWindow().close(); SynchronizationHandlerObj.runReviseAll('{$component}');",
62
+ );
63
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
64
+ $this->setChild('revise_all_confirm_popup_ok_button', $buttonBlock);
65
+ //------------------------------
66
+
67
+ //-------------------------------
68
+ $this->inspectorMode = (int)Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
69
+ '/defaults/inspector/','mode'
70
+ );
71
+ //-------------------------------
72
+
73
+ return parent::_beforeToHtml();
74
+ }
75
+
76
+ // ####################################
77
+
78
+ public function isShowReviseAll()
79
+ {
80
+ return Mage::helper('M2ePro/Module')->getConfig()->getGroupValue(
81
+ '/view/synchronization/revise_total/','show'
82
+ );
83
+ }
84
+
85
+ // ####################################
86
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template.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_Template extends Ess_M2ePro_Block_Adminhtml_Common_Template
8
+ {
9
+ protected $nick = Ess_M2ePro_Helper_Component_Amazon::NICK;
10
+
11
+ // ########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('commonAmazonTemplate');
20
+ //------------------------------
21
+
22
+ }
23
+
24
+ // ########################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $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
+ $url = $this->getUrl('*/adminhtml_common_amazon_template_description/new');
39
+ $this->_addButton('add', array(
40
+ 'label' => Mage::helper('M2ePro')->__('Add Description Policy'),
41
+ 'onclick' => 'setLocation(\'' . $url .'\')',
42
+ 'class' => 'add'
43
+ ));
44
+ //------------------------------
45
+ }
46
+
47
+ // ########################################
48
+ }
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 Ess_M2ePro_Block_Adminhtml_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 Ess_M2ePro_Block_Adminhtml_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: 83.5%; 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,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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($attributeCode, $availableValues, $value = null)
97
+ {
98
+ if (empty($attributeCode) ||
99
+ Mage::helper('M2ePro/Magento_Attribute')->isExistInAttributesArray($attributeCode, $availableValues)) {
100
+ return '';
101
+ }
102
+
103
+ $attributeLabel = Mage::helper('M2ePro/Magento_Attribute')->getAttributeLabel($attributeCode);
104
+ $html = "<option %s selected=\"selected\">{$attributeLabel}</option>";
105
+
106
+ return is_null($value) ? sprintf($html, "value='{$attributeCode}'")
107
+ : sprintf($html, "attribute_code='{$attributeCode}' value='{$value}'");
108
+ }
109
+
110
+ // ------------------------------------
111
+
112
+ public function getWeightUnits()
113
+ {
114
+ return array(
115
+ 'GR',
116
+ 'KG',
117
+ 'OZ',
118
+ 'LB',
119
+ 'MG'
120
+ );
121
+ }
122
+
123
+ public function getDimensionsUnits()
124
+ {
125
+ return array(
126
+ 'MM',
127
+ 'CM',
128
+ 'M',
129
+ 'IN',
130
+ 'FT'
131
+ );
132
+ }
133
+
134
+ // ####################################
135
+ }
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,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ? OR `atd`.`browsenode_id` LIKE ? OR `main_table`.`title` LIKE ?',
205
+ '%'. $value .'%'
206
+ );
207
+ }
208
+
209
+ // ####################################
210
+
211
+ public function getGridUrl()
212
+ {
213
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/grid', array('_current'=>true));
214
+ }
215
+
216
+ public function getRowUrl($row)
217
+ {
218
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array('id' => $row->getData('id')));
219
+ }
220
+
221
+ // ####################################
222
+ }
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/Grid.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_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Template_Grid
9
+ {
10
+ protected $nick = Ess_M2ePro_Helper_Component_Amazon::NICK;
11
+
12
+ // ##########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('commonAmazonTemplateGrid');
21
+ //------------------------------
22
+ }
23
+
24
+ // ##########################################
25
+
26
+ public function getRowUrl($row)
27
+ {
28
+ return $this->getUrl(
29
+ '*/adminhtml_common_template/edit',
30
+ array(
31
+ 'id' => $row->getData('template_id'),
32
+ 'type' => $row->getData('type'),
33
+ 'back' => 1
34
+ )
35
+ );
36
+ }
37
+
38
+ // ##########################################
39
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit.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_Template_SellingFormat_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('amazonTemplateSellingFormatEdit');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_amazon_template_sellingFormat';
21
+ $this->_mode = 'edit';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $helper = Mage::helper('M2ePro');
27
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
28
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
29
+ $headerTextEdit = $helper->__("Edit %component_name% Selling Format Policy", $componentName);
30
+ $headerTextAdd = $helper->__("Add %component_name% Selling Format Policy", $componentName);
31
+ } else {
32
+ $headerTextEdit = $helper->__("Edit Selling Format Policy");
33
+ $headerTextAdd = $helper->__("Add Selling Format Policy" );
34
+ }
35
+
36
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
37
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
38
+ ) {
39
+ $this->_headerText = $headerTextEdit;
40
+ $this->_headerText .= ' "'.$this->escapeHtml(
41
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
42
+ } else {
43
+ $this->_headerText = $headerTextAdd;
44
+ }
45
+ //------------------------------
46
+
47
+ // Set buttons actions
48
+ //------------------------------
49
+ $this->removeButton('back');
50
+ $this->removeButton('reset');
51
+ $this->removeButton('delete');
52
+ $this->removeButton('add');
53
+ $this->removeButton('save');
54
+ $this->removeButton('edit');
55
+ //------------------------------
56
+
57
+ //------------------------------
58
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
59
+ $this->_addButton('back', array(
60
+ 'label' => Mage::helper('M2ePro')->__('Back'),
61
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.back_click(\'' . $url . '\')',
62
+ 'class' => 'back'
63
+ ));
64
+ //------------------------------
65
+
66
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
67
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
68
+ ) {
69
+ //------------------------------
70
+ $this->_addButton('duplicate', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
72
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.duplicate_click'
73
+ .'(\'common-amazon-template-sellingFormat\')',
74
+ 'class' => 'add M2ePro_duplicate_button'
75
+ ));
76
+ //------------------------------
77
+
78
+ //------------------------------
79
+ $this->_addButton('delete', array(
80
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
81
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.delete_click()',
82
+ 'class' => 'delete M2ePro_delete_button'
83
+ ));
84
+ //------------------------------
85
+ }
86
+
87
+ //------------------------------
88
+ $this->_addButton('save', array(
89
+ 'label' => Mage::helper('M2ePro')->__('Save'),
90
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.save_click()',
91
+ 'class' => 'save'
92
+ ));
93
+ //------------------------------
94
+
95
+ //------------------------------
96
+ $this->_addButton('save_and_continue', array(
97
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
98
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.save_and_edit_click()',
99
+ 'class' => 'save'
100
+ ));
101
+ //------------------------------
102
+ }
103
+
104
+ // ####################################
105
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit/Form.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_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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('amazonTemplateSellingFormatEditForm');
20
+ //------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/template/selling_format/form.phtml');
23
+ }
24
+
25
+ protected function _prepareForm()
26
+ {
27
+ $form = new Varien_Data_Form(array(
28
+ 'id' => 'edit_form',
29
+ 'action' => $this->getUrl('*/*/save'),
30
+ 'method' => 'post',
31
+ 'enctype' => 'multipart/form-data'
32
+ ));
33
+
34
+ $form->setUseContainer(true);
35
+ $this->setForm($form);
36
+
37
+ return parent::_prepareForm();
38
+ }
39
+
40
+ protected function _beforeToHtml()
41
+ {
42
+ //------------------------------
43
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
44
+ //------------------------------
45
+
46
+ //------------------------------
47
+ $this->setData('currencies', Mage::helper('M2ePro/Component_Amazon')->getCurrencies());
48
+ //------------------------------
49
+
50
+ //------------------------------
51
+ $this->customerGroups = Mage::getModel('customer/group')->getCollection()->toOptionArray();
52
+ //------------------------------
53
+
54
+ return parent::_beforeToHtml();
55
+ }
56
+
57
+ // ####################################
58
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit.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_Template_Synchronization_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('amazonTemplateSynchronizationEdit');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_amazon_template_synchronization';
21
+ $this->_mode = 'edit';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
27
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
28
+ $headerTextEdit = Mage::helper('M2ePro')->__(
29
+ "Edit %component_name% Synchronization Policy",
30
+ $componentName
31
+ );
32
+ $headerTextAdd = Mage::helper('M2ePro')->__(
33
+ "Add %component_name% Synchronization Policy",
34
+ $componentName);
35
+ } else {
36
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit Synchronization Policy");
37
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add Synchronization Policy");
38
+ }
39
+
40
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
41
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
42
+ ) {
43
+ $this->_headerText = $headerTextEdit;
44
+ $this->_headerText .= ' "'.$this->escapeHtml(
45
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
46
+ } else {
47
+ $this->_headerText = $headerTextAdd;
48
+ }
49
+ //------------------------------
50
+
51
+ // Set buttons actions
52
+ //------------------------------
53
+ $this->removeButton('back');
54
+ $this->removeButton('reset');
55
+ $this->removeButton('delete');
56
+ $this->removeButton('add');
57
+ $this->removeButton('save');
58
+ $this->removeButton('edit');
59
+ //------------------------------
60
+
61
+ //------------------------------
62
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
63
+ $this->_addButton('back', array(
64
+ 'label' => Mage::helper('M2ePro')->__('Back'),
65
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.back_click(\'' . $url . '\')',
66
+ 'class' => 'back'
67
+ ));
68
+ //------------------------------
69
+
70
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
71
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
72
+ ) {
73
+ //------------------------------
74
+ $this->_addButton('duplicate', array(
75
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
76
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.duplicate_click'
77
+ .'(\'common-amazon-template-synchronization\')',
78
+ 'class' => 'add M2ePro_duplicate_button'
79
+ ));
80
+ //------------------------------
81
+
82
+ //------------------------------
83
+ $this->_addButton('delete', array(
84
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
85
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.delete_click()',
86
+ 'class' => 'delete M2ePro_delete_button'
87
+ ));
88
+ //------------------------------
89
+ }
90
+
91
+ //------------------------------
92
+ $this->_addButton('save', array(
93
+ 'label' => Mage::helper('M2ePro')->__('Save'),
94
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.save_click()',
95
+ 'class' => 'save'
96
+ ));
97
+ //------------------------------
98
+
99
+ //------------------------------
100
+ $this->_addButton('save_and_continue', array(
101
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
102
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.save_and_edit_click'
103
+ .'(\'\',\'amazonTemplateSynchronizationEditTabs\')',
104
+ 'class' => 'save'
105
+ ));
106
+ //------------------------------
107
+ }
108
+
109
+ // ####################################
110
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Form.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_Template_Synchronization_Edit_Form
8
+ extends Mage_Adminhtml_Block_Widget_Form
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateSynchronizationEditForm');
19
+ //------------------------------
20
+ }
21
+
22
+ protected function _prepareForm()
23
+ {
24
+ $form = new Varien_Data_Form(array(
25
+ 'id' => 'edit_form',
26
+ 'action' => $this->getUrl('*/*/save'),
27
+ 'method' => 'post',
28
+ 'enctype' => 'multipart/form-data'
29
+ ));
30
+
31
+ $form->setUseContainer(true);
32
+ $this->setForm($form);
33
+
34
+ return parent::_prepareForm();
35
+ }
36
+
37
+ // ####################################
38
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs.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_Template_Synchronization_Edit_Tabs
8
+ extends Mage_Adminhtml_Block_Widget_Tabs
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('amazonTemplateSynchronizationEditTabs');
19
+ //------------------------------
20
+
21
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
22
+ $this->setDestElementId('edit_form');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $this->addTab('list',array(
28
+ 'label' => Mage::helper('M2ePro')->__('List Rules'),
29
+ 'title' => Mage::helper('M2ePro')->__('List Rules'),
30
+ 'content' => $this->getLayout()
31
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_list')
32
+ ->toHtml()
33
+ ));
34
+
35
+ $this->addTab('revise',array(
36
+ 'label' => Mage::helper('M2ePro')->__('Revise Rules'),
37
+ 'title' => Mage::helper('M2ePro')->__('Revise Rules'),
38
+ 'content' => $this->getLayout()
39
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_revise')
40
+ ->toHtml()
41
+ ));
42
+
43
+ $this->addTab('relist',array(
44
+ 'label' => Mage::helper('M2ePro')->__('Relist Rules'),
45
+ 'title' => Mage::helper('M2ePro')->__('Relist Rules'),
46
+ 'content' => $this->getLayout()
47
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_relist')
48
+ ->toHtml()
49
+ ));
50
+
51
+ $this->addTab('stop',array(
52
+ 'label' => Mage::helper('M2ePro')->__('Stop Rules'),
53
+ 'title' => Mage::helper('M2ePro')->__('Stop Rules'),
54
+ 'content' => $this->getLayout()
55
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_stop')
56
+ ->toHtml()
57
+ ));
58
+
59
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'list'));
60
+
61
+ return parent::_beforeToHtml();
62
+ }
63
+
64
+ // ####################################
65
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/List.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_Template_Synchronization_Edit_Tabs_List
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('amazonTemplateSynchronizationEditTabsList');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/list.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Relist.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_Template_Synchronization_Edit_Tabs_Relist
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('amazonTemplateSynchronizationEditTabsRelist');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/relist.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Revise.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_Template_Synchronization_Edit_Tabs_Revise
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('amazonTemplateSynchronizationEditTabsRevise');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/revise.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Stop.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_Template_Synchronization_Edit_Tabs_Stop
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('amazonTemplateSynchronizationEditTabsStop');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/stop.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyAccountEdit');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_account';
20
+ $this->_mode = 'edit';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
26
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
27
+ $headerTextEdit = $this->_headerText = Mage::helper('M2ePro')->__(
28
+ "Edit %component_name% Account",
29
+ $componentName
30
+ );
31
+ $headerTextAdd = $this->_headerText = Mage::helper('M2ePro')->__(
32
+ "Add %component_name% Account",
33
+ $componentName
34
+ );
35
+ } else {
36
+ $headerTextEdit = $this->_headerText = Mage::helper('M2ePro')->__("Edit Account");
37
+ $headerTextAdd = $this->_headerText = Mage::helper('M2ePro')->__("Add Account");
38
+ }
39
+
40
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
41
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
42
+ ) {
43
+ $this->_headerText = $headerTextEdit;
44
+ $this->_headerText .= ' "'.$this->escapeHtml(
45
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()
46
+ ).'"';
47
+ } else {
48
+ $this->_headerText = $headerTextAdd;
49
+ }
50
+ //------------------------------
51
+
52
+ // Set buttons actions
53
+ //------------------------------
54
+ $this->removeButton('back');
55
+ $this->removeButton('reset');
56
+ $this->removeButton('delete');
57
+ $this->removeButton('add');
58
+ $this->removeButton('save');
59
+ $this->removeButton('edit');
60
+
61
+ /* @var $wizardHelper Ess_M2ePro_Helper_Module_Wizard */
62
+ $wizardHelper = Mage::helper('M2ePro/Module_Wizard');
63
+
64
+ if ($wizardHelper->isActive('buy') &&
65
+ $wizardHelper->getStep('buy') == 'account'
66
+ ) {
67
+
68
+ //------------------------------
69
+ $this->_addButton('save_and_continue', array(
70
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
71
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
72
+ 'class' => 'save'
73
+ ));
74
+ //------------------------------
75
+
76
+ if ($this->getRequest()->getParam('id')) {
77
+ //------------------------------
78
+ $url = $this->getUrl('*/adminhtml_common_buy_account/new', array('wizard' => true));
79
+ $this->_addButton('add_new_account', array(
80
+ 'label' => Mage::helper('M2ePro')->__('Add New Account'),
81
+ 'onclick' => 'setLocation(\''. $url .'\')',
82
+ 'class' => 'add_new_account'
83
+ ));
84
+ //------------------------------
85
+
86
+ //------------------------------
87
+ $this->_addButton('close', array(
88
+ 'label' => Mage::helper('M2ePro')->__('Complete This Step'),
89
+ 'onclick' => 'BuyAccountHandlerObj.completeStep();',
90
+ 'class' => 'close'
91
+ ));
92
+ //------------------------------
93
+ }
94
+ } else {
95
+
96
+ if ((bool)$this->getRequest()->getParam('close_on_save',false)) {
97
+
98
+ if ($this->getRequest()->getParam('id')) {
99
+ $this->_addButton('save', array(
100
+ 'label' => Mage::helper('M2ePro')->__('Save And Close'),
101
+ 'onclick' => 'BuyAccountHandlerObj.saveAndClose()',
102
+ 'class' => 'save'
103
+ ));
104
+ } else {
105
+ $this->_addButton('save_and_continue', array(
106
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
107
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
108
+ 'class' => 'save'
109
+ ));
110
+ }
111
+ return;
112
+ }
113
+
114
+ //------------------------------
115
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
116
+ $this->_addButton('back', array(
117
+ 'label' => Mage::helper('M2ePro')->__('Back'),
118
+ 'onclick' => 'BuyAccountHandlerObj.back_click(\'' . $url .'\')',
119
+ 'class' => 'back'
120
+ ));
121
+ //------------------------------
122
+
123
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
124
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
125
+ ) {
126
+ //------------------------------
127
+ $this->_addButton('delete', array(
128
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
129
+ 'onclick' => 'BuyAccountHandlerObj.delete_click()',
130
+ 'class' => 'delete M2ePro_delete_button'
131
+ ));
132
+ //------------------------------
133
+ }
134
+
135
+ //------------------------------
136
+ $this->_addButton('save', array(
137
+ 'label' => Mage::helper('M2ePro')->__('Save'),
138
+ 'onclick' => 'BuyAccountHandlerObj.save_click()',
139
+ 'class' => 'save'
140
+ ));
141
+ //------------------------------
142
+
143
+ //------------------------------
144
+ $this->_addButton('save_and_continue', array(
145
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
146
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
147
+ 'class' => 'save'
148
+ ));
149
+ //------------------------------
150
+ }
151
+ }
152
+
153
+ // ####################################
154
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Form.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_Buy_Account_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('buyAccountEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareForm()
22
+ {
23
+ $form = new Varien_Data_Form(array(
24
+ 'id' => 'edit_form',
25
+ 'action' => $this->getUrl('*/*/save'),
26
+ 'method' => 'post',
27
+ 'enctype' => 'multipart/form-data'
28
+ ));
29
+
30
+ $form->setUseContainer(true);
31
+ $this->setForm($form);
32
+
33
+ return parent::_prepareForm();
34
+ }
35
+
36
+ // ####################################
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/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_Account_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('buyAccountEditTabs');
18
+ //------------------------------
19
+
20
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
21
+ $this->setDestElementId('edit_form');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ $this->addTab('general', array(
27
+ 'label' => Mage::helper('M2ePro')->__('General'),
28
+ 'title' => Mage::helper('M2ePro')->__('General'),
29
+ 'content' => $this->getLayout()
30
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_general')
31
+ ->toHtml(),
32
+ ));
33
+
34
+ $this->addTab('listingOther', array(
35
+ 'label' => Mage::helper('M2ePro')->__('3rd Party Listings'),
36
+ 'title' => Mage::helper('M2ePro')->__('3rd Party Listings'),
37
+ 'content' => $this->getLayout()
38
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_listingOther')
39
+ ->toHtml(),
40
+ ));
41
+
42
+ $this->addTab('orders', array(
43
+ 'label' => Mage::helper('M2ePro')->__('Orders'),
44
+ 'title' => Mage::helper('M2ePro')->__('Orders'),
45
+ 'content' => $this->getLayout()
46
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_order')
47
+ ->toHtml(),
48
+ ));
49
+
50
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
51
+
52
+ return parent::_beforeToHtml();
53
+ }
54
+
55
+ // ####################################
56
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/General.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyAccountEditTabsGeneral');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/account/tabs/general.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
26
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
27
+ ) {
28
+
29
+ /** @var $accountObj Ess_M2ePro_Model_Account */
30
+ $accountObj = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
31
+
32
+ $this->synchronizeProcessing = $accountObj->isLockedObject('server_synchronize');
33
+
34
+ if (!$this->synchronizeProcessing) {
35
+ $accountId = $accountObj->getId();
36
+
37
+ Mage::helper('M2ePro/Data_Global')->unsetValue('temp_data');
38
+ Mage::helper('M2ePro/Data_Global')->setValue(
39
+ 'temp_data',
40
+ Mage::helper('M2ePro/Component_Buy')->getCachedObject('Account',$accountId)
41
+ );
42
+ }
43
+ } else {
44
+ $this->synchronizeProcessing = false;
45
+ }
46
+
47
+ $marketplaces = Mage::helper('M2ePro/Component_Buy')->getCollection('Marketplace')
48
+ ->addFieldToFilter('status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
49
+
50
+ $this->marketplace = true;
51
+ if ($marketplaces->getSize() <= 0) {
52
+ $this->marketplace = false;
53
+ }
54
+ //var_dump($this->marketplace); exit();
55
+
56
+ //------------------------------
57
+ $data = array(
58
+ 'label' => Mage::helper('M2ePro')->__('Update FTP Password'),
59
+ 'onclick' => 'BuyAccountHandlerObj.update_password(\'ftp\')',
60
+ 'class' => 'scalable'
61
+ );
62
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
63
+ $this->setChild('buy_update_ftp_password', $buttonBlock);
64
+ //------------------------------
65
+
66
+ //------------------------------
67
+ $data = array(
68
+ 'label' => Mage::helper('M2ePro')->__('Update Web Password'),
69
+ 'onclick' => 'BuyAccountHandlerObj.update_password(\'web\')',
70
+ 'class' => 'scalable'
71
+ );
72
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
73
+ $this->setChild('buy_update_web_password', $buttonBlock);
74
+ //------------------------------
75
+
76
+ return parent::_beforeToHtml();
77
+ }
78
+
79
+ // ####################################
80
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/ListingOther.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyAccountEditTabsListingOther');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/account/tabs/listing_other.phtml');
21
+ }
22
+
23
+ protected function _beforeToHtml()
24
+ {
25
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
26
+
27
+ return parent::_beforeToHtml();
28
+ }
29
+
30
+ // ####################################
31
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/Order.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('buyAccountEditTabsOrder');
20
+ //------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/buy/account/tabs/order.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
28
+ $magentoOrdersSettings = !empty($data['magento_orders_settings'])
29
+ ? json_decode($data['magento_orders_settings'], true) : array();
30
+
31
+ //----------------------------
32
+ $temp = Mage::getModel('core/website')->getCollection()->setOrder('sort_order','ASC')->toArray();
33
+ $this->websites = $temp['items'];
34
+ //----------------------------
35
+
36
+ //----------------------------
37
+ $temp = Mage::getModel('customer/group')->getCollection()->toArray();
38
+ $this->groups = $temp['items'];
39
+ //----------------------------
40
+
41
+ //----------------------------
42
+ $selectedStore = !empty($magentoOrdersSettings['listing']['store_id'])
43
+ ? $magentoOrdersSettings['listing']['store_id'] : '';
44
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
45
+ 'id' => 'magento_orders_listings_store_id',
46
+ 'name' => 'magento_orders_settings[listing][store_id]',
47
+ 'selected' => $selectedStore
48
+ ));
49
+ $blockStoreSwitcher->hasDefaultOption(false);
50
+ $this->setChild('magento_orders_listings_store_id', $blockStoreSwitcher);
51
+ //----------------------------
52
+
53
+ //----------------------------
54
+ $selectedStore = !empty($magentoOrdersSettings['listing_other']['store_id'])
55
+ ? $magentoOrdersSettings['listing_other']['store_id'] : '';
56
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
57
+ 'id' => 'magento_orders_listings_other_store_id',
58
+ 'name' => 'magento_orders_settings[listing_other][store_id]',
59
+ 'selected' => $selectedStore
60
+ ));
61
+ $blockStoreSwitcher->hasDefaultOption(false);
62
+ $this->setChild('magento_orders_listings_other_store_id', $blockStoreSwitcher);
63
+ //----------------------------
64
+
65
+ //----------------------------
66
+ $productTaxClasses = Mage::getModel('tax/class')->getCollection()
67
+ ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)
68
+ ->toOptionArray();
69
+
70
+ $none = array('value' => Ess_M2ePro_Model_Magento_Product::TAX_CLASS_ID_NONE, 'label' => 'None');
71
+ array_unshift($productTaxClasses, $none);
72
+
73
+ $this->productTaxClasses = $productTaxClasses;
74
+ //----------------------------
75
+
76
+ return parent::_beforeToHtml();
77
+ }
78
+
79
+ public function getMagentoOrderStatusList()
80
+ {
81
+ if (is_null($this->_possibleMagentoStatuses)) {
82
+ $this->_possibleMagentoStatuses = Mage::getSingleton('sales/order_config')->getStatuses();
83
+ }
84
+
85
+ return $this->_possibleMagentoStatuses;
86
+ }
87
+
88
+ // ####################################
89
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing.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_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
+ $this->setTemplate('M2ePro/widget/grid/container/only_content.phtml');
38
+ }
39
+
40
+ // ####################################
41
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Form.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
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->setId('buyListingEditForm');
20
+ //------------------------------
21
+ }
22
+
23
+ // ########################################
24
+ }
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,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'sku_modification_mode' => Ess_M2ePro_Model_Buy_Listing::SKU_MODIFICATION_MODE_NONE,
55
+ 'sku_modification_custom_value' => '',
56
+ 'generate_sku_mode' => Ess_M2ePro_Model_Buy_Listing::GENERATE_SKU_MODE_NO,
57
+
58
+ 'template_selling_format_id' => '',
59
+ 'template_synchronization_id' => '',
60
+
61
+ 'shipping_standard_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
62
+ 'shipping_standard_value' => 0,
63
+ 'shipping_standard_custom_attribute' => '',
64
+
65
+ 'shipping_expedited_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
66
+ 'shipping_expedited_value' => 0,
67
+ 'shipping_expedited_custom_attribute' => '',
68
+
69
+ 'shipping_two_day_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
70
+ 'shipping_two_day_value' => 0,
71
+ 'shipping_two_day_custom_attribute' => '',
72
+
73
+ 'shipping_one_day_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
74
+ 'shipping_one_day_value' => 0,
75
+ 'shipping_one_day_custom_attribute' => '',
76
+
77
+ 'condition_mode' => Ess_M2ePro_Model_Buy_Listing::CONDITION_MODE_DEFAULT,
78
+ 'condition_value' => Ess_M2ePro_Model_Buy_Listing::CONDITION_NEW,
79
+ 'condition_custom_attribute' => '',
80
+ 'condition_note_mode' => Ess_M2ePro_Model_Buy_Listing::CONDITION_NOTE_MODE_NONE,
81
+ 'condition_note_value' => ''
82
+ );
83
+ }
84
+
85
+ // ####################################
86
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ // ####################################
13
+ }
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,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ // ####################################
13
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Group/Grid.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_Buy_Listing_AutoAction_Mode_Category_Group_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Group_Grid
9
+ {
10
+ // ####################################
11
+
12
+ public function getGridUrl()
13
+ {
14
+ return $this->getUrl('*/adminhtml_common_listing_autoAction/getCategoryGroupGrid', array('_current' => true));
15
+ }
16
+
17
+ // ####################################
18
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Global.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ // ####################################
13
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Website.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ // ####################################
13
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingEdit');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_listing';
20
+ $this->_mode = 'edit';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
26
+
27
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
28
+ $headerText = Mage::helper('M2ePro')->__(
29
+ 'Edit %component_name% Listing Settings "%listing_title%"',
30
+ Mage::helper('M2ePro/Component_Buy')->getTitle(),
31
+ $this->escapeHtml($listingData['title'])
32
+ );
33
+ } else {
34
+ $headerText =Mage::helper('M2ePro')->__(
35
+ 'Edit Listing Settings "%listing_title%"',
36
+ $this->escapeHtml($listingData['title'])
37
+ );
38
+ }
39
+
40
+ $this->_headerText = $headerText;
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
54
+ //------------------------------
55
+ $url = Mage::helper('M2ePro')->getBackUrl(
56
+ '*/adminhtml_common_listing/index',
57
+ array(
58
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
59
+ )
60
+ );
61
+ $this->_addButton('back', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Back'),
63
+ 'onclick' => 'CommonListingSettingsHandlerObj.back_click(\''.$url.'\')',
64
+ 'class' => 'back'
65
+ ));
66
+ //------------------------------
67
+ }
68
+
69
+ //------------------------------
70
+ $this->_addButton('auto_action', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
72
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
73
+ ));
74
+ //------------------------------
75
+
76
+ $backUrl = Mage::helper('M2ePro')->getBackUrlParam('list');
77
+
78
+ //------------------------------
79
+ $url = $this->getUrl(
80
+ '*/adminhtml_common_buy_listing/save',
81
+ array(
82
+ 'id' => $listingData['id'],
83
+ 'back' => Mage::helper('M2ePro')->getBackUrlParam('list')
84
+ )
85
+ );
86
+ $this->_addButton('save', array(
87
+ 'label' => Mage::helper('M2ePro')->__('Save'),
88
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_click(\'' . $url . '\')',
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' => 'CommonListingSettingsHandlerObj.save_and_edit_click(\''.$url.'\', 1)',
97
+ 'class' => 'save'
98
+ ));
99
+ //------------------------------
100
+ }
101
+
102
+ // ####################################
103
+
104
+ protected function _beforeToHtml()
105
+ {
106
+ parent::_beforeToHtml();
107
+
108
+ //------------------------------
109
+ $tabs = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_edit_tabs');
110
+ $this->setChild('tabs', $tabs);
111
+ //------------------------------
112
+
113
+ return $this;
114
+ }
115
+
116
+ // ####################################
117
+
118
+ public function getFormHtml()
119
+ {
120
+ $listing = Mage::helper('M2ePro/Component_Buy')->getCachedObject(
121
+ 'Listing', $this->getRequest()->getParam('id')
122
+ );
123
+
124
+ $viewHeaderBlock = $this->getLayout()->createBlock(
125
+ 'M2ePro/adminhtml_listing_view_header','',
126
+ array('listing' => $listing)
127
+ );
128
+
129
+ $tabs = $this->getChild('tabs');
130
+
131
+ $urls = Mage::helper('M2ePro')->getControllerActions(
132
+ 'adminhtml_common_listing_autoAction',
133
+ array(
134
+ 'listing_id' => $this->getRequest()->getParam('id'),
135
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK
136
+ )
137
+ );
138
+ $urls = json_encode($urls);
139
+
140
+ /** @var $helper Ess_M2ePro_Helper_Data */
141
+ $helper = Mage::helper('M2ePro');
142
+
143
+ $translations = json_encode(array(
144
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
145
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
146
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
147
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
148
+ ));
149
+
150
+ $js = <<<HTML
151
+ <script type="text/javascript">
152
+
153
+ M2ePro.url.add({$urls});
154
+ M2ePro.translator.add({$translations});
155
+
156
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
157
+
158
+ </script>
159
+ HTML;
160
+
161
+ return $viewHeaderBlock->toHtml() . $tabs->toHtml() . parent::getFormHtml() . $js;
162
+ }
163
+
164
+ // ####################################
165
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Form.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_Buy_Listing_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('buyListingEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareForm()
22
+ {
23
+ $form = new Varien_Data_Form(array(
24
+ 'id' => 'edit_form',
25
+ 'action' => $this->getUrl('*/adminhtml_common_buy_listing/save'),
26
+ 'method' => 'post',
27
+ 'enctype' => 'multipart/form-data'
28
+ ));
29
+
30
+ $form->setUseContainer(true);
31
+ $this->setForm($form);
32
+
33
+ return parent::_prepareForm();
34
+ }
35
+
36
+ // ####################################
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Tabs.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingEditTabs');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('widget/tabshoriz.phtml');
21
+ $this->setDestElementId('edit_form');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ $this->addTab('selling', array(
27
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
28
+ 'title' => Mage::helper('M2ePro')->__('Selling Settings'),
29
+ 'content' => $this->getLayout()
30
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_add_tabs_selling')
31
+ ->toHtml(),
32
+ ));
33
+
34
+ $this->addTab('search', array(
35
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
36
+ 'title' => Mage::helper('M2ePro')->__('Search Settings'),
37
+ 'content' => $this->getLayout()
38
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_add_tabs_search')
39
+ ->toHtml(),
40
+ ));
41
+
42
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'selling'));
43
+
44
+ return parent::_beforeToHtml();
45
+ }
46
+
47
+ // ####################################
48
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/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_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_ManageListings::TAB_ID_LISTING,
80
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
81
+ )
82
+ );
83
+
84
+ $this->getMassactionBlock()->addItem('clear_logs', array(
85
+ 'label' => Mage::helper('M2ePro')->__('Clear Log(s)'),
86
+ 'url' => $this->getUrl('*/adminhtml_listing/clearLog', array('back' => $backUrl)),
87
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
88
+ ));
89
+ //--------------------------------
90
+
91
+ // Set remove listings action
92
+ //--------------------------------
93
+ $this->getMassactionBlock()->addItem('delete_listings', array(
94
+ 'label' => Mage::helper('M2ePro')->__('Delete Listing(s)'),
95
+ 'url' => $this->getUrl('*/adminhtml_common_buy_listing/delete', array('back' => $backUrl)),
96
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
97
+ ));
98
+ //--------------------------------
99
+
100
+ return parent::_prepareMassaction();
101
+ }
102
+
103
+ // ####################################
104
+
105
+ protected function getColumnActionsItems()
106
+ {
107
+ $helper = Mage::helper('M2ePro');
108
+ $backUrl = $helper->makeBackUrlParam(
109
+ '*/adminhtml_common_listing/index',
110
+ array(
111
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
112
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
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_buy_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_Buy::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_Buy::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_buy_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::CHANNEL_ID_BUY
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' => $helper->__('Are you sure?'),
199
+ 'group' => 'other',
200
+ 'field' => 'id',
201
+ 'url' => array(
202
+ 'base' => '*/adminhtml_common_buy_listing/delete',
203
+ 'params' => array(
204
+ 'back' => $backUrl
205
+ )
206
+ )
207
+ ),
208
+
209
+ 'editListingTitle' => array(
210
+ 'caption' => $helper->__('Title'),
211
+ 'group' => 'edit_actions',
212
+ 'confirm' => $helper->__('Are you sure?'),
213
+ 'field' => 'id',
214
+ 'onclick_action' => 'editListingTitle'
215
+ ),
216
+
217
+ 'sellingSetting' => array(
218
+ 'caption' => $helper->__('Selling'),
219
+ 'group' => 'edit_actions',
220
+ 'field' => 'id',
221
+ 'url' => array(
222
+ 'base' => '*/adminhtml_common_buy_listing/edit',
223
+ 'params' => array(
224
+ 'back' => $backUrl,
225
+ 'tab' => 'selling'
226
+ )
227
+ )
228
+ ),
229
+
230
+ 'searchSetting' => array(
231
+ 'caption' => $helper->__('Search'),
232
+ 'group' => 'edit_actions',
233
+ 'field' => 'id',
234
+ 'url' => array(
235
+ 'base' => '*/adminhtml_common_buy_listing/edit',
236
+ 'params' => array(
237
+ 'back' => $backUrl,
238
+ 'tab' => 'search'
239
+ )
240
+ )
241
+ )
242
+ );
243
+
244
+ return $actions;
245
+ }
246
+
247
+ // ####################################
248
+
249
+ public function callbackColumnSoldProducts($value, $row, $column, $isExport)
250
+ {
251
+ return $this->getColumnValue($value);
252
+ }
253
+
254
+ public function callbackColumnTitle($value, $row, $column, $isExport)
255
+ {
256
+ $value = '<span id="listing_title_'.$row->getId().'">' .
257
+ Mage::helper('M2ePro')->escapeHtml($value) .
258
+ '</span>';
259
+
260
+ /* @var $row Ess_M2ePro_Model_Listing */
261
+ $accountTitle = $row->getData('account_title');
262
+
263
+ $storeModel = Mage::getModel('core/store')->load($row->getStoreId());
264
+ $storeView = $storeModel->getWebsite()->getName();
265
+ if (strtolower($storeView) != 'admin') {
266
+ $storeView .= ' > '.$storeModel->getGroup()->getName();
267
+ $storeView .= ' > '.$storeModel->getName();
268
+ } else {
269
+ $storeView = Mage::helper('M2ePro')->__('Admin (Default Values)');
270
+ }
271
+
272
+ $account = Mage::helper('M2ePro')->__('Account');
273
+ $store = Mage::helper('M2ePro')->__('Magento Store View');
274
+
275
+ $value .= <<<HTML
276
+ <div>
277
+ <span style="font-weight: bold">{$account}</span>: <span style="color: #505050">{$accountTitle}</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
+ $collection->getSelect()->where('main_table.title LIKE ? OR a.title LIKE ?','%'. $value .'%');
296
+ }
297
+
298
+ // ####################################
299
+
300
+ public function getGridUrl()
301
+ {
302
+ return $this->getUrl('*/adminhtml_common_buy_listing/listingGrid', array('_current'=>true));
303
+ }
304
+
305
+ public function getRowUrl($row)
306
+ {
307
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
308
+ '*/adminhtml_common_listing/index',
309
+ array(
310
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
311
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
312
+ )
313
+ );
314
+
315
+ return $this->getUrl(
316
+ '*/adminhtml_common_buy_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/Buy/Listing/Other/Grid.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2011 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Other_Grid
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setId('buyListingOtherGrid');
17
+ }
18
+
19
+ // ####################################
20
+
21
+ protected function _prepareCollection()
22
+ {
23
+ $this->prepareCacheData();
24
+
25
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
26
+ $collection->getSelect()->group(array('account_id','marketplace_id'));
27
+
28
+ // exit($collection->getSelect()->__toString());
29
+
30
+ // Set collection to grid
31
+ $this->setCollection($collection);
32
+
33
+ return parent::_prepareCollection();
34
+ }
35
+
36
+ // ####################################
37
+
38
+ public function getRowUrl($row)
39
+ {
40
+ return $this->getUrl('*/adminhtml_common_buy_listing_other/view', array(
41
+ 'account' => $row->getData('account_id'),
42
+ 'back'=>Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_listing/index', array(
43
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING_OTHER,
44
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Other::TAB_ID_BUY
45
+ ))
46
+ ));
47
+ }
48
+
49
+ // ####################################
50
+
51
+ protected function prepareCacheData()
52
+ {
53
+ $this->cacheData = array();
54
+
55
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
56
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
57
+ $collection->getSelect()->columns(
58
+ array('account_id', 'status')
59
+ );
60
+
61
+ /* @var $item Ess_M2ePro_Model_Listing_Other */
62
+ foreach ($collection->getItems() as $item) {
63
+
64
+ $accountId = $item->getAccountId();
65
+ $key = $accountId;
66
+
67
+ empty($this->cacheData[$key]) && ($this->cacheData[$key] = array(
68
+ 'total_items' => 0,
69
+ 'active_items' => 0,
70
+ 'inactive_items' => 0
71
+ ));
72
+
73
+ ++$this->cacheData[$key]['total_items'];
74
+
75
+ if ($item->getStatus() == Ess_M2ePro_Model_Listing_Product::STATUS_LISTED) {
76
+ ++$this->cacheData[$key]['active_items'];
77
+ } else {
78
+ ++$this->cacheData[$key]['inactive_items'];
79
+ }
80
+ }
81
+
82
+ }
83
+
84
+ // ####################################
85
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View.php ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_View extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+ // ####################################
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+
11
+ // Initialization block
12
+ //------------------------------
13
+ $this->setId('buyListing');
14
+ $this->_blockGroup = 'M2ePro';
15
+ $this->_controller = 'adminhtml_common_buy_listing_other_view';
16
+ //------------------------------
17
+
18
+ // Set header text
19
+ //------------------------------
20
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
21
+ $this->_headerText = Mage::helper('M2ePro')->__(
22
+ '3rd Party %channel_title% Listings',
23
+ Mage::helper('M2ePro/Component_Buy')->getTitle()
24
+ );
25
+ } else {
26
+ $this->_headerText = Mage::helper('M2ePro')->__('3rd Party Listings');
27
+ }
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
42
+ $url = Mage::helper('M2ePro')->getBackUrl();
43
+ $this->_addButton('back', array(
44
+ 'label' => Mage::helper('M2ePro')->__('Back'),
45
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
46
+ 'class' => 'back'
47
+ ));
48
+ }
49
+ //------------------------------
50
+
51
+ }
52
+
53
+ // ####################################
54
+
55
+ public function getGridHtml()
56
+ {
57
+ $accountId = $this->getRequest()->getParam('account');
58
+
59
+ //------------------------------
60
+ $viewHeaderBlock = $this->getLayout()->createBlock(
61
+ 'M2ePro/adminhtml_listing_other_view_header','',
62
+ array(
63
+ 'account' => Mage::helper('M2ePro/Component_Buy')->getCachedObject('Account', $accountId),
64
+ 'marketplace' => Mage::helper('M2ePro/Component_Buy')->getMarketplace()
65
+ )
66
+ );
67
+ //------------------------------
68
+
69
+ $mapToProductBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_listing_other_mapping');
70
+
71
+ return $viewHeaderBlock->toHtml() . $mapToProductBlock->toHtml() . parent::getGridHtml();
72
+ }
73
+
74
+ // ####################################
75
+
76
+ protected function _toHtml()
77
+ {
78
+ /** @var $helper Ess_M2ePro_Helper_Data */
79
+ $helper = Mage::helper('M2ePro');
80
+ $componentMode = Ess_M2ePro_Helper_Component_Buy::NICK;
81
+
82
+ $logViewUrl = $this->getUrl(
83
+ '*/adminhtml_common_log/listingOther',
84
+ array(
85
+ 'filter' => base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Buy::NICK),
86
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_listing_other/index/tab/' . $componentMode)
87
+ )
88
+ );
89
+
90
+ $prepareData = $this->getUrl('*/adminhtml_listing_other_moving/prepareMoveToListing');
91
+ $createDefaultListingUrl = $this->getUrl('*/adminhtml_listing_other_moving/createDefaultListing');
92
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/moveToListingGrid');
93
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/getFailedProductsGrid');
94
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_other_moving/tryToMoveToListing');
95
+ $moveToListing = $this->getUrl('*/adminhtml_listing_other_moving/moveToListing');
96
+
97
+ $mapAutoToProductUrl = $this->getUrl('*/adminhtml_listing_other_mapping/autoMap');
98
+
99
+ $removingProductsUrl = $this->getUrl('*/adminhtml_common_listing_other/removing');
100
+ $unmappingProductsUrl = $this->getUrl('*/adminhtml_listing_other_mapping/unmapping');
101
+
102
+ $someProductsWereNotMappedMessage = 'No matches were found. Please change the Mapping Attributes in <strong>';
103
+ $someProductsWereNotMappedMessage .= 'Configuration > Account > 3rd Party Listings</strong> ';
104
+ $someProductsWereNotMappedMessage .= 'or try to map manually.';
105
+ $someProductsWereNotMappedMessage = $helper->escapeJs($helper->__($someProductsWereNotMappedMessage));
106
+
107
+ $successfullyMappedMessage = $helper->escapeJs($helper->__('Product was successfully Mapped.'));
108
+
109
+ $createListing = $helper->escapeJs($helper->__(
110
+ 'Listings, which have the same Marketplace and Account were not found.'
111
+ ));
112
+ $createListing .= $helper->escapeJs($helper->__('Would you like to create one with Default Settings ?'));
113
+ $popupTitle = $helper->escapeJs($helper->__('Moving Rakuten.com Items'));
114
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Rakuten.com Item'));
115
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
116
+
117
+ $confirmMessage = $helper->escapeJs($helper->__('Are you sure?'));
118
+
119
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
120
+ $productsWereNotMovedMessage = $helper->escapeJs(
121
+ $helper->__('Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
122
+ );
123
+ $someProductsWereNotMovedMessage = $helper->escapeJs($helper->__(
124
+ 'Some of the Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.'
125
+ ));
126
+
127
+ $notEnoughDataMessage = $helper->escapeJs($helper->__('Not enough data.'));
128
+ $successfullyUnmappedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Unmapped.'));
129
+ $successfullyRemovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Removed.'));
130
+
131
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
132
+
133
+ $selectItemsMessage = $helper->escapeJs(
134
+ $helper->__('Please select the Products you want to perform the Action on.')
135
+ );
136
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
137
+
138
+ $processingDataMessage = $helper->escapeJs($helper->__('Processing %product_title% Product(s).'));
139
+
140
+ $successWord = $helper->escapeJs($helper->__('Success'));
141
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
142
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
143
+ $errorWord = $helper->escapeJs($helper->__('Error'));
144
+ $closeWord = $helper->escapeJs($helper->__('Close'));
145
+
146
+ $autoMapProgressTitle = $helper->escapeJs($helper->__('Map Item(s) to Products'));
147
+ $selectOnlyMapped = $helper->escapeJs($helper->__('Only Mapped Products must be selected.'));
148
+ $selectTheSameTypeProducts = $helper->escapeJs(
149
+ $helper->__('Selected Items must belong to the same Account and Marketplace.')
150
+ );
151
+
152
+ $translations = json_encode(array(
153
+
154
+ 'Mapping Product' => $helper->__('Mapping Product'),
155
+ 'Product does not exist.' => $helper->__('Product does not exist.'),
156
+ 'Please enter correct Product ID.' => $helper->__('Please enter correct Product ID.'),
157
+ 'Product(s) was successfully Mapped.' => $helper->__('Product(s) was successfully Mapped.'),
158
+ 'Please enter correct Product ID or SKU' => $helper->__('Please enter correct Product ID or SKU'),
159
+
160
+ 'Current version only supports Simple Products. Please, choose Simple Product.' => $helper->__(
161
+ 'Current version only supports Simple Products. Please, choose Simple Product.'
162
+ ),
163
+
164
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.' => $helper->__(
165
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.'
166
+ )
167
+
168
+ ));
169
+
170
+ $urls = json_encode(array(
171
+
172
+ 'adminhtml_common_log/listingOther' => $this->getUrl('*/adminhtml_common_log/listingOther',array(
173
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_listing_other/index')
174
+ )),
175
+
176
+ 'adminhtml_listing_other_mapping/map' => $this->getUrl('*/adminhtml_listing_other_mapping/map'),
177
+
178
+ ));
179
+
180
+ $javascriptsMain = <<<JAVASCRIPT
181
+ <script type="text/javascript">
182
+
183
+ M2eProBuy = {};
184
+ M2eProBuy.url = {};
185
+ M2eProBuy.formData = {};
186
+ M2eProBuy.customData = {};
187
+ M2eProBuy.text = {};
188
+
189
+ M2ePro.url.add({$urls});
190
+ M2ePro.translator.add({$translations});
191
+
192
+ M2eProBuy.url.logViewUrl = '{$logViewUrl}';
193
+ M2eProBuy.url.prepareData = '{$prepareData}';
194
+ M2eProBuy.url.createDefaultListing = '{$createDefaultListingUrl}';
195
+ M2eProBuy.url.getGridHtml = '{$getMoveToListingGridHtml}';
196
+ M2eProBuy.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
197
+ M2eProBuy.url.tryToMoveToListing = '{$tryToMoveToListing}';
198
+ M2eProBuy.url.moveToListing = '{$moveToListing}';
199
+ M2eProBuy.url.mapAutoToProduct = '{$mapAutoToProductUrl}';
200
+ M2eProBuy.url.removingProducts = '{$removingProductsUrl}';
201
+ M2eProBuy.url.unmappingProducts = '{$unmappingProductsUrl}';
202
+
203
+ M2eProBuy.text.create_listing = '{$createListing}';
204
+ M2eProBuy.text.popup_title = '{$popupTitle}';
205
+ M2eProBuy.text.popup_title_single = '{$popupTitleSingle}';
206
+ M2eProBuy.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
207
+ M2eProBuy.text.confirm = '{$confirmMessage}';
208
+ M2eProBuy.text.successfully_moved = '{$successfullyMovedMessage}';
209
+ M2eProBuy.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
210
+ M2eProBuy.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
211
+ M2eProBuy.text.not_enough_data = '{$notEnoughDataMessage}';
212
+ M2eProBuy.text.successfully_unmapped = '{$successfullyUnmappedMessage}';
213
+ M2eProBuy.text.successfully_removed = '{$successfullyRemovedMessage}';
214
+
215
+ M2eProBuy.text.select_items_message = '{$selectItemsMessage}';
216
+ M2eProBuy.text.select_action_message = '{$selectActionMessage}';
217
+
218
+ M2eProBuy.text.automap_progress_title = '{$autoMapProgressTitle}';
219
+ M2eProBuy.text.processing_data_message = '{$processingDataMessage}';
220
+ M2eProBuy.text.successfully_mapped = '{$successfullyMappedMessage}';
221
+ M2eProBuy.text.failed_mapped = '{$someProductsWereNotMappedMessage}';
222
+
223
+ M2eProBuy.text.select_only_mapped_products = '{$selectOnlyMapped}';
224
+ M2eProBuy.text.select_the_same_type_products = '{$selectTheSameTypeProducts}';
225
+
226
+ M2eProBuy.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
227
+
228
+ M2eProBuy.text.success_word = '{$successWord}';
229
+ M2eProBuy.text.notice_word = '{$noticeWord}';
230
+ M2eProBuy.text.warning_word = '{$warningWord}';
231
+ M2eProBuy.text.error_word = '{$errorWord}';
232
+ M2eProBuy.text.close_word = '{$closeWord}';
233
+
234
+ M2eProBuy.customData.componentMode = '{$componentMode}';
235
+ M2eProBuy.customData.gridId = 'buyListingOtherGrid';
236
+
237
+ Event.observe(window,'load',function() {
238
+ ListingProgressBarObj = new ProgressBar('listing_other_progress_bar');
239
+ GridWrapperObj = new AreaWrapper('listing_other_content_container');
240
+
241
+ BuyListingOtherGridHandlerObj = new CommonBuyListingOtherGridHandler('buyListingOtherGrid');
242
+ BuyListingOtherMappingHandlerObj = new ListingOtherMappingHandler(
243
+ BuyListingOtherGridHandlerObj,
244
+ 'buy'
245
+ );
246
+
247
+ // todo next (temp solution)
248
+ BuyListingOtherGridHandlerObj.movingHandler.setOptions(M2eProBuy);
249
+ BuyListingOtherGridHandlerObj.autoMappingHandler.setOptions(M2eProBuy);
250
+ BuyListingOtherGridHandlerObj.removingHandler.setOptions(M2eProBuy);
251
+ BuyListingOtherGridHandlerObj.unmappingHandler.setOptions(M2eProBuy);
252
+ });
253
+
254
+ </script>
255
+ JAVASCRIPT;
256
+
257
+ return $javascriptsMain.
258
+ '<div id="listing_other_progress_bar"></div>' .
259
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
260
+ '<div id="listing_other_content_container">' .
261
+ parent::_toHtml() .
262
+ '</div>';
263
+ }
264
+
265
+ // ####################################
266
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View/Grid.php ADDED
@@ -0,0 +1,534 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_View_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('account');
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_buy_listing_other/view',
130
+ array(
131
+ 'account' => $this->getRequest()->getParam('account'),
132
+ 'marketplace' => $this->getRequest()->getParam('marketplace'),
133
+ 'back' => $this->getRequest()->getParam('back', null)
134
+ )
135
+ );
136
+
137
+ $this->addColumn('actions', array(
138
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
139
+ 'align' => 'left',
140
+ 'width' => '70px',
141
+ 'type' => 'action',
142
+ 'index' => 'actions',
143
+ 'filter' => false,
144
+ 'sortable' => false,
145
+ 'getter' => 'getId',
146
+ 'actions' => array(
147
+ array(
148
+ 'caption' => Mage::helper('M2ePro')->__('View Log'),
149
+ 'field' => 'id',
150
+ 'url' => array(
151
+ 'base' => '*/adminhtml_common_log/listingOther',
152
+ 'params' => array(
153
+ 'back' => $backUrl,
154
+ 'channel' => Ess_M2ePro_Helper_Component_Buy::NICK
155
+ )
156
+ )
157
+ ),
158
+ array(
159
+ 'caption' => Mage::helper('M2ePro')->__('Clear Log'),
160
+ 'url' => array(
161
+ 'base' => '*/adminhtml_listing_other/clearLog',
162
+ 'params' => array(
163
+ 'back' => $backUrl
164
+ )
165
+ ),
166
+ 'field' => 'id',
167
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
168
+ )
169
+ )
170
+ ));
171
+
172
+ return parent::_prepareColumns();
173
+ }
174
+
175
+ protected function _prepareMassaction()
176
+ {
177
+ // Set mass-action identifiers
178
+ //--------------------------------
179
+ $this->setMassactionIdField('`main_table`.id');
180
+ $this->getMassactionBlock()->setFormFieldName('ids');
181
+ //--------------------------------
182
+
183
+ $this->getMassactionBlock()->setGroups(array(
184
+ 'mapping' => Mage::helper('M2ePro')->__('Mapping'),
185
+ 'other' => Mage::helper('M2ePro')->__('Other')
186
+ ));
187
+
188
+ // Set mass-action
189
+ //--------------------------------
190
+ $this->getMassactionBlock()->addItem('autoMapping', array(
191
+ 'label' => Mage::helper('M2ePro')->__('Map Item(s) Automatically'),
192
+ 'url' => '',
193
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
194
+ ), 'mapping');
195
+ $this->getMassactionBlock()->addItem('moving', array(
196
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) To Listing'),
197
+ 'url' => '',
198
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
199
+ ), 'other');
200
+ $this->getMassactionBlock()->addItem('removing', array(
201
+ 'label' => Mage::helper('M2ePro')->__('Remove Item(s)'),
202
+ 'url' => '',
203
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
204
+ ), 'other');
205
+ $this->getMassactionBlock()->addItem('unmapping', array(
206
+ 'label' => Mage::helper('M2ePro')->__('Unmap Item(s)'),
207
+ 'url' => '',
208
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
209
+ ), 'mapping');
210
+ //--------------------------------
211
+
212
+ return parent::_prepareMassaction();
213
+ }
214
+
215
+ // ####################################
216
+
217
+ public function callbackColumnProductId($value, $row, $column, $isExport)
218
+ {
219
+ if (empty($value)) {
220
+ $productTitle = $row->getData('title');
221
+
222
+ if (is_null($productTitle) || $productTitle === '') {
223
+ $productTitle = Mage::helper('M2ePro')->__('N/A');
224
+ } else {
225
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
226
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
227
+ if (strlen($productTitle) > 60) {
228
+ $productTitle = substr($productTitle, 0, 60) . '...';
229
+ }
230
+ }
231
+
232
+ $htmlValue = '&nbsp;<a href="javascript:void(0);"
233
+ onclick="BuyListingOtherMappingHandlerObj.openPopUp(\''
234
+ .$productTitle
235
+ .'\','
236
+ .(int)$row->getId()
237
+ .');">'
238
+ .Mage::helper('M2ePro')->__('Map').'</a>';
239
+
240
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
241
+ $htmlValue .= '<br/>' . $row->getId();
242
+ }
243
+
244
+ return $htmlValue;
245
+ }
246
+
247
+ $htmlValue = '&nbsp<a href="'
248
+ .$this->getUrl('adminhtml/catalog_product/edit',
249
+ array('id' => $row->getData('product_id')))
250
+ .'" target="_blank">'
251
+ .$row->getData('product_id')
252
+ .'</a>';
253
+
254
+ $htmlValue .= '&nbsp&nbsp&nbsp<a href="javascript:void(0);"'
255
+ .' onclick="BuyListingOtherGridHandlerObj.movingHandler.getGridHtml('
256
+ .json_encode(array((int)$row->getData('id')))
257
+ .')">'
258
+ .Mage::helper('M2ePro')->__('Move')
259
+ .'</a>';
260
+
261
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
262
+ $htmlValue .= '<br/>' . $row->getId();
263
+ }
264
+
265
+ return $htmlValue;
266
+ }
267
+
268
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
269
+ {
270
+ if (is_null($value)) {
271
+ $value = '<i style="color:gray;">receiving...</i>';
272
+ } elseif ($value == '') {
273
+ $value = '<i style="color:gray;">none</i>';
274
+ } else {
275
+ $value = '<span>' . Mage::helper('M2ePro')->escapeHtml($value) . '</span>';
276
+ }
277
+
278
+ $tempSku = $row->getData('sku');
279
+ is_null($tempSku) && $tempSku = Mage::helper('M2ePro')->__('N/A');
280
+
281
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('Reference ID').':</strong> '
282
+ .Mage::helper('M2ePro')->escapeHtml($tempSku);
283
+
284
+ return $value;
285
+ }
286
+
287
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
288
+ {
289
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
290
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
291
+ }
292
+
293
+ public function callbackColumnSku($value, $row, $column, $isExport)
294
+ {
295
+ return $value;
296
+ }
297
+
298
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
299
+ {
300
+ if (is_null($value) || $value === '') {
301
+ return Mage::helper('M2ePro')->__('N/A');
302
+ }
303
+
304
+ if ($value <= 0) {
305
+ return '<span style="color: red;">0</span>';
306
+ }
307
+
308
+ return $value;
309
+ }
310
+
311
+ public function callbackColumnPrice($value, $row, $column, $isExport)
312
+ {
313
+ if (is_null($value) || $value === '') {
314
+ return Mage::helper('M2ePro')->__('N/A');
315
+ }
316
+
317
+ if ((float)$value <= 0) {
318
+ return '<span style="color: #f00;">0</span>';
319
+ }
320
+
321
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
322
+ }
323
+
324
+ public function callbackColumnStatus($value, $row, $column, $isExport)
325
+ {
326
+ switch ($row->getData('status')) {
327
+
328
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
329
+ $value = '<span style="color: gray;">' . $value . '</span>';
330
+ break;
331
+
332
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
333
+ $value = '<span style="color: green;">' . $value . '</span>';
334
+ break;
335
+
336
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
337
+ $value = '<span style="color: red;">' . $value . '</span>';
338
+ break;
339
+
340
+ default:
341
+ break;
342
+ }
343
+
344
+ return $value.$this->getViewLogIconHtml($row->getId());
345
+ }
346
+
347
+ protected function callbackFilterTitle($collection, $column)
348
+ {
349
+ $value = $column->getFilter()->getValue();
350
+
351
+ if ($value == null) {
352
+ return;
353
+ }
354
+
355
+ $collection->getSelect()->where('second_table.title LIKE ? OR second_table.sku LIKE ?', '%'.$value.'%');
356
+ }
357
+
358
+ // ####################################
359
+
360
+ public function getViewLogIconHtml($listingOtherId)
361
+ {
362
+ $listingOtherId = (int)$listingOtherId;
363
+
364
+ // Get last messages
365
+ //--------------------------
366
+ $dbSelect = $this->connRead->select()
367
+ ->from(
368
+ Mage::getResourceModel('M2ePro/Listing_Other_Log')->getMainTable(),
369
+ array('action_id','action','type','description','create_date','initiator')
370
+ )
371
+ ->where('`listing_other_id` = ?', $listingOtherId)
372
+ ->where('`action_id` IS NOT NULL')
373
+ ->order(array('id DESC'))
374
+ ->limit(30);
375
+
376
+ $logRows = $this->connRead->fetchAll($dbSelect);
377
+ //--------------------------
378
+
379
+ // Get grouped messages by action_id
380
+ //--------------------------
381
+ $actionsRows = array();
382
+ $tempActionRows = array();
383
+ $lastActionId = false;
384
+
385
+ foreach ($logRows as $row) {
386
+
387
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
388
+
389
+ if ($row['action_id'] !== $lastActionId) {
390
+ if (count($tempActionRows) > 0) {
391
+ $actionsRows[] = array(
392
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
393
+ 'date' => $this->getMainDateForActionId($tempActionRows),
394
+ 'action' => $this->getActionForAction($tempActionRows[0]),
395
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
396
+ 'items' => $tempActionRows
397
+ );
398
+ $tempActionRows = array();
399
+ }
400
+ $lastActionId = $row['action_id'];
401
+ }
402
+ $tempActionRows[] = $row;
403
+ }
404
+
405
+ if (count($tempActionRows) > 0) {
406
+ $actionsRows[] = array(
407
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
408
+ 'date' => $this->getMainDateForActionId($tempActionRows),
409
+ 'action' => $this->getActionForAction($tempActionRows[0]),
410
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
411
+ 'items' => $tempActionRows
412
+ );
413
+ }
414
+
415
+ if (count($actionsRows) <= 0) {
416
+ return '';
417
+ }
418
+
419
+ $tips = array(
420
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
421
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
422
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
423
+ );
424
+
425
+ $icons = array(
426
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
427
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
428
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
429
+ );
430
+
431
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
432
+ 'entity_id' => $listingOtherId,
433
+ 'rows' => $actionsRows,
434
+ 'tips' => $tips,
435
+ 'icons' => $icons,
436
+ 'view_help_handler' => 'BuyListingOtherGridHandlerObj.viewItemHelp',
437
+ 'hide_help_handler' => 'BuyListingOtherGridHandlerObj.hideItemHelp',
438
+ ));
439
+
440
+ return $summary->toHtml();
441
+ }
442
+
443
+ public function getActionForAction($actionRows)
444
+ {
445
+ $string = '';
446
+
447
+ switch ((int)$actionRows['action']) {
448
+ case Ess_M2ePro_Model_Listing_Other_Log::ACTION_CHANNEL_CHANGE:
449
+ $string = Mage::helper('M2ePro')->__('Channel Change');
450
+ break;
451
+ }
452
+
453
+ return $string;
454
+ }
455
+
456
+ public function getInitiatorForAction($actionRows)
457
+ {
458
+ $string = '';
459
+
460
+ switch ($actionRows['initiator']) {
461
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
462
+ $string = '';
463
+ break;
464
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
465
+ $string = Mage::helper('M2ePro')->__('Manual');
466
+ break;
467
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
468
+ $string = Mage::helper('M2ePro')->__('Automatic');
469
+ break;
470
+ }
471
+
472
+ return $string;
473
+ }
474
+
475
+ public function getMainTypeForActionId($actionRows)
476
+ {
477
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
478
+
479
+ foreach ($actionRows as $row) {
480
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
481
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
482
+ break;
483
+ }
484
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
485
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
486
+ }
487
+ }
488
+
489
+ return $type;
490
+ }
491
+
492
+ public function getMainDateForActionId($actionRows)
493
+ {
494
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
495
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
496
+ }
497
+
498
+ // ####################################
499
+
500
+ protected function _toHtml()
501
+ {
502
+ $javascriptsMain = <<<JAVASCRIPT
503
+ <script type="text/javascript">
504
+
505
+ if (typeof BuyListingOtherGridHandlerObj != 'undefined') {
506
+ BuyListingOtherGridHandlerObj.afterInitPage();
507
+ }
508
+
509
+ Event.observe(window, 'load', function() {
510
+ setTimeout(function() {
511
+ BuyListingOtherGridHandlerObj.afterInitPage();
512
+ }, 350);
513
+ });
514
+
515
+ </script>
516
+ JAVASCRIPT;
517
+
518
+ return parent::_toHtml().$javascriptsMain;
519
+ }
520
+
521
+ // ####################################
522
+
523
+ public function getGridUrl()
524
+ {
525
+ return $this->getUrl('*/adminhtml_common_buy_listing_other/grid', array('_current' => true));
526
+ }
527
+
528
+ public function getRowUrl($row)
529
+ {
530
+ return false;
531
+ }
532
+
533
+ // ####################################
534
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingProduct');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_listing_product';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
25
+
26
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
27
+ $headerText = Mage::helper('M2ePro')->__(
28
+ 'Add Products To %component_name% Listing "%listing_title%"',
29
+ Mage::helper('M2ePro/Component_Buy')->getTitle(),
30
+ $this->escapeHtml($listingData['title'])
31
+ );
32
+ } else {
33
+ $headerText = Mage::helper('M2ePro')->__('Add Products To Listing "%listing_title%"',
34
+ $this->escapeHtml($listingData['title'])
35
+ );
36
+ }
37
+
38
+ $this->_headerText = $headerText;
39
+ //------------------------------
40
+
41
+ // Set buttons actions
42
+ //------------------------------
43
+ $this->removeButton('back');
44
+ $this->removeButton('reset');
45
+ $this->removeButton('delete');
46
+ $this->removeButton('add');
47
+ $this->removeButton('save');
48
+ $this->removeButton('edit');
49
+ //------------------------------
50
+
51
+ //------------------------------
52
+ if (is_null($this->getRequest()->getParam('back'))) {
53
+ $url = $this->getUrl(
54
+ '*/adminhtml_common_buy_listing/categoryProduct',
55
+ array(
56
+ 'id' => $listingData['id'],
57
+ 'save_categories' => $this->getRequest()->getParam('save_categories', 1),
58
+ 'selected_categories' => $this->getRequest()->getParam('selected_categories')
59
+ )
60
+ );
61
+ } else {
62
+ $url = Mage::helper('M2ePro')->getBackUrl(
63
+ '*/adminhtml_common_listing/index',
64
+ array(
65
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
66
+ )
67
+ );
68
+ }
69
+ $this->_addButton('back', array(
70
+ 'label' => Mage::helper('M2ePro')->__('Back'),
71
+ 'onclick' => 'ProductGridHandlerObj.back_click(\''.$url.'\')',
72
+ 'class' => 'back'
73
+ ));
74
+ //------------------------------
75
+
76
+ //------------------------------
77
+ $this->_addButton('save', array(
78
+ 'label' => Mage::helper('M2ePro')->__('Save'),
79
+ 'onclick' => 'ProductGridHandlerObj.save_click(\'view\')',
80
+ 'class' => 'save'
81
+ ));
82
+ //------------------------------
83
+ }
84
+
85
+ public function getGridHtml()
86
+ {
87
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_product_help');
88
+ return $helpBlock->toHtml() . parent::getGridHtml();
89
+ }
90
+
91
+ protected function _toHtml()
92
+ {
93
+ return '<div id="add_products_progress_bar"></div>'.
94
+ '<div id="add_products_container">'.
95
+ parent::_toHtml().
96
+ '</div>';
97
+ }
98
+
99
+ // ####################################
100
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product/Help.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingProductHelp');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/listing/product/help.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Grid.php ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ $this->productId = Mage::helper('M2ePro/Data_Global')->getValue('product_id');
18
+
19
+ // Initialization block
20
+ //------------------------------
21
+ $this->setId('buyProductSearchGrid');
22
+ //------------------------------
23
+
24
+ // Set default values
25
+ //------------------------------
26
+ $this->setFilterVisibility(false);
27
+ $this->setPagerVisibility(false);
28
+ $this->setDefaultSort('id');
29
+ $this->setDefaultDir('ASC');
30
+ $this->setSaveParametersInSession(true);
31
+ $this->setUseAjax(true);
32
+ //------------------------------
33
+ }
34
+
35
+ protected function _prepareCollection()
36
+ {
37
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
38
+
39
+ $results = new Varien_Data_Collection();
40
+ foreach ($data as $index => $item) {
41
+ $temp = array(
42
+ 'id' => $index,
43
+ 'general_id' => isset($item['general_id']) ? $item['general_id'] : null,
44
+ 'title' => $item['title'],
45
+ 'image_url' => $item['image_url'],
46
+ 'price' => isset($item['price']) ? $item['price'] : null,
47
+ 'variations' => isset($item['variations']) ? $item['variations'] : null
48
+ );
49
+
50
+ $results->addItem(new Varien_Object($temp));
51
+ }
52
+
53
+ $this->setCollection($results);
54
+
55
+ return parent::_prepareCollection();
56
+ }
57
+
58
+ protected function _prepareColumns()
59
+ {
60
+ $this->addColumn('image', array(
61
+ 'header' => Mage::helper('M2ePro')->__('Image'),
62
+ 'align' => 'center',
63
+ 'type' => 'text',
64
+ 'width' => '80px',
65
+ 'index' => 'image_url',
66
+ 'filter' => false,
67
+ 'sortable' => false,
68
+ 'frame_callback' => array($this, 'callbackColumnImage')
69
+ ));
70
+
71
+ $this->addColumn('general_id', array(
72
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
73
+ 'align' => 'center',
74
+ 'type' => 'text',
75
+ 'width' => '75px',
76
+ 'index' => 'general_id',
77
+ 'filter' => false,
78
+ 'sortable' => false,
79
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
80
+ ));
81
+
82
+ $this->addColumn('title', array(
83
+ 'header' => Mage::helper('M2ePro')->__('Product Title'),
84
+ 'align' => 'left',
85
+ 'type' => 'text',
86
+ 'width' => '375px',
87
+ 'string_limit' => 10000,
88
+ 'index' => 'title',
89
+ 'filter' => false,
90
+ 'sortable' => false,
91
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
92
+ ));
93
+
94
+ $this->addColumn('price',array(
95
+ 'header' => Mage::helper('catalog')->__('Price'),
96
+ 'width' => '60px',
97
+ 'align' => 'right',
98
+ 'index' => 'price',
99
+ 'filter' => false,
100
+ 'sortable' => false,
101
+ 'type' => 'text',
102
+ 'frame_callback' => array($this, 'callbackColumnPrice')
103
+ ));
104
+
105
+ $this->addColumn('actions', array(
106
+ 'header' => Mage::helper('M2ePro')->__('Action'),
107
+ 'align' => 'left',
108
+ 'type' => 'text',
109
+ 'width' => '78px',
110
+ 'filter' => false,
111
+ 'sortable' => false,
112
+ 'frame_callback' => array($this, 'callbackColumnActions'),
113
+ ));
114
+
115
+ }
116
+
117
+ // ####################################
118
+
119
+ public function callbackColumnImage($value, $product, $column, $isExport)
120
+ {
121
+ return '<img width="75px" src="'.$value.'" />';
122
+ }
123
+
124
+ public function callbackColumnGeneralId($value, $product, $column, $isExport)
125
+ {
126
+ if (empty($value)) {
127
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl('%general_id%');
128
+ $templateHtml = '<a href="'.$url.'" target="_blank">%general_id%</a>';
129
+ return '<span id="buy_link_'.$product->getId().'">' . Mage::helper('M2ePro')->__('N/A') . '</span>' .
130
+ '<div id="template_buy_link_'.$product->getId().'" style="display: none;">'.$templateHtml.'</div>';
131
+ }
132
+
133
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
134
+
135
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
136
+ }
137
+
138
+ public function callbackColumnTitle($value, $row, $column, $isExport)
139
+ {
140
+ $value = '<div style="margin-left: 3px; margin-bottom: 10px;">'.
141
+ Mage::helper('M2ePro')->escapeHtml($value)."</div>";
142
+
143
+ $variations = $row->getData('variations');
144
+ if (is_null($variations)) {
145
+ return $value;
146
+ }
147
+
148
+ $specificsHtml = '';
149
+ $id = $row->getId();
150
+ foreach ($variations['set'] as $specificName => $specific) {
151
+ $specificsHtml .= '<span style="margin-left: 10px;
152
+ font-size: 11px;
153
+ color: #808080;
154
+ display: inline-block;
155
+ width: 100px;">'.
156
+ ucfirst(strtolower($specificName)).
157
+ ':</span>';
158
+ $specificsHtml .= '<select class="specifics_'.$id.'"
159
+ onchange="ListingGridHandlerObj.productSearchHandler.specificsChange(this)"
160
+ style="width: 150px; margin-left: 5px; margin-bottom: 5px; font-size: 10px;"
161
+ id="specific_'.$specificName.'_'.$id.'">';
162
+ $specificsHtml .= '<option value=""></option>';
163
+ foreach ($specific as $option) {
164
+ $specificsHtml .= '<option value="'.$option.'">'.$option.'</option>';
165
+ }
166
+ $specificsHtml .= '</select><br/>';
167
+ }
168
+
169
+ $specificsJsonContainer = '<div id="skus_'.$id.'" style="display: none;">'.
170
+ json_encode($variations['skus']).'</div>';
171
+
172
+ return $value . $specificsHtml . $specificsJsonContainer;
173
+ }
174
+
175
+ public function callbackColumnPrice($value, $row, $column, $isExport)
176
+ {
177
+ if (empty($value)) {
178
+ $value = Mage::helper('M2ePro')->__('N/A');
179
+ }
180
+
181
+ return '<div id="price_'.$row->getId().'" style="margin-right: 5px;">'.$value.'</div>';
182
+ }
183
+
184
+ public function callbackColumnActions($value, $row, $column, $isExport)
185
+ {
186
+ $assignText = Mage::helper('M2ePro')->__('Assign Rakuten.com SKU');
187
+ //->__('There is no such variation on Rakuten.com. Please, choose another variation.');
188
+ $naMessage = 'There is no such Variation on Rakuten.com. Please, choose another Variation.';
189
+ $naMessage = Mage::helper('M2ePro')->__($naMessage);
190
+
191
+ if (!is_null($row->getData('variations'))) {
192
+ $templateMapHtml =
193
+ '<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId('
194
+ .$this->productId
195
+ .', \'%general_id%\');">'.$assignText.'</a>';
196
+
197
+ $templateNaHtml = '<a href="javascript:void(0);" onclick="alert(\''.$naMessage.'\')">'.$assignText.'</a>';
198
+
199
+ return '<span id="map_link_'.$row->getId().'"><span style="color: #808080">'.$assignText.'</span></span>
200
+ <div id="template_map_link_'.$row->getId().'" style="display: none;">'.$templateMapHtml.'</div>
201
+ <div id="template_na_link_'.$row->getId().'" style="display: none;">'.$templateNaHtml.'</div>';
202
+ }
203
+
204
+ return '<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId('
205
+ .$this->productId
206
+ .', \''
207
+ .$row->getData('general_id')
208
+ .'\');">'.$assignText.'</a>';
209
+ }
210
+
211
+ // ####################################
212
+
213
+ protected function _toHtml()
214
+ {
215
+ $javascriptsMain = <<<JAVASCRIPT
216
+ <script type="text/javascript">
217
+
218
+ $$('#buyProductSearchGrid div.grid th').each(function(el){
219
+ el.style.padding = '2px 2px';
220
+ });
221
+
222
+ $$('#buyProductSearchGrid div.grid td').each(function(el){
223
+ el.style.padding = '2px 2px';
224
+ });
225
+
226
+ </script>
227
+ JAVASCRIPT;
228
+
229
+ return parent::_toHtml() . $javascriptsMain;
230
+ }
231
+
232
+ // ####################################
233
+
234
+ public function getGridUrl()
235
+ {
236
+ return $this->getUrl('*/adminhtml_common_buy_listing/getSuggestedBuyComSkuGrid', array('_current'=>true));
237
+ }
238
+
239
+ public function getRowUrl($row)
240
+ {
241
+ return false;
242
+ }
243
+
244
+ // ####################################
245
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Main.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_Listing_ProductSearch_Main
8
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setTemplate('M2ePro/common/buy/listing/product_search/main.phtml');
17
+ }
18
+
19
+ protected function _beforeToHtml()
20
+ {
21
+ //------------------------------
22
+ $data = array(
23
+ 'id' => 'productSearch_submit_button',
24
+ 'label' => Mage::helper('M2ePro')->__('Search'),
25
+ 'class' => 'productSearch_submit_button submit'
26
+ );
27
+ $buttonSubmitBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
28
+ $this->setChild('productSearch_submit_button', $buttonSubmitBlock);
29
+ //------------------------------
30
+
31
+ //------------------------------
32
+ $data = array(
33
+ 'id' => 'productSearch_back_button',
34
+ 'label' => Mage::helper('M2ePro')->__('Back'),
35
+ 'class' => 'productSearch_back_button'
36
+ );
37
+ $buttonBackBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
38
+ $this->setChild('productSearch_back_button', $buttonBackBlock);
39
+ //------------------------------
40
+
41
+ //------------------------------
42
+ $data = array(
43
+ 'id' => 'productSearch_cancel_button',
44
+ 'label' => Mage::helper('M2ePro')->__('Close'),
45
+ 'class' => 'productSearch_cancel_button'
46
+ );
47
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
48
+ $this->setChild('productSearch_cancel_button', $buttonCancelBlock);
49
+ //------------------------------
50
+
51
+ //------------------------------
52
+ $data = array(
53
+ 'id' => 'productSearch_cleanSuggest_button',
54
+ 'label' => Mage::helper('M2ePro')->__('Clear Search Results'),
55
+ 'class' => 'productSearch_cleanSuggest_button',
56
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndOpenSearchMenu()'
57
+ );
58
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
59
+ $this->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
60
+ //------------------------------
61
+
62
+ parent::_beforeToHtml();
63
+ }
64
+
65
+ // ####################################
66
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Menu.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_ProductSearch_Menu
8
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
9
+ {
10
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ $this->setTemplate('M2ePro/common/buy/listing/product_search/menu.phtml');
17
+ }
18
+
19
+ protected function _beforeToHtml()
20
+ {
21
+ //------------------------------
22
+ $data = array(
23
+ 'id' => 'productSearchMenu_cancel_button',
24
+ 'label' => Mage::helper('M2ePro')->__('Close'),
25
+ 'class' => 'productSearchMenu_cancel_button'
26
+ );
27
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
28
+ $this->setChild('productSearchMenu_cancel_button', $buttonCancelBlock);
29
+ //------------------------------
30
+
31
+ parent::_beforeToHtml();
32
+ }
33
+
34
+ // ####################################
35
+ }
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::CHANNEL_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,608 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $listingProductCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Product');
36
+ $listingProductCollection->getSelect()->distinct();
37
+ $listingProductCollection->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
+ $listingProductCollection->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
+ $listingProductCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
76
+ $listingProductCollection->getSelect()->columns(
77
+ array(
78
+ 'is_m2epro_listing' => new Zend_Db_Expr('1'),
79
+ 'magento_sku' => 'cpe.sku',
80
+ 'is_in_stock' => 'cisi.is_in_stock',
81
+ 'product_name' => 'cpev.value',
82
+ 'listing_title' => 'l.title',
83
+ 'store_id' => 'l.store_id',
84
+ 'account_id' => 'l.account_id',
85
+ 'marketplace_id' => 'l.marketplace_id',
86
+ 'listing_product_id' => 'main_table.id',
87
+ 'product_id' => 'main_table.product_id',
88
+ 'listing_id' => 'main_table.listing_id',
89
+ 'status' => 'main_table.status',
90
+ 'general_id' => 'second_table.general_id',
91
+ 'online_sku' => 'second_table.sku',
92
+ 'online_qty' => 'second_table.online_qty',
93
+ 'online_price' => 'second_table.online_price'
94
+ )
95
+ );
96
+
97
+ //------------------------------
98
+ $listingOtherCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
99
+ $listingOtherCollection->getSelect()->distinct();
100
+
101
+ // add stock availability, type id, status & visibility to select
102
+ //------------------------------
103
+ $listingOtherCollection->getSelect()
104
+ ->joinLeft(
105
+ array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()),
106
+ '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)',
107
+ array('is_in_stock'))
108
+ ->joinLeft(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
109
+ '(cpe.entity_id = `main_table`.product_id)',
110
+ array('magento_sku'=>'sku'));
111
+ //------------------------------
112
+
113
+ $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
114
+ $listingOtherCollection->getSelect()->columns(
115
+ array(
116
+ 'is_m2epro_listing' => new Zend_Db_Expr(0),
117
+ 'magento_sku' => 'cpe.sku',
118
+ 'is_in_stock' => 'cisi.is_in_stock',
119
+ 'product_name' => 'second_table.title',
120
+ 'listing_title' => new Zend_Db_Expr('NULL'),
121
+ 'store_id' => new Zend_Db_Expr(0),
122
+ 'account_id' => 'main_table.account_id',
123
+ 'marketplace_id' => 'main_table.marketplace_id',
124
+ 'listing_product_id' => new Zend_Db_Expr('NULL'),
125
+ 'product_id' => 'main_table.product_id',
126
+ 'listing_id' => new Zend_Db_Expr('NULL'),
127
+ 'status' => 'main_table.status',
128
+ 'general_id' => 'second_table.general_id',
129
+ 'online_sku' => 'second_table.sku',
130
+ 'online_qty' => 'second_table.online_qty',
131
+ 'online_price' => 'second_table.online_price',
132
+ )
133
+ );
134
+ //------------------------------
135
+
136
+ //------------------------------
137
+ $selects = array(
138
+ $listingProductCollection->getSelect(),
139
+ $listingOtherCollection->getSelect()
140
+ );
141
+
142
+ $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
143
+ $unionSelect->union($selects);
144
+
145
+ $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
146
+ $resultCollection->getSelect()->reset()->from(
147
+ array('main_table' => $unionSelect),
148
+ array(
149
+ 'is_m2epro_listing',
150
+ 'magento_sku',
151
+ 'is_in_stock',
152
+ 'product_name',
153
+ 'listing_title',
154
+ 'store_id',
155
+ 'account_id',
156
+ 'marketplace_id',
157
+ 'listing_product_id',
158
+ 'product_id',
159
+ 'listing_id',
160
+ 'status',
161
+ 'general_id',
162
+ 'online_sku',
163
+ 'online_qty',
164
+ 'online_price'
165
+ )
166
+ );
167
+
168
+ // exit($resultCollection->getSelect()->__toString());
169
+
170
+ // Set collection to grid
171
+ $this->setCollection($resultCollection);
172
+
173
+ return parent::_prepareCollection();
174
+ }
175
+
176
+ protected function _prepareColumns()
177
+ {
178
+ $this->addColumn('product_id', array(
179
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
180
+ 'align' => 'right',
181
+ 'width' => '100px',
182
+ 'type' => 'number',
183
+ 'index' => 'product_id',
184
+ 'filter_index' => 'product_id',
185
+ 'frame_callback' => array($this, 'callbackColumnProductId')
186
+ ));
187
+
188
+ $this->addColumn('name', array(
189
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Listing / Product SKU'),
190
+ 'align' => 'left',
191
+ //'width' => '300px',
192
+ 'type' => 'text',
193
+ 'index' => 'product_name',
194
+ 'filter_index' => 'product_name',
195
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
196
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
197
+ ));
198
+
199
+ $this->addColumn('stock_availability',
200
+ array(
201
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
202
+ 'width' => '100px',
203
+ 'index' => 'is_in_stock',
204
+ 'filter_index' => 'is_in_stock',
205
+ 'type' => 'options',
206
+ 'sortable' => false,
207
+ 'options' => array(
208
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
209
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
210
+ ),
211
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
212
+ ));
213
+
214
+ if (Mage::helper('M2ePro/View_Common')->is3rdPartyShouldBeShown(Ess_M2ePro_Helper_Component_Buy::NICK)) {
215
+ $this->addColumn('is_m2epro_listing', array(
216
+ 'header' => Mage::helper('M2ePro')->__('Listing Type'),
217
+ 'align' => 'left',
218
+ 'width' => '100px',
219
+ 'type' => 'options',
220
+ 'sortable' => false,
221
+ 'index' => 'is_m2epro_listing',
222
+ 'options' => array(
223
+ 1 => Mage::helper('M2ePro')->__('M2E Pro'),
224
+ 0 => Mage::helper('M2ePro')->__('3rd Party')
225
+ )
226
+ ));
227
+ }
228
+
229
+ $this->addColumn('sku', array(
230
+ 'header' => Mage::helper('M2ePro')->__('Reference ID'),
231
+ 'align' => 'left',
232
+ 'width' => '150px',
233
+ 'type' => 'text',
234
+ 'index' => 'online_sku',
235
+ 'filter_index' => 'online_sku',
236
+ 'frame_callback' => array($this, 'callbackColumnSku')
237
+ ));
238
+
239
+ $this->addColumn('general_id', array(
240
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
241
+ 'align' => 'left',
242
+ 'width' => '90px',
243
+ 'type' => 'text',
244
+ 'index' => 'general_id',
245
+ 'filter_index' => 'general_id',
246
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
247
+ ));
248
+
249
+ $this->addColumn('online_qty', array(
250
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
251
+ 'align' => 'right',
252
+ 'width' => '70px',
253
+ 'type' => 'number',
254
+ 'index' => 'online_qty',
255
+ 'filter_index' => 'online_qty',
256
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
257
+ ));
258
+
259
+ $this->addColumn('online_price', array(
260
+ 'header' => Mage::helper('M2ePro')->__('Price'),
261
+ 'align' => 'right',
262
+ 'width' => '70px',
263
+ 'type' => 'number',
264
+ 'index' => 'online_price',
265
+ 'filter_index' => 'online_price',
266
+ 'frame_callback' => array($this, 'callbackColumnPrice')
267
+ ));
268
+
269
+ $this->addColumn('status', array(
270
+ 'header' => Mage::helper('M2ePro')->__('Status'),
271
+ 'width' => '125px',
272
+ 'index' => 'status',
273
+ 'filter_index' => 'status',
274
+ 'type' => 'options',
275
+ 'sortable' => false,
276
+ 'options' => array(
277
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
278
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
279
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive')
280
+ ),
281
+ 'frame_callback' => array($this, 'callbackColumnStatus')
282
+ ));
283
+
284
+ $this->addColumn('goto_listing_item', array(
285
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
286
+ 'align' => 'center',
287
+ 'width' => '50px',
288
+ 'type' => 'text',
289
+ 'filter' => false,
290
+ 'sortable' => false,
291
+ 'frame_callback' => array($this, 'callbackColumnActions')
292
+ ));
293
+
294
+ return parent::_prepareColumns();
295
+ }
296
+
297
+ // ####################################
298
+
299
+ public function callbackColumnProductId($value, $row, $column, $isExport)
300
+ {
301
+ if (is_null($row->getData('product_id'))) {
302
+ return Mage::helper('M2ePro')->__('N/A');
303
+ }
304
+
305
+ $productId = (int)$row->getData('product_id');
306
+ $storeId = (int)$row->getData('store_id');
307
+
308
+ $withoutImageHtml = '<a href="'
309
+ .$this->getUrl('adminhtml/catalog_product/edit',
310
+ array('id' => $productId))
311
+ .'" target="_blank">'
312
+ .$productId
313
+ .'</a>';
314
+
315
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
316
+ ->getGroupValue('/view/','show_products_thumbnails');
317
+ if (!$showProductsThumbnails) {
318
+ return $withoutImageHtml;
319
+ }
320
+
321
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
322
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
323
+ $magentoProduct->setProductId($productId);
324
+ $magentoProduct->setStoreId($storeId);
325
+
326
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
327
+ if (is_null($imageUrlResized)) {
328
+ return $withoutImageHtml;
329
+ }
330
+
331
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
332
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
333
+
334
+ return $withImageHtml;
335
+ }
336
+
337
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
338
+ {
339
+ if (is_null($value) || $value === '') {
340
+ $value = '<i style="color:gray;">receiving...</i>';
341
+ } else {
342
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
343
+ }
344
+
345
+ if (!is_null($row->getData('listing_id'))) {
346
+ $urlParams = array();
347
+ $urlParams['id'] = $row->getData('listing_id');
348
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/search');
349
+
350
+ $listingUrl = $this->getUrl('*/adminhtml_common_buy_listing/view',$urlParams);
351
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
352
+
353
+ if (strlen($listingTitle) > 50) {
354
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
355
+ }
356
+
357
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
358
+ $value .= '<strong>'
359
+ .Mage::helper('M2ePro')->__('Listing')
360
+ .': </strong> <a href="'
361
+ .$listingUrl
362
+ .'">'
363
+ .$listingTitle
364
+ .'</a>';
365
+ }
366
+
367
+ if (!is_null($row->getData('magento_sku'))) {
368
+ $tempSku = $row->getData('magento_sku');
369
+
370
+ $value .= '<br/><strong>'
371
+ . Mage::helper('M2ePro')->__('SKU')
372
+ . ':</strong> '
373
+ . Mage::helper('M2ePro')->escapeHtml($tempSku);
374
+ }
375
+
376
+ if (is_null($row->getData('listing_product_id'))) {
377
+ return $value;
378
+ }
379
+
380
+ $listingProductId = (int)$row->getData('listing_product_id');
381
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
382
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
383
+
384
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationProduct() &&
385
+ $listingProduct->getChildObject()->getVariationManager()->isVariationProductMatched()
386
+ ) {
387
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()->getProductOptions();
388
+
389
+ $value .= '<br/>';
390
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
391
+ foreach ($productOptions as $attribute => $option) {
392
+ !$option && $option = '--';
393
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
394
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
395
+ }
396
+ $value .= '</div>';
397
+ $value .= '<br/>';
398
+ }
399
+
400
+ return $value;
401
+ }
402
+
403
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
404
+ {
405
+ if (is_null($row->getData('is_in_stock'))) {
406
+ return Mage::helper('M2ePro')->__('N/A');
407
+ }
408
+
409
+ if ((int)$row->getData('is_in_stock') <= 0) {
410
+ return '<span style="color: red;">'.$value.'</span>';
411
+ }
412
+
413
+ return $value;
414
+ }
415
+
416
+ public function callbackColumnSku($value, $row, $column, $isExport)
417
+ {
418
+ if (is_null($value) || $value === '') {
419
+ return Mage::helper('M2ePro')->__('N/A');
420
+ }
421
+ return $value;
422
+ }
423
+
424
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
425
+ {
426
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
427
+ if (is_null($value) || $value === '') {
428
+ return Mage::helper('M2ePro')->__('N/A');
429
+ }
430
+ } else {
431
+ if (is_null($value) || $value === '') {
432
+ return '<i style="color:gray;">receiving...</i>';
433
+ }
434
+ }
435
+
436
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
437
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
438
+ }
439
+
440
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
441
+ {
442
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
443
+ if (is_null($value) || $value === '') {
444
+ return Mage::helper('M2ePro')->__('N/A');
445
+ }
446
+ } else {
447
+ if (is_null($value) || $value === '') {
448
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
449
+ }
450
+ }
451
+
452
+ if ($value <= 0) {
453
+ return '<span style="color: red;">0</span>';
454
+ }
455
+
456
+ return $value;
457
+ }
458
+
459
+ public function callbackColumnPrice($value, $row, $column, $isExport)
460
+ {
461
+ if ((int)$row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
462
+ if (is_null($value) || $value === '') {
463
+ return Mage::helper('M2ePro')->__('N/A');
464
+ }
465
+ } else {
466
+ if (is_null($value) || $value === '') {
467
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
468
+ }
469
+ }
470
+
471
+ if ((float)$value <= 0) {
472
+ return '<span style="color: #f00;">0</span>';
473
+ }
474
+
475
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
476
+ }
477
+
478
+ public function callbackColumnStatus($value, $row, $column, $isExport)
479
+ {
480
+ switch ($row->getData('status')) {
481
+
482
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
483
+ $value = '<span style="color: gray;">' . $value . '</span>';
484
+ break;
485
+
486
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
487
+ $value = '<span style="color: green;">' . $value . '</span>';
488
+ break;
489
+
490
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
491
+ $value = '<span style="color: red;">'.$value.'</span>';
492
+ break;
493
+
494
+ default:
495
+ break;
496
+ }
497
+
498
+ if (is_null($row->getData('listing_product_id'))) {
499
+ return $value;
500
+ }
501
+
502
+ $listingProductId = (int)$row->getData('listing_product_id');
503
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
504
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
505
+
506
+ $tempLocks = $listingProduct->getObjectLocks();
507
+
508
+ foreach ($tempLocks as $lock) {
509
+
510
+ switch ($lock->getTag()) {
511
+
512
+ case 'new_sku_action':
513
+ $title = Mage::helper('M2ePro')->__('Add New SKU in Progress...');
514
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
515
+ break;
516
+
517
+ case 'list_action':
518
+ $title = Mage::helper('M2ePro')->__('List in Progress...');
519
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
520
+ break;
521
+
522
+ case 'relist_action':
523
+ $title = Mage::helper('M2ePro')->__('Relist in Progress...');
524
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
525
+ break;
526
+
527
+ case 'revise_action':
528
+ $title = Mage::helper('M2ePro')->__('Revise in Progress...');
529
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
530
+ break;
531
+
532
+ case 'stop_action':
533
+ $title = Mage::helper('M2ePro')->__('Stop in Progress...');
534
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
535
+ break;
536
+
537
+ case 'stop_and_remove_action':
538
+ $title = Mage::helper('M2ePro')->__('Stop And Remove in Progress...');
539
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
540
+ break;
541
+
542
+ default:
543
+ break;
544
+
545
+ }
546
+ }
547
+
548
+ return $value;
549
+ }
550
+
551
+ public function callbackColumnActions($value, $row, $column, $isExport)
552
+ {
553
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to Listing'));
554
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
555
+
556
+ if ($row->getData('is_m2epro_listing')) {
557
+ $url = $this->getUrl('*/adminhtml_common_buy_listing/view/', array(
558
+ 'id'=>$row->getData('listing_id'),
559
+ 'filter'=>base64_encode(
560
+ 'product_id[from]='.(int)$row->getData('product_id')
561
+ .'&product_id[to]='.(int)$row->getData('product_id')
562
+ )
563
+ ));
564
+ } else {
565
+ $url = $this->getUrl('*/adminhtml_common_buy_listing_other/view/', array(
566
+ 'account' => $row->getData('account_id'),
567
+ 'marketplace' => $row->getData('marketplace_id'),
568
+ 'filter' => base64_encode(
569
+ 'title='.$row->getData('online_sku')
570
+ )
571
+ ));
572
+ }
573
+
574
+ $html = <<<HTML
575
+ <div style="float:right; margin:5px 15px 0 0;">
576
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" /></a>
577
+ </div>
578
+ HTML;
579
+
580
+ return $html;
581
+ }
582
+
583
+ protected function callbackFilterTitle($collection, $column)
584
+ {
585
+ $value = $column->getFilter()->getValue();
586
+
587
+ if ($value == null) {
588
+ return;
589
+ }
590
+
591
+ $collection->getSelect()
592
+ ->where('product_name LIKE ? OR magento_sku LIKE ? OR listing_title LIKE ?', '%'.$value.'%');
593
+ }
594
+
595
+ // ####################################
596
+
597
+ public function getGridUrl()
598
+ {
599
+ return $this->getUrl('*/adminhtml_common_buy_listing/searchGrid', array('_current'=>true));
600
+ }
601
+
602
+ public function getRowUrl($row)
603
+ {
604
+ return false;
605
+ }
606
+
607
+ // ####################################
608
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View.php ADDED
@@ -0,0 +1,598 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingView');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_listing_view';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
25
+
26
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
27
+ $headerText = Mage::helper('M2ePro')->__(
28
+ 'View %component_name% Listing',
29
+ Mage::helper('M2ePro/Component_Buy')->getTitle()
30
+ );
31
+ } else {
32
+ $headerText = Mage::helper('M2ePro')->__('View Listing ');
33
+ }
34
+
35
+ $this->_headerText = $headerText;
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 = $this->getUrl('*/adminhtml_common_log/listing', array(
50
+ 'id' => $listingData['id'],
51
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_BUY
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
+ $this->_addButton('edit_settings', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Edit Settings'),
63
+ 'onclick' => '',
64
+ 'class' => 'drop_down edit_settings_drop_down'
65
+ ));
66
+ //------------------------------
67
+
68
+ //------------------------------
69
+ $this->_addButton('add_products', array(
70
+ 'label' => Mage::helper('M2ePro')->__('Add Products'),
71
+ 'onclick' => '',
72
+ 'class' => 'add drop_down add_products_drop_down'
73
+ ));
74
+ //------------------------------
75
+ }
76
+
77
+ protected function _toHtml()
78
+ {
79
+ return '<div id="listing_view_progress_bar"></div>' .
80
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
81
+ '<div id="listing_view_content_container">'.
82
+ parent::_toHtml() .
83
+ '</div>';
84
+ }
85
+
86
+ public function getGridHtml()
87
+ {
88
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
89
+
90
+ /** @var $helper Ess_M2ePro_Helper_Data */
91
+ $helper = Mage::helper('M2ePro');
92
+
93
+ //------------------------------
94
+ $urls = $helper->getControllerActions(
95
+ 'adminhtml_common_listing_autoAction', array(
96
+ 'listing_id' => $this->getRequest()->getParam('id'),
97
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK
98
+ )
99
+ );
100
+ $showAutoAction = json_encode((bool)$this->getRequest()->getParam('auto_actions'));
101
+
102
+ $path = 'adminhtml_common_log/listingProduct';
103
+ $urls[$path] = $this->getUrl('*/' . $path, array(
104
+ 'channel' => Ess_M2ePro_Helper_Component_Buy::NICK,
105
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array('id' =>$listingData['id']))
106
+ ));
107
+
108
+ $path = 'adminhtml_common_listing/duplicateProducts';
109
+ $urls[$path] = $this->getUrl('*/' . $path);
110
+
111
+ $urls = json_encode($urls);
112
+ //------------------------------
113
+
114
+ $component = Ess_M2ePro_Helper_Component_Buy::NICK;
115
+ $layout = $this->getLayout();
116
+
117
+ $temp = Mage::helper('M2ePro/Data_Session')->getValue('products_ids_for_list', true);
118
+ $productsIdsForList = empty($temp) ? '' : $temp;
119
+
120
+ $gridId = 'buyListingViewGrid' . $listingData['id'];
121
+ $ignoreListings = json_encode(array($listingData['id']));
122
+
123
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing', array(
124
+ 'id' => $listingData['id'],
125
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_BUY,
126
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array('id' =>$listingData['id']))
127
+ ));
128
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
129
+
130
+ $runListProducts = $this->getUrl('*/adminhtml_common_buy_listing/runListProducts');
131
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_buy_listing/runReviseProducts');
132
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_buy_listing/runRelistProducts');
133
+ $runStopProducts = $this->getUrl('*/adminhtml_common_buy_listing/runStopProducts');
134
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_buy_listing/runStopAndRemoveProducts');
135
+
136
+ $prepareData = $this->getUrl('*/adminhtml_listing_moving/prepareMoveToListing');
137
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_moving/moveToListingGrid');
138
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_moving/getFailedProductsGrid');
139
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_moving/tryToMoveToListing');
140
+ $moveToListing = $this->getUrl('*/adminhtml_listing_moving/moveToListing');
141
+
142
+ $getVariationEditPopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationEditPopup');
143
+ $getVariationManagePopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationManagePopup');
144
+
145
+ $variationEditActionUrl = $this->getUrl('*/adminhtml_common_listing/variationEdit');
146
+ $variationManageActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManage');
147
+ $variationManageGenerateActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManageGenerate');
148
+
149
+ $popupTitle = $helper->escapeJs($helper->__('Moving Rakuten.com Items'));
150
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Rakuten.com Item'));
151
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
152
+
153
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
154
+ $taskCompletedSuccessMessage = $helper->escapeJs(
155
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
156
+ );
157
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
158
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
159
+ ));
160
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
161
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
162
+ ));
163
+
164
+ $lockedObjNoticeMessage = $helper->escapeJs(
165
+ $helper->__('Some Rakuten.com request(s) are being processed now.')
166
+ );
167
+ $sendingDataToBuyMessage = $helper->escapeJs($helper->__(
168
+ 'Sending %product_title% Product(s) data on Rakuten.com.'
169
+ ));
170
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
171
+
172
+ $listingLockedMessage = $helper->escapeJs(
173
+ $helper->__('The Listing was locked by another process. Please try again later.')
174
+ );
175
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
176
+
177
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
178
+ ->__('Listing All Items On Rakuten.com'));
179
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
180
+ ->__('Listing Selected Items On Rakuten.com'));
181
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
182
+ ->__('Revising Selected Items On Rakuten.com'));
183
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
184
+ ->__('Relisting Selected Items On Rakuten.com'));
185
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
186
+ ->__('Stopping Selected Items On Rakuten.com'));
187
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
188
+ ->escapeJs(Mage::helper('M2ePro')
189
+ ->__('Stopping On Rakuten.com And Removing From Listing Selected Items'));
190
+ $addNewSkuSelectedItemsMessage = Mage::helper('M2ePro')
191
+ ->escapeJs(Mage::helper('M2ePro')
192
+ ->__('Adding New SKU On Rakuten.com'));
193
+
194
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
195
+ $productsWereNotMovedMessage = $helper->escapeJs(
196
+ $helper->__('Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
197
+ );
198
+ $someProductsWereNotMovedMessage = $helper->escapeJs(
199
+ $helper->__('Some Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
200
+ );
201
+
202
+ $selectItemsMessage = $helper->escapeJs(
203
+ $helper->__('Please select the Products you want to perform the Action on.')
204
+ );
205
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
206
+
207
+ $successWord = $helper->escapeJs($helper->__('Success'));
208
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
209
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
210
+ $errorWord = $helper->escapeJs($helper->__('Error'));
211
+ $closeWord = $helper->escapeJs($helper->__('Close'));
212
+
213
+ $naString = Mage::helper('M2ePro')->__('N/A');
214
+ $assignString = Mage::helper('M2ePro')->__('Assign Rakuten.com SKU');
215
+
216
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
217
+
218
+ $searchBuyComSkuManual = $this->getUrl('*/adminhtml_common_buy_listing/searchBuyComSkuManual');
219
+ $suggestedBuyComSkuGridHmtl = $this->getUrl('*/adminhtml_common_buy_listing/getSuggestedBuyComSkuGrid');
220
+ $searchBuyComSkuAuto = $this->getUrl('*/adminhtml_common_buy_listing/searchBuyComSkuAuto');
221
+ $mapToBuyComSku = $this->getUrl('*/adminhtml_common_buy_listing/mapToBuyComSku');
222
+ $unmapFromBuyComSku = $this->getUrl('*/adminhtml_common_buy_listing/unmapFromBuyComSku');
223
+
224
+ $newGeneralId = $this->getUrl('*/adminhtml_common_buy_template_newProduct');
225
+
226
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
227
+ $marketplaceInstance = Mage::helper('M2ePro/Component_Buy')->getCachedObject('Marketplace',$marketplaceId);
228
+ $marketplace = json_encode($marketplaceInstance->getData());
229
+
230
+ $marketplaceSynchUrl = $this->getUrl(
231
+ '*/adminhtml_common_marketplace/index',
232
+ array('tab' => Ess_M2ePro_Block_Adminhtml_Common_Marketplace::TAB_ID_RAKUTEN)
233
+ );
234
+ $notSynchronizedMarketplace = $helper->escapeJs(
235
+ $helper->__(
236
+ 'In order to use New SKU functionality, please re-synchronize Marketplace data.'
237
+ ).' '.
238
+ $helper->__(
239
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
240
+ )
241
+ );
242
+
243
+ $enterProductSearchQueryMessage = $helper->escapeJs(
244
+ $helper->__('Please enter Product Title or Rakuten.com SKU/ISBN/UPC.')
245
+ );
246
+ $autoMapBuyComSkuProgressTitle = $helper->escapeJs($helper->__('Assign Rakuten.com SKU to Item(s)'));
247
+ $autoMapBuyComSkuErrorMessage = $helper->escapeJs(
248
+ $helper->__('Server is currently unavailable. Please try again later.')
249
+ );
250
+
251
+ $noVariationsLeftText = $helper->__('All Variations are already added.');
252
+
253
+ $translations = json_encode(array(
254
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
255
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
256
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
257
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
258
+ ));
259
+
260
+ $javascriptsMain = <<<JAVASCRIPT
261
+ <script type="text/javascript">
262
+
263
+ if (typeof M2ePro == 'undefined') {
264
+ M2ePro = {};
265
+ M2ePro.url = {};
266
+ M2ePro.formData = {};
267
+ M2ePro.customData = {};
268
+ M2ePro.text = {};
269
+ }
270
+
271
+ M2ePro.url.add({$urls});
272
+ M2ePro.translator.add({$translations});
273
+
274
+ M2ePro.productsIdsForList = '{$productsIdsForList}';
275
+
276
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
277
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
278
+
279
+ M2ePro.url.runListProducts = '{$runListProducts}';
280
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
281
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
282
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
283
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
284
+
285
+ M2ePro.url.searchBuyComSkuManual = '{$searchBuyComSkuManual}';
286
+ M2ePro.url.searchBuyComSkuAuto = '{$searchBuyComSkuAuto}';
287
+ M2ePro.url.suggestedBuyComSkuGrid = '{$suggestedBuyComSkuGridHmtl}';
288
+ M2ePro.url.mapToBuyComSku = '{$mapToBuyComSku}';
289
+ M2ePro.url.unmapFromBuyComSku = '{$unmapFromBuyComSku}';
290
+
291
+ M2ePro.url.prepareData = '{$prepareData}';
292
+ M2ePro.url.getGridHtml = '{$getMoveToListingGridHtml}';
293
+ M2ePro.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
294
+ M2ePro.url.tryToMoveToListing = '{$tryToMoveToListing}';
295
+ M2ePro.url.moveToListing = '{$moveToListing}';
296
+
297
+ M2ePro.url.get_variation_edit_popup = '{$getVariationEditPopupUrl}';
298
+ M2ePro.url.get_variation_manage_popup = '{$getVariationManagePopupUrl}';
299
+
300
+ M2ePro.url.variation_edit_action = '{$variationEditActionUrl}';
301
+ M2ePro.url.variation_manage_action = '{$variationManageActionUrl}';
302
+ M2ePro.url.variation_manage_generate_action = '{$variationManageGenerateActionUrl}';
303
+
304
+ M2ePro.url.newGeneralId = '{$newGeneralId}';
305
+ M2ePro.url.marketplace_synch = '{$marketplaceSynchUrl}';
306
+
307
+ M2ePro.text.popup_title = '{$popupTitle}';
308
+ M2ePro.text.popup_title_single = '{$popupTitleSingle}';
309
+ M2ePro.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
310
+
311
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
312
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
313
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
314
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
315
+
316
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
317
+ M2ePro.text.sending_data_message = '{$sendingDataToBuyMessage}';
318
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
319
+
320
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
321
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
322
+
323
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
324
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
325
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
326
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
327
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
328
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
329
+ M2ePro.text.add_new_sku_selected_items_message = '{$addNewSkuSelectedItemsMessage}';
330
+
331
+ M2ePro.text.successfully_moved = '{$successfullyMovedMessage}';
332
+ M2ePro.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
333
+ M2ePro.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
334
+
335
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
336
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
337
+
338
+ M2ePro.text.success_word = '{$successWord}';
339
+ M2ePro.text.notice_word = '{$noticeWord}';
340
+ M2ePro.text.warning_word = '{$warningWord}';
341
+ M2ePro.text.error_word = '{$errorWord}';
342
+ M2ePro.text.close_word = '{$closeWord}';
343
+
344
+ M2ePro.text.na = '{$naString}';
345
+ M2ePro.text.assign = '{$assignString}';
346
+
347
+ M2ePro.text.confirm = '{$textConfirm}';
348
+
349
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
350
+ M2ePro.text.automap_buy_com_sku_progress_title = '{$autoMapBuyComSkuProgressTitle}';
351
+ M2ePro.text.automap_error_message = '{$autoMapBuyComSkuErrorMessage}';
352
+
353
+ M2ePro.text.no_variations_left = '{$noVariationsLeftText}';
354
+
355
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
356
+
357
+ M2ePro.customData.componentMode = '{$component}';
358
+ M2ePro.customData.gridId = '{$gridId}';
359
+ M2ePro.customData.ignoreListings = '{$ignoreListings}';
360
+
361
+ M2ePro.customData.marketplace = {$marketplace};
362
+
363
+ Event.observe(window, 'load', function() {
364
+
365
+ ListingGridHandlerObj = new CommonBuyListingGridHandler(
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 CommonListingProductVariationHandler(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
+
597
+ // ####################################
598
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Grid.php ADDED
@@ -0,0 +1,974 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'template_new_product_id' => 'template_new_product_id',
81
+ 'general_id' => 'general_id',
82
+ 'buy_sku' => 'sku',
83
+ 'online_price' => 'online_price',
84
+ 'online_qty' => 'online_qty',
85
+ 'search_settings_status' => 'search_settings_status',
86
+ 'search_settings_data' => 'search_settings_data'
87
+ ),
88
+ null
89
+ );
90
+ //----------------------------
91
+
92
+ //exit($collection->getSelect()->__toString());
93
+
94
+ // Set collection to grid
95
+ $this->setCollection($collection);
96
+
97
+ return parent::_prepareCollection();
98
+ }
99
+
100
+ protected function _prepareColumns()
101
+ {
102
+ $this->addColumn('product_id', array(
103
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
104
+ 'align' => 'right',
105
+ 'width' => '100px',
106
+ 'type' => 'number',
107
+ 'index' => 'entity_id',
108
+ 'filter_index' => 'entity_id',
109
+ 'frame_callback' => array($this, 'callbackColumnProductId')
110
+ ));
111
+
112
+ $this->addColumn('name', array(
113
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
114
+ 'align' => 'left',
115
+ //'width' => '300px',
116
+ 'type' => 'text',
117
+ 'index' => 'name',
118
+ 'filter_index' => 'name',
119
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
120
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
121
+ ));
122
+
123
+ $this->addColumn('sku', array(
124
+ 'header' => Mage::helper('M2ePro')->__('Reference ID'),
125
+ 'align' => 'left',
126
+ 'width' => '150px',
127
+ 'type' => 'text',
128
+ 'index' => 'buy_sku',
129
+ 'filter_index' => 'buy_sku',
130
+ 'frame_callback' => array($this, 'callbackColumnSku')
131
+ ));
132
+
133
+ $this->addColumn('general_id', array(
134
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
135
+ 'align' => 'left',
136
+ 'width' => '80px',
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' => '125px',
166
+ 'index' => 'buy_status',
167
+ 'filter_index' => 'buy_status',
168
+ 'type' => 'options',
169
+ 'sortable' => false,
170
+ 'options' => array(
171
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
172
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
173
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
174
+ ),
175
+ 'frame_callback' => array($this, 'callbackColumnStatus')
176
+ ));
177
+
178
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
179
+ $this->addColumn('developer_action', array(
180
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
181
+ 'align' => 'left',
182
+ 'width' => '120px',
183
+ 'type' => 'text',
184
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
185
+ 'index' => 'value',
186
+ 'filter' => false,
187
+ 'sortable' => false,
188
+ 'js_handler' => 'ListingGridHandlerObj'
189
+ ));
190
+ }
191
+
192
+ return parent::_prepareColumns();
193
+ }
194
+
195
+ protected function _prepareMassaction()
196
+ {
197
+ // Set massaction identifiers
198
+ //--------------------------------
199
+ $this->setMassactionIdField('id');
200
+ $this->setMassactionIdFieldOnlyIndexValue(true);
201
+ //--------------------------------
202
+
203
+ // Set mass-action
204
+ //--------------------------------
205
+ $groups = array(
206
+ 'actions' => Mage::helper('M2ePro')->__('Actions'),
207
+ 'rekuten_sku' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
208
+ 'other' => Mage::helper('M2ePro')->__('Other')
209
+ );
210
+
211
+ $this->getMassactionBlock()->setGroups($groups);
212
+
213
+ $this->getMassactionBlock()->addItem('list', array(
214
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
215
+ 'url' => '',
216
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
217
+ ), 'actions');
218
+
219
+ $this->getMassactionBlock()->addItem('revise', array(
220
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
221
+ 'url' => '',
222
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
223
+ ), 'actions');
224
+
225
+ $this->getMassactionBlock()->addItem('relist', array(
226
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
227
+ 'url' => '',
228
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
229
+ ), 'actions');
230
+
231
+ $this->getMassactionBlock()->addItem('stop', array(
232
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
233
+ 'url' => '',
234
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
235
+ ), 'actions');
236
+
237
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
238
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
239
+ 'url' => '',
240
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
241
+ ), 'actions');
242
+
243
+ $this->getMassactionBlock()->addItem('newGeneralId', array(
244
+ 'label' => Mage::helper('M2ePro')->__('Add New'),
245
+ 'url' => '',
246
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
247
+ ), 'rekuten_sku');
248
+
249
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
250
+ 'label' => Mage::helper('M2ePro')->__('Assign'),
251
+ 'url' => '',
252
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
253
+ ), 'rekuten_sku');
254
+
255
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
256
+ 'label' => Mage::helper('M2ePro')->__('Unassign'),
257
+ 'url' => '',
258
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
259
+ ), 'rekuten_sku');
260
+
261
+ $this->getMassactionBlock()->addItem('moving', array(
262
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Another Listing'),
263
+ 'url' => '',
264
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
265
+ ), 'other');
266
+
267
+ $this->getMassactionBlock()->addItem('duplicate', array(
268
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
269
+ 'url' => '',
270
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
271
+ ), 'other');
272
+ //--------------------------------
273
+
274
+ return parent::_prepareMassaction();
275
+ }
276
+
277
+ public function getMassactionBlockName()
278
+ {
279
+ return 'M2ePro/adminhtml_grid_massaction';
280
+ }
281
+
282
+ // ####################################
283
+
284
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
285
+ {
286
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
287
+
288
+ $value = '<span>'.$productTitle.'</span>';
289
+
290
+ $tempSku = $row->getData('sku');
291
+ is_null($tempSku)
292
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
293
+
294
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
295
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
296
+
297
+ $listingProductId = (int)$row->getData('id');
298
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
299
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product', $listingProductId);
300
+
301
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
302
+ return $value;
303
+ }
304
+
305
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()->getProductOptions();
306
+
307
+ if (!empty($productOptions)) {
308
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
309
+ foreach ($productOptions as $attribute => $option) {
310
+ !$option && $option = '--';
311
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
312
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
313
+ }
314
+ $value .= '</div>';
315
+ }
316
+
317
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProductMatched()) {
318
+
319
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
320
+ Mage::helper('M2ePro')->__('Manage "%product_title%" Options', $productTitle))
321
+ );
322
+ $linkTitle = Mage::helper('M2ePro')->__('Manage Options');
323
+ $linkContent = '<img height="12" width="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
324
+
325
+ $value.= <<<HTML
326
+ <div style="clear: both"></div>
327
+ <div style="float: left; margin: 0 0 0 5px">
328
+ <a href="javascript:"
329
+ onclick="ListingProductVariationHandlerObj
330
+ .setListingProductId({$listingProductId})
331
+ .showManagePopup('{$popupTitle}');"
332
+ title="{$linkTitle}">{$linkContent}</a>
333
+ </div>
334
+ HTML;
335
+
336
+ $linkContent = Mage::helper('M2ePro')->__('Manage Options');
337
+
338
+ $value .= <<<HTML
339
+ <div style="float: left; margin: 0 0 0 5px">
340
+ <a href="javascript:"
341
+ onclick="ListingProductVariationHandlerObj
342
+ .setListingProductId({$listingProductId})
343
+ .showManagePopup('{$popupTitle}');"
344
+ title="{$linkTitle}">{$linkContent}</a>
345
+ </div>
346
+ HTML;
347
+
348
+ return $value;
349
+ }
350
+
351
+ // ---------------------------------
352
+ $hasInActionLock = $this->getLockedData($row);
353
+ $hasInActionLock = $hasInActionLock['in_action'];
354
+ // ---------------------------------
355
+
356
+ if (!$hasInActionLock) {
357
+
358
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
359
+ Mage::helper('M2ePro')->__('Edit "%product_title%" Variation', $productTitle))
360
+ );
361
+ $linkTitle = Mage::helper('M2ePro')->__('Edit Variation');
362
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/pencil.png').'">';
363
+
364
+ $value .= <<<HTML
365
+ <div style="clear: both"></div>
366
+ <div style="margin: 0 0 0 7px; float: left;">
367
+ <a href="javascript:"
368
+ onclick="ListingProductVariationHandlerObj
369
+ .setListingProductId({$listingProductId})
370
+ .showEditPopup('{$popupTitle}');"
371
+ title="{$linkTitle}">{$linkContent}</a>
372
+ </div>
373
+ HTML;
374
+ }
375
+
376
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
377
+ Mage::helper('M2ePro')->__('Add Another "%product_title%" Variations', $productTitle))
378
+ );
379
+ $linkTitle = Mage::helper('M2ePro')->__('Add Another Variation(s)');
380
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
381
+
382
+ $value.= <<<HTML
383
+ <div style="margin: 0 0 0 5px; float: left;">
384
+ <a href="javascript:"
385
+ onclick="ListingProductVariationHandlerObj
386
+ .setListingProductId({$listingProductId})
387
+ .showManagePopup('{$popupTitle}');"
388
+ title="{$linkTitle}">{$linkContent}</a>
389
+ </div>
390
+ HTML;
391
+
392
+ return $value;
393
+ }
394
+
395
+ public function callbackColumnSku($value, $row, $column, $isExport)
396
+ {
397
+ if (is_null($value) || $value === '') {
398
+ return Mage::helper('M2ePro')->__('N/A');
399
+ }
400
+ return $value;
401
+ }
402
+
403
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
404
+ {
405
+ if (empty($generalId)) {
406
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
407
+ }
408
+
409
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
410
+ }
411
+
412
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
413
+ {
414
+ if ((int)$row->getData('buy_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
415
+ if (is_null($value) || $value === '') {
416
+ return Mage::helper('M2ePro')->__('N/A');
417
+ }
418
+ } else {
419
+ if (is_null($value) || $value === '') {
420
+ return '<i style="color:gray;">receiving...</i>';
421
+ }
422
+ }
423
+
424
+ if ($value <= 0) {
425
+ return '<span style="color: red;">0</span>';
426
+ }
427
+
428
+ return $value;
429
+ }
430
+
431
+ public function callbackColumnPrice($value, $row, $column, $isExport)
432
+ {
433
+ if ((int)$row->getData('buy_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
434
+ if (is_null($value) || $value === '') {
435
+ return Mage::helper('M2ePro')->__('N/A');
436
+ }
437
+ } else {
438
+ if (is_null($value) || $value === '') {
439
+ return '<i style="color:gray;">receiving...</i>';
440
+ }
441
+ }
442
+
443
+ if ((float)$value <= 0) {
444
+ return '<span style="color: #f00;">0</span>';
445
+ }
446
+
447
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
448
+ }
449
+
450
+ public function callbackColumnStatus($value, $row, $column, $isExport)
451
+ {
452
+ $listingProductId = (int)$row->getData('id');
453
+
454
+ $html = $this->getViewLogIconHtml($listingProductId);
455
+
456
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
457
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
458
+
459
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
460
+ if (!empty($synchNote)) {
461
+
462
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
463
+
464
+ if (empty($html)) {
465
+ $html = <<<HTML
466
+ <span style="float:right;">
467
+ <img id="map_link_error_icon_{$row->getId()}"
468
+ class="tool-tip-image"
469
+ style="vertical-align: middle;"
470
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
471
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
472
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
473
+ <span>{$synchNote}</span>
474
+ </span>
475
+ </span>
476
+ HTML;
477
+ } else {
478
+ $html .= <<<HTML
479
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
480
+ HTML;
481
+ }
482
+ }
483
+
484
+ switch ($row->getData('buy_status')) {
485
+
486
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
487
+ $html .= '<span style="color: gray;">' . $value . '</span>';
488
+ break;
489
+
490
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
491
+ $html .= '<span style="color: green;">' . $value . '</span>';
492
+ break;
493
+
494
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
495
+ $html .= '<span style="color: red;">'.$value.'</span>';
496
+ break;
497
+
498
+ default:
499
+ break;
500
+ }
501
+
502
+ $tempLocks = $this->getLockedData($row);
503
+ $tempLocks = $tempLocks['object_locks'];
504
+
505
+ foreach ($tempLocks as $lock) {
506
+
507
+ switch ($lock->getTag()) {
508
+
509
+ case 'newsku_action':
510
+ $html .= '<br/><span style="color: #605fff">[Add New SKU in Progress...]</span>';
511
+ break;
512
+
513
+ case 'list_action':
514
+ $html .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
515
+ break;
516
+
517
+ case 'relist_action':
518
+ $html .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
519
+ break;
520
+
521
+ case 'revise_action':
522
+ $html .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
523
+ break;
524
+
525
+ case 'stop_action':
526
+ $html .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
527
+ break;
528
+
529
+ case 'stop_and_remove_action':
530
+ $html .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
531
+ break;
532
+
533
+ default:
534
+ break;
535
+ }
536
+ }
537
+
538
+ return $html;
539
+ }
540
+
541
+ protected function callbackFilterTitle($collection, $column)
542
+ {
543
+ $value = $column->getFilter()->getValue();
544
+
545
+ if ($value == null) {
546
+ return;
547
+ }
548
+
549
+ $collection->addFieldToFilter(
550
+ array(
551
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
552
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
553
+ )
554
+ );
555
+ }
556
+
557
+ // ############################################
558
+
559
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
560
+ {
561
+ // ---------------------------------
562
+ if ((int)$row->getData('buy_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
563
+ return <<<HTML
564
+ <i style="color:gray;">receiving...</i>
565
+ HTML;
566
+ }
567
+ // ---------------------------------
568
+
569
+ // ---------------------------------
570
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
571
+ // ---------------------------------
572
+
573
+ // ---------------------------------
574
+ $lpId = $row->getData('id');
575
+
576
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
577
+ if (strlen($productTitle) > 60) {
578
+ $productTitle = substr($productTitle, 0, 60) . '...';
579
+ }
580
+ $productTitle = Mage::helper('M2ePro')->__('Assign Rakuten.com SKU For &quot;%product_title%&quot;',
581
+ $productTitle);
582
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
583
+ // ---------------------------------
584
+
585
+ // ---------------------------------
586
+ $hasInActionLock = $this->getLockedData($row);
587
+ $hasInActionLock = $hasInActionLock['in_action'];
588
+ // ---------------------------------
589
+
590
+ $na = Mage::helper('M2ePro')->__('N/A');
591
+
592
+ $templateNewProductId = $row->getData('template_new_product_id');
593
+ if (!empty($templateNewProductId)) {
594
+
595
+ $newSkuTemplateUrl = $this->getUrl(
596
+ '*/adminhtml_common_buy_template_newProduct/edit/',
597
+ array(
598
+ 'id' => $templateNewProductId,
599
+ 'listing_product_id' => $lpId,
600
+ 'save_and_assign' => 0,
601
+ 'back' => Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/view',array(
602
+ 'id' => $row->getData('listing_id'),
603
+ ))
604
+ )
605
+ );
606
+
607
+ $newSkuTemplateTitle = Mage::getModel('M2ePro/Buy_Template_NewProduct')
608
+ ->load($templateNewProductId)
609
+ ->getData('title');
610
+
611
+ if ($hasInActionLock) {
612
+ return $newSkuTemplateTitle;
613
+ }
614
+
615
+ $tip = Mage::helper('M2ePro')->__('Unassign New SKU Policy');
616
+ $iconSrc = $iconPath.'unassign.png';
617
+
618
+ return <<<HTML
619
+ <a href="{$newSkuTemplateUrl}">{$newSkuTemplateTitle}</a>
620
+ <a href="javascript:;" title="{$tip}"
621
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt('{$lpId}');">
622
+ <img src="{$iconSrc}" alt="" width="16" height="16">
623
+ </a>
624
+ HTML;
625
+ }
626
+ // ---------------------------------
627
+
628
+ // ---------------------------------
629
+ $searchSettingsData = $row->getData('search_settings_data');
630
+
631
+ if (!is_null($searchSettingsData)) {
632
+ $searchSettingsData = @json_decode($searchSettingsData,true);
633
+ }
634
+ // ---------------------------------
635
+
636
+ if (!empty($searchSettingsData['data'])) {
637
+
638
+ $tip = Mage::helper('M2ePro')->__('Choose Rakuten.com SKU from the list');
639
+ $iconSrc = $iconPath.'list.png';
640
+
641
+ return <<<HTML
642
+ {$na} &nbsp;
643
+ <a href="javascript:;" title="{$tip}"
644
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">
645
+ <img src="{$iconSrc}" alt="" width="16" height="16">
646
+ </a>
647
+ HTML;
648
+ }
649
+
650
+ $searchSettingsStatus = $row->getData('search_settings_status');
651
+
652
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Buy_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND) {
653
+
654
+ $tip = Mage::helper('M2ePro')->__(
655
+ 'There were no Products found on Rakuten.com according to the Listing Search Settings.'
656
+ );
657
+ $tip = Mage::helper('M2ePro')->escapeJs($tip);
658
+
659
+ $iconSrc = $iconPath.'error.png';
660
+
661
+ return <<<HTML
662
+ {$na} &nbsp;
663
+ <a href="javascript: void(0);" title="{$tip}"
664
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId},'{$tip}');">
665
+ <img src="{$iconSrc}" alt="" width="16" height="16">
666
+ </a>
667
+ HTML;
668
+ }
669
+
670
+ $tip = Mage::helper('M2ePro')->__('Search for Rakuten.com SKU');
671
+ $iconSrc = $iconPath.'search.png';
672
+
673
+ return <<<HTML
674
+ {$na} &nbsp;
675
+ <a href="javascript:;" title="{$tip}"
676
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId});">
677
+ <img src="{$iconSrc}" alt="" width="16" height="16">
678
+ </a>
679
+ HTML;
680
+ }
681
+
682
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
683
+ {
684
+ $generalId = $row->getData('general_id');
685
+
686
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($generalId);
687
+
688
+ if ((int)$row->getData('buy_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
689
+ $conditionTitle = '';
690
+ switch ((int)$row->getData('condition')) {
691
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_NEW:
692
+ $conditionTitle = Mage::helper('M2ePro')->__('New');
693
+ break;
694
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_LIKE_NEW:
695
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Like New');
696
+ break;
697
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_VERY_GOOD:
698
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Very Good');
699
+ break;
700
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_GOOD:
701
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Good');
702
+ break;
703
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_USED_ACCEPTABLE:
704
+ $conditionTitle = Mage::helper('M2ePro')->__('Used - Acceptable');
705
+ break;
706
+ case Ess_M2ePro_Model_Buy_Listing::CONDITION_REFURBISHED:
707
+ $conditionTitle = Mage::helper('M2ePro')->__('Refurbished');
708
+ break;
709
+ }
710
+ return <<<HTML
711
+ <a href="{$url}" target="_blank">{$generalId}</a><br/>
712
+ <span style="color:gray;">{$conditionTitle}</span>
713
+ HTML;
714
+ }
715
+
716
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
717
+
718
+ $generalIdSearchInfo = @json_decode($row->getData('general_id_search_info'), true);
719
+
720
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
721
+
722
+ $tip = Mage::helper('M2ePro')->__('Rakuten.com SKU was found automatically');
723
+
724
+ $text = <<<HTML
725
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
726
+ HTML;
727
+
728
+ } else {
729
+
730
+ $text = <<<HTML
731
+ <a href="{$url}" target="_blank">{$generalId}</a>
732
+ HTML;
733
+
734
+ }
735
+
736
+ // ---------------------------------
737
+ $hasInActionLock = $this->getLockedData($row);
738
+ $hasInActionLock = $hasInActionLock['in_action'];
739
+ // ---------------------------------
740
+
741
+ if ($hasInActionLock) {
742
+ return $text;
743
+ }
744
+
745
+ $tip = Mage::helper('M2ePro')->__('Unassign Rakuten.com SKU');
746
+ $iconSrc = $iconPath.'unassign.png';
747
+
748
+ $id = $row->getData('id');
749
+
750
+ $text .= <<<HTML
751
+ <a href="javascript:;" onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$id});"
752
+ title="{$tip}">
753
+ <img src="{$iconSrc}" width="16" height="16"/>
754
+ </a>
755
+ HTML;
756
+
757
+ return $text;
758
+ }
759
+
760
+ // ############################################
761
+
762
+ public function getViewLogIconHtml($listingProductId)
763
+ {
764
+ $listingProductId = (int)$listingProductId;
765
+
766
+ // Get last messages
767
+ //--------------------------
768
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
769
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
770
+
771
+ $dbSelect = $connRead->select()
772
+ ->from(
773
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
774
+ array('action_id','action','type','description','create_date','initiator')
775
+ )
776
+ ->where('`listing_product_id` = ?',$listingProductId)
777
+ ->where('`action_id` IS NOT NULL')
778
+ ->order(array('id DESC'))
779
+ ->limit(30);
780
+
781
+ $logRows = $connRead->fetchAll($dbSelect);
782
+ //--------------------------
783
+
784
+ // Get grouped messages by action_id
785
+ //--------------------------
786
+ $actionsRows = array();
787
+ $tempActionRows = array();
788
+ $lastActionId = false;
789
+
790
+ foreach ($logRows as $row) {
791
+
792
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
793
+
794
+ if ($row['action_id'] !== $lastActionId) {
795
+ if (count($tempActionRows) > 0) {
796
+ $actionsRows[] = array(
797
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
798
+ 'date' => $this->getMainDateForActionId($tempActionRows),
799
+ 'action' => $this->getActionForAction($tempActionRows[0]),
800
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
801
+ 'items' => $tempActionRows
802
+ );
803
+ $tempActionRows = array();
804
+ }
805
+ $lastActionId = $row['action_id'];
806
+ }
807
+ $tempActionRows[] = $row;
808
+ }
809
+
810
+ if (count($tempActionRows) > 0) {
811
+ $actionsRows[] = array(
812
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
813
+ 'date' => $this->getMainDateForActionId($tempActionRows),
814
+ 'action' => $this->getActionForAction($tempActionRows[0]),
815
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
816
+ 'items' => $tempActionRows
817
+ );
818
+ }
819
+
820
+ if (count($actionsRows) <= 0) {
821
+ return '';
822
+ }
823
+
824
+ $tips = array(
825
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
826
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
827
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
828
+ );
829
+
830
+ $icons = array(
831
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
832
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
833
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
834
+ );
835
+
836
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
837
+ 'entity_id' => $listingProductId,
838
+ 'rows' => $actionsRows,
839
+ 'tips' => $tips,
840
+ 'icons' => $icons,
841
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
842
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
843
+ ));
844
+
845
+ return $summary->toHtml();
846
+ }
847
+
848
+ public function getActionForAction($actionRows)
849
+ {
850
+ $string = '';
851
+
852
+ switch ($actionRows['action']) {
853
+ case Ess_M2ePro_Model_Listing_Log::ACTION_NEW_SKU_PRODUCT_ON_COMPONENT:
854
+ $string = Mage::helper('M2ePro')->__('New SKU');
855
+ break;
856
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
857
+ $string = Mage::helper('M2ePro')->__('List');
858
+ break;
859
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
860
+ $string = Mage::helper('M2ePro')->__('Relist');
861
+ break;
862
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
863
+ $string = Mage::helper('M2ePro')->__('Revise');
864
+ break;
865
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
866
+ $string = Mage::helper('M2ePro')->__('Stop');
867
+ break;
868
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
869
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
870
+ break;
871
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
872
+ $string = Mage::helper('M2ePro')->__('Channel Change');
873
+ break;
874
+ }
875
+
876
+ return $string;
877
+ }
878
+
879
+ public function getInitiatorForAction($actionRows)
880
+ {
881
+ $string = '';
882
+
883
+ switch ((int)$actionRows['initiator']) {
884
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
885
+ $string = '';
886
+ break;
887
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
888
+ $string = Mage::helper('M2ePro')->__('Manual');
889
+ break;
890
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
891
+ $string = Mage::helper('M2ePro')->__('Automatic');
892
+ break;
893
+ }
894
+
895
+ return $string;
896
+ }
897
+
898
+ public function getMainTypeForActionId($actionRows)
899
+ {
900
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
901
+
902
+ foreach ($actionRows as $row) {
903
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
904
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
905
+ break;
906
+ }
907
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
908
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
909
+ }
910
+ }
911
+
912
+ return $type;
913
+ }
914
+
915
+ public function getMainDateForActionId($actionRows)
916
+ {
917
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
918
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
919
+ }
920
+
921
+ // ####################################
922
+
923
+ public function getGridUrl()
924
+ {
925
+ return $this->getUrl('*/adminhtml_common_buy_listing/viewGrid', array('_current'=>true));
926
+ }
927
+
928
+ public function getRowUrl($row)
929
+ {
930
+ return false;
931
+ }
932
+
933
+ // ####################################
934
+
935
+ protected function _toHtml()
936
+ {
937
+ $javascriptsMain = <<<JAVASCRIPT
938
+ <script type="text/javascript">
939
+
940
+ if (typeof ListingGridHandlerObj != 'undefined') {
941
+ ListingGridHandlerObj.afterInitPage();
942
+ }
943
+
944
+ Event.observe(window, 'load', function() {
945
+ setTimeout(function() {
946
+ ListingGridHandlerObj.afterInitPage();
947
+ }, 350);
948
+ });
949
+
950
+ </script>
951
+ JAVASCRIPT;
952
+
953
+ return parent::_toHtml().$javascriptsMain;
954
+ }
955
+
956
+ // ####################################
957
+
958
+ private function getLockedData($row)
959
+ {
960
+ $listingProductId = $row->getData('id');
961
+ if (!isset($this->lockedDataCache[$listingProductId])) {
962
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($listingProductId)->getObjectLocks();
963
+ $tempArray = array(
964
+ 'object_locks' => $objectLocks,
965
+ 'in_action' => !empty($objectLocks),
966
+ );
967
+ $this->lockedDataCache[$listingProductId] = $tempArray;
968
+ }
969
+
970
+ return $this->lockedDataCache[$listingProductId];
971
+ }
972
+
973
+ // ####################################
974
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Help.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyListingViewHelp');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/listing/view/help.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/ListingSwitcher.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+
18
+ $this->setAddListingUrl('*/adminhtml_common_listing_create/index/step/1/component/buy/');
19
+ }
20
+
21
+ // ####################################
22
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
11
+
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ //------------------------------
18
+ $this->setId('buyOrderEditShippingAddress');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_buy_order_edit';
21
+ $this->_mode = 'shippingAddress';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $this->_headerText = Mage::helper('M2ePro')->__('Edit Shipping Address');
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
40
+ //------------------------------
41
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
42
+ $this->_addButton('back', array(
43
+ 'label' => Mage::helper('M2ePro')->__('Back'),
44
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
45
+ 'class' => 'back'
46
+ ));
47
+ //------------------------------
48
+ } else {
49
+ //------------------------------
50
+ $url = $this->getUrl('*/*/view', array('id' => $this->getRequest()->getParam('id')));
51
+ $this->_addButton('back', array(
52
+ 'label' => Mage::helper('M2ePro')->__('Back'),
53
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
54
+ 'class' => 'back'
55
+ ));
56
+ //------------------------------
57
+ }
58
+
59
+ //------------------------------
60
+ $this->_addButton('save', array(
61
+ 'label' => Mage::helper('M2ePro')->__('Save Order Address'),
62
+ 'onclick' => 'CommonHandlerObj.save_click()',
63
+ 'class' => 'save'
64
+ ));
65
+ //------------------------------
66
+ }
67
+
68
+ // ####################################
69
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress/Form.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_Buy_Order_Edit_ShippingAddress_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ private $order;
10
+
11
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('buyOrderEditShippingAddressForm');
20
+ //------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/buy/order/edit/shipping_address.phtml');
23
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
24
+ }
25
+
26
+ protected function _prepareForm()
27
+ {
28
+ $form = new Varien_Data_Form(array(
29
+ 'id' => 'edit_form',
30
+ 'action' => $this->getUrl('*/*/save'),
31
+ 'method' => 'post',
32
+ 'enctype' => 'multipart/form-data'
33
+ ));
34
+
35
+ $form->setUseContainer(true);
36
+ $this->setForm($form);
37
+
38
+ return parent::_prepareForm();
39
+ }
40
+
41
+ protected function _beforeToHtml()
42
+ {
43
+ try {
44
+ $regionCode = $this->order->getShippingAddress()->getRegionCode();
45
+ } catch (Exception $e) {
46
+ $regionCode = null;
47
+ }
48
+
49
+ $this->setData('buyer_name', $this->order->getData('buyer_name'));
50
+ $this->setData('buyer_email', $this->order->getData('buyer_email'));
51
+ $this->setData('address', $this->order->getShippingAddress()->getData());
52
+ $this->setData('region_code', $regionCode);
53
+ $this->setData('company', $this->order->getChildObject()->getBillingAddress()->getData('company'));
54
+ $this->setData('phone', $this->order->getChildObject()->getBillingAddress()->getData('phone'));
55
+
56
+ return parent::_beforeToHtml();
57
+ }
58
+
59
+ // ####################################
60
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Grid.php ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('buyOrderGrid');
21
+ //------------------------------
22
+
23
+ // Set default values
24
+ //------------------------------
25
+ $this->setDefaultSort('purchase_create_date');
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
+ protected function _prepareCollection()
38
+ {
39
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Order');
40
+
41
+ $collection->getSelect()->joinLeft(
42
+ array('so' => Mage::getSingleton('core/resource')->getTableName('sales/order')),
43
+ '(so.entity_id = `main_table`.magento_order_id)',
44
+ array('magento_order_num' => 'increment_id')
45
+ );
46
+
47
+ // Add Filter By Account
48
+ //------------------------------
49
+ if ($accountId = $this->getRequest()->getParam('buyAccount')) {
50
+ $collection->addFieldToFilter('`main_table`.account_id', $accountId);
51
+ }
52
+ //------------------------------
53
+
54
+ // Add Not Created Magento Orders Filter
55
+ //------------------------------
56
+ if ($this->getRequest()->getParam('not_created_only')) {
57
+ $collection->addFieldToFilter('magento_order_id', array('null' => true));
58
+ }
59
+ //------------------------------
60
+
61
+ $this->setCollection($collection);
62
+
63
+ return parent::_prepareCollection();
64
+ }
65
+
66
+ protected function _afterLoadCollection()
67
+ {
68
+ $this->itemsCollection = Mage::helper('M2ePro/Component_Buy')
69
+ ->getCollection('Order_Item')
70
+ ->addFieldToFilter('order_id', array('in' => $this->getCollection()->getColumnValues('id')));
71
+
72
+ return parent::_afterLoadCollection();
73
+ }
74
+
75
+ protected function _prepareColumns()
76
+ {
77
+ $this->addColumn('purchase_create_date', array(
78
+ 'header' => Mage::helper('M2ePro')->__('Sale Date'),
79
+ 'align' => 'left',
80
+ 'type' => 'datetime',
81
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
82
+ 'index' => 'purchase_create_date',
83
+ 'width' => '170px'
84
+ ));
85
+
86
+ $this->addColumn('magento_order_num', array(
87
+ 'header' => Mage::helper('M2ePro')->__('Magento Order #'),
88
+ 'align' => 'left',
89
+ 'index' => 'so.increment_id',
90
+ 'width' => '110px',
91
+ 'frame_callback' => array($this, 'callbackColumnMagentoOrder')
92
+ ));
93
+
94
+ $this->addColumn('buy_order_id', array(
95
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com Order #'),
96
+ 'align' => 'left',
97
+ 'width' => '110px',
98
+ 'index' => 'buy_order_id',
99
+ ));
100
+
101
+ $this->addColumn('buy_order_items', array(
102
+ 'header' => Mage::helper('M2ePro')->__('Items'),
103
+ 'align' => 'left',
104
+ 'index' => 'buy_order_items',
105
+ 'sortable' => false,
106
+ 'width' => '*',
107
+ 'frame_callback' => array($this, 'callbackColumnItems'),
108
+ 'filter_condition_callback' => array($this, 'callbackFilterItems')
109
+ ));
110
+
111
+ $this->addColumn('buyer', array(
112
+ 'header' => Mage::helper('M2ePro')->__('Buyer'),
113
+ 'align' => 'left',
114
+ 'index' => 'buyer_name',
115
+ 'frame_callback' => array($this, 'callbackColumnBuyer'),
116
+ 'filter_condition_callback' => array($this, 'callbackFilterBuyer'),
117
+ 'width' => '170px'
118
+ ));
119
+
120
+ $this->addColumn('paid_amount', array(
121
+ 'header' => Mage::helper('M2ePro')->__('Total Paid'),
122
+ 'align' => 'left',
123
+ 'width' => '110px',
124
+ 'index' => 'paid_amount',
125
+ 'type' => 'number',
126
+ 'frame_callback' => array($this, 'callbackColumnTotal')
127
+ ));
128
+
129
+ $back = Mage::helper('M2ePro')->makeBackUrlParam(
130
+ '*/adminhtml_common_order/index',
131
+ array(
132
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
133
+ )
134
+ );
135
+
136
+ $this->addColumn('action', array(
137
+ 'header' => Mage::helper('M2ePro')->__('Action'),
138
+ 'width' => '80px',
139
+ 'type' => 'action',
140
+ 'getter' => 'getId',
141
+ 'actions' => array(
142
+ array(
143
+ 'caption' => Mage::helper('M2ePro')->__('View'),
144
+ 'url' => array('base' => '*/adminhtml_common_buy_order/view'),
145
+ 'field' => 'id'
146
+ ),
147
+ array(
148
+ 'caption' => Mage::helper('M2ePro')->__('Edit Shipping Address'),
149
+ 'url' => array(
150
+ 'base' => '*/adminhtml_common_buy_order/editShippingAddress/',
151
+ 'params' => array('back' => $back)
152
+ ),
153
+ 'field' => 'id'
154
+ ),
155
+ array(
156
+ 'caption' => Mage::helper('M2ePro')->__('Create Order'),
157
+ 'url' => array('base' => '*/adminhtml_common_buy_order/createMagentoOrder'),
158
+ 'field' => 'id'
159
+ )
160
+ ),
161
+ 'filter' => false,
162
+ 'sortable' => false,
163
+ 'is_system' => true
164
+ ));
165
+
166
+ return parent::_prepareColumns();
167
+ }
168
+
169
+ protected function _prepareMassaction()
170
+ {
171
+ // Set massaction identifiers
172
+ //--------------------------------
173
+ $this->setMassactionIdField('main_table.id');
174
+ $this->getMassactionBlock()->setFormFieldName('ids');
175
+ //--------------------------------
176
+
177
+ // Set mass-action
178
+ //--------------------------------
179
+ $this->getMassactionBlock()->addItem('resend_shipping', array(
180
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
181
+ 'url' => $this->getUrl('*/adminhtml_order/resubmitShippingInfo'),
182
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
183
+ ));
184
+ //--------------------------------
185
+
186
+ return parent::_prepareMassaction();
187
+ }
188
+
189
+ //##############################################################
190
+
191
+ public function callbackColumnMagentoOrder($value, $row, $column, $isExport)
192
+ {
193
+ $magentoOrderId = $row['magento_order_id'];
194
+ $magentoOrderNumber = Mage::helper('M2ePro')->escapeHtml($row['magento_order_num']);
195
+
196
+ $returnString = Mage::helper('M2ePro')->__('N/A');
197
+
198
+ if ($row['magento_order_id']) {
199
+ if ($row['magento_order_num']) {
200
+ $orderUrl = $this->getUrl('adminhtml/sales_order/view', array('order_id' => $magentoOrderId));
201
+ $returnString = '<a href="' . $orderUrl . '" target="_blank">' . $magentoOrderNumber . '</a>';
202
+ } else {
203
+ $returnString = '<span style="color: red;">'.Mage::helper('M2ePro')->__('Deleted').'</span>';
204
+ }
205
+ }
206
+
207
+ return $returnString.$this->getViewLogIconHtml($row->getId());
208
+ }
209
+
210
+ private function getViewLogIconHtml($orderId)
211
+ {
212
+ $orderId = (int)$orderId;
213
+
214
+ // Prepare collection
215
+ // --------------------------------
216
+ $orderLogsCollection = Mage::getModel('M2ePro/Order_Log')->getCollection()
217
+ ->addFieldToFilter('order_id', $orderId)
218
+ ->setOrder('id', 'DESC');
219
+ $orderLogsCollection->getSelect()
220
+ ->limit(3);
221
+ // --------------------------------
222
+
223
+ // Prepare logs data
224
+ // --------------------------------
225
+ if ($orderLogsCollection->getSize() <= 0) {
226
+ return '';
227
+ }
228
+
229
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
230
+
231
+ $logRows = array();
232
+ foreach ($orderLogsCollection as $log) {
233
+ $logRows[] = array(
234
+ 'type' => $log->getData('type'),
235
+ 'text' => Mage::helper('M2ePro/View')->getModifiedLogMessage($log->getData('message')),
236
+ 'initiator' => $this->getInitiatorForAction($log->getData('initiator')),
237
+ 'date' => Mage::app()->getLocale()->date(strtotime($log->getData('create_date')))->toString($format)
238
+ );
239
+ }
240
+ // --------------------------------
241
+
242
+ $tips = array(
243
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Order Action was completed successfully.',
244
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Order Action was completed with error(s).',
245
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Order Action was completed with warning(s).'
246
+ );
247
+
248
+ $icons = array(
249
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
250
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
251
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
252
+ );
253
+
254
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
255
+ 'entity_id' => $orderId,
256
+ 'rows' => $logRows,
257
+ 'tips' => $tips,
258
+ 'icons' => $icons,
259
+ 'view_help_handler' => 'OrderHandlerObj.viewOrderHelp',
260
+ 'hide_help_handler' => 'OrderHandlerObj.hideOrderHelp',
261
+ ));
262
+
263
+ return $summary->toHtml();
264
+ }
265
+
266
+ public function getInitiatorForAction($initiator)
267
+ {
268
+ $string = '';
269
+
270
+ switch ((int)$initiator) {
271
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
272
+ $string = '';
273
+ break;
274
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
275
+ $string = Mage::helper('M2ePro')->__('Manual');
276
+ break;
277
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
278
+ $string = Mage::helper('M2ePro')->__('Automatic');
279
+ break;
280
+ }
281
+
282
+ return $string;
283
+ }
284
+
285
+ //--------------------------------------------------------------
286
+
287
+ public function callbackColumnItems($value, $row, $column, $isExport)
288
+ {
289
+ /** @var $items Ess_M2ePro_Model_Order_Item[] */
290
+ $items = $this->itemsCollection->getItemsByColumnValue('order_id', $row->getData('id'));
291
+
292
+ $html = '';
293
+ $gridId = $this->getId();
294
+
295
+ foreach ($items as $item) {
296
+ if ($html != '') {
297
+ $html .= '<br/>';
298
+ }
299
+
300
+ $isShowEditLink = false;
301
+
302
+ $product = $item->getProduct();
303
+ if (!is_null($product)) {
304
+ /** @var Ess_M2ePro_Model_Magento_Product $magentoProduct */
305
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
306
+ $magentoProduct->setProduct($product);
307
+
308
+ $associatedProducts = $item->getAssociatedProducts();
309
+ $associatedOptions = $item->getAssociatedOptions();
310
+
311
+ if ($magentoProduct->isProductWithVariations()
312
+ && empty($associatedOptions)
313
+ && empty($associatedProducts)
314
+ ) {
315
+ $isShowEditLink = true;
316
+ }
317
+ }
318
+
319
+ $editItemHtml = '';
320
+ if ($isShowEditLink) {
321
+ $orderItemId = $item->getId();
322
+ $orderItemEditLabel = Mage::helper('M2ePro')->__('edit');
323
+
324
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
325
+
326
+ $editItemHtml = <<<HTML
327
+ <span>&nbsp;<a href="javascript:void(0);" onclick="{$js}">[{$orderItemEditLabel}]</a></span>
328
+ HTML;
329
+ }
330
+
331
+ $skuHtml = '';
332
+ if ($item->getSku()) {
333
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
334
+ $sku = Mage::helper('M2ePro')->escapeHtml($item->getSku());
335
+
336
+ $skuHtml = <<<HTML
337
+ <span style="padding-left: 10px;"><b>{$skuLabel}:</b>&nbsp;{$sku}</span><br/>
338
+ HTML;
339
+ }
340
+
341
+ $generalId = $item->getGeneralId();
342
+
343
+ $itemLabel = Mage::helper('M2ePro')->__('Item');
344
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
345
+ $itemUrl = Mage::helper('M2ePro/Component_Buy')->getItemUrl($generalId);
346
+
347
+ $qtyLabel = Mage::helper('M2ePro')->__('QTY');
348
+ $qty = (int)$item->getQtyPurchased();
349
+ $qtyHtml = <<<HTML
350
+ <span style="padding-left: 10px;"><b>{$qtyLabel}:&nbsp;</b>{$qty}</span>
351
+ HTML;
352
+
353
+ $html .= <<<HTML
354
+ <b>{$itemLabel}:&nbsp;#</b>&nbsp;<a href="{$itemUrl}" target="_blank">{$generalId}</a><br/>
355
+ {$itemTitle}&nbsp;{$editItemHtml}<br/>
356
+ <small>{$skuHtml}{$qtyHtml}</small>
357
+ HTML;
358
+ }
359
+
360
+ return $html;
361
+ }
362
+
363
+ public function callbackColumnBuyer($value, $row, $column, $isExport)
364
+ {
365
+ $html = Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_name')) . '<br/>';
366
+
367
+ $buyerEmail = $row->getData('buyer_email');
368
+ if ($buyerEmail) {
369
+ $html .= '&lt;' . $buyerEmail . '&gt;<br/>';
370
+ }
371
+
372
+ return $html;
373
+ }
374
+
375
+ public function callbackColumnTotal($value, $row, $column, $isExport)
376
+ {
377
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
378
+ $row->getData('currency'), $row->getData('paid_amount')
379
+ );
380
+ }
381
+
382
+ //##############################################################
383
+
384
+ protected function callbackFilterItems(Varien_Data_Collection_Db $collection, $column)
385
+ {
386
+ $value = $column->getFilter()->getValue();
387
+ if ($value == null) {
388
+ return;
389
+ }
390
+
391
+ /** @var $orderItemsCollection Varien_Data_Collection_Db */
392
+ $orderItemsCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Order_Item');
393
+
394
+ $orderItemsCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
395
+ $orderItemsCollection->getSelect()->columns('order_id');
396
+ $orderItemsCollection->getSelect()->distinct(true);
397
+
398
+ $orderItemsCollection->getSelect()
399
+ ->where('general_id LIKE ? OR sku LIKE ? OR title LIKE ?', '%'.$value.'%');
400
+
401
+ $ordersIds = $orderItemsCollection->getColumnValues('order_id');
402
+ $collection->addFieldToFilter('`main_table`.id', array('in' => $ordersIds));
403
+ }
404
+
405
+ protected function callbackFilterBuyer(Varien_Data_Collection_Db $collection, $column)
406
+ {
407
+ $value = $column->getFilter()->getValue();
408
+ if ($value == null) {
409
+ return;
410
+ }
411
+
412
+ $collection->getSelect()
413
+ ->where('buyer_email LIKE ? OR buyer_name LIKE ?', '%'.$value.'%');
414
+ }
415
+
416
+ //##############################################################
417
+
418
+ public function getGridUrl()
419
+ {
420
+ return $this->getUrl('*/adminhtml_common_buy_order/grid', array('_current' => true));
421
+ }
422
+
423
+ public function getRowUrl($row)
424
+ {
425
+ $back = Mage::helper('M2ePro')->makeBackUrlParam(
426
+ '*/adminhtml_common_order/index',
427
+ array(
428
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
429
+ )
430
+ );
431
+
432
+ return $this->getUrl('*/adminhtml_common_buy_order/view', array('id' => $row->getId(), 'back' => $back));
433
+ }
434
+
435
+ // ####################################
436
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View.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_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyOrderView');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_order';
20
+ $this->_mode = 'view';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ $this->_headerText = Mage::helper('M2ePro')->__('View Order Details');
26
+ //------------------------------
27
+
28
+ /** @var $order Ess_M2ePro_Model_Order */
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 (is_null($this->order->getMagentoOrderId())) {
51
+ //------------------------------
52
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId()));
53
+ $this->_addButton('order', array(
54
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
55
+ 'onclick' => "setLocation('".$url."');",
56
+ 'class' => 'scalable'
57
+ ));
58
+ //------------------------------
59
+ } else if (is_null($this->order->getMagentoOrder()) || $this->order->getMagentoOrder()->isCanceled()) {
60
+ //------------------------------
61
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId(), 'force' => 'yes'));
62
+ $confirm = Mage::helper('M2ePro')->escapeJs(
63
+ Mage::helper('M2ePro')->__('Are you sure that you want to create new Magento Order?')
64
+ );
65
+
66
+ $this->_addButton('order', array(
67
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
68
+ 'onclick' => "confirmSetLocation('".$confirm."','".$url."');",
69
+ 'class' => 'scalable'
70
+ ));
71
+ //------------------------------
72
+ }
73
+ }
74
+
75
+ // ####################################
76
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Form.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Ess_M2ePro_Block_Adminhtml_Widget_Container
8
+ {
9
+ public $shippingAddress = array();
10
+
11
+ public $realMagentoOrderId = NULL;
12
+
13
+ // ####################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ //------------------------------
21
+ $this->setId('buyOrderViewForm');
22
+ $this->setTemplate('M2ePro/common/buy/order.phtml');
23
+ //------------------------------
24
+
25
+ /** @var $order Ess_M2ePro_Model_Order */
26
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+ }
28
+
29
+ protected function _beforeToHtml()
30
+ {
31
+ // Magento order data
32
+ // ---------------
33
+ $this->realMagentoOrderId = NULL;
34
+
35
+ $magentoOrder = $this->order->getMagentoOrder();
36
+ if (!is_null($magentoOrder)) {
37
+ $this->realMagentoOrderId = $magentoOrder->getRealOrderId();
38
+ }
39
+ // ---------------
40
+
41
+ // ---------------
42
+ if (!is_null($magentoOrder) && $magentoOrder->hasShipments()) {
43
+ $url = $this->getUrl('*/adminhtml_order/resubmitShippingInfo', array('id' => $this->order->getId()));
44
+ $data = array(
45
+ 'class' => '',
46
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
47
+ 'onclick' => 'setLocation(\''.$url.'\');',
48
+ );
49
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
50
+ $this->setChild('resubmit_shipping_info', $buttonBlock);
51
+ }
52
+ // ---------------
53
+
54
+ // Shipping data
55
+ // ---------------
56
+ /** @var $shippingAddress Ess_M2ePro_Model_Buy_Order_ShippingAddress */
57
+ $shippingAddress = $this->order->getShippingAddress();
58
+
59
+ $this->shippingAddress = $shippingAddress->getData();
60
+ $this->shippingAddress['country_name'] = $shippingAddress->getCountryName();
61
+ $this->shippingAddress['phone'] = $this->order->getChildObject()->getBillingAddress()->getData('phone');
62
+ $this->shippingAddress['company'] = $this->order->getChildObject()->getBillingAddress()->getData('company');
63
+ // ---------------
64
+
65
+ $this->setChild('item', $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_order_view_item'));
66
+ $this->setChild('item_edit', $this->getLayout()->createBlock('M2ePro/adminhtml_order_item_edit'));
67
+ $this->setChild('log', $this->getLayout()->createBlock('M2ePro/adminhtml_order_view_log_grid'));
68
+
69
+ return parent::_beforeToHtml();
70
+ }
71
+
72
+ private function getStore()
73
+ {
74
+ if (is_null($this->order->getData('store_id'))) {
75
+ return null;
76
+ }
77
+
78
+ try {
79
+ $store = Mage::app()->getStore($this->order->getData('store_id'));
80
+ } catch (Exception $e) {
81
+ return null;
82
+ }
83
+
84
+ return $store;
85
+ }
86
+
87
+ public function isCurrencyAllowed()
88
+ {
89
+ $store = $this->getStore();
90
+
91
+ if (is_null($store)) {
92
+ return true;
93
+ }
94
+
95
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
96
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
97
+
98
+ return $currencyHelper->isAllowed($this->order->getChildObject()->getCurrency(), $store);
99
+ }
100
+
101
+ public function hasCurrencyConversionRate()
102
+ {
103
+ $store = $this->getStore();
104
+
105
+ if (is_null($store)) {
106
+ return true;
107
+ }
108
+
109
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
110
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
111
+
112
+ return $currencyHelper->getConvertRateFromBase($this->order->getChildObject()->getCurrency(), $store) != 0;
113
+ }
114
+
115
+ // ####################################
116
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Item.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyOrderViewItem');
18
+ //------------------------------
19
+
20
+ // Set default values
21
+ //------------------------------
22
+ $this->setDefaultSort('id');
23
+ $this->setDefaultDir('DESC');
24
+ $this->setPagerVisibility(false);
25
+ $this->setFilterVisibility(false);
26
+ $this->setUseAjax(true);
27
+ $this->_defaultLimit = 200;
28
+ //------------------------------
29
+
30
+ /** @var $order Ess_M2ePro_Model_Order */
31
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
32
+ }
33
+
34
+ protected function _prepareCollection()
35
+ {
36
+ $collection = Mage::helper('M2ePro/Component_Buy')
37
+ ->getCollection('Order_Item')
38
+ ->addFieldToFilter('order_id', $this->order->getId());
39
+
40
+ $collection->getSelect()->joinLeft(
41
+ array('cisi' => Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
42
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
43
+ array('is_in_stock')
44
+ );
45
+
46
+ $this->setCollection($collection);
47
+
48
+ return parent::_prepareCollection();
49
+ }
50
+
51
+ protected function _prepareColumns()
52
+ {
53
+ $this->addColumn('product_id', array(
54
+ 'header' => Mage::helper('M2ePro')->__('Product'),
55
+ 'align' => 'left',
56
+ 'width' => '*',
57
+ 'index' => 'product_id',
58
+ 'frame_callback' => array($this, 'callbackColumnProduct')
59
+ ));
60
+
61
+ $this->addColumn('stock_availability', array(
62
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
63
+ 'width' => '100px',
64
+ 'index' => 'is_in_stock',
65
+ 'filter_index' => 'cisi.is_in_stock',
66
+ 'type' => 'options',
67
+ 'sortable' => false,
68
+ 'options' => array(
69
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
70
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
71
+ ),
72
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
73
+ ));
74
+
75
+ $this->addColumn('original_price', array(
76
+ 'header' => Mage::helper('M2ePro')->__('Original Price'),
77
+ 'align' => 'left',
78
+ 'width' => '80px',
79
+ 'filter' => false,
80
+ 'sortable' => false,
81
+ 'frame_callback' => array($this, 'callbackColumnOriginalPrice')
82
+ ));
83
+
84
+ $this->addColumn('qty', array(
85
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
86
+ 'align' => 'left',
87
+ 'width' => '80px',
88
+ 'index' => 'qty'
89
+ ));
90
+
91
+ $this->addColumn('price', array(
92
+ 'header' => Mage::helper('M2ePro')->__('Price'),
93
+ 'align' => 'left',
94
+ 'width' => '80px',
95
+ 'index' => 'price',
96
+ 'frame_callback' => array($this, 'callbackColumnPrice')
97
+ ));
98
+
99
+ $this->addColumn('row_total', array(
100
+ 'header' => Mage::helper('M2ePro')->__('Row Total'),
101
+ 'align' => 'left',
102
+ 'width' => '80px',
103
+ 'frame_callback' => array($this, 'callbackColumnRowTotal')
104
+ ));
105
+
106
+ return parent::_prepareColumns();
107
+ }
108
+
109
+ //##############################################################
110
+
111
+ /**
112
+ * @param $value
113
+ * @param $row Ess_M2ePro_Model_Order_Item
114
+ * @param $column
115
+ * @param $isExport
116
+ *
117
+ * @return string
118
+ */
119
+ public function callbackColumnProduct($value, $row, $column, $isExport)
120
+ {
121
+ $skuHtml = '';
122
+ if ($row->getSku()) {
123
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
124
+ $sku = Mage::helper('M2ePro')->escapeHtml($row->getSku());
125
+
126
+ $skuHtml = <<<HTML
127
+ <b>{$skuLabel}:</b> {$sku}<br/>
128
+ HTML;
129
+ }
130
+
131
+ // $referenceIdLabel = Mage::helper('M2ePro')->__('Reference ID');
132
+ // $referenceId = Mage::helper('M2ePro')->escapeHtml($row->getGeneralId());
133
+ //
134
+ // $generalIdHtml = <<<HTML
135
+ //<b>{$referenceIdLabel}:</b> {$referenceId}<br/>
136
+ //HTML;
137
+
138
+ $itemUrl = Mage::helper('M2ePro/Component_Buy')->getItemUrl($row->getGeneralId());
139
+ $itemLinkText = Mage::helper('M2ePro')->__('View on Rakuten.com');
140
+
141
+ $buyLink = <<<HTML
142
+ <a href="{$itemUrl}" target="_blank">{$itemLinkText}</a>
143
+ HTML;
144
+
145
+ $productLink = '';
146
+ if ($productId = $row->getData('product_id')) {
147
+ $productUrl = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
148
+ $productLink = ' | <a href="'.$productUrl.'" target="_blank">'.Mage::helper('M2ePro')->__('View').'</a>';
149
+ }
150
+
151
+ $orderItemId = (int)$row->getId();
152
+ $gridId = $this->getId();
153
+
154
+ $editLink = '';
155
+ if (!$row->getProductId() || $row->getMagentoProduct()->hasRequiredOptions()) {
156
+
157
+ if (!$row->getProductId()) {
158
+ $action = Mage::helper('M2ePro')->__('Map to Magento Product');
159
+ } else {
160
+ $action = Mage::helper('M2ePro')->__('Set Options');
161
+ }
162
+
163
+ $class = 'class="gray"';
164
+
165
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
166
+ $editLink = '<a href="javascript:void(0);" onclick="'.$js.'" '.$class.'>'.$action.'</a>';
167
+ }
168
+
169
+ $discardLink = '';
170
+ if ($row->getProductId()) {
171
+ $action = Mage::helper('M2ePro')->__('Unmap');
172
+
173
+ $js = "{OrderEditItemHandlerObj.unassignProduct('{$gridId}', {$orderItemId});}";
174
+ $discardLink = '<a href="javascript:void(0);" onclick="'.$js.'" class="gray">'.$action.'</a>';
175
+
176
+ if ($editLink) {
177
+ $discardLink = '&nbsp;|&nbsp;' . $discardLink;
178
+ }
179
+ }
180
+
181
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($row->getTitle());
182
+
183
+ return <<<HTML
184
+ <b>{$itemTitle}</b><br/>
185
+ <div style="padding-left: 10px;">
186
+ {$skuHtml}
187
+ </div>
188
+ <div style="float: left;">{$buyLink}{$productLink}</div>
189
+ <div style="float: right;">{$editLink}{$discardLink}</div>
190
+ HTML;
191
+ }
192
+
193
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
194
+ {
195
+ if (is_null($row->getData('is_in_stock'))) {
196
+ return Mage::helper('M2ePro')->__('N/A');
197
+ }
198
+
199
+ if ((int)$row->getData('is_in_stock') <= 0) {
200
+ return '<span style="color: red;">'.$value.'</span>';
201
+ }
202
+
203
+ return $value;
204
+ }
205
+
206
+ public function callbackColumnOriginalPrice($value, $row, $column, $isExport)
207
+ {
208
+ $productId = $row->getData('product_id');
209
+ $formattedPrice = Mage::helper('M2ePro')->__('N/A');
210
+
211
+ if ($productId && $product = Mage::getModel('catalog/product')->load($productId)) {
212
+ $formattedPrice = $product->getFormatedPrice();
213
+ }
214
+
215
+ return $formattedPrice;
216
+ }
217
+
218
+ public function callbackColumnPrice($value, $row, $column, $isExport)
219
+ {
220
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($row->getData('currency'), $row->getData('price'));
221
+ }
222
+
223
+ public function callbackColumnRowTotal($value, $row, $column, $isExport)
224
+ {
225
+ $price = (float)$row->getData('price');
226
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
227
+ $row->getData('currency'), $price * $row->getData('qty')
228
+ );
229
+ }
230
+
231
+ public function getRowUrl($row)
232
+ {
233
+ return '';
234
+ }
235
+
236
+ public function getGridUrl()
237
+ {
238
+ return $this->getUrl('*/*/orderItemGrid', array('_current' => true));
239
+ }
240
+
241
+ // ####################################
242
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Synchronization/Form.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('buySynchronizationForm');
20
+ $this->setContainerId('magento_block_buy_synchronization');
21
+ $this->setTemplate('M2ePro/common/buy/synchronization.phtml');
22
+ //------------------------------
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ //----------------------------
28
+ $this->templatesMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
29
+ ->getGroupValue('/buy/templates/', 'mode');
30
+ //----------------------------
31
+
32
+ //----------------------------
33
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
34
+
35
+ $this->reviseAllInProcessingState = !is_null(
36
+ Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
37
+ '/buy/templates/revise/total/', 'last_listing_product_id'
38
+ )
39
+ );
40
+
41
+ $this->reviseAllStartDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
42
+ '/buy/templates/revise/total/', 'start_date'
43
+ );
44
+ $this->reviseAllStartDate && $this->reviseAllStartDate = Mage::app()->getLocale()
45
+ ->date(strtotime($this->reviseAllStartDate))
46
+ ->toString($format);
47
+
48
+ $this->reviseAllEndDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
49
+ '/buy/templates/revise/total/', 'end_date'
50
+ );
51
+ $this->reviseAllEndDate && $this->reviseAllEndDate = Mage::app()->getLocale()
52
+ ->date(strtotime($this->reviseAllEndDate))
53
+ ->toString($format);
54
+ //----------------------------
55
+
56
+ //----------------------------
57
+ $component = Ess_M2ePro_Helper_Component_Buy::NICK;
58
+ $data = array(
59
+ 'class' => 'ok_button',
60
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
61
+ 'onclick' => "Windows.getFocusedWindow().close(); SynchronizationHandlerObj.runReviseAll('{$component}');",
62
+ );
63
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
64
+ $this->setChild('revise_all_confirm_popup_ok_button', $buttonBlock);
65
+ //------------------------------
66
+
67
+ //-------------------------------
68
+ $this->inspectorMode = (int)Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
69
+ '/defaults/inspector/','mode'
70
+ );
71
+ //-------------------------------
72
+
73
+ return parent::_beforeToHtml();
74
+ }
75
+
76
+ // ####################################
77
+
78
+ public function isShowReviseAll()
79
+ {
80
+ return Mage::helper('M2ePro/Module')->getConfig()->getGroupValue(
81
+ '/view/synchronization/revise_total/','show'
82
+ );
83
+ }
84
+
85
+ // ####################################
86
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Template extends Ess_M2ePro_Block_Adminhtml_Common_Template
8
+ {
9
+ protected $nick = Ess_M2ePro_Helper_Component_Buy::NICK;
10
+
11
+ // ########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('commonBuyTemplate');
20
+ //------------------------------
21
+ }
22
+
23
+ // ########################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Grid.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_Buy_Template_Grid
8
+ extends Ess_M2ePro_Block_Adminhtml_Common_Template_Grid
9
+ {
10
+ protected $nick = Ess_M2ePro_Helper_Component_Buy::NICK;
11
+
12
+ // ##########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ //------------------------------
20
+ $this->setId('commonBuyTemplateGrid');
21
+ //------------------------------
22
+ }
23
+
24
+ // ##########################################
25
+
26
+ public function getRowUrl($row)
27
+ {
28
+ return $this->getUrl(
29
+ '*/adminhtml_common_template/edit',
30
+ array(
31
+ 'id' => $row->getData('template_id'),
32
+ 'type' => $row->getData('type'),
33
+ 'back' => 1
34
+ )
35
+ );
36
+ }
37
+
38
+ // ##########################################
39
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateNewProduct');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_template_newProduct';
20
+ //------------------------------
21
+
22
+ // Set header text
23
+ //------------------------------
24
+ $this->_headerText = Mage::helper('M2ePro')->__('New SKU Policies For %rakuten%',
25
+ Mage::helper('M2ePro/Component_Buy')->getTitle());
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
+ $listingProductIds = Mage::helper('M2ePro/Data_Session')->getValue('buy_listing_product_ids');
38
+
39
+ $listingId = Mage::helper('M2ePro/Component_Buy')
40
+ ->getObject('Listing_Product',reset($listingProductIds))
41
+ ->getListingId();
42
+
43
+ //------------------------------
44
+ $url = $this->getUrl(
45
+ '*/adminhtml_common_buy_listing/view',
46
+ array(
47
+ 'id' => $listingId
48
+ )
49
+ );
50
+ $this->_addButton('back', array(
51
+ 'label' => Mage::helper('M2ePro')->__('Back'),
52
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
53
+ 'class' => 'back'
54
+ ));
55
+ //------------------------------
56
+
57
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_template_newProduct');
58
+
59
+ //------------------------------
60
+ $url = $this->getUrl(
61
+ '*/adminhtml_common_buy_template_newProduct/add',
62
+ array(
63
+ 'back' => $backUrl
64
+ )
65
+ );
66
+ $this->_addButton('new', array(
67
+ 'label' => Mage::helper('M2ePro')->__('Add New SKU Policy'),
68
+ 'onclick' => 'setLocation(\''.$url.'\')',
69
+ 'class' => 'add'
70
+ ));
71
+ //------------------------------
72
+ }
73
+
74
+ public function getGridHtml()
75
+ {
76
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_template_newProduct_help');
77
+
78
+ return $helpBlock->toHtml() . parent::getGridHtml();
79
+ }
80
+
81
+ // ####################################
82
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateNewProductEdit');
18
+ $this->_blockGroup = 'M2ePro';
19
+ $this->_controller = 'adminhtml_common_buy_template_newProduct';
20
+ $this->_mode = 'edit';
21
+ //------------------------------
22
+
23
+ // Set header text
24
+ //------------------------------
25
+ $templateId = $this->getRequest()->getParam('id');
26
+
27
+ $this->_headerText = $templateId
28
+ ? Mage::helper('M2ePro')->__('Edit New SKU Policy For %rakuten%',
29
+ Mage::helper('M2ePro/Component_Buy')->getTitle())
30
+ : Mage::helper('M2ePro')->__('Add New SKU Policy For %rakuten%',
31
+ Mage::helper('M2ePro/Component_Buy')->getTitle());
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
+ $back = $this->getRequest()->getParam('back');
44
+ $buyListingProductIds = Mage::helper('M2ePro/Data_Session')->getValue('buy_listing_product_ids');
45
+ $listingProductId = $this->getRequest()->getParam('listing_product_id');
46
+
47
+ if ($back && ($buyListingProductIds || $listingProductId)) {
48
+ //------------------------------
49
+ $url = Mage::helper('M2ePro')->getBackUrl();
50
+ $this->_addButton('back', array(
51
+ 'label' => Mage::helper('M2ePro')->__('Back'),
52
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url .'\')',
53
+ 'class' => 'back'
54
+ ));
55
+ //------------------------------
56
+ }
57
+
58
+ //------------------------------
59
+ $params = array();
60
+ $listingProductId && $params['listing_product_id'] = $listingProductId;
61
+ $templateId && $params['id'] = $listingProductId;
62
+
63
+ $url = $this->getUrl('*/adminhtml_common_buy_template_newProduct/add', $params);
64
+ $this->_addButton('save', array(
65
+ 'label' => Mage::helper('M2ePro')->__('Save'),
66
+ 'onclick' => 'CommonHandlerObj.save_click(\''.$url.'\')',
67
+ 'class' => 'save'
68
+ ));
69
+ //------------------------------
70
+
71
+ $saveAndAssign = (int)$this->getRequest()->getParam('save_and_assign', 1);
72
+
73
+ if ($saveAndAssign && $buyListingProductIds) {
74
+ //------------------------------
75
+ $url = $this->getUrl(
76
+ '*/adminhtml_common_buy_template_newProduct/add',
77
+ array(
78
+ 'do_map' => true
79
+ )
80
+ );
81
+ $this->_addButton('save_and_map', array(
82
+ 'label' => Mage::helper('M2ePro')->__('Save And Assign'),
83
+ 'onclick' => 'CommonHandlerObj.save_click(\''.$url.'\')',
84
+ 'class' => 'save'
85
+ ));
86
+ //------------------------------
87
+ }
88
+ }
89
+
90
+ // ####################################
91
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Form.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_Buy_Template_NewProduct_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('buyTemplateNewProductEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareForm()
22
+ {
23
+ $form = new Varien_Data_Form(array(
24
+ 'id' => 'edit_form',
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
+
35
+ protected function _beforeToHtml()
36
+ {
37
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
38
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
39
+
40
+ $this->nodes = $connRead->select()
41
+ ->from(Mage::getSingleton('core/resource')->getTableName('m2epro_buy_dictionary_category'))
42
+ ->where('parent_category_id = ?', 0)
43
+ ->order('title ASC')
44
+ ->query()
45
+ ->fetchAll();
46
+
47
+ //------------------------------
48
+ $data = array(
49
+ 'id' => 'category_confirm_button',
50
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
51
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.confirmCategory();',
52
+ );
53
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
54
+ $this->setChild('category_confirm_button',$buttonBlock);
55
+ //------------------------------
56
+
57
+ //------------------------------
58
+ $data = array(
59
+ 'id' => 'category_change_button',
60
+ 'label' => Mage::helper('M2ePro')->__('Change Category'),
61
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.changeCategory();',
62
+ );
63
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
64
+ $this->setChild('category_change_button',$buttonBlock);
65
+ //------------------------------
66
+
67
+ return parent::_beforeToHtml();
68
+ }
69
+
70
+ // ####################################
71
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/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_NewProduct_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('buyTemplateNewProductEditTabs');
18
+ //------------------------------
19
+
20
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
21
+ $this->setDestElementId('edit_form');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ $this->addTab('general', array(
27
+ 'label' => Mage::helper('M2ePro')->__('General'),
28
+ 'title' => Mage::helper('M2ePro')->__('General'),
29
+ 'content' => $this->getLayout()->createBlock(
30
+ 'M2ePro/adminhtml_common_buy_template_newProduct_edit_tabs_general'
31
+ )->toHtml(),
32
+ ));
33
+
34
+ $this->addTab('core', array(
35
+ 'label' => Mage::helper('M2ePro')->__('Description'),
36
+ 'title' => Mage::helper('M2ePro')->__('Description'),
37
+ 'content' => $this->getLayout()->createBlock(
38
+ 'M2ePro/adminhtml_common_buy_template_newProduct_edit_tabs_description'
39
+ )->toHtml(),
40
+ ));
41
+
42
+ $this->addTab('attribute', array(
43
+ 'label' => Mage::helper('M2ePro')->__('Specifics'),
44
+ 'title' => Mage::helper('M2ePro')->__('Specifics'),
45
+ 'content' => $this->getLayout()->createBlock(
46
+ 'M2ePro/adminhtml_common_buy_template_newProduct_edit_tabs_attributes'
47
+ )->toHtml(),
48
+ ));
49
+
50
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
51
+
52
+ return parent::_beforeToHtml();
53
+ }
54
+
55
+ // ####################################
56
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Attributes.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateNewProductEditTabsAttributes');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/template/newProduct/tabs/attributes.phtml');
21
+ }
22
+
23
+ //------------------------------
24
+
25
+ public function getAttributesJsHtml()
26
+ {
27
+ $html = '';
28
+
29
+ $allAttributes = $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getAll();
30
+ $attributes = Mage::helper('M2ePro/Magento_Attribute')->filterByInputTypes(
31
+ $allAttributes, array('text', 'price', 'select')
32
+ );
33
+
34
+ foreach($attributes as $attribute) {
35
+ $code = Mage::helper('M2ePro')->escapeHtml($attribute['code']);
36
+ $html .= sprintf('<option value="%s">%s</option>', $code, $attribute['label']);
37
+ }
38
+
39
+ return Mage::helper('M2ePro')->escapeJs($html);
40
+ }
41
+
42
+ // ####################################
43
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Description.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_Edit_Tabs_Description
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('buyTemplateNewProductEditTabsDescription');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/buy/template/newProduct/tabs/description.phtml');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getAll();
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.appendToText(".
42
+ "'select_attributes_for_manufacturer'," . " 'manufacturer_template'".
43
+ ");",
44
+ 'class' => 'select_attributes_for_mfg_name_template_button'
45
+ );
46
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
47
+ $this->setChild('select_attributes_for_mfg_name_template_button',$buttonBlock);
48
+ //------------------------------
49
+
50
+ //------------------------------
51
+ $data = array(
52
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
53
+ 'onclick' => "AttributeHandlerObj.appendToTextarea('#' + $('select_attributes').value + '#');",
54
+ 'class' => 'add_product_attribute_button',
55
+ );
56
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
57
+ $this->setChild('add_product_attribute_button',$buttonBlock);
58
+ //------------------------------
59
+
60
+ //------------------------------
61
+ for ($i = 0; $i < Ess_M2ePro_Model_Buy_Template_NewProduct_Core::FEATURES_COUNT; $i++) {
62
+ $data = array(
63
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
64
+ 'onclick' => "AttributeHandlerObj.appendToText('select_attributes_for_features_{$i}',"
65
+ . " 'features_{$i}');BuyTemplateNewProductHandlerObj.allowAddFeature(this);",
66
+ 'class' => "select_attributes_for_features_{$i}_button"
67
+ );
68
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
69
+ $this->setChild("select_attributes_for_features_{$i}_button",$buttonBlock);
70
+ }
71
+ //------------------------------
72
+
73
+ return parent::_beforeToHtml();
74
+ }
75
+
76
+ // ####################################
77
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/General.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ->order('title ASC')
34
+ ->query()
35
+ ->fetchAll();
36
+ !is_array($this->nodes) && $this->nodes = array();
37
+
38
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
39
+
40
+ //------------------------------
41
+ $data = array(
42
+ 'id' => 'category_confirm_button',
43
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
44
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.confirmCategory();',
45
+ );
46
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
47
+ $this->setChild('category_confirm_button',$buttonBlock);
48
+ //------------------------------
49
+
50
+ //------------------------------
51
+ $data = array(
52
+ 'id' => 'category_change_button',
53
+ 'label' => Mage::helper('M2ePro')->__('Change Category'),
54
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.changeCategory();',
55
+ );
56
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
57
+ $this->setChild('category_change_button',$buttonBlock);
58
+ //------------------------------
59
+
60
+ //------------------------------
61
+ $data = array(
62
+ 'id' => 'browse_category_button',
63
+ 'label' => Mage::helper('M2ePro')->__('Browse'),
64
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.browse_category.showCenter(true)'
65
+ );
66
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
67
+ $this->setChild('browse_category_button',$buttonBlock);
68
+ //------------------------------
69
+
70
+ //------------------------------
71
+ $data = array(
72
+ 'id' => 'search_category_button',
73
+ 'label' => Mage::helper('M2ePro')->__('Search By Keywords'),
74
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.search_category.showCenter(true)',
75
+ );
76
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
77
+ $this->setChild('search_category_button',$buttonBlock);
78
+ //------------------------------
79
+
80
+ //------------------------------
81
+ $data = array(
82
+ 'id' => 'search_category_popup_button',
83
+ 'label' => Mage::helper('M2ePro')->__('Search'),
84
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.searchClick()',
85
+ );
86
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
87
+ $this->setChild('search_category_popup_button',$buttonBlock);
88
+ //------------------------------
89
+
90
+ //------------------------------
91
+ $data = array(
92
+ 'id' => 'close_browse_popup_button',
93
+ 'label' => Mage::helper('M2ePro')->__('Close'),
94
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.closeBrowseCategoryPopup()',
95
+ );
96
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
97
+ $this->setChild('close_browse_popup_button',$buttonBlock);
98
+ //------------------------------
99
+
100
+ //------------------------------
101
+ $data = array(
102
+ 'id' => 'close_search_popup_button',
103
+ 'label' => Mage::helper('M2ePro')->__('Close'),
104
+ 'onclick' => 'BuyTemplateNewProductHandlerObj.closeSearchCategoryPopup()',
105
+ );
106
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
107
+ $this->setChild('close_search_popup_button',$buttonBlock);
108
+ //------------------------------
109
+
110
+ return parent::_beforeToHtml();
111
+ }
112
+
113
+ // ########################################
114
+
115
+ public function isAllowedUpcExemption($formData)
116
+ {
117
+ $isAllowedUpcExemption = Ess_M2ePro_Model_Buy_Template_NewProduct::isAllowedUpcExemption();
118
+ $gtinMode = $formData['category']['gtin_mode'];
119
+ return $isAllowedUpcExemption || $gtinMode == Ess_M2ePro_Model_Buy_Template_NewProduct_Core::GTIN_MODE_NONE;
120
+ }
121
+
122
+ // ########################################
123
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Grid.php ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('templateNewProductGrid');
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
+ protected function _prepareCollection()
30
+ {
31
+ $collection = Mage::getModel('M2ePro/Buy_Template_NewProduct')->getCollection();
32
+ $this->setCollection($collection);
33
+ return parent::_prepareCollection();
34
+ }
35
+
36
+ protected function _prepareColumns()
37
+ {
38
+ $this->addColumn('id', array(
39
+ 'header' => Mage::helper('M2ePro')->__('ID'),
40
+ 'align' => 'right',
41
+ 'type' => 'number',
42
+ 'width' => '50px',
43
+ 'index' => 'id',
44
+ 'filter_index' => 'id',
45
+ 'frame_callback' => array($this, 'callbackColumnId')
46
+ ));
47
+
48
+ $this->addColumn('title', array(
49
+ 'header' => Mage::helper('M2ePro')->__('Title'),
50
+ 'align' => 'left',
51
+ 'type' => 'text',
52
+ 'width' => '100px',
53
+ 'index' => 'title',
54
+ 'filter_index' => 'title',
55
+ 'frame_callback' => array($this, 'callbackColumnTitle')
56
+ ));
57
+
58
+ $this->addColumn('node_title', array(
59
+ 'header' => Mage::helper('M2ePro')->__('Department'),
60
+ 'align' => 'left',
61
+ 'type' => 'text',
62
+ 'width' => '100px',
63
+ 'index' => 'node_title',
64
+ 'filter_index' => 'node_title',
65
+ 'frame_callback' => array($this, 'callbackColumnNodeTitle')
66
+ ));
67
+
68
+ $this->addColumn('category_path', array(
69
+ 'header' => Mage::helper('M2ePro')->__('Category'),
70
+ 'align' => 'left',
71
+ 'type' => 'text',
72
+ 'width' => '350px',
73
+ 'index' => 'category_path',
74
+ 'filter_index' => 'category_path',
75
+ 'frame_callback' => array($this, 'callbackColumnCategoryPath')
76
+ ));
77
+
78
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_template_newProduct');
79
+
80
+ $this->addColumn('assignment', array(
81
+ 'header' => Mage::helper('M2ePro')->__('Assignment'),
82
+ 'align' => 'left',
83
+ 'type' => 'text',
84
+ 'width' => '130px',
85
+ 'filter' => false,
86
+ 'sortable' => false,
87
+ 'frame_callback' => array($this, 'callbackColumnActions'),
88
+ ));
89
+
90
+ $this->addColumn('actions', array(
91
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
92
+ 'align' => 'left',
93
+ 'width' => '100px',
94
+ 'type' => 'action',
95
+ 'index' => 'actions',
96
+ 'filter' => false,
97
+ 'sortable' => false,
98
+ 'getter' => 'getId',
99
+ 'actions' => array(
100
+ array(
101
+ 'caption' => Mage::helper('M2ePro')->__('Edit'),
102
+ 'url' => array('base'=> '*/adminhtml_common_buy_template_newProduct/edit/back/'.$back),
103
+ 'field' => 'id'
104
+ ),
105
+ array(
106
+ 'caption' => Mage::helper('M2ePro')->__('Delete Policy'),
107
+ 'url' => array('base'=> '*/adminhtml_common_buy_template_newProduct/delete/back/'
108
+ .$this->getRequest()->getParam('back')),
109
+ 'field' => 'ids',
110
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
111
+ ),
112
+ )
113
+ ));
114
+ }
115
+
116
+ // ####################################
117
+
118
+ protected function _prepareMassaction()
119
+ {
120
+ // Set massaction identifiers
121
+ //--------------------------------
122
+ $this->setMassactionIdField('id');
123
+ $this->getMassactionBlock()->setFormFieldName('ids');
124
+ //--------------------------------
125
+
126
+ // Set delete action
127
+ //--------------------------------
128
+ $this->getMassactionBlock()->addItem('delete', array(
129
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
130
+ 'url' => $this->getUrl('*/*/delete'),
131
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
132
+ ));
133
+ //--------------------------------
134
+
135
+ return parent::_prepareMassaction();
136
+ }
137
+
138
+ // ####################################
139
+
140
+ public function callbackColumnId($value, $row, $column, $isExport)
141
+ {
142
+ return $value.'&nbsp;';
143
+ }
144
+
145
+ public function callbackColumnTitle($value, $row, $column, $isExport)
146
+ {
147
+ return '&nbsp'.$value;
148
+ }
149
+
150
+ public function callbackColumnNodeTitle($value, $row, $column, $isExport)
151
+ {
152
+ return '&nbsp'.$value;
153
+ }
154
+
155
+ public function callbackColumnCategoryPath($value, $row, $column, $isExport)
156
+ {
157
+ return '&nbsp;'.$value;
158
+ }
159
+
160
+ public function callbackColumnActions($value, $row, $column, $isExport)
161
+ {
162
+ $url = $this->getUrl(
163
+ '*/adminhtml_common_buy_template_newProduct/map/',
164
+ array(
165
+ 'id' => $row->getId(),
166
+ )
167
+ );
168
+
169
+ $confirmMessage = Mage::helper('M2ePro')->__('Are you sure?');
170
+ $actions = '&nbsp;<a href="javascript:;" onclick="confirm(\''.$confirmMessage.'\') && ';
171
+ $actions .= 'setLocation(\''.$url.'\');">';
172
+ $actions .= Mage::helper('M2ePro')->__('Assign To This Policy');
173
+ $actions .= '</a>';
174
+
175
+ return $actions;
176
+ }
177
+
178
+ // ####################################
179
+
180
+ public function getGridUrl()
181
+ {
182
+ return $this->getUrl('*/adminhtml_common_buy_template_newProduct/templateNewProductGrid',
183
+ array('_current'=>true));
184
+ }
185
+
186
+ public function getRowUrl($row)
187
+ {
188
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_template_newProduct');
189
+
190
+ return $this->getUrl('*/adminhtml_common_buy_template_newProduct/edit', array(
191
+ 'id' => $row->getId(),
192
+ 'back' => $back
193
+ ));
194
+ }
195
+
196
+ // ####################################
197
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Help.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateNewProductHelp');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/template/newProduct/help.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Search/Grid.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_Template_NewProduct_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('buyTemplateNewProductSearchGrid');
18
+ //------------------------------
19
+
20
+ // Set default values
21
+ //------------------------------
22
+ $this->setFilterVisibility(false);
23
+ $this->setPagerVisibility(false);
24
+ $this->setDefaultSort('id');
25
+ $this->setDefaultDir('ASC');
26
+ $this->setSaveParametersInSession(true);
27
+ $this->setUseAjax(true);
28
+ //------------------------------
29
+ }
30
+
31
+ protected function _prepareCollection()
32
+ {
33
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
34
+
35
+ $results = new Varien_Data_Collection();
36
+ foreach ($data as $index => $item) {
37
+ $temp = array(
38
+ 'id' => $item['category_id'],
39
+ 'title' => $item['title'],
40
+ 'path' => $item['path'],
41
+ 'node_id' => $item['node_id'],
42
+ 'native_id' => $item['native_id']
43
+ );
44
+
45
+ $results->addItem(new Varien_Object($temp));
46
+ }
47
+
48
+ $this->setCollection($results);
49
+
50
+ return parent::_prepareCollection();
51
+ }
52
+
53
+ protected function _prepareColumns()
54
+ {
55
+ $this->addColumn('title', array(
56
+ 'header' => Mage::helper('M2ePro')->__('Category'),
57
+ 'align' => 'left',
58
+ 'type' => 'text',
59
+ 'index' => 'title',
60
+ 'filter' => false,
61
+ 'sortable' => false,
62
+ 'frame_callback' => array($this, 'callbackColumnTitle')
63
+ ));
64
+
65
+ $this->addColumn('actions', array(
66
+ 'header' => Mage::helper('M2ePro')->__('Action'),
67
+ 'align' => 'center',
68
+ 'type' => 'text',
69
+ 'width' => '80px',
70
+ 'filter' => false,
71
+ 'sortable' => false,
72
+ 'frame_callback' => array($this, 'callbackColumnActions'),
73
+ ));
74
+
75
+ }
76
+
77
+ // ####################################
78
+
79
+ public function callbackColumnTitle($title, $row, $column, $isExport)
80
+ {
81
+ $categoryInfo = json_encode($row->getData());
82
+ $categoryInfo = Mage::helper('M2ePro')->escapeHtml($categoryInfo);
83
+ $categoryInfo = Mage::helper('M2ePro')->escapeJs($categoryInfo);
84
+
85
+ $path = $row->getData('path');
86
+ (strlen($path) != strlen($title)) && $path = substr($path,0,strlen($path) - strlen($title)-2);
87
+ $path = str_replace('->',' > ',$path);
88
+
89
+ $title = Mage::helper('M2ePro')->escapeHtml($title);
90
+ if (strlen($title) > 60) {
91
+ $title = substr($title, 0, 60) . '...';
92
+ }
93
+ $foundIn = Mage::helper('M2ePro')->__('Found In: ');
94
+
95
+ $fullPath = $path;
96
+ if (strlen($path) > 135) {
97
+ $path = substr($path, 0, 135) . '...';
98
+ }
99
+
100
+ $html = <<<HTML
101
+ <div style="margin-left: 3px">
102
+ <a href="javascript:;" onclick="BuyTemplateNewProductHandlerObj.confirmSearchClick($categoryInfo)">$title</a>
103
+ <br/>
104
+ <span style="font-weight: bold;">$foundIn</span>
105
+ &nbsp;
106
+ <span title="$fullPath">$path</span><br/>
107
+ </div>
108
+ HTML;
109
+
110
+ return $html;
111
+ }
112
+
113
+ public function callbackColumnActions($value, $row, $column, $isExport)
114
+ {
115
+ $categoryInfo = json_encode($row->getData());
116
+ $categoryInfo = Mage::helper('M2ePro')->escapeHtml($categoryInfo);
117
+ $categoryInfo = Mage::helper('M2ePro')->escapeJs($categoryInfo);
118
+
119
+ $select = Mage::helper('M2ePro')->__('Select');
120
+ $html = <<<HTML
121
+ <a href="javascript:;" onclick="BuyTemplateNewProductHandlerObj.confirmSearchClick($categoryInfo)">$select</a>
122
+ HTML;
123
+
124
+ return $html;
125
+ }
126
+
127
+ // ####################################
128
+
129
+ protected function _toHtml()
130
+ {
131
+ $javascriptsMain = <<<JAVASCRIPT
132
+ <script type="text/javascript">
133
+
134
+ $$('#buyTemplateNewProductSearchGrid div.grid th').each(function(el){
135
+ el.style.padding = '2px 2px';
136
+ });
137
+
138
+ $$('#buyTemplateNewProductSearchGrid div.grid td').each(function(el){
139
+ el.style.padding = '2px 2px';
140
+ });
141
+
142
+ $$('#buyTemplateNewProductSearchGrid div.grid table').each(function(el){
143
+ el.style.width = '99.9%';
144
+ });
145
+
146
+ </script>
147
+ JAVASCRIPT;
148
+
149
+ return parent::_toHtml() . $javascriptsMain;
150
+ }
151
+
152
+ // ####################################
153
+
154
+ public function getRowUrl($row)
155
+ {
156
+ return false;
157
+ }
158
+
159
+ // ####################################
160
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit.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_Buy_Template_SellingFormat_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('buyTemplateSellingFormatEdit');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_buy_template_sellingFormat';
21
+ $this->_mode = 'edit';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $helper = Mage::helper('M2ePro');
27
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
28
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
29
+ $headerTextEdit = $helper->__("Edit %component_name% Selling Format Policy", $componentName);
30
+ $headerTextAdd = $helper->__("Add %component_name% Selling Format Policy", $componentName);
31
+ } else {
32
+ $headerTextEdit = $helper->__("Edit Selling Format Policy");
33
+ $headerTextAdd = $helper->__("Add Selling Format Policy");
34
+ }
35
+
36
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
37
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
38
+ ) {
39
+ $this->_headerText = $headerTextEdit;
40
+ $this->_headerText .= ' "'.$this->escapeHtml(
41
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
42
+ } else {
43
+ $this->_headerText = $headerTextAdd;
44
+ }
45
+ //------------------------------
46
+
47
+ // Set buttons actions
48
+ //------------------------------
49
+ $this->removeButton('back');
50
+ $this->removeButton('reset');
51
+ $this->removeButton('delete');
52
+ $this->removeButton('add');
53
+ $this->removeButton('save');
54
+ $this->removeButton('edit');
55
+ //------------------------------
56
+
57
+ //------------------------------
58
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
59
+ $this->_addButton('back', array(
60
+ 'label' => Mage::helper('M2ePro')->__('Back'),
61
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.back_click(\'' . $url . '\')',
62
+ 'class' => 'back'
63
+ ));
64
+ //------------------------------
65
+
66
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
67
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
68
+ ) {
69
+ //------------------------------
70
+ $this->_addButton('duplicate', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
72
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.duplicate_click'
73
+ .'(\'common-buy-template-sellingFormat\')',
74
+ 'class' => 'add M2ePro_duplicate_button'
75
+ ));
76
+ //------------------------------
77
+
78
+ //------------------------------
79
+ $this->_addButton('delete', array(
80
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
81
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.delete_click()',
82
+ 'class' => 'delete M2ePro_delete_button'
83
+ ));
84
+ //------------------------------
85
+ }
86
+
87
+ //------------------------------
88
+ $this->_addButton('save', array(
89
+ 'label' => Mage::helper('M2ePro')->__('Save'),
90
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.save_click()',
91
+ 'class' => 'save'
92
+ ));
93
+ //------------------------------
94
+
95
+ //------------------------------
96
+ $this->_addButton('save_and_continue', array(
97
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
98
+ 'onclick' => 'BuyTemplateSellingFormatHandlerObj.save_and_edit_click()',
99
+ 'class' => 'save'
100
+ ));
101
+ //------------------------------
102
+ }
103
+
104
+ // ####################################
105
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/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_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
+ // ####################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ //------------------------------
19
+ $this->setId('buyTemplateSellingFormatEditForm');
20
+ //------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/buy/template/selling_format/form.phtml');
23
+ }
24
+
25
+ protected function _prepareForm()
26
+ {
27
+ $form = new Varien_Data_Form(array(
28
+ 'id' => 'edit_form',
29
+ 'action' => $this->getUrl('*/*/save'),
30
+ 'method' => 'post',
31
+ 'enctype' => 'multipart/form-data'
32
+ ));
33
+
34
+ $form->setUseContainer(true);
35
+ $this->setForm($form);
36
+
37
+ return parent::_prepareForm();
38
+ }
39
+
40
+ protected function _beforeToHtml()
41
+ {
42
+ //------------------------------
43
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
44
+ //------------------------------
45
+
46
+ //------------------------------
47
+ $this->customerGroups = Mage::getModel('customer/group')->getCollection()->toOptionArray();
48
+ //------------------------------
49
+
50
+ return parent::_beforeToHtml();
51
+ }
52
+
53
+ // ####################################
54
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/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_Buy_Template_Synchronization_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('buyTemplateSynchronizationEdit');
19
+ $this->_blockGroup = 'M2ePro';
20
+ $this->_controller = 'adminhtml_common_buy_template_synchronization';
21
+ $this->_mode = 'edit';
22
+ //------------------------------
23
+
24
+ // Set header text
25
+ //------------------------------
26
+ $helper = Mage::helper('M2ePro');
27
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
28
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
29
+ $headerTextEdit = $helper->__("Edit %component_name% Synchronization Policy", $componentName);
30
+ $headerTextAdd = $helper->__("Add %component_name% Synchronization Policy", $componentName);
31
+ } else {
32
+ $headerTextEdit = $helper->__("Edit Synchronization Policy");
33
+ $headerTextAdd = $helper->__("Add Synchronization Policy");
34
+ }
35
+
36
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
37
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
38
+ ) {
39
+ $this->_headerText = $headerTextEdit;
40
+ $this->_headerText .= ' "'.$this->escapeHtml(
41
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
42
+ } else {
43
+ $this->_headerText = $headerTextAdd;
44
+ }
45
+ //------------------------------
46
+
47
+ // Set buttons actions
48
+ //------------------------------
49
+ $this->removeButton('back');
50
+ $this->removeButton('reset');
51
+ $this->removeButton('delete');
52
+ $this->removeButton('add');
53
+ $this->removeButton('save');
54
+ $this->removeButton('edit');
55
+ //------------------------------
56
+
57
+ //------------------------------
58
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
59
+ $this->_addButton('back', array(
60
+ 'label' => Mage::helper('M2ePro')->__('Back'),
61
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.back_click(\'' . $url . '\')',
62
+ 'class' => 'back'
63
+ ));
64
+ //------------------------------
65
+
66
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
67
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
68
+ ) {
69
+ //------------------------------
70
+ $this->_addButton('duplicate', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
72
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.duplicate_click'
73
+ .'(\'common-buy-template-synchronization\')',
74
+ 'class' => 'add M2ePro_duplicate_button'
75
+ ));
76
+ //------------------------------
77
+
78
+ //------------------------------
79
+ $this->_addButton('delete', array(
80
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
81
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.delete_click()',
82
+ 'class' => 'delete M2ePro_delete_button'
83
+ ));
84
+ //------------------------------
85
+ }
86
+
87
+ //------------------------------
88
+ $this->_addButton('save', array(
89
+ 'label' => Mage::helper('M2ePro')->__('Save'),
90
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.save_click()',
91
+ 'class' => 'save'
92
+ ));
93
+ //------------------------------
94
+
95
+ //------------------------------
96
+ $this->_addButton('save_and_continue', array(
97
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
98
+ 'onclick' => 'BuyTemplateSynchronizationHandlerObj.save_and_edit_click'
99
+ .'(\'\',\'buyTemplateSynchronizationEditTabs\')',
100
+ 'class' => 'save'
101
+ ));
102
+ //------------------------------
103
+ }
104
+
105
+ // ####################################
106
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Form.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_Buy_Template_Synchronization_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('buyTemplateSynchronizationEditForm');
18
+ //------------------------------
19
+ }
20
+
21
+ protected function _prepareForm()
22
+ {
23
+ $form = new Varien_Data_Form(array(
24
+ 'id' => 'edit_form',
25
+ 'action' => $this->getUrl('*/*/save'),
26
+ 'method' => 'post',
27
+ 'enctype' => 'multipart/form-data'
28
+ ));
29
+
30
+ $form->setUseContainer(true);
31
+ $this->setForm($form);
32
+
33
+ return parent::_prepareForm();
34
+ }
35
+
36
+ // ####################################
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs.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_Buy_Template_Synchronization_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('buyTemplateSynchronizationEditTabs');
18
+ //------------------------------
19
+
20
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
21
+ $this->setDestElementId('edit_form');
22
+ }
23
+
24
+ protected function _beforeToHtml()
25
+ {
26
+ $this->addTab('list', array(
27
+ 'label' => Mage::helper('M2ePro')->__('List Rules'),
28
+ 'title' => Mage::helper('M2ePro')->__('List Rules'),
29
+ 'content' => $this->getLayout()
30
+ ->createBlock('M2ePro/adminhtml_common_buy_template_synchronization_edit_tabs_list')
31
+ ->toHtml(),
32
+ ))
33
+ ->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_buy_template_synchronization_edit_tabs_revise')
38
+ ->toHtml(),
39
+ ))
40
+ ->addTab('relist', array(
41
+ 'label' => Mage::helper('M2ePro')->__('Relist Rules'),
42
+ 'title' => Mage::helper('M2ePro')->__('Relist Rules'),
43
+ 'content' => $this->getLayout()
44
+ ->createBlock('M2ePro/adminhtml_common_buy_template_synchronization_edit_tabs_relist')
45
+ ->toHtml(),
46
+ ))
47
+ ->addTab('stop', array(
48
+ 'label' => Mage::helper('M2ePro')->__('Stop Rules'),
49
+ 'title' => Mage::helper('M2ePro')->__('Stop Rules'),
50
+ 'content' => $this->getLayout()
51
+ ->createBlock('M2ePro/adminhtml_common_buy_template_synchronization_edit_tabs_stop')
52
+ ->toHtml(),
53
+ ))
54
+ ->setActiveTab($this->getRequest()->getParam('tab', 'list'));
55
+
56
+ return parent::_beforeToHtml();
57
+ }
58
+
59
+ // ####################################
60
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/List.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateSynchronizationEditTabsList');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/list.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Relist.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_Template_Synchronization_Edit_Tabs_Relist
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('buyTemplateSynchronizationEditTabsRelist');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/relist.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Revise.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_Template_Synchronization_Edit_Tabs_Revise
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('buyTemplateSynchronizationEditTabsRevise');
19
+ //------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/revise.phtml');
22
+ }
23
+
24
+ // ####################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Synchronization/Edit/Tabs/Stop.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('buyTemplateSynchronizationEditTabsStop');
18
+ //------------------------------
19
+
20
+ $this->setTemplate('M2ePro/common/buy/template/synchronization/stop.phtml');
21
+ }
22
+
23
+ // ####################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Abstract.php ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Ess_M2ePro_Block_Adminhtml_Widget_Container
8
+ {
9
+ const TAB_ID_AMAZON = 'amazon';
10
+ const TAB_ID_BUY = 'buy';
11
+
12
+ // ########################################
13
+
14
+ protected $tabs = array();
15
+
16
+ protected $enabledTab = NULL;
17
+
18
+ protected $tabsContainerBlock = NULL;
19
+
20
+ protected $tabsContainerId = 'components_container';
21
+
22
+ protected $useAjax = false;
23
+
24
+ protected $tabsAjaxUrls = array();
25
+
26
+ // ########################################
27
+
28
+ static public function getTabIdByComponent($component)
29
+ {
30
+ $tabId = null;
31
+
32
+ switch ($component) {
33
+ case Ess_M2ePro_Helper_Component_Amazon::NICK:
34
+ $tabId = self::TAB_ID_AMAZON;
35
+ break;
36
+ case Ess_M2ePro_Helper_Component_Buy::NICK:
37
+ $tabId = self::TAB_ID_BUY;
38
+ break;
39
+ }
40
+
41
+ return $tabId;
42
+ }
43
+
44
+ // ########################################
45
+
46
+ public function enableAmazonTab()
47
+ {
48
+ $this->setEnabledTab(self::TAB_ID_AMAZON);
49
+ }
50
+
51
+ public function enableBuyTab()
52
+ {
53
+ $this->setEnabledTab(self::TAB_ID_BUY);
54
+ }
55
+
56
+ // ########################################
57
+
58
+ public function setEnabledTab($id)
59
+ {
60
+ $this->enabledTab = $id;
61
+ }
62
+
63
+ // ----------------------------------------
64
+
65
+ protected function isTabEnabled($id)
66
+ {
67
+ if (is_null($this->enabledTab)) {
68
+ return true;
69
+ }
70
+
71
+ return $id == $this->enabledTab;
72
+ }
73
+
74
+ // ----------------------------------------
75
+
76
+ protected function canUseAjax()
77
+ {
78
+ if (count($this->tabs) < 2) {
79
+ return false;
80
+ }
81
+
82
+ return $this->useAjax;
83
+ }
84
+
85
+ // ########################################
86
+
87
+ protected function initializeTabs()
88
+ {
89
+ $this->initializeAmazon();
90
+ $this->initializeBuy();
91
+ }
92
+
93
+ protected function initializeTab($id)
94
+ {
95
+ if ($this->isTabEnabled($id) && !in_array($id, $this->tabs)) {
96
+ $this->tabs[] = $id;
97
+ }
98
+ }
99
+
100
+ protected function initializeAmazon()
101
+ {
102
+ if (Mage::helper('M2ePro/Component_Amazon')->isActive()) {
103
+ $this->initializeTab(self::TAB_ID_AMAZON);
104
+ }
105
+ }
106
+
107
+ protected function initializeBuy()
108
+ {
109
+ if (Mage::helper('M2ePro/Component_Buy')->isActive()) {
110
+ $this->initializeTab(self::TAB_ID_BUY);
111
+ }
112
+ }
113
+
114
+ // ########################################
115
+
116
+ protected function getTabBlockById($id)
117
+ {
118
+ $id = ucfirst($id);
119
+ $method = "get{$id}TabBlock";
120
+
121
+ if (method_exists($this, $method)) {
122
+ return $this->$method();
123
+ }
124
+
125
+ return NULL;
126
+ }
127
+
128
+ protected function getTabHtmlById($id)
129
+ {
130
+ $id = ucfirst($id);
131
+ $method = "get{$id}TabHtml";
132
+
133
+ if (method_exists($this, $method)) {
134
+ return $this->$method();
135
+ }
136
+
137
+ return '';
138
+ }
139
+
140
+ protected function getTabLabelById($id)
141
+ {
142
+ $label = '';
143
+
144
+ if (in_array($id, Mage::helper('M2ePro/Component')->getComponents())) {
145
+ $label = Mage::helper('M2ePro/Component_' . ucfirst($id))->getTitle();
146
+ }
147
+
148
+ return $label ? $label : Mage::helper('M2ePro')->__('N/A');
149
+ }
150
+
151
+ protected function getTabUrlById($id)
152
+ {
153
+ return isset($this->tabsAjaxUrls[$id]) ? $this->tabsAjaxUrls[$id] : '';
154
+ }
155
+
156
+ // ########################################
157
+
158
+ protected function _prepareLayout()
159
+ {
160
+ if (count(Mage::helper('M2ePro/View_Common_Component')->getActiveComponents()) == 0) {
161
+ throw new LogicException('At least 1 Channel should be enabled.');
162
+ }
163
+
164
+ $this->initializeTabs();
165
+
166
+ parent::_prepareLayout();
167
+ }
168
+
169
+ // ########################################
170
+
171
+ protected function _toHtml()
172
+ {
173
+ return parent::_toHtml() . $this->_componentsToHtml();
174
+ }
175
+
176
+ protected function _componentsToHtml()
177
+ {
178
+ $tabsCount = count($this->tabs);
179
+
180
+ if ($tabsCount <= 0) {
181
+ return '';
182
+ }
183
+
184
+ if ($tabsCount == 1) {
185
+ $tabId = reset($this->tabs);
186
+
187
+ return $this->getTabHtmlById($tabId);
188
+ }
189
+
190
+ $tabsContainer = $this->getTabsContainerBlock();
191
+ $tabsContainer->setDestElementId($this->tabsContainerId);
192
+
193
+ foreach ($this->tabs as $tabId) {
194
+ $tab = $this->prepareTabById($tabId);
195
+ $tabsContainer->addTab($tabId, $tab);
196
+ }
197
+
198
+ $tabsContainer->setActiveTab($this->getActiveTab());
199
+
200
+ return $tabsContainer->toHtml() . $this->getTabsContainerDestinationHtml();
201
+ }
202
+
203
+ // ########################################
204
+
205
+ protected function prepareTabById($id)
206
+ {
207
+ $label = $this->getTabLabelById($id);
208
+
209
+ $tab = array(
210
+ 'label' => $label,
211
+ 'title' => $label
212
+ );
213
+
214
+ if ($this->canUseAjax() && $this->getActiveTab() != $id) {
215
+ $tab['class'] = 'ajax';
216
+ $tab['url'] = $this->getTabUrlById($id);
217
+ } else {
218
+ $tab['content'] = $this->getTabHtmlById($id);
219
+ }
220
+
221
+ return $tab;
222
+ }
223
+
224
+ // ########################################
225
+
226
+ protected function getSingleBlock()
227
+ {
228
+ if (count($this->tabs) != 1) {
229
+ return NULL;
230
+ }
231
+
232
+ $tabId = reset($this->tabs);
233
+
234
+ return $this->getTabBlockById($tabId);
235
+ }
236
+
237
+ // ########################################
238
+
239
+ /**
240
+ * @abstract
241
+ * @return Mage_Core_Block_Abstract
242
+ */
243
+ abstract protected function getAmazonTabBlock();
244
+
245
+ public function getAmazonTabHtml()
246
+ {
247
+ return $this->getAmazonTabBlock()->toHtml();
248
+ }
249
+
250
+ /**
251
+ * @abstract
252
+ * @return Mage_Core_Block_Abstract
253
+ */
254
+ abstract protected function getBuyTabBlock();
255
+
256
+ public function getBuyTabHtml()
257
+ {
258
+ return $this->getBuyTabBlock()->toHtml();
259
+ }
260
+
261
+ // ########################################
262
+
263
+ /**
264
+ * @return Ess_M2ePro_Block_Adminhtml_Common_Component_Tabs
265
+ */
266
+ protected function getTabsContainerBlock()
267
+ {
268
+ if (is_null($this->tabsContainerBlock)) {
269
+ $this->tabsContainerBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_component_tabs');
270
+ }
271
+
272
+ return $this->tabsContainerBlock;
273
+ }
274
+
275
+ protected function getTabsContainerDestinationHtml()
276
+ {
277
+ return '<div id="'.$this->tabsContainerId.'"></div>';
278
+ }
279
+
280
+ // ########################################
281
+
282
+ protected function getActiveTab()
283
+ {
284
+ $activeTab = $this->getRequest()->getParam('tab');
285
+ if (is_null($activeTab)) {
286
+ Mage::helper('M2ePro/View_Common_Component')->isAmazonDefault() && $activeTab = self::TAB_ID_AMAZON;
287
+ Mage::helper('M2ePro/View_Common_Component')->isBuyDefault() && $activeTab = self::TAB_ID_BUY;
288
+ }
289
+
290
+ return $activeTab;
291
+ }
292
+
293
+ // ########################################
294
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Grid/Container.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // ########################################
17
+
18
+ protected function getAddButtonOnClickAction()
19
+ {
20
+ $components = Mage::helper('M2ePro/View_Common_Component')->getActiveComponents();
21
+ $action = '';
22
+
23
+ if (count($components) == 1) {
24
+ $component = reset($components);
25
+ $action = 'setLocation(\''.$this->getNewUrl($component).'\');';
26
+ }
27
+
28
+ return $action;
29
+ }
30
+
31
+ // ########################################
32
+
33
+ protected function _toHtml()
34
+ {
35
+ return $this->getAddButtonJavascript() . parent::_toHtml();
36
+ }
37
+
38
+ // ----------------------------------------
39
+
40
+ protected function getAddButtonJavascript()
41
+ {
42
+ if (count(Mage::helper('M2ePro/View_Common_Component')->getActiveComponents()) < 2) {
43
+ return '';
44
+ }
45
+
46
+ $data = array(
47
+ 'target_css_class' => 'add-button-drop-down',
48
+ 'items' => $this->getAddButtonDropDownItems()
49
+ );
50
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
51
+ $dropDownBlock->setData($data);
52
+
53
+ return $dropDownBlock->toHtml();
54
+ }
55
+
56
+ protected function getAddButtonDropDownItems()
57
+ {
58
+ $items = array();
59
+
60
+ $activeComponents = Mage::helper('M2ePro/View_Common_Component')->getActiveComponentsTitles();
61
+
62
+ //------------------------------
63
+ foreach ($activeComponents as $component => $title) {
64
+ $items[] = array(
65
+ 'url' => $this->getNewUrl($component),
66
+ 'label' => $title
67
+ );
68
+ }
69
+ //------------------------------
70
+
71
+ return $items;
72
+ }
73
+
74
+ // ########################################
75
+
76
+ protected function getNewUrl($component)
77
+ {
78
+ $component = ucfirst(strtolower($component));
79
+ $method = "get{$component}NewUrl";
80
+
81
+ if (!method_exists($this, $method)) {
82
+ throw new Exception('Method of adding a new entity is not defined.');
83
+ }
84
+
85
+ return $this->$method();
86
+ }
87
+
88
+ // ########################################
89
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Component/Tabs.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_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
+ // ########################################
30
+ }
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/Configuration.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_Configuration extends Ess_M2ePro_Block_Adminhtml_Widget_Container
8
+ {
9
+ // ####################################
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+
15
+ // Initialization block
16
+ //------------------------------
17
+ $this->setId('commonConfiguration');
18
+ //------------------------------
19
+
20
+ // Set header text
21
+ //------------------------------
22
+ $this->_headerText = Mage::helper('M2ePro')->__('Configuration');
23
+ //------------------------------
24
+
25
+ // Set buttons actions
26
+ //------------------------------
27
+ $this->removeButton('back');
28
+ $this->removeButton('delete');
29
+ $this->removeButton('add');
30
+ $this->removeButton('save');
31
+ $this->removeButton('edit');
32
+
33
+ //------------------------------
34
+ $this->setTemplate('M2ePro/common/component/container.phtml');
35
+ //------------------------------
36
+ }
37
+
38
+ protected function _toHtml()
39
+ {
40
+ $javascript = <<<JAVASCIRPT
41
+
42
+ <script type="text/javascript">
43
+
44
+ Event.observe(window, 'load', function() {
45
+ CommonHandlerObj = new CommonHandler();
46
+ });
47
+
48
+ </script>
49
+
50
+ JAVASCIRPT;
51
+
52
+ $activeTab = !is_null($this->getData('active_tab')) ? $this->getData('active_tab')
53
+ : Ess_M2ePro_Block_Adminhtml_Common_Configuration_Tabs::TAB_ID_MARKETPLACE;
54
+ $tabsBlock = $this->getLayout()->createBlock(
55
+ 'M2ePro/adminhtml_common_configuration_tabs', '', array('active_tab' => $activeTab)
56
+ );
57
+
58
+ return $javascript .
59
+ parent::_toHtml() .
60
+ $tabsBlock->toHtml() .
61
+ '<div id="tabs_container"></div>';
62
+ }
63
+
64
+ // ####################################
65
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Configuration/Tabs.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Configuration_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
8
+ {
9
+ const TAB_ID_ACCOUNT = 'account';
10
+ const TAB_ID_MARKETPLACE = 'marketplace';
11
+ const TAB_ID_SYNCHRONIZATION = 'synchronization';
12
+ const TAB_ID_GLOBAL = 'global';
13
+ const TAB_ID_TEMPLATE = 'template';
14
+ const TAB_ID_DESCRIPTION_TEMPLATE = 'description_template';
15
+
16
+ // ########################################
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+ $this->setTemplate('widget/tabshoriz.phtml');
22
+ $this->setId('commonConfigurationTabs');
23
+ $this->setDestElementId('tabs_container');
24
+ }
25
+
26
+ // ########################################
27
+
28
+ protected function _prepareLayout()
29
+ {
30
+
31
+ $this->addTab(self::TAB_ID_ACCOUNT, $this->prepareTabAccount());
32
+ $this->addTab(self::TAB_ID_MARKETPLACE, $this->prepareTabMarketplace());
33
+ $this->addTab(self::TAB_ID_TEMPLATE, $this->prepareTabTemplate());
34
+ if (Mage::helper('M2ePro/Component_Amazon')->isActive()) {
35
+ $this->addTab(self::TAB_ID_DESCRIPTION_TEMPLATE, $this->prepareTabDescriptionTemplate());
36
+ }
37
+ $this->addTab(self::TAB_ID_SYNCHRONIZATION, $this->prepareTabSynchronization());
38
+ $this->addTab(self::TAB_ID_GLOBAL, $this->prepareTabGlobal());
39
+
40
+ $this->setActiveTab($this->getData('active_tab'));
41
+
42
+ return parent::_prepareLayout();
43
+ }
44
+
45
+ // ########################################
46
+
47
+ protected function prepareTabMarketplace()
48
+ {
49
+ $tab = array(
50
+ 'label' => Mage::helper('M2ePro')->__('Marketplaces'),
51
+ 'title' => Mage::helper('M2ePro')->__('Marketplaces')
52
+ );
53
+
54
+ if ($this->getData('active_tab') == self::TAB_ID_MARKETPLACE) {
55
+ $tab['content'] = $this->getLayout()->createBlock('M2ePro/adminhtml_common_marketplace_help')->toHtml();
56
+ $tab['content'] .= $this->getLayout()->createBlock('M2ePro/adminhtml_common_marketplace')->toHtml();
57
+ } else {
58
+ $tab['url'] = $this->getUrl('*/adminhtml_common_marketplace/index');
59
+ }
60
+
61
+ return $tab;
62
+ }
63
+
64
+ protected function prepareTabSynchronization()
65
+ {
66
+ $tab = array(
67
+ 'label' => Mage::helper('M2ePro')->__('Synchronization'),
68
+ 'title' => Mage::helper('M2ePro')->__('Synchronization')
69
+ );
70
+
71
+ if ($this->getData('active_tab') == self::TAB_ID_SYNCHRONIZATION) {
72
+ $tab['content'] = $this->getLayout()->createBlock('M2ePro/adminhtml_common_synchronization_help')->toHtml();
73
+ $tab['content'] .= $this->getLayout()->createBlock('M2ePro/adminhtml_common_synchronization')->toHtml();
74
+ } else {
75
+ $tab['url'] = $this->getUrl('*/adminhtml_common_synchronization/index');
76
+ }
77
+
78
+ return $tab;
79
+ }
80
+
81
+ protected function prepareTabTemplate()
82
+ {
83
+ $tab = array(
84
+ 'label' => Mage::helper('M2ePro')->__('Policies'),
85
+ 'title' => Mage::helper('M2ePro')->__('Policies')
86
+ );
87
+
88
+ if ($this->getData('active_tab') == self::TAB_ID_TEMPLATE) {
89
+ $tab['content'] = $this->getLayout()->createBlock('M2ePro/adminhtml_Common_template_help')->toHtml();
90
+ $tab['content'] .= $this->getLayout()->createBlock('M2ePro/adminhtml_common_' .
91
+ $this->getActiveChannelTab() . '_template')->toHtml();
92
+ } else {
93
+ $tab['url'] = $this->getUrl('*/adminhtml_common_template/index', array(
94
+ 'channel' => $this->getActiveChannelTab()
95
+ ));
96
+ }
97
+
98
+ return $tab;
99
+ }
100
+
101
+ protected function prepareTabDescriptionTemplate()
102
+ {
103
+ $componentName = !Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()
104
+ ? Mage::helper('M2ePro/Component_Amazon')->getTitle().' ' : '';
105
+
106
+ $title = Mage::helper('M2ePro')->__("%sDescription Policies", $componentName);
107
+
108
+ $tab = array(
109
+ 'label' => Mag