m2epro_ebay_magento - Version 6.3.5

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.5
Comparing to
See all releases


Code changes from version 1.0.3 to 6.3.5

Files changed (162) 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 +296 -0
  23. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php +701 -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 +19 -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 +571 -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 +83 -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 +892 -0
  52. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Grid.php +463 -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 +157 -0
  55. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php +577 -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 +1659 -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/Manage/Tabs/Vocabulary.php +127 -0
  61. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToIndividualPopup.php +50 -0
  62. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToParentPopup.php +50 -0
  63. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyAttributesPopup.php +49 -0
  64. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyOptionsPopup.php +49 -0
  65. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View.php +779 -0
  66. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php +1608 -0
  67. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Help.php +24 -0
  68. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ListingSwitcher.php +22 -0
  69. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Magento/Grid.php +360 -0
  70. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.php +48 -0
  71. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php +995 -0
  72. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Settings/Grid.php +518 -0
  73. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Marketplace/Form.php +97 -0
  74. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress.php +69 -0
  75. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress/Form.php +59 -0
  76. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Grid.php +571 -0
  77. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View.php +109 -0
  78. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Form.php +114 -0
  79. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Item.php +341 -0
  80. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Synchronization/Form.php +86 -0
  81. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template.php +25 -0
  82. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description.php +48 -0
  83. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Edit.php +99 -0
  84. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs.php +71 -0
  85. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Browse.php +28 -0
  86. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Recent.php +42 -0
  87. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Search.php +28 -0
  88. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add.php +71 -0
  89. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add/Grid.php +248 -0
  90. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit.php +103 -0
  91. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Form.php +39 -0
  92. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs.php +58 -0
  93. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Definition.php +135 -0
  94. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/General.php +60 -0
  95. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Specifics.php +36 -0
  96. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Grid.php +222 -0
  97. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Help.php +18 -0
  98. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Grid.php +39 -0
  99. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit.php +105 -0
  100. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit/Form.php +58 -0
  101. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit.php +110 -0
  102. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Form.php +38 -0
  103. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs.php +65 -0
  104. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/List.php +25 -0
  105. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Relist.php +25 -0
  106. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Revise.php +25 -0
  107. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Stop.php +25 -0
  108. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit.php +154 -0
  109. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Form.php +37 -0
  110. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs.php +56 -0
  111. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/General.php +80 -0
  112. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/ListingOther.php +31 -0
  113. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/Order.php +89 -0
  114. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing.php +41 -0
  115. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Form.php +24 -0
  116. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/General.php +25 -0
  117. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Search.php +42 -0
  118. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Selling.php +86 -0
  119. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode.php +19 -0
  120. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category.php +23 -0
  121. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Form.php +13 -0
  122. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Group/Grid.php +18 -0
  123. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Global.php +13 -0
  124. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Website.php +13 -0
  125. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit.php +165 -0
  126. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Form.php +37 -0
  127. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Tabs.php +48 -0
  128. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Grid.php +325 -0
  129. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/Grid.php +85 -0
  130. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View.php +266 -0
  131. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View/Grid.php +530 -0
  132. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product.php +100 -0
  133. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product/Help.php +24 -0
  134. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Grid.php +245 -0
  135. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Main.php +66 -0
  136. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Menu.php +35 -0
  137. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search.php +160 -0
  138. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search/Grid.php +614 -0
  139. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View.php +598 -0
  140. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Grid.php +974 -0
  141. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Help.php +24 -0
  142. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/ListingSwitcher.php +22 -0
  143. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress.php +69 -0
  144. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Edit/ShippingAddress/Form.php +60 -0
  145. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/Grid.php +436 -0
  146. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View.php +76 -0
  147. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Form.php +116 -0
  148. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Order/View/Item.php +242 -0
  149. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Synchronization/Form.php +86 -0
  150. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template.php +24 -0
  151. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/Grid.php +39 -0
  152. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct.php +82 -0
  153. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit.php +91 -0
  154. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Form.php +71 -0
  155. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs.php +56 -0
  156. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Attributes.php +43 -0
  157. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/Description.php +77 -0
  158. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Edit/Tabs/General.php +123 -0
  159. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Grid.php +197 -0
  160. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Help.php +24 -0
  161. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/NewProduct/Search/Grid.php +160 -0
  162. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Template/SellingFormat/Edit.php +86 -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,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $data = array(
86
+ 'id' => 'productSearch_cleanSuggest_button',
87
+ 'label' => Mage::helper('M2ePro')->__('Search ASIN/ISBN Manually'),
88
+ 'class' => 'productSearch_cleanSuggest_button',
89
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndManualSearch()'
90
+ );
91
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
92
+ $productSearchBlock->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
93
+ //------------------------------
94
+
95
+ return $helpBlock->toHtml()
96
+ . $viewHeaderBlock->toHtml()
97
+ . $productSearchBlock->toHtml()
98
+ . parent::getGridHtml();
99
+ }
100
+
101
+ protected function _toHtml()
102
+ {
103
+ $helper = Mage::helper('M2ePro');
104
+
105
+ // --------TEXT------------------
106
+ $createEmptyListingMessage = $helper->escapeJs($helper->__('Are you sure you want to create empty Listing?'));
107
+
108
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
109
+ $taskCompletedSuccessMessage = $helper->escapeJs(
110
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
111
+ );
112
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
113
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
114
+ ));
115
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
116
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
117
+ ));
118
+
119
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
120
+ 'Sending %product_title% Product(s) data on Amazon.')
121
+ );
122
+
123
+ $selectItemsMessage = $helper->escapeJs(
124
+ $helper->__('Please select the Products you want to perform the Action on.')
125
+ );
126
+
127
+ $assignString = Mage::helper('M2ePro')->__('Assign');
128
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
129
+
130
+ $enterProductSearchQueryMessage = $helper->escapeJs(
131
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
132
+ );
133
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
134
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
135
+ $autoMapAsinErrorMessage = $helper->escapeJs(
136
+ $helper->__('Server is currently unavailable. Please try again later.')
137
+ );
138
+ $newAsinNotAvailable = $helper->escapeJs(
139
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
140
+ );
141
+ $notSynchronizedMarketplace = $helper->escapeJs(
142
+ $helper->__(
143
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
144
+ ).' '.
145
+ $helper->__(
146
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
147
+ )
148
+ );
149
+
150
+ $newAsinPopupTitle = $helper->escapeJs($helper->__('New ASIN/ISBN creation'));
151
+ $notCompletedPopupTitle = $helper->escapeJs(
152
+ $helper->__('Adding of New Products to the Listing was not competed')
153
+ );
154
+ // -------------------------------
155
+
156
+ // ---------URL-------------------
157
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
158
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
159
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
160
+ $getCategoriesByAsin = $this->getUrl('*/adminhtml_common_amazon_listing/getCategoriesByAsin');
161
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
162
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
163
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
164
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
165
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
166
+
167
+ $viewSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/viewSearchSettings');
168
+ $saveSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/saveSearchSettings');
169
+
170
+ $checkSearchResults = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/checkSearchResults', array(
171
+ 'id' => $this->getListing()->getId()
172
+ ));
173
+
174
+ $showNewAsinStep = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/showNewAsinStep', array(
175
+ 'id' => $this->getListing()->getId()
176
+ ));
177
+
178
+ $addProductsUrl = $this->getUrl(
179
+ '*/adminhtml_common_listing_productAdd/addProducts', array(
180
+ 'component' => $this->getData('component')
181
+ )
182
+ );
183
+ $backUrl = $this->getUrl('*/*/index');
184
+ // -------------------------------
185
+
186
+ $showNotCompletedPopup = '';
187
+ if ($this->getRequest()->getParam('not_completed', false)) {
188
+ $showNotCompletedPopup = 'ListingGridHandlerObj.showNotCompletedPopup();';
189
+ }
190
+
191
+ $javascript = <<<JAVASCRIPT
192
+ <script type="text/javascript">
193
+ if (typeof M2ePro == 'undefined') {
194
+ M2ePro = {};
195
+ M2ePro.url = {};
196
+ M2ePro.formData = {};
197
+ M2ePro.customData = {};
198
+ M2ePro.text = {};
199
+ }
200
+
201
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
202
+ M2ePro.text.create_empty_listing_message = '{$createEmptyListingMessage}';
203
+
204
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
205
+
206
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
207
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
208
+
209
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
210
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
211
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
212
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
213
+
214
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
215
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
216
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
217
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
218
+
219
+ M2ePro.text.assign = '{$assignString}';
220
+ M2ePro.text.confirm = '{$textConfirm}';
221
+
222
+ M2ePro.text.new_asin_popup_title = '{$newAsinPopupTitle}';
223
+ M2ePro.text.not_completed_popup_title = '{$notCompletedPopupTitle}';
224
+
225
+ M2ePro.url.add_products = '{$addProductsUrl}';
226
+ M2ePro.url.back = '{$backUrl}';
227
+
228
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
229
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
230
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
231
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
232
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
233
+ M2ePro.url.getCategoriesByAsin = '{$getCategoriesByAsin}';
234
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
235
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
236
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
237
+
238
+ M2ePro.url.viewSearchSettings = '{$viewSearchSettings}';
239
+ M2ePro.url.saveSearchSettings = '{$saveSearchSettings}';
240
+
241
+ M2ePro.url.checkSearchResults = '{$checkSearchResults}';
242
+ M2ePro.url.showNewAsinStep = '{$showNewAsinStep}';
243
+
244
+ Event.observe(window, 'load', function() {
245
+
246
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
247
+
248
+ ListingGridHandlerObj = new CommonAmazonListingSearchAsinGridHandler(
249
+ '{$this->getChild('grid')->getId()}',
250
+ {$this->getListing()->getId()}
251
+ );
252
+
253
+ // todo next (temp solution)
254
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
255
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
256
+
257
+ ListingProgressBarObj = new ProgressBar('search_asin_progress_bar');
258
+ GridWrapperObj = new AreaWrapper('search_asin_products_container');
259
+
260
+ {$showNotCompletedPopup}
261
+ });
262
+
263
+ </script>
264
+ JAVASCRIPT;
265
+
266
+ //------------------------------
267
+ $notCompletedPopup = $this->getLayout()->createBlock(
268
+ 'M2ePro/adminhtml_common_amazon_listing_add_searchAsin_notCompleted');
269
+ //------------------------------
270
+
271
+ return $notCompletedPopup->toHtml() .
272
+ $javascript .
273
+ '<div id="search_asin_progress_bar"></div>' .
274
+ '<div id="search_asin_products_container">' .
275
+ parent::_toHtml() .
276
+ '</div>';
277
+ }
278
+
279
+ // ####################################
280
+
281
+ public function getListing()
282
+ {
283
+ if (!$listingId = $this->getRequest()->getParam('id')) {
284
+ throw new Exception('Listing is not defined');
285
+ }
286
+
287
+ if (is_null($this->listing)) {
288
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
289
+ ->getObject('Listing', $listingId)->getChildObject();
290
+ }
291
+
292
+ return $this->listing;
293
+ }
294
+
295
+ // ####################################
296
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php ADDED
@@ -0,0 +1,701 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 one of the Results');
391
+
392
+ $linkHtml = <<<HTML
393
+ <a href="javascript:void(0)"
394
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">{$linkTxt}</a>
395
+ HTML;
396
+
397
+ $msg = Mage::helper('M2ePro')->__('Action Required');
398
+ $tip = Mage::helper('M2ePro')->__(
399
+ 'Please %link% that were found by %type% "%value%"',
400
+ $linkHtml, $this->prepareSearchType($searchData['type']), $searchData['value']
401
+ );
402
+
403
+ return <<<HTML
404
+ <span style="color: orange; {$style}">{$msg}</span>&nbsp;
405
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
406
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
407
+ <img src="{$skinUrl}/images/help.png">
408
+ <span>{$tip}</span>
409
+ </span>
410
+ HTML;
411
+ }
412
+
413
+ $searchInfo = json_decode($row->getData('general_id_search_info'), true);
414
+
415
+ $msg = Mage::helper('M2ePro')->__('Completed');
416
+ $tip = Mage::helper('M2ePro')->__(
417
+ 'Product was found by %type% "%value%"',
418
+ $this->prepareSearchType($searchInfo['type']), $searchInfo['value']
419
+ );
420
+
421
+ return <<<HTML
422
+ <span style="color: green; {$style}">{$msg}</span>&nbsp;
423
+ <img class="tool-tip-image" style="{$style}" src="{$skinUrl}/images/tool-tip-icon.png">
424
+ <span class="tool-tip-message tip-left" style="left: 528px; top: 249px; display: none; min-width: 230px;">
425
+ <img src="{$skinUrl}/images/help.png">
426
+ <span>{$tip}</span>
427
+ </span><br/>
428
+ HTML;
429
+ }
430
+
431
+ private function prepareSearchType($searchType)
432
+ {
433
+ if ($searchType == 'string') {
434
+ return 'query';
435
+ }
436
+
437
+ return strtoupper($searchType);
438
+ }
439
+
440
+ // ####################################
441
+
442
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
443
+ {
444
+ // ---------------------------------
445
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
446
+ // ---------------------------------
447
+
448
+ // ---------------------------------
449
+ $lpId = $row->getData('id');
450
+
451
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
452
+ if (strlen($productTitle) > 60) {
453
+ $productTitle = substr($productTitle, 0, 60) . '...';
454
+ }
455
+ $productTitle = Mage::helper('M2ePro')->__('Search ASIN/ISBN For &quot;%product_title%&quot;', $productTitle);
456
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
457
+ // ---------------------------------
458
+
459
+ // ---------------------------------
460
+
461
+ $searchSettingsStatus = $row->getData('search_settings_status');
462
+
463
+ // ---------------------------------
464
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
465
+
466
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN Search in Progress.');
467
+ $iconSrc = $iconPath.'processing.gif';
468
+
469
+ return <<<HTML
470
+ &nbsp;
471
+ <a href="javascript: void(0);" title="{$tip}">
472
+ <img src="{$iconSrc}" alt="">
473
+ </a>
474
+ HTML;
475
+ }
476
+ // ---------------------------------
477
+
478
+ // ---------------------------------
479
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_ACTION_REQUIRED) {
480
+
481
+ $linkTxt = Mage::helper('M2ePro')->__('Choose ASIN/ISBN');
482
+
483
+ return <<<HTML
484
+ <a href="javascript:;" title="{$linkTxt}"
485
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">{$linkTxt}</a>
486
+ HTML;
487
+ }
488
+ // ---------------------------------
489
+
490
+ $na = Mage::helper('M2ePro')->__('N/A');
491
+ $tip = Mage::helper('M2ePro')->__('Search for ASIN/ISBN');
492
+ $iconSrc = $iconPath.'search.png';
493
+
494
+ return <<<HTML
495
+ {$na} &nbsp;
496
+ <a href="javascript:;" title="{$tip}"
497
+ onclick="ListingGridHandlerObj.productSearchHandler.showSearchManualPrompt('{$productTitle}',{$lpId});">
498
+ <img src="{$iconSrc}" alt="" width="16" height="16">
499
+ </a>
500
+ HTML;
501
+ }
502
+
503
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
504
+ {
505
+ $generalId = $row->getData('general_id');
506
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
507
+
508
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
509
+ $generalId,
510
+ $marketplaceId
511
+ );
512
+
513
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
514
+
515
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
516
+
517
+ if (!empty($generalIdSearchInfo)) {
518
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
519
+ }
520
+
521
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
522
+
523
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
524
+
525
+ $text = <<<HTML
526
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
527
+ HTML;
528
+
529
+ } else {
530
+
531
+ $text = <<<HTML
532
+ <a href="{$url}" target="_blank">{$generalId}</a>
533
+ HTML;
534
+
535
+ }
536
+
537
+ // ---------------------------------
538
+ $hasInActionLock = $this->getLockedData($row);
539
+ $hasInActionLock = $hasInActionLock['in_action'];
540
+ // ---------------------------------
541
+
542
+ if ($hasInActionLock) {
543
+ return $text;
544
+ }
545
+
546
+ $listingProductId = (int)$row->getData('id');
547
+
548
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
549
+ $iconSrc = $iconPath.'unassign.png';
550
+
551
+ $text .= <<<HTML
552
+ <a href="javascript:;"
553
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$listingProductId});"
554
+ title="{$tip}">
555
+ <img src="{$iconSrc}" width="16" height="16"/>
556
+ </a>
557
+ HTML;
558
+
559
+ return $text;
560
+ }
561
+
562
+ // ####################################
563
+
564
+ protected function callbackFilterTitle($collection, $column)
565
+ {
566
+ $value = $column->getFilter()->getValue();
567
+
568
+ if ($value == null) {
569
+ return;
570
+ }
571
+
572
+ $collection->addFieldToFilter(
573
+ array(
574
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
575
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
576
+ )
577
+ );
578
+ }
579
+
580
+ protected function callbackFilterStatus($collection, $column)
581
+ {
582
+ $value = $column->getFilter()->getValue();
583
+
584
+ if ($value == null) {
585
+ return;
586
+ }
587
+
588
+ if ($value == self::SEARCH_SETTINGS_STATUS_NONE) {
589
+ $collection->addFieldToFilter('general_id', array('null' => NULL));
590
+ $collection->addFieldToFilter('search_settings_status', array('null' => NULL));
591
+ return;
592
+ }
593
+
594
+ if ($value == self::SEARCH_SETTINGS_STATUS_COMPLETED) {
595
+ $collection->addFieldToFilter(
596
+ array(
597
+ array('attribute'=>'general_id', 'notnull' => NULL)
598
+ )
599
+ );
600
+
601
+ return;
602
+ }
603
+
604
+ $collection->addFieldToFilter(
605
+ array(
606
+ array('attribute' => 'search_settings_status', 'eq' => $value)
607
+ )
608
+ );
609
+ }
610
+
611
+ // ####################################
612
+
613
+ public function getRowUrl($row)
614
+ {
615
+ return false;
616
+ }
617
+
618
+ // ####################################
619
+
620
+ protected function _toHtml()
621
+ {
622
+ $disableMassactionSearch = '';
623
+ $startSearch = '';
624
+
625
+ $listing = $this->getListing();
626
+
627
+ if (!$listing->getChildObject()->isGeneralIdAttributeMode() &&
628
+ !$listing->getChildObject()->isWorldwideIdAttributeMode()) {
629
+
630
+ if (!$listing->getChildObject()->isSearchByMagentoTitleModeEnabled()) {
631
+ $gridId = $this->getId();
632
+
633
+ $disableMassactionSearch = <<<JS
634
+ var mmassActionEl = $("{$gridId}_massaction-select");
635
+
636
+ if (mmassActionEl && mmassActionEl.select('option[value="assignGeneralId"]').length > 0) {
637
+ var assignGeneralIdOption = mmassActionEl.select('option[value="assignGeneralId"]')[0];
638
+ assignGeneralIdOption.disabled = true;
639
+
640
+ mmassActionEl.insert({bottom: assignGeneralIdOption.remove()});
641
+ }
642
+ JS;
643
+ }
644
+
645
+ } else {
646
+ $autoSearchSetting = $listing->getSetting('additional_data', 'auto_search_was_performed');
647
+
648
+ if (!$autoSearchSetting) {
649
+ $listing->setSetting('additional_data', 'auto_search_was_performed', 1);
650
+ $listing->save();
651
+
652
+ $startSearch = <<<JS
653
+ ListingGridHandlerObj.getGridMassActionObj().selectAll();
654
+ ListingGridHandlerObj.productSearchHandler.searchGeneralIdAuto(ListingGridHandlerObj.getSelectedProductsString());
655
+ JS;
656
+ }
657
+ }
658
+
659
+ $javascriptsMain = <<<JAVASCRIPT
660
+ <script type="text/javascript">
661
+
662
+ if (typeof ListingGridHandlerObj != 'undefined') {
663
+ ListingGridHandlerObj.afterInitPage();
664
+ {$disableMassactionSearch}
665
+ }
666
+
667
+ Event.observe(window, 'load', function() {
668
+ setTimeout(function() {
669
+ ListingGridHandlerObj.afterInitPage();
670
+ {$disableMassactionSearch}
671
+ {$startSearch}
672
+ }, 350);
673
+ });
674
+
675
+ </script>
676
+ JAVASCRIPT;
677
+
678
+ return parent::_toHtml() . $javascriptsMain;
679
+ }
680
+
681
+ // ####################################
682
+
683
+ /**
684
+ * @return Ess_M2ePro_Model_Amazon_Listing
685
+ * @throws Exception
686
+ */
687
+ public function getListing()
688
+ {
689
+ if (!$listingId = $this->getRequest()->getParam('id')) {
690
+ throw new Exception('Listing is not defined');
691
+ }
692
+
693
+ if (is_null($this->listing)) {
694
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing', $listingId);
695
+ }
696
+
697
+ return $this->listing;
698
+ }
699
+
700
+ // ####################################
701
+ }
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,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ public function getHelpPageUrl()
13
+ {
14
+ return Mage::helper('M2ePro/Module_Support')
15
+ ->getDocumentationUrl(NULL, 'pages/viewpage.action?pageId=18188381');
16
+ }
17
+
18
+ // ####################################
19
+ }
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,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = Mage::helper('M2ePro')->__('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_LISTED:
366
+ $value = '<span style="color: green;">' . $value . '</span>';
367
+ break;
368
+
369
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
370
+ $value = '<span style="color: red;">' . $value . '</span>';
371
+ break;
372
+
373
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
374
+ $value = '<span style="color: orange; font-weight: bold;">' . $value . '</span>';
375
+ break;
376
+
377
+ default:
378
+ break;
379
+ }
380
+
381
+ return $value.$this->getViewLogIconHtml($row->getId());
382
+ }
383
+
384
+ protected function callbackFilterTitle($collection, $column)
385
+ {
386
+ $value = $column->getFilter()->getValue();
387
+
388
+ if ($value == null) {
389
+ return;
390
+ }
391
+
392
+ $collection->getSelect()->where('second_table.title LIKE ? OR second_table.sku LIKE ?', '%'.$value.'%');
393
+ }
394
+
395
+ // ####################################
396
+
397
+ public function getViewLogIconHtml($listingOtherId)
398
+ {
399
+ $listingOtherId = (int)$listingOtherId;
400
+
401
+ // Get last messages
402
+ //--------------------------
403
+ $dbSelect = $this->connRead->select()
404
+ ->from(
405
+ Mage::getResourceModel('M2ePro/Listing_Other_Log')->getMainTable(),
406
+ array('action_id','action','type','description','create_date','initiator')
407
+ )
408
+ ->where('`listing_other_id` = ?', $listingOtherId)
409
+ ->where('`action_id` IS NOT NULL')
410
+ ->order(array('id DESC'))
411
+ ->limit(30);
412
+
413
+ $logRows = $this->connRead->fetchAll($dbSelect);
414
+ //--------------------------
415
+
416
+ // Get grouped messages by action_id
417
+ //--------------------------
418
+ $actionsRows = array();
419
+ $tempActionRows = array();
420
+ $lastActionId = false;
421
+
422
+ foreach ($logRows as $row) {
423
+
424
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
425
+
426
+ if ($row['action_id'] !== $lastActionId) {
427
+ if (count($tempActionRows) > 0) {
428
+ $actionsRows[] = array(
429
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
430
+ 'date' => $this->getMainDateForActionId($tempActionRows),
431
+ 'action' => $this->getActionForAction($tempActionRows[0]),
432
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
433
+ 'items' => $tempActionRows
434
+ );
435
+ $tempActionRows = array();
436
+ }
437
+ $lastActionId = $row['action_id'];
438
+ }
439
+ $tempActionRows[] = $row;
440
+ }
441
+
442
+ if (count($tempActionRows) > 0) {
443
+ $actionsRows[] = array(
444
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
445
+ 'date' => $this->getMainDateForActionId($tempActionRows),
446
+ 'action' => $this->getActionForAction($tempActionRows[0]),
447
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
448
+ 'items' => $tempActionRows
449
+ );
450
+ }
451
+
452
+ if (count($actionsRows) <= 0) {
453
+ return '';
454
+ }
455
+
456
+ $tips = array(
457
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
458
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
459
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
460
+ );
461
+
462
+ $icons = array(
463
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
464
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
465
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
466
+ );
467
+
468
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
469
+ 'entity_id' => $listingOtherId,
470
+ 'rows' => $actionsRows,
471
+ 'tips' => $tips,
472
+ 'icons' => $icons,
473
+ 'view_help_handler' => 'AmazonListingOtherGridHandlerObj.viewItemHelp',
474
+ 'hide_help_handler' => 'AmazonListingOtherGridHandlerObj.hideItemHelp',
475
+ ));
476
+
477
+ return $summary->toHtml();
478
+ }
479
+
480
+ public function getActionForAction($actionRows)
481
+ {
482
+ $string = '';
483
+
484
+ switch ((int)$actionRows['action']) {
485
+ case Ess_M2ePro_Model_Listing_Other_Log::ACTION_CHANNEL_CHANGE:
486
+ $string = Mage::helper('M2ePro')->__('Channel Change');
487
+ break;
488
+ }
489
+
490
+ return $string;
491
+ }
492
+
493
+ public function getInitiatorForAction($actionRows)
494
+ {
495
+ $string = '';
496
+
497
+ switch ($actionRows['initiator']) {
498
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
499
+ $string = '';
500
+ break;
501
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
502
+ $string = Mage::helper('M2ePro')->__('Manual');
503
+ break;
504
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
505
+ $string = Mage::helper('M2ePro')->__('Automatic');
506
+ break;
507
+ }
508
+
509
+ return $string;
510
+ }
511
+
512
+ public function getMainTypeForActionId($actionRows)
513
+ {
514
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
515
+
516
+ foreach ($actionRows as $row) {
517
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
518
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
519
+ break;
520
+ }
521
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
522
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
523
+ }
524
+ }
525
+
526
+ return $type;
527
+ }
528
+
529
+ public function getMainDateForActionId($actionRows)
530
+ {
531
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
532
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
533
+ }
534
+
535
+ // ####################################
536
+
537
+ protected function _toHtml()
538
+ {
539
+ $javascriptsMain = <<<JAVASCRIPT
540
+ <script type="text/javascript">
541
+
542
+ if (typeof AmazonListingOtherGridHandlerObj != 'undefined') {
543
+ AmazonListingOtherGridHandlerObj.afterInitPage();
544
+ }
545
+
546
+ Event.observe(window, 'load', function() {
547
+ setTimeout(function() {
548
+ AmazonListingOtherGridHandlerObj.afterInitPage();
549
+ }, 350);
550
+ });
551
+
552
+ </script>
553
+ JAVASCRIPT;
554
+
555
+ return parent::_toHtml().$javascriptsMain;
556
+ }
557
+
558
+ // ####################################
559
+
560
+ public function getGridUrl()
561
+ {
562
+ return $this->getUrl('*/adminhtml_common_amazon_listing_other/grid', array('_current' => true));
563
+ }
564
+
565
+ public function getRowUrl($row)
566
+ {
567
+ return false;
568
+ }
569
+
570
+ // ####################################
571
+ }
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,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $buttonResetBlock = $this->getChild('productSearch_cleanSuggest_button');
52
+
53
+ if (empty($buttonResetBlock)) {
54
+ //------------------------------
55
+ $data = array(
56
+ 'id' => 'productSearch_cleanSuggest_button',
57
+ 'label' => Mage::helper('M2ePro')->__('Clear Search Results'),
58
+ 'class' => 'productSearch_cleanSuggest_button',
59
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndOpenSearchMenu()'
60
+ );
61
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
62
+ $this->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
63
+ //------------------------------
64
+ }
65
+
66
+ parent::_beforeToHtml();
67
+ }
68
+
69
+ protected function _toHtml()
70
+ {
71
+ $vocabularyAttributesBlock = $this->getLayout()->createBlock(
72
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyAttributesPopup'
73
+ );
74
+
75
+ $vocabularyOptionsBlock = $this->getLayout()->createBlock(
76
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyOptionsPopup'
77
+ );
78
+
79
+ return $vocabularyAttributesBlock->toHtml() . $vocabularyOptionsBlock->toHtml() . parent::_toHtml();
80
+ }
81
+
82
+ // ####################################
83
+ }
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,892 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'is_general_id_owner' => 'second_table.is_general_id_owner',
97
+ 'general_id' => 'second_table.general_id',
98
+ 'is_afn_channel' => 'second_table.is_afn_channel',
99
+ 'is_variation_parent' => 'second_table.is_variation_parent',
100
+ 'online_sku' => 'second_table.sku',
101
+ 'online_qty' => 'second_table.online_qty',
102
+ 'online_price' => 'second_table.online_price',
103
+ 'online_sale_price' => 'second_table.online_sale_price',
104
+ 'online_sale_price_start_date' => 'second_table.online_sale_price_start_date',
105
+ 'online_sale_price_end_date' => 'second_table.online_sale_price_end_date',
106
+ 'min_online_price' => 'IF(
107
+ (`t`.`variation_min_price` IS NULL),
108
+ IF(
109
+ `second_table`.`online_sale_price_start_date` IS NOT NULL AND
110
+ `second_table`.`online_sale_price_end_date` IS NOT NULL AND
111
+ `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND
112
+ `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(),
113
+ `second_table`.`online_sale_price`,
114
+ `second_table`.`online_price`
115
+ ),
116
+ `t`.`variation_min_price`
117
+ )',
118
+ 'max_online_price' => 'IF(
119
+ (`t`.`variation_max_price` IS NULL),
120
+ IF(
121
+ `second_table`.`online_sale_price_start_date` IS NOT NULL AND
122
+ `second_table`.`online_sale_price_end_date` IS NOT NULL AND
123
+ `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND
124
+ `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(),
125
+ `second_table`.`online_sale_price`,
126
+ `second_table`.`online_price`
127
+ ),
128
+ `t`.`variation_max_price`
129
+ )'
130
+ )
131
+ );
132
+ $listingProductCollection->getSelect()->joinLeft(
133
+ new Zend_Db_Expr('(
134
+ SELECT
135
+ `malp`.`variation_parent_id`,
136
+ MIN(
137
+ IF(
138
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
139
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
140
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
141
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
142
+ `malp`.`online_sale_price`,
143
+ `malp`.`online_price`
144
+ )
145
+ ) as variation_min_price,
146
+ MAX(
147
+ IF(
148
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
149
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
150
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
151
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
152
+ `malp`.`online_sale_price`,
153
+ `malp`.`online_price`
154
+ )
155
+ ) as variation_max_price
156
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
157
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
158
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
159
+ WHERE `mlp`.`status` IN (
160
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
161
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
162
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
163
+ GROUP BY `malp`.`variation_parent_id`
164
+ )'),
165
+ 'second_table.listing_product_id=t.variation_parent_id',
166
+ array(
167
+ 'variation_min_price' => 'variation_min_price',
168
+ 'variation_max_price' => 'variation_max_price',
169
+ )
170
+ );
171
+
172
+ //------------------------------
173
+ $listingOtherCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
174
+ $listingOtherCollection->getSelect()->distinct();
175
+
176
+ // add stock availability, type id, status & visibility to select
177
+ //------------------------------
178
+ $listingOtherCollection->getSelect()
179
+ ->joinLeft(
180
+ array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()),
181
+ '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)',
182
+ array('is_in_stock'))
183
+ ->joinLeft(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
184
+ '(cpe.entity_id = `main_table`.product_id)',
185
+ array('magento_sku'=>'sku'));
186
+ //------------------------------
187
+
188
+ $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
189
+ $listingOtherCollection->getSelect()->columns(
190
+ array(
191
+ 'is_m2epro_listing' => new Zend_Db_Expr(0),
192
+ 'magento_sku' => 'cpe.sku',
193
+ 'is_in_stock' => 'cisi.is_in_stock',
194
+ 'product_name' => 'second_table.title',
195
+ 'listing_title' => new Zend_Db_Expr('NULL'),
196
+ 'store_id' => new Zend_Db_Expr(0),
197
+ 'account_id' => 'main_table.account_id',
198
+ 'marketplace_id' => 'main_table.marketplace_id',
199
+ 'template_selling_format_id' => new Zend_Db_Expr('NULL'),
200
+ 'listing_product_id' => new Zend_Db_Expr('NULL'),
201
+ 'product_id' => 'main_table.product_id',
202
+ 'listing_id' => new Zend_Db_Expr('NULL'),
203
+ 'status' => 'main_table.status',
204
+ 'is_general_id_owner' => new Zend_Db_Expr('NULL'),
205
+ 'general_id' => 'second_table.general_id',
206
+ 'is_afn_channel' => 'second_table.is_afn_channel',
207
+ 'is_variation_parent' => new Zend_Db_Expr('NULL'),
208
+ 'online_sku' => 'second_table.sku',
209
+ 'online_qty' => 'second_table.online_qty',
210
+ 'online_price' => 'second_table.online_price',
211
+ 'online_sale_price' => new Zend_Db_Expr('NULL'),
212
+ 'online_sale_price_start_date' => new Zend_Db_Expr('NULL'),
213
+ 'online_sale_price_end_date' => new Zend_Db_Expr('NULL'),
214
+ 'min_online_price' => 'second_table.online_price',
215
+ 'max_online_price' => 'second_table.online_price',
216
+ 'variation_min_price' => new Zend_Db_Expr('NULL'),
217
+ 'variation_max_price' => new Zend_Db_Expr('NULL')
218
+ )
219
+ );
220
+ //------------------------------
221
+
222
+ //------------------------------
223
+ $selects = array(
224
+ $listingProductCollection->getSelect(),
225
+ $listingOtherCollection->getSelect()
226
+ );
227
+
228
+ $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
229
+ $unionSelect->union($selects);
230
+
231
+ $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
232
+ $resultCollection->getSelect()->reset()->from(
233
+ array('main_table' => $unionSelect),
234
+ array(
235
+ 'is_m2epro_listing',
236
+ 'magento_sku',
237
+ 'is_in_stock',
238
+ 'product_name',
239
+ 'listing_title',
240
+ 'store_id',
241
+ 'account_id',
242
+ 'marketplace_id',
243
+ 'template_selling_format_id',
244
+ 'listing_product_id',
245
+ 'product_id',
246
+ 'listing_id',
247
+ 'status',
248
+ 'is_general_id_owner',
249
+ 'general_id',
250
+ 'is_afn_channel',
251
+ 'is_variation_parent',
252
+ 'online_sku',
253
+ 'online_qty',
254
+ 'online_price',
255
+ 'online_sale_price',
256
+ 'online_sale_price_start_date',
257
+ 'online_sale_price_end_date',
258
+ 'min_online_price',
259
+ 'max_online_price',
260
+ 'variation_min_price',
261
+ 'variation_max_price'
262
+ )
263
+ );
264
+
265
+ // exit($resultCollection->getSelect()->__toString());
266
+
267
+ // Set collection to grid
268
+ $this->setCollection($resultCollection);
269
+
270
+ return parent::_prepareCollection();
271
+ }
272
+
273
+ protected function _prepareColumns()
274
+ {
275
+ $this->addColumn('product_id', array(
276
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
277
+ 'align' => 'right',
278
+ 'width' => '100px',
279
+ 'type' => 'number',
280
+ 'index' => 'product_id',
281
+ 'filter_index' => 'product_id',
282
+ 'frame_callback' => array($this, 'callbackColumnProductId')
283
+ ));
284
+
285
+ $this->addColumn('name', array(
286
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Listing / Product SKU'),
287
+ 'align' => 'left',
288
+ //'width' => '300px',
289
+ 'type' => 'text',
290
+ 'index' => 'product_name',
291
+ 'filter_index' => 'product_name',
292
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
293
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
294
+ ));
295
+
296
+ $this->addColumn('stock_availability',
297
+ array(
298
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
299
+ 'width' => '100px',
300
+ 'index' => 'is_in_stock',
301
+ 'filter_index' => 'is_in_stock',
302
+ 'type' => 'options',
303
+ 'sortable' => false,
304
+ 'options' => array(
305
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
306
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
307
+ ),
308
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
309
+ ));
310
+
311
+ if (Mage::helper('M2ePro/View_Common')->is3rdPartyShouldBeShown(Ess_M2ePro_Helper_Component_Amazon::NICK)) {
312
+ $this->addColumn('is_m2epro_listing', array(
313
+ 'header' => Mage::helper('M2ePro')->__('Listing Type'),
314
+ 'align' => 'left',
315
+ 'width' => '100px',
316
+ 'type' => 'options',
317
+ 'sortable' => false,
318
+ 'index' => 'is_m2epro_listing',
319
+ 'options' => array(
320
+ 1 => Mage::helper('M2ePro')->__('M2E Pro'),
321
+ 0 => Mage::helper('M2ePro')->__('3rd Party')
322
+ )
323
+ ));
324
+ }
325
+
326
+ $this->addColumn('sku', array(
327
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
328
+ 'align' => 'left',
329
+ 'width' => '150px',
330
+ 'type' => 'text',
331
+ 'index' => 'online_sku',
332
+ 'filter_index' => 'online_sku',
333
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
334
+ ));
335
+
336
+ $this->addColumn('general_id', array(
337
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
338
+ 'align' => 'left',
339
+ 'width' => '100px',
340
+ 'type' => 'text',
341
+ 'index' => 'general_id',
342
+ 'filter_index' => 'general_id',
343
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
344
+ ));
345
+
346
+ $this->addColumn('online_qty', array(
347
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
348
+ 'align' => 'right',
349
+ 'width' => '70px',
350
+ 'type' => 'number',
351
+ 'index' => 'online_qty',
352
+ 'filter_index' => 'online_qty',
353
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
354
+ ));
355
+
356
+ $dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
357
+
358
+ if ($dir == 'desc') {
359
+ $priceSortField = 'max_online_price';
360
+ } else {
361
+ $priceSortField = 'min_online_price';
362
+ }
363
+
364
+ $this->addColumn('online_price', array(
365
+ 'header' => Mage::helper('M2ePro')->__('Price'),
366
+ 'align' => 'right',
367
+ 'width' => '70px',
368
+ 'type' => 'number',
369
+ 'index' => $priceSortField,
370
+ 'filter_index' => $priceSortField,
371
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
372
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
373
+ ));
374
+
375
+ $this->addColumn('is_afn_channel', array(
376
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
377
+ 'width' => '90px',
378
+ 'index' => 'is_afn_channel',
379
+ 'filter_index' => 'is_afn_channel',
380
+ 'type' => 'options',
381
+ 'sortable' => false,
382
+ 'options' => array(
383
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
384
+ 1 => Mage::helper('M2ePro')->__('Amazon')
385
+ ),
386
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
387
+ ));
388
+
389
+ $this->addColumn('status', array(
390
+ 'header' => Mage::helper('M2ePro')->__('Status'),
391
+ 'width' => '125px',
392
+ 'index' => 'status',
393
+ 'filter_index' => 'status',
394
+ 'type' => 'options',
395
+ 'sortable' => false,
396
+ 'options' => array(
397
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
398
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
399
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
400
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
401
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
402
+ ),
403
+ 'frame_callback' => array($this, 'callbackColumnStatus')
404
+ ));
405
+
406
+ $this->addColumn('goto_listing_item', array(
407
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
408
+ 'align' => 'center',
409
+ 'width' => '50px',
410
+ 'type' => 'text',
411
+ 'filter' => false,
412
+ 'sortable' => false,
413
+ 'frame_callback' => array($this, 'callbackColumnActions')
414
+ ));
415
+
416
+ return parent::_prepareColumns();
417
+ }
418
+
419
+ // ####################################
420
+
421
+ public function callbackColumnProductId($value, $row, $column, $isExport)
422
+ {
423
+ if (is_null($row->getData('product_id'))) {
424
+ return Mage::helper('M2ePro')->__('N/A');
425
+ }
426
+
427
+ $productId = (int)$row->getData('product_id');
428
+ $storeId = (int)$row->getData('store_id');
429
+
430
+ $withoutImageHtml = '<a href="'
431
+ .$this->getUrl('adminhtml/catalog_product/edit',
432
+ array('id' => $productId))
433
+ .'" target="_blank">'
434
+ .$productId
435
+ .'</a>';
436
+
437
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
438
+ ->getGroupValue('/view/',
439
+ 'show_products_thumbnails');
440
+ if (!$showProductsThumbnails) {
441
+ return $withoutImageHtml;
442
+ }
443
+
444
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
445
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
446
+ $magentoProduct->setProductId($productId);
447
+ $magentoProduct->setStoreId($storeId);
448
+
449
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
450
+ if (is_null($imageUrlResized)) {
451
+ return $withoutImageHtml;
452
+ }
453
+
454
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
455
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
456
+
457
+ return $withImageHtml;
458
+ }
459
+
460
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
461
+ {
462
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
463
+
464
+ if (!is_null($row->getData('listing_id'))) {
465
+ $urlParams = array();
466
+ $urlParams['id'] = $row->getData('listing_id');
467
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/search');
468
+
469
+ $listingUrl = $this->getUrl('*/adminhtml_common_amazon_listing/view',$urlParams);
470
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
471
+
472
+ if (strlen($listingTitle) > 50) {
473
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
474
+ }
475
+
476
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
477
+ $value .= '<strong>'
478
+ .Mage::helper('M2ePro')->__('Listing')
479
+ .': </strong> <a href="'
480
+ .$listingUrl
481
+ .'">'
482
+ .$listingTitle
483
+ .'</a>';
484
+ }
485
+
486
+ if (!is_null($row->getData('magento_sku'))) {
487
+ $tempSku = $row->getData('magento_sku');
488
+
489
+ $value .= '<br/><strong>'
490
+ . Mage::helper('M2ePro')->__('SKU')
491
+ . ':</strong> '
492
+ . Mage::helper('M2ePro')->escapeHtml($tempSku);
493
+ }
494
+
495
+ if (is_null($row->getData('listing_product_id'))) {
496
+ return $value;
497
+ }
498
+
499
+ $listingProductId = (int)$row->getData('listing_product_id');
500
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
501
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
502
+
503
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
504
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
505
+ ->getTypeModel()->getProductAttributes();
506
+
507
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey;"><br/>';
508
+ $value .= implode(', ', $productOptions);
509
+ $value .= '</div>';
510
+ }
511
+
512
+ if ($listingProduct->getChildObject()->getVariationManager()->isIndividualType() &&
513
+ $listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()
514
+ ) {
515
+ $productOptions = $listingProduct->getChildObject()
516
+ ->getVariationManager()->getTypeModel()->getProductOptions();
517
+
518
+ $value .= '<br/>';
519
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
520
+ foreach ($productOptions as $attribute => $option) {
521
+ !$option && $option = '--';
522
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
523
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
524
+ }
525
+ $value .= '</div>';
526
+ $value .= '<br/>';
527
+ }
528
+
529
+ return $value;
530
+ }
531
+
532
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
533
+ {
534
+ if (is_null($row->getData('is_in_stock'))) {
535
+ return Mage::helper('M2ePro')->__('N/A');
536
+ }
537
+
538
+ if ((int)$row->getData('is_in_stock') <= 0) {
539
+ return '<span style="color: red;">'.$value.'</span>';
540
+ }
541
+
542
+ return $value;
543
+ }
544
+
545
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
546
+ {
547
+ if ((!$row->getData('is_variation_parent') &&
548
+ $row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
549
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
550
+
551
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
552
+ }
553
+
554
+ if (is_null($value) || $value === '') {
555
+ return Mage::helper('M2ePro')->__('N/A');
556
+ }
557
+
558
+ return $value;
559
+ }
560
+
561
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
562
+ {
563
+ if (empty($value)) {
564
+
565
+ if ((int)$row->getData('status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
566
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
567
+ }
568
+
569
+ if ($row->getData('is_general_id_owner')) {
570
+ return Mage::helper('M2ePro')->__('New ASIN/ISBN');
571
+ }
572
+
573
+ return Mage::helper('M2ePro')->__('N/A');
574
+ }
575
+
576
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($value, $row->getData('marketplace_id'));
577
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
578
+ }
579
+
580
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
581
+ {
582
+ if ((!$row->getData('is_variation_parent') &&
583
+ $row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
584
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
585
+
586
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
587
+ }
588
+
589
+ if ($row->getData('is_afn_channel')) {
590
+ return Mage::helper('M2ePro')->__('N/A');
591
+ }
592
+
593
+ if (is_null($value) || $value === '') {
594
+ if ($row->getData('status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
595
+ return '<i style="color:gray;">receiving...</i>';
596
+ }
597
+
598
+ return Mage::helper('M2ePro')->__('N/A');
599
+ }
600
+
601
+ if ($value <= 0) {
602
+ return '<span style="color: red;">0</span>';
603
+ }
604
+
605
+ return $value;
606
+ }
607
+
608
+ public function callbackColumnPrice($value, $row, $column, $isExport)
609
+ {
610
+ if ((!$row->getData('is_variation_parent') &&
611
+ $row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
612
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
613
+
614
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
615
+ }
616
+
617
+ $onlineMinPrice = $row->getData('min_online_price');
618
+ $onlineMaxPrice = $row->getData('max_online_price');
619
+
620
+ if (is_null($onlineMinPrice) || $onlineMinPrice === '') {
621
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
622
+ $row->getData('is_variation_parent')
623
+ ) {
624
+ return Mage::helper('M2ePro')->__('N/A');
625
+ } else {
626
+ return '<i style="color:gray;">receiving...</i>';
627
+ }
628
+ }
629
+
630
+ $marketplaceId = $row->getData('marketplace_id');
631
+ $currency = Mage::helper('M2ePro/Component_Amazon')
632
+ ->getCachedObject('Marketplace',$marketplaceId)
633
+ ->getChildObject()
634
+ ->getDefaultCurrency();
635
+
636
+ if ($row->getData('is_variation_parent')) {
637
+ $onlineMinPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMinPrice);
638
+ $onlineMaxPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMaxPrice);
639
+
640
+ return $onlineMinPriceStr . (($onlineMinPrice != $onlineMaxPrice) ? ' - ' . $onlineMaxPriceStr : '');
641
+ }
642
+
643
+ $onlinePrice = $row->getData('online_price');
644
+ if ((float)$onlinePrice <= 0) {
645
+ $priceValue = '<span style="color: #f00;">0</span>';
646
+ } else {
647
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
648
+ }
649
+
650
+ $resultHtml = '';
651
+
652
+ $salePrice = $row->getData('online_sale_price');
653
+ if (!$row->getData('is_variation_parent') && (float)$salePrice > 0) {
654
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
655
+
656
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
657
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
658
+
659
+ if ($currentTimestamp <= $endDateTimestamp) {
660
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
661
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
662
+
663
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
664
+
665
+ $fromDate = Mage::app()->getLocale()->date(
666
+ $row->getData('online_sale_price_start_date'), $dateFormat
667
+ )->toString($dateFormat);
668
+ $toDate = Mage::app()->getLocale()->date(
669
+ $row->getData('online_sale_price_end_date'), $dateFormat
670
+ )->toString($dateFormat);
671
+
672
+ $intervalHtml = '<img class="tool-tip-image"
673
+ style="vertical-align: middle;"
674
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
675
+ text-align: left;
676
+ width: 110px;
677
+ background: #E3E3E3;">
678
+ <img src="'.$iconHelpPath.'">
679
+ <span style="color:gray;">
680
+ <strong>From:</strong> '.$fromDate.'<br/>
681
+ <strong>To:</strong> '.$toDate.'
682
+ </span>
683
+ </span>';
684
+
685
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
686
+
687
+ if ($currentTimestamp >= $startDateTimestamp &&
688
+ $currentTimestamp <= $endDateTimestamp &&
689
+ $salePrice < (float)$onlinePrice
690
+ ) {
691
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
692
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
693
+ } else {
694
+ $resultHtml .= $priceValue;
695
+ $resultHtml .= '<br/>'.$intervalHtml.
696
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
697
+ }
698
+ }
699
+ }
700
+
701
+ if (empty($resultHtml)) {
702
+ $resultHtml = $priceValue;
703
+ }
704
+
705
+ return $resultHtml;
706
+ }
707
+
708
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
709
+ {
710
+ if ((!$row->getData('is_variation_parent') &&
711
+ $row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
712
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
713
+
714
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
715
+ }
716
+
717
+ if (is_null($value) || $value === '') {
718
+ return Mage::helper('M2ePro')->__('N/A');
719
+ }
720
+
721
+ return $value;
722
+ }
723
+
724
+ public function callbackColumnStatus($value, $row, $column, $isExport)
725
+ {
726
+ switch ($row->getData('status')) {
727
+
728
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
729
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
730
+ $value = '<span style="color: gray;">' . $value . '</span>';
731
+ break;
732
+
733
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
734
+ $value = '<span style="color: green;">' . $value . '</span>';
735
+ break;
736
+
737
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
738
+ $value = '<span style="color: red;">'.$value.'</span>';
739
+ break;
740
+
741
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
742
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
743
+ break;
744
+
745
+ default:
746
+ break;
747
+ }
748
+
749
+ if (is_null($row->getData('listing_product_id'))) {
750
+ return $value;
751
+ }
752
+
753
+ $listingProductId = (int)$row->getData('listing_product_id');
754
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
755
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
756
+
757
+ $tempLocks = $listingProduct->getObjectLocks();
758
+
759
+ foreach ($tempLocks as $lock) {
760
+
761
+ switch ($lock->getTag()) {
762
+
763
+ case 'list_action':
764
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
765
+ break;
766
+
767
+ case 'relist_action':
768
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
769
+ break;
770
+
771
+ case 'revise_action':
772
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
773
+ break;
774
+
775
+ case 'stop_action':
776
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
777
+ break;
778
+
779
+ case 'stop_and_remove_action':
780
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
781
+ break;
782
+
783
+ case 'delete_and_remove_action':
784
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
785
+ break;
786
+
787
+ default:
788
+ break;
789
+
790
+ }
791
+ }
792
+
793
+ return $value;
794
+ }
795
+
796
+ public function callbackColumnActions($value, $row, $column, $isExport)
797
+ {
798
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to Listing'));
799
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
800
+
801
+ if ($row->getData('is_m2epro_listing')) {
802
+ $url = $this->getUrl('*/adminhtml_common_amazon_listing/view/',array(
803
+ 'id' => $row->getData('listing_id'),
804
+ 'filter' => base64_encode(
805
+ 'product_id[from]='.(int)$row->getData('product_id')
806
+ .'&product_id[to]='.(int)$row->getData('product_id')
807
+ )
808
+ ));
809
+ } else {
810
+ $url = $this->getUrl('*/adminhtml_common_amazon_listing_other/view/', array(
811
+ 'account' => $row->getData('account_id'),
812
+ 'marketplace' => $row->getData('marketplace_id'),
813
+ 'filter' => base64_encode(
814
+ 'title='.$row->getData('online_sku')
815
+ )
816
+ ));
817
+ }
818
+
819
+ $html = <<<HTML
820
+ <div style="float:right; margin:5px 15px 0 0;">
821
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" alt="{$altTitle}" /></a>
822
+ </div>
823
+ HTML;
824
+
825
+ return $html;
826
+ }
827
+
828
+ // ####################################
829
+
830
+ protected function callbackFilterTitle($collection, $column)
831
+ {
832
+ $value = $column->getFilter()->getValue();
833
+
834
+ if ($value == null) {
835
+ return;
836
+ }
837
+
838
+ $collection->getSelect()
839
+ ->where('product_name LIKE ? OR magento_sku LIKE ? OR listing_title LIKE ?', '%'.$value.'%');
840
+ }
841
+
842
+ protected function callbackFilterPrice($collection, $column)
843
+ {
844
+ $value = $column->getFilter()->getValue();
845
+
846
+ if (empty($value)) {
847
+ return;
848
+ }
849
+
850
+ $condition = '';
851
+
852
+ if (isset($value['from']) && $value['from'] != '') {
853
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
854
+ }
855
+ if (isset($value['to']) && $value['to'] != '') {
856
+ if (isset($value['from']) && $value['from'] != '') {
857
+ $condition .= ' AND ';
858
+ }
859
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
860
+ }
861
+
862
+ $condition = '(' . $condition . ') OR (';
863
+
864
+ if (isset($value['from']) && $value['from'] != '') {
865
+ $condition .= 'max_online_price >= \''.$value['from'].'\'';
866
+ }
867
+ if (isset($value['to']) && $value['to'] != '') {
868
+ if (isset($value['from']) && $value['from'] != '') {
869
+ $condition .= ' AND ';
870
+ }
871
+ $condition .= 'max_online_price <= \''.$value['to'].'\'';
872
+ }
873
+
874
+ $condition .= ')';
875
+
876
+ $collection->getSelect()->where($condition);
877
+ }
878
+
879
+ // ####################################
880
+
881
+ public function getGridUrl()
882
+ {
883
+ return $this->getUrl('*/adminhtml_common_amazon_listing/searchGrid', array('_current'=>true));
884
+ }
885
+
886
+ public function getRowUrl($row)
887
+ {
888
+ return false;
889
+ }
890
+
891
+ // ####################################
892
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/TemplateDescription/Grid.php ADDED
@@ -0,0 +1,463 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->getSelect()->columns(
378
+ array(
379
+ 'main_table.additional_data'
380
+ )
381
+ );
382
+
383
+ foreach ($collection->getData() as $row) {
384
+ $data = json_decode($row['additional_data'], true);
385
+
386
+ $count = count($data['variation_product_attributes']);
387
+ if (!in_array($count, $this->productsAttributesCountVariations)) {
388
+ $this->productsAttributesCountVariations[] = $count;
389
+ }
390
+ }
391
+ }
392
+
393
+ return $this->productsAttributesCountVariations;
394
+ }
395
+
396
+ // ####################################
397
+
398
+ private function prepareCollection($collection)
399
+ {
400
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Template_Description_Collection $preparedCollection */
401
+ $preparedCollection = new Varien_Data_Collection();
402
+
403
+ $data = $collection->getData();
404
+ $preparedData = array();
405
+ foreach ($data as $item) {
406
+ if (!$this->getCheckNewAsinAccepted()) {
407
+ $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED;
408
+ $preparedData[] = $item;
409
+ continue;
410
+ }
411
+
412
+ if (!$item['is_new_asin_accepted']) {
413
+ $item['description_template_action_status'] = self::ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED;
414
+ $preparedData[] = $item;
415
+ continue;
416
+ }
417
+
418
+ $productAttrCounts = $this->getProductAttributesCountVariations();
419
+
420
+ if (!empty($productAttrCounts)) {
421
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
422
+ $detailsModel->setMarketplaceId($this->getMarketplaceId());
423
+ $themes = $detailsModel->getVariationThemes($item['product_data_nick']);
424
+
425
+ if (empty($themes)) {
426
+ $item['description_template_action_status'] = self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED;
427
+ $preparedData[] = $item;
428
+ continue;
429
+ }
430
+
431
+ $themeAttrCounts = array();
432
+ foreach ($themes as $theme) {
433
+ $themeAttrCounts[] = count($theme['attributes']);
434
+ }
435
+
436
+ if (count(array_intersect($productAttrCounts, $themeAttrCounts)) !== count($productAttrCounts)) {
437
+ $item['description_template_action_status'] = self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED;
438
+ $preparedData[] = $item;
439
+ continue;
440
+ }
441
+ }
442
+
443
+ $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED;
444
+ $preparedData[] = $item;
445
+ continue;
446
+ }
447
+
448
+ if (!empty($preparedData)) {
449
+ usort($preparedData, function($a, $b)
450
+ {
451
+ return $a["description_template_action_status"] < $b["description_template_action_status"];
452
+ });
453
+
454
+ foreach ($preparedData as $item) {
455
+ $preparedCollection->addItem(new Varien_Object($item));
456
+ }
457
+ }
458
+
459
+ return $preparedCollection;
460
+ }
461
+
462
+ // ####################################
463
+ }
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,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $this->addTab('vocabulary', array(
104
+ 'label' => Mage::helper('M2ePro')->__('Advanced'),
105
+ 'title' => Mage::helper('M2ePro')->__('Advanced'),
106
+ 'content' => $this->getLayout()
107
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_vocabulary')
108
+ ->setListingProductId($this->getListingProductId())
109
+ ->toHtml()
110
+ ));
111
+
112
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
113
+ if(empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner()) {
114
+ $this->setActiveTab('settings');
115
+ } else {
116
+ $this->setActiveTab('variations');
117
+ }
118
+
119
+ return parent::_beforeToHtml();
120
+ }
121
+
122
+ protected function _toHtml()
123
+ {
124
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
125
+
126
+ $showMask = 0;
127
+ if(!(empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner())) {
128
+ $showMask = 1;
129
+ }
130
+
131
+ $data = array(
132
+ 'style' => 'float: right; margin-top: 7px; ',
133
+ 'label' => Mage::helper('M2ePro')->__('Close'),
134
+ 'onclick' => 'ListingGridHandlerObj.variationProductManageHandler.closeManageVariationsPopup()'
135
+ );
136
+ $closeBtn = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
137
+
138
+ $additionalJavascript = <<<JAVASCRIPT
139
+ <script type="text/javascript">
140
+ amazonVariationProductManageTabsJsTabs.moveTabContentInDest();
141
+
142
+ if (!{$showMask}) {
143
+ amazonVariationProductManageTabsJsTabs.tabs[0].hide();
144
+ }
145
+
146
+ ListingGridHandlerObj.variationProductManageHandler.loadVariationsGrid({$showMask});
147
+ </script>
148
+ JAVASCRIPT;
149
+
150
+ return parent::_toHtml() .
151
+ '<div id="variation_product_manage_tabs_container"></div>' .
152
+ $additionalJavascript .
153
+ $closeBtn->toHtml();
154
+ }
155
+
156
+ // ####################################
157
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php ADDED
@@ -0,0 +1,577 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $marketPlaceId = $this->getListingProduct()->getListing()->getMarketplaceId();
306
+
307
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
308
+ $detailsModel->setMarketplaceId($marketPlaceId);
309
+
310
+ $channelThemes = $detailsModel->getVariationThemes($descriptionTemplate->getProductDataNick());
311
+
312
+ $variationHelper = Mage::helper('M2ePro/Component_Amazon_Variation');
313
+ $themesUsageData = $variationHelper->getThemesUsageData();
314
+ $usedThemes = array();
315
+
316
+ foreach ($themesUsageData[$marketPlaceId] as $theme => $count) {
317
+ if (!empty($channelThemes[$theme])) {
318
+ $usedThemes[$theme] = $channelThemes[$theme];
319
+ }
320
+ }
321
+
322
+ return $this->channelThemes = array_merge($usedThemes, $channelThemes);
323
+ }
324
+
325
+ public function getChannelThemeAttr()
326
+ {
327
+ $theme = $this->getChannelTheme();
328
+ $themes = $this->getChannelThemes();
329
+
330
+ if(!empty($themes[$theme])) {
331
+ return $themes[$theme]['attributes'];
332
+ }
333
+
334
+ return null;
335
+ }
336
+
337
+ public function getChannelThemeNote()
338
+ {
339
+ $theme = $this->getChannelTheme();
340
+ $themes = $this->getChannelThemes();
341
+
342
+ if(!empty($themes[$theme])) {
343
+ return $themes[$theme]['note'];
344
+ }
345
+
346
+ return null;
347
+ }
348
+
349
+ public function getChannelThemeAttrString()
350
+ {
351
+ $themesAttributes = $this->getChannelThemeAttr();
352
+
353
+ if(!empty($themesAttributes)) {
354
+ return implode(', ', $themesAttributes);
355
+ }
356
+
357
+ return Mage::helper('M2ePro')->__('Variation Theme not found.');
358
+ }
359
+
360
+ // ----------------------------------------
361
+
362
+ public function hasMatchedAttributes()
363
+ {
364
+ return $this->getListingProduct()->getChildObject()
365
+ ->getVariationManager()->getTypeModel()->hasMatchedAttributes();
366
+ }
367
+
368
+ public function getMatchedAttributes()
369
+ {
370
+ if($this->hasMatchedAttributes()) {
371
+ return $this->getListingProduct()->getChildObject()
372
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
373
+ }
374
+ return $this->getMatcherAttributes()->getMatchedAttributes();
375
+ }
376
+
377
+ public function getDestinationAttributes()
378
+ {
379
+ if(!$this->hasGeneralId() && $this->isGeneralIdOwner() && $this->hasChannelTheme()) {
380
+ return $this->getChannelThemeAttr();
381
+ }
382
+ return array_keys($this->getListingProduct()->getChildObject()
383
+ ->getVariationManager()->getTypeModel()->getChannelAttributesSets());
384
+ }
385
+
386
+ // ###########################################
387
+
388
+ public function getChildListingProducts()
389
+ {
390
+ if (!is_null($this->childListingProducts)) {
391
+ return $this->childListingProducts;
392
+ }
393
+
394
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
395
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
396
+ }
397
+
398
+ public function getCurrentProductVariations()
399
+ {
400
+ if (!is_null($this->currentProductVariations)) {
401
+ return $this->currentProductVariations;
402
+ }
403
+
404
+ $magentoProductVariations = $this->getListingProduct()
405
+ ->getMagentoProduct()
406
+ ->getVariationInstance()
407
+ ->getVariationsTypeStandard();
408
+
409
+ $productVariations = array();
410
+
411
+ foreach ($magentoProductVariations['variations'] as $option) {
412
+ $productOption = array();
413
+
414
+ foreach ($option as $attribute) {
415
+ $productOption[$attribute['attribute']] = $attribute['option'];
416
+ }
417
+
418
+ $productVariations[] = $productOption;
419
+ }
420
+
421
+ return $this->currentProductVariations = $productVariations;
422
+ }
423
+
424
+ public function getChannelVariations()
425
+ {
426
+ if (!is_null($this->childListingProducts)) {
427
+ return $this->childListingProducts;
428
+ }
429
+
430
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
431
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
432
+ }
433
+
434
+ public function getCurrentChannelVariations()
435
+ {
436
+ return $this->getListingProduct()->getChildObject()
437
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
438
+ }
439
+
440
+ // ------------------------------------------
441
+
442
+ public function getUsedChannelVariations()
443
+ {
444
+ $usedOptions = array();
445
+
446
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
447
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
448
+
449
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
450
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
451
+
452
+ if (!$childTypeModel->isVariationChannelMatched()) {
453
+ continue;
454
+ }
455
+
456
+ $usedOptions[] = $childTypeModel->getChannelOptions();
457
+ }
458
+
459
+ return $usedOptions;
460
+ }
461
+
462
+ public function getUsedProductVariations()
463
+ {
464
+ $usedOptions = array();
465
+
466
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
467
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
468
+
469
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
470
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
471
+
472
+ if (!$childTypeModel->isVariationProductMatched()) {
473
+ continue;
474
+ }
475
+
476
+ $usedOptions[] = $childTypeModel->getProductOptions();
477
+ }
478
+
479
+ return $usedOptions;
480
+ }
481
+
482
+ // ------------------------------------------
483
+
484
+ public function getUnusedProductVariations()
485
+ {
486
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
487
+ }
488
+
489
+ public function getUnusedChannelVariations()
490
+ {
491
+ return $this->getUnusedVariations($this->getCurrentChannelVariations(), $this->getUsedChannelVariations());
492
+ }
493
+
494
+ private function getUnusedVariations($currentVariations, $usedVariations)
495
+ {
496
+ if (empty($currentVariations)) {
497
+ return array();
498
+ }
499
+
500
+ if (empty($usedVariations)) {
501
+ return $currentVariations;
502
+ }
503
+
504
+ $unusedOptions = array();
505
+
506
+ foreach ($currentVariations as $id => $currentOption) {
507
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
508
+ continue;
509
+ }
510
+
511
+ $unusedOptions[$id] = $currentOption;
512
+ }
513
+
514
+ return $unusedOptions;
515
+ }
516
+
517
+ private function isVariationExistsInArray(array $needle, array $haystack)
518
+ {
519
+ foreach ($haystack as $option) {
520
+ if ($option != $needle) {
521
+ continue;
522
+ }
523
+
524
+ return true;
525
+ }
526
+
527
+ return false;
528
+ }
529
+
530
+ // ------------------------------------------
531
+
532
+ public function hasUnusedProductVariation()
533
+ {
534
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
535
+ }
536
+
537
+ public function hasUnusedChannelVariations()
538
+ {
539
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
540
+ }
541
+
542
+ // ------------------------------------------
543
+
544
+ public function hasChildWithEmptyProductOptions()
545
+ {
546
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
547
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
548
+
549
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
550
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
551
+
552
+ if (!$childTypeModel->isVariationProductMatched()) {
553
+ return true;
554
+ }
555
+ }
556
+
557
+ return false;
558
+ }
559
+
560
+ public function hasChildWithEmptyChannelOptions()
561
+ {
562
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
563
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
564
+
565
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
566
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
567
+
568
+ if (!$childTypeModel->isVariationChannelMatched()) {
569
+ return true;
570
+ }
571
+ }
572
+
573
+ return false;
574
+ }
575
+
576
+ // ###########################################
577
+ }
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,1659 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $collection->getSelect()->joinLeft(
80
+ new Zend_Db_Expr('(
81
+ SELECT
82
+ mlpv.listing_product_id,
83
+ GROUP_CONCAT(`mlpvo`.`attribute`, \'=\', `mlpvo`.`product_id` SEPARATOR \'|\') as products_ids
84
+ FROM `'. Mage::getResourceModel('M2ePro/Listing_Product_Variation')->getMainTable() .'` as mlpv
85
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product_Variation_Option')->getMainTable() .
86
+ '` AS `mlpvo` ON (`mlpvo`.`listing_product_variation_id`=`mlpv`.`id`)
87
+ WHERE `mlpv`.`component_mode` = \'amazon\'
88
+ GROUP BY `mlpv`.`listing_product_id`
89
+ )'),
90
+ 'main_table.id=t.listing_product_id',
91
+ array(
92
+ 'products_ids' => 'products_ids',
93
+ )
94
+ );
95
+
96
+ // Set collection to grid
97
+ $this->setCollection($collection);
98
+ // exit($collection->getSelect()->__toString());
99
+
100
+ return parent::_prepareCollection();
101
+ }
102
+
103
+ protected function _prepareColumns()
104
+ {
105
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
106
+ $parentType = $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel();
107
+
108
+ $channelAttributesSets = $parentType->getChannelAttributesSets();
109
+
110
+ if ($parentType->hasMatchedAttributes()) {
111
+ $channelAttributes = array_values($parentType->getMatchedAttributes());
112
+ } else if (!empty($channelAttributesSets)) {
113
+ $channelAttributes = array_keys($channelAttributesSets);
114
+ } else {
115
+ $channelAttributes = array();
116
+ }
117
+
118
+ $this->addColumn('product_options', array(
119
+ 'header' => Mage::helper('M2ePro')->__('Magento Variation'),
120
+ 'align' => 'left',
121
+ 'width' => '210px',
122
+ 'sortable' => false,
123
+ 'index' => 'additional_data',
124
+ 'filter_index' => 'additional_data',
125
+ 'frame_callback' => array($this, 'callbackColumnProductOptions'),
126
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
127
+ 'options' => $parentType->getProductAttributes(),
128
+ 'filter_condition_callback' => array($this, 'callbackProductOptions')
129
+ ));
130
+
131
+ $this->addColumn('channel_options', array(
132
+ 'header' => Mage::helper('M2ePro')->__('Amazon Variation'),
133
+ 'align' => 'left',
134
+ 'width' => '210px',
135
+ 'sortable' => false,
136
+ 'index' => 'additional_data',
137
+ 'filter_index' => 'additional_data',
138
+ 'frame_callback' => array($this, 'callbackColumnChannelOptions'),
139
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
140
+ 'options' => $channelAttributes,
141
+ 'filter_condition_callback' => array($this, 'callbackChannelOptions')
142
+ ));
143
+
144
+ $this->addColumn('sku', array(
145
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
146
+ 'align' => 'left',
147
+ 'type' => 'text',
148
+ 'index' => 'sku',
149
+ 'filter_index' => 'sku',
150
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
151
+ ));
152
+
153
+ $this->addColumn('general_id', array(
154
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
155
+ 'align' => 'left',
156
+ 'width' => '100px',
157
+ 'type' => 'text',
158
+ 'index' => 'general_id',
159
+ 'filter_index' => 'general_id',
160
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
161
+ ));
162
+
163
+ $this->addColumn('online_qty', array(
164
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
165
+ 'align' => 'right',
166
+ 'width' => '70px',
167
+ 'type' => 'number',
168
+ 'index' => 'online_qty',
169
+ 'filter_index' => 'online_qty',
170
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
171
+ ));
172
+
173
+ $this->addColumn('online_price', array(
174
+ 'header' => Mage::helper('M2ePro')->__('Price'),
175
+ 'align' => 'right',
176
+ 'width' => '70px',
177
+ 'type' => 'number',
178
+ 'index' => 'online_price',
179
+ 'filter_index' => 'online_price',
180
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
181
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
182
+ ));
183
+
184
+ $this->addColumn('status', array(
185
+ 'header' => Mage::helper('M2ePro')->__('Status'),
186
+ 'width' => '100px',
187
+ 'index' => 'status',
188
+ 'filter_index' => 'status',
189
+ 'type' => 'options',
190
+ 'sortable' => false,
191
+ 'options' => array(
192
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
193
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
194
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
195
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
196
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
197
+ ),
198
+ 'frame_callback' => array($this, 'callbackColumnStatus')
199
+ ));
200
+
201
+ return parent::_prepareColumns();
202
+ }
203
+
204
+ protected function _prepareMassaction()
205
+ {
206
+ // Set massaction identifiers
207
+ //--------------------------------
208
+ $this->setMassactionIdField('id');
209
+ $this->setMassactionIdFieldOnlyIndexValue(true);
210
+ //--------------------------------
211
+
212
+ // Set mass-action
213
+ //--------------------------------
214
+ $this->getMassactionBlock()->addItem('list', array(
215
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
216
+ 'url' => '',
217
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
218
+ ));
219
+
220
+ $this->getMassactionBlock()->addItem('revise', array(
221
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
222
+ 'url' => '',
223
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
224
+ ));
225
+
226
+ $this->getMassactionBlock()->addItem('relist', array(
227
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
228
+ 'url' => '',
229
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
230
+ ));
231
+
232
+ $this->getMassactionBlock()->addItem('stop', array(
233
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
234
+ 'url' => '',
235
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
236
+ ));
237
+
238
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
239
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
240
+ 'url' => '',
241
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
242
+ ));
243
+
244
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
245
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
246
+ 'url' => '',
247
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
248
+ ));
249
+
250
+ //--------------------------------
251
+
252
+ return parent::_prepareMassaction();
253
+ }
254
+
255
+ // ####################################
256
+
257
+ public function callbackColumnProductOptions($additionalData, $row, $column, $isExport)
258
+ {
259
+ $html = '';
260
+
261
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $typeModel */
262
+ $typeModel = $row->getChildObject()->getVariationManager()->getTypeModel();
263
+
264
+ $html .= '<div class="product-options-main" style="font-size: 11px; color: grey; margin-left: 7px">';
265
+ $productOptions = $typeModel->getProductOptions();
266
+ if (!empty($productOptions)) {
267
+ $productsIds = $this->parseGroupedData($row->getData('products_ids'));
268
+ $uniqueProductsIds = count(array_unique($productsIds)) > 1;
269
+
270
+ $html .= '<div class="m2ePro-variation-attributes product-options-list">';
271
+ if (!$uniqueProductsIds) {
272
+ $url = $this->getUrl('adminhtml/catalog_product/edit', array('id' => reset($productsIds)));
273
+ $html .= '<a href="' . $url . '" target="_blank">';
274
+ }
275
+ foreach ($productOptions as $attribute => $option) {
276
+ !$option && $option = '--';
277
+ $optionHtml = '<span class="attribute-row"><span class="attribute"><strong>' .
278
+ Mage::helper('M2ePro')->escapeHtml($attribute) .
279
+ '</strong></span>:&nbsp;<span class="value">' . Mage::helper('M2ePro')->escapeHtml($option) .
280
+ '</span></span>';
281
+
282
+ if ($uniqueProductsIds && $option !== '--') {
283
+ $url = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productsIds[$attribute]));
284
+ $html .= '<a href="' . $url . '" target="_blank">' . $optionHtml . '</a><br/>';
285
+ } else {
286
+ $html .= $optionHtml . '<br>';
287
+ }
288
+ }
289
+ if (!$uniqueProductsIds) {
290
+ $html .= '</a>';
291
+ }
292
+ $html .= '</div>';
293
+ }
294
+
295
+ if ($this->canChangeProductVariation($row)) {
296
+
297
+ $listingProductId = $row->getId();
298
+ $attributes = $this->getListingProduct()->getChildObject()
299
+ ->getVariationManager()->getTypeModel()->getProductAttributes();
300
+ $variationsTree = $this->getProductVariationsTree($row);
301
+
302
+ sort($attributes);
303
+
304
+ $linkTitle = Mage::helper('M2ePro')->__('Change Variation');
305
+ $linkContent = Mage::helper('M2ePro')->__('Change Variation');
306
+
307
+ $attributes = Mage::helper('M2ePro')->escapeHtml(json_encode($attributes));
308
+ $variationsTree = Mage::helper('M2ePro')->escapeHtml(json_encode($variationsTree));
309
+
310
+ $html .= <<<HTML
311
+ <form action="javascript:void(0);" class="product-options-edit"></form>
312
+ <a href="javascript:"
313
+ onclick="ListingGridHandlerObj.editProductOptions(this, {$attributes}, {$variationsTree}, {$listingProductId})"
314
+ title="{$linkTitle}">{$linkContent}</a>
315
+ HTML;
316
+ }
317
+
318
+ $html .= '</div>';
319
+
320
+ return $html;
321
+ }
322
+
323
+ public function callbackColumnChannelOptions($additionalData, $row, $column, $isExport)
324
+ {
325
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
326
+ $amazonListingProduct = $row->getChildObject();
327
+
328
+ $typeModel = $amazonListingProduct->getVariationManager()->getTypeModel();
329
+
330
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $parentAmazonListingProduct */
331
+ $parentAmazonListingProduct = $typeModel->getParentListingProduct()->getChildObject();
332
+
333
+ $matchedAttributes = $parentAmazonListingProduct->getVariationManager()
334
+ ->getTypeModel()
335
+ ->getMatchedAttributes();
336
+
337
+ if (!$typeModel->isVariationChannelMatched()) {
338
+ if (!$typeModel->isVariationProductMatched() || !$amazonListingProduct->isGeneralIdOwner()) {
339
+ return '';
340
+ }
341
+
342
+ if (empty($matchedAttributes)) {
343
+ return '';
344
+ }
345
+
346
+ $options = array();
347
+
348
+ foreach ($typeModel->getProductOptions() as $attribute => $value) {
349
+ $options[$matchedAttributes[$attribute]] = $value;
350
+ }
351
+ } else {
352
+ $options = $typeModel->getChannelOptions();
353
+
354
+ if (!empty($matchedAttributes)) {
355
+
356
+ $sortedOptions = array();
357
+
358
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
359
+ $sortedOptions[$amazonAttr] = $options[$amazonAttr];
360
+ }
361
+
362
+ $options = $sortedOptions;
363
+ }
364
+ }
365
+
366
+ if (empty($options)) {
367
+ return '';
368
+ }
369
+
370
+ $generalId = $amazonListingProduct->getGeneralId();
371
+
372
+ $html = '<div style="font-size: 11px; color: grey; margin-left: 7px">';
373
+
374
+ foreach ($options as $attribute => $option) {
375
+ !$option && $option = '--';
376
+
377
+ $attrName = Mage::helper('M2ePro')->escapeHtml($attribute);
378
+ $optionName = Mage::helper('M2ePro')->escapeHtml($option);
379
+
380
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
381
+ $html .= <<<HTML
382
+ {$attrName}:&nbsp;{$optionName}<br/>
383
+ HTML;
384
+ } else {
385
+ $html .= <<<HTML
386
+ <b>{$attrName}</b>:&nbsp;{$optionName}<br/>
387
+ HTML;
388
+ }
389
+
390
+ }
391
+
392
+ $html .= '</div>';
393
+
394
+ return $html;
395
+ }
396
+
397
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
398
+ {
399
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
400
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
401
+ }
402
+
403
+ if (is_null($value) || $value === '') {
404
+ $value = Mage::helper('M2ePro')->__('N/A');
405
+ }
406
+
407
+ if ($row->getData('defected_messages')) {
408
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
409
+
410
+ $msg = '';
411
+ foreach ($defectedMessages as $message) {
412
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
413
+ if (!empty($message['value'])) {
414
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
415
+ }
416
+ $msg .= '</p>';
417
+ }
418
+
419
+ $value .= <<<HTML
420
+ <span style="float:right;">
421
+ <img id="map_link_defected_message_icon_{$row->getId()}"
422
+ class="tool-tip-image"
423
+ style="vertical-align: middle;"
424
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
425
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
426
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
427
+ <span>{$msg}</span>
428
+ </span>
429
+ </span>
430
+ HTML;
431
+ }
432
+
433
+ return $value;
434
+ }
435
+
436
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
437
+ {
438
+ if (is_null($generalId) || $generalId === '') {
439
+
440
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
441
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
442
+ if ($amazonListingProduct->isGeneralIdOwner()) {
443
+ return Mage::helper('M2ePro')->__('New ASIN/ISBN');
444
+ }
445
+
446
+ return Mage::helper('M2ePro')->__('N/A');
447
+ }
448
+ return $this->getGeneralIdLink($generalId);
449
+ }
450
+
451
+ public function callbackColumnAvailableQty($qty, $row, $column, $isExport)
452
+ {
453
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
454
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
455
+ }
456
+
457
+ if ((bool)$row->getData('is_afn_channel')) {
458
+ return Mage::helper('M2ePro')->__('N/A');
459
+ }
460
+
461
+ if (is_null($qty) || $qty === '') {
462
+ return Mage::helper('M2ePro')->__('N/A');
463
+ }
464
+
465
+ return $qty;
466
+ }
467
+
468
+ public function callbackColumnPrice($value, $row, $column, $isExport)
469
+ {
470
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
471
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
472
+ }
473
+
474
+ if (is_null($value) || $value === '') {
475
+ return Mage::helper('M2ePro')->__('N/A');
476
+ }
477
+
478
+ $marketplaceId = $this->getListingProduct()->getListing()->getMarketplaceId();
479
+ $currency = Mage::helper('M2ePro/Component_Amazon')
480
+ ->getCachedObject('Marketplace',$marketplaceId)
481
+ ->getChildObject()
482
+ ->getDefaultCurrency();
483
+
484
+ if ((float)$value <= 0) {
485
+ $priceValue = '<span style="color: #f00;">0</span>';
486
+ } else {
487
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($value);
488
+ }
489
+
490
+ $resultHtml = '';
491
+
492
+ $salePrice = $row->getData('online_sale_price');
493
+ if ((float)$salePrice > 0) {
494
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
495
+
496
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
497
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
498
+
499
+ if ($currentTimestamp <= $endDateTimestamp) {
500
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
501
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
502
+
503
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
504
+
505
+ $fromDate = Mage::app()->getLocale()->date(
506
+ $row->getData('online_sale_price_start_date'), $dateFormat
507
+ )->toString($dateFormat);
508
+ $toDate = Mage::app()->getLocale()->date(
509
+ $row->getData('online_sale_price_end_date'), $dateFormat
510
+ )->toString($dateFormat);
511
+
512
+ $intervalHtml = '<img class="tool-tip-image"
513
+ style="vertical-align: middle;"
514
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
515
+ text-align: left;
516
+ width: 120px;
517
+ background: #E3E3E3;">
518
+ <img src="'.$iconHelpPath.'">
519
+ <span style="color:gray;">
520
+ <strong>From:</strong> '.$fromDate.'<br/>
521
+ <strong>To:</strong> '.$toDate.'
522
+ </span>
523
+ </span>';
524
+
525
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
526
+
527
+ if ($currentTimestamp >= $startDateTimestamp &&
528
+ $currentTimestamp <= $endDateTimestamp &&
529
+ $salePrice < (float)$value
530
+ ) {
531
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
532
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
533
+ } else {
534
+ $resultHtml .= $priceValue;
535
+ $resultHtml .= '<br/>'.$intervalHtml.
536
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
537
+ }
538
+ }
539
+ }
540
+
541
+ if (empty($resultHtml)) {
542
+ $resultHtml = $priceValue;
543
+ }
544
+
545
+ return $resultHtml;
546
+ }
547
+
548
+ public function callbackColumnStatus($value, $row, $column, $isExport)
549
+ {
550
+ $listingProductId = (int)$row->getData('id');
551
+
552
+ $html = $this->getViewLogIconHtml($row);
553
+
554
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
555
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
556
+
557
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
558
+ if (!empty($synchNote)) {
559
+
560
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
561
+
562
+ if (empty($html)) {
563
+ $html = <<<HTML
564
+ <span style="float:right;">
565
+ <img id="map_link_error_icon_{$row->getId()}"
566
+ class="tool-tip-image"
567
+ style="vertical-align: middle;"
568
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
569
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
570
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
571
+ <span>{$synchNote}</span>
572
+ </span>
573
+ </span>
574
+ HTML;
575
+ } else {
576
+ $html .= <<<HTML
577
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
578
+ HTML;
579
+ }
580
+ }
581
+
582
+ switch ($row->getData('status')) {
583
+
584
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
585
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
586
+ $html .= '<span style="color: gray;">' . $value . '</span>';
587
+ break;
588
+
589
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
590
+ $html .= '<span style="color: green;">' . $value . '</span>';
591
+ break;
592
+
593
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
594
+ $html .= '<span style="color: red;">'.$value.'</span>';
595
+ break;
596
+
597
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
598
+ $html .= '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
599
+ break;
600
+
601
+ default:
602
+ break;
603
+ }
604
+
605
+ $tempLocks = $this->getLockedData($row);
606
+ $tempLocks = $tempLocks['object_locks'];
607
+
608
+ foreach ($tempLocks as $lock) {
609
+
610
+ switch ($lock->getTag()) {
611
+
612
+ case 'list_action':
613
+ $html .= '<br/><span style="color: #605fff">[Listing...]</span>';
614
+ break;
615
+
616
+ case 'relist_action':
617
+ $html .= '<br/><span style="color: #605fff">[Relisting...]</span>';
618
+ break;
619
+
620
+ case 'revise_action':
621
+ $html .= '<br/><span style="color: #605fff">[Revising...]</span>';
622
+ break;
623
+
624
+ case 'stop_action':
625
+ $html .= '<br/><span style="color: #605fff">[Stopping...]</span>';
626
+ break;
627
+
628
+ case 'stop_and_remove_action':
629
+ $html .= '<br/><span style="color: #605fff">[Stopping...]</span>';
630
+ break;
631
+
632
+ case 'delete_and_remove_action':
633
+ $html .= '<br/><span style="color: #605fff">[Removing...]</span>';
634
+ break;
635
+
636
+ default:
637
+ break;
638
+
639
+ }
640
+ }
641
+
642
+ return $html;
643
+ }
644
+
645
+ public function callbackProductOptions($collection, $column)
646
+ {
647
+ $values = $column->getFilter()->getValue();
648
+
649
+ if ($values == null && !is_array($values)) {
650
+ return;
651
+ }
652
+
653
+ foreach ($values as $value) {
654
+ if(is_array($value) && isset($value['value'])) {
655
+ $collection->addFieldToFilter(
656
+ 'additional_data',
657
+ array('regexp'=> '"variation_product_options":[^}]*'.$value['attr'].'":"' .
658
+ // trying to screen slashes that in json
659
+ addslashes(addslashes($value['value'])))
660
+ );
661
+ }
662
+ }
663
+ }
664
+
665
+ public function callbackChannelOptions($collection, $column)
666
+ {
667
+ $values = $column->getFilter()->getValue();
668
+
669
+ if ($values == null && !is_array($values)) {
670
+ return;
671
+ }
672
+
673
+ foreach ($values as $value) {
674
+ if(is_array($value) && isset($value['value'])) {
675
+ $collection->addFieldToFilter(
676
+ 'additional_data',
677
+ array('regexp'=> '"variation_channel_options":[^}]*'.$value['attr'].'":"' .
678
+ // trying to screen slashes that in json
679
+ addslashes(addslashes($value['value'])))
680
+ );
681
+ }
682
+ }
683
+ }
684
+
685
+ protected function callbackFilterPrice($collection, $column)
686
+ {
687
+ $value = $column->getFilter()->getValue();
688
+
689
+ if (empty($value)) {
690
+ return;
691
+ }
692
+
693
+ $from = $value['from'];
694
+ $to = $value['to'];
695
+
696
+ $collection->getSelect()->where(
697
+ '(online_price >= \''.$from.'\' AND online_price <= \''.$to.'\' AND
698
+ (
699
+ online_sale_price IS NULL OR
700
+ online_sale_price_start_date > NOW() OR
701
+ online_sale_price_end_date < NOW()
702
+ )) OR (online_sale_price >= \''.$from.'\' AND online_sale_price <= \''.$to.'\' AND
703
+ (
704
+ online_sale_price IS NOT NULL AND
705
+ online_sale_price_start_date < NOW() AND
706
+ online_sale_price_end_date > NOW()
707
+ ))'
708
+ );
709
+ }
710
+
711
+ // ####################################
712
+
713
+ /**
714
+ * @param Ess_M2ePro_Model_Listing_Product $listingProduct
715
+ * @return string
716
+ */
717
+ public function getViewLogIconHtml($listingProduct)
718
+ {
719
+ $listingProductId = (int)$listingProduct->getId();
720
+
721
+ // Get last messages
722
+ //--------------------------
723
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
724
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
725
+
726
+ $dbSelect = $connRead->select()
727
+ ->from(
728
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
729
+ array('action_id','action','type','description','create_date','initiator')
730
+ )
731
+ ->where('`listing_product_id` = ?', $listingProductId)
732
+ ->where('`action_id` IS NOT NULL')
733
+ ->order(array('id DESC'))
734
+ ->limit(30);
735
+
736
+ $logRows = $connRead->fetchAll($dbSelect);
737
+ //--------------------------
738
+
739
+ // Get grouped messages by action_id
740
+ //--------------------------
741
+ $actionsRows = array();
742
+ $tempActionRows = array();
743
+ $lastActionId = false;
744
+
745
+ foreach ($logRows as $row) {
746
+
747
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
748
+
749
+ if ($row['action_id'] !== $lastActionId) {
750
+ if (count($tempActionRows) > 0) {
751
+ $actionsRows[] = array(
752
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
753
+ 'date' => $this->getMainDateForActionId($tempActionRows),
754
+ 'action' => $this->getActionForAction($tempActionRows[0]),
755
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
756
+ 'items' => $tempActionRows
757
+ );
758
+ $tempActionRows = array();
759
+ }
760
+ $lastActionId = $row['action_id'];
761
+ }
762
+ $tempActionRows[] = $row;
763
+ }
764
+
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
+ }
774
+
775
+ if (count($actionsRows) <= 0) {
776
+ return '';
777
+ }
778
+
779
+ foreach ($actionsRows as &$actionsRow) {
780
+ usort($actionsRow['items'], function($a, $b)
781
+ {
782
+ $sortOrder = array(
783
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
784
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
785
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
786
+ );
787
+
788
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
789
+ });
790
+ }
791
+
792
+ $tips = array(
793
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
794
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
795
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
796
+ );
797
+
798
+ $icons = array(
799
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
800
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
801
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
802
+ );
803
+
804
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
805
+ 'entity_id' => (int)$listingProduct->getId(),
806
+ 'rows' => $actionsRows,
807
+ 'tips' => $tips,
808
+ 'icons' => $icons,
809
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
810
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
811
+ ));
812
+
813
+ return $summary->toHtml();
814
+ }
815
+
816
+ public function getActionForAction($actionRows)
817
+ {
818
+ $string = '';
819
+
820
+ switch ($actionRows['action']) {
821
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
822
+ $string = Mage::helper('M2ePro')->__('List');
823
+ break;
824
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
825
+ $string = Mage::helper('M2ePro')->__('Relist');
826
+ break;
827
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
828
+ $string = Mage::helper('M2ePro')->__('Revise');
829
+ break;
830
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
831
+ $string = Mage::helper('M2ePro')->__('Stop');
832
+ break;
833
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
834
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
835
+ break;
836
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
837
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
838
+ break;
839
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
840
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
841
+ break;
842
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
843
+ $string = Mage::helper('M2ePro')->__('Channel Change');
844
+ break;
845
+ }
846
+
847
+ return $string;
848
+ }
849
+
850
+ public function getInitiatorForAction($actionRows)
851
+ {
852
+ $string = '';
853
+
854
+ switch ((int)$actionRows['initiator']) {
855
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
856
+ $string = '';
857
+ break;
858
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
859
+ $string = Mage::helper('M2ePro')->__('Manual');
860
+ break;
861
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
862
+ $string = Mage::helper('M2ePro')->__('Automatic');
863
+ break;
864
+ }
865
+
866
+ return $string;
867
+ }
868
+
869
+ public function getMainTypeForActionId($actionRows)
870
+ {
871
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
872
+
873
+ foreach ($actionRows as $row) {
874
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
875
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
876
+ break;
877
+ }
878
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
879
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
880
+ }
881
+ }
882
+
883
+ return $type;
884
+ }
885
+
886
+ public function getMainDateForActionId($actionRows)
887
+ {
888
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
889
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
890
+ }
891
+
892
+ // ####################################
893
+
894
+ public function getMainButtonsHtml()
895
+ {
896
+ $html = '';
897
+ if($this->getFilterVisibility()){
898
+ $html.= $this->getAddNewChildButtonsHtml();
899
+ $html.= $this->getResetFilterButtonHtml();
900
+ $html.= $this->getSearchButtonHtml();
901
+ }
902
+ return $html;
903
+ }
904
+
905
+ public function getMassactionBlockHtml()
906
+ {
907
+ if ($this->isNewChildAllowed()) {
908
+ $blockName = 'adminhtml_common_amazon_listing_variation_product_manage_tabs_variations_child_form';
909
+ $form = $this->getLayout()->createBlock('M2ePro/'.$blockName);
910
+ $form->setListingProductId($this->getListingProductId());
911
+
912
+ return $form->toHtml() . parent::getMassactionBlockHtml();
913
+ }
914
+
915
+ return parent::getMassactionBlockHtml();
916
+ }
917
+
918
+ private function getAddNewChildButtonsHtml()
919
+ {
920
+ if ($this->isNewChildAllowed()) {
921
+
922
+ //------------------------------
923
+ $data = array(
924
+ 'label' => Mage::helper('adminhtml')->__('Add New Child Product'),
925
+ 'onclick' => 'ListingGridHandlerObj.showNewChildForm('. !$this->hasUnusedChannelVariations() .')',
926
+ 'class' => 'task',
927
+ 'id' => 'add_new_child_button'
928
+ );
929
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
930
+ $this->setChild('add_new_child_button', $buttonBlock);
931
+ //------------------------------
932
+
933
+ }
934
+
935
+ return $this->getChildHtml('add_new_child_button');
936
+ }
937
+
938
+ protected function isNewChildAllowed()
939
+ {
940
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
941
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
942
+
943
+ if (!$amazonListingProduct->getGeneralId()) {
944
+ return false;
945
+ }
946
+
947
+ if (!$amazonListingProduct->getVariationManager()->getTypeModel()->hasMatchedAttributes()) {
948
+ return false;
949
+ }
950
+
951
+ if (!$this->hasUnusedProductVariation()) {
952
+ return false;
953
+ }
954
+
955
+ if ($this->hasChildWithEmptyProductOptions()) {
956
+ return false;
957
+ }
958
+
959
+ if (!$this->isGeneralIdOwner() && !$this->hasUnusedChannelVariations()) {
960
+ return false;
961
+ }
962
+
963
+ if (!$this->isGeneralIdOwner() && $this->hasChildWithEmptyChannelOptions()) {
964
+ return false;
965
+ }
966
+
967
+ return true;
968
+ }
969
+
970
+ public function isGeneralIdOwner()
971
+ {
972
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
973
+ }
974
+
975
+ public function getCurrentChannelVariations()
976
+ {
977
+ return $this->getListingProduct()->getChildObject()
978
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
979
+ }
980
+
981
+ public function hasUnusedProductVariation()
982
+ {
983
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
984
+ }
985
+
986
+ public function hasUnusedChannelVariations()
987
+ {
988
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
989
+ }
990
+
991
+ public function hasChildWithEmptyProductOptions()
992
+ {
993
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
994
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
995
+
996
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
997
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
998
+
999
+ if (!$childTypeModel->isVariationProductMatched()) {
1000
+ return true;
1001
+ }
1002
+ }
1003
+
1004
+ return false;
1005
+ }
1006
+
1007
+ public function hasChildWithEmptyChannelOptions()
1008
+ {
1009
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1010
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1011
+
1012
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1013
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1014
+
1015
+ if (!$childTypeModel->isVariationChannelMatched()) {
1016
+ return true;
1017
+ }
1018
+ }
1019
+
1020
+ return false;
1021
+ }
1022
+
1023
+ public function getUsedChannelVariations()
1024
+ {
1025
+ $usedOptions = array();
1026
+
1027
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1028
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1029
+
1030
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1031
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1032
+
1033
+ if (!$childTypeModel->isVariationChannelMatched()) {
1034
+ continue;
1035
+ }
1036
+
1037
+ $usedOptions[] = $childTypeModel->getChannelOptions();
1038
+ }
1039
+
1040
+ return $usedOptions;
1041
+ }
1042
+
1043
+ // ------------------------------------
1044
+
1045
+ public function getGridUrl()
1046
+ {
1047
+ return $this->getUrl('*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsGridAjax', array(
1048
+ '_current' => true
1049
+ ));
1050
+ }
1051
+
1052
+ public function getRowUrl($row)
1053
+ {
1054
+ return false;
1055
+ }
1056
+
1057
+ // ####################################
1058
+
1059
+ protected function _toHtml()
1060
+ {
1061
+ $listingId = $this->getListingProduct()->getListingId();
1062
+
1063
+ /** @var $helper Ess_M2ePro_Helper_Data */
1064
+ $helper = Mage::helper('M2ePro');
1065
+
1066
+ //------------------------------
1067
+ $urls = array();
1068
+
1069
+ $path = 'adminhtml_common_log/listingProduct';
1070
+ $urls[$path] = $this->getUrl('*/' . $path, array(
1071
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
1072
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array('id' => $listingId))
1073
+ ));
1074
+
1075
+ $urls['adminhtml_common_amazon_listing_variation_product_manage/createNewChild'] = $this->getUrl(
1076
+ '*/adminhtml_common_amazon_listing_variation_product_manage/createNewChild');
1077
+
1078
+ $urls = json_encode($urls);
1079
+ //------------------------------
1080
+
1081
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
1082
+
1083
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing', array(
1084
+ 'id' =>$listingId,
1085
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON,
1086
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array('id' => $listingId))
1087
+ ));
1088
+
1089
+ $checkLockListing = $this->getUrl('*/adminhtml_listing/checkLockListing', array('component' => $component));
1090
+ $lockListingNow = $this->getUrl('*/adminhtml_listing/lockListingNow', array('component' => $component));
1091
+ $unlockListingNow = $this->getUrl('*/adminhtml_listing/unlockListingNow', array('component' => $component));
1092
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
1093
+
1094
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
1095
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
1096
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
1097
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
1098
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopAndRemoveProducts');
1099
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
1100
+
1101
+ $setChildListingProductOptions = $this->getUrl(
1102
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setChildListingProductOptions');
1103
+
1104
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
1105
+ $taskCompletedSuccessMessage = $helper->escapeJs(
1106
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
1107
+ );
1108
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
1109
+ '"%task_title%" Task has completed with warnings.
1110
+ <a target="_blank" href="%url%">View Log</a> for details.'
1111
+ ));
1112
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
1113
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
1114
+ ));
1115
+
1116
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
1117
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
1118
+ 'Sending %product_title% Product(s) data on Amazon.'
1119
+ ));
1120
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
1121
+
1122
+ $listingLockedMessage = $helper->escapeJs(
1123
+ $helper->__('The Listing was locked by another process. Please try again later.')
1124
+ );
1125
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
1126
+
1127
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1128
+ ->__('Listing All Items On Amazon'));
1129
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1130
+ ->__('Listing Selected Items On Amazon'));
1131
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1132
+ ->__('Revising Selected Items On Amazon'));
1133
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1134
+ ->__('Relisting Selected Items On Amazon'));
1135
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1136
+ ->__('Stopping Selected Items On Amazon'));
1137
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
1138
+ ->escapeJs(Mage::helper('M2ePro')
1139
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
1140
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
1141
+ ->escapeJs(Mage::helper('M2ePro')
1142
+ ->__('Removing From Amazon And Listing Selected Items'));
1143
+
1144
+ $selectItemsMessage = $helper->escapeJs($helper->__('Please select Items.'));
1145
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
1146
+
1147
+ $errorChangingProductOptions = $helper->escapeJs($helper->__('Please Select Product Options.'));
1148
+
1149
+ $successWord = $helper->escapeJs($helper->__('Success'));
1150
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
1151
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
1152
+ $errorWord = $helper->escapeJs($helper->__('Error'));
1153
+ $closeWord = $helper->escapeJs($helper->__('Close'));
1154
+ $confirmWord = $helper->escapeJs($helper->__('Confirm'));
1155
+ $cancelWord = $helper->escapeJs($helper->__('Cancel'));
1156
+
1157
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
1158
+
1159
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
1160
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
1161
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
1162
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
1163
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
1164
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy for Products'));
1165
+
1166
+ $generalId = $this->getListingProduct()->getGeneralId();
1167
+ $hideMassAction = empty($generalId) ?
1168
+ '$(\'amazonVariationProductManageGrid_massaction-form\').hide();' : '';
1169
+
1170
+ $javascriptMain = <<<JAVASCRIPT
1171
+ <script type="text/javascript">
1172
+
1173
+ if (typeof M2ePro == 'undefined') {
1174
+ M2ePro = {};
1175
+ M2ePro.url = {};
1176
+ M2ePro.formData = {};
1177
+ M2ePro.customData = {};
1178
+ M2ePro.text = {};
1179
+ }
1180
+
1181
+ M2ePro.url.add({$urls});
1182
+
1183
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
1184
+
1185
+ M2ePro.url.checkLockListing = '{$checkLockListing}';
1186
+ M2ePro.url.lockListingNow = '{$lockListingNow}';
1187
+ M2ePro.url.unlockListingNow = '{$unlockListingNow}';
1188
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
1189
+
1190
+ M2ePro.url.runListProducts = '{$runListProducts}';
1191
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
1192
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
1193
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
1194
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
1195
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
1196
+ M2ePro.url.setChildListingProductOptions = '{$setChildListingProductOptions}';
1197
+
1198
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
1199
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
1200
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
1201
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
1202
+
1203
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
1204
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
1205
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
1206
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
1207
+
1208
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
1209
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
1210
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
1211
+
1212
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
1213
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
1214
+
1215
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
1216
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
1217
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
1218
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
1219
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
1220
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
1221
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
1222
+
1223
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
1224
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
1225
+
1226
+ M2ePro.text.error_changing_product_options = '{$errorChangingProductOptions}';
1227
+
1228
+ M2ePro.text.success_word = '{$successWord}';
1229
+ M2ePro.text.notice_word = '{$noticeWord}';
1230
+ M2ePro.text.warning_word = '{$warningWord}';
1231
+ M2ePro.text.error_word = '{$errorWord}';
1232
+ M2ePro.text.close_word = '{$closeWord}';
1233
+ M2ePro.text.confirm_word = '{$confirmWord}';
1234
+ M2ePro.text.cancel_word = '{$cancelWord}';
1235
+
1236
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
1237
+
1238
+ M2ePro.text.confirm = '{$textConfirm}';
1239
+
1240
+ M2ePro.customData.componentMode = '{$component}';
1241
+ M2ePro.customData.gridId = 'amazonVariationProductManageGrid';
1242
+
1243
+ // fix for tool tip position in iframe
1244
+ MagentoFieldTip.prototype.changeToolTipPosition = function(element)
1245
+ {
1246
+ var toolTip = element.up().select('.tool-tip-message')[0];
1247
+
1248
+ var settings = {
1249
+ setHeight: false,
1250
+ setWidth: false,
1251
+ setLeft: true,
1252
+ offsetTop: 25,
1253
+ offsetLeft: -20
1254
+ };
1255
+
1256
+ if (element.up().getStyle('float') == 'right') {
1257
+ settings.offsetLeft += 18;
1258
+ }
1259
+ if (element.up().match('span')) {
1260
+ settings.offsetLeft += 15;
1261
+ }
1262
+
1263
+ toolTip.clonePosition(element, settings);
1264
+
1265
+ if (toolTip.hasClassName('tip-left')) {
1266
+ toolTip.style.left = (parseInt(toolTip.style.left) - toolTip.getWidth() - 10) + 'px';
1267
+ }
1268
+ };
1269
+
1270
+ Event.observe(window, 'load', function() {
1271
+
1272
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
1273
+
1274
+ ListingGridHandlerObj = new CommonAmazonListingVariationProductManageVariationsGridHandler(
1275
+ 'amazonVariationProductManageGrid',
1276
+ {$listingId}
1277
+ );
1278
+
1279
+ // todo next (temp solution)
1280
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
1281
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
1282
+
1283
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
1284
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
1285
+
1286
+ setTimeout(function() {
1287
+ ListingGridHandlerObj.afterInitPage();
1288
+ }, 350);
1289
+ });
1290
+
1291
+ if (typeof ListingGridHandlerObj != 'undefined') {
1292
+ ListingGridHandlerObj.afterInitPage();
1293
+ }
1294
+
1295
+ {$hideMassAction}
1296
+
1297
+ </script>
1298
+ JAVASCRIPT;
1299
+
1300
+ $additionalCss = <<<HTML
1301
+ <style>
1302
+ body {
1303
+ background: none;
1304
+ }
1305
+
1306
+ .wrapper {
1307
+ min-width: inherit;
1308
+ }
1309
+
1310
+ .footer {
1311
+ display: none;
1312
+ }
1313
+
1314
+ .middle {
1315
+ padding: 0px;
1316
+ background: none;
1317
+ }
1318
+
1319
+ td.help_line .hl_close {
1320
+ margin-top: -6px;
1321
+ }
1322
+
1323
+ td.help_line .hl_header {
1324
+ padding: 0 0 10px !important;
1325
+ }
1326
+
1327
+ </style>
1328
+ HTML;
1329
+
1330
+ return '<div id="messages"></div>' .
1331
+ '<div id="listing_view_progress_bar"></div>' .
1332
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
1333
+ '<div id="listing_view_content_container">'.
1334
+ parent::_toHtml() .
1335
+ '</div>' . $javascriptMain . $additionalCss;
1336
+ }
1337
+
1338
+ // ####################################
1339
+
1340
+ private function canChangeProductVariation(Ess_M2ePro_Model_Listing_Product $childListingProduct)
1341
+ {
1342
+ if (!$this->hasUnusedProductVariation()) {
1343
+ return false;
1344
+ }
1345
+
1346
+ $lockData = $this->getLockedData($childListingProduct);
1347
+ if ($lockData['in_action']) {
1348
+ return false;
1349
+ }
1350
+
1351
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonChildListingProduct */
1352
+ $amazonChildListingProduct = $childListingProduct->getChildObject();
1353
+
1354
+ if (!$amazonChildListingProduct->getGeneralId()) {
1355
+ return false;
1356
+ }
1357
+
1358
+ $childTypeModel = $amazonChildListingProduct->getVariationManager()->getTypeModel();
1359
+
1360
+ if ($childTypeModel->isVariationProductMatched() && $this->hasChildWithEmptyProductOptions()) {
1361
+ return false;
1362
+ }
1363
+
1364
+ return true;
1365
+ }
1366
+
1367
+ private function getLockedData($row)
1368
+ {
1369
+ $listingProductId = $row->getData('id');
1370
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1371
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
1372
+ $tempArray = array(
1373
+ 'object_locks' => $objectLocks,
1374
+ 'in_action' => !empty($objectLocks),
1375
+ );
1376
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1377
+ }
1378
+
1379
+ return $this->lockedDataCache[$listingProductId];
1380
+ }
1381
+
1382
+ // ####################################
1383
+
1384
+ protected function getTemplateDescriptionLinkHtml($listingProduct)
1385
+ {
1386
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
1387
+ 'id' => $listingProduct->getChildObject()->getTemplateDescriptionId()
1388
+ ));
1389
+
1390
+ $helper = Mage::helper('M2ePro');
1391
+ $templateTitle = $listingProduct->getChildObject()->getDescriptionTemplate()->getTitle();
1392
+
1393
+ return <<<HTML
1394
+ <span style="font-size: 9px;">{$helper->__('Description Title')}:&nbsp;
1395
+ <a target="_blank" href="{$templateDescriptionEditUrl}">
1396
+ {$helper->escapeHtml($templateTitle)}</a>
1397
+ </span>
1398
+ <br/>
1399
+ HTML;
1400
+ }
1401
+
1402
+ // ####################################
1403
+
1404
+ public function getProductVariationsTree($childProduct)
1405
+ {
1406
+ $unusedVariations = $this->getUnusedProductVariations();
1407
+
1408
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1409
+ $childTypeModel = $childProduct->getChildObject()->getVariationManager()->getTypeModel();
1410
+
1411
+ if ($childTypeModel->isVariationProductMatched()) {
1412
+ $unusedVariations[] = $childTypeModel->getProductOptions();
1413
+ }
1414
+
1415
+ $variationsSets = $this->getAttributesVariationsSets($unusedVariations);
1416
+ $firstAttribute = key($variationsSets);
1417
+
1418
+ return $this->prepareVariations($firstAttribute,$unusedVariations,$variationsSets);
1419
+ }
1420
+
1421
+ private function prepareVariations($currentAttribute,$unusedVariations,$variationsSets,$filters = array())
1422
+ {
1423
+ $return = false;
1424
+
1425
+ $temp = array_flip(array_keys($variationsSets));
1426
+
1427
+ $lastAttributePosition = count($variationsSets) - 1;
1428
+ $currentAttributePosition = $temp[$currentAttribute];
1429
+
1430
+ if ($currentAttributePosition != $lastAttributePosition) {
1431
+
1432
+ $temp = array_keys($variationsSets);
1433
+ $nextAttribute = $temp[$currentAttributePosition + 1];
1434
+
1435
+ foreach ($variationsSets[$currentAttribute] as $option) {
1436
+
1437
+ $filters[$currentAttribute] = $option;
1438
+
1439
+ $result = $this->prepareVariations(
1440
+ $nextAttribute,$unusedVariations,$variationsSets,$filters
1441
+ );
1442
+
1443
+ if (!$result) {
1444
+ continue;
1445
+ }
1446
+
1447
+ $return[$currentAttribute][$option] = $result;
1448
+ }
1449
+
1450
+ ksort($return[$currentAttribute]);
1451
+
1452
+ return $return;
1453
+ }
1454
+
1455
+ $return = false;
1456
+ foreach ($unusedVariations as $key => $magentoVariation) {
1457
+ foreach ($magentoVariation as $attribute => $option) {
1458
+
1459
+ if ($attribute == $currentAttribute) {
1460
+
1461
+ if (count($variationsSets) != 1) {
1462
+ continue;
1463
+ }
1464
+
1465
+ $values = array_flip($variationsSets[$currentAttribute]);
1466
+ $return = array($currentAttribute => $values);
1467
+
1468
+ foreach ($return[$currentAttribute] as &$option) {
1469
+ $option = true;
1470
+ }
1471
+
1472
+ return $return;
1473
+ }
1474
+
1475
+ if ($option != $filters[$attribute]) {
1476
+ unset($unusedVariations[$key]);
1477
+ continue;
1478
+ }
1479
+
1480
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
1481
+ if ($tempAttribute == $currentAttribute) {
1482
+ $option = $tempOption;
1483
+ $return[$currentAttribute][$option] = true;
1484
+ }
1485
+ }
1486
+ }
1487
+ }
1488
+
1489
+ if (count($unusedVariations) < 1) {
1490
+ return false;
1491
+ }
1492
+
1493
+ ksort($return[$currentAttribute]);
1494
+
1495
+ return $return;
1496
+ }
1497
+
1498
+ // ####################################
1499
+
1500
+ public function getCurrentProductVariations()
1501
+ {
1502
+
1503
+ if (!is_null($this->currentProductVariations)) {
1504
+ return $this->currentProductVariations;
1505
+ }
1506
+
1507
+ $magentoProductVariations = $this->getListingProduct()
1508
+ ->getMagentoProduct()
1509
+ ->getVariationInstance()
1510
+ ->getVariationsTypeStandard();
1511
+
1512
+ $productVariations = array();
1513
+
1514
+ foreach ($magentoProductVariations['variations'] as $option) {
1515
+ $productOption = array();
1516
+
1517
+ foreach ($option as $attribute) {
1518
+ $productOption[$attribute['attribute']] = $attribute['option'];
1519
+ }
1520
+
1521
+ $productVariations[] = $productOption;
1522
+ }
1523
+
1524
+ return $this->currentProductVariations = $productVariations;
1525
+ }
1526
+
1527
+ public function getUsedProductVariations()
1528
+ {
1529
+ if (is_null($this->usedProductVariations)) {
1530
+
1531
+ $usedOptions = array();
1532
+
1533
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1534
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1535
+
1536
+ /**
1537
+ * @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel
1538
+ */
1539
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1540
+
1541
+ if (!$childTypeModel->isVariationProductMatched()) {
1542
+ continue;
1543
+ }
1544
+
1545
+ $usedOptions[] = $childTypeModel->getProductOptions();
1546
+ }
1547
+
1548
+ $this->usedProductVariations = $usedOptions;
1549
+ }
1550
+
1551
+ return $this->usedProductVariations;
1552
+ }
1553
+
1554
+ // ####################################
1555
+
1556
+ public function getUnusedProductVariations()
1557
+ {
1558
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
1559
+ }
1560
+
1561
+ private function getUnusedVariations($currentVariations, $usedVariations)
1562
+ {
1563
+ if (empty($currentVariations)) {
1564
+ return array();
1565
+ }
1566
+
1567
+ if (empty($usedVariations)) {
1568
+ return $currentVariations;
1569
+ }
1570
+
1571
+ $unusedOptions = array();
1572
+
1573
+ foreach ($currentVariations as $id => $currentOption) {
1574
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
1575
+ continue;
1576
+ }
1577
+
1578
+ $unusedOptions[$id] = $currentOption;
1579
+ }
1580
+
1581
+ return $unusedOptions;
1582
+ }
1583
+
1584
+ private function isVariationExistsInArray(array $needle, array $haystack)
1585
+ {
1586
+ foreach ($haystack as $option) {
1587
+ if ($option != $needle) {
1588
+ continue;
1589
+ }
1590
+
1591
+ return true;
1592
+ }
1593
+
1594
+ return false;
1595
+ }
1596
+
1597
+ // ####################################
1598
+
1599
+ public function getChildListingProducts()
1600
+ {
1601
+ if (!is_null($this->childListingProducts)) {
1602
+ return $this->childListingProducts;
1603
+ }
1604
+
1605
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
1606
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
1607
+ }
1608
+
1609
+ public function getAttributesVariationsSets($variations)
1610
+ {
1611
+ $attributesOptions = array();
1612
+
1613
+ foreach ($variations as $variation) {
1614
+ foreach ($variation as $attr => $option) {
1615
+ if (!isset($attributesOptions[$attr])) {
1616
+ $attributesOptions[$attr] = array();
1617
+ }
1618
+ if (!in_array($option, $attributesOptions[$attr])) {
1619
+ $attributesOptions[$attr][] = $option;
1620
+ }
1621
+ }
1622
+ }
1623
+
1624
+ ksort($attributesOptions);
1625
+
1626
+ return $attributesOptions;
1627
+ }
1628
+
1629
+ // ####################################
1630
+
1631
+ protected function getGeneralIdLink($generalId)
1632
+ {
1633
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1634
+ $generalId,
1635
+ $this->getListingProduct()->getListing()->getMarketplaceId()
1636
+ );
1637
+
1638
+ return <<<HTML
1639
+ <a href="{$url}" target="_blank" title="{$generalId}" >{$generalId}</a>
1640
+ HTML;
1641
+ }
1642
+
1643
+ // ####################################
1644
+
1645
+ private function parseGroupedData($data)
1646
+ {
1647
+ $result = array();
1648
+
1649
+ $variationData = explode('|', $data);
1650
+ foreach ($variationData as $variationAttribute) {
1651
+ $value = explode('=', $variationAttribute);
1652
+ $result[$value[0]] = $value[1];
1653
+ }
1654
+
1655
+ return $result;
1656
+ }
1657
+
1658
+ // ####################################
1659
+ }
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/Manage/Tabs/Vocabulary.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Vocabulary
8
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
9
+ {
10
+ protected $listingProductId;
11
+
12
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
13
+ protected $listingProduct;
14
+
15
+ // ####################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/vocabulary.phtml');
22
+
23
+ return $this;
24
+ }
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
+ /**
49
+ * @return Ess_M2ePro_Model_Listing_Product|null
50
+ */
51
+ public function getListingProduct()
52
+ {
53
+ if(is_null($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 prepareData()
64
+ {
65
+ $localVocabulary = array();
66
+ $fixedAttributes = array();
67
+ $matchedAttributes = $this->getListingProduct()->getChildObject()
68
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
69
+ $magentoProductVariations = $this->getListingProduct()
70
+ ->getMagentoProduct()
71
+ ->getVariationInstance()
72
+ ->getVariationsTypeStandard();
73
+
74
+ $vocabularyHelper = Mage::helper('M2ePro/Component_Amazon_Vocabulary');
75
+ $vocabularyData = $vocabularyHelper->getLocalData();
76
+
77
+ if (empty($matchedAttributes)) {
78
+ return array(
79
+ 'local_vocabulary' => $localVocabulary,
80
+ 'fixed_attributes' => $fixedAttributes
81
+ );
82
+ }
83
+
84
+ foreach ($matchedAttributes as $magentoAttr => $channelAttr) {
85
+ foreach ($vocabularyData as $attribute => $attributeData) {
86
+
87
+ if (in_array($magentoAttr, $attributeData['names']) || $attribute == $channelAttr) {
88
+
89
+ if (!in_array($magentoAttr, $attributeData['names'])) {
90
+ $fixedAttributes[$magentoAttr][] = $attribute;
91
+ }
92
+
93
+ $localVocabulary[$magentoAttr][$attribute] = array();
94
+
95
+ if (!empty($attributeData['options'])) {
96
+ foreach ($magentoProductVariations['set'][$magentoAttr] as $magentoOption) {
97
+
98
+ foreach ($attributeData['options'] as $attributeOptions) {
99
+
100
+ if (in_array($magentoOption, $attributeOptions)) {
101
+ $localVocabulary[$magentoAttr][$attribute][$magentoOption][] = $attributeOptions;
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ if (!empty($fixedAttributes[$magentoAttr]) &&
108
+ in_array($attribute, $fixedAttributes[$magentoAttr]) &&
109
+ empty($localVocabulary[$magentoAttr][$attribute])) {
110
+
111
+ unset($localVocabulary[$magentoAttr][$attribute]);
112
+ if (empty($localVocabulary[$magentoAttr])) {
113
+ unset($localVocabulary[$magentoAttr]);
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+
120
+ return array(
121
+ 'local_vocabulary' => $localVocabulary,
122
+ 'fixed_attributes' => $fixedAttributes
123
+ );
124
+ }
125
+
126
+ // ####################################
127
+ }
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,779 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ const VIEW_MODE_SETTINGS = 'settings';
13
+
14
+ const DEFAULT_VIEW_MODE = self::VIEW_MODE_AMAZON;
15
+
16
+ // ####################################
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+
22
+ // Initialization block
23
+ //------------------------------
24
+ $this->setId('amazonListingView');
25
+ $this->_blockGroup = 'M2ePro';
26
+ $this->_controller = 'adminhtml_common_amazon_listing_view_' . $this->getViewMode();
27
+ //------------------------------
28
+
29
+ // Set header text
30
+ //------------------------------
31
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
32
+
33
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
34
+ $headerText = Mage::helper('M2ePro')->__(
35
+ 'View %component_name% Listing',
36
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()
37
+ );
38
+ } else {
39
+ $headerText = Mage::helper('M2ePro')->__('View Listing ');
40
+ }
41
+
42
+ $this->_headerText = $headerText;
43
+ //------------------------------
44
+
45
+ // Set buttons actions
46
+ //------------------------------
47
+ $this->removeButton('back');
48
+ $this->removeButton('reset');
49
+ $this->removeButton('delete');
50
+ $this->removeButton('add');
51
+ $this->removeButton('save');
52
+ $this->removeButton('edit');
53
+ //------------------------------
54
+
55
+ //------------------------------
56
+ $url = $this->getUrl('*/adminhtml_common_log/listing', array(
57
+ 'id' => $listingData['id'],
58
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON
59
+ ));
60
+ $this->_addButton('view_log', array(
61
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
62
+ 'onclick' => 'window.open(\'' . $url . '\')',
63
+ 'class' => 'button_link'
64
+ ));
65
+ //------------------------------
66
+
67
+ //------------------------------
68
+ $this->_addButton('edit_settings', array(
69
+ 'label' => Mage::helper('M2ePro')->__('Edit Settings'),
70
+ 'onclick' => '',
71
+ 'class' => 'drop_down edit_settings_drop_down'
72
+ ));
73
+ //------------------------------
74
+
75
+ //------------------------------
76
+ $this->_addButton('add_products', array(
77
+ 'label' => Mage::helper('M2ePro')->__('Add Products'),
78
+ 'onclick' => '',
79
+ 'class' => 'add drop_down add_products_drop_down'
80
+ ));
81
+ //------------------------------
82
+ }
83
+
84
+ // ####################################
85
+
86
+ public function getViewMode()
87
+ {
88
+ $allowedModes = array(
89
+ self::VIEW_MODE_AMAZON,
90
+ self::VIEW_MODE_SETTINGS,
91
+ self::VIEW_MODE_MAGENTO,
92
+ self::VIEW_MODE_SELLERCENTRAL
93
+ );
94
+ $mode = $this->getParam('view_mode', self::DEFAULT_VIEW_MODE);
95
+
96
+ if (in_array($mode, $allowedModes)) {
97
+ return $mode;
98
+ }
99
+
100
+ return self::DEFAULT_VIEW_MODE;
101
+ }
102
+
103
+ protected function getParam($paramName, $default = NULL)
104
+ {
105
+ $session = Mage::helper('M2ePro/Data_Session');
106
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
107
+ $sessionParamName = $this->getId() . $listingData['id'] . $paramName;
108
+
109
+ if ($this->getRequest()->has($paramName)) {
110
+ $param = $this->getRequest()->getParam($paramName);
111
+ $session->setValue($sessionParamName, $param);
112
+ return $param;
113
+ } elseif ($param = $session->getValue($sessionParamName)) {
114
+ return $param;
115
+ }
116
+
117
+ return $default;
118
+ }
119
+
120
+ // ####################################
121
+
122
+ protected function _toHtml()
123
+ {
124
+ return '<div id="listing_view_progress_bar"></div>' .
125
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
126
+ '<div id="listing_view_content_container">'.
127
+ parent::_toHtml() .
128
+ '</div>';
129
+ }
130
+
131
+ public function getGridHtml()
132
+ {
133
+ if ($this->getRequest()->isXmlHttpRequest()) {
134
+ return parent::getGridHtml();
135
+ }
136
+
137
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
138
+
139
+ /** @var $helper Ess_M2ePro_Helper_Data */
140
+ $helper = Mage::helper('M2ePro');
141
+
142
+ //------------------------------
143
+ $urls = $helper->getControllerActions(
144
+ 'adminhtml_common_listing_autoAction', array(
145
+ 'listing_id' => $this->getRequest()->getParam('id'),
146
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
147
+ )
148
+ );
149
+ $showAutoAction = json_encode((bool)$this->getRequest()->getParam('auto_actions'));
150
+
151
+ $path = 'adminhtml_common_log/listingProduct';
152
+ $urls[$path] = $this->getUrl('*/' . $path, array(
153
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
154
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array(
155
+ 'id' => $listingData['id']
156
+ ))
157
+ ));
158
+
159
+ $path = 'adminhtml_common_listing/duplicateProducts';
160
+ $urls[$path] = $this->getUrl('*/' . $path);
161
+
162
+ $urls = json_encode($urls);
163
+ //------------------------------
164
+
165
+ // todo next (change)
166
+
167
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
168
+
169
+ $temp = Mage::helper('M2ePro/Data_Session')->getValue('products_ids_for_list', true);
170
+ $productsIdsForList = empty($temp) ? '' : $temp;
171
+
172
+ $gridId = $this->getChild('grid')->getId();
173
+ $ignoreListings = json_encode(array($listingData['id']));
174
+
175
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
176
+ $marketplaceInstance = Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Marketplace',$marketplaceId);
177
+ $marketplace = json_encode($marketplaceInstance->getData());
178
+ $isNewAsinAvailable = json_encode($marketplaceInstance->getChildObject()->isNewAsinAvailable());
179
+
180
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing',array(
181
+ 'id' => $listingData['id'],
182
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON,
183
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',
184
+ array('id' =>$listingData['id']))
185
+ ));
186
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
187
+
188
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
189
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
190
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
191
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
192
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopAndRemoveProducts');
193
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
194
+
195
+ $prepareData = $this->getUrl('*/adminhtml_listing_moving/prepareMoveToListing');
196
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_moving/moveToListingGrid');
197
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_moving/getFailedProductsGrid');
198
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_moving/tryToMoveToListing');
199
+ $moveToListing = $this->getUrl('*/adminhtml_listing_moving/moveToListing');
200
+
201
+ $marketplaceSynchUrl = $this->getUrl(
202
+ '*/adminhtml_common_marketplace/index',
203
+ array('tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON)
204
+ );
205
+
206
+ $getVariationEditPopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationEditPopup');
207
+ $getVariationManagePopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationManagePopup');
208
+
209
+ $variationEditActionUrl = $this->getUrl('*/adminhtml_common_listing/variationEdit');
210
+ $variationManageActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManage');
211
+ $variationManageGenerateActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManageGenerate');
212
+ $variationResetActionUrl = $this->getUrl('*/adminhtml_common_listing/variationReset');
213
+
214
+ $saveListingAdditionalDataActionUrl = $this->getUrl('*/adminhtml_listing/saveListingAdditionalData', array(
215
+ 'id' => $listingData['id']
216
+ ));
217
+
218
+ $popupTitle = $helper->escapeJs($helper->__('Moving Amazon Items'));
219
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Amazon Item'));
220
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
221
+
222
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
223
+ $taskCompletedSuccessMessage = $helper->escapeJs(
224
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
225
+ );
226
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
227
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
228
+ ));
229
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
230
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
231
+ ));
232
+
233
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
234
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
235
+ 'Sending %product_title% Product(s) data on Amazon.')
236
+ );
237
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
238
+
239
+ $listingLockedMessage = $helper->escapeJs(
240
+ $helper->__('The Listing was locked by another process. Please try again later.')
241
+ );
242
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
243
+
244
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
245
+ ->__('Listing All Items On Amazon'));
246
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
247
+ ->__('Listing Selected Items On Amazon'));
248
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
249
+ ->__('Revising Selected Items On Amazon'));
250
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
251
+ ->__('Relisting Selected Items On Amazon'));
252
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
253
+ ->__('Stopping Selected Items On Amazon'));
254
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
255
+ ->escapeJs(Mage::helper('M2ePro')
256
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
257
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
258
+ ->escapeJs(Mage::helper('M2ePro')
259
+ ->__('Removing From Amazon And Listing Selected Items'));
260
+
261
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
262
+ $productsWereNotMovedMessage = $helper->escapeJs(
263
+ $helper->__('Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
264
+ );
265
+ $someProductsWereNotMovedMessage = $helper->escapeJs(
266
+ $helper->__('Some Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
267
+ );
268
+
269
+ $selectItemsMessage = $helper->escapeJs(
270
+ $helper->__('Please select the Products you want to perform the Action on.')
271
+ );
272
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
273
+
274
+ $successWord = $helper->escapeJs($helper->__('Success'));
275
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
276
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
277
+ $errorWord = $helper->escapeJs($helper->__('Error'));
278
+ $closeWord = $helper->escapeJs($helper->__('Close'));
279
+
280
+ $assignString = Mage::helper('M2ePro')->__('Assign');
281
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
282
+
283
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
284
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
285
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
286
+ $getCategoriesByAsin = $this->getUrl('*/adminhtml_common_amazon_listing/getCategoriesByAsin');
287
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
288
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
289
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
290
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
291
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
292
+
293
+ $variationProductManage = $this->getUrl(
294
+ '*/adminhtml_common_amazon_listing_variation_product_manage/index');
295
+ $variationProductSetGeneralIdOwner = $this->getUrl(
296
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setGeneralIdOwner');
297
+ $variationProductSetVariationTheme = $this->getUrl(
298
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setVariationTheme');
299
+ $variationProductSetMatchedAttributes = $this->getUrl(
300
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setMatchedAttributes');
301
+ $variationProductSetListingProductSku = $this->getUrl(
302
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setListingProductSku');
303
+ $manageVariationViewTemplateDescriptionsGrid = $this->getUrl(
304
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewTemplateDescriptionsGrid');
305
+ $manageVariationMapToTemplateDescription = $this->getUrl(
306
+ '*/adminhtml_common_amazon_listing_variation_product_manage/mapToTemplateDescription');
307
+ $addAttributesToVocabularyUrl = $this->getUrl(
308
+ '*/adminhtml_common_amazon_listing_variation_product_manage/addAttributesToVocabulary'
309
+ );
310
+ $addOptionsToVocabularyUrl = $this->getUrl(
311
+ '*/adminhtml_common_amazon_listing_variation_product_manage/addOptionsToVocabulary'
312
+ );
313
+
314
+ $viewVocabularyAjax = $this->getUrl(
315
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewVocabularyAjax'
316
+ );
317
+ $saveAutoActionSettings = $this->getUrl(
318
+ '*/adminhtml_common_amazon_listing_variation_product_manage/saveAutoActionSettings'
319
+ );
320
+ $removeAttributeFromVocabulary = $this->getUrl(
321
+ '*/adminhtml_common_amazon_listing_variation_product_manage/removeAttributeFromVocabulary'
322
+ );
323
+ $removeOptionFromVocabulary = $this->getUrl(
324
+ '*/adminhtml_common_amazon_listing_variation_product_manage/removeOptionFromVocabulary'
325
+ );
326
+
327
+ $viewVariationsSettingsAjax = $this->getUrl(
328
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsSettingsAjax');
329
+
330
+ $newAsinUrl = $this->getUrl('*/adminhtml_common_amazon_template_newProduct',array(
331
+ 'marketplace_id' => Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'),
332
+ ));
333
+
334
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
335
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
336
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
337
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
338
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
339
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
340
+
341
+ $enterProductSearchQueryMessage = $helper->escapeJs(
342
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
343
+ );
344
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
345
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
346
+ $autoMapAsinErrorMessage = $helper->escapeJs(
347
+ $helper->__('Server is currently unavailable. Please try again later.')
348
+ );
349
+ $newAsinNotAvailable = $helper->escapeJs(
350
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
351
+ );
352
+ $notSynchronizedMarketplace = $helper->escapeJs(
353
+ $helper->__(
354
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
355
+ ).' '.
356
+ $helper->__(
357
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
358
+ )
359
+ );
360
+
361
+ $noVariationsLeftText = $helper->__('All variations are already added.');
362
+
363
+ $variationManageMatchedAttributesError = $helper->__('Please choose valid Attributes.');
364
+ $variationManageMatchedAttributesErrorDuplicateSelection =
365
+ $helper->__('You can not choose the same Attribute twice.');
366
+
367
+ $variationManageSkuPopUpTitle =
368
+ $helper->__('Enter Amazon Parent Product SKU');
369
+
370
+ $switchToIndividualModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
371
+ $switchToParentModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
372
+
373
+ $emptySkuError = $helper->escapeJs($helper->__('Please enter Amazon Parent Product SKU.'));
374
+
375
+ $translations = json_encode(array(
376
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
377
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
378
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
379
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
380
+ ));
381
+
382
+ $javascriptsMain = <<<HTML
383
+ <script type="text/javascript">
384
+
385
+ if (typeof M2ePro == 'undefined') {
386
+ M2ePro = {};
387
+ M2ePro.url = {};
388
+ M2ePro.formData = {};
389
+ M2ePro.customData = {};
390
+ M2ePro.text = {};
391
+ }
392
+
393
+ M2ePro.url.add({$urls});
394
+ M2ePro.translator.add({$translations});
395
+
396
+ M2ePro.productsIdsForList = '{$productsIdsForList}';
397
+
398
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
399
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
400
+
401
+ M2ePro.url.runListProducts = '{$runListProducts}';
402
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
403
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
404
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
405
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
406
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
407
+
408
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
409
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
410
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
411
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
412
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
413
+ M2ePro.url.getCategoriesByAsin = '{$getCategoriesByAsin}';
414
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
415
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
416
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
417
+
418
+ M2ePro.url.variationProductManage = '{$variationProductManage}';
419
+ M2ePro.url.variationProductSetGeneralIdOwner = '{$variationProductSetGeneralIdOwner}';
420
+ M2ePro.url.variationProductSetVariationTheme = '{$variationProductSetVariationTheme}';
421
+ M2ePro.url.variationProductSetMatchedAttributes = '{$variationProductSetMatchedAttributes}';
422
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
423
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
424
+ M2ePro.url.manageVariationViewTemplateDescriptionsGrid = '{$manageVariationViewTemplateDescriptionsGrid}';
425
+ M2ePro.url.manageVariationMapToTemplateDescription = '{$manageVariationMapToTemplateDescription}';
426
+ M2ePro.url.viewVariationsSettingsAjax = '{$viewVariationsSettingsAjax}';
427
+ M2ePro.url.addAttributesToVocabulary = '{$addAttributesToVocabularyUrl}';
428
+ M2ePro.url.addOptionsToVocabulary = '{$addOptionsToVocabularyUrl}';
429
+ M2ePro.url.viewVocabularyAjax = '{$viewVocabularyAjax}';
430
+ M2ePro.url.saveAutoActionSettings = '{$saveAutoActionSettings}';
431
+ M2ePro.url.removeAttributeFromVocabulary = '{$removeAttributeFromVocabulary}';
432
+ M2ePro.url.removeOptionFromVocabulary = '{$removeOptionFromVocabulary}';
433
+
434
+ M2ePro.url.newAsin = '{$newAsinUrl}';
435
+
436
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
437
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
438
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
439
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
440
+
441
+ M2ePro.url.prepareData = '{$prepareData}';
442
+ M2ePro.url.getGridHtml = '{$getMoveToListingGridHtml}';
443
+ M2ePro.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
444
+ M2ePro.url.tryToMoveToListing = '{$tryToMoveToListing}';
445
+ M2ePro.url.moveToListing = '{$moveToListing}';
446
+
447
+ M2ePro.url.marketplace_synch = '{$marketplaceSynchUrl}';
448
+
449
+ M2ePro.url.get_variation_edit_popup = '{$getVariationEditPopupUrl}';
450
+ M2ePro.url.get_variation_manage_popup = '{$getVariationManagePopupUrl}';
451
+
452
+ M2ePro.url.variation_edit_action = '{$variationEditActionUrl}';
453
+ M2ePro.url.variation_manage_action = '{$variationManageActionUrl}';
454
+ M2ePro.url.variation_manage_generate_action = '{$variationManageGenerateActionUrl}';
455
+ M2ePro.url.variation_reset_action = '{$variationResetActionUrl}';
456
+
457
+ M2ePro.url.save_listing_additional_data = '{$saveListingAdditionalDataActionUrl}';
458
+
459
+ M2ePro.text.popup_title = '{$popupTitle}';
460
+ M2ePro.text.popup_title_single = '{$popupTitleSingle}';
461
+ M2ePro.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
462
+
463
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
464
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
465
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
466
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
467
+
468
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
469
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
470
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
471
+
472
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
473
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
474
+
475
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
476
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
477
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
478
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
479
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
480
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
481
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
482
+
483
+ M2ePro.text.successfully_moved = '{$successfullyMovedMessage}';
484
+ M2ePro.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
485
+ M2ePro.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
486
+
487
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
488
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
489
+
490
+ M2ePro.text.success_word = '{$successWord}';
491
+ M2ePro.text.notice_word = '{$noticeWord}';
492
+ M2ePro.text.warning_word = '{$warningWord}';
493
+ M2ePro.text.error_word = '{$errorWord}';
494
+ M2ePro.text.close_word = '{$closeWord}';
495
+
496
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
497
+
498
+ M2ePro.text.assign = '{$assignString}';
499
+ M2ePro.text.confirm = '{$textConfirm}';
500
+
501
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
502
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
503
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
504
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
505
+
506
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
507
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
508
+
509
+ M2ePro.text.no_variations_left = '{$noVariationsLeftText}';
510
+
511
+ M2ePro.text.variation_manage_matched_attributes_error = '{$variationManageMatchedAttributesError}';
512
+ M2ePro.text.variation_manage_matched_attributes_error_duplicate =
513
+ '{$variationManageMatchedAttributesErrorDuplicateSelection}';
514
+
515
+ M2ePro.text.variation_manage_matched_sku_popup_title = '{$variationManageSkuPopUpTitle}';
516
+ M2ePro.text.empty_sku_error = '{$emptySkuError}';
517
+
518
+ M2ePro.text.switch_to_individual_mode_popup_title = '{$switchToIndividualModePopUpTitle}';
519
+ M2ePro.text.switch_to_parent_mode_popup_title = '{$switchToParentModePopUpTitle}';
520
+
521
+ M2ePro.customData.componentMode = '{$component}';
522
+ M2ePro.customData.gridId = '{$gridId}';
523
+ M2ePro.customData.ignoreListings = '{$ignoreListings}';
524
+
525
+ M2ePro.customData.marketplace = {$marketplace};
526
+ M2ePro.customData.isNewAsinAvailable = {$isNewAsinAvailable};
527
+
528
+ Event.observe(window, 'load', function() {
529
+
530
+ ListingGridHandlerObj = new CommonAmazonListingGridHandler(
531
+ '{$gridId}',
532
+ {$listingData['id']}
533
+ );
534
+
535
+ // todo next
536
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
537
+ ListingGridHandlerObj.movingHandler.setOptions(M2ePro);
538
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
539
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
540
+ ListingGridHandlerObj.variationProductManageHandler.setOptions(M2ePro);
541
+
542
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
543
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
544
+
545
+ ListingProductVariationHandlerObj = new CommonListingProductVariationHandler(M2ePro,
546
+ ListingGridHandlerObj);
547
+
548
+ if (M2ePro.productsIdsForList) {
549
+ ListingGridHandlerObj.getGridMassActionObj().checkedString = M2ePro.productsIdsForList;
550
+ ListingGridHandlerObj.actionHandler.listAction();
551
+ }
552
+
553
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
554
+ if ({$showAutoAction}) {
555
+ ListingAutoActionHandlerObj.loadAutoActionHtml();
556
+ }
557
+
558
+ });
559
+
560
+ </script>
561
+ HTML;
562
+
563
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_view_help');
564
+ $productSearchBlock = $this->getLayout()
565
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_productSearch_main');
566
+
567
+ //------------------------------
568
+ $data = array(
569
+ 'target_css_class' => 'edit_settings_drop_down',
570
+ 'items' => $this->getTemplatesButtonDropDownItems()
571
+ );
572
+ $templatesDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
573
+ $templatesDropDownBlock->setData($data);
574
+ //------------------------------
575
+
576
+ //------------------------------
577
+ $data = array(
578
+ 'target_css_class' => 'add_products_drop_down',
579
+ 'items' => $this->getAddProductsDropDownItems()
580
+ );
581
+ $addProductsDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
582
+ $addProductsDropDownBlock->setData($data);
583
+ //------------------------------
584
+
585
+ //------------------------------
586
+ $listingSwitcher = $this->getLayout()->createBlock(
587
+ 'M2ePro/adminhtml_common_amazon_listing_view_listingSwitcher'
588
+ );
589
+ //------------------------------
590
+
591
+ //------------------------------
592
+ $viewHeaderBlock = $this->getLayout()->createBlock(
593
+ 'M2ePro/adminhtml_listing_view_header','',
594
+ array('listing' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Listing',$listingData['id']))
595
+ );
596
+ //------------------------------
597
+
598
+ //------------------------------
599
+ $switchToIndividualPopup = $this->getLayout()->createBlock(
600
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToIndividualPopup');
601
+ //------------------------------
602
+
603
+ //------------------------------
604
+ $switchToParentPopup = $this->getLayout()->createBlock(
605
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToParentPopup');
606
+ //------------------------------
607
+
608
+ return $javascriptsMain
609
+ . $templatesDropDownBlock->toHtml()
610
+ . $listingSwitcher->toHtml()
611
+ . $addProductsDropDownBlock->toHtml()
612
+ . $helpBlock->toHtml()
613
+ . $viewHeaderBlock->toHtml()
614
+ . $productSearchBlock->toHtml()
615
+ . $switchToIndividualPopup->toHtml()
616
+ . $switchToParentPopup->toHtml()
617
+ . parent::getGridHtml();
618
+ }
619
+
620
+ public function getHeaderHtml()
621
+ {
622
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
623
+
624
+ //------------------------------
625
+ $collection = Mage::getModel('M2ePro/Listing')->getCollection();
626
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
627
+ $collection->addFieldToFilter('id', array('neq' => $listingData['id']));
628
+ $collection->setPageSize(200);
629
+ $collection->setOrder('title', 'ASC');
630
+
631
+ $items = array();
632
+ foreach ($collection->getItems() as $item) {
633
+ $items[] = array(
634
+ 'label' => $item->getTitle(),
635
+ 'url' => $this->getUrl('*/*/view', array('id' => $item->getId()))
636
+ );
637
+ }
638
+ //------------------------------
639
+
640
+ if (count($items) == 0) {
641
+ return parent::getHeaderHtml();
642
+ }
643
+
644
+ //------------------------------
645
+ $data = array(
646
+ 'target_css_class' => 'listing-profile-title',
647
+ 'style' => 'max-height: 120px; overflow: auto; width: 200px;',
648
+ 'items' => $items
649
+ );
650
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
651
+ $dropDownBlock->setData($data);
652
+ //------------------------------
653
+
654
+ return parent::getHeaderHtml() . $dropDownBlock->toHtml();
655
+ }
656
+
657
+ public function getHeaderText()
658
+ {
659
+ //------------------------------
660
+ $changeProfile = Mage::helper('M2ePro')->__('Change Listing');
661
+ $headerText = parent::getHeaderText();
662
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
663
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($listingData['title']);
664
+ //------------------------------
665
+
666
+ return <<<HTML
667
+ {$headerText} <a href="javascript: void(0);"
668
+ id="listing-profile-title"
669
+ class="listing-profile-title"
670
+ style="font-weight: bold;"
671
+ title="{$changeProfile}"><span class="drop_down_header">"{$listingTitle}"</span></a>
672
+ HTML;
673
+ }
674
+
675
+ protected function getTemplatesButtonDropDownItems()
676
+ {
677
+ $items = array();
678
+
679
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
680
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
681
+ '*/adminhtml_common_amazon_listing/view',
682
+ array(
683
+ 'id' => $listingData['id']
684
+ )
685
+ );
686
+
687
+ //------------------------------
688
+ $url = $this->getUrl(
689
+ '*/adminhtml_common_amazon_listing/edit',
690
+ array(
691
+ 'id'=>$listingData['id'],
692
+ 'back'=>$backUrl,
693
+ 'tab' => 'selling'
694
+ )
695
+ );
696
+ $items[] = array(
697
+ 'url' => $url,
698
+ 'label' => Mage::helper('M2ePro')->__('Selling'),
699
+ 'target' => '_blank'
700
+ );
701
+ //------------------------------
702
+
703
+ //------------------------------
704
+ $url = $this->getUrl(
705
+ '*/adminhtml_common_amazon_listing/edit',
706
+ array(
707
+ 'id'=>$listingData['id'],
708
+ 'back'=>$backUrl,
709
+ 'tab' => 'search'
710
+ )
711
+ );
712
+ $items[] = array(
713
+ 'url' => $url,
714
+ 'label' => Mage::helper('M2ePro')->__('Search'),
715
+ 'target' => '_blank'
716
+ );
717
+ //------------------------------
718
+
719
+ //------------------------------
720
+ $items[] = array(
721
+ 'url' => 'javascript: void(0);',
722
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();',
723
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules')
724
+ );
725
+ //------------------------------
726
+
727
+ return $items;
728
+ }
729
+
730
+ public function getAddProductsDropDownItems()
731
+ {
732
+ $items = array();
733
+
734
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
735
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array(
736
+ 'id' => $listingData['id']
737
+ ));
738
+
739
+ //------------------------------
740
+ $url = $this->getUrl(
741
+ '*/adminhtml_common_listing_productAdd/index',
742
+ array(
743
+ 'id' => $listingData['id'],
744
+ 'back' => $backUrl,
745
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
746
+ 'clear' => 1,
747
+ 'step' => 2,
748
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
749
+ )
750
+ );
751
+ $items[] = array(
752
+ 'url' => $url,
753
+ 'label' => Mage::helper('M2ePro')->__('From Products List')
754
+ );
755
+ //------------------------------
756
+
757
+ //------------------------------
758
+ $url = $this->getUrl(
759
+ '*/adminhtml_common_listing_productAdd/index',
760
+ array(
761
+ 'id' => $listingData['id'],
762
+ 'back' => $backUrl,
763
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
764
+ 'clear' => 1,
765
+ 'step' => 2,
766
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
767
+ )
768
+ );
769
+ $items[] = array(
770
+ 'url' => $url,
771
+ 'label' => Mage::helper('M2ePro')->__('From Categories')
772
+ );
773
+ //------------------------------
774
+
775
+ return $items;
776
+ }
777
+
778
+ // ####################################
779
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php ADDED
@@ -0,0 +1,1608 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 $childProductsWarningsData;
16
+
17
+ private $hideSwitchToIndividualConfirm;
18
+ private $hideSwitchToParentConfirm;
19
+
20
+ // ####################################
21
+
22
+ public function __construct()
23
+ {
24
+ parent::__construct();
25
+
26
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+
28
+ $listing = Mage::helper('M2ePro/Component')->getUnknownObject('Listing', $listingData['id']);
29
+
30
+ $this->hideSwitchToIndividualConfirm =
31
+ $listing->getSetting('additional_data', 'hide_switch_to_individual_confirm', 0);
32
+
33
+ $this->hideSwitchToParentConfirm =
34
+ $listing->getSetting('additional_data', 'hide_switch_to_parent_confirm', 0);
35
+
36
+ // Initialization block
37
+ //------------------------------
38
+ $this->setId('amazonListingViewAmazonGrid'.$listingData['id']);
39
+ //------------------------------
40
+
41
+ $this->showAdvancedFilterProductsOption = false;
42
+
43
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
44
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
45
+ array('template')
46
+ );
47
+ }
48
+
49
+ // ####################################
50
+
51
+ public function getMainButtonsHtml()
52
+ {
53
+ $data = array(
54
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
55
+ );
56
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
57
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
58
+ );
59
+ $viewModeSwitcherBlock->addData($data);
60
+
61
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
62
+ }
63
+
64
+ // ####################################
65
+
66
+ protected function _prepareCollection()
67
+ {
68
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
69
+
70
+ // Get collection
71
+ //----------------------------
72
+ /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
73
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
74
+ Mage::getModel('catalog/product')->getResource());
75
+ $collection->setListingProductModeOn();
76
+ $collection
77
+ ->addAttributeToSelect('name')
78
+ ->addAttributeToSelect('sku')
79
+ ->joinTable(
80
+ array('cisi' => 'cataloginventory/stock_item'),
81
+ 'product_id=entity_id',
82
+ array('qty' => 'qty'),
83
+ '{{table}}.stock_id=1',
84
+ 'left'
85
+ );
86
+
87
+ //----------------------------
88
+
89
+ $collection->joinTable(
90
+ array('lp' => 'M2ePro/Listing_Product'),
91
+ 'product_id=entity_id',
92
+ array(
93
+ 'id' => 'id',
94
+ 'component_mode' => 'component_mode',
95
+ 'amazon_status' => 'status',
96
+ 'additional_data' => 'additional_data'
97
+ ),
98
+ array(
99
+ 'listing_id' => (int)$listingData['id']
100
+ )
101
+ );
102
+ $collection->joinTable(
103
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
104
+ 'listing_product_id=id',
105
+ array(
106
+ 'general_id' => 'general_id',
107
+ 'general_id_search_info' => 'general_id_search_info',
108
+ 'search_settings_status' => 'search_settings_status',
109
+ 'search_settings_data' => 'search_settings_data',
110
+ 'variation_child_statuses' => 'variation_child_statuses',
111
+ 'amazon_sku' => 'sku',
112
+ 'online_qty' => 'online_qty',
113
+ 'online_price' => 'online_price',
114
+ 'online_sale_price' => 'IF(
115
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
116
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
117
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
118
+ `alp`.`online_sale_price`,
119
+ NULL
120
+ )',
121
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
122
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
123
+ 'is_afn_channel' => 'is_afn_channel',
124
+ 'is_general_id_owner' => 'is_general_id_owner',
125
+ 'is_variation_parent' => 'is_variation_parent',
126
+ 'defected_messages' => 'defected_messages',
127
+ 'min_online_price' => 'IF(
128
+ (`t`.`variation_min_price` IS NULL),
129
+ IF(
130
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
131
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
132
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
133
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
134
+ `alp`.`online_sale_price`,
135
+ `alp`.`online_price`
136
+ ),
137
+ `t`.`variation_min_price`
138
+ )',
139
+ 'max_online_price' => 'IF(
140
+ (`t`.`variation_max_price` IS NULL),
141
+ IF(
142
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
143
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
144
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
145
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
146
+ `alp`.`online_sale_price`,
147
+ `alp`.`online_price`
148
+ ),
149
+ `t`.`variation_max_price`
150
+ )'
151
+ ),
152
+ '{{table}}.variation_parent_id is NULL'
153
+ );
154
+
155
+ $collection->getSelect()->joinLeft(
156
+ new Zend_Db_Expr('(
157
+ SELECT
158
+ `malp`.`variation_parent_id`,
159
+ MIN(
160
+ IF(
161
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
162
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
163
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
164
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
165
+ `malp`.`online_sale_price`,
166
+ `malp`.`online_price`
167
+ )
168
+ ) as variation_min_price,
169
+ MAX(
170
+ IF(
171
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
172
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
173
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
174
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
175
+ `malp`.`online_sale_price`,
176
+ `malp`.`online_price`
177
+ )
178
+ ) as variation_max_price
179
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
180
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
181
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
182
+ WHERE `mlp`.`status` IN (
183
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
184
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
185
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
186
+ GROUP BY `malp`.`variation_parent_id`
187
+ )'),
188
+ 'alp.listing_product_id=t.variation_parent_id',
189
+ array(
190
+ 'variation_min_price' => 'variation_min_price',
191
+ 'variation_max_price' => 'variation_max_price',
192
+ )
193
+ );
194
+
195
+ //----------------------------
196
+ // exit($collection->getSelect()->__toString());
197
+
198
+ // Set collection to grid
199
+ $this->setCollection($collection);
200
+
201
+ return parent::_prepareCollection();
202
+ }
203
+
204
+ protected function _prepareColumns()
205
+ {
206
+ $this->addColumn('product_id', array(
207
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
208
+ 'align' => 'right',
209
+ 'width' => '100px',
210
+ 'type' => 'number',
211
+ 'index' => 'entity_id',
212
+ 'filter_index' => 'entity_id',
213
+ 'frame_callback' => array($this, 'callbackColumnProductId')
214
+ ));
215
+
216
+ $this->addColumn('name', array(
217
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
218
+ 'align' => 'left',
219
+ //'width' => '300px',
220
+ 'type' => 'text',
221
+ 'index' => 'name',
222
+ 'filter_index' => 'name',
223
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
224
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
225
+ ));
226
+
227
+ $this->addColumn('sku', array(
228
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
229
+ 'align' => 'left',
230
+ 'width' => '150px',
231
+ 'type' => 'text',
232
+ 'index' => 'amazon_sku',
233
+ 'filter_index' => 'amazon_sku',
234
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
235
+ ));
236
+
237
+ $this->addColumn('general_id', array(
238
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
239
+ 'align' => 'left',
240
+ 'width' => '140px',
241
+ 'type' => 'text',
242
+ 'index' => 'general_id',
243
+ 'filter_index' => 'general_id',
244
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
245
+ ));
246
+
247
+ $this->addColumn('online_qty', array(
248
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
249
+ 'align' => 'right',
250
+ 'width' => '70px',
251
+ 'type' => 'number',
252
+ 'index' => 'online_qty',
253
+ 'filter_index' => 'online_qty',
254
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
255
+ ));
256
+
257
+ $dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
258
+
259
+ if ($dir == 'desc') {
260
+ $priceSortField = 'max_online_price';
261
+ } else {
262
+ $priceSortField = 'min_online_price';
263
+ }
264
+
265
+ $this->addColumn('online_price', array(
266
+ 'header' => Mage::helper('M2ePro')->__('Price'),
267
+ 'align' => 'right',
268
+ 'width' => '70px',
269
+ 'type' => 'number',
270
+ 'index' => $priceSortField,
271
+ 'filter_index' => $priceSortField,
272
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
273
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
274
+ ));
275
+
276
+ $this->addColumn('is_afn_channel', array(
277
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
278
+ 'align' => 'right',
279
+ 'width' => '90px',
280
+ 'index' => 'is_afn_channel',
281
+ 'filter_index' => 'is_afn_channel',
282
+ 'type' => 'options',
283
+ 'sortable' => false,
284
+ 'options' => array(
285
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
286
+ 1 => Mage::helper('M2ePro')->__('Amazon')
287
+ ),
288
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
289
+ ));
290
+
291
+ $this->addColumn('status', array(
292
+ 'header' => Mage::helper('M2ePro')->__('Status'),
293
+ 'width' => '155px',
294
+ 'index' => 'amazon_status',
295
+ 'filter_index' => 'amazon_status',
296
+ 'type' => 'options',
297
+ 'sortable' => false,
298
+ 'options' => array(
299
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
300
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
301
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
302
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
303
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
304
+ ),
305
+ 'frame_callback' => array($this, 'callbackColumnStatus'),
306
+ 'filter_condition_callback' => array($this, 'callbackFilterStatus')
307
+ ));
308
+
309
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
310
+ $this->addColumn('developer_action', array(
311
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
312
+ 'align' => 'left',
313
+ 'width' => '100px',
314
+ 'type' => 'text',
315
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
316
+ 'index' => 'value',
317
+ 'filter' => false,
318
+ 'sortable' => false,
319
+ 'js_handler' => 'ListingGridHandlerObj'
320
+ ));
321
+ }
322
+
323
+ return parent::_prepareColumns();
324
+ }
325
+
326
+ protected function _prepareMassaction()
327
+ {
328
+ // Set massaction identifiers
329
+ //--------------------------------
330
+ $this->setMassactionIdField('id');
331
+ $this->setMassactionIdFieldOnlyIndexValue(true);
332
+ //--------------------------------
333
+
334
+ // Set mass-action
335
+ //--------------------------------
336
+ $groups = array(
337
+ 'actions' => Mage::helper('M2ePro')->__('Actions'),
338
+ 'asin_isbn' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
339
+ 'description_policy' => Mage::helper('M2ePro')->__('Description Policy'),
340
+ 'other' => Mage::helper('M2ePro')->__('Other'),
341
+ );
342
+
343
+ $this->getMassactionBlock()->setGroups($groups);
344
+
345
+ $this->getMassactionBlock()->addItem('list', array(
346
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
347
+ 'url' => '',
348
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
349
+ ), 'actions');
350
+
351
+ $this->getMassactionBlock()->addItem('revise', array(
352
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
353
+ 'url' => '',
354
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
355
+ ), 'actions');
356
+
357
+ $this->getMassactionBlock()->addItem('relist', array(
358
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
359
+ 'url' => '',
360
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
361
+ ), 'actions');
362
+
363
+ $this->getMassactionBlock()->addItem('stop', array(
364
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
365
+ 'url' => '',
366
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
367
+ ), 'actions');
368
+
369
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
370
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
371
+ 'url' => '',
372
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
373
+ ), 'actions');
374
+
375
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
376
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
377
+ 'url' => '',
378
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
379
+ ), 'actions');
380
+
381
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
382
+ 'label' => Mage::helper('M2ePro')->__('Search Automatically'),
383
+ 'url' => '',
384
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
385
+ ), 'asin_isbn');
386
+
387
+ $this->getMassactionBlock()->addItem('newGeneralId', array(
388
+ 'label' => Mage::helper('M2ePro')->__('Assign Settings for New ASIN/ISBN'),
389
+ 'url' => '',
390
+ ), 'asin_isbn');
391
+
392
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
393
+ 'label' => Mage::helper('M2ePro')->__('Reset Information'),
394
+ 'url' => '',
395
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
396
+ ), 'asin_isbn');
397
+ //--------------------------------
398
+
399
+ return parent::_prepareMassaction();
400
+ }
401
+
402
+ // ####################################
403
+
404
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
405
+ {
406
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
407
+
408
+ $value = '<span>'.$productTitle.'</span>';
409
+
410
+ $tempSku = $row->getData('sku');
411
+ is_null($tempSku)
412
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
413
+
414
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
415
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
416
+
417
+ $listingProductId = (int)$row->getData('id');
418
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
419
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
420
+
421
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
422
+ return $value;
423
+ }
424
+
425
+ $generalId = $row->getData('general_id');
426
+
427
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
428
+ $amazonListingProduct = $listingProduct->getChildObject();
429
+ $variationManager = $amazonListingProduct->getVariationManager();
430
+
431
+ if ($variationManager->isRelationParentType()) {
432
+
433
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
434
+
435
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
436
+ $value .= implode(', ', $productAttributes);
437
+
438
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
439
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
440
+ Mage::helper('M2ePro')->__('Manage Magento Product Variations'))
441
+ );
442
+
443
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
444
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
445
+ );
446
+
447
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
448
+
449
+ $switchToIndividualJsMethod = <<<JS
450
+ ListingProductVariationHandlerObj
451
+ .setListingProductId({$listingProductId})
452
+ .showSwitchToIndividualModePopUp('{$popupTitle}');
453
+ JS;
454
+
455
+ if ($this->hideSwitchToIndividualConfirm) {
456
+ $switchToIndividualJsMethod = <<<JS
457
+ ListingProductVariationHandlerObj
458
+ .setListingProductId({$listingProductId})
459
+ .showManagePopup('{$popupTitle}');
460
+ JS;
461
+ }
462
+
463
+ $value .= <<<HTML
464
+ &nbsp;
465
+ <a href="javascript:"
466
+ onclick="{$switchToIndividualJsMethod}"
467
+ title="{$linkTitle}">
468
+ <img width="12" height="12" style="height: 12px; width: 12px; vertical-align: middle;" src="{$iconSettingsPath}">
469
+ </a>
470
+ HTML;
471
+ }
472
+
473
+ $value .= '</div>';
474
+
475
+ if (!empty($generalId) || $amazonListingProduct->isGeneralIdOwner()) {
476
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
477
+ $parentType = $variationManager->getTypeModel();
478
+
479
+ $linkContent = Mage::helper('M2ePro')->__('Manage Variations');
480
+ $vpmt = Mage::helper('M2ePro')->__('Manage Variations of &quot;%s&quot; ', $productTitle);
481
+ $vpmt = addslashes($vpmt);
482
+
483
+ if (!empty($generalId)) {
484
+ $vpmt .= '('. $generalId .')';
485
+ }
486
+
487
+ $problemStyle = '';
488
+ $problemIcon = '';
489
+
490
+ $linkTitle = Mage::helper('M2ePro')->__('Open Manage Variations Tool');
491
+
492
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
493
+ if (!$parentType->hasChannelTheme() || !$parentType->hasMatchedAttributes()) {
494
+
495
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
496
+ $problemStyle = 'style="font-weight: bold; color: #FF0000;" ';
497
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
498
+ $problemIcon = '<img style="vertical-align: middle;" src="'
499
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
500
+ }
501
+ } elseif (!empty($generalId)) {
502
+ if (!$parentType->hasMatchedAttributes()) {
503
+
504
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
505
+ $problemStyle = 'style="font-weight: bold;color: #FF0000;" ';
506
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
507
+ $problemIcon = '<img style="vertical-align: middle;" src="'
508
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
509
+ } elseif (($listingProduct->getChildObject()->isGeneralIdOwner() &&
510
+ !$parentType->hasChannelTheme()) ||
511
+ $this->hasChildWithWarning($listingProductId)) {
512
+
513
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
514
+ $problemStyle = 'style="font-weight: bold;" ';
515
+ $iconPath = $this->getSkinUrl('M2ePro/images/warning.png');
516
+ $problemIcon = '<img style="vertical-align: middle;" src="'
517
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
518
+ }
519
+ }
520
+
521
+ $value .= <<<HTML
522
+ <div style="float: left; margin: 0 0 0 7px">
523
+ <a {$problemStyle}href="javascript:"
524
+ onclick="ListingGridHandlerObj.variationProductManageHandler.openPopUp({$listingProductId}, '{$vpmt}')"
525
+ title="{$linkTitle}">{$linkContent}</a>&nbsp;{$problemIcon}
526
+ </div>
527
+ HTML;
528
+ }
529
+
530
+ return $value;
531
+ }
532
+
533
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
534
+
535
+ if (!empty($productOptions)) {
536
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
537
+ foreach ($productOptions as $attribute => $option) {
538
+ !$option && $option = '--';
539
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
540
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
541
+ }
542
+ $value .= '</div>';
543
+ }
544
+
545
+ // ---------------------------------
546
+ $hasInActionLock = $this->getLockedData($row);
547
+ $hasInActionLock = $hasInActionLock['in_action'];
548
+ // ---------------------------------
549
+
550
+ if (!$hasInActionLock) {
551
+
552
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variation');
553
+ $linkTitle = Mage::helper('M2ePro')->__('Edit Variation');
554
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/pencil.png').'">';
555
+
556
+ $value .= <<<HTML
557
+ <div style="clear: both"></div>
558
+ <div style="margin: 0 0 0 7px; float: left;">
559
+ <a href="javascript:"
560
+ onclick="ListingProductVariationHandlerObj
561
+ .setListingProductId({$listingProductId})
562
+ .showEditPopup('{$popupTitle}');"
563
+ title="{$linkTitle}">{$linkContent}</a>
564
+ </div>
565
+ HTML;
566
+ }
567
+
568
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variations') ;
569
+ $linkTitle = Mage::helper('M2ePro')->__('Add Another Variation(s)');
570
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
571
+
572
+ $value.= <<<HTML
573
+ <div style="margin: 0 0 0 7px; float: left;">
574
+ <a href="javascript:"
575
+ onclick="ListingProductVariationHandlerObj
576
+ .setListingProductId({$listingProductId})
577
+ .showManagePopup('{$popupTitle}');"
578
+ title="{$linkTitle}">{$linkContent}</a>
579
+ </div>
580
+ HTML;
581
+
582
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
583
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
584
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
585
+ );
586
+
587
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
588
+
589
+ $switchToParentJsMethod = <<<JS
590
+ ListingProductVariationHandlerObj
591
+ .setListingProductId({$listingProductId})
592
+ .showSwitchToParentModePopUp('{$popupTitle}');
593
+ JS;
594
+
595
+ if ($this->hideSwitchToParentConfirm) {
596
+ $switchToParentJsMethod = <<<JS
597
+ ListingProductVariationHandlerObj
598
+ .setListingProductId({$listingProductId})
599
+ .resetListingProductVariation();
600
+ JS;
601
+ }
602
+
603
+ $value .= <<<HTML
604
+ <div style="margin: 0 0 0 7px; float: left;">
605
+ <a href="javascript:"
606
+ onclick="{$switchToParentJsMethod}"
607
+ title="{$linkTitle}">
608
+ <img width="12" height="12" src="{$iconSettingsPath}">
609
+ </a>
610
+ </div>
611
+ HTML;
612
+ }
613
+
614
+ return $value;
615
+ }
616
+
617
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
618
+ {
619
+ if ((!$row->getData('is_variation_parent') &&
620
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
621
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
622
+
623
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
624
+ }
625
+
626
+ if (is_null($value) || $value === '') {
627
+ $value = Mage::helper('M2ePro')->__('N/A');
628
+ }
629
+
630
+ if (!$row->getData('is_variation_parent') && $row->getData('defected_messages')) {
631
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
632
+
633
+ $msg = '';
634
+ foreach ($defectedMessages as $message) {
635
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
636
+ if (!empty($message['value'])) {
637
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
638
+ }
639
+ $msg .= '</p>';
640
+ }
641
+
642
+ $value .= <<<HTML
643
+ <span style="float:right;">
644
+ <img id="map_link_defected_message_icon_{$row->getId()}"
645
+ class="tool-tip-image"
646
+ style="vertical-align: middle;"
647
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
648
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
649
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
650
+ <span>{$msg}</span>
651
+ </span>
652
+ </span>
653
+ HTML;
654
+ }
655
+
656
+ return $value;
657
+ }
658
+
659
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
660
+ {
661
+ if (empty($generalId)) {
662
+ if($row->getData('is_general_id_owner') == 1){
663
+ return $this->getGeneralIdColumnValueGeneralIdOwner($row);
664
+ }
665
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
666
+ }
667
+
668
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
669
+ }
670
+
671
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
672
+ {
673
+ if ((!$row->getData('is_variation_parent') &&
674
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
675
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
676
+
677
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
678
+ }
679
+
680
+ if ((bool)$row->getData('is_afn_channel')) {
681
+ return Mage::helper('M2ePro')->__('N/A');
682
+ }
683
+
684
+ if (is_null($value) || $value === '') {
685
+ if ($row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
686
+ !$row->getData('is_variation_parent')
687
+ ) {
688
+ return '<i style="color:gray;">receiving...</i>';
689
+ }
690
+
691
+ return Mage::helper('M2ePro')->__('N/A');
692
+ }
693
+
694
+ if ($value <= 0) {
695
+ return '<span style="color: red;">0</span>';
696
+ }
697
+
698
+ return $value;
699
+ }
700
+
701
+ public function callbackColumnPrice($value, $row, $column, $isExport)
702
+ {
703
+ if ((!$row->getData('is_variation_parent') &&
704
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
705
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
706
+
707
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
708
+ }
709
+
710
+ $onlineMinPrice = $row->getData('min_online_price');
711
+ $onlineMaxPrice = $row->getData('max_online_price');
712
+
713
+ if (is_null($onlineMinPrice) || $onlineMinPrice === '') {
714
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
715
+ $row->getData('is_variation_parent')
716
+ ) {
717
+ return Mage::helper('M2ePro')->__('N/A');
718
+ } else {
719
+ return '<i style="color:gray;">receiving...</i>';
720
+ }
721
+ }
722
+
723
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
724
+ $currency = Mage::helper('M2ePro/Component_Amazon')
725
+ ->getCachedObject('Marketplace',$marketplaceId)
726
+ ->getChildObject()
727
+ ->getDefaultCurrency();
728
+
729
+ if ($row->getData('is_variation_parent')) {
730
+ $onlineMinPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMinPrice);
731
+ $onlineMaxPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMaxPrice);
732
+
733
+ return $onlineMinPriceStr . (($onlineMinPrice != $onlineMaxPrice) ? ' - ' . $onlineMaxPriceStr : '');
734
+ }
735
+
736
+ $onlinePrice = $row->getData('online_price');
737
+ if ((float)$onlinePrice <= 0) {
738
+ $priceValue = '<span style="color: #f00;">0</span>';
739
+ } else {
740
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
741
+ }
742
+
743
+ $resultHtml = '';
744
+
745
+ $salePrice = $row->getData('online_sale_price');
746
+ if (!$row->getData('is_variation_parent') && (float)$salePrice > 0) {
747
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
748
+
749
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
750
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
751
+
752
+ if ($currentTimestamp <= $endDateTimestamp) {
753
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
754
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
755
+
756
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
757
+
758
+ $fromDate = Mage::app()->getLocale()->date(
759
+ $row->getData('online_sale_price_start_date'), $dateFormat
760
+ )->toString($dateFormat);
761
+ $toDate = Mage::app()->getLocale()->date(
762
+ $row->getData('online_sale_price_end_date'), $dateFormat
763
+ )->toString($dateFormat);
764
+
765
+ $intervalHtml = '<img class="tool-tip-image"
766
+ style="vertical-align: middle;"
767
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
768
+ text-align: left;
769
+ width: 120px;
770
+ background: #E3E3E3;">
771
+ <img src="'.$iconHelpPath.'">
772
+ <span style="color:gray;">
773
+ <strong>From:</strong> '.$fromDate.'<br/>
774
+ <strong>To:</strong> '.$toDate.'
775
+ </span>
776
+ </span>';
777
+
778
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
779
+
780
+ if ($currentTimestamp >= $startDateTimestamp &&
781
+ $currentTimestamp <= $endDateTimestamp &&
782
+ $salePrice < (float)$onlinePrice
783
+ ) {
784
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
785
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
786
+ } else {
787
+ $resultHtml .= $priceValue;
788
+ $resultHtml .= '<br/>'.$intervalHtml.
789
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
790
+ }
791
+ }
792
+ }
793
+
794
+ if (empty($resultHtml)) {
795
+ $resultHtml = $priceValue;
796
+ }
797
+
798
+ return $resultHtml;
799
+ }
800
+
801
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
802
+ {
803
+ if ((!$row->getData('is_variation_parent') &&
804
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
805
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
806
+
807
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
808
+ }
809
+
810
+ if (is_null($value) || $value === '') {
811
+ return Mage::helper('M2ePro')->__('N/A');
812
+ }
813
+
814
+ return $value;
815
+ }
816
+
817
+ public function callbackColumnStatus($value, $row, $column, $isExport)
818
+ {
819
+ $listingProductId = (int)$row->getData('id');
820
+
821
+ $html = $this->getViewLogIconHtml($listingProductId);
822
+
823
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
824
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
825
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
826
+
827
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
828
+ if (!empty($synchNote)) {
829
+
830
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
831
+
832
+ if (empty($html)) {
833
+ $html = <<<HTML
834
+ <span style="float:right;">
835
+ <img id="map_link_error_icon_{$row->getId()}"
836
+ class="tool-tip-image"
837
+ style="vertical-align: middle;"
838
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
839
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
840
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
841
+ <span>{$synchNote}</span>
842
+ </span>
843
+ </span>
844
+ HTML;
845
+ } else {
846
+ $html .= <<<HTML
847
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
848
+ HTML;
849
+ }
850
+ }
851
+
852
+ if (!$variationManager->isVariationParent()) {
853
+ return $html . $this->getProductStatus($row->getData('amazon_status')). $this->getLockedTag($row);
854
+ } else {
855
+
856
+ $generalId = $listingProduct->getGeneralId();
857
+ $variationChildStatuses = $row->getData('variation_child_statuses');
858
+ if (empty($generalId) || empty($variationChildStatuses)) {
859
+ return $html . $this->getProductStatus(Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) .
860
+ $this->getLockedTag($row);
861
+ }
862
+
863
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
864
+ $variationChildStatuses = array(
865
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED =>
866
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED],
867
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED =>
868
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_LISTED],
869
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED =>
870
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED],
871
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED =>
872
+ $variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED]
873
+ );
874
+
875
+ $linkTitle = Mage::helper('M2ePro')->__('Show all Child Products with such Status');
876
+
877
+ foreach ($variationChildStatuses as $status => $productsCount) {
878
+ if (empty($productsCount)) {
879
+ continue;
880
+ }
881
+
882
+ $filter = base64_encode('status=' . $status);
883
+
884
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
885
+ $vpmt = Mage::helper('M2ePro')->__('Manage Variations of &quot;%s&quot; ', $productTitle);
886
+ $vpmt = addslashes($vpmt);
887
+
888
+ $generalId = $row->getData('general_id');
889
+ if (!empty($generalId)) {
890
+ $vpmt .= '('. $generalId .')';
891
+ }
892
+
893
+ $productsCount = <<<HTML
894
+ <a onclick="ListingGridHandlerObj.variationProductManageHandler.openPopUp({$listingProductId}, '{$vpmt}', '{$filter}')"
895
+ class="hover-underline"
896
+ title="{$linkTitle}"
897
+ href="javascript:void(0)">[{$productsCount}]</a>
898
+ HTML;
899
+
900
+ $html .= '' . $this->getProductStatus($status) . '&nbsp;'. $productsCount . '<br/>';
901
+ }
902
+
903
+ $html .= $this->getLockedTag($row);
904
+ }
905
+
906
+ return $html;
907
+ }
908
+
909
+ private function getProductStatus($status)
910
+ {
911
+ switch ($status) {
912
+
913
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
914
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Unknown') . '</span>';
915
+
916
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
917
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
918
+
919
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
920
+ return '<span style="color: green;">' . Mage::helper('M2ePro')->__('Active') . '</span>';
921
+
922
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
923
+ return'<span style="color: red;">' . Mage::helper('M2ePro')->__('Inactive') . '</span>';
924
+
925
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
926
+ return'<span style="color: orange; font-weight: bold;">' .
927
+ Mage::helper('M2ePro')->__('Inactive (Blocked)') . '</span>';
928
+ }
929
+
930
+ return '';
931
+ }
932
+
933
+ private function getLockedTag($row)
934
+ {
935
+ $html = '';
936
+
937
+ $tempLocks = $this->getLockedData($row);
938
+ $tempLocks = $tempLocks['object_locks'];
939
+
940
+ $childCount = 0;
941
+
942
+ foreach ($tempLocks as $lock) {
943
+
944
+ switch ($lock->getTag()) {
945
+
946
+ case 'list_action':
947
+ $html .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
948
+ break;
949
+
950
+ case 'relist_action':
951
+ $html .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
952
+ break;
953
+
954
+ case 'revise_action':
955
+ $html .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
956
+ break;
957
+
958
+ case 'stop_action':
959
+ $html .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
960
+ break;
961
+
962
+ case 'stop_and_remove_action':
963
+ $html .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
964
+ break;
965
+
966
+ case 'delete_and_remove_action':
967
+ $html .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
968
+ break;
969
+
970
+ case 'child_products_in_action':
971
+ $childCount++;
972
+ break;
973
+
974
+ default:
975
+ break;
976
+
977
+ }
978
+ }
979
+
980
+ if ($childCount > 0) {
981
+ $html .= '<br/><span style="color: #605fff">[Child(s) in Action...]</span>';
982
+ }
983
+
984
+ return $html;
985
+ }
986
+
987
+ //----------------------------------------
988
+
989
+ protected function callbackFilterTitle($collection, $column)
990
+ {
991
+ $value = $column->getFilter()->getValue();
992
+
993
+ if ($value == null) {
994
+ return;
995
+ }
996
+
997
+ $collection->addFieldToFilter(
998
+ array(
999
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
1000
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
1001
+ )
1002
+ );
1003
+ }
1004
+
1005
+ protected function callbackFilterPrice($collection, $column)
1006
+ {
1007
+ $value = $column->getFilter()->getValue();
1008
+
1009
+ if (empty($value)) {
1010
+ return;
1011
+ }
1012
+
1013
+ $condition = '';
1014
+
1015
+ if (isset($value['from']) && $value['from'] != '') {
1016
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
1017
+ }
1018
+ if (isset($value['to']) && $value['to'] != '') {
1019
+ if (isset($value['from']) && $value['from'] != '') {
1020
+ $condition .= ' AND ';
1021
+ }
1022
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
1023
+ }
1024
+
1025
+ $condition = '(' . $condition . ') OR (';
1026
+
1027
+ if (isset($value['from']) && $value['from'] != '') {
1028
+ $condition .= 'max_online_price >= \''.$value['from'].'\'';
1029
+ }
1030
+ if (isset($value['to']) && $value['to'] != '') {
1031
+ if (isset($value['from']) && $value['from'] != '') {
1032
+ $condition .= ' AND ';
1033
+ }
1034
+ $condition .= 'max_online_price <= \''.$value['to'].'\'';
1035
+ }
1036
+
1037
+ $condition .= ')';
1038
+
1039
+ $collection->getSelect()->having($condition);
1040
+ }
1041
+
1042
+ protected function callbackFilterStatus($collection, $column)
1043
+ {
1044
+ $value = $column->getFilter()->getValue();
1045
+
1046
+ if ($value == null) {
1047
+ return;
1048
+ }
1049
+
1050
+ $collection->getSelect()->where("lp.status = {$value} OR
1051
+ (alp.variation_child_statuses REGEXP '\"{$value}\":[^0]') AND alp.is_variation_parent = 1");
1052
+ }
1053
+
1054
+ //----------------------------------------
1055
+
1056
+ public function getViewLogIconHtml($listingProductId)
1057
+ {
1058
+ $listingProductId = (int)$listingProductId;
1059
+
1060
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
1061
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
1062
+
1063
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
1064
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1065
+
1066
+ // Get last messages
1067
+ //--------------------------
1068
+ $dbSelect = $connRead->select()
1069
+ ->from(
1070
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
1071
+ array('action_id','action','type','description','create_date','initiator','listing_product_id')
1072
+ )
1073
+ ->where('`action_id` IS NOT NULL')
1074
+ ->order(array('id DESC'))
1075
+ ->limit(30);
1076
+
1077
+ if($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
1078
+ $dbSelect->where('listing_product_id = ? OR parent_listing_product_id = ?', $listingProductId);
1079
+ } else {
1080
+ $dbSelect->where('listing_product_id = ?', $listingProductId);
1081
+ }
1082
+
1083
+ $logRows = $connRead->fetchAll($dbSelect);
1084
+ //--------------------------
1085
+
1086
+ // Get grouped messages by action_id
1087
+ //--------------------------
1088
+ $actionsRows = array();
1089
+ $tempActionRows = array();
1090
+ $lastActionId = false;
1091
+
1092
+ foreach ($logRows as $row) {
1093
+
1094
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
1095
+
1096
+ if ($row['action_id'] !== $lastActionId) {
1097
+ if (count($tempActionRows) > 0) {
1098
+ $actionsRows[] = array(
1099
+ 'action_id' => $lastActionId,
1100
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
1101
+ 'date' => $this->getMainDateForActionId($tempActionRows),
1102
+ 'action' => $this->getActionForAction($tempActionRows[0]),
1103
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
1104
+ 'items' => $tempActionRows
1105
+ );
1106
+ $tempActionRows = array();
1107
+ }
1108
+ $lastActionId = $row['action_id'];
1109
+ }
1110
+ $tempActionRows[] = $row;
1111
+ }
1112
+
1113
+ if (count($tempActionRows) > 0) {
1114
+ $actionsRows[] = array(
1115
+ 'action_id' => $lastActionId,
1116
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
1117
+ 'date' => $this->getMainDateForActionId($tempActionRows),
1118
+ 'action' => $this->getActionForAction($tempActionRows[0]),
1119
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
1120
+ 'items' => $tempActionRows
1121
+ );
1122
+ }
1123
+
1124
+ if (count($actionsRows) <= 0) {
1125
+ return '';
1126
+ }
1127
+
1128
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
1129
+ foreach ($actionsRows as &$actionsRow) {
1130
+ if (!empty($actionsRow['items']) && $actionsRow['items'][0]['listing_product_id']==$listingProductId) {
1131
+ continue;
1132
+ }
1133
+ $actionsRow['action_in_progress'] = $this->isActionInProgress($actionsRow['action_id']);
1134
+
1135
+ $descArr = array();
1136
+ foreach ($actionsRow['items'] as $key => &$item) {
1137
+ if (array_key_exists($item['description'], $descArr)) {
1138
+ $descArr[$item['description']]['count']++;
1139
+ unset($actionsRow['items'][$key]);
1140
+ continue;
1141
+ }
1142
+ $item['count'] = 1;
1143
+ $descArr[$item['description']] = $item;
1144
+ }
1145
+ $actionsRow['items'] = array_values($descArr);
1146
+ }
1147
+ }
1148
+
1149
+ foreach ($actionsRows as &$actionsRow) {
1150
+ usort($actionsRow['items'], function($a, $b)
1151
+ {
1152
+ $sortOrder = array(
1153
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
1154
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
1155
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
1156
+ );
1157
+
1158
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
1159
+ });
1160
+ }
1161
+
1162
+ $tips = array(
1163
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
1164
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
1165
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
1166
+ );
1167
+
1168
+ $icons = array(
1169
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
1170
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
1171
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
1172
+ );
1173
+
1174
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
1175
+ 'entity_id' => $listingProductId,
1176
+ 'rows' => $actionsRows,
1177
+ 'tips' => $tips,
1178
+ 'icons' => $icons,
1179
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
1180
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
1181
+ ));
1182
+
1183
+ return $summary->toHtml();
1184
+ }
1185
+
1186
+ public function getActionForAction($actionRows)
1187
+ {
1188
+ $string = '';
1189
+
1190
+ switch ($actionRows['action']) {
1191
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
1192
+ $string = Mage::helper('M2ePro')->__('List');
1193
+ break;
1194
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
1195
+ $string = Mage::helper('M2ePro')->__('Relist');
1196
+ break;
1197
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
1198
+ $string = Mage::helper('M2ePro')->__('Revise');
1199
+ break;
1200
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
1201
+ $string = Mage::helper('M2ePro')->__('Stop');
1202
+ break;
1203
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
1204
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
1205
+ break;
1206
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
1207
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
1208
+ break;
1209
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
1210
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
1211
+ break;
1212
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
1213
+ $string = Mage::helper('M2ePro')->__('Channel Change');
1214
+ break;
1215
+ }
1216
+
1217
+ return $string;
1218
+ }
1219
+
1220
+ public function getInitiatorForAction($actionRows)
1221
+ {
1222
+ $string = '';
1223
+
1224
+ switch ((int)$actionRows['initiator']) {
1225
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
1226
+ $string = '';
1227
+ break;
1228
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
1229
+ $string = Mage::helper('M2ePro')->__('Manual');
1230
+ break;
1231
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
1232
+ $string = Mage::helper('M2ePro')->__('Automatic');
1233
+ break;
1234
+ }
1235
+
1236
+ return $string;
1237
+ }
1238
+
1239
+ public function getMainTypeForActionId($actionRows)
1240
+ {
1241
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
1242
+
1243
+ foreach ($actionRows as $row) {
1244
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
1245
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
1246
+ break;
1247
+ }
1248
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
1249
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
1250
+ }
1251
+ }
1252
+
1253
+ return $type;
1254
+ }
1255
+
1256
+ public function getMainDateForActionId($actionRows)
1257
+ {
1258
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
1259
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
1260
+ }
1261
+
1262
+ public function isActionInProgress($actionId)
1263
+ {
1264
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
1265
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1266
+
1267
+ // Get last messages
1268
+ //--------------------------
1269
+ $dbSelect = $connRead->select()
1270
+ ->from(
1271
+ Mage::getResourceModel('M2ePro/Processing_Request')->getMainTable()
1272
+ )
1273
+ ->where('responser_params REGEXP \'"logs_action_id":'.$actionId.'\'');
1274
+
1275
+ $result = $connRead->fetchAll($dbSelect);
1276
+
1277
+ return !empty($result);
1278
+ }
1279
+
1280
+ // ####################################
1281
+
1282
+ public function getGridUrl()
1283
+ {
1284
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
1285
+ }
1286
+
1287
+ public function getRowUrl($row)
1288
+ {
1289
+ return false;
1290
+ }
1291
+
1292
+ // ####################################
1293
+
1294
+ protected function _getStore()
1295
+ {
1296
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
1297
+
1298
+ // Get store filter
1299
+ //----------------------------
1300
+ $storeId = $listing['store_id'];
1301
+ //----------------------------
1302
+
1303
+ return Mage::app()->getStore((int)$storeId);
1304
+ }
1305
+
1306
+ // ####################################
1307
+
1308
+ protected function _toHtml()
1309
+ {
1310
+ $javascriptsMain = <<<JAVASCRIPT
1311
+ <script type="text/javascript">
1312
+
1313
+ if (typeof ListingGridHandlerObj != 'undefined') {
1314
+ ListingGridHandlerObj.afterInitPage();
1315
+ }
1316
+
1317
+ Event.observe(window, 'load', function() {
1318
+ setTimeout(function() {
1319
+ ListingGridHandlerObj.afterInitPage();
1320
+ }, 350);
1321
+ });
1322
+
1323
+ </script>
1324
+ JAVASCRIPT;
1325
+
1326
+ return parent::_toHtml().$javascriptsMain;
1327
+ }
1328
+
1329
+ // ####################################
1330
+
1331
+ private function getLockedData($row)
1332
+ {
1333
+ $listingProductId = $row->getData('id');
1334
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1335
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($listingProductId)->getObjectLocks();
1336
+ $tempArray = array(
1337
+ 'object_locks' => $objectLocks,
1338
+ 'in_action' => !empty($objectLocks),
1339
+ );
1340
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1341
+ }
1342
+
1343
+ return $this->lockedDataCache[$listingProductId];
1344
+ }
1345
+
1346
+ // ####################################
1347
+
1348
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
1349
+ {
1350
+ // ---------------------------------
1351
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1352
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
1353
+ }
1354
+ // ---------------------------------
1355
+
1356
+ // ---------------------------------
1357
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1358
+ // ---------------------------------
1359
+
1360
+ // ---------------------------------
1361
+ $lpId = $row->getData('id');
1362
+
1363
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
1364
+ if (strlen($productTitle) > 60) {
1365
+ $productTitle = substr($productTitle, 0, 60) . '...';
1366
+ }
1367
+ $productTitle = Mage::helper('M2ePro')->__('Assign ASIN/ISBN For &quot;%product_title%&quot;', $productTitle);
1368
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
1369
+ // ---------------------------------
1370
+
1371
+ // ---------------------------------
1372
+
1373
+ $searchSettingsStatus = $row->getData('search_settings_status');
1374
+
1375
+ // ---------------------------------
1376
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
1377
+
1378
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN Search in Progress.');
1379
+ $iconSrc = $iconPath.'processing.gif';
1380
+
1381
+ return <<<HTML
1382
+ &nbsp;
1383
+ <a href="javascript: void(0);" title="{$tip}">
1384
+ <img src="{$iconSrc}" alt="">
1385
+ </a>
1386
+ HTML;
1387
+ }
1388
+ // ---------------------------------
1389
+
1390
+ // ---------------------------------
1391
+ $searchSettingsData = $row->getData('search_settings_data');
1392
+
1393
+ $suggestData = array();
1394
+ if (!is_null($searchSettingsData)) {
1395
+ $searchSettingsData = @json_decode($searchSettingsData,true);
1396
+ !empty($searchSettingsData['data']) && $suggestData = $searchSettingsData['data'];
1397
+
1398
+ }
1399
+ // ---------------------------------
1400
+
1401
+ $na = Mage::helper('M2ePro')->__('N/A');
1402
+
1403
+ if (!empty($suggestData)) {
1404
+
1405
+ $tip = Mage::helper('M2ePro')->__('Choose ASIN/ISBN from the list');
1406
+ $iconSrc = $iconPath.'list.png';
1407
+
1408
+ return <<<HTML
1409
+ {$na} &nbsp;
1410
+ <a href="javascript:;" title="{$tip}"
1411
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">
1412
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1413
+ </a>
1414
+ HTML;
1415
+ }
1416
+
1417
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND) {
1418
+
1419
+ $tip = Mage::helper('M2ePro')->__(
1420
+ 'There were no Products found on Amazon according to the Listing Search Settings.'
1421
+ );
1422
+ $tip = Mage::helper('M2ePro')->escapeJs($tip);
1423
+
1424
+ $iconSrc = $iconPath.'error.png';
1425
+
1426
+ return <<<HTML
1427
+ {$na} &nbsp;
1428
+ <a href="javascript: void(0);" title="{$tip}"
1429
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId},'{$tip}');">
1430
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1431
+ </a>
1432
+ HTML;
1433
+ }
1434
+
1435
+ $tip = Mage::helper('M2ePro')->__('Search for ASIN/ISBN');
1436
+ $iconSrc = $iconPath.'search.png';
1437
+
1438
+ return <<<HTML
1439
+ {$na} &nbsp;
1440
+ <a href="javascript:;" title="{$tip}"
1441
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId});">
1442
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1443
+ </a>
1444
+ HTML;
1445
+ }
1446
+
1447
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
1448
+ {
1449
+ $generalId = $row->getData('general_id');
1450
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
1451
+
1452
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1453
+ $generalId,
1454
+ $marketplaceId
1455
+ );
1456
+
1457
+ $generalIdOwnerHtml = '';
1458
+ if($row->getData('is_general_id_owner') == Ess_M2ePro_Model_Amazon_Listing_Product::IS_GENERAL_ID_OWNER_YES){
1459
+
1460
+ $generalIdOwnerHtml = '<br/><span style="font-size: 10px; color: grey;">'.
1461
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
1462
+ '</span>';
1463
+ }
1464
+
1465
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1466
+
1467
+ return <<<HTML
1468
+ <a href="{$url}" target="_blank">{$generalId}</a>{$generalIdOwnerHtml}
1469
+ HTML;
1470
+ }
1471
+
1472
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1473
+
1474
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
1475
+
1476
+ if (!empty($generalIdSearchInfo)) {
1477
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
1478
+ }
1479
+
1480
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
1481
+
1482
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
1483
+
1484
+ $text = <<<HTML
1485
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
1486
+ HTML;
1487
+
1488
+ } else {
1489
+
1490
+ $text = <<<HTML
1491
+ <a href="{$url}" target="_blank">{$generalId}</a>
1492
+ HTML;
1493
+
1494
+ }
1495
+
1496
+ // ---------------------------------
1497
+ $hasInActionLock = $this->getLockedData($row);
1498
+ $hasInActionLock = $hasInActionLock['in_action'];
1499
+ // ---------------------------------
1500
+
1501
+ if ($hasInActionLock) {
1502
+ return $text . $generalIdOwnerHtml;
1503
+ }
1504
+
1505
+ $listingProductId = (int)$row->getData('id');
1506
+
1507
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
1508
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
1509
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
1510
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
1511
+ $variationChildStatuses = $row->getData('variation_child_statuses');
1512
+
1513
+ if ($variationManager->isVariationParent() && !empty($variationChildStatuses)) {
1514
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
1515
+ unset($variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED]);
1516
+
1517
+ foreach ($variationChildStatuses as $variationChildStatus) {
1518
+ if (!empty($variationChildStatus)) {
1519
+ return $text . $generalIdOwnerHtml;
1520
+ }
1521
+ }
1522
+ }
1523
+
1524
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1525
+ $iconSrc = $iconPath.'unassign.png';
1526
+
1527
+ $text .= <<<HTML
1528
+ &nbsp;
1529
+ <a href="javascript:;"
1530
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$listingProductId});"
1531
+ title="{$tip}">
1532
+ <img src="{$iconSrc}" width="16" height="16"/>
1533
+ </a>{$generalIdOwnerHtml}
1534
+ HTML;
1535
+
1536
+ return $text;
1537
+ }
1538
+
1539
+ private function getGeneralIdColumnValueGeneralIdOwner($row)
1540
+ {
1541
+ $text = Mage::helper('M2ePro')->__('New ASIN/ISBN');
1542
+
1543
+ // ---------------------------------
1544
+ $hasInActionLock = $this->getLockedData($row);
1545
+ $hasInActionLock = $hasInActionLock['in_action'];
1546
+ // ---------------------------------
1547
+
1548
+ if ($hasInActionLock) {
1549
+ return $text;
1550
+ }
1551
+
1552
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1553
+
1554
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1555
+ $iconSrc = $iconPath.'unassign.png';
1556
+
1557
+ $lpId = $row->getData('id');
1558
+
1559
+ $text .= <<<HTML
1560
+ &nbsp;
1561
+ <a href="javascript:;"
1562
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$lpId});"
1563
+ title="{$tip}"><img src="{$iconSrc}" width="16" height="16"/>
1564
+ </a>
1565
+ HTML;
1566
+ return $text;
1567
+ }
1568
+
1569
+ // ####################################
1570
+
1571
+ protected function getChildProductsWarningsData()
1572
+ {
1573
+ if (is_null($this->childProductsWarningsData)) {
1574
+ $this->childProductsWarningsData = array();
1575
+
1576
+ $productsIds = array();
1577
+ foreach ($this->getCollection()->getData() as $row) {
1578
+ $productsIds[] = $row['id'];
1579
+ }
1580
+
1581
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1582
+ $tableAmazonListingProduct = Mage::getSingleton('core/resource')
1583
+ ->getTableName('m2epro_amazon_listing_product');
1584
+
1585
+ $select = $connRead->select();
1586
+ $select->distinct(true);
1587
+ $select->from(array('alp' => $tableAmazonListingProduct), array('variation_parent_id'))
1588
+ ->where('variation_parent_id IN (?)', $productsIds)
1589
+ ->where(
1590
+ 'is_variation_product_matched = 0 OR
1591
+ (general_id IS NOT NULL AND is_variation_channel_matched = 0)'
1592
+ );
1593
+
1594
+ $this->childProductsWarningsData = Mage::getResourceModel('core/config')
1595
+ ->getReadConnection()
1596
+ ->fetchCol($select);
1597
+ }
1598
+
1599
+ return $this->childProductsWarningsData;
1600
+ }
1601
+
1602
+ protected function hasChildWithWarning($listingProductId)
1603
+ {
1604
+ return in_array($listingProductId, $this->getChildProductsWarningsData());
1605
+ }
1606
+
1607
+ // ####################################
1608
+ }
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,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $priceAttributeAlias = 'price';
196
+ if ($store->getId()) {
197
+ $priceAttributeAlias = 'magento_price';
198
+ }
199
+
200
+ $this->addColumn($priceAttributeAlias, array(
201
+ 'header' => Mage::helper('M2ePro')->__('Price'),
202
+ 'align' => 'right',
203
+ 'width' => '100px',
204
+ 'type' => 'price',
205
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
206
+ 'index' => $priceAttributeAlias,
207
+ 'filter_index' => $priceAttributeAlias,
208
+ 'frame_callback' => array($this, 'callbackColumnPrice')
209
+ ));
210
+
211
+ $this->addColumn('qty', array(
212
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
213
+ 'align' => 'right',
214
+ 'width' => '100px',
215
+ 'type' => 'number',
216
+ 'index' => 'qty',
217
+ 'filter_index' => 'qty',
218
+ 'frame_callback' => array($this, 'callbackColumnQty')
219
+ ));
220
+
221
+ $this->addColumn('visibility', array(
222
+ 'header' => Mage::helper('M2ePro')->__('Visibility'),
223
+ 'align' => 'left',
224
+ 'width' => '90px',
225
+ 'type' => 'options',
226
+ 'sortable' => false,
227
+ 'index' => 'visibility',
228
+ 'filter_index' => 'visibility',
229
+ 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray()
230
+ ));
231
+
232
+ $this->addColumn('status', array(
233
+ 'header' => Mage::helper('M2ePro')->__('Status'),
234
+ 'align' => 'left',
235
+ 'width' => '90px',
236
+ 'type' => 'options',
237
+ 'sortable' => false,
238
+ 'index' => 'status',
239
+ 'filter_index' => 'status',
240
+ 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
241
+ 'frame_callback' => array($this, 'callbackColumnStatus')
242
+ ));
243
+
244
+ if (!Mage::app()->isSingleStoreMode()) {
245
+
246
+ $this->addColumn('websites', array(
247
+ 'header' => Mage::helper('M2ePro')->__('Websites'),
248
+ 'align' => 'left',
249
+ 'width' => '90px',
250
+ 'type' => 'options',
251
+ 'sortable' => false,
252
+ 'index' => 'websites',
253
+ 'filter_index' => 'websites',
254
+ 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash()
255
+ ));
256
+ }
257
+
258
+ return parent::_prepareColumns();
259
+ }
260
+
261
+ // ####################################
262
+
263
+ public function callbackColumnPrice($value, $row, $column, $isExport)
264
+ {
265
+ $rowVal = $row->getData();
266
+
267
+ if ($column->getId() == 'magento_price' &&
268
+ (!isset($rowVal['magento_price']) || (float)$rowVal['magento_price'] <= 0)
269
+ ) {
270
+ $value = '<span style="color: red;">0</span>';
271
+ }
272
+
273
+ if ($column->getId() == 'price' &&
274
+ (!isset($rowVal['price']) || (float)$rowVal['price'] <= 0)
275
+ ) {
276
+ $value = '<span style="color: red;">0</span>';
277
+ }
278
+
279
+ return $value;
280
+ }
281
+
282
+ // ####################################
283
+
284
+ public function getGridUrl()
285
+ {
286
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
287
+ }
288
+
289
+ public function getRowUrl($row)
290
+ {
291
+ return false;
292
+ }
293
+
294
+ // ####################################
295
+
296
+ protected function _addColumnFilterToCollection($column)
297
+ {
298
+ if ($this->getCollection()) {
299
+ if ($column->getId() == 'websites') {
300
+ $this->getCollection()->joinField('websites',
301
+ 'catalog/product_website',
302
+ 'website_id',
303
+ 'product_id=entity_id',
304
+ null,
305
+ 'left');
306
+ }
307
+ }
308
+ return parent::_addColumnFilterToCollection($column);
309
+ }
310
+
311
+ // ####################################
312
+
313
+ protected function _getStore()
314
+ {
315
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
316
+
317
+ // Get store filter
318
+ //----------------------------
319
+ $storeId = $listing['store_id'];
320
+ //----------------------------
321
+
322
+ return Mage::app()->getStore((int)$storeId);
323
+ }
324
+
325
+ protected function _toHtml()
326
+ {
327
+ $javascriptsMain = <<<JAVASCRIPT
328
+ <script type="text/javascript">
329
+
330
+ if (typeof ListingGridHandlerObj != 'undefined') {
331
+ ListingGridHandlerObj.afterInitPage();
332
+ }
333
+
334
+ Event.observe(window, 'load', function() {
335
+ setTimeout(function() {
336
+ ListingGridHandlerObj.afterInitPage();
337
+ }, 350);
338
+ });
339
+
340
+ </script>
341
+ JAVASCRIPT;
342
+
343
+ return parent::_toHtml().$javascriptsMain;
344
+ }
345
+
346
+ // ####################################
347
+
348
+ protected function isShowRuleBlock()
349
+ {
350
+ /** @var $ruleModel Ess_M2ePro_Model_Magento_Product_Rule */
351
+ $ruleModel = Mage::helper('M2ePro/Data_Global')->getValue('rule_model');
352
+ if ($ruleModel->isEmpty()) {
353
+ return false;
354
+ }
355
+
356
+ return parent::isShowRuleBlock();
357
+ }
358
+
359
+ // ####################################
360
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.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_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_SETTINGS,
34
+ 'label' => Mage::helper('M2ePro')->__('Settings')
35
+ ),
36
+ array(
37
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_SELLERCENTRAL,
38
+ 'label' => Mage::helper('M2ePro')->__('Seller Сentral')
39
+ ),
40
+ array(
41
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_MAGENTO,
42
+ 'label' => Mage::helper('M2ePro')->__('Magento')
43
+ )
44
+ );
45
+ }
46
+
47
+ // ####################################
48
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php ADDED
@@ -0,0 +1,995 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN,
99
+ )
100
+ )
101
+ );
102
+ $collection->joinTable(
103
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
104
+ 'listing_product_id=id',
105
+ array(
106
+ 'general_id' => 'general_id',
107
+ 'search_settings_status' => 'search_settings_status',
108
+ 'amazon_sku' => 'sku',
109
+ 'online_qty' => 'online_qty',
110
+ 'online_price' => 'online_price',
111
+ 'online_sale_price' => 'IF(
112
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
113
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
114
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
115
+ `alp`.`online_sale_price`,
116
+ NULL
117
+ )',
118
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
119
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
120
+ 'is_afn_channel' => 'is_afn_channel',
121
+ 'is_general_id_owner' => 'is_general_id_owner',
122
+ 'variation_child_statuses' => 'variation_child_statuses',
123
+ 'is_variation_parent' => 'is_variation_parent',
124
+ 'variation_parent_id' => 'variation_parent_id',
125
+ 'defected_messages' => 'defected_messages',
126
+ 'min_online_price' => 'IF(
127
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
128
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
129
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
130
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
131
+ `alp`.`online_sale_price`,
132
+ `alp`.`online_price`
133
+ )'
134
+ ),
135
+ '{{table}}.is_variation_parent = 0'
136
+ );
137
+ //----------------------------
138
+ // exit($collection->getSelect()->__toString());
139
+
140
+ // Set collection to grid
141
+ $this->setCollection($collection);
142
+
143
+ return parent::_prepareCollection();
144
+ }
145
+
146
+ protected function _prepareColumns()
147
+ {
148
+ $this->addColumn('product_id', array(
149
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
150
+ 'align' => 'right',
151
+ 'width' => '100px',
152
+ 'type' => 'number',
153
+ 'index' => 'entity_id',
154
+ 'filter_index' => 'entity_id',
155
+ 'frame_callback' => array($this, 'callbackColumnProductId')
156
+ ));
157
+
158
+ $this->addColumn('name', array(
159
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
160
+ 'align' => 'left',
161
+ //'width' => '300px',
162
+ 'type' => 'text',
163
+ 'index' => 'name',
164
+ 'filter_index' => 'name',
165
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
166
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
167
+ ));
168
+
169
+ $this->addColumn('sku', array(
170
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
171
+ 'align' => 'left',
172
+ 'width' => '150px',
173
+ 'type' => 'text',
174
+ 'index' => 'amazon_sku',
175
+ 'filter_index' => 'amazon_sku',
176
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
177
+ ));
178
+
179
+ $this->addColumn('general_id', array(
180
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
181
+ 'align' => 'left',
182
+ 'width' => '140px',
183
+ 'type' => 'text',
184
+ 'index' => 'general_id',
185
+ 'filter_index' => 'general_id',
186
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
187
+ ));
188
+
189
+ $this->addColumn('online_qty', array(
190
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
191
+ 'align' => 'right',
192
+ 'width' => '70px',
193
+ 'type' => 'number',
194
+ 'index' => 'online_qty',
195
+ 'filter_index' => 'online_qty',
196
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
197
+ ));
198
+
199
+ $this->addColumn('online_price', array(
200
+ 'header' => Mage::helper('M2ePro')->__('Price'),
201
+ 'align' => 'right',
202
+ 'width' => '70px',
203
+ 'type' => 'number',
204
+ 'index' => 'min_online_price',
205
+ 'filter_index' => 'min_online_price',
206
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
207
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
208
+ ));
209
+
210
+ $this->addColumn('is_afn_channel', array(
211
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
212
+ 'align' => 'right',
213
+ 'width' => '90px',
214
+ 'index' => 'is_afn_channel',
215
+ 'filter_index' => 'is_afn_channel',
216
+ 'type' => 'options',
217
+ 'sortable' => false,
218
+ 'options' => array(
219
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
220
+ 1 => Mage::helper('M2ePro')->__('Amazon')
221
+ ),
222
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
223
+ ));
224
+
225
+ $this->addColumn('status', array(
226
+ 'header' => Mage::helper('M2ePro')->__('Status'),
227
+ 'width' => '155px',
228
+ 'index' => 'amazon_status',
229
+ 'filter_index' => 'amazon_status',
230
+ 'type' => 'options',
231
+ 'sortable' => false,
232
+ 'options' => array(
233
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
234
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
235
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
236
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
237
+ ),
238
+ 'frame_callback' => array($this, 'callbackColumnStatus')
239
+ ));
240
+
241
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
242
+ $this->addColumn('developer_action', array(
243
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
244
+ 'align' => 'left',
245
+ 'width' => '100px',
246
+ 'type' => 'text',
247
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
248
+ 'index' => 'value',
249
+ 'filter' => false,
250
+ 'sortable' => false,
251
+ 'js_handler' => 'ListingGridHandlerObj'
252
+ ));
253
+ }
254
+
255
+ return parent::_prepareColumns();
256
+ }
257
+
258
+ protected function _prepareMassaction()
259
+ {
260
+ // Set massaction identifiers
261
+ //--------------------------------
262
+ $this->setMassactionIdField('id');
263
+ $this->setMassactionIdFieldOnlyIndexValue(true);
264
+ //--------------------------------
265
+
266
+ // Set mass-action
267
+ //--------------------------------
268
+ $this->getMassactionBlock()->addItem('revise', array(
269
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
270
+ 'url' => '',
271
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
272
+ ));
273
+
274
+ $this->getMassactionBlock()->addItem('relist', array(
275
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
276
+ 'url' => '',
277
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
278
+ ));
279
+
280
+ $this->getMassactionBlock()->addItem('stop', array(
281
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
282
+ 'url' => '',
283
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
284
+ ));
285
+
286
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
287
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
288
+ 'url' => '',
289
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
290
+ ));
291
+
292
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
293
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
294
+ 'url' => '',
295
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
296
+ ));
297
+ //--------------------------------
298
+
299
+ return parent::_prepareMassaction();
300
+ }
301
+
302
+ // ####################################
303
+
304
+ public function callbackColumnProductId($value, $row, $column, $isExport)
305
+ {
306
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
307
+
308
+ $storeId = (int)$listingData['store_id'];
309
+
310
+ $withoutImageHtml = '<a href="'
311
+ .$this->getUrl('adminhtml/catalog_product/edit',
312
+ array('id' => $value))
313
+ .'" target="_blank">'.$value.'</a>';
314
+
315
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
316
+ ->getGroupValue('/view/',
317
+ 'show_products_thumbnails');
318
+ if (!$showProductsThumbnails) {
319
+ return $withoutImageHtml;
320
+ }
321
+
322
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
323
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
324
+ $magentoProduct->setProductId($value);
325
+ $magentoProduct->setStoreId($storeId);
326
+
327
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
328
+ if (is_null($imageUrlResized)) {
329
+ return $withoutImageHtml;
330
+ }
331
+
332
+ $imageHtml = $value.'<hr style="border: 1px solid silver; border-bottom: none;"><img src="'.
333
+ $imageUrlResized.'" />';
334
+ $withImageHtml = str_replace('>'.$value.'<','>'.$imageHtml.'<',$withoutImageHtml);
335
+
336
+ return $withImageHtml;
337
+ }
338
+
339
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
340
+ {
341
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
342
+
343
+ $value = '<span>'.$productTitle.'</span>';
344
+
345
+ $tempSku = $row->getData('sku');
346
+ is_null($tempSku)
347
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
348
+
349
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
350
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
351
+
352
+ $listingProduct = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'));
353
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
354
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
355
+
356
+ if (!$variationManager->isVariationProduct()) {
357
+ return $value;
358
+ }
359
+
360
+ if ($variationManager->isRelationChildType()) {
361
+ $typeModel = $variationManager->getTypeModel();
362
+
363
+ $productOptions = $typeModel->getProductOptions();
364
+ $channelOptions = $typeModel->getChannelOptions();
365
+
366
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $parentAmazonListingProduct */
367
+ $parentAmazonListingProduct = $typeModel->getParentListingProduct()->getChildObject();
368
+
369
+ $matchedAttributes = $parentAmazonListingProduct->getVariationManager()
370
+ ->getTypeModel()
371
+ ->getMatchedAttributes();
372
+
373
+ if (!empty($matchedAttributes)) {
374
+
375
+ $sortedOptions = array();
376
+
377
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
378
+ $sortedOptions[$amazonAttr] = $channelOptions[$amazonAttr];
379
+ }
380
+
381
+ $channelOptions = $sortedOptions;
382
+ }
383
+
384
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
385
+ Mage::helper('M2ePro')->__('Magento Variation') . '</div>';
386
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
387
+ foreach ($productOptions as $attribute => $option) {
388
+ !$option && $option = '--';
389
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
390
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
391
+ }
392
+ $value .= '</div>';
393
+
394
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
395
+ Mage::helper('M2ePro')->__('Amazon Variation') . '</div>';
396
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
397
+ foreach ($channelOptions as $attribute => $option) {
398
+ !$option && $option = '--';
399
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
400
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
401
+ }
402
+ $value .= '</div>';
403
+
404
+ return $value;
405
+ }
406
+
407
+ $productOptions = array();
408
+ if ($listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()) {
409
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
410
+ ->getTypeModel()->getProductOptions();
411
+ }
412
+
413
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
414
+ foreach ($productOptions as $attribute => $option) {
415
+ !$option && $option = '--';
416
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
417
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
418
+ }
419
+ $value .= '</div>';
420
+
421
+ return $value;
422
+ }
423
+
424
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
425
+ {
426
+ if (is_null($value) || $value === '') {
427
+ $value = Mage::helper('M2ePro')->__('N/A');
428
+ }
429
+
430
+ if ($row->getData('defected_messages')) {
431
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
432
+
433
+ $msg = '';
434
+ foreach ($defectedMessages as $message) {
435
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
436
+ if (!empty($message['value'])) {
437
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
438
+ }
439
+ $msg .= '</p>';
440
+ }
441
+
442
+ $value .= <<<HTML
443
+ <span style="float:right;">
444
+ <img id="map_link_defected_message_icon_{$row->getId()}"
445
+ class="tool-tip-image"
446
+ style="vertical-align: middle;"
447
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
448
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
449
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
450
+ <span>{$msg}</span>
451
+ </span>
452
+ </span>
453
+ HTML;
454
+ }
455
+
456
+ return $value;
457
+ }
458
+
459
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
460
+ {
461
+ if (is_null($value) || $value === '') {
462
+ return Mage::helper('M2ePro')->__('N/A');
463
+ }
464
+
465
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
466
+
467
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
468
+ $value,
469
+ $marketplaceId
470
+ );
471
+
472
+ $parentAsinHtml = '';
473
+ $variationParentId = $row->getData('variation_parent_id');
474
+ if(!empty($variationParentId)){
475
+ $parentAsinHtml = '<br/><span style="display: block;
476
+ margin-bottom: 5px;
477
+ font-size: 10px;
478
+ color: grey;">'.
479
+ Mage::helper('M2ePro')->__('child ASIN/ISBN<br/>of parent %parent_asin%',
480
+ $this->getParentAsin($row->getData('id'))) . '</span>';
481
+ }
482
+
483
+ $generalIdOwnerHtml = '';
484
+ if($row->getData('is_general_id_owner') == 1){
485
+ $generalIdOwnerHtml = '<span style="font-size: 10px; color: grey; display: block;">'.
486
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
487
+ '</span>';
488
+ }
489
+ return <<<HTML
490
+ <a href="{$url}" target="_blank">{$value}</a>{$parentAsinHtml}{$generalIdOwnerHtml}
491
+ HTML;
492
+ }
493
+
494
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
495
+ {
496
+ if ((int)$row->getData('is_in_stock') <= 0) {
497
+ return '<span style="color: red;">'.$value.'</span>';
498
+ }
499
+
500
+ return $value;
501
+ }
502
+
503
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
504
+ {
505
+ if ((bool)$row->getData('is_afn_channel')) {
506
+ return Mage::helper('M2ePro')->__('N/A');
507
+ }
508
+
509
+ if ((int)$row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
510
+ if (is_null($value) || $value === '') {
511
+ return Mage::helper('M2ePro')->__('N/A');
512
+ }
513
+ } else {
514
+ if (is_null($value) || $value === '') {
515
+ return '<i style="color:gray;">receiving...</i>';
516
+ }
517
+ }
518
+
519
+ if ($value <= 0) {
520
+ return '<span style="color: red;">0</span>';
521
+ }
522
+
523
+ return $value;
524
+ }
525
+
526
+ public function callbackColumnPrice($value, $row, $column, $isExport)
527
+ {
528
+ $onlinePrice = $row->getData('online_price');
529
+
530
+ if (is_null($onlinePrice) || $onlinePrice === '') {
531
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
532
+ return Mage::helper('M2ePro')->__('N/A');
533
+ } else {
534
+ return '<i style="color:gray;">receiving...</i>';
535
+ }
536
+ }
537
+
538
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
539
+ $currency = Mage::helper('M2ePro/Component_Amazon')
540
+ ->getCachedObject('Marketplace',$marketplaceId)
541
+ ->getChildObject()
542
+ ->getDefaultCurrency();
543
+
544
+ if ((float)$onlinePrice <= 0) {
545
+ $priceValue = '<span style="color: #f00;">0</span>';
546
+ } else {
547
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
548
+ }
549
+
550
+ $resultHtml = '';
551
+
552
+ $salePrice = $row->getData('online_sale_price');
553
+ if ((float)$salePrice > 0) {
554
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
555
+
556
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
557
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
558
+
559
+ if ($currentTimestamp <= $endDateTimestamp) {
560
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
561
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
562
+
563
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
564
+
565
+ $fromDate = Mage::app()->getLocale()->date(
566
+ $row->getData('online_sale_price_start_date'), $dateFormat
567
+ )->toString($dateFormat);
568
+ $toDate = Mage::app()->getLocale()->date(
569
+ $row->getData('online_sale_price_end_date'), $dateFormat
570
+ )->toString($dateFormat);
571
+
572
+ $intervalHtml = '<img class="tool-tip-image"
573
+ style="vertical-align: middle;"
574
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
575
+ text-align: left;
576
+ width: 120px;
577
+ background: #E3E3E3;">
578
+ <img src="'.$iconHelpPath.'">
579
+ <span style="color:gray;">
580
+ <strong>From:</strong> '.$fromDate.'<br/>
581
+ <strong>To:</strong> '.$toDate.'
582
+ </span>
583
+ </span>';
584
+
585
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
586
+
587
+ if ($currentTimestamp >= $startDateTimestamp &&
588
+ $currentTimestamp <= $endDateTimestamp &&
589
+ $salePrice < (float)$onlinePrice
590
+ ) {
591
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
592
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
593
+ } else {
594
+ $resultHtml .= $priceValue;
595
+ $resultHtml .= '<br/>'.$intervalHtml.
596
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
597
+ }
598
+ }
599
+ }
600
+
601
+ if (empty($resultHtml)) {
602
+ $resultHtml = $priceValue;
603
+ }
604
+
605
+ return $resultHtml;
606
+ }
607
+
608
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
609
+ {
610
+ if (is_null($value) || $value === '') {
611
+ return Mage::helper('M2ePro')->__('N/A');
612
+ }
613
+
614
+ return $value;
615
+ }
616
+
617
+ public function callbackColumnStatus($value, $row, $column, $isExport)
618
+ {
619
+ switch ($row->getData('amazon_status')) {
620
+
621
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
622
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
623
+ $value = '<span style="color: gray;">' . $value . '</span>';
624
+ break;
625
+
626
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
627
+ $value = '<span style="color: green;">' . $value . '</span>';
628
+ break;
629
+
630
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
631
+ $value = '<span style="color: red;">'.$value.'</span>';
632
+ break;
633
+
634
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
635
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
636
+ break;
637
+
638
+ default:
639
+ break;
640
+ }
641
+
642
+ $value .= $this->getViewLogIconHtml($row->getData('id'));
643
+
644
+ $tempLocks = $this->getLockedData($row);
645
+ $tempLocks = $tempLocks['object_locks'];
646
+
647
+ foreach ($tempLocks as $lock) {
648
+
649
+ switch ($lock->getTag()) {
650
+
651
+ case 'list_action':
652
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
653
+ break;
654
+
655
+ case 'relist_action':
656
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
657
+ break;
658
+
659
+ case 'revise_action':
660
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
661
+ break;
662
+
663
+ case 'stop_action':
664
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
665
+ break;
666
+
667
+ case 'stop_and_remove_action':
668
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
669
+ break;
670
+
671
+ case 'delete_and_remove_action':
672
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
673
+ break;
674
+
675
+ default:
676
+ break;
677
+
678
+ }
679
+ }
680
+
681
+ return $value;
682
+ }
683
+
684
+ protected function callbackFilterTitle($collection, $column)
685
+ {
686
+ $value = $column->getFilter()->getValue();
687
+
688
+ if ($value == null) {
689
+ return;
690
+ }
691
+
692
+ $collection->addFieldToFilter(
693
+ array(
694
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
695
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
696
+ )
697
+ );
698
+ }
699
+
700
+ protected function callbackFilterPrice($collection, $column)
701
+ {
702
+ $value = $column->getFilter()->getValue();
703
+
704
+ if (empty($value)) {
705
+ return;
706
+ }
707
+
708
+ $condition = '';
709
+
710
+ if (isset($value['from']) && $value['from'] != '') {
711
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
712
+ }
713
+ if (isset($value['to']) && $value['to'] != '') {
714
+ if (isset($value['from']) && $value['from'] != '') {
715
+ $condition .= ' AND ';
716
+ }
717
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
718
+ }
719
+
720
+ $collection->getSelect()->having($condition);
721
+ }
722
+
723
+ //----------------------------------------
724
+
725
+ public function getViewLogIconHtml($listingProductId)
726
+ {
727
+ $listingProductId = (int)$listingProductId;
728
+
729
+ // Get last messages
730
+ //--------------------------
731
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
732
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
733
+
734
+ $dbSelect = $connRead->select()
735
+ ->from(
736
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
737
+ array('action_id','action','type','description','create_date','initiator')
738
+ )
739
+ ->where('`listing_product_id` = ?',$listingProductId)
740
+ ->where('`action_id` IS NOT NULL')
741
+ ->order(array('id DESC'))
742
+ ->limit(30);
743
+
744
+ $logRows = $connRead->fetchAll($dbSelect);
745
+ //--------------------------
746
+
747
+ // Get grouped messages by action_id
748
+ //--------------------------
749
+ $actionsRows = array();
750
+ $tempActionRows = array();
751
+ $lastActionId = false;
752
+
753
+ foreach ($logRows as $row) {
754
+
755
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
756
+
757
+ if ($row['action_id'] !== $lastActionId) {
758
+ if (count($tempActionRows) > 0) {
759
+ $actionsRows[] = array(
760
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
761
+ 'date' => $this->getMainDateForActionId($tempActionRows),
762
+ 'action' => $this->getActionForAction($tempActionRows[0]),
763
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
764
+ 'items' => $tempActionRows
765
+ );
766
+ $tempActionRows = array();
767
+ }
768
+ $lastActionId = $row['action_id'];
769
+ }
770
+ $tempActionRows[] = $row;
771
+ }
772
+
773
+ if (count($tempActionRows) > 0) {
774
+ $actionsRows[] = array(
775
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
776
+ 'date' => $this->getMainDateForActionId($tempActionRows),
777
+ 'action' => $this->getActionForAction($tempActionRows[0]),
778
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
779
+ 'items' => $tempActionRows
780
+ );
781
+ }
782
+
783
+ if (count($actionsRows) <= 0) {
784
+ return '';
785
+ }
786
+
787
+ foreach ($actionsRows as &$actionsRow) {
788
+ usort($actionsRow['items'], function($a, $b)
789
+ {
790
+ $sortOrder = array(
791
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
792
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
793
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
794
+ );
795
+
796
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
797
+ });
798
+ }
799
+
800
+ $tips = array(
801
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
802
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
803
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
804
+ );
805
+
806
+ $icons = array(
807
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
808
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
809
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
810
+ );
811
+
812
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
813
+ 'entity_id' => $listingProductId,
814
+ 'rows' => $actionsRows,
815
+ 'tips' => $tips,
816
+ 'icons' => $icons,
817
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
818
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
819
+ ));
820
+
821
+ return $summary->toHtml();
822
+ }
823
+
824
+ public function getActionForAction($actionRows)
825
+ {
826
+ $string = '';
827
+
828
+ switch ($actionRows['action']) {
829
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
830
+ $string = Mage::helper('M2ePro')->__('List');
831
+ break;
832
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
833
+ $string = Mage::helper('M2ePro')->__('Relist');
834
+ break;
835
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
836
+ $string = Mage::helper('M2ePro')->__('Revise');
837
+ break;
838
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
839
+ $string = Mage::helper('M2ePro')->__('Stop');
840
+ break;
841
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
842
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
843
+ break;
844
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
845
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
846
+ break;
847
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
848
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
849
+ break;
850
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
851
+ $string = Mage::helper('M2ePro')->__('Channel Change');
852
+ break;
853
+ }
854
+
855
+ return $string;
856
+ }
857
+
858
+ public function getInitiatorForAction($actionRows)
859
+ {
860
+ $string = '';
861
+
862
+ switch ((int)$actionRows['initiator']) {
863
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
864
+ $string = '';
865
+ break;
866
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
867
+ $string = Mage::helper('M2ePro')->__('Manual');
868
+ break;
869
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
870
+ $string = Mage::helper('M2ePro')->__('Automatic');
871
+ break;
872
+ }
873
+
874
+ return $string;
875
+ }
876
+
877
+ public function getMainTypeForActionId($actionRows)
878
+ {
879
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
880
+
881
+ foreach ($actionRows as $row) {
882
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
883
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
884
+ break;
885
+ }
886
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
887
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
888
+ }
889
+ }
890
+
891
+ return $type;
892
+ }
893
+
894
+ public function getMainDateForActionId($actionRows)
895
+ {
896
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
897
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
898
+ }
899
+
900
+ // ####################################
901
+
902
+ public function getGridUrl()
903
+ {
904
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
905
+ }
906
+
907
+ public function getRowUrl($row)
908
+ {
909
+ return false;
910
+ }
911
+
912
+ // ####################################
913
+
914
+ protected function _toHtml()
915
+ {
916
+ $javascriptsMain = <<<JAVASCRIPT
917
+ <script type="text/javascript">
918
+
919
+ if (typeof ListingGridHandlerObj != 'undefined') {
920
+ ListingGridHandlerObj.afterInitPage();
921
+ }
922
+
923
+ Event.observe(window, 'load', function() {
924
+ setTimeout(function() {
925
+ ListingGridHandlerObj.afterInitPage();
926
+ }, 350);
927
+ });
928
+
929
+ </script>
930
+ JAVASCRIPT;
931
+
932
+ return parent::_toHtml().$javascriptsMain;
933
+ }
934
+
935
+ public function getEmptyText()
936
+ {
937
+ return Mage::helper('M2ePro')->__(
938
+ 'Only Simple and Child Products listed on Amazon will be shown in Seller Сentral View Mode.'
939
+ );
940
+ }
941
+
942
+ // ####################################
943
+
944
+ private function getLockedData($row)
945
+ {
946
+ $listingProductId = $row->getData('id');
947
+ if (!isset($this->lockedDataCache[$listingProductId])) {
948
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
949
+ $tempArray = array(
950
+ 'object_locks' => $objectLocks,
951
+ 'in_action' => !empty($objectLocks),
952
+ );
953
+ $this->lockedDataCache[$listingProductId] = $tempArray;
954
+ }
955
+
956
+ return $this->lockedDataCache[$listingProductId];
957
+ }
958
+
959
+ // ####################################
960
+
961
+ private function getParentAsin($childId)
962
+ {
963
+ if (is_null($this->parentAsins)) {
964
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
965
+ $tableAmazonListingProduct = Mage::getSingleton('core/resource')
966
+ ->getTableName('m2epro_amazon_listing_product');
967
+
968
+ $select = $connRead->select();
969
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id','variation_parent_id'))
970
+ ->where('listing_product_id IN (?)', $this->getCollection()->getAllIds())
971
+ ->where('variation_parent_id IS NOT NULL');
972
+
973
+ $parentIds = Mage::getResourceModel('core/config')
974
+ ->getReadConnection()
975
+ ->fetchPairs($select);
976
+
977
+ $select = $connRead->select();
978
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id', 'general_id'))
979
+ ->where('listing_product_id IN (?)', $parentIds);
980
+
981
+ $parentAsins = Mage::getResourceModel('core/config')
982
+ ->getReadConnection()
983
+ ->fetchPairs($select);
984
+
985
+ $this->parentAsins = array();
986
+ foreach ($parentIds as $childId => $parentId) {
987
+ $this->parentAsins[$childId] = $parentAsins[$parentId];
988
+ }
989
+ }
990
+
991
+ return $this->parentAsins[$childId];
992
+ }
993
+
994
+ // ####################################
995
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Settings/Grid.php ADDED
@@ -0,0 +1,518 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Settings_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('amazonListingViewSettingsGrid'.$listingData['id']);
21
+ //------------------------------
22
+
23
+ $this->showAdvancedFilterProductsOption = false;
24
+ }
25
+
26
+ // ####################################
27
+
28
+ public function getMainButtonsHtml()
29
+ {
30
+ $data = array(
31
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
32
+ );
33
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
34
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
35
+ );
36
+ $viewModeSwitcherBlock->addData($data);
37
+
38
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
39
+ }
40
+
41
+ // ####################################
42
+
43
+ protected function _prepareCollection()
44
+ {
45
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
46
+
47
+ // Get collection
48
+ //----------------------------
49
+ /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
50
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
51
+ Mage::getModel('catalog/product')->getResource());
52
+ $collection->setListingProductModeOn();
53
+ $collection
54
+ ->addAttributeToSelect('name')
55
+ ->addAttributeToSelect('sku')
56
+ ->joinTable(
57
+ array('cisi' => 'cataloginventory/stock_item'),
58
+ 'product_id=entity_id',
59
+ array('qty' => 'qty'),
60
+ '{{table}}.stock_id=1',
61
+ 'left'
62
+ );
63
+
64
+ //----------------------------
65
+
66
+ $collection->joinTable(
67
+ array('lp' => 'M2ePro/Listing_Product'),
68
+ 'product_id=entity_id',
69
+ array(
70
+ 'id' => 'id',
71
+ 'component_mode' => 'component_mode',
72
+ 'amazon_status' => 'status',
73
+ 'additional_data' => 'additional_data'
74
+ ),
75
+ array(
76
+ 'listing_id' => (int)$listingData['id']
77
+ )
78
+ );
79
+ $collection->joinTable(
80
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
81
+ 'listing_product_id=id',
82
+ array(
83
+ 'template_description_id' => 'template_description_id',
84
+ 'general_id' => 'general_id',
85
+ 'general_id_search_info' => 'general_id_search_info',
86
+ 'search_settings_status' => 'search_settings_status',
87
+ 'search_settings_data' => 'search_settings_data',
88
+ 'variation_child_statuses' => 'variation_child_statuses',
89
+ 'amazon_sku' => 'sku',
90
+ 'online_qty' => 'online_qty',
91
+ 'online_price' => 'online_price',
92
+ 'online_sale_price' => 'IF(
93
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
94
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
95
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
96
+ `alp`.`online_sale_price`,
97
+ NULL
98
+ )',
99
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
100
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
101
+ 'is_afn_channel' => 'is_afn_channel',
102
+ 'is_general_id_owner' => 'is_general_id_owner',
103
+ 'is_variation_parent' => 'is_variation_parent',
104
+ 'defected_messages' => 'defected_messages',
105
+ 'min_online_price' => 'IF(
106
+ (`t`.`variation_min_price` IS NULL),
107
+ IF(
108
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
109
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
110
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
111
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
112
+ `alp`.`online_sale_price`,
113
+ `alp`.`online_price`
114
+ ),
115
+ `t`.`variation_min_price`
116
+ )',
117
+ 'max_online_price' => 'IF(
118
+ (`t`.`variation_max_price` IS NULL),
119
+ IF(
120
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
121
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
122
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
123
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
124
+ `alp`.`online_sale_price`,
125
+ `alp`.`online_price`
126
+ ),
127
+ `t`.`variation_max_price`
128
+ )'
129
+ ),
130
+ '{{table}}.variation_parent_id is NULL'
131
+ );
132
+
133
+ $collection->getSelect()->joinLeft(
134
+ new Zend_Db_Expr('(
135
+ SELECT
136
+ `malp`.`variation_parent_id`,
137
+ MIN(
138
+ IF(
139
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
140
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
141
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
142
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
143
+ `malp`.`online_sale_price`,
144
+ `malp`.`online_price`
145
+ )
146
+ ) as variation_min_price,
147
+ MAX(
148
+ IF(
149
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
150
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
151
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
152
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
153
+ `malp`.`online_sale_price`,
154
+ `malp`.`online_price`
155
+ )
156
+ ) as variation_max_price
157
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
158
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
159
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
160
+ WHERE `mlp`.`status` IN (
161
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
162
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
163
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
164
+ GROUP BY `malp`.`variation_parent_id`
165
+ )'),
166
+ 'alp.listing_product_id=t.variation_parent_id',
167
+ array(
168
+ 'variation_min_price' => 'variation_min_price',
169
+ 'variation_max_price' => 'variation_max_price',
170
+ )
171
+ );
172
+ $collection->joinTable(
173
+ array('td' => 'M2ePro/Template_Description'),
174
+ 'id=template_description_id',
175
+ array(
176
+ 'template_description_title' => 'title'
177
+ ),
178
+ null,
179
+ 'left'
180
+ );
181
+
182
+ //----------------------------
183
+ // exit($collection->getSelect()->__toString());
184
+
185
+ // Set collection to grid
186
+ $this->setCollection($collection);
187
+
188
+ return parent::_prepareCollection();
189
+ }
190
+
191
+ protected function _prepareColumns()
192
+ {
193
+ $this->addColumn('product_id', array(
194
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
195
+ 'align' => 'right',
196
+ 'width' => '100px',
197
+ 'type' => 'number',
198
+ 'index' => 'entity_id',
199
+ 'filter_index' => 'entity_id',
200
+ 'frame_callback' => array($this, 'callbackColumnProductId')
201
+ ));
202
+
203
+ $this->addColumn('name', array(
204
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
205
+ 'align' => 'left',
206
+ //'width' => '300px',
207
+ 'type' => 'text',
208
+ 'index' => 'name',
209
+ 'filter_index' => 'name',
210
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
211
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
212
+ ));
213
+
214
+ $this->addColumn('sku', array(
215
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
216
+ 'align' => 'left',
217
+ 'width' => '150px',
218
+ 'type' => 'text',
219
+ 'index' => 'amazon_sku',
220
+ 'filter_index' => 'amazon_sku',
221
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
222
+ ));
223
+
224
+ $this->addColumn('description_template', array(
225
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
226
+ 'align' => 'left',
227
+ 'width' => '150px',
228
+ 'type' => 'text',
229
+ 'index' => 'template_description_title',
230
+ 'filter_index' => 'template_description_title',
231
+ 'frame_callback' => array($this, 'callbackColumnTemplateDescription')
232
+ ));
233
+
234
+ $this->addColumn('actions', array(
235
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
236
+ 'align' => 'left',
237
+ 'width' => '100px',
238
+ 'type' => 'action',
239
+ 'index' => 'actions',
240
+ 'filter' => false,
241
+ 'sortable' => false,
242
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
243
+ 'field' => 'id',
244
+ 'group_order' => $this->getGroupOrder(),
245
+ 'actions' => $this->getColumnActionsItems()
246
+ ));
247
+
248
+ return parent::_prepareColumns();
249
+ }
250
+
251
+ // ####################################
252
+
253
+ protected function getGroupOrder()
254
+ {
255
+ return array(
256
+ 'edit_template_description' => Mage::helper('M2ePro')->__('Description Policy')
257
+ );
258
+ }
259
+
260
+ protected function getColumnActionsItems()
261
+ {
262
+ $helper = Mage::helper('M2ePro');
263
+
264
+ $actions = array(
265
+ 'assignTemplateDescription' => array(
266
+ 'caption' => $helper->__('Assign'),
267
+ 'group' => 'edit_template_description',
268
+ 'field' => 'id',
269
+ 'onclick_action' => 'ListingGridHandlerObj.actions[\'assignTemplateDescriptionIdAction\']'
270
+ ),
271
+
272
+ 'unassignTemplateDescription' => array(
273
+ 'caption' => $helper->__('Unassign'),
274
+ 'group' => 'edit_template_description',
275
+ 'field' => 'id',
276
+ 'onclick_action' => 'ListingGridHandlerObj.actions[\'unassignTemplateDescriptionIdAction\']'
277
+ ),
278
+ );
279
+
280
+ return $actions;
281
+ }
282
+
283
+ // ####################################
284
+
285
+ protected function _prepareMassaction()
286
+ {
287
+ // Set massaction identifiers
288
+ //--------------------------------
289
+ $this->setMassactionIdField('id');
290
+ $this->setMassactionIdFieldOnlyIndexValue(true);
291
+ //--------------------------------
292
+
293
+ // Set mass-action
294
+ //--------------------------------
295
+ $groups = array(
296
+ 'description_policy' => Mage::helper('M2ePro')->__('Description Policy'),
297
+ 'other' => Mage::helper('M2ePro')->__('Other'),
298
+ );
299
+
300
+ $this->getMassactionBlock()->setGroups($groups);
301
+
302
+ $this->getMassactionBlock()->addItem('assignTemplateDescriptionId', array(
303
+ 'label' => Mage::helper('M2ePro')->__('Assign'),
304
+ 'url' => '',
305
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
306
+ ), 'description_policy');
307
+
308
+ $this->getMassactionBlock()->addItem('unassignTemplateDescriptionId', array(
309
+ 'label' => Mage::helper('M2ePro')->__('Unassign'),
310
+ 'url' => '',
311
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
312
+ ), 'description_policy');
313
+
314
+ $this->getMassactionBlock()->addItem('moving', array(
315
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Another Listing'),
316
+ 'url' => '',
317
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
318
+ ), 'other');
319
+
320
+ $this->getMassactionBlock()->addItem('duplicate', array(
321
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
322
+ 'url' => '',
323
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
324
+ ), 'other');
325
+ //--------------------------------
326
+
327
+ return parent::_prepareMassaction();
328
+ }
329
+
330
+ // ####################################
331
+
332
+ public function callbackColumnProductId($value, $row, $column, $isExport)
333
+ {
334
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
335
+
336
+ $storeId = (int)$listingData['store_id'];
337
+
338
+ $withoutImageHtml = '<a href="'
339
+ .$this->getUrl('adminhtml/catalog_product/edit',
340
+ array('id' => $value))
341
+ .'" target="_blank">'.$value.'</a>';
342
+
343
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
344
+ ->getGroupValue('/view/',
345
+ 'show_products_thumbnails');
346
+ if (!$showProductsThumbnails) {
347
+ return $withoutImageHtml;
348
+ }
349
+
350
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
351
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
352
+ $magentoProduct->setProductId($value);
353
+ $magentoProduct->setStoreId($storeId);
354
+
355
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
356
+ if (is_null($imageUrlResized)) {
357
+ return $withoutImageHtml;
358
+ }
359
+
360
+ $imageHtml = $value.'<hr style="border: 1px solid silver; border-bottom: none;"><img src="'.
361
+ $imageUrlResized.'" />';
362
+ $withImageHtml = str_replace('>'.$value.'<','>'.$imageHtml.'<',$withoutImageHtml);
363
+
364
+ return $withImageHtml;
365
+ }
366
+
367
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
368
+ {
369
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
370
+
371
+ $value = '<span>'.$productTitle.'</span>';
372
+
373
+ $tempSku = $row->getData('sku');
374
+ is_null($tempSku)
375
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
376
+
377
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
378
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
379
+
380
+ $listingProductId = (int)$row->getData('id');
381
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
382
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
383
+
384
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
385
+ return $value;
386
+ }
387
+
388
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
389
+ $amazonListingProduct = $listingProduct->getChildObject();
390
+ $variationManager = $amazonListingProduct->getVariationManager();
391
+
392
+ if ($variationManager->isRelationParentType()) {
393
+
394
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
395
+
396
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
397
+ $value .= implode(', ', $productAttributes);
398
+ $value .= '</div>';
399
+
400
+ return $value;
401
+ }
402
+
403
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
404
+
405
+ if (!empty($productOptions)) {
406
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
407
+ foreach ($productOptions as $attribute => $option) {
408
+ !$option && $option = '--';
409
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
410
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
411
+ }
412
+ $value .= '</div>';
413
+ }
414
+
415
+ return $value;
416
+ }
417
+
418
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
419
+ {
420
+ if ((!$row->getData('is_variation_parent') &&
421
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
422
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
423
+
424
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
425
+ }
426
+
427
+ if (is_null($value) || $value === '') {
428
+ $value = Mage::helper('M2ePro')->__('N/A');
429
+ }
430
+
431
+ return $value;
432
+ }
433
+
434
+ public function callbackColumnTemplateDescription($value, $row, $column, $isExport)
435
+ {
436
+ $html = Mage::helper('M2ePro')->__('N/A');
437
+
438
+ $listingProductId = (int)$row->getData('id');
439
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
440
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
441
+
442
+ if ($listingProduct->getChildObject()->isExistDescriptionTemplate()) {
443
+ $html = $this->getTemplateDescriptionLinkHtml($listingProduct);
444
+ }
445
+
446
+ return $html;
447
+ }
448
+ // ####################################
449
+
450
+ protected function callbackFilterTitle($collection, $column)
451
+ {
452
+ $value = $column->getFilter()->getValue();
453
+
454
+ if ($value == null) {
455
+ return;
456
+ }
457
+
458
+ $collection->addFieldToFilter(
459
+ array(
460
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
461
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
462
+ )
463
+ );
464
+ }
465
+
466
+ // ####################################
467
+
468
+ public function getGridUrl()
469
+ {
470
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
471
+ }
472
+
473
+ public function getRowUrl($row)
474
+ {
475
+ return false;
476
+ }
477
+
478
+ // ####################################
479
+
480
+ protected function _toHtml()
481
+ {
482
+ $javascriptsMain = <<<JAVASCRIPT
483
+ <script type="text/javascript">
484
+
485
+ if (typeof ListingGridHandlerObj != 'undefined') {
486
+ ListingGridHandlerObj.afterInitPage();
487
+ }
488
+
489
+ Event.observe(window, 'load', function() {
490
+ setTimeout(function() {
491
+ ListingGridHandlerObj.afterInitPage();
492
+ }, 350);
493
+ });
494
+
495
+ </script>
496
+ JAVASCRIPT;
497
+
498
+ return parent::_toHtml().$javascriptsMain;
499
+ }
500
+
501
+ // ####################################
502
+
503
+ protected function getTemplateDescriptionLinkHtml($listingProduct)
504
+ {
505
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
506
+ 'id' => $listingProduct->getChildObject()->getTemplateDescriptionId()
507
+ ));
508
+
509
+ $helper = Mage::helper('M2ePro');
510
+ $templateTitle = $listingProduct->getChildObject()->getDescriptionTemplate()->getTitle();
511
+
512
+ return <<<HTML
513
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$helper->escapeHtml($templateTitle)}</a>
514
+ HTML;
515
+ }
516
+
517
+ // ####################################
518
+ }
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,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ public function getHelpPageUrl()
13
+ {
14
+ return Mage::helper('M2ePro/Module_Support')
15
+ ->getDocumentationUrl(NULL, 'pages/viewpage.action?pageId=18189166');
16
+ }
17
+
18
+ // ####################################
19
+ }
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,530 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @copyright Copyright (c) 2013 by ESS-UA.
5
+ */
6
+
7
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_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_LISTED:
329
+ $value = '<span style="color: green;">' . $value . '</span>';
330
+ break;
331
+
332
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
333
+ $value = '<span style="color: red;">' . $value . '</span>';
334
+ break;
335
+
336
+ default:
337
+ break;
338
+ }
339
+
340
+ return $value.$this->getViewLogIconHtml($row->getId());
341
+ }
342
+
343
+ protected function callbackFilterTitle($collection, $column)
344
+ {
345
+ $value = $column->getFilter()->getValue();
346
+
347
+ if ($value == null) {
348
+ return;
349
+ }
350
+
351
+ $collection->getSelect()->where('second_table.title LIKE ? OR second_table.sku LIKE ?', '%'.$value.'%');
352
+ }
353
+
354
+ // ####################################
355
+
356
+ public function getViewLogIconHtml($listingOtherId)
357
+ {
358
+ $listingOtherId = (int)$listingOtherId;
359
+
360
+ // Get last messages
361
+ //--------------------------
362
+ $dbSelect = $this->connRead->select()
363
+ ->from(
364
+ Mage::getResourceModel('M2ePro/Listing_Other_Log')->getMainTable(),
365
+ array('action_id','action','type','description','create_date','initiator')
366
+ )
367
+ ->where('`listing_other_id` = ?', $listingOtherId)
368
+ ->where('`action_id` IS NOT NULL')
369
+ ->order(array('id DESC'))
370
+ ->limit(30);
371
+
372
+ $logRows = $this->connRead->fetchAll($dbSelect);
373
+ //--------------------------
374
+
375
+ // Get grouped messages by action_id
376
+ //--------------------------
377
+ $actionsRows = array();
378
+ $tempActionRows = array();
379
+ $lastActionId = false;
380
+
381
+ foreach ($logRows as $row) {
382
+
383
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
384
+
385
+ if ($row['action_id'] !== $lastActionId) {
386
+ if (count($tempActionRows) > 0) {
387
+ $actionsRows[] = array(
388
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
389
+ 'date' => $this->getMainDateForActionId($tempActionRows),
390
+ 'action' => $this->getActionForAction($tempActionRows[0]),
391
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
392
+ 'items' => $tempActionRows
393
+ );
394
+ $tempActionRows = array();
395
+ }
396
+ $lastActionId = $row['action_id'];
397
+ }
398
+ $tempActionRows[] = $row;
399
+ }
400
+
401
+ if (count($tempActionRows) > 0) {
402
+ $actionsRows[] = array(
403
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
404
+ 'date' => $this->getMainDateForActionId($tempActionRows),
405
+ 'action' => $this->getActionForAction($tempActionRows[0]),
406
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
407
+ 'items' => $tempActionRows
408
+ );
409
+ }
410
+
411
+ if (count($actionsRows) <= 0) {
412
+ return '';
413
+ }
414
+
415
+ $tips = array(
416
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
417
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
418
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
419
+ );
420
+
421
+ $icons = array(
422
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
423
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
424
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
425
+ );
426
+
427
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
428
+ 'entity_id' => $listingOtherId,
429
+ 'rows' => $actionsRows,
430
+ 'tips' => $tips,
431
+ 'icons' => $icons,
432
+ 'view_help_handler' => 'BuyListingOtherGridHandlerObj.viewItemHelp',
433
+ 'hide_help_handler' => 'BuyListingOtherGridHandlerObj.hideItemHelp',
434
+ ));
435
+
436
+ return $summary->toHtml();
437
+ }
438
+
439
+ public function getActionForAction($actionRows)
440
+ {
441
+ $string = '';
442
+
443
+ switch ((int)$actionRows['action']) {
444
+ case Ess_M2ePro_Model_Listing_Other_Log::ACTION_CHANNEL_CHANGE:
445
+ $string = Mage::helper('M2ePro')->__('Channel Change');
446
+ break;
447
+ }
448
+
449
+ return $string;
450
+ }
451
+
452
+ public function getInitiatorForAction($actionRows)
453
+ {
454
+ $string = '';
455
+
456
+ switch ($actionRows['initiator']) {
457
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
458
+ $string = '';
459
+ break;
460
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
461
+ $string = Mage::helper('M2ePro')->__('Manual');
462
+ break;
463
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
464
+ $string = Mage::helper('M2ePro')->__('Automatic');
465
+ break;
466
+ }
467
+
468
+ return $string;
469
+ }
470
+
471
+ public function getMainTypeForActionId($actionRows)
472
+ {
473
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
474
+
475
+ foreach ($actionRows as $row) {
476
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
477
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
478
+ break;
479
+ }
480
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
481
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
482
+ }
483
+ }
484
+
485
+ return $type;
486
+ }
487
+
488
+ public function getMainDateForActionId($actionRows)
489
+ {
490
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
491
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
492
+ }
493
+
494
+ // ####################################
495
+
496
+ protected function _toHtml()
497
+ {
498
+ $javascriptsMain = <<<JAVASCRIPT
499
+ <script type="text/javascript">
500
+
501
+ if (typeof BuyListingOtherGridHandlerObj != 'undefined') {
502
+ BuyListingOtherGridHandlerObj.afterInitPage();
503
+ }
504
+
505
+ Event.observe(window, 'load', function() {
506
+ setTimeout(function() {
507
+ BuyListingOtherGridHandlerObj.afterInitPage();
508
+ }, 350);
509
+ });
510
+
511
+ </script>
512
+ JAVASCRIPT;
513
+
514
+ return parent::_toHtml().$javascriptsMain;
515
+ }
516
+
517
+ // ####################################
518
+
519
+ public function getGridUrl()
520
+ {
521
+ return $this->getUrl('*/adminhtml_common_buy_listing_other/grid', array('_current' => true));
522
+ }
523
+
524
+ public function getRowUrl($row)
525
+ {
526
+ return false;
527
+ }
528
+
529
+ // ####################################
530
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product.php ADDED
@@ -0,0 +1,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,614 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'template_new_product_id' => 'second_table.template_new_product_id',
91
+ 'general_id' => 'second_table.general_id',
92
+ 'online_sku' => 'second_table.sku',
93
+ 'online_qty' => 'second_table.online_qty',
94
+ 'online_price' => 'second_table.online_price'
95
+ )
96
+ );
97
+
98
+ //------------------------------
99
+ $listingOtherCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
100
+ $listingOtherCollection->getSelect()->distinct();
101
+
102
+ // add stock availability, type id, status & visibility to select
103
+ //------------------------------
104
+ $listingOtherCollection->getSelect()
105
+ ->joinLeft(
106
+ array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()),
107
+ '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)',
108
+ array('is_in_stock'))
109
+ ->joinLeft(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
110
+ '(cpe.entity_id = `main_table`.product_id)',
111
+ array('magento_sku'=>'sku'));
112
+ //------------------------------
113
+
114
+ $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
115
+ $listingOtherCollection->getSelect()->columns(
116
+ array(
117
+ 'is_m2epro_listing' => new Zend_Db_Expr(0),
118
+ 'magento_sku' => 'cpe.sku',
119
+ 'is_in_stock' => 'cisi.is_in_stock',
120
+ 'product_name' => 'second_table.title',
121
+ 'listing_title' => new Zend_Db_Expr('NULL'),
122
+ 'store_id' => new Zend_Db_Expr(0),
123
+ 'account_id' => 'main_table.account_id',
124
+ 'marketplace_id' => 'main_table.marketplace_id',
125
+ 'listing_product_id' => new Zend_Db_Expr('NULL'),
126
+ 'product_id' => 'main_table.product_id',
127
+ 'listing_id' => new Zend_Db_Expr('NULL'),
128
+ 'status' => 'main_table.status',
129
+ 'template_new_product_id' => new Zend_Db_Expr('NULL'),
130
+ 'general_id' => 'second_table.general_id',
131
+ 'online_sku' => 'second_table.sku',
132
+ 'online_qty' => 'second_table.online_qty',
133
+ 'online_price' => 'second_table.online_price',
134
+ )
135
+ );
136
+ //------------------------------
137
+
138
+ //------------------------------
139
+ $selects = array(
140
+ $listingProductCollection->getSelect(),
141
+ $listingOtherCollection->getSelect()
142
+ );
143
+
144
+ $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
145
+ $unionSelect->union($selects);
146
+
147
+ $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
148
+ $resultCollection->getSelect()->reset()->from(
149
+ array('main_table' => $unionSelect),
150
+ array(
151
+ 'is_m2epro_listing',
152
+ 'magento_sku',
153
+ 'is_in_stock',
154
+ 'product_name',
155
+ 'listing_title',
156
+ 'store_id',
157
+ 'account_id',
158
+ 'marketplace_id',
159
+ 'listing_product_id',
160
+ 'product_id',
161
+ 'listing_id',
162
+ 'status',
163
+ 'template_new_product_id',
164
+ 'general_id',
165
+ 'online_sku',
166
+ 'online_qty',
167
+ 'online_price'
168
+ )
169
+ );
170
+
171
+ // exit($resultCollection->getSelect()->__toString());
172
+
173
+ // Set collection to grid
174
+ $this->setCollection($resultCollection);
175
+
176
+ return parent::_prepareCollection();
177
+ }
178
+
179
+ protected function _prepareColumns()
180
+ {
181
+ $this->addColumn('product_id', array(
182
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
183
+ 'align' => 'right',
184
+ 'width' => '100px',
185
+ 'type' => 'number',
186
+ 'index' => 'product_id',
187
+ 'filter_index' => 'product_id',
188
+ 'frame_callback' => array($this, 'callbackColumnProductId')
189
+ ));
190
+
191
+ $this->addColumn('name', array(
192
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Listing / Product SKU'),
193
+ 'align' => 'left',
194
+ //'width' => '300px',
195
+ 'type' => 'text',
196
+ 'index' => 'product_name',
197
+ 'filter_index' => 'product_name',
198
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
199
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
200
+ ));
201
+
202
+ $this->addColumn('stock_availability',
203
+ array(
204
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
205
+ 'width' => '100px',
206
+ 'index' => 'is_in_stock',
207
+ 'filter_index' => 'is_in_stock',
208
+ 'type' => 'options',
209
+ 'sortable' => false,
210
+ 'options' => array(
211
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
212
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
213
+ ),
214
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
215
+ ));
216
+
217
+ if (Mage::helper('M2ePro/View_Common')->is3rdPartyShouldBeShown(Ess_M2ePro_Helper_Component_Buy::NICK)) {
218
+ $this->addColumn('is_m2epro_listing', array(
219
+ 'header' => Mage::helper('M2ePro')->__('Listing Type'),
220
+ 'align' => 'left',
221
+ 'width' => '100px',
222
+ 'type' => 'options',
223
+ 'sortable' => false,
224
+ 'index' => 'is_m2epro_listing',
225
+ 'options' => array(
226
+ 1 => Mage::helper('M2ePro')->__('M2E Pro'),
227
+ 0 => Mage::helper('M2ePro')->__('3rd Party')
228
+ )
229
+ ));
230
+ }
231
+
232
+ $this->addColumn('sku', array(
233
+ 'header' => Mage::helper('M2ePro')->__('Reference ID'),
234
+ 'align' => 'left',
235
+ 'width' => '150px',
236
+ 'type' => 'text',
237
+ 'index' => 'online_sku',
238
+ 'filter_index' => 'online_sku',
239
+ 'frame_callback' => array($this, 'callbackColumnSku')
240
+ ));
241
+
242
+ $this->addColumn('general_id', array(
243
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
244
+ 'align' => 'left',
245
+ 'width' => '100px',
246
+ 'type' => 'text',
247
+ 'index' => 'general_id',
248
+ 'filter_index' => 'general_id',
249
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
250
+ ));
251
+
252
+ $this->addColumn('online_qty', array(
253
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
254
+ 'align' => 'right',
255
+ 'width' => '70px',
256
+ 'type' => 'number',
257
+ 'index' => 'online_qty',
258
+ 'filter_index' => 'online_qty',
259
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
260
+ ));
261
+
262
+ $this->addColumn('online_price', array(
263
+ 'header' => Mage::helper('M2ePro')->__('Price'),
264
+ 'align' => 'right',
265
+ 'width' => '70px',
266
+ 'type' => 'number',
267
+ 'index' => 'online_price',
268
+ 'filter_index' => 'online_price',
269
+ 'frame_callback' => array($this, 'callbackColumnPrice')
270
+ ));
271
+
272
+ $this->addColumn('status', array(
273
+ 'header' => Mage::helper('M2ePro')->__('Status'),
274
+ 'width' => '125px',
275
+ 'index' => 'status',
276
+ 'filter_index' => 'status',
277
+ 'type' => 'options',
278
+ 'sortable' => false,
279
+ 'options' => array(
280
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
281
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
282
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive')
283
+ ),
284
+ 'frame_callback' => array($this, 'callbackColumnStatus')
285
+ ));
286
+
287
+ $this->addColumn('goto_listing_item', array(
288
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
289
+ 'align' => 'center',
290
+ 'width' => '50px',
291
+ 'type' => 'text',
292
+ 'filter' => false,
293
+ 'sortable' => false,
294
+ 'frame_callback' => array($this, 'callbackColumnActions')
295
+ ));
296
+
297
+ return parent::_prepareColumns();
298
+ }
299
+
300
+ // ####################################
301
+
302
+ public function callbackColumnProductId($value, $row, $column, $isExport)
303
+ {
304
+ if (is_null($row->getData('product_id'))) {
305
+ return Mage::helper('M2ePro')->__('N/A');
306
+ }
307
+
308
+ $productId = (int)$row->getData('product_id');
309
+ $storeId = (int)$row->getData('store_id');
310
+
311
+ $withoutImageHtml = '<a href="'
312
+ .$this->getUrl('adminhtml/catalog_product/edit',
313
+ array('id' => $productId))
314
+ .'" target="_blank">'
315
+ .$productId
316
+ .'</a>';
317
+
318
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
319
+ ->getGroupValue('/view/','show_products_thumbnails');
320
+ if (!$showProductsThumbnails) {
321
+ return $withoutImageHtml;
322
+ }
323
+
324
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
325
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
326
+ $magentoProduct->setProductId($productId);
327
+ $magentoProduct->setStoreId($storeId);
328
+
329
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
330
+ if (is_null($imageUrlResized)) {
331
+ return $withoutImageHtml;
332
+ }
333
+
334
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
335
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
336
+
337
+ return $withImageHtml;
338
+ }
339
+
340
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
341
+ {
342
+ if (is_null($value) || $value === '') {
343
+ $value = '<i style="color:gray;">receiving...</i>';
344
+ } else {
345
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
346
+ }
347
+
348
+ if (!is_null($row->getData('listing_id'))) {
349
+ $urlParams = array();
350
+ $urlParams['id'] = $row->getData('listing_id');
351
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/search');
352
+
353
+ $listingUrl = $this->getUrl('*/adminhtml_common_buy_listing/view',$urlParams);
354
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
355
+
356
+ if (strlen($listingTitle) > 50) {
357
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
358
+ }
359
+
360
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
361
+ $value .= '<strong>'
362
+ .Mage::helper('M2ePro')->__('Listing')
363
+ .': </strong> <a href="'
364
+ .$listingUrl
365
+ .'">'
366
+ .$listingTitle
367
+ .'</a>';
368
+ }
369
+
370
+ if (!is_null($row->getData('magento_sku'))) {
371
+ $tempSku = $row->getData('magento_sku');
372
+
373
+ $value .= '<br/><strong>'
374
+ . Mage::helper('M2ePro')->__('SKU')
375
+ . ':</strong> '
376
+ . Mage::helper('M2ePro')->escapeHtml($tempSku);
377
+ }
378
+
379
+ if (is_null($row->getData('listing_product_id'))) {
380
+ return $value;
381
+ }
382
+
383
+ $listingProductId = (int)$row->getData('listing_product_id');
384
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
385
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
386
+
387
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationProduct() &&
388
+ $listingProduct->getChildObject()->getVariationManager()->isVariationProductMatched()
389
+ ) {
390
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()->getProductOptions();
391
+
392
+ $value .= '<br/>';
393
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
394
+ foreach ($productOptions as $attribute => $option) {
395
+ !$option && $option = '--';
396
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
397
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
398
+ }
399
+ $value .= '</div>';
400
+ $value .= '<br/>';
401
+ }
402
+
403
+ return $value;
404
+ }
405
+
406
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
407
+ {
408
+ if (is_null($row->getData('is_in_stock'))) {
409
+ return Mage::helper('M2ePro')->__('N/A');
410
+ }
411
+
412
+ if ((int)$row->getData('is_in_stock') <= 0) {
413
+ return '<span style="color: red;">'.$value.'</span>';
414
+ }
415
+
416
+ return $value;
417
+ }
418
+
419
+ public function callbackColumnSku($value, $row, $column, $isExport)
420
+ {
421
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
422
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
423
+ }
424
+
425
+ if (is_null($value) || $value === '') {
426
+ return Mage::helper('M2ePro')->__('N/A');
427
+ }
428
+ return $value;
429
+ }
430
+
431
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
432
+ {
433
+ if (empty($value)) {
434
+
435
+ if ($row->getData('status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
436
+ return '<i style="color:gray;">receiving...</i>';
437
+ }
438
+
439
+ if ($row->getData('template_new_product_id')) {
440
+ return Mage::helper('M2ePro')->__('New SKU');
441
+ }
442
+
443
+ return Mage::helper('M2ePro')->__('N/A');
444
+ }
445
+
446
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
447
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
448
+ }
449
+
450
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
451
+ {
452
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
453
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
454
+ }
455
+
456
+ if (is_null($value) || $value === '') {
457
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
458
+ }
459
+
460
+ if ($value <= 0) {
461
+ return '<span style="color: red;">0</span>';
462
+ }
463
+
464
+ return $value;
465
+ }
466
+
467
+ public function callbackColumnPrice($value, $row, $column, $isExport)
468
+ {
469
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
470
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
471
+ }
472
+
473
+ if (is_null($value) || $value === '') {
474
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
475
+ }
476
+
477
+ if ((float)$value <= 0) {
478
+ return '<span style="color: #f00;">0</span>';
479
+ }
480
+
481
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
482
+ }
483
+
484
+ public function callbackColumnStatus($value, $row, $column, $isExport)
485
+ {
486
+ switch ($row->getData('status')) {
487
+
488
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
489
+ $value = '<span style="color: gray;">' . $value . '</span>';
490
+ break;
491
+
492
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
493
+ $value = '<span style="color: green;">' . $value . '</span>';
494
+ break;
495
+
496
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
497
+ $value = '<span style="color: red;">'.$value.'</span>';
498
+ break;
499
+
500
+ default:
501
+ break;
502
+ }
503
+
504
+ if (is_null($row->getData('listing_product_id'))) {
505
+ return $value;
506
+ }
507
+
508
+ $listingProductId = (int)$row->getData('listing_product_id');
509
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
510
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
511
+
512
+ $tempLocks = $listingProduct->getObjectLocks();
513
+
514
+ foreach ($tempLocks as $lock) {
515
+
516
+ switch ($lock->getTag()) {
517
+
518
+ case 'new_sku_action':
519
+ $title = Mage::helper('M2ePro')->__('Add New SKU in Progress...');
520
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
521
+ break;
522
+
523
+ case 'list_action':
524
+ $title = Mage::helper('M2ePro')->__('List in Progress...');
525
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
526
+ break;
527
+
528
+ case 'relist_action':
529
+ $title = Mage::helper('M2ePro')->__('Relist in Progress...');
530
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
531
+ break;
532
+
533
+ case 'revise_action':
534
+ $title = Mage::helper('M2ePro')->__('Revise in Progress...');
535
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
536
+ break;
537
+
538
+ case 'stop_action':
539
+ $title = Mage::helper('M2ePro')->__('Stop in Progress...');
540
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
541
+ break;
542
+
543
+ case 'stop_and_remove_action':
544
+ $title = Mage::helper('M2ePro')->__('Stop And Remove in Progress...');
545
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
546
+ break;
547
+
548
+ default:
549
+ break;
550
+
551
+ }
552
+ }
553
+
554
+ return $value;
555
+ }
556
+
557
+ public function callbackColumnActions($value, $row, $column, $isExport)
558
+ {
559
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to Listing'));
560
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
561
+
562
+ if ($row->getData('is_m2epro_listing')) {
563
+ $url = $this->getUrl('*/adminhtml_common_buy_listing/view/', array(
564
+ 'id'=>$row->getData('listing_id'),
565
+ 'filter'=>base64_encode(
566
+ 'product_id[from]='.(int)$row->getData('product_id')
567
+ .'&product_id[to]='.(int)$row->getData('product_id')
568
+ )
569
+ ));
570
+ } else {
571
+ $url = $this->getUrl('*/adminhtml_common_buy_listing_other/view/', array(
572
+ 'account' => $row->getData('account_id'),
573
+ 'marketplace' => $row->getData('marketplace_id'),
574
+ 'filter' => base64_encode(
575
+ 'title='.$row->getData('online_sku')
576
+ )
577
+ ));
578
+ }
579
+
580
+ $html = <<<HTML
581
+ <div style="float:right; margin:5px 15px 0 0;">
582
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" /></a>
583
+ </div>
584
+ HTML;
585
+
586
+ return $html;
587
+ }
588
+
589
+ protected function callbackFilterTitle($collection, $column)
590
+ {
591
+ $value = $column->getFilter()->getValue();
592
+
593
+ if ($value == null) {
594
+ return;
595
+ }
596
+
597
+ $collection->getSelect()
598
+ ->where('product_name LIKE ? OR magento_sku LIKE ? OR listing_title LIKE ?', '%'.$value.'%');
599
+ }
600
+
601
+ // ####################################
602
+
603
+ public function getGridUrl()
604
+ {
605
+ return $this->getUrl('*/adminhtml_common_buy_listing/searchGrid', array('_current'=>true));
606
+ }
607
+
608
+ public function getRowUrl($row)
609
+ {
610
+ return false;
611
+ }
612
+
613
+ // ####################################
614
+ }
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 ($row->getData('buy_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
398
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
399
+ }
400
+
401
+ if (is_null($value) || $value === '') {
402
+ return Mage::helper('M2ePro')->__('N/A');
403
+ }
404
+ return $value;
405
+ }
406
+
407
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
408
+ {
409
+ if (empty($generalId)) {
410
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
411
+ }
412
+
413
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
414
+ }
415
+
416
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
417
+ {
418
+ if ($row->getData('buy_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
419
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
420
+ }
421
+
422
+ if (is_null($value) || $value === '') {
423
+ return '<i style="color:gray;">receiving...</i>';
424
+ }
425
+
426
+ if ($value <= 0) {
427
+ return '<span style="color: red;">0</span>';
428
+ }
429
+
430
+ return $value;
431
+ }
432
+
433
+ public function callbackColumnPrice($value, $row, $column, $isExport)
434
+ {
435
+ if ($row->getData('buy_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
436
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
437
+ }
438
+
439
+ if (is_null($value) || $value === '') {
440
+ return '<i style="color:gray;">receiving...</i>';
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
+