m2epro_ebay_magento - Version 6.3.9

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


Code changes from version 1.0.3 to 6.3.9

Files changed (152) hide show
  1. app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Grid.php +149 -0
  2. app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Switcher.php +73 -0
  3. app/code/community/Ess/M2ePro/Block/Adminhtml/Category/Grid.php +106 -0
  4. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account.php +60 -0
  5. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Grid.php +137 -0
  6. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Help.php +20 -0
  7. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit.php +150 -0
  8. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Form.php +39 -0
  9. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs.php +66 -0
  10. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/General.php +56 -0
  11. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/ListingOther.php +33 -0
  12. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Order.php +91 -0
  13. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Repricing.php +59 -0
  14. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Grid/Column/Filter/Price.php +42 -0
  15. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Grid/Column/Filter/Qty.php +42 -0
  16. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing.php +44 -0
  17. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Form.php +26 -0
  18. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin.php +126 -0
  19. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category.php +163 -0
  20. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category/Grid.php +346 -0
  21. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual.php +165 -0
  22. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/Grid.php +357 -0
  23. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/SkipPopup.php +43 -0
  24. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Review.php +30 -0
  25. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin.php +298 -0
  26. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php +701 -0
  27. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Help.php +26 -0
  28. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NewAsinPopup.php +43 -0
  29. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NotCompleted.php +36 -0
  30. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/SearchSettings.php +75 -0
  31. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/General.php +27 -0
  32. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Search.php +54 -0
  33. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Selling.php +99 -0
  34. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode.php +21 -0
  35. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category.php +25 -0
  36. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Form.php +37 -0
  37. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Group/Grid.php +20 -0
  38. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Global.php +22 -0
  39. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Website.php +22 -0
  40. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit.php +167 -0
  41. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Form.php +39 -0
  42. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Tabs.php +50 -0
  43. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Grid.php +330 -0
  44. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/Grid.php +160 -0
  45. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View.php +271 -0
  46. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View/Grid.php +662 -0
  47. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product.php +103 -0
  48. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product/Help.php +26 -0
  49. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Grid.php +775 -0
  50. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Main.php +85 -0
  51. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Menu.php +95 -0
  52. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/SuggestedAsinGridHelp.php +27 -0
  53. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search.php +164 -0
  54. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search/Grid.php +1048 -0
  55. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/Description/Grid.php +436 -0
  56. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/Description/Main.php +79 -0
  57. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/ShippingOverride.php +60 -0
  58. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/ShippingOverride/Grid.php +223 -0
  59. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs.php +161 -0
  60. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php +671 -0
  61. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations.php +42 -0
  62. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Child/Form.php +413 -0
  63. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Grid.php +1785 -0
  64. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Help.php +27 -0
  65. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Vocabulary.php +129 -0
  66. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToIndividualPopup.php +52 -0
  67. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToParentPopup.php +52 -0
  68. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyAttributesPopup.php +50 -0
  69. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyOptionsPopup.php +50 -0
  70. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View.php +827 -0
  71. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php +1760 -0
  72. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Help.php +26 -0
  73. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ListingSwitcher.php +24 -0
  74. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Magento/Grid.php +359 -0
  75. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.php +50 -0
  76. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php +1135 -0
  77. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Settings/Grid.php +702 -0
  78. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Marketplace/Form.php +99 -0
  79. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress.php +71 -0
  80. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress/Form.php +61 -0
  81. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Grid.php +590 -0
  82. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment.php +23 -0
  83. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Breadcrumb.php +26 -0
  84. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Configuration.php +118 -0
  85. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Information.php +114 -0
  86. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Magento/Shipment.php +60 -0
  87. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Message.php +26 -0
  88. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/ShippingServices.php +61 -0
  89. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View.php +111 -0
  90. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Form.php +134 -0
  91. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Item.php +343 -0
  92. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Synchronization/Form.php +88 -0
  93. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template.php +80 -0
  94. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Edit.php +101 -0
  95. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs.php +73 -0
  96. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Browse.php +30 -0
  97. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Recent.php +44 -0
  98. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Search.php +30 -0
  99. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add.php +73 -0
  100. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add/Grid.php +250 -0
  101. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit.php +105 -0
  102. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Form.php +41 -0
  103. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs.php +60 -0
  104. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Definition.php +137 -0
  105. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/General.php +62 -0
  106. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Specifics.php +38 -0
  107. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Grid.php +224 -0
  108. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Grid.php +298 -0
  109. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit.php +107 -0
  110. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit/Form.php +58 -0
  111. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/ShippingOverride/Edit.php +107 -0
  112. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/ShippingOverride/Edit/Form.php +114 -0
  113. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit.php +112 -0
  114. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Form.php +40 -0
  115. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs.php +67 -0
  116. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/List.php +27 -0
  117. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Relist.php +27 -0
  118. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Revise.php +27 -0
  119. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Stop.php +27 -0
  120. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit.php +156 -0
  121. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Form.php +39 -0
  122. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs.php +58 -0
  123. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/General.php +81 -0
  124. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/ListingOther.php +33 -0
  125. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/Order.php +91 -0
  126. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing.php +43 -0
  127. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Form.php +26 -0
  128. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/General.php +27 -0
  129. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Search.php +51 -0
  130. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Selling.php +95 -0
  131. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode.php +21 -0
  132. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category.php +25 -0
  133. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Form.php +15 -0
  134. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Group/Grid.php +20 -0
  135. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Global.php +15 -0
  136. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Website.php +15 -0
  137. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit.php +167 -0
  138. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Form.php +39 -0
  139. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Tabs.php +50 -0
  140. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Grid.php +324 -0
  141. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/Grid.php +84 -0
  142. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View.php +271 -0
  143. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View/Grid.php +530 -0
  144. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product.php +102 -0
  145. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product/Help.php +26 -0
  146. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Grid.php +254 -0
  147. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Main.php +68 -0
  148. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Menu.php +37 -0
  149. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search.php +162 -0
  150. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search/Grid.php +613 -0
  151. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View.php +600 -0
  152. app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Grid.php +89 -0
app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Grid.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ abstract class Ess_M2ePro_Block_Adminhtml_Account_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ protected $viewComponentHelper = NULL;
12
+
13
+ //########################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialize view
20
+ // ---------------------------------------
21
+ $view = Mage::helper('M2ePro/View')->getCurrentView();
22
+ $this->viewComponentHelper = Mage::helper('M2ePro/View')->getComponentHelper($view);
23
+ // ---------------------------------------
24
+
25
+ // Initialization block
26
+ // ---------------------------------------
27
+ $this->setId($view . 'AccountGrid');
28
+ // ---------------------------------------
29
+
30
+ // Set default values
31
+ // ---------------------------------------
32
+ $this->setDefaultSort('title');
33
+ $this->setDefaultDir('ASC');
34
+ $this->setSaveParametersInSession(true);
35
+ $this->setUseAjax(true);
36
+ // ---------------------------------------
37
+ }
38
+
39
+ //########################################
40
+
41
+ protected function _prepareCollection()
42
+ {
43
+ // Get collection of accounts
44
+ $collection = $this->getCollection();
45
+ if (is_null($collection)) {
46
+ $collection = Mage::getModel('M2ePro/Account')->getCollection();
47
+ }
48
+
49
+ $components = $this->viewComponentHelper->getActiveComponents();
50
+ $collection->addFieldToFilter('main_table.component_mode', array('in'=>$components));
51
+
52
+ // Set collection to grid
53
+ $this->setCollection($collection);
54
+
55
+ return parent::_prepareCollection();
56
+ }
57
+
58
+ protected function _prepareColumns()
59
+ {
60
+ $this->addColumn('create_date', array(
61
+ 'header' => Mage::helper('M2ePro')->__('Creation Date'),
62
+ 'align' => 'left',
63
+ 'width' => '150px',
64
+ 'type' => 'datetime',
65
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
66
+ 'index' => 'create_date',
67
+ 'filter_index' => 'main_table.create_date'
68
+ ));
69
+
70
+ $this->addColumn('update_date', array(
71
+ 'header' => Mage::helper('M2ePro')->__('Update Date'),
72
+ 'align' => 'left',
73
+ 'width' => '150px',
74
+ 'type' => 'datetime',
75
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
76
+ 'index' => 'update_date',
77
+ 'filter_index' => 'main_table.update_date'
78
+ ));
79
+
80
+ $confirm = 'Attention! By Deleting Account you delete all information on it from M2E Pro Server. ';
81
+ $confirm .= 'This will cause inappropriate work of all Accounts\' copies.';
82
+ $confirm = Mage::helper('M2ePro')->__($confirm);
83
+
84
+ $this->addColumn('actions', array(
85
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
86
+ 'align' => 'left',
87
+ 'width' => '150px',
88
+ 'type' => 'action',
89
+ 'index' => 'actions',
90
+ 'filter' => false,
91
+ 'sortable' => false,
92
+ 'getter' => 'getId',
93
+ 'actions' => array(
94
+ array(
95
+ 'caption' => Mage::helper('M2ePro')->__('Edit'),
96
+ 'url' => array('base'=> '*/*/edit'),
97
+ 'field' => 'id'
98
+ ),
99
+ array(
100
+ 'caption' => Mage::helper('M2ePro')->__('Delete'),
101
+ 'url' => array('base'=> '*/*/delete'),
102
+ 'field' => 'id',
103
+ 'confirm' => $confirm
104
+ )
105
+ )
106
+ ));
107
+
108
+ return parent::_prepareColumns();
109
+ }
110
+
111
+ protected function _prepareMassaction()
112
+ {
113
+ // Set massaction identifiers
114
+ // ---------------------------------------
115
+ $this->setMassactionIdField('main_table.id');
116
+ $this->getMassactionBlock()->setFormFieldName('ids');
117
+ // ---------------------------------------
118
+
119
+ // Set delete action
120
+ // ---------------------------------------
121
+ $confirm = 'Attention! By deleting Account you delete all information on it from M2E Pro Server. ';
122
+ $confirm .= 'This will cause inappropriate work of all Accounts\' copies.';
123
+ $confirm = Mage::helper('M2ePro')->__($confirm);
124
+
125
+ $this->getMassactionBlock()->addItem('delete', array(
126
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
127
+ 'url' => $this->getUrl('*/*/delete'),
128
+ 'confirm' => $confirm
129
+ ));
130
+ // ---------------------------------------
131
+
132
+ return parent::_prepareMassaction();
133
+ }
134
+
135
+ //########################################
136
+
137
+ public function getGridUrl()
138
+ {
139
+ return $this->getUrl('*/*/accountGrid', array('_current'=>true));
140
+ }
141
+
142
+ public function getRowUrl($row)
143
+ {
144
+ return Mage::helper('M2ePro/View')
145
+ ->getUrl($row, 'account', 'edit', array('id' => $row->getData('id')));
146
+ }
147
+
148
+ //########################################
149
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Account/Switcher.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Account_Switcher extends Ess_M2ePro_Block_Adminhtml_Component_Switcher
10
+ {
11
+ protected $paramName = 'account';
12
+
13
+ //########################################
14
+
15
+ public function getLabel()
16
+ {
17
+ if ($this->getData('component_mode') == Ess_M2ePro_Helper_Component_Ebay::NICK) {
18
+ return Mage::helper('M2ePro')->__('Account');
19
+ }
20
+
21
+ return Mage::helper('M2ePro')->__($this->getComponentLabel('%component% Account'));
22
+ }
23
+
24
+ public function getItems()
25
+ {
26
+ $collection = Mage::getModel('M2ePro/Account')->getCollection()
27
+ ->setOrder('component_mode', 'ASC')
28
+ ->setOrder('title', 'ASC');
29
+
30
+ if (!is_null($this->getData('component_mode'))) {
31
+ $collection->addFieldToFilter('component_mode', $this->getData('component_mode'));
32
+ }
33
+
34
+ if ($collection->getSize() < 2) {
35
+ return array();
36
+ }
37
+
38
+ $items = array();
39
+
40
+ foreach ($collection as $account) {
41
+ /** @var $account Ess_M2ePro_Model_Account */
42
+
43
+ if (!isset($items[$account->getComponentMode()]['label'])) {
44
+ $label = '';
45
+ if (isset($componentTitles[$account->getComponentMode()])) {
46
+ $label = $componentTitles[$account->getComponentMode()];
47
+ }
48
+
49
+ $items[$account->getComponentMode()]['label'] = $label;
50
+ }
51
+
52
+ $items[$account->getComponentMode()]['value'][] = array(
53
+ 'value' => $account->getId(),
54
+ 'label' => $account->getTitle()
55
+ );
56
+ }
57
+
58
+ return $items;
59
+ }
60
+
61
+ //########################################
62
+
63
+ public function getDefaultOptionName()
64
+ {
65
+ if ($this->getData('component_mode') == Ess_M2ePro_Helper_Component_Ebay::NICK) {
66
+ return Mage::helper('M2ePro')->__('All Users');
67
+ }
68
+
69
+ return Mage::helper('M2ePro')->__('All Accounts');
70
+ }
71
+
72
+ //########################################
73
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Category/Grid.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Category_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function getStoreId()
14
+ {
15
+ return !is_null($this->getData('store_id')) ? $this->getData('store_id') : Mage_Core_Model_App::ADMIN_STORE_ID;
16
+ }
17
+
18
+ public function setStoreId($storeId)
19
+ {
20
+ $this->setData('store_id',$storeId);
21
+ return $this;
22
+ }
23
+
24
+ //########################################
25
+
26
+ public function setCollection($collection)
27
+ {
28
+ $this->_prepareCache(clone $collection);
29
+ parent::setCollection($collection);
30
+ }
31
+
32
+ protected function _prepareCache($collection)
33
+ {
34
+ $stmt = $collection->getSelect()->query();
35
+
36
+ $ids = array();
37
+ foreach ($stmt as $item) {
38
+ $ids = array_merge($ids,array_map('intval',explode('/',$item['path'])));
39
+ }
40
+ $ids = array_unique($ids);
41
+
42
+ if (empty($ids)) {
43
+ return;
44
+ }
45
+
46
+ /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
47
+ $attribute = $collection->getFirstItem()->getResource()->getAttribute('name');
48
+
49
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
50
+
51
+ $tableName = Mage_Catalog_Model_Category::ENTITY . '_entity_' . $attribute->getBackendType();
52
+
53
+ $dbSelect1 = $connRead
54
+ ->select()
55
+ ->from(Mage::getSingleton('core/resource')->getTableName($tableName), new Zend_Db_Expr('MAX(`store_id`)'))
56
+ ->where("`entity_id` = `ccev`.`entity_id`")
57
+ ->where("`attribute_id` = `ccev`.`attribute_id`")
58
+ ->where("`store_id` = 0 OR `store_id` = ?",$this->getStoreId());
59
+
60
+ $dbSelect2 = $connRead
61
+ ->select()
62
+ ->from(
63
+ array('ccev' => Mage::getSingleton('core/resource')->getTableName($tableName)),
64
+ array('name' => 'value','category_id' => 'entity_id')
65
+ )
66
+ ->where('ccev.entity_id IN ('.implode(',',$ids).')')
67
+ ->where('ccev.attribute_id = ?', $attribute->getAttributeId())
68
+ ->where('ccev.entity_type_id = ?', $attribute->getEntityTypeId())
69
+ ->where('ccev.store_id = ('.$dbSelect1->__toString().')');
70
+
71
+ $cacheData = array();
72
+
73
+ foreach ($connRead->fetchAll($dbSelect2) as $row) {
74
+ $cacheData[$row['category_id']] = $row['name'];
75
+ }
76
+ $this->setData('categories_cache', $cacheData);
77
+ }
78
+
79
+ //########################################
80
+
81
+ public function callbackColumnMagentoCategory($value, $row, $column, $isExport)
82
+ {
83
+ $ids = explode('/',$row->getPath());
84
+
85
+ $categoriesCache = $this->getData('categories_cache');
86
+ $path = '';
87
+ foreach ($ids as $id) {
88
+ if (!isset($categoriesCache[$id])) {
89
+ continue;
90
+ }
91
+ $path != '' && $path .= ' > ';
92
+ $path .= $categoriesCache[$id];
93
+ }
94
+
95
+ return Mage::helper('M2ePro')->escapeHtml($path);
96
+ }
97
+
98
+ //########################################
99
+
100
+ public function getMultipleRows($item)
101
+ {
102
+ return false;
103
+ }
104
+
105
+ //########################################
106
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Account extends Ess_M2ePro_Block_Adminhtml_Common_Component_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('account');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_account';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ $this->_headerText = '';
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
+ $this->_addButton('add', array(
40
+ 'label' => Mage::helper('M2ePro')->__('Add Account'),
41
+ 'onclick' => $this->getAddButtonOnClickAction(),
42
+ 'class' => 'add add-button-drop-down'
43
+ ));
44
+ // ---------------------------------------
45
+ }
46
+
47
+ //########################################
48
+
49
+ protected function getAmazonNewUrl()
50
+ {
51
+ return $this->getUrl('*/adminhtml_common_amazon_account/new');
52
+ }
53
+
54
+ protected function getBuyNewUrl()
55
+ {
56
+ return $this->getUrl('*/adminhtml_common_buy_account/new');
57
+ }
58
+
59
+ //########################################
60
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Grid.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Account_Grid extends Ess_M2ePro_Block_Adminhtml_Account_Grid
10
+ {
11
+ //########################################
12
+
13
+ protected function _prepareCollection()
14
+ {
15
+ $collection = Mage::getModel('M2ePro/Account')->getCollection();
16
+
17
+ $collection->getSelect()
18
+ ->joinLeft(array('aa'=>Mage::getResourceModel('M2ePro/Amazon_Account')->getMainTable()),
19
+ '(`aa`.`account_id` = `main_table`.`id`)',
20
+ array('merchant_id'))
21
+ ->joinLeft(array('ba'=>Mage::getResourceModel('M2ePro/Buy_Account')->getMainTable()),
22
+ '(`ba`.`account_id` = `main_table`.`id`)',
23
+ array('seller_id'))
24
+ ->joinLeft(array('m'=>Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
25
+ '(`m`.`id` = `aa`.`marketplace_id`)',
26
+ array('marketplace_title'=>'title'));
27
+
28
+ $this->setCollection($collection);
29
+
30
+ return parent::_prepareCollection();
31
+ }
32
+
33
+ //########################################
34
+
35
+ protected function _prepareColumns()
36
+ {
37
+ $this->addColumn('id', array(
38
+ 'header' => Mage::helper('M2ePro')->__('ID'),
39
+ 'align' => 'right',
40
+ 'width' => '100px',
41
+ 'type' => 'number',
42
+ 'index' => 'id',
43
+ 'filter_index' => 'main_table.id'
44
+ ));
45
+
46
+ $this->addColumn('title', array(
47
+ 'header' => Mage::helper('M2ePro')->__('Title / Info'),
48
+ 'align' => 'left',
49
+ 'type' => 'text',
50
+ 'index' => 'title',
51
+ 'escape' => true,
52
+ 'filter_index' => 'main_table.title',
53
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
54
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
55
+ ));
56
+
57
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
58
+ $this->addColumn('component_mode', array(
59
+ 'header' => Mage::helper('M2ePro')->__('Channel'),
60
+ 'align' => 'left',
61
+ 'width' => '120px',
62
+ 'type' => 'options',
63
+ 'index' => 'component_mode',
64
+ 'filter_index' => 'main_table.component_mode',
65
+ 'sortable' => false,
66
+ 'options' => Mage::helper('M2ePro/View_Common_Component')->getActiveComponentsTitles()
67
+ ));
68
+ }
69
+
70
+ return parent::_prepareColumns();
71
+ }
72
+
73
+ //########################################
74
+
75
+ public function callbackColumnTitle($value, $row, $column, $isExport)
76
+ {
77
+ if ($row->isComponentModeAmazon()) {
78
+ $marketplaceLabel = Mage::helper('M2ePro')->__('Marketplace');
79
+ $marketplaceTitle = $row->getData('marketplace_title');
80
+
81
+ $merchantLabel = Mage::helper('M2ePro')->__('Merchant ID');
82
+ $merchantId = $row->getData('merchant_id');
83
+
84
+ $value = <<<HTML
85
+ <div>
86
+ {$value}<br/>
87
+ <span style="font-weight: bold">{$merchantLabel}</span>:
88
+ <span style="color: #505050">{$merchantId}</span>
89
+ <br/>
90
+ <span style="font-weight: bold">{$marketplaceLabel}</span>:
91
+ <span style="color: #505050">{$marketplaceTitle}</span>
92
+ <br/>
93
+ </div>
94
+ HTML;
95
+ } else {
96
+ $sellerId = $row->getData('seller_id');
97
+
98
+ if (empty($sellerId)) {
99
+ return $value;
100
+ }
101
+
102
+ $sellerLabel = Mage::helper('M2ePro')->__('Seller ID');
103
+
104
+ $value = <<<HTML
105
+ <div>
106
+ {$value}<br/>
107
+ <span style="font-weight: bold">{$sellerLabel}</span>:
108
+ <span style="color: #505050">{$sellerId}</span>
109
+ <br/>
110
+ </div>
111
+ HTML;
112
+ }
113
+
114
+ return $value;
115
+ }
116
+
117
+ //########################################
118
+
119
+ protected function callbackFilterTitle($collection, $column)
120
+ {
121
+ $value = $column->getFilter()->getValue();
122
+
123
+ if ($value == null) {
124
+ return;
125
+ }
126
+
127
+ $collection->getSelect()->where(
128
+ 'main_table.title LIKE ?
129
+ OR m.title LIKE ?
130
+ OR aa.merchant_id LIKE ?
131
+ OR ba.seller_id LIKE ?',
132
+ '%'. $value .'%'
133
+ );
134
+ }
135
+
136
+ //########################################
137
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Account/Help.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Account_Help extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ $this->setTemplate('M2ePro/common/account/help.phtml');
17
+ }
18
+
19
+ //########################################
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonAccountEdit');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_amazon_account';
22
+ $this->_mode = 'edit';
23
+ // ---------------------------------------
24
+
25
+ // Set header text
26
+ // ---------------------------------------
27
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
28
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
29
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit %component_name% Account", $componentName);
30
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add %component_name% Account", $componentName);
31
+ } else {
32
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit Account");
33
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add Account");
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(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
41
+ ->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
+ /* @var $wizardHelper Ess_M2ePro_Helper_Module_Wizard */
58
+ $wizardHelper = Mage::helper('M2ePro/Module_Wizard');
59
+
60
+ if ($wizardHelper->isActive('amazon') &&
61
+ $wizardHelper->getStep('amazon') == 'account') {
62
+
63
+ // ---------------------------------------
64
+ $this->_addButton('save_and_continue', array(
65
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
66
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
67
+ 'class' => 'save'
68
+ ));
69
+ // ---------------------------------------
70
+
71
+ if ($this->getRequest()->getParam('id')) {
72
+ // ---------------------------------------
73
+ $url = $this->getUrl('*/adminhtml_common_amazon_account/new', array('wizard' => true));
74
+ $this->_addButton('add_new_account', array(
75
+ 'label' => Mage::helper('M2ePro')->__('Add New Account'),
76
+ 'onclick' => 'setLocation(\''. $url .'\')',
77
+ 'class' => 'add_new_account'
78
+ ));
79
+ // ---------------------------------------
80
+
81
+ // ---------------------------------------
82
+ $this->_addButton('close', array(
83
+ 'label' => Mage::helper('M2ePro')->__('Complete This Step'),
84
+ 'onclick' => 'AmazonAccountHandlerObj.completeStep();',
85
+ 'class' => 'close'
86
+ ));
87
+ // ---------------------------------------
88
+ }
89
+ } else {
90
+
91
+ if ((bool)$this->getRequest()->getParam('close_on_save',false)) {
92
+
93
+ if ($this->getRequest()->getParam('id')) {
94
+ $this->_addButton('save', array(
95
+ 'label' => Mage::helper('M2ePro')->__('Save And Close'),
96
+ 'onclick' => 'AmazonAccountHandlerObj.saveAndClose()',
97
+ 'class' => 'save'
98
+ ));
99
+ } else {
100
+ $this->_addButton('save_and_continue', array(
101
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
102
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
103
+ 'class' => 'save'
104
+ ));
105
+ }
106
+ return;
107
+ }
108
+
109
+ // ---------------------------------------
110
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
111
+ $this->_addButton('back', array(
112
+ 'label' => Mage::helper('M2ePro')->__('Back'),
113
+ 'onclick' => 'AmazonAccountHandlerObj.back_click(\''. $url .'\')',
114
+ 'class' => 'back'
115
+ ));
116
+ // ---------------------------------------
117
+
118
+ // ---------------------------------------
119
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
120
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
121
+ ) {
122
+ // ---------------------------------------
123
+ $this->_addButton('delete', array(
124
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
125
+ 'onclick' => 'AmazonAccountHandlerObj.delete_click()',
126
+ 'class' => 'delete M2ePro_delete_button'
127
+ ));
128
+ // ---------------------------------------
129
+ }
130
+
131
+ // ---------------------------------------
132
+ $this->_addButton('save', array(
133
+ 'label' => Mage::helper('M2ePro')->__('Save'),
134
+ 'onclick' => 'AmazonAccountHandlerObj.save_click()',
135
+ 'class' => 'save'
136
+ ));
137
+ // ---------------------------------------
138
+
139
+ // ---------------------------------------
140
+ $this->_addButton('save_and_continue', array(
141
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
142
+ 'onclick' => 'AmazonAccountHandlerObj.save_and_edit_click(\'\',\'amazonAccountEditTabs\')',
143
+ 'class' => 'save'
144
+ ));
145
+ // ---------------------------------------
146
+ }
147
+ }
148
+
149
+ //########################################
150
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Form.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonAccountEditForm');
20
+ // ---------------------------------------
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/*/save'),
28
+ 'method' => 'post',
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ //########################################
39
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonAccountEditTabs');
20
+ // ---------------------------------------
21
+
22
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
23
+ $this->setDestElementId('edit_form');
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()
32
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_general')->toHtml(),
33
+ ));
34
+
35
+ $this->addTab('listingOther', array(
36
+ 'label' => Mage::helper('M2ePro')->__('3rd Party Listings'),
37
+ 'title' => Mage::helper('M2ePro')->__('3rd Party Listings'),
38
+ 'content' => $this->getLayout()
39
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_listingOther')->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_amazon_account_edit_tabs_order')->toHtml(),
47
+ ));
48
+
49
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() &&
50
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) {
51
+
52
+ $this->addTab('repricing', array(
53
+ 'label' => Mage::helper('M2ePro')->__('Repricing Tool'),
54
+ 'title' => Mage::helper('M2ePro')->__('Repricing Tool'),
55
+ 'content' => $this->getLayout()
56
+ ->createBlock('M2ePro/adminhtml_common_amazon_account_edit_tabs_repricing')->toHtml(),
57
+ ));
58
+ }
59
+
60
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
61
+
62
+ return parent::_beforeToHtml();
63
+ }
64
+
65
+ //########################################
66
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/General.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs_General extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonAccountEditTabsGeneral');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/general.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $this->synchronizeProcessing = false;
28
+
29
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
30
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) {
31
+
32
+ /** @var $accountObj Ess_M2ePro_Model_Account */
33
+ $accountObj = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
34
+
35
+ $this->synchronizeProcessing = $accountObj->isLockedObject('server_synchronize');
36
+
37
+ if (!$this->synchronizeProcessing) {
38
+ $accountId = $accountObj->getId();
39
+
40
+ Mage::helper('M2ePro/Data_Global')->unsetValue('temp_data');
41
+ Mage::helper('M2ePro/Data_Global')->setValue(
42
+ 'temp_data',
43
+ Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Account',$accountId)
44
+ );
45
+ }
46
+ }
47
+
48
+ $marketplaces = Mage::helper('M2ePro/Component_Amazon')->getMarketplacesAvailableForApiCreation();
49
+ $marketplaces = $marketplaces->toArray();
50
+ $this->marketplaces = $marketplaces['items'];
51
+
52
+ return parent::_beforeToHtml();
53
+ }
54
+
55
+ //########################################
56
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/ListingOther.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs_ListingOther extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonAccountEditTabsListingOther');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/listing_other.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
28
+
29
+ return parent::_beforeToHtml();
30
+ }
31
+
32
+ //########################################
33
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Order.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs_Order extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ protected $_possibleMagentoStatuses = null;
12
+
13
+ //########################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ // ---------------------------------------
21
+ $this->setId('amazonAccountEditTabsOrder');
22
+ // ---------------------------------------
23
+
24
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/order.phtml');
25
+ }
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
30
+ $magentoOrdersSettings = !empty($data['magento_orders_settings'])
31
+ ? json_decode($data['magento_orders_settings'], true) : array();
32
+
33
+ // ---------------------------------------
34
+ $temp = Mage::getModel('core/website')->getCollection()->setOrder('sort_order','ASC')->toArray();
35
+ $this->websites = $temp['items'];
36
+ // ---------------------------------------
37
+
38
+ // ---------------------------------------
39
+ $temp = Mage::getModel('customer/group')->getCollection()->toArray();
40
+ $this->groups = $temp['items'];
41
+ // ---------------------------------------
42
+
43
+ // ---------------------------------------
44
+ $selectedStore = !empty($magentoOrdersSettings['listing']['store_id'])
45
+ ? $magentoOrdersSettings['listing']['store_id'] : '';
46
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
47
+ 'id' => 'magento_orders_listings_store_id',
48
+ 'name' => 'magento_orders_settings[listing][store_id]',
49
+ 'selected' => $selectedStore
50
+ ));
51
+ $blockStoreSwitcher->hasDefaultOption(false);
52
+ $this->setChild('magento_orders_listings_store_id', $blockStoreSwitcher);
53
+ // ---------------------------------------
54
+
55
+ // ---------------------------------------
56
+ $selectedStore = !empty($magentoOrdersSettings['listing_other']['store_id'])
57
+ ? $magentoOrdersSettings['listing_other']['store_id'] : '';
58
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
59
+ 'id' => 'magento_orders_listings_other_store_id',
60
+ 'name' => 'magento_orders_settings[listing_other][store_id]',
61
+ 'selected' => $selectedStore
62
+ ));
63
+ $blockStoreSwitcher->hasDefaultOption(false);
64
+ $this->setChild('magento_orders_listings_other_store_id', $blockStoreSwitcher);
65
+ // ---------------------------------------
66
+
67
+ // ---------------------------------------
68
+ $productTaxClasses = Mage::getModel('tax/class')->getCollection()
69
+ ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)
70
+ ->toOptionArray();
71
+
72
+ $none = array('value' => Ess_M2ePro_Model_Magento_Product::TAX_CLASS_ID_NONE, 'label' => 'None');
73
+ array_unshift($productTaxClasses, $none);
74
+
75
+ $this->productTaxClasses = $productTaxClasses;
76
+ // ---------------------------------------
77
+
78
+ return parent::_beforeToHtml();
79
+ }
80
+
81
+ public function getMagentoOrderStatusList()
82
+ {
83
+ if (is_null($this->_possibleMagentoStatuses)) {
84
+ $this->_possibleMagentoStatuses = Mage::getSingleton('sales/order_config')->getStatuses();
85
+ }
86
+
87
+ return $this->_possibleMagentoStatuses;
88
+ }
89
+
90
+ //########################################
91
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Account/Edit/Tabs/Repricing.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Account_Edit_Tabs_Repricing extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonAccountEditTabsRepricing');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/account/tabs/repricing.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $this->isRepricingLinked = false;
28
+
29
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
30
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) {
31
+
32
+ /** @var $accountObj Ess_M2ePro_Model_Account */
33
+ $accountObj = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
34
+
35
+ $this->isRepricingLinked = $accountObj->getChildObject()->isRepricingLinked();
36
+
37
+ if ($this->isRepricingLinked) {
38
+ $this->repricingData = $accountObj->getChildObject()->getRepricing();
39
+
40
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Listing_Product_Collection $collection */
41
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
42
+
43
+ $collection->getSelect()
44
+ ->join(array('l' => Mage::getResourceModel('M2ePro/Listing')->getMainTable()),
45
+ '(`l`.`id` = `main_table`.`listing_id`)', array());
46
+
47
+ $collection->getSelect()->where("`second_table`.`is_variation_parent` = 0");
48
+ $collection->getSelect()->where("`second_table`.`is_repricing` = 1");
49
+ $collection->getSelect()->where("`l`.`account_id` = ?", $accountObj->getId());
50
+
51
+ $this->m2eproRepricingProducts = $collection->count();
52
+ }
53
+ }
54
+
55
+ return parent::_beforeToHtml();
56
+ }
57
+
58
+ //########################################
59
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Grid/Column/Filter/Price.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Grid_Column_Filter_Price
10
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Range
11
+ {
12
+ //########################################
13
+
14
+ public function getHtml()
15
+ {
16
+ $afnChecked = ($this->getValue('is_repricing') == 1) ? 'checked="checked"' : '';
17
+
18
+ return parent::getHtml() .
19
+ '<div class="range"><div class="range-line" style="width: auto;"><span class="label" style="width: auto;">'.
20
+ Mage::helper('M2ePro')->__('Repricing ON') . ': </span>' .
21
+ '<input style="margin-left:6px;float:none;width:auto !important;" type="checkbox" value="1" name="'.
22
+ $this->_getHtmlName() . '[is_repricing]" ' . $afnChecked . '></div></div>';
23
+ }
24
+
25
+ //########################################
26
+
27
+ public function getValue($index=null)
28
+ {
29
+ if ($index) {
30
+ return $this->getData('value', $index);
31
+ }
32
+ $value = $this->getData('value');
33
+ if ((isset($value['from']) && strlen($value['from']) > 0) ||
34
+ (isset($value['to']) && strlen($value['to']) > 0) ||
35
+ (isset($value['is_repricing']) && $value['is_repricing'] == 1)) {
36
+ return $value;
37
+ }
38
+ return null;
39
+ }
40
+
41
+ //########################################
42
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Grid/Column/Filter/Qty.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Grid_Column_Filter_Qty
10
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Range
11
+ {
12
+ //########################################
13
+
14
+ public function getHtml()
15
+ {
16
+ $afnChecked = ($this->getValue('afn') == 1) ? 'checked="checked"' : '';
17
+
18
+ return parent::getHtml() .
19
+ '<div class="range"><div class="range-line"><span class="label">' .
20
+ Mage::helper('M2ePro')->__('AFN') . ': </span>' .
21
+ '<input style="margin-left:6px;float:none;width:auto !important;" type="checkbox" value="1" name="' .
22
+ $this->_getHtmlName() . '[afn]" ' . $afnChecked . '></div></div>';
23
+ }
24
+
25
+ //########################################
26
+
27
+ public function getValue($index=null)
28
+ {
29
+ if ($index) {
30
+ return $this->getData('value', $index);
31
+ }
32
+ $value = $this->getData('value');
33
+ if ((isset($value['from']) && strlen($value['from']) > 0) ||
34
+ (isset($value['to']) && strlen($value['to']) > 0) ||
35
+ (isset($value['afn']) && $value['afn'] == 1)) {
36
+ return $value;
37
+ }
38
+ return null;
39
+ }
40
+
41
+ //########################################
42
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListing');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_amazon_listing';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ $this->_headerText = '';
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
+ $this->setTemplate('M2ePro/widget/grid/container/only_content.phtml');
40
+
41
+ }
42
+
43
+ //########################################
44
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Form.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Form
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Form
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->component = Ess_M2ePro_Helper_Component_Amazon::NICK;
21
+ $this->setId('amazonListingEditForm');
22
+ // ---------------------------------------
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin extends Ess_M2ePro_Block_Adminhtml_Widget_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingAddNewAsin');
20
+ // ---------------------------------------
21
+
22
+ $this->_headerText = Mage::helper('M2ePro')->__('New ASIN/ISBN Creation');
23
+
24
+ $url = $this->getUrl('*/*/index', array(
25
+ 'step' => 1,
26
+ '_current' => true
27
+ ));
28
+ $this->_addButton('back', array(
29
+ 'label' => Mage::helper('M2ePro')->__('Back'),
30
+ 'class' => 'back',
31
+ 'onclick' => 'setLocation(\''.$url.'\');'
32
+ ));
33
+
34
+ $this->_addButton('next', array(
35
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
36
+ 'class' => 'scalable next',
37
+ 'onclick' => "descriptionTemplateModeFormSubmit()"
38
+ ));
39
+
40
+ $this->setTemplate('M2ePro/common/amazon/listing/add/new_asin.phtml');
41
+ }
42
+
43
+ //########################################
44
+
45
+ public function getHeaderWidth()
46
+ {
47
+ return 'width:50%;';
48
+ }
49
+
50
+ //########################################
51
+
52
+ protected function _beforeToHtml()
53
+ {
54
+ parent::_beforeToHtml();
55
+
56
+ $listing = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
57
+ 'Listing', $this->getRequest()->getParam('id')
58
+ );
59
+
60
+ $viewHeaderBlock = $this->getLayout()->createBlock(
61
+ 'M2ePro/adminhtml_listing_view_header','',
62
+ array('listing' => $listing)
63
+ );
64
+
65
+ $this->setChild('view_header', $viewHeaderBlock);
66
+
67
+ // ---------------------------------------
68
+ $buttonBlock = $this->getLayout()
69
+ ->createBlock('adminhtml/widget_button')
70
+ ->setData(array(
71
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
72
+ 'onclick' => '',
73
+ ));
74
+ $this->setChild('mode_same_remember_pop_up_confirm_button', $buttonBlock);
75
+ }
76
+
77
+ //########################################
78
+
79
+ /**
80
+ * @return Ess_M2ePro_Model_Listing
81
+ * @throws Exception
82
+ */
83
+ public function getListing()
84
+ {
85
+ if (!$listingId = $this->getRequest()->getParam('id')) {
86
+ throw new Ess_M2ePro_Model_Exception('Listing is not defined');
87
+ }
88
+
89
+ if (is_null($this->listing)) {
90
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
91
+ ->getObject('Listing', $listingId);
92
+ }
93
+
94
+ return $this->listing;
95
+ }
96
+
97
+ //########################################
98
+
99
+ public function getProductsIds()
100
+ {
101
+ return $this->getListing()->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
102
+ }
103
+
104
+ //########################################
105
+
106
+ public function getDescriptionTemplateMode()
107
+ {
108
+ $listingAdditionalData = $this->getListing()->getData('additional_data');
109
+ $listingAdditionalData = json_decode($listingAdditionalData, true);
110
+
111
+ $mode = 'same';
112
+
113
+ $sessionMode = Mage::helper('M2ePro/Data_Session')->getValue('products_source');
114
+ if ($sessionMode == 'category') {
115
+ $mode = $sessionMode;
116
+ }
117
+
118
+ if (!empty($listingAdditionalData['new_asin_mode'])) {
119
+ $mode = $listingAdditionalData['new_asin_mode'];
120
+ }
121
+
122
+ return $mode;
123
+ }
124
+
125
+ //########################################
126
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Category
10
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('newAsinDescriptionTemplateCategory');
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_category';
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
+
51
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
52
+ // ---------------------------------------
53
+ $this->_addButton('save_and_go_to_listing_view', array(
54
+ 'id' => 'save_and_go_to_listing_view',
55
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
56
+ 'onclick' => 'ListingGridHandlerObj.checkCategoryProducts(\''.$url.'\')',
57
+ 'class' => 'scalable next'
58
+ ));
59
+ // ---------------------------------------
60
+ }
61
+
62
+ public function getGridHtml()
63
+ {
64
+ $listing = Mage::helper('M2ePro/Component')->getCachedUnknownObject(
65
+ 'Listing', $this->getRequest()->getParam('id')
66
+ );
67
+
68
+ $viewHeaderBlock = $this->getLayout()->createBlock(
69
+ 'M2ePro/adminhtml_listing_view_header','',
70
+ array('listing' => $listing)
71
+ );
72
+
73
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml();
74
+ }
75
+
76
+ protected function _toHtml()
77
+ {
78
+ $helper = Mage::helper('M2ePro');
79
+
80
+ // TEXT
81
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
82
+ // ---------------------------------------
83
+
84
+ // URL
85
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
86
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
87
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
88
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
89
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/*/viewTemplateDescriptionsGrid');
90
+
91
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
92
+ $unmapFromNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
93
+
94
+ $checkNewAsinCategoryProducts = $this->getUrl('*/*/checkNewAsinCategoryProducts', array('_current' => true));
95
+ // ---------------------------------------
96
+
97
+ $javascript = <<<HTML
98
+ <script type="text/javascript">
99
+ selectTemplateDescription = function (el, templateId, mapToGeneralId)
100
+ {
101
+ ListingGridHandlerObj.mapToTemplateDescription(el, templateId, mapToGeneralId);
102
+ };
103
+
104
+ if (typeof M2ePro == 'undefined') {
105
+ M2ePro = {};
106
+ M2ePro.url = {};
107
+ M2ePro.formData = {};
108
+ M2ePro.customData = {};
109
+ M2ePro.text = {};
110
+ }
111
+
112
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
113
+
114
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
115
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
116
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
117
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
118
+
119
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
120
+ M2ePro.url.unmapFromNewAsin = '{$unmapFromNewAsin}';
121
+
122
+ M2ePro.url.checkNewAsinCategoryProducts = '{$checkNewAsinCategoryProducts}';
123
+
124
+ Event.observe(window, 'load', function() {
125
+
126
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
127
+
128
+ ListingGridHandlerObj = new CommonAmazonListingNewAsinTemplateDescriptionGridHandler(
129
+ '{$this->getChild('grid')->getId()}',
130
+ {$this->getListing()->getId()}
131
+ );
132
+
133
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
134
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
135
+ });
136
+
137
+ </script>
138
+ HTML;
139
+
140
+ return $javascript .
141
+ '<div id="search_asin_products_container">' .
142
+ parent::_toHtml() .
143
+ '</div>';
144
+ }
145
+
146
+ //########################################
147
+
148
+ public function getListing()
149
+ {
150
+ if (!$listingId = $this->getRequest()->getParam('id')) {
151
+ throw new Ess_M2ePro_Model_Exception('Listing is not defined');
152
+ }
153
+
154
+ if (is_null($this->listing)) {
155
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
156
+ ->getObject('Listing', $listingId)->getChildObject();
157
+ }
158
+
159
+ return $this->listing;
160
+ }
161
+
162
+ //########################################
163
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Category/Grid.php ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Category_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Category_Grid
11
+ {
12
+ /** @var Ess_M2ePro_Model_Listing */
13
+ private $listing = NULL;
14
+
15
+ //########################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ // Initialization block
22
+ // ---------------------------------------
23
+ $this->setId('newAsinCategoryGrid');
24
+ // ---------------------------------------
25
+
26
+ // Set default values
27
+ // ---------------------------------------
28
+ $this->setDefaultSort('id');
29
+ $this->setDefaultDir('DESC');
30
+ $this->setUseAjax(true);
31
+ // ---------------------------------------
32
+
33
+ $this->prepareDataByCategories();
34
+ }
35
+
36
+ //########################################
37
+
38
+ protected function _prepareCollection()
39
+ {
40
+ /* @var $collection Mage_Catalog_Model_Resource_Category_Collection */
41
+ $collection = Mage::getModel('catalog/category')->getCollection();
42
+ $collection->addAttributeToSelect('name');
43
+
44
+ $collection->addFieldToFilter(array(
45
+ array('attribute' => 'entity_id', 'in' => array_keys($this->getData('categories_data')))
46
+ ));
47
+
48
+ $this->setCollection($collection);
49
+
50
+ return parent::_prepareCollection();
51
+ }
52
+
53
+ //########################################
54
+
55
+ protected function _prepareColumns()
56
+ {
57
+ $this->addColumn('magento_category', array(
58
+ 'header' => Mage::helper('M2ePro')->__('Magento Category'),
59
+ 'align' => 'left',
60
+ 'width' => '500px',
61
+ 'type' => 'text',
62
+ 'index' => 'name',
63
+ 'filter' => false,
64
+ 'sortable' => false,
65
+ 'frame_callback' => array($this, 'callbackColumnMagentoCategory')
66
+ ));
67
+
68
+ $this->addColumn('description_template', array(
69
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
70
+ 'align' => 'left',
71
+ 'width' => '*',
72
+ 'sortable' => false,
73
+ 'type' => 'options',
74
+ 'index' => 'description_template_id',
75
+ 'filter_index' => 'description_template_id',
76
+ 'options' => array(
77
+ 1 => Mage::helper('M2ePro')->__('Description Policy Selected'),
78
+ 0 => Mage::helper('M2ePro')->__('Description Policy Not Selected')
79
+ ),
80
+ 'frame_callback' => array($this, 'callbackColumnDescriptionTemplateCallback'),
81
+ 'filter_condition_callback' => array($this, 'callbackColumnDescriptionTemplateFilterCallback')
82
+ ));
83
+
84
+ $actionsColumn = array(
85
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
86
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
87
+ 'align' => 'center',
88
+ 'width' => '130px',
89
+ 'type' => 'text',
90
+ 'sortable' => false,
91
+ 'filter' => false,
92
+ 'actions' => array()
93
+ );
94
+
95
+ $actions = array(
96
+ array(
97
+ 'caption' => Mage::helper('M2ePro')->__('Set Description Policy'),
98
+ 'field' => 'entity_id',
99
+ 'onclick_action' => 'ListingGridHandlerObj.setDescriptionTemplateByCategoryRowAction'
100
+ ),
101
+ array(
102
+ 'caption' => Mage::helper('M2ePro')->__('Reset Description Policy'),
103
+ 'field' => 'entity_id',
104
+ 'onclick_action' => 'ListingGridHandlerObj.resetDescriptionTemplateByCategoryRowAction'
105
+ )
106
+ );
107
+
108
+ $actionsColumn['actions'] = $actions;
109
+
110
+ $this->addColumn('actions', $actionsColumn);
111
+
112
+ return parent::_prepareColumns();
113
+ }
114
+
115
+ //########################################
116
+
117
+ protected function _prepareMassaction()
118
+ {
119
+ $this->setMassactionIdField('entity_id');
120
+ $this->setMassactionIdFieldOnlyIndexValue(true);
121
+
122
+ // ---------------------------------------
123
+ $this->getMassactionBlock()->addItem('setDescriptionTemplateByCategory', array(
124
+ 'label' => Mage::helper('M2ePro')->__('Set Description Policy'),
125
+ 'url' => ''
126
+ ));
127
+
128
+ $this->getMassactionBlock()->addItem('resetDescriptionTemplateByCategory', array(
129
+ 'label' => Mage::helper('M2ePro')->__('Reset Description Policy'),
130
+ 'url' => ''
131
+ ));
132
+ // ---------------------------------------
133
+
134
+ return parent::_prepareMassaction();
135
+ }
136
+
137
+ //########################################
138
+
139
+ public function callbackColumnDescriptionTemplateCallback($value, $row, $column, $isExport)
140
+ {
141
+ $categoriesData = $this->getData('categories_data');
142
+ $productsIds = implode(',', $categoriesData[$row->getData('entity_id')]);
143
+
144
+ $descriptionTemplatesData = $this->getData('description_templates_data');
145
+ $descriptionTemplatesIds = array();
146
+ foreach ($categoriesData[$row->getData('entity_id')] as $productId) {
147
+ if (empty($descriptionTemplatesIds[$descriptionTemplatesData[$productId]])) {
148
+ $descriptionTemplatesIds[$descriptionTemplatesData[$productId]] = 0;
149
+ }
150
+ $descriptionTemplatesIds[$descriptionTemplatesData[$productId]]++;
151
+ }
152
+
153
+ arsort($descriptionTemplatesIds);
154
+
155
+ reset($descriptionTemplatesIds);
156
+ $descriptionTemplateId = key($descriptionTemplatesIds);
157
+
158
+ if (empty($descriptionTemplateId)) {
159
+ $iconSrc = $this->getSkinUrl('M2ePro/images/warning.png');
160
+ $label = Mage::helper('M2ePro')->__('Not Selected');
161
+
162
+ return <<<HTML
163
+ <img src="{$iconSrc}" alt="">&nbsp;<span style="color: gray; font-style: italic;">{$label}</span>
164
+ <input type="hidden" id="products_ids_{$row->getData('entity_id')}" value="{$productsIds}">
165
+ HTML;
166
+ }
167
+
168
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
169
+ 'id' => $descriptionTemplateId
170
+ ));
171
+
172
+ /** @var Ess_M2ePro_Model_Amazon_Template_Description $descriptionTemplate */
173
+ $descriptionTemplate = Mage::helper('M2ePro/Component_Amazon')
174
+ ->getModel('Template_Description')->load($descriptionTemplateId);
175
+
176
+ $title = Mage::helper('M2ePro')->escapeHtml($descriptionTemplate->getData('title'));
177
+
178
+ return <<<HTML
179
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
180
+ <input type="hidden" id="products_ids_{$row->getData('entity_id')}" value="{$productsIds}">
181
+ HTML;
182
+ }
183
+
184
+ //########################################
185
+
186
+ protected function callbackColumnDescriptionTemplateFilterCallback($collection, $column)
187
+ {
188
+ $value = $column->getFilter()->getValue();
189
+
190
+ if ($value == null) {
191
+ return;
192
+ }
193
+
194
+ $filteredProductsCategories = array();
195
+ $filteredListingProductsIds = array();
196
+
197
+ $categoriesData = $this->getData('categories_data');
198
+ $descriptionTemplatesIds = $this->getData('description_templates_data');
199
+
200
+ foreach ($descriptionTemplatesIds as $listingProductId => $descriptionTemplateId) {
201
+ if ($descriptionTemplateId !== NULL) {
202
+ $filteredListingProductsIds[] = $listingProductId;
203
+ }
204
+ }
205
+
206
+ foreach ($categoriesData as $categoryId => $listingProducts) {
207
+ foreach ($filteredListingProductsIds as $listingProductId) {
208
+ if (in_array($listingProductId, $listingProducts)) {
209
+ $filteredProductsCategories[] = $categoryId;
210
+ }
211
+ }
212
+ }
213
+
214
+ $filteredProductsCategories = array_unique($filteredProductsCategories);
215
+
216
+ if ($value) {
217
+ $collection->addFieldToFilter('entity_id', array('in' => $filteredProductsCategories));
218
+ } else if (!empty($filteredProductsCategories)) {
219
+ $collection->addFieldToFilter('entity_id', array('nin' => $filteredProductsCategories));
220
+ }
221
+ }
222
+
223
+ //########################################
224
+
225
+ public function getRowUrl($row)
226
+ {
227
+ return false;
228
+ }
229
+
230
+ //########################################
231
+
232
+ protected function _toHtml()
233
+ {
234
+ $addErrorJs = '';
235
+
236
+ if (count($this->getData('categories_data')) === 0) {
237
+ $msg = Mage::helper('M2ePro')
238
+ ->__('Magento Categories are not specified for Products you are adding.');
239
+
240
+ $addErrorJs = <<<JS
241
+ MagentoMessageObj['addError']('{$msg}');
242
+ $('save_and_go_to_listing_view').addClassName('disabled').onclick = function() {
243
+ return null;
244
+ };
245
+ JS;
246
+
247
+ }
248
+
249
+ $javascriptsMain = <<<HTML
250
+ <script type="text/javascript">
251
+
252
+ if (typeof ListingGridHandlerObj != 'undefined') {
253
+ ListingGridHandlerObj.afterInitPage();
254
+ }
255
+
256
+ {$addErrorJs}
257
+
258
+ Event.observe(window, 'load', function() {
259
+ setTimeout(function() {
260
+ ListingGridHandlerObj.afterInitPage();
261
+ }, 350);
262
+ });
263
+
264
+ </script>
265
+ HTML;
266
+
267
+ return parent::_toHtml() . $javascriptsMain;
268
+ }
269
+
270
+ //########################################
271
+
272
+ /**
273
+ * @return Ess_M2ePro_Model_Amazon_Listing
274
+ * @throws Exception
275
+ */
276
+ public function getListing()
277
+ {
278
+ if (!$listingId = $this->getRequest()->getParam('id')) {
279
+ throw new Ess_M2ePro_Model_Exception('Listing is not defined');
280
+ }
281
+
282
+ if (is_null($this->listing)) {
283
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
284
+ ->getObject('Listing', $listingId);
285
+ }
286
+
287
+ return $this->listing;
288
+ }
289
+
290
+ //########################################
291
+
292
+ private function prepareDataByCategories()
293
+ {
294
+ $listingProductsIds = $this->getListing()
295
+ ->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
296
+
297
+ $listingProductCollection = Mage::helper('M2ePro/Component_Amazon')
298
+ ->getCollection('Listing_Product')
299
+ ->addFieldToFilter('id',array('in' => $listingProductsIds));
300
+
301
+ $productsIds = array();
302
+ $descriptionTemplatesIds = array();
303
+ foreach ($listingProductCollection->getData() as $item) {
304
+ $productsIds[$item['id']] = $item['product_id'];
305
+ $descriptionTemplatesIds[$item['id']] = $item['template_description_id'];
306
+ }
307
+ $productsIds = array_unique($productsIds);
308
+
309
+ $categoriesIds = Mage::helper('M2ePro/Magento_Category')->getLimitedCategoriesByProducts(
310
+ $productsIds,
311
+ $this->getListing()->getStoreId()
312
+ );
313
+
314
+ $categoriesData = array();
315
+
316
+ foreach ($categoriesIds as $categoryId) {
317
+ /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
318
+ $collection = Mage::getModel('catalog/product')->getCollection();
319
+ $collection->addFieldToFilter('entity_id', array('in' => $productsIds));
320
+
321
+ $collection->joinTable(
322
+ array('ccp' => 'catalog/category_product'),
323
+ 'product_id=entity_id',
324
+ array('category_id' => 'category_id')
325
+ );
326
+ $collection->addFieldToFilter('category_id', $categoryId);
327
+
328
+ $data = $collection->getData();
329
+
330
+ foreach ($data as $item) {
331
+ $categoriesData[$categoryId][] = array_search($item['entity_id'], $productsIds);
332
+ }
333
+
334
+ $categoriesData[$categoryId] = array_unique($categoriesData[$categoryId]);
335
+ }
336
+
337
+ $this->setData('categories_data', $categoriesData);
338
+ $this->setData('description_templates_data', $descriptionTemplatesIds);
339
+
340
+ $this->getListing()
341
+ ->setSetting('additional_data', 'adding_new_asin_description_templates_data', $descriptionTemplatesIds);
342
+ $this->getListing()->save();
343
+ }
344
+
345
+ //########################################
346
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Manual
10
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $listingId = $this->getRequest()->getParam('id');
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('newAsinDescriptionTemplateManual');
23
+ // ---------------------------------------
24
+
25
+ // Set header text
26
+ // ---------------------------------------
27
+ $this->_headerText = Mage::helper('M2ePro')->__("Set Description Policy for New ASIN/ISBN Creation");
28
+ $this->_blockGroup = 'M2ePro';
29
+ $this->_controller = 'adminhtml_common_amazon_listing_add_newAsin_manual';
30
+ // ---------------------------------------
31
+
32
+ // Set buttons actions
33
+ // ---------------------------------------
34
+ $this->removeButton('back');
35
+ $this->removeButton('reset');
36
+ $this->removeButton('delete');
37
+ $this->removeButton('add');
38
+ $this->removeButton('save');
39
+ $this->removeButton('edit');
40
+ // ---------------------------------------
41
+
42
+ // ---------------------------------------
43
+ $url = $this->getUrl('*/*/resetNewAsin', array(
44
+ '_current' => true
45
+ ));
46
+ $this->_addButton('back', array(
47
+ 'label' => Mage::helper('M2ePro')->__('Back'),
48
+ 'onclick' => 'ListingGridHandlerObj.back_click(\'' . $url . '\')',
49
+ 'class' => 'back'
50
+ ));
51
+
52
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
53
+ // ---------------------------------------
54
+ $this->_addButton('save_and_go_to_listing_view', array(
55
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
56
+ 'onclick' => 'ListingGridHandlerObj.checkManualProducts(\''.$url.'\')',
57
+ 'class' => 'scalable next'
58
+ ));
59
+ // ---------------------------------------
60
+ }
61
+
62
+ public function getGridHtml()
63
+ {
64
+ $listing = Mage::helper('M2ePro/Component')->getCachedUnknownObject(
65
+ 'Listing', $this->getRequest()->getParam('id')
66
+ );
67
+
68
+ $viewHeaderBlock = $this->getLayout()->createBlock(
69
+ 'M2ePro/adminhtml_listing_view_header','',
70
+ array('listing' => $listing)
71
+ );
72
+
73
+ return $viewHeaderBlock->toHtml() . parent::getGridHtml();
74
+ }
75
+
76
+ protected function _toHtml()
77
+ {
78
+ $helper = Mage::helper('M2ePro');
79
+
80
+ // TEXT
81
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
82
+ $setDescriptionPolicy = $helper->escapeJs($helper->__('Set Description Policy.'));
83
+ // ---------------------------------------
84
+
85
+ // URL
86
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
87
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
88
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
89
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
90
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/*/viewTemplateDescriptionsGrid');
91
+
92
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
93
+ $unmapFromNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
94
+
95
+ $checkNewAsinManualProducts = $this->getUrl('*/*/checkNewAsinManualProducts', array('_current' => true));
96
+ // ---------------------------------------
97
+
98
+ $javascript = <<<HTML
99
+ <script type="text/javascript">
100
+ selectTemplateDescription = function (el, templateId, mapToGeneralId)
101
+ {
102
+ ListingGridHandlerObj.mapToTemplateDescription(el, templateId, mapToGeneralId);
103
+ };
104
+
105
+ if (typeof M2ePro == 'undefined') {
106
+ M2ePro = {};
107
+ M2ePro.url = {};
108
+ M2ePro.formData = {};
109
+ M2ePro.customData = {};
110
+ M2ePro.text = {};
111
+ }
112
+
113
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
114
+ M2ePro.text.setDescriptionPolicy = '{$setDescriptionPolicy}';
115
+
116
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
117
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
118
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
119
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
120
+
121
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
122
+ M2ePro.url.unmapFromNewAsin = '{$unmapFromNewAsin}';
123
+
124
+ M2ePro.url.checkNewAsinManualProducts = '{$checkNewAsinManualProducts}';
125
+
126
+ Event.observe(window, 'load', function() {
127
+
128
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
129
+
130
+ ListingGridHandlerObj = new CommonAmazonListingNewAsinTemplateDescriptionGridHandler(
131
+ '{$this->getChild('grid')->getId()}',
132
+ {$this->getListing()->getId()}
133
+ );
134
+
135
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
136
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
137
+ });
138
+
139
+ </script>
140
+ HTML;
141
+
142
+ return $javascript .
143
+ '<div id="search_asin_products_container">' .
144
+ parent::_toHtml() .
145
+ '</div>';
146
+ }
147
+
148
+ //########################################
149
+
150
+ public function getListing()
151
+ {
152
+ if (!$listingId = $this->getRequest()->getParam('id')) {
153
+ throw new Ess_M2ePro_Model_Exception('Listing is not defined');
154
+ }
155
+
156
+ if (is_null($this->listing)) {
157
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
158
+ ->getObject('Listing', $listingId)->getChildObject();
159
+ }
160
+
161
+ return $this->listing;
162
+ }
163
+
164
+ //########################################
165
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/Grid.php ADDED
@@ -0,0 +1,357 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Manual_Grid
10
+ extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+ /** @var Ess_M2ePro_Model_Listing */
13
+ private $listing = NULL;
14
+
15
+ //########################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ // Initialization block
22
+ // ---------------------------------------
23
+ $this->setId('newAsinManualGrid');
24
+ // ---------------------------------------
25
+
26
+ // Set default values
27
+ // ---------------------------------------
28
+ $this->setDefaultSort('product_id');
29
+ $this->setDefaultDir('DESC');
30
+ $this->setUseAjax(true);
31
+ // ---------------------------------------
32
+ }
33
+
34
+ //########################################
35
+
36
+ protected function _prepareCollection()
37
+ {
38
+ // Get collection
39
+ // ---------------------------------------
40
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
41
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
42
+ Mage::getModel('catalog/product')->getResource())
43
+ ->setStoreId($this->getListing()->getData('store_id'))
44
+ ->setListingProductModeOn()
45
+ ->addAttributeToSelect('name')
46
+ ->addAttributeToSelect('sku');
47
+ // ---------------------------------------
48
+
49
+ // ---------------------------------------
50
+ $listingProductsIds = $this->getListing()
51
+ ->getSetting('additional_data', 'adding_new_asin_listing_products_ids');
52
+
53
+ $collection->joinTable(
54
+ array('lp' => 'M2ePro/Listing_Product'),
55
+ 'product_id=entity_id',
56
+ array(
57
+ 'id' => 'id'
58
+ ),
59
+ '{{table}}.listing_id='.(int)$this->getListing()->getId()
60
+ );
61
+ $collection->joinTable(
62
+ array('elp' => 'M2ePro/Amazon_Listing_Product'),
63
+ 'listing_product_id=id',
64
+ array(
65
+ 'listing_product_id' => 'listing_product_id',
66
+ 'template_description_id' => 'template_description_id'
67
+ )
68
+ );
69
+
70
+ $collection->getSelect()->where('lp.id IN (?)', $listingProductsIds);
71
+ $collection->getSelect()->where('elp.search_settings_status != ? OR elp.search_settings_status IS NULL',
72
+ Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS);
73
+ $collection->getSelect()->where('elp.general_id IS NULL');
74
+ // ---------------------------------------
75
+
76
+ $this->setCollection($collection);
77
+
78
+ parent::_prepareCollection();
79
+
80
+ return $this;
81
+ }
82
+
83
+ protected function _prepareColumns()
84
+ {
85
+ $this->addColumn('product_id', array(
86
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
87
+ 'align' => 'right',
88
+ 'width' => '100px',
89
+ 'type' => 'number',
90
+ 'index' => 'entity_id',
91
+ 'filter_index' => 'entity_id',
92
+ 'frame_callback' => array($this, 'callbackColumnProductId')
93
+ ));
94
+
95
+ $this->addColumn('name', array(
96
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
97
+ 'align' => 'left',
98
+ 'width' => '400px',
99
+ 'type' => 'text',
100
+ 'index' => 'name',
101
+ 'filter_index' => 'name',
102
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
103
+ 'filter_condition_callback' => array($this, 'callbackFilterProductTitle')
104
+ ));
105
+
106
+ $this->addColumn('description_template', array(
107
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
108
+ 'align' => 'left',
109
+ 'width' => '*',
110
+ 'sortable' => false,
111
+ 'type' => 'options',
112
+ 'index' => 'description_template_id',
113
+ 'filter_index' => 'description_template_id',
114
+ 'options' => array(
115
+ 1 => Mage::helper('M2ePro')->__('Description Policy Selected'),
116
+ 0 => Mage::helper('M2ePro')->__('Description Policy Not Selected')
117
+ ),
118
+ 'frame_callback' => array($this, 'callbackColumnDescriptionTemplateCallback'),
119
+ 'filter_condition_callback' => array($this, 'callbackColumnDescriptionTemplateFilterCallback')
120
+ ));
121
+
122
+ $actionsColumn = array(
123
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
124
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
125
+ 'align' => 'center',
126
+ 'width' => '130px',
127
+ 'type' => 'text',
128
+ 'field' => 'id',
129
+ 'sortable' => false,
130
+ 'filter' => false,
131
+ 'actions' => array()
132
+ );
133
+
134
+ $actions = array(
135
+ array(
136
+ 'caption' => Mage::helper('M2ePro')->__('Set Description Policy'),
137
+ 'field' => 'id',
138
+ 'onclick_action' => 'ListingGridHandlerObj.setDescriptionTemplateRowAction'
139
+ ),
140
+ array(
141
+ 'caption' => Mage::helper('M2ePro')->__('Reset Description Policy'),
142
+ 'field' => 'id',
143
+ 'onclick_action' => 'ListingGridHandlerObj.resetDescriptionTemplateRowAction'
144
+ )
145
+ );
146
+
147
+ $actionsColumn['actions'] = $actions;
148
+
149
+ $this->addColumn('actions', $actionsColumn);
150
+
151
+ return parent::_prepareColumns();
152
+ }
153
+
154
+ protected function _prepareMassaction()
155
+ {
156
+ $this->setMassactionIdField('listing_product_id');
157
+ $this->setMassactionIdFieldOnlyIndexValue(true);
158
+
159
+ // ---------------------------------------
160
+ $this->getMassactionBlock()->addItem('setDescriptionTemplate', array(
161
+ 'label' => Mage::helper('M2ePro')->__('Set Description Policy'),
162
+ 'url' => ''
163
+ ));
164
+
165
+ $this->getMassactionBlock()->addItem('resetDescriptionTemplate', array(
166
+ 'label' => Mage::helper('M2ePro')->__('Reset Description Policy'),
167
+ 'url' => ''
168
+ ));
169
+ // ---------------------------------------
170
+
171
+ return parent::_prepareMassaction();
172
+ }
173
+
174
+ //########################################
175
+
176
+ public function callbackColumnProductId($value, $row, $column, $isExport)
177
+ {
178
+ $productId = (int)$row->getData('entity_id');
179
+ $storeId = (int)$this->listing->getData('store_id');
180
+
181
+ $url = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
182
+ $htmlWithoutThumbnail = '<a href="' . $url . '" target="_blank">'.$productId.'</a>';
183
+
184
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
185
+ ->getGroupValue('/view/','show_products_thumbnails');
186
+
187
+ if (!$showProductsThumbnails) {
188
+ return $htmlWithoutThumbnail;
189
+ }
190
+
191
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
192
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
193
+ $magentoProduct->setProductId($productId);
194
+ $magentoProduct->setStoreId($storeId);
195
+
196
+ $thumbnail = $magentoProduct->getThumbnailImageLink();
197
+ if (is_null($thumbnail)) {
198
+ return $htmlWithoutThumbnail;
199
+ }
200
+
201
+ return <<<HTML
202
+ <a href="{$url}" target="_blank">
203
+ {$productId}
204
+ <hr style="border: 1px solid silver; border-bottom: none;">
205
+ <img src="{$thumbnail}" />
206
+ </a>
207
+ HTML;
208
+ }
209
+
210
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
211
+ {
212
+ if (strlen($productTitle) > 60) {
213
+ $productTitle = substr($productTitle, 0, 60) . '...';
214
+ }
215
+
216
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
217
+
218
+ $value = '<span>'.$productTitle.'</span>';
219
+
220
+ $sku = $row->getData('sku');
221
+
222
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
223
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($sku) . '<br/>';
224
+
225
+ $listingProductId = (int)$row->getData('id');
226
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
227
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
228
+
229
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
230
+ return $value;
231
+ }
232
+
233
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
234
+ ->getTypeModel()->getProductAttributes();
235
+
236
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
237
+ $value .= implode(', ', $productOptions);
238
+ $value .= '</div>';
239
+
240
+ return $value;
241
+ }
242
+
243
+ public function callbackColumnDescriptionTemplateCallback($value, $row, $column, $isExport)
244
+ {
245
+ $descriptionTemplateId = $row->getData('template_description_id');
246
+
247
+ if (empty($descriptionTemplateId)) {
248
+ $iconSrc = $this->getSkinUrl('M2ePro/images/warning.png');
249
+ $label = Mage::helper('M2ePro')->__('Not Selected');
250
+
251
+ return <<<HTML
252
+ <img src="{$iconSrc}" alt="">&nbsp;<span style="color: gray; font-style: italic;">{$label}</span>
253
+ HTML;
254
+ }
255
+
256
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
257
+ 'id' => $descriptionTemplateId
258
+ ));
259
+
260
+ /** @var Ess_M2ePro_Model_Amazon_Template_Description $descriptionTemplate */
261
+ $descriptionTemplate = Mage::helper('M2ePro/Component_Amazon')
262
+ ->getModel('Template_Description')->load($descriptionTemplateId);
263
+
264
+ $title = Mage::helper('M2ePro')->escapeHtml($descriptionTemplate->getData('title'));
265
+
266
+ return <<<HTML
267
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
268
+ HTML;
269
+ }
270
+
271
+ //########################################
272
+
273
+ protected function callbackFilterProductTitle($collection, $column)
274
+ {
275
+ $value = $column->getFilter()->getValue();
276
+
277
+ if ($value == null) {
278
+ return;
279
+ }
280
+
281
+ $collection->addFieldToFilter(
282
+ array(
283
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
284
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
285
+ )
286
+ );
287
+ }
288
+
289
+ // ---------------------------------------
290
+
291
+ protected function callbackColumnDescriptionTemplateFilterCallback($collection, $column)
292
+ {
293
+ $value = $column->getFilter()->getValue();
294
+
295
+ if ($value == null) {
296
+ return;
297
+ }
298
+
299
+ if ($value) {
300
+ $collection->addFieldToFilter('template_description_id', array('notnull' => null));
301
+ } else {
302
+ $collection->addFieldToFilter('template_description_id', array('null' => null));
303
+ }
304
+ }
305
+
306
+ //########################################
307
+
308
+ public function getRowUrl($row)
309
+ {
310
+ return false;
311
+ }
312
+
313
+ //########################################
314
+
315
+ protected function _toHtml()
316
+ {
317
+ $javascriptsMain = <<<HTML
318
+ <script type="text/javascript">
319
+
320
+ if (typeof ListingGridHandlerObj != 'undefined') {
321
+ ListingGridHandlerObj.afterInitPage();
322
+ }
323
+
324
+ Event.observe(window, 'load', function() {
325
+ setTimeout(function() {
326
+ ListingGridHandlerObj.afterInitPage();
327
+ }, 350);
328
+ });
329
+
330
+ </script>
331
+ HTML;
332
+
333
+ return parent::_toHtml() . $javascriptsMain;
334
+ }
335
+
336
+ //########################################
337
+
338
+ /**
339
+ * @return Ess_M2ePro_Model_Amazon_Listing
340
+ * @throws Exception
341
+ */
342
+ public function getListing()
343
+ {
344
+ if (!$listingId = $this->getRequest()->getParam('id')) {
345
+ throw new Ess_M2ePro_Model_Exception('Listing is not defined');
346
+ }
347
+
348
+ if (is_null($this->listing)) {
349
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
350
+ ->getObject('Listing', $listingId)->getChildObject();
351
+ }
352
+
353
+ return $this->listing;
354
+ }
355
+
356
+ //########################################
357
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/NewAsin/Manual/SkipPopup.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_NewAsin_Manual_SkipPopup
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonListingAddNewAsinManualPopup');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/manual/skip_popup.phtml');
24
+ }
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ parent::_beforeToHtml();
29
+
30
+ $url = $this->getUrl('*/*/index', array('_current' => true, 'step' => 3));
31
+
32
+ $data = array(
33
+ 'class' => 'next',
34
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
35
+ 'onclick' => 'setLocation(\''.$url.'\')',
36
+ );
37
+ $this->setChild('continue_button',$this->getLayout()->createBlock('adminhtml/widget_button')->setData($data));
38
+
39
+ return $this;
40
+ }
41
+
42
+ //########################################
43
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Review.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Review
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Review
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('listingProductReview');
21
+ $this->setData('component', Ess_M2ePro_Helper_Component_Amazon::NICK);
22
+ // ---------------------------------------
23
+
24
+ $this->_headerText = Mage::helper('M2ePro')->__('Congratulations');
25
+
26
+ $this->setTemplate('M2ePro/common/amazon/listing/add/review.phtml');
27
+ }
28
+
29
+ //########################################
30
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin.php ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin
10
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $listingId = $this->getRequest()->getParam('id');
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('searchAsinForListingProducts');
23
+ // ---------------------------------------
24
+
25
+ // Set header text
26
+ // ---------------------------------------
27
+ $this->_headerText = Mage::helper('M2ePro')->__("Search Existing Amazon Products (ASIN/ISBN)");
28
+ $this->_blockGroup = 'M2ePro';
29
+ $this->_controller = 'adminhtml_common_amazon_listing_add_searchAsin';
30
+ // ---------------------------------------
31
+
32
+ // Set buttons actions
33
+ // ---------------------------------------
34
+ $this->removeButton('back');
35
+ $this->removeButton('reset');
36
+ $this->removeButton('delete');
37
+ $this->removeButton('add');
38
+ $this->removeButton('save');
39
+ $this->removeButton('edit');
40
+ // ---------------------------------------
41
+
42
+ // ---------------------------------------
43
+ $url = $this->getUrl('*/*/removeAddedProducts', array(
44
+ 'id' => $listingId,
45
+ '_current' => true
46
+ ));
47
+ $this->_addButton('back', array(
48
+ 'label' => Mage::helper('M2ePro')->__('Back'),
49
+ 'onclick' => 'ListingGridHandlerObj.back_click(\'' . $url . '\')',
50
+ 'class' => 'back'
51
+ ));
52
+
53
+ // ---------------------------------------
54
+ $this->_addButton('auto_action', array(
55
+ 'label' => Mage::helper('M2ePro')->__('Edit Search Settings'),
56
+ 'onclick' => 'ListingGridHandlerObj.editSearchSettings(\'' .
57
+ Mage::helper('M2ePro')->__('Listing Search Settings') . '\' ,' .
58
+ $this->getListing()->getId() .
59
+ ');'
60
+ ));
61
+ // ---------------------------------------
62
+
63
+ // ---------------------------------------
64
+ $this->_addButton('save_and_go_to_listing_view', array(
65
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
66
+ 'onclick' => 'ListingGridHandlerObj.checkSearchResults('.$listingId.')',
67
+ 'class' => 'scalable next'
68
+ ));
69
+ // ---------------------------------------
70
+ }
71
+
72
+ public function getGridHtml()
73
+ {
74
+ $listing = Mage::helper('M2ePro/Component')->getCachedUnknownObject(
75
+ 'Listing', $this->getRequest()->getParam('id')
76
+ );
77
+
78
+ $viewHeaderBlock = $this->getLayout()->createBlock(
79
+ 'M2ePro/adminhtml_listing_view_header','',
80
+ array('listing' => $listing)
81
+ );
82
+
83
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_add_searchAsin_help');
84
+
85
+ $productSearchBlock = $this->getLayout()
86
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_productSearch_main');
87
+ // ---------------------------------------
88
+ $data = array(
89
+ 'id' => 'productSearch_cleanSuggest_button',
90
+ 'label' => Mage::helper('M2ePro')->__('Search ASIN/ISBN Manually'),
91
+ 'class' => 'productSearch_cleanSuggest_button',
92
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndManualSearch()'
93
+ );
94
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
95
+ $productSearchBlock->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
96
+ // ---------------------------------------
97
+
98
+ return $helpBlock->toHtml()
99
+ . $viewHeaderBlock->toHtml()
100
+ . $productSearchBlock->toHtml()
101
+ . parent::getGridHtml();
102
+ }
103
+
104
+ protected function _toHtml()
105
+ {
106
+ $helper = Mage::helper('M2ePro');
107
+
108
+ // TEXT
109
+ $createEmptyListingMessage = $helper->escapeJs($helper->__('Are you sure you want to create empty Listing?'));
110
+
111
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
112
+ $taskCompletedSuccessMessage = $helper->escapeJs(
113
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
114
+ );
115
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
116
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
117
+ ));
118
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
119
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
120
+ ));
121
+
122
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
123
+ 'Sending %product_title% Product(s) data on Amazon.')
124
+ );
125
+
126
+ $selectItemsMessage = $helper->escapeJs(
127
+ $helper->__('Please select the Products you want to perform the Action on.')
128
+ );
129
+
130
+ $assignString = Mage::helper('M2ePro')->__('Assign');
131
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
132
+
133
+ $enterProductSearchQueryMessage = $helper->escapeJs(
134
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
135
+ );
136
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
137
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
138
+ $autoMapAsinErrorMessage = $helper->escapeJs(
139
+ $helper->__('Server is currently unavailable. Please try again later.')
140
+ );
141
+ $newAsinNotAvailable = $helper->escapeJs(
142
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
143
+ );
144
+ $notSynchronizedMarketplace = $helper->escapeJs(
145
+ $helper->__(
146
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
147
+ ).' '.
148
+ $helper->__(
149
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
150
+ )
151
+ );
152
+
153
+ $newAsinPopupTitle = $helper->escapeJs($helper->__('New ASIN/ISBN creation'));
154
+ $notCompletedPopupTitle = $helper->escapeJs(
155
+ $helper->__('Adding of New Products to the Listing was not competed')
156
+ );
157
+ // ---------------------------------------
158
+
159
+ // URL
160
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
161
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
162
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
163
+ $getCategoriesByAsin = $this->getUrl('*/adminhtml_common_amazon_listing/getCategoriesByAsin');
164
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
165
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
166
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
167
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
168
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
169
+
170
+ $viewSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/viewSearchSettings');
171
+ $saveSearchSettings = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/saveSearchSettings');
172
+
173
+ $checkSearchResults = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/checkSearchResults', array(
174
+ 'id' => $this->getListing()->getId()
175
+ ));
176
+
177
+ $showNewAsinStep = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/showNewAsinStep', array(
178
+ 'id' => $this->getListing()->getId()
179
+ ));
180
+
181
+ $addProductsUrl = $this->getUrl(
182
+ '*/adminhtml_common_listing_productAdd/addProducts', array(
183
+ 'component' => $this->getData('component')
184
+ )
185
+ );
186
+ $backUrl = $this->getUrl('*/*/index');
187
+ // ---------------------------------------
188
+
189
+ $showNotCompletedPopup = '';
190
+ if ($this->getRequest()->getParam('not_completed', false)) {
191
+ $showNotCompletedPopup = 'ListingGridHandlerObj.showNotCompletedPopup();';
192
+ }
193
+
194
+ $javascript = <<<HTML
195
+ <script type="text/javascript">
196
+ if (typeof M2ePro == 'undefined') {
197
+ M2ePro = {};
198
+ M2ePro.url = {};
199
+ M2ePro.formData = {};
200
+ M2ePro.customData = {};
201
+ M2ePro.text = {};
202
+ }
203
+
204
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
205
+ M2ePro.text.create_empty_listing_message = '{$createEmptyListingMessage}';
206
+
207
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
208
+
209
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
210
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
211
+
212
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
213
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
214
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
215
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
216
+
217
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
218
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
219
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
220
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
221
+
222
+ M2ePro.text.assign = '{$assignString}';
223
+ M2ePro.text.confirm = '{$textConfirm}';
224
+
225
+ M2ePro.text.new_asin_popup_title = '{$newAsinPopupTitle}';
226
+ M2ePro.text.not_completed_popup_title = '{$notCompletedPopupTitle}';
227
+
228
+ M2ePro.url.add_products = '{$addProductsUrl}';
229
+ M2ePro.url.back = '{$backUrl}';
230
+
231
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
232
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
233
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
234
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
235
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
236
+ M2ePro.url.getCategoriesByAsin = '{$getCategoriesByAsin}';
237
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
238
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
239
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
240
+
241
+ M2ePro.url.viewSearchSettings = '{$viewSearchSettings}';
242
+ M2ePro.url.saveSearchSettings = '{$saveSearchSettings}';
243
+
244
+ M2ePro.url.checkSearchResults = '{$checkSearchResults}';
245
+ M2ePro.url.showNewAsinStep = '{$showNewAsinStep}';
246
+
247
+ Event.observe(window, 'load', function() {
248
+
249
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
250
+
251
+ ListingGridHandlerObj = new CommonAmazonListingSearchAsinGridHandler(
252
+ '{$this->getChild('grid')->getId()}',
253
+ {$this->getListing()->getId()}
254
+ );
255
+
256
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
257
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
258
+
259
+ ListingProgressBarObj = new ProgressBar('search_asin_progress_bar');
260
+ GridWrapperObj = new AreaWrapper('search_asin_products_container');
261
+
262
+ {$showNotCompletedPopup}
263
+ });
264
+
265
+ </script>
266
+ HTML;
267
+
268
+ // ---------------------------------------
269
+ $notCompletedPopup = $this->getLayout()->createBlock(
270
+ 'M2ePro/adminhtml_common_amazon_listing_add_searchAsin_notCompleted');
271
+ // ---------------------------------------
272
+
273
+ return $notCompletedPopup->toHtml() .
274
+ $javascript .
275
+ '<div id="search_asin_progress_bar"></div>' .
276
+ '<div id="search_asin_products_container">' .
277
+ parent::_toHtml() .
278
+ '</div>';
279
+ }
280
+
281
+ //########################################
282
+
283
+ public function getListing()
284
+ {
285
+ if (!$listingId = $this->getRequest()->getParam('id')) {
286
+ throw new Ess_M2ePro_Model_Exception('Listing is not defined');
287
+ }
288
+
289
+ if (is_null($this->listing)) {
290
+ $this->listing = Mage::helper('M2ePro/Component_Amazon')
291
+ ->getObject('Listing', $listingId)->getChildObject();
292
+ }
293
+
294
+ return $this->listing;
295
+ }
296
+
297
+ //########################################
298
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/Grid.php ADDED
@@ -0,0 +1,701 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_Grid
10
+ extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+ /** @var Ess_M2ePro_Model_Listing */
13
+ private $listing = NULL;
14
+
15
+ const SEARCH_SETTINGS_STATUS_NONE = 'none';
16
+ const SEARCH_SETTINGS_STATUS_COMPLETED = 'completed';
17
+
18
+ //########################################
19
+
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ $listingData = $this->getListing()->getData();
25
+
26
+ // Initialization block
27
+ // ---------------------------------------
28
+ $this->setId('searchAsinForListingProductsGrid'.$listingData['id']);
29
+ // ---------------------------------------
30
+
31
+ // Set default values
32
+ // ---------------------------------------
33
+ $this->setDefaultSort('product_id');
34
+ $this->setDefaultDir('DESC');
35
+ $this->setUseAjax(true);
36
+ // ---------------------------------------
37
+ }
38
+
39
+ //########################################
40
+
41
+ protected function _prepareCollection()
42
+ {
43
+ $listingProductsIds = $this->getListing()->getSetting('additional_data', 'adding_listing_products_ids');
44
+ $listingData = $this->getListing()->getData();
45
+
46
+ // Get collection
47
+ // ---------------------------------------
48
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
49
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
50
+ Mage::getModel('catalog/product')->getResource());
51
+ $collection->setStoreId($listingData['store_id'])
52
+ ->setListingProductModeOn()
53
+ ->addAttributeToSelect('name')
54
+ ->addAttributeToSelect('sku')
55
+ ->joinTable(
56
+ array('cisi' => 'cataloginventory/stock_item'),
57
+ 'product_id=entity_id',
58
+ array('qty' => 'qty'),
59
+ '{{table}}.stock_id=1',
60
+ 'left'
61
+ );
62
+
63
+ // ---------------------------------------
64
+
65
+ $collection->joinTable(
66
+ array('lp' => 'M2ePro/Listing_Product'),
67
+ 'product_id=entity_id',
68
+ array(
69
+ 'id' => 'id',
70
+ 'component_mode' => 'component_mode',
71
+ 'amazon_status' => 'status',
72
+ 'additional_data' => 'additional_data'
73
+ ),
74
+ array(
75
+ 'listing_id' => (int)$listingData['id']
76
+ )
77
+ );
78
+ $collection->joinTable(
79
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
80
+ 'listing_product_id=id',
81
+ array(
82
+ 'general_id' => 'general_id',
83
+ 'general_id_search_info' => 'general_id_search_info',
84
+ 'search_settings_status' => 'search_settings_status',
85
+ 'search_settings_data' => 'search_settings_data',
86
+ 'variation_child_statuses' => 'variation_child_statuses',
87
+ 'amazon_sku' => 'sku',
88
+ 'online_qty' => 'online_qty',
89
+ 'online_price' => 'online_price',
90
+ 'online_sale_price' => 'online_sale_price',
91
+ 'is_afn_channel' => 'is_afn_channel',
92
+ 'is_general_id_owner' => 'is_general_id_owner',
93
+ 'is_variation_parent' => 'is_variation_parent',
94
+ ),
95
+ '{{table}}.variation_parent_id is NULL'
96
+ );
97
+
98
+ $collection->getSelect()->where('lp.id IN (?)', $listingProductsIds);
99
+
100
+ // ---------------------------------------
101
+
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 = <<<HTML
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
+ HTML;
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 Ess_M2ePro_Model_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,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_Help extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingViewHelp');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/help.phtml');
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NewAsinPopup.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_NewAsinPopup extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('searchAsinNewAsinPopup');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/new_asin_popup.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $data = array(
28
+ 'label' => Mage::helper('M2ePro')->__('Yes'),
29
+ 'onclick' => 'ListingGridHandlerObj.newAsinPopupYesClick()'
30
+ );
31
+ $yesButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
32
+ $this->setChild('yesBtn', $yesButton);
33
+
34
+ $data = array(
35
+ 'label' => Mage::helper('M2ePro')->__('No'),
36
+ 'onclick' => 'ListingGridHandlerObj.noAsinPopupNoClick()'
37
+ );
38
+ $noButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
39
+ $this->setChild('noBtn', $noButton);
40
+ }
41
+
42
+ //########################################
43
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/NotCompleted.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_NotCompleted extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('searchAsinNotCompletedPopup');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/not_completed.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $data = array(
28
+ 'label' => Mage::helper('M2ePro')->__('Close'),
29
+ 'onclick' => 'Windows.getFocusedWindow().close();'
30
+ );
31
+ $closeButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
32
+ $this->setChild('closeBtn', $closeButton);
33
+ }
34
+
35
+ //########################################
36
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/SearchAsin/SearchSettings.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_SearchAsin_SearchSettings
10
+ extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ protected $component;
13
+
14
+ //########################################
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('searchSettings');
23
+ // ---------------------------------------
24
+
25
+ $this->setTemplate('M2ePro/common/amazon/listing/add/search_asin/search_settings.phtml');
26
+ }
27
+
28
+ protected function _prepareForm()
29
+ {
30
+ // Prepare action
31
+ // ---------------------------------------
32
+ $action = $this->getUrl('*/adminhtml_common_amazon_listing_productAdd/saveSearchSettings', array(
33
+ 'id' => (int)$this->getRequest()->getParam('id')
34
+ ));
35
+ // ---------------------------------------
36
+
37
+ $form = new Varien_Data_Form(array(
38
+ 'id' => 'search_settings_form',
39
+ 'action' => $action,
40
+ 'method' => 'post'
41
+ ));
42
+
43
+ $form->setUseContainer(true);
44
+ $this->setForm($form);
45
+
46
+ return parent::_prepareForm();
47
+ }
48
+
49
+ protected function _beforeToHtml()
50
+ {
51
+ $child = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_search');
52
+
53
+ $this->setChild('content', $child);
54
+
55
+ return parent::_beforeToHtml();
56
+ }
57
+
58
+ //########################################
59
+
60
+ protected function _toHtml()
61
+ {
62
+ $buttonSave = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
63
+ 'id' => 'save_search_settings',
64
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
65
+ 'style' => 'float: right; margin: 0 0 7px 5px;',
66
+ 'onclick' => 'ListingGridHandlerObj.saveSearchSettings()'
67
+ ));
68
+
69
+ $this->setChild('save_search_settings', $buttonSave);
70
+
71
+ return parent::_toHtml();
72
+ }
73
+
74
+ //########################################
75
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/General.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Tabs_General
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_General
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->sessionKey = 'amazon_listing_create';
21
+ $this->setId('amazonListingAddTabsGeneral');
22
+ $this->setTemplate('M2ePro/common/amazon/listing/add/tabs/general.phtml');
23
+ // ---------------------------------------
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Search.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Tabs_Search
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Search
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->sessionKey = 'amazon_listing_create';
21
+ $this->setId('amazonListingAddTabsGeneral');
22
+ $this->setTemplate('M2ePro/common/amazon/listing/add/tabs/search.phtml');
23
+ // ---------------------------------------
24
+ }
25
+
26
+ //########################################
27
+
28
+ protected function getDefaults()
29
+ {
30
+ return self::getDefaultFieldsValues();
31
+ }
32
+
33
+ static function getDefaultFieldsValues()
34
+ {
35
+ return array(
36
+ 'general_id_mode' => Ess_M2ePro_Model_Amazon_Listing::GENERAL_ID_MODE_NOT_SET,
37
+ 'general_id_custom_attribute' => '',
38
+
39
+ 'worldwide_id_mode' => Ess_M2ePro_Model_Amazon_Listing::WORLDWIDE_ID_MODE_NOT_SET,
40
+ 'worldwide_id_custom_attribute' => '',
41
+
42
+ 'search_by_magento_title_mode' => Ess_M2ePro_Model_Amazon_Listing::SEARCH_BY_MAGENTO_TITLE_MODE_NONE
43
+ );
44
+ }
45
+
46
+ //########################################
47
+
48
+ public function isEditMode()
49
+ {
50
+ return !!$this->getRequest()->getParam('id');
51
+ }
52
+
53
+ //########################################
54
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Add/Tabs/Selling.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Add_Tabs_Selling
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Selling
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->component = Ess_M2ePro_Helper_Component_Amazon::NICK;
21
+ $this->sessionKey = 'amazon_listing_create';
22
+ $this->setId('amazonListingAddTabsSelling');
23
+ $this->setTemplate('M2ePro/common/amazon/listing/add/tabs/selling.phtml');
24
+ // ---------------------------------------
25
+ }
26
+
27
+ //########################################
28
+
29
+ protected function _beforeToHtml()
30
+ {
31
+ $buttonBlock = $this->getLayout()
32
+ ->createBlock('adminhtml/widget_button')
33
+ ->setData(array(
34
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
35
+ 'onclick' => "AmazonListingChannelSettingsHandlerObj.appendToText"
36
+ ."('condition_note_custom_attribute', 'condition_note_value');",
37
+ 'class' => 'condition_note_value_insert_button'
38
+ ));
39
+ $this->setChild('condition_note_value_insert_button', $buttonBlock);
40
+
41
+ return parent::_beforeToHtml();
42
+ }
43
+
44
+ //########################################
45
+
46
+ protected function getDefaults()
47
+ {
48
+ return self::getDefaultFieldsValues();
49
+ }
50
+
51
+ static function getDefaultFieldsValues()
52
+ {
53
+ return array(
54
+ 'sku_mode' => Ess_M2ePro_Model_Amazon_Listing::SKU_MODE_DEFAULT,
55
+ 'sku_custom_attribute' => '',
56
+ 'sku_modification_mode' => Ess_M2ePro_Model_Amazon_Listing::SKU_MODIFICATION_MODE_NONE,
57
+ 'sku_modification_custom_value' => '',
58
+ 'generate_sku_mode' => Ess_M2ePro_Model_Amazon_Listing::GENERATE_SKU_MODE_NO,
59
+
60
+ 'template_selling_format_id' => '',
61
+ 'template_synchronization_id' => '',
62
+
63
+ 'condition_mode' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_MODE_DEFAULT,
64
+ 'condition_value' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_NEW,
65
+ 'condition_custom_attribute' => '',
66
+ 'condition_note_mode' => Ess_M2ePro_Model_Amazon_Listing::CONDITION_NOTE_MODE_NONE,
67
+ 'condition_note_value' => '',
68
+
69
+ 'image_main_mode' => Ess_M2ePro_Model_Amazon_Listing::IMAGE_MAIN_MODE_NONE,
70
+ 'image_main_attribute' => '',
71
+ 'gallery_images_mode' => Ess_M2ePro_Model_Amazon_Listing::GALLERY_IMAGES_MODE_NONE,
72
+ 'gallery_images_limit' => '',
73
+ 'gallery_images_attribute' => '',
74
+
75
+ 'gift_wrap_mode' => Ess_M2ePro_Model_Amazon_Listing::GIFT_WRAP_MODE_NO,
76
+ 'gift_wrap_attribute' => '',
77
+
78
+ 'gift_message_mode' => Ess_M2ePro_Model_Amazon_Listing::GIFT_MESSAGE_MODE_NO,
79
+ 'gift_message_attribute' => '',
80
+
81
+ 'handling_time_mode' => Ess_M2ePro_Model_Amazon_Listing::HANDLING_TIME_MODE_NONE,
82
+ 'handling_time_value' => '',
83
+ 'handling_time_custom_attribute' => '',
84
+
85
+ 'restock_date_mode' => Ess_M2ePro_Model_Amazon_Listing::RESTOCK_DATE_MODE_NONE,
86
+ 'restock_date_value' => Mage::helper('M2ePro')->getCurrentTimezoneDate(),
87
+ 'restock_date_custom_attribute' => ''
88
+ );
89
+ }
90
+
91
+ //########################################
92
+
93
+ public function isEditMode()
94
+ {
95
+ return !!$this->getRequest()->getParam('id');
96
+ }
97
+
98
+ //########################################
99
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode
11
+ {
12
+ //########################################
13
+
14
+ public function getHelpPageUrl()
15
+ {
16
+ return Mage::helper('M2ePro/Module_Support')
17
+ ->getDocumentationUrl(NULL, 'pages/viewpage.action?pageId=18188381');
18
+ }
19
+
20
+ //########################################
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Category
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category
11
+ {
12
+ //########################################
13
+
14
+ protected function prepareGroupsGrid()
15
+ {
16
+ $groupGrid = $this->getLayout()
17
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_autoAction_mode_category_group_grid');
18
+ $groupGrid->prepareGrid();
19
+ $this->setChild('group_grid', $groupGrid);
20
+
21
+ return $groupGrid;
22
+ }
23
+
24
+ //########################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Form.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Category_Form
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Form
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/auto_action/mode/category/form.phtml');
19
+ }
20
+
21
+ //########################################
22
+
23
+ public function getDefault()
24
+ {
25
+ return array(
26
+ 'id' => NULL,
27
+ 'title' => NULL,
28
+ 'category_id' => NULL,
29
+ 'adding_mode' => Ess_M2ePro_Model_Listing::ADDING_MODE_NONE,
30
+ 'deleting_mode' => Ess_M2ePro_Model_Listing::DELETING_MODE_NONE,
31
+ 'adding_add_not_visible' => Ess_M2ePro_Model_Listing::AUTO_ADDING_ADD_NOT_VISIBLE_YES,
32
+ 'adding_description_template_id' => NULL
33
+ );
34
+ }
35
+
36
+ //########################################
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Category/Group/Grid.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Category_Group_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Group_Grid
11
+ {
12
+ //########################################
13
+
14
+ public function getGridUrl()
15
+ {
16
+ return $this->getUrl('*/adminhtml_common_listing_autoAction/getCategoryGroupGrid', array('_current' => true));
17
+ }
18
+
19
+ //########################################
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Global.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Global
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Global
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/auto_action/mode/global.phtml');
19
+ }
20
+
21
+ //########################################
22
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/AutoAction/Mode/Website.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_AutoAction_Mode_Website
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Website
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/auto_action/mode/website.phtml');
19
+ }
20
+
21
+ //########################################
22
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingEdit');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_amazon_listing';
22
+ $this->_mode = 'edit';
23
+ // ---------------------------------------
24
+
25
+ // Set header text
26
+ // ---------------------------------------
27
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
28
+
29
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
30
+ $headerText = Mage::helper('M2ePro')->__(
31
+ 'Edit %component_name% Listing Settings "%listing_title%"',
32
+ Mage::helper('M2ePro/Component_Amazon')->getTitle(),
33
+ $this->escapeHtml($listingData['title'])
34
+ );
35
+ } else {
36
+ $headerText = Mage::helper('M2ePro')->__(
37
+ 'Edit Listing Settings "%listing_title%"',
38
+ $this->escapeHtml($listingData['title'])
39
+ );
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
56
+ // ---------------------------------------
57
+ $url = Mage::helper('M2ePro')->getBackUrl(
58
+ '*/adminhtml_common_listing/index',
59
+ array(
60
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
61
+ )
62
+ );
63
+ $this->_addButton('back', array(
64
+ 'label' => Mage::helper('M2ePro')->__('Back'),
65
+ 'onclick' => 'CommonListingSettingsHandlerObj.back_click(\''.$url.'\')',
66
+ 'class' => 'back'
67
+ ));
68
+ // ---------------------------------------
69
+ }
70
+
71
+ // ---------------------------------------
72
+ $this->_addButton('auto_action', array(
73
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
74
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
75
+ ));
76
+ // ---------------------------------------
77
+
78
+ $backUrl = Mage::helper('M2ePro')->getBackUrlParam('list');
79
+
80
+ // ---------------------------------------
81
+ $url = $this->getUrl(
82
+ '*/adminhtml_common_amazon_listing/save',
83
+ array(
84
+ 'id' => $listingData['id'],
85
+ 'back' => $backUrl
86
+ )
87
+ );
88
+ $this->_addButton('save', array(
89
+ 'label' => Mage::helper('M2ePro')->__('Save'),
90
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_click(\'' . $url . '\')',
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' => 'CommonListingSettingsHandlerObj.save_and_edit_click(\''.$url.'\', 1)',
99
+ 'class' => 'save'
100
+ ));
101
+ // ---------------------------------------
102
+ }
103
+
104
+ //########################################
105
+
106
+ protected function _beforeToHtml()
107
+ {
108
+ parent::_beforeToHtml();
109
+
110
+ // ---------------------------------------
111
+ $tabs = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_edit_tabs');
112
+ $this->setChild('tabs', $tabs);
113
+ // ---------------------------------------
114
+
115
+ return $this;
116
+ }
117
+
118
+ //########################################
119
+
120
+ public function getFormHtml()
121
+ {
122
+ $listing = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
123
+ 'Listing', $this->getRequest()->getParam('id')
124
+ );
125
+
126
+ $viewHeaderBlock = $this->getLayout()->createBlock(
127
+ 'M2ePro/adminhtml_listing_view_header','',
128
+ array('listing' => $listing)
129
+ );
130
+
131
+ $tabs = $this->getChild('tabs');
132
+
133
+ $urls = Mage::helper('M2ePro')->getControllerActions(
134
+ 'adminhtml_common_listing_autoAction',
135
+ array(
136
+ 'listing_id' => $this->getRequest()->getParam('id'),
137
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
138
+ )
139
+ );
140
+ $urls = json_encode($urls);
141
+
142
+ /** @var $helper Ess_M2ePro_Helper_Data */
143
+ $helper = Mage::helper('M2ePro');
144
+
145
+ $translations = json_encode(array(
146
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
147
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
148
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
149
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
150
+ ));
151
+
152
+ $js = <<<HTML
153
+ <script type="text/javascript">
154
+
155
+ M2ePro.url.add({$urls});
156
+ M2ePro.translator.add({$translations});
157
+
158
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
159
+
160
+ </script>
161
+ HTML;
162
+
163
+ return $viewHeaderBlock->toHtml() . $tabs->toHtml() . parent::getFormHtml() . $js;
164
+ }
165
+
166
+ //########################################
167
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Form.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingEditForm');
20
+ // ---------------------------------------
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/adminhtml_common_amazon_listing/save'),
28
+ 'method' => 'post',
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ //########################################
39
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Edit/Tabs.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingEditTabs');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('widget/tabshoriz.phtml');
23
+ $this->setDestElementId('edit_form');
24
+ }
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ $this->addTab('selling', array(
29
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
30
+ 'title' => Mage::helper('M2ePro')->__('Selling Settings'),
31
+ 'content' => $this->getLayout()
32
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_selling')
33
+ ->toHtml(),
34
+ ));
35
+
36
+ $this->addTab('search', array(
37
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
38
+ 'title' => Mage::helper('M2ePro')->__('Search Settings'),
39
+ 'content' => $this->getLayout()
40
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_add_tabs_search')
41
+ ->toHtml(),
42
+ ));
43
+
44
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'selling'));
45
+
46
+ return parent::_beforeToHtml();
47
+ }
48
+
49
+ //########################################
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Grid.php ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingGrid');
20
+ // ---------------------------------------
21
+ }
22
+
23
+ protected function _prepareCollection()
24
+ {
25
+ // Update statistic table values
26
+ Mage::getResourceModel('M2ePro/Amazon_Listing')->updateStatisticColumns();
27
+
28
+ // Get collection of listings
29
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing');
30
+
31
+ // Set global filters
32
+ // ---------------------------------------
33
+ $filterSellingFormatTemplate = $this->getRequest()->getParam('filter_amazon_selling_format_template');
34
+ $filterSynchronizationTemplate = $this->getRequest()->getParam('filter_amazon_synchronization_template');
35
+
36
+ if ($filterSellingFormatTemplate != 0) {
37
+ $collection->addFieldToFilter(
38
+ 'second_table.template_selling_format_id', (int)$filterSellingFormatTemplate
39
+ );
40
+ }
41
+
42
+ if ($filterSynchronizationTemplate != 0) {
43
+ $collection->addFieldToFilter(
44
+ 'second_table.template_synchronization_id', (int)$filterSynchronizationTemplate
45
+ );
46
+ }
47
+ // ---------------------------------------
48
+
49
+ // join marketplace and accounts
50
+ // ---------------------------------------
51
+ $collection->getSelect()
52
+ ->join(array('a'=>Mage::getResourceModel('M2ePro/Account')->getMainTable()),
53
+ '(`a`.`id` = `main_table`.`account_id`)',
54
+ array('account_title'=>'title'))
55
+ ->join(array('m'=>Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
56
+ '(`m`.`id` = `main_table`.`marketplace_id`)',
57
+ array('marketplace_title'=>'title'));
58
+ // ---------------------------------------
59
+
60
+ $this->setCollection($collection);
61
+
62
+ return parent::_prepareCollection();
63
+ }
64
+
65
+ //########################################
66
+
67
+ protected function _prepareMassaction()
68
+ {
69
+ // Set massaction identifiers
70
+ // ---------------------------------------
71
+ $this->setMassactionIdField('main_table.id');
72
+ $this->getMassactionBlock()->setFormFieldName('ids');
73
+ // ---------------------------------------
74
+
75
+ // Set clear log action
76
+ // ---------------------------------------
77
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
78
+ '*/adminhtml_common_listing/index',
79
+ array(
80
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
81
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
82
+ )
83
+ );
84
+
85
+ $this->getMassactionBlock()->addItem('clear_logs', array(
86
+ 'label' => Mage::helper('M2ePro')->__('Clear Log(s)'),
87
+ 'url' => $this->getUrl('*/adminhtml_listing/clearLog', array('back' => $backUrl)),
88
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
89
+ ));
90
+ // ---------------------------------------
91
+
92
+ // Set remove listings action
93
+ // ---------------------------------------
94
+ $this->getMassactionBlock()->addItem('delete_listings', array(
95
+ 'label' => Mage::helper('M2ePro')->__('Delete Listing(s)'),
96
+ 'url' => $this->getUrl('*/adminhtml_common_amazon_listing/delete', array('back' => $backUrl)),
97
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
98
+ ));
99
+ // ---------------------------------------
100
+
101
+ return parent::_prepareMassaction();
102
+ }
103
+
104
+ //########################################
105
+
106
+ protected function getColumnActionsItems()
107
+ {
108
+ $helper = Mage::helper('M2ePro');
109
+ $backUrl = $helper->makeBackUrlParam(
110
+ '*/adminhtml_common_listing/index',
111
+ array(
112
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
113
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
114
+ )
115
+ );
116
+
117
+ $actions = array(
118
+ 'manageProducts' => array(
119
+ 'caption' => $helper->__('Manage'),
120
+ 'group' => 'products_actions',
121
+ 'field' => 'id',
122
+ 'url' => array(
123
+ 'base' => '*/adminhtml_common_amazon_listing/view',
124
+ 'params' => array('back' => $backUrl)
125
+ )
126
+ ),
127
+
128
+ 'addProductsFromProductsList' => array(
129
+ 'caption' => $helper->__('Add From Products List'),
130
+ 'group' => 'products_actions',
131
+ 'field' => 'id',
132
+ 'url' => array(
133
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
134
+ 'params' => array(
135
+ 'back' => $backUrl,
136
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
137
+ 'step' => 2,
138
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
139
+ )
140
+ )
141
+ ),
142
+
143
+ 'addProductsFromCategories' => array(
144
+ 'caption' => $helper->__('Add From Categories'),
145
+ 'group' => 'products_actions',
146
+ 'field' => 'id',
147
+ 'url' => array(
148
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
149
+ 'params' => array(
150
+ 'back' => $backUrl,
151
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
152
+ 'step' => 2,
153
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
154
+ )
155
+ )
156
+ ),
157
+
158
+ 'automaticActions' => array(
159
+ 'caption' => $helper->__('Auto Add/Remove Rules'),
160
+ 'group' => 'products_actions',
161
+ 'field' => 'id',
162
+ 'url' => array(
163
+ 'base' => '*/adminhtml_common_amazon_listing/view',
164
+ 'params' => array(
165
+ 'back' => $backUrl,
166
+ 'auto_actions' => 1
167
+ )
168
+ )
169
+ ),
170
+
171
+ 'viewLog' => array(
172
+ 'caption' => $helper->__('View Log'),
173
+ 'group' => 'other',
174
+ 'field' => 'id',
175
+ 'url' => array(
176
+ 'base' => '*/adminhtml_common_log/listing',
177
+ 'params' => array(
178
+ 'back' => $backUrl,
179
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON
180
+ )
181
+ )
182
+ ),
183
+
184
+ 'clearLogs' => array(
185
+ 'caption' => $helper->__('Clear Log'),
186
+ 'confirm' => $helper->__('Are you sure?'),
187
+ 'group' => 'other',
188
+ 'field' => 'id',
189
+ 'url' => array(
190
+ 'base' => '*/adminhtml_listing/clearLog',
191
+ 'params' => array(
192
+ 'back' => $backUrl
193
+ )
194
+ )
195
+ ),
196
+
197
+ 'deleteListing' => array(
198
+ 'caption' => $helper->__('Delete Listing'),
199
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
200
+ 'group' => 'other',
201
+ 'field' => 'id',
202
+ 'url' => array(
203
+ 'base' => '*/adminhtml_common_amazon_listing/delete',
204
+ 'params' => array(
205
+ 'back' => $backUrl
206
+ )
207
+ )
208
+ ),
209
+
210
+ 'editListingTitle' => array(
211
+ 'caption' => $helper->__('Title'),
212
+ 'group' => 'edit_actions',
213
+ 'confirm' => $helper->__('Are you sure?'),
214
+ 'field' => 'id',
215
+ 'onclick_action' => 'editListingTitle'
216
+ ),
217
+
218
+ 'sellingSetting' => array(
219
+ 'caption' => $helper->__('Selling'),
220
+ 'group' => 'edit_actions',
221
+ 'field' => 'id',
222
+ 'url' => array(
223
+ 'base' => '*/adminhtml_common_amazon_listing/edit',
224
+ 'params' => array(
225
+ 'back' => $backUrl,
226
+ 'tab' => 'selling'
227
+ )
228
+ )
229
+ ),
230
+
231
+ 'searchSetting' => array(
232
+ 'caption' => $helper->__('Search'),
233
+ 'group' => 'edit_actions',
234
+ 'field' => 'id',
235
+ 'url' => array(
236
+ 'base' => '*/adminhtml_common_amazon_listing/edit',
237
+ 'params' => array(
238
+ 'back' => $backUrl,
239
+ 'tab' => 'search'
240
+ )
241
+ )
242
+ )
243
+ );
244
+
245
+ return $actions;
246
+ }
247
+
248
+ //########################################
249
+
250
+ public function callbackColumnSoldProducts($value, $row, $column, $isExport)
251
+ {
252
+ return $this->getColumnValue($value);
253
+ }
254
+
255
+ public function callbackColumnTitle($value, $row, $column, $isExport)
256
+ {
257
+ $value = '<span id="listing_title_'.$row->getId().'">' .
258
+ Mage::helper('M2ePro')->escapeHtml($value) .
259
+ '</span>';
260
+
261
+ /* @var $row Ess_M2ePro_Model_Listing */
262
+ $accountTitle = $row->getData('account_title');
263
+ $marketplaceTitle = $row->getData('marketplace_title');
264
+
265
+ $storeModel = Mage::getModel('core/store')->load($row->getStoreId());
266
+ $storeView = $storeModel->getWebsite()->getName();
267
+ if (strtolower($storeView) != 'admin') {
268
+ $storeView .= ' > '.$storeModel->getGroup()->getName();
269
+ $storeView .= ' > '.$storeModel->getName();
270
+ } else {
271
+ $storeView = Mage::helper('M2ePro')->__('Admin (Default Values)');
272
+ }
273
+
274
+ $account = Mage::helper('M2ePro')->__('Account');
275
+ $marketplace = Mage::helper('M2ePro')->__('Marketplace');
276
+ $store = Mage::helper('M2ePro')->__('Magento Store View');
277
+
278
+ $value .= <<<HTML
279
+ <div>
280
+ <span style="font-weight: bold">{$account}</span>: <span style="color: #505050">{$accountTitle}</span><br/>
281
+ <span style="font-weight: bold">{$marketplace}</span>: <span style="color: #505050">{$marketplaceTitle}</span><br/>
282
+ <span style="font-weight: bold">{$store}</span>: <span style="color: #505050">{$storeView}</span>
283
+ </div>
284
+ HTML;
285
+
286
+ return $value;
287
+ }
288
+
289
+ //########################################
290
+
291
+ protected function callbackFilterTitle($collection, $column)
292
+ {
293
+ $value = $column->getFilter()->getValue();
294
+
295
+ if ($value == null) {
296
+ return;
297
+ }
298
+
299
+ $collection->getSelect()->where('main_table.title LIKE ? OR m.title LIKE ? OR a.title LIKE ?',
300
+ '%'. $value .'%');
301
+ }
302
+
303
+ //########################################
304
+
305
+ public function getGridUrl()
306
+ {
307
+ return $this->getUrl('*/adminhtml_common_amazon_listing/listingGrid', array('_current'=>true));
308
+ }
309
+
310
+ public function getRowUrl($row)
311
+ {
312
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
313
+ '*/adminhtml_common_listing/index',
314
+ array(
315
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
316
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
317
+ )
318
+ );
319
+
320
+ return $this->getUrl(
321
+ '*/adminhtml_common_amazon_listing/view',
322
+ array(
323
+ 'id' => $row->getId(),
324
+ 'back' => $backUrl
325
+ )
326
+ );
327
+ }
328
+
329
+ //########################################
330
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/Grid.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Other_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Other_Grid
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setId('amazonListingOtherGrid');
19
+ }
20
+
21
+ //########################################
22
+
23
+ protected function _prepareCollection()
24
+ {
25
+ $this->prepareCacheData();
26
+
27
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
28
+ $collection->getSelect()->group(array('account_id','marketplace_id'));
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
+ 'type' => 'text',
42
+ 'sortable' => false,
43
+ 'frame_callback' => array($this, 'callbackColumnMarketplace')
44
+ ), 'account');
45
+
46
+ return parent::_prepareColumns();
47
+ }
48
+
49
+ //########################################
50
+
51
+ public function callbackColumnMarketplace($value, $row, $column, $isExport)
52
+ {
53
+ $marketplaceTitle = Mage::helper('M2ePro/Component_Amazon')
54
+ ->getCachedObject('Marketplace',$row->getData('marketplace_id'))
55
+ ->getTitle();
56
+ return Mage::helper('M2ePro')->escapeHtml($marketplaceTitle);
57
+ }
58
+
59
+ public function callbackColumnTotalProducts($value, $row, $column, $isExport)
60
+ {
61
+ $accountId = $row->getAccountId();
62
+ $marketplaceId = $row->getMarketplaceId();
63
+ $key = $accountId . ',' . $marketplaceId;
64
+
65
+ $value = $this->cacheData[$key]['total_items'];
66
+
67
+ if (is_null($value) || $value === '') {
68
+ $value = Mage::helper('M2ePro')->__('N/A');
69
+ } else if ($value <= 0) {
70
+ $value = '<span style="color: red;">0</span>';
71
+ }
72
+
73
+ return $value;
74
+ }
75
+
76
+ public function callbackColumnListedProducts($value, $row, $column, $isExport)
77
+ {
78
+ $accountId = $row->getAccountId();
79
+ $marketplaceId = $row->getMarketplaceId();
80
+ $key = $accountId . ',' . $marketplaceId;
81
+
82
+ $value = $this->cacheData[$key]['active_items'];
83
+
84
+ if (is_null($value) || $value === '') {
85
+ $value = Mage::helper('M2ePro')->__('N/A');
86
+ } else if ($value <= 0) {
87
+ $value = '<span style="color: red;">0</span>';
88
+ }
89
+
90
+ return $value;
91
+ }
92
+
93
+ public function callbackColumnInactiveProducts($value, $row, $column, $isExport)
94
+ {
95
+ $accountId = $row->getAccountId();
96
+ $marketplaceId = $row->getMarketplaceId();
97
+ $key = $accountId . ',' . $marketplaceId;
98
+
99
+ $value = $this->cacheData[$key]['inactive_items'];
100
+
101
+ if (is_null($value) || $value === '') {
102
+ $value = Mage::helper('M2ePro')->__('N/A');
103
+ } else if ($value <= 0) {
104
+ $value = '<span style="color: red;">0</span>';
105
+ }
106
+
107
+ return $value;
108
+ }
109
+
110
+ //########################################
111
+
112
+ public function getRowUrl($row)
113
+ {
114
+ return $this->getUrl('*/adminhtml_common_amazon_listing_other/view', array(
115
+ 'account' => $row->getData('account_id'),
116
+ 'marketplace' => $row->getData('marketplace_id'),
117
+ 'back'=>Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_listing/index', array(
118
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING_OTHER,
119
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Other::TAB_ID_AMAZON
120
+ ))
121
+ ));
122
+ }
123
+
124
+ //########################################
125
+
126
+ protected function prepareCacheData()
127
+ {
128
+ $this->cacheData = array();
129
+
130
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
131
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
132
+ $collection->getSelect()->columns(
133
+ array('account_id', 'marketplace_id', 'status')
134
+ );
135
+
136
+ /* @var $item Ess_M2ePro_Model_Listing_Other */
137
+ foreach ($collection->getItems() as $item) {
138
+
139
+ $accountId = $item->getAccountId();
140
+ $marketplaceId = $item->getMarketplaceId();
141
+ $key = $accountId . ',' . $marketplaceId;
142
+
143
+ empty($this->cacheData[$key]) && ($this->cacheData[$key] = array(
144
+ 'total_items' => 0,
145
+ 'active_items' => 0,
146
+ 'inactive_items' => 0
147
+ ));
148
+
149
+ ++$this->cacheData[$key]['total_items'];
150
+
151
+ if ($item->getStatus() == Ess_M2ePro_Model_Listing_Product::STATUS_LISTED) {
152
+ ++$this->cacheData[$key]['active_items'];
153
+ } else {
154
+ ++$this->cacheData[$key]['inactive_items'];
155
+ }
156
+ }
157
+ }
158
+
159
+ //########################################
160
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Other_View extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListing');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_amazon_listing_other_view';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
27
+ $this->_headerText = Mage::helper('M2ePro')->__(
28
+ '3rd Party %channel_title% Listings',
29
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()
30
+ );
31
+ } else {
32
+ $this->_headerText = Mage::helper('M2ePro')->__('3rd Party Listings');
33
+ }
34
+ // ---------------------------------------
35
+
36
+ // Set buttons actions
37
+ // ---------------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ // ---------------------------------------
45
+
46
+ // ---------------------------------------
47
+ if (!is_null($this->getRequest()->getParam('back'))) {
48
+ $url = Mage::helper('M2ePro')->getBackUrl();
49
+ $this->_addButton('back', array(
50
+ 'label' => Mage::helper('M2ePro')->__('Back'),
51
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
52
+ 'class' => 'back'
53
+ ));
54
+ }
55
+ // ---------------------------------------
56
+
57
+ }
58
+
59
+ //########################################
60
+
61
+ public function getGridHtml()
62
+ {
63
+ $accountId = $this->getRequest()->getParam('account');
64
+ $marketplaceId = $this->getRequest()->getParam('marketplace');
65
+
66
+ // ---------------------------------------
67
+ $viewHeaderBlock = $this->getLayout()->createBlock(
68
+ 'M2ePro/adminhtml_listing_other_view_header','',
69
+ array(
70
+ 'account' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Account', $accountId),
71
+ 'marketplace' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Marketplace', $marketplaceId)
72
+ )
73
+ );
74
+ // ---------------------------------------
75
+
76
+ $mapToProductBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_listing_other_mapping');
77
+
78
+ return $viewHeaderBlock->toHtml() . $mapToProductBlock->toHtml() . parent::getGridHtml();
79
+ }
80
+
81
+ //########################################
82
+
83
+ protected function _toHtml()
84
+ {
85
+ /** @var $helper Ess_M2ePro_Helper_Data */
86
+ $helper = Mage::helper('M2ePro');
87
+ $componentMode = Ess_M2ePro_Helper_Component_Amazon::NICK;
88
+
89
+ $prepareData = $this->getUrl('*/adminhtml_listing_other_moving/prepareMoveToListing');
90
+ $createDefaultListingUrl = $this->getUrl('*/adminhtml_listing_other_moving/createDefaultListing');
91
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/moveToListingGrid');
92
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/getFailedProductsGrid');
93
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_other_moving/tryToMoveToListing');
94
+ $moveToListing = $this->getUrl('*/adminhtml_listing_other_moving/moveToListing');
95
+
96
+ $mapAutoToProductUrl = $this->getUrl('*/adminhtml_listing_other_mapping/autoMap');
97
+
98
+ $removingProductsUrl = $this->getUrl('*/adminhtml_common_listing_other/removing');
99
+ $unmappingProductsUrl = $this->getUrl('*/adminhtml_listing_other_mapping/unmapping');
100
+
101
+ $getAFNQtyBySku = $this->getUrl('*/adminhtml_common_amazon_listing/getAFNQtyBySku');
102
+
103
+ $someProductsWereNotMappedMessage = 'No matches were found. Please change the Mapping Attributes in <strong>';
104
+ $someProductsWereNotMappedMessage .= 'Configuration > Account > 3rd Party Listings</strong> ';
105
+ $someProductsWereNotMappedMessage .= 'or try to map manually.';
106
+ $someProductsWereNotMappedMessage = $helper->escapeJs($helper->__($someProductsWereNotMappedMessage));
107
+
108
+ $successfullyMappedMessage = $helper->escapeJs($helper->__('Product was successfully Mapped.'));
109
+
110
+ $createListing = $helper->escapeJs($helper->__(
111
+ 'Listings, which have the same Marketplace and Account were not found.'
112
+ ));
113
+ $createListing .= $helper->escapeJs($helper->__('Would you like to create one with Default Settings ?'));
114
+ $popupTitle = $helper->escapeJs($helper->__('Moving Amazon Items'));
115
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Amazon Item'));
116
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
117
+
118
+ $confirmMessage = $helper->escapeJs($helper->__('Are you sure?'));
119
+
120
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
121
+ $productsWereNotMovedMessage = $helper->escapeJs(
122
+ $helper->__('Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
123
+ );
124
+ $someProductsWereNotMovedMessage = $helper->escapeJs($helper->__(
125
+ 'Some of the Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.'
126
+ ));
127
+
128
+ $notEnoughDataMessage = $helper->escapeJs($helper->__('Not enough data'));
129
+ $successfullyUnmappedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Unmapped.'));
130
+ $successfullyRemovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Removed.'));
131
+
132
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
133
+
134
+ $selectItemsMessage = $helper->escapeJs(
135
+ $helper->__('Please select the Products you want to perform the Action on.')
136
+ );
137
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
138
+
139
+ $processingDataMessage = $helper->escapeJs($helper->__('Processing %product_title% Product(s).'));
140
+
141
+ $autoMapProgressTitle = $helper->escapeJs($helper->__('Map Item(s) to Products'));
142
+ $selectOnlyMapped = $helper->escapeJs($helper->__('Only Mapped Products must be selected.'));
143
+ $selectTheSameTypeProducts = $helper->escapeJs(
144
+ $helper->__('Selected Items must belong to the same Account and Marketplace.')
145
+ );
146
+
147
+ $successWord = $helper->escapeJs($helper->__('Success'));
148
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
149
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
150
+ $errorWord = $helper->escapeJs($helper->__('Error'));
151
+ $closeWord = $helper->escapeJs($helper->__('Close'));
152
+
153
+ $translations = json_encode(array(
154
+
155
+ 'Mapping Product' => $helper->__('Mapping Product'),
156
+ 'Product does not exist.' => $helper->__('Product does not exist.'),
157
+ 'Please enter correct Product ID.' => $helper->__('Please enter correct Product ID.'),
158
+ 'Product(s) was successfully Mapped.' => $helper->__('Product(s) was successfully Mapped.'),
159
+ 'Please enter correct Product ID or SKU' => $helper->__('Please enter correct Product ID or SKU'),
160
+
161
+ 'Current version only supports Simple Products. Please, choose Simple Product.' => $helper->__(
162
+ 'Current version only supports Simple Products. Please, choose Simple Product.'
163
+ ),
164
+
165
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.' => $helper->__(
166
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.'
167
+ )
168
+
169
+ ));
170
+
171
+ $urls = json_encode(array(
172
+
173
+ 'adminhtml_common_log/listingOther' => $this->getUrl('*/adminhtml_common_log/listingOther',array(
174
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_listing_other/index')
175
+ )),
176
+
177
+ 'adminhtml_listing_other_mapping/map' => $this->getUrl('*/adminhtml_listing_other_mapping/map'),
178
+
179
+ ));
180
+
181
+ $javascriptsMain = <<<HTML
182
+ <script type="text/javascript">
183
+
184
+ M2eProAmazon = {};
185
+ M2eProAmazon.url = {};
186
+ M2eProAmazon.formData = {};
187
+ M2eProAmazon.customData = {};
188
+ M2eProAmazon.text = {};
189
+
190
+ M2ePro.url.add({$urls});
191
+ M2ePro.translator.add({$translations});
192
+
193
+ M2eProAmazon.url.prepareData = '{$prepareData}';
194
+ M2eProAmazon.url.createDefaultListing = '{$createDefaultListingUrl}';
195
+ M2eProAmazon.url.getGridHtml = '{$getMoveToListingGridHtml}';
196
+ M2eProAmazon.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
197
+ M2eProAmazon.url.tryToMoveToListing = '{$tryToMoveToListing}';
198
+ M2eProAmazon.url.moveToListing = '{$moveToListing}';
199
+
200
+ M2eProAmazon.url.mapAutoToProduct = '{$mapAutoToProductUrl}';
201
+
202
+ M2eProAmazon.url.removingProducts = '{$removingProductsUrl}';
203
+ M2eProAmazon.url.unmappingProducts = '{$unmappingProductsUrl}';
204
+
205
+ M2ePro.url.getAFNQtyBySku = '{$getAFNQtyBySku}';
206
+
207
+ M2eProAmazon.text.create_listing = '{$createListing}';
208
+ M2eProAmazon.text.popup_title = '{$popupTitle}';
209
+ M2eProAmazon.text.popup_title_single = '{$popupTitleSingle}';
210
+ M2eProAmazon.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
211
+ M2eProAmazon.text.confirm = '{$confirmMessage}';
212
+ M2eProAmazon.text.successfully_moved = '{$successfullyMovedMessage}';
213
+ M2eProAmazon.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
214
+ M2eProAmazon.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
215
+ M2eProAmazon.text.not_enough_data = '{$notEnoughDataMessage}';
216
+ M2eProAmazon.text.successfully_unmapped = '{$successfullyUnmappedMessage}';
217
+ M2eProAmazon.text.successfully_removed = '{$successfullyRemovedMessage}';
218
+
219
+ M2eProAmazon.text.select_items_message = '{$selectItemsMessage}';
220
+ M2eProAmazon.text.select_action_message = '{$selectActionMessage}';
221
+
222
+ M2eProAmazon.text.automap_progress_title = '{$autoMapProgressTitle}';
223
+ M2eProAmazon.text.processing_data_message = '{$processingDataMessage}';
224
+ M2eProAmazon.text.successfully_mapped = '{$successfullyMappedMessage}';
225
+ M2eProAmazon.text.failed_mapped = '{$someProductsWereNotMappedMessage}';
226
+
227
+ M2eProAmazon.text.select_only_mapped_products = '{$selectOnlyMapped}';
228
+ M2eProAmazon.text.select_the_same_type_products = '{$selectTheSameTypeProducts}';
229
+
230
+ M2eProAmazon.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
231
+
232
+ M2eProAmazon.text.success_word = '{$successWord}';
233
+ M2eProAmazon.text.notice_word = '{$noticeWord}';
234
+ M2eProAmazon.text.warning_word = '{$warningWord}';
235
+ M2eProAmazon.text.error_word = '{$errorWord}';
236
+ M2eProAmazon.text.close_word = '{$closeWord}';
237
+
238
+ M2eProAmazon.customData.componentMode = '{$componentMode}';
239
+ M2eProAmazon.customData.gridId = 'amazonListingOtherGrid';
240
+
241
+ Event.observe(window,'load',function() {
242
+ ListingProgressBarObj = new ProgressBar('listing_other_progress_bar');
243
+ GridWrapperObj = new AreaWrapper('listing_other_content_container');
244
+
245
+ AmazonListingOtherGridHandlerObj = new CommonAmazonListingOtherGridHandler('amazonListingOtherGrid');
246
+ AmazonListingOtherMappingHandlerObj = new ListingOtherMappingHandler(
247
+ AmazonListingOtherGridHandlerObj,
248
+ 'amazon'
249
+ );
250
+
251
+ AmazonListingOtherGridHandlerObj.movingHandler.setOptions(M2eProAmazon);
252
+ AmazonListingOtherGridHandlerObj.autoMappingHandler.setOptions(M2eProAmazon);
253
+ AmazonListingOtherGridHandlerObj.removingHandler.setOptions(M2eProAmazon);
254
+ AmazonListingOtherGridHandlerObj.unmappingHandler.setOptions(M2eProAmazon);
255
+
256
+ CommonAmazonListingAfnQtyHandlerObj = new CommonAmazonListingAfnQtyHandler();
257
+ });
258
+
259
+ </script>
260
+ HTML;
261
+
262
+ return $javascriptsMain.
263
+ '<div id="listing_other_progress_bar"></div>' .
264
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
265
+ '<div id="listing_other_content_container">' .
266
+ parent::_toHtml() .
267
+ '</div>';
268
+ }
269
+
270
+ //########################################
271
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Other/View/Grid.php ADDED
@@ -0,0 +1,662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Other_View_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ /** @var $this->connRead Varien_Db_Adapter_Pdo_Mysql */
18
+ $this->connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('amazonListingOtherGrid');
23
+ // ---------------------------------------
24
+
25
+ // Set default values
26
+ // ---------------------------------------
27
+ $this->setDefaultSort('id');
28
+ $this->setDefaultDir('DESC');
29
+ $this->setSaveParametersInSession(true);
30
+ $this->setUseAjax(true);
31
+ // ---------------------------------------
32
+ }
33
+
34
+ public function getMassactionBlockName()
35
+ {
36
+ return 'M2ePro/adminhtml_grid_massaction';
37
+ }
38
+
39
+ //########################################
40
+
41
+ protected function _prepareCollection()
42
+ {
43
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
44
+
45
+ $collection->getSelect()->joinLeft(
46
+ array('mp' => Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
47
+ 'mp.id = main_table.marketplace_id',
48
+ array('marketplace_title' => 'mp.title')
49
+ )->joinLeft(
50
+ array('am' => Mage::getResourceModel('M2ePro/Amazon_Marketplace')->getMainTable()),
51
+ 'am.marketplace_id = main_table.marketplace_id',
52
+ array('currency' => 'am.default_currency'));
53
+
54
+ // Add Filter By Account
55
+ if ($this->getRequest()->getParam('account')) {
56
+ $collection->addFieldToFilter('main_table.account_id',
57
+ $this->getRequest()->getParam('account'));
58
+ }
59
+
60
+ // Add Filter By Marketplace
61
+ if ($this->getRequest()->getParam('marketplace')) {
62
+ $collection->addFieldToFilter('main_table.marketplace_id',
63
+ $this->getRequest()->getParam('marketplace'));
64
+ }
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
+ 'filter' => 'M2ePro/adminhtml_common_amazon_grid_column_filter_qty',
112
+ 'filter_condition_callback' => array($this, 'callbackFilterQty')
113
+ ));
114
+
115
+ $priceColumn = array(
116
+ 'header' => Mage::helper('M2ePro')->__('Price'),
117
+ 'align' => 'right',
118
+ 'width' => '110px',
119
+ 'type' => 'number',
120
+ 'index' => 'online_price',
121
+ 'filter_index' => 'online_price',
122
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
123
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
124
+ );
125
+
126
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled()) {
127
+ $priceColumn['filter'] = 'M2ePro/adminhtml_common_amazon_grid_column_filter_price';
128
+ }
129
+
130
+ $this->addColumn('online_price', $priceColumn);
131
+
132
+ $this->addColumn('status', array(
133
+ 'header' => Mage::helper('M2ePro')->__('Status'),
134
+ 'width' => '75px',
135
+ 'index' => 'status',
136
+ 'filter_index' => 'main_table.status',
137
+ 'type' => 'options',
138
+ 'sortable' => false,
139
+ 'options' => array(
140
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
141
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
142
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
143
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
144
+ ),
145
+ 'frame_callback' => array($this, 'callbackColumnStatus')
146
+ ));
147
+
148
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
149
+ '*/adminhtml_common_amazon_listing_other/view',
150
+ array(
151
+ 'account' => $this->getRequest()->getParam('account'),
152
+ 'marketplace' => $this->getRequest()->getParam('marketplace'),
153
+ 'back' => $this->getRequest()->getParam('back', null)
154
+ )
155
+ );
156
+
157
+ $this->addColumn('actions', array(
158
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
159
+ 'align' => 'left',
160
+ 'width' => '70px',
161
+ 'type' => 'action',
162
+ 'index' => 'actions',
163
+ 'filter' => false,
164
+ 'sortable' => false,
165
+ 'getter' => 'getId',
166
+ 'actions' => array(
167
+ array(
168
+ 'caption' => Mage::helper('M2ePro')->__('View Log'),
169
+ 'field' => 'id',
170
+ 'url' => array(
171
+ 'base' => '*/adminhtml_common_log/listingOther',
172
+ 'params' => array(
173
+ 'back' => $backUrl,
174
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK
175
+ )
176
+ )
177
+ ),
178
+ array(
179
+ 'caption' => Mage::helper('M2ePro')->__('Clear Log'),
180
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
181
+ 'field' => 'id',
182
+ 'url' => array(
183
+ 'base' => '*/adminhtml_listing_other/clearLog',
184
+ 'params' => array(
185
+ 'back' => $backUrl
186
+ )
187
+ )
188
+ )
189
+ )
190
+ ));
191
+
192
+ return parent::_prepareColumns();
193
+ }
194
+
195
+ protected function _prepareMassaction()
196
+ {
197
+ // Set mass-action identifiers
198
+ // ---------------------------------------
199
+ $this->setMassactionIdField('main_table.id');
200
+ $this->getMassactionBlock()->setFormFieldName('ids');
201
+ // ---------------------------------------
202
+
203
+ $this->getMassactionBlock()->setGroups(array(
204
+ 'mapping' => Mage::helper('M2ePro')->__('Mapping'),
205
+ 'other' => Mage::helper('M2ePro')->__('Other')
206
+ ));
207
+
208
+ // Set mass-action
209
+ // ---------------------------------------
210
+ $this->getMassactionBlock()->addItem('autoMapping', array(
211
+ 'label' => Mage::helper('M2ePro')->__('Map Item(s) Automatically'),
212
+ 'url' => '',
213
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
214
+ ), 'mapping');
215
+ $this->getMassactionBlock()->addItem('moving', array(
216
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Listing'),
217
+ 'url' => '',
218
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
219
+ ), 'other');
220
+ $this->getMassactionBlock()->addItem('removing', array(
221
+ 'label' => Mage::helper('M2ePro')->__('Remove Item(s)'),
222
+ 'url' => '',
223
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
224
+ ), 'other');
225
+ $this->getMassactionBlock()->addItem('unmapping', array(
226
+ 'label' => Mage::helper('M2ePro')->__('Unmap Item(s)'),
227
+ 'url' => '',
228
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
229
+ ), 'mapping');
230
+ // ---------------------------------------
231
+
232
+ return parent::_prepareMassaction();
233
+ }
234
+
235
+ //########################################
236
+
237
+ public function callbackColumnProductId($value, $row, $column, $isExport)
238
+ {
239
+ if (empty($value)) {
240
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('title'));
241
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
242
+ if (strlen($productTitle) > 60) {
243
+ $productTitle = substr($productTitle, 0, 60) . '...';
244
+ }
245
+ $htmlValue = '&nbsp;<a href="javascript:void(0);"
246
+ onclick="AmazonListingOtherMappingHandlerObj.openPopUp(\''.
247
+ $productTitle.
248
+ '\','.
249
+ (int)$row->getId().
250
+ ');">' . Mage::helper('M2ePro')->__('Map') . '</a>';
251
+
252
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
253
+ $htmlValue .= '<br/>' . $row->getId();
254
+ }
255
+ return $htmlValue;
256
+ }
257
+
258
+ $htmlValue = '&nbsp<a href="'
259
+ .$this->getUrl('adminhtml/catalog_product/edit',
260
+ array('id' => $row->getData('product_id')))
261
+ .'" target="_blank">'
262
+ .$row->getData('product_id')
263
+ .'</a>';
264
+
265
+ $htmlValue .= '&nbsp&nbsp&nbsp<a href="javascript:void(0);"'
266
+ .' onclick="AmazonListingOtherGridHandlerObj.movingHandler.getGridHtml('
267
+ .json_encode(array((int)$row->getData('id')))
268
+ .')">'
269
+ .Mage::helper('M2ePro')->__('Move')
270
+ .'</a>';
271
+
272
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
273
+ $htmlValue .= '<br/>' . $row->getId();
274
+ }
275
+
276
+ return $htmlValue;
277
+ }
278
+
279
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
280
+ {
281
+ if (is_null($value)) {
282
+ $value = '<i style="color:gray;">receiving...</i>';
283
+ } elseif ($value == '') {
284
+ $value = '<i style="color:gray;">none</i>';
285
+ } else {
286
+ $value = '<span>' . Mage::helper('M2ePro')->escapeHtml($value) . '</span>';
287
+ }
288
+
289
+ $tempSku = $row->getData('sku');
290
+ empty($tempSku) && $tempSku = Mage::helper('M2ePro')->__('N/A');
291
+
292
+ $value .= '<br/><strong>'
293
+ .Mage::helper('M2ePro')->__('SKU')
294
+ .':</strong> '
295
+ .Mage::helper('M2ePro')->escapeHtml($tempSku);
296
+
297
+ return $value;
298
+ }
299
+
300
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
301
+ {
302
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($value, $row->getData('marketplace_id'));
303
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
304
+ }
305
+
306
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
307
+ {
308
+ if ((bool)$row->getData('is_afn_channel')) {
309
+ $sku = $row->getData('sku');
310
+
311
+ $afn = Mage::helper('M2ePro')->__('AFN');
312
+ $total = Mage::helper('M2ePro')->__('Total');
313
+ $inStock = Mage::helper('M2ePro')->__('In Stock');
314
+ $productId = $row->getData('id');
315
+ $accountId = $row->getData('account_id');
316
+
317
+ return <<<HTML
318
+ <div id="m2ePro_afn_qty_value_{$productId}">
319
+ <span class="m2ePro-online-sku-value" productId="{$productId}" style="display: none">{$sku}</span>
320
+ <span class="m2epro-empty-afn-qty-data" style="display: none">{$afn}</span>
321
+ <div class="m2epro-afn-qty-data" style="display: none">
322
+ <div class="total">{$total}: <span></span></div>
323
+ <div class="in-stock">{$inStock}: <span></span></div>
324
+ </div>
325
+ <a href="javascript:void(0)"
326
+ onclick="CommonAmazonListingAfnQtyHandlerObj.showAfnQty(this,'{$sku}',{$productId}, {$accountId})">
327
+ {$afn}
328
+ </a>
329
+ </div>
330
+ HTML;
331
+ }
332
+
333
+ if (is_null($value) || $value === '') {
334
+ return Mage::helper('M2ePro')->__('N/A');
335
+ }
336
+
337
+ if ($value <= 0) {
338
+ return '<span style="color: red;">0</span>';
339
+ }
340
+
341
+ return $value;
342
+ }
343
+
344
+ public function callbackColumnPrice($value, $row, $column, $isExport)
345
+ {
346
+ $html ='';
347
+
348
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() &&
349
+ (int)$row->getData('is_repricing') === Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES) {
350
+ $text = Mage::helper('M2ePro')->__(
351
+ 'This product is used by Amazon Repricing Tool.
352
+ The Price cannot be updated through the M2E Pro.'
353
+ );
354
+
355
+ $html = <<<HTML
356
+ <span style="float:right; text-align: left;">
357
+ <img class="tool-tip-image"
358
+ style="vertical-align: middle; width: 16px;"
359
+ src="{$this->getSkinUrl('M2ePro/images/money.png')}">
360
+ <span class="tool-tip-message tool-tip-message tip-left" style="display:none;">
361
+ <img src="{$this->getSkinUrl('M2ePro/images/i_icon.png')}">
362
+ <span>{$text}</span>
363
+ </span>
364
+ </span>
365
+ HTML;
366
+ }
367
+
368
+ if (is_null($value) || $value === '') {
369
+ return Mage::helper('M2ePro')->__('N/A') . $html;
370
+ }
371
+
372
+ if ((float)$value <= 0) {
373
+ return '<span style="color: #f00;">0</span>' . $html;
374
+ }
375
+
376
+ $currency = Mage::helper('M2ePro/Component_Amazon')
377
+ ->getCachedObject('Marketplace',$row->getData('marketplace_id'))
378
+ ->getChildObject()
379
+ ->getDefaultCurrency();
380
+
381
+ return Mage::app()->getLocale()->currency($currency)->toCurrency($value) . $html;
382
+ }
383
+
384
+ public function callbackColumnStatus($value, $row, $column, $isExport)
385
+ {
386
+ switch ($row->getData('status')) {
387
+
388
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
389
+ $value = '<span style="color: gray;">' . $value . '</span>';
390
+ break;
391
+
392
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
393
+ $value = '<span style="color: green;">' . $value . '</span>';
394
+ break;
395
+
396
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
397
+ $value = '<span style="color: red;">' . $value . '</span>';
398
+ break;
399
+
400
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
401
+ $value = '<span style="color: orange; font-weight: bold;">' . $value . '</span>';
402
+ break;
403
+
404
+ default:
405
+ break;
406
+ }
407
+
408
+ return $value.$this->getViewLogIconHtml($row->getId());
409
+ }
410
+
411
+ //########################################
412
+
413
+ protected function callbackFilterTitle($collection, $column)
414
+ {
415
+ $value = $column->getFilter()->getValue();
416
+
417
+ if ($value == null) {
418
+ return;
419
+ }
420
+
421
+ $collection->getSelect()->where('second_table.title LIKE ? OR second_table.sku LIKE ?', '%'.$value.'%');
422
+ }
423
+
424
+ protected function callbackFilterQty($collection, $column)
425
+ {
426
+ $value = $column->getFilter()->getValue();
427
+
428
+ if (empty($value)) {
429
+ return;
430
+ }
431
+
432
+ $where = '';
433
+
434
+ if (isset($value['from']) && $value['from'] != '') {
435
+ $where .= 'online_qty >= ' . $value['from'];
436
+ }
437
+
438
+ if (isset($value['to']) && $value['to'] != '') {
439
+ if (isset($value['from']) && $value['from'] != '') {
440
+ $where .= ' AND ';
441
+ }
442
+ $where .= 'online_qty <= ' . $value['to'];
443
+ }
444
+
445
+ if (!empty($value['afn'])) {
446
+ if (!empty($where)) {
447
+ $where = '(' . $where . ') OR ';
448
+ }
449
+ $where .= 'is_afn_channel = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_AFN_CHANNEL_YES;;
450
+ }
451
+
452
+ $collection->getSelect()->where($where);
453
+ }
454
+
455
+ protected function callbackFilterPrice($collection, $column)
456
+ {
457
+ $value = $column->getFilter()->getValue();
458
+
459
+ if (empty($value)) {
460
+ return;
461
+ }
462
+
463
+ $where = '';
464
+
465
+ if (isset($value['from']) && $value['from'] != '') {
466
+ $where .= 'online_price >= ' . $value['from'];
467
+ }
468
+
469
+ if (isset($value['to']) && $value['to'] != '') {
470
+ if (isset($value['from']) && $value['from'] != '') {
471
+ $where .= ' AND ';
472
+ }
473
+ $where .= 'online_price <= ' . $value['to'];
474
+ }
475
+
476
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() && !empty($value['is_repricing'])) {
477
+ if (!empty($where)) {
478
+ $where = '(' . $where . ') OR ';
479
+ }
480
+ $where .= 'is_repricing = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES;
481
+ }
482
+
483
+ $collection->getSelect()->where($where);
484
+ }
485
+
486
+ //########################################
487
+
488
+ public function getViewLogIconHtml($listingOtherId)
489
+ {
490
+ $listingOtherId = (int)$listingOtherId;
491
+
492
+ // Get last messages
493
+ // ---------------------------------------
494
+ $dbSelect = $this->connRead->select()
495
+ ->from(
496
+ Mage::getResourceModel('M2ePro/Listing_Other_Log')->getMainTable(),
497
+ array('action_id','action','type','description','create_date','initiator')
498
+ )
499
+ ->where('`listing_other_id` = ?', $listingOtherId)
500
+ ->where('`action_id` IS NOT NULL')
501
+ ->order(array('id DESC'))
502
+ ->limit(30);
503
+
504
+ $logRows = $this->connRead->fetchAll($dbSelect);
505
+ // ---------------------------------------
506
+
507
+ // Get grouped messages by action_id
508
+ // ---------------------------------------
509
+ $actionsRows = array();
510
+ $tempActionRows = array();
511
+ $lastActionId = false;
512
+
513
+ foreach ($logRows as $row) {
514
+
515
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
516
+
517
+ if ($row['action_id'] !== $lastActionId) {
518
+ if (count($tempActionRows) > 0) {
519
+ $actionsRows[] = array(
520
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
521
+ 'date' => $this->getMainDateForActionId($tempActionRows),
522
+ 'action' => $this->getActionForAction($tempActionRows[0]),
523
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
524
+ 'items' => $tempActionRows
525
+ );
526
+ $tempActionRows = array();
527
+ }
528
+ $lastActionId = $row['action_id'];
529
+ }
530
+ $tempActionRows[] = $row;
531
+ }
532
+
533
+ if (count($tempActionRows) > 0) {
534
+ $actionsRows[] = array(
535
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
536
+ 'date' => $this->getMainDateForActionId($tempActionRows),
537
+ 'action' => $this->getActionForAction($tempActionRows[0]),
538
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
539
+ 'items' => $tempActionRows
540
+ );
541
+ }
542
+
543
+ if (count($actionsRows) <= 0) {
544
+ return '';
545
+ }
546
+
547
+ $tips = array(
548
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
549
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
550
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
551
+ );
552
+
553
+ $icons = array(
554
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
555
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
556
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
557
+ );
558
+
559
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
560
+ 'entity_id' => $listingOtherId,
561
+ 'rows' => $actionsRows,
562
+ 'tips' => $tips,
563
+ 'icons' => $icons,
564
+ 'view_help_handler' => 'AmazonListingOtherGridHandlerObj.viewItemHelp',
565
+ 'hide_help_handler' => 'AmazonListingOtherGridHandlerObj.hideItemHelp',
566
+ ));
567
+
568
+ return $summary->toHtml();
569
+ }
570
+
571
+ public function getActionForAction($actionRows)
572
+ {
573
+ $string = '';
574
+
575
+ switch ((int)$actionRows['action']) {
576
+ case Ess_M2ePro_Model_Listing_Other_Log::ACTION_CHANNEL_CHANGE:
577
+ $string = Mage::helper('M2ePro')->__('Channel Change');
578
+ break;
579
+ }
580
+
581
+ return $string;
582
+ }
583
+
584
+ public function getInitiatorForAction($actionRows)
585
+ {
586
+ $string = '';
587
+
588
+ switch ($actionRows['initiator']) {
589
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
590
+ $string = '';
591
+ break;
592
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
593
+ $string = Mage::helper('M2ePro')->__('Manual');
594
+ break;
595
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
596
+ $string = Mage::helper('M2ePro')->__('Automatic');
597
+ break;
598
+ }
599
+
600
+ return $string;
601
+ }
602
+
603
+ public function getMainTypeForActionId($actionRows)
604
+ {
605
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
606
+
607
+ foreach ($actionRows as $row) {
608
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
609
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
610
+ break;
611
+ }
612
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
613
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
614
+ }
615
+ }
616
+
617
+ return $type;
618
+ }
619
+
620
+ public function getMainDateForActionId($actionRows)
621
+ {
622
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
623
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
624
+ }
625
+
626
+ //########################################
627
+
628
+ protected function _toHtml()
629
+ {
630
+ $javascriptsMain = <<<HTML
631
+ <script type="text/javascript">
632
+
633
+ if (typeof AmazonListingOtherGridHandlerObj != 'undefined') {
634
+ AmazonListingOtherGridHandlerObj.afterInitPage();
635
+ }
636
+
637
+ Event.observe(window, 'load', function() {
638
+ setTimeout(function() {
639
+ AmazonListingOtherGridHandlerObj.afterInitPage();
640
+ }, 350);
641
+ });
642
+
643
+ </script>
644
+ HTML;
645
+
646
+ return parent::_toHtml().$javascriptsMain;
647
+ }
648
+
649
+ //########################################
650
+
651
+ public function getGridUrl()
652
+ {
653
+ return $this->getUrl('*/adminhtml_common_amazon_listing_other/grid', array('_current' => true));
654
+ }
655
+
656
+ public function getRowUrl($row)
657
+ {
658
+ return false;
659
+ }
660
+
661
+ //########################################
662
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Product extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingProduct');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_amazon_listing_product';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+
28
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
29
+ $headerText = Mage::helper('M2ePro')->__(
30
+ 'Add Products To %component_name% Listing "%listing_title%"',
31
+ Mage::helper('M2ePro/Component_Amazon')->getTitle(),
32
+ $this->escapeHtml($listingData['title'])
33
+ );
34
+ } else {
35
+ $headerText = Mage::helper('M2ePro')->__(
36
+ 'Add Products To Listing "%listing_title%"',
37
+ $this->escapeHtml($listingData['title'])
38
+ );
39
+ }
40
+
41
+ $this->_headerText = $headerText;
42
+ // ---------------------------------------
43
+
44
+ // Set buttons actions
45
+ // ---------------------------------------
46
+ $this->removeButton('back');
47
+ $this->removeButton('reset');
48
+ $this->removeButton('delete');
49
+ $this->removeButton('add');
50
+ $this->removeButton('save');
51
+ $this->removeButton('edit');
52
+ // ---------------------------------------
53
+
54
+ // ---------------------------------------
55
+ if (is_null($this->getRequest()->getParam('back'))) {
56
+ $url = $this->getUrl(
57
+ '*/adminhtml_common_amazon_listing/categoryProduct',
58
+ array(
59
+ 'id' => $listingData['id'],
60
+ 'save_categories' => $this->getRequest()->getParam('save_categories', 1),
61
+ 'selected_categories' => $this->getRequest()->getParam('selected_categories')
62
+ )
63
+ );
64
+ } else {
65
+ $url = Mage::helper('M2ePro')->getBackUrl(
66
+ '*/adminhtml_common_listing/index',
67
+ array(
68
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
69
+ )
70
+ );
71
+ }
72
+ $this->_addButton('back', array(
73
+ 'label' => Mage::helper('M2ePro')->__('Back'),
74
+ 'onclick' => 'ProductGridHandlerObj.back_click(\''.$url.'\')',
75
+ 'class' => 'back'
76
+ ));
77
+ // ---------------------------------------
78
+
79
+ // ---------------------------------------
80
+ $this->_addButton('save', array(
81
+ 'label' => Mage::helper('M2ePro')->__('Save'),
82
+ 'onclick' => 'ProductGridHandlerObj.save_click(\'view\')',
83
+ 'class' => 'save'
84
+ ));
85
+ // ---------------------------------------
86
+ }
87
+
88
+ public function getGridHtml()
89
+ {
90
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_product_help');
91
+ return $helpBlock->toHtml() . parent::getGridHtml();
92
+ }
93
+
94
+ protected function _toHtml()
95
+ {
96
+ return '<div id="add_products_progress_bar"></div>'.
97
+ '<div id="add_products_container">'.
98
+ parent::_toHtml().
99
+ '</div>';
100
+ }
101
+
102
+ //########################################
103
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Product/Help.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Product_Help extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingProductHelp');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/listing/product/help.phtml');
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Grid.php ADDED
@@ -0,0 +1,775 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ private $productId;
12
+ private $currency;
13
+
14
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
15
+ private $listingProduct;
16
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute $matcherAttributes */
17
+ private $matcherAttributes;
18
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Option $matcherOptions */
19
+ private $matcherOptions;
20
+
21
+ //########################################
22
+
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+
27
+ $this->productId = Mage::helper('M2ePro/Data_Global')->getValue('product_id');
28
+ $this->listingProduct = Mage::getModel('M2ePro/Listing_Product')->load($this->productId);
29
+
30
+ $this->matcherAttributes = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Attribute');
31
+ $this->matcherOptions = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Option');
32
+
33
+ $this->currency = Mage::helper('M2ePro/Component_Amazon')
34
+ ->getCachedObject('Marketplace', Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'))
35
+ ->getChildObject()
36
+ ->getDefaultCurrency();
37
+
38
+ // Initialization block
39
+ // ---------------------------------------
40
+ $this->setId('amazonProductSearchGrid');
41
+ // ---------------------------------------
42
+
43
+ // Set default values
44
+ // ---------------------------------------
45
+ $this->setFilterVisibility(false);
46
+ $this->setPagerVisibility(false);
47
+ $this->setDefaultSort('id');
48
+ $this->setDefaultDir('ASC');
49
+ $this->setSaveParametersInSession(true);
50
+ $this->setUseAjax(true);
51
+ // ---------------------------------------
52
+ }
53
+
54
+ protected function _prepareCollection()
55
+ {
56
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
57
+
58
+ $results = new Varien_Data_Collection();
59
+ foreach ($data['data'] as $index => $item) {
60
+ $temp = array(
61
+ 'id' => $index,
62
+ 'general_id' => $item['general_id'],
63
+ 'brand' => $item['brand'],
64
+ 'title' => $item['title'],
65
+ 'image_url' => $item['image_url'],
66
+ 'price' => isset($item['list_price']['amount']) ? $item['list_price']['amount'] : null,
67
+ 'is_variation_product' => $item['is_variation_product']
68
+ );
69
+
70
+ if ($temp['is_variation_product']) {
71
+ if (!$item['bad_parent']) {
72
+ $temp += array(
73
+ 'parentage' => $item['parentage'],
74
+ 'variations' => $item['variations'],
75
+ 'bad_parent' => $item['bad_parent']
76
+ );
77
+ } else {
78
+ $temp['bad_parent'] = $item['bad_parent'];
79
+ }
80
+
81
+ if (!empty($item['requested_child_id'])) {
82
+ $temp['requested_child_id'] = $item['requested_child_id'];
83
+ }
84
+ }
85
+
86
+ $results->addItem(new Varien_Object($temp));
87
+ }
88
+
89
+ $this->setCollection($results);
90
+
91
+ return parent::_prepareCollection();
92
+ }
93
+
94
+ protected function _prepareColumns()
95
+ {
96
+ $this->addColumn('image', array(
97
+ 'header' => Mage::helper('M2ePro')->__('Image'),
98
+ 'align' => 'center',
99
+ 'type' => 'text',
100
+ 'width' => '80px',
101
+ 'index' => 'image_url',
102
+ 'filter' => false,
103
+ 'sortable' => false,
104
+ 'frame_callback' => array($this, 'callbackColumnImage')
105
+ ));
106
+
107
+ $this->addColumn('title', array(
108
+ 'header' => Mage::helper('M2ePro')->__('Title'),
109
+ 'align' => 'left',
110
+ 'type' => 'text',
111
+ 'string_limit' => 10000,
112
+ 'width' => '375px',
113
+ 'index' => 'title',
114
+ 'filter' => false,
115
+ 'sortable' => false,
116
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
117
+ ));
118
+
119
+ $this->addColumn('price',array(
120
+ 'header' => Mage::helper('catalog')->__('Price'),
121
+ 'width' => '60px',
122
+ 'align' => 'right',
123
+ 'index' => 'price',
124
+ 'filter' => false,
125
+ 'sortable' => false,
126
+ 'type' => 'number',
127
+ 'frame_callback' => array($this, 'callbackColumnPrice')
128
+ ));
129
+
130
+ $this->addColumn('general_id', array(
131
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
132
+ 'align' => 'center',
133
+ 'type' => 'text',
134
+ 'width' => '75px',
135
+ 'index' => 'general_id',
136
+ 'filter' => false,
137
+ 'sortable' => false,
138
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
139
+ ));
140
+
141
+ $this->addColumn('actions', array(
142
+ 'header' => Mage::helper('M2ePro')->__('Action'),
143
+ 'align' => 'center',
144
+ 'type' => 'text',
145
+ 'width' => '78px',
146
+ 'filter' => false,
147
+ 'sortable' => false,
148
+ 'frame_callback' => array($this, 'callbackColumnActions'),
149
+ ));
150
+
151
+ }
152
+
153
+ //########################################
154
+
155
+ public function callbackColumnImage($value, $product, $column, $isExport)
156
+ {
157
+ return '<img src="'.$value.'" />';
158
+ }
159
+
160
+ public function callbackColumnGeneralId($value, $product, $column, $isExport)
161
+ {
162
+ $url = Mage::helper('M2ePro/Component_Amazon')
163
+ ->getItemUrl($value, Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'));
164
+
165
+ $parentAsinText = Mage::helper('M2ePro')->__('parent ASIN/ISBN');
166
+
167
+ return <<<HTML
168
+ <a id="asin_link_{$product->getData('id')}" href="{$url}" target="_blank">{$value}</a>
169
+ <div id="parent_asin_text_{$product->getData('id')}" style="font-size: 9px; color: grey; display: none">
170
+ {$parentAsinText}
171
+ </div>
172
+ HTML;
173
+
174
+ }
175
+
176
+ public function callbackColumnTitle($value, $row, $column, $isExport)
177
+ {
178
+ $value = '<div style="margin-left: 3px; margin-bottom: 3px;">'.
179
+ Mage::helper('M2ePro')->escapeHtml($value)."</div>";
180
+
181
+ $id = $row->getId();
182
+ $generalId = $row->getData('general_id');
183
+ $categoryLinkTitle = Mage::helper('M2ePro')->escapeHtml('Show Categories');
184
+ $notFoundText = Mage::helper('M2ePro')->__('Categories Not Found');
185
+
186
+ $value .= <<<HTML
187
+ <div style="margin-left: 3px; margin-bottom: 10px; font-size:10px; line-height: 1.1em">
188
+ <a href="javascript:void(0)"
189
+ onclick="ListingGridHandlerObj.productSearchHandler.showAsinCategories(
190
+ this, {$id}, '{$generalId}', {$this->productId})">
191
+ {$categoryLinkTitle}
192
+ </a>
193
+ <div id="asin_categories_{$id}"></div>
194
+ <div id="asin_categories_not_found_{$id}" style="display: none; font-style: italic">{$notFoundText}</div>
195
+ </div>
196
+ HTML;
197
+
198
+ if (!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct()
199
+ || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
200
+ if (!$row->getData('is_variation_product')) {
201
+ return $value;
202
+ }
203
+ } else {
204
+ if (!$row->getData('is_variation_product')) {
205
+ return $value;
206
+ }
207
+ }
208
+
209
+ if ($row->getData('is_variation_product') && $row->getData('bad_parent')) {
210
+ return $value;
211
+ }
212
+
213
+ $variations = $row->getData('variations');
214
+
215
+ if ($this->listingProduct->getChildObject()->getVariationManager()->isRelationParentType()) {
216
+
217
+ $magentoProductAttributesHtml = '';
218
+ $magentoProductAttributesJs = '';
219
+
220
+ $destinationAttributes = array_keys($variations['set']);
221
+
222
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
223
+ $this->matcherAttributes->setDestinationAttributes($destinationAttributes);
224
+
225
+ if ($this->matcherAttributes->isAmountEqual()) {
226
+ $magentoProductAttributesJs .= '<script type="text/javascript">';
227
+ $magentoProductAttributesHtml .= '<div><span style="margin-left: 10px;
228
+ font-size: 11px;
229
+ font-weight: bold;
230
+ color: #808080;
231
+ display: inline-block;
232
+ width: 170px;">' .
233
+ Mage::helper('M2ePro')->__('Magento Attributes') .
234
+ '</span><span style="margin-left: 10px;
235
+ font-size: 11px;
236
+ font-weight: bold;
237
+ color: #808080;
238
+ display: inline-block;">' .
239
+ Mage::helper('M2ePro')->__('Amazon Attributes') .
240
+ '</span></div>';
241
+
242
+ $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
243
+ $attributeId = 0;
244
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
245
+
246
+ $magentoProductAttributesHtml .= '<span style="margin-left: 10px;
247
+ font-size: 11px;
248
+ color: #808080;
249
+ display: inline-block;
250
+ width: 170px;">'.
251
+ ucfirst(strtolower($magentoAttr)).
252
+ '</span>';
253
+ $magentoProductAttributesHtml .= '<input type="hidden" value="' .
254
+ Mage::helper('M2ePro')->escapeHtml($magentoAttr) . '"
255
+ id="magento_product_attribute_'.$attributeId.'_'.$id.'">';
256
+ $magentoProductAttributesHtml .= '<select class="amazon_product_attribute_'.$id.'"
257
+ onchange="ListingGridHandlerObj.productSearchHandler.attributesChange(this)"
258
+ style="width: 170px; margin-left: 10px;
259
+ margin-bottom: 7px; font-size: 10px;"
260
+ id="amazon_product_attribute_'.$attributeId.'_'.$id.'">';
261
+
262
+ if (!array_key_exists($amazonAttr,$variations['set']))
263
+ {
264
+ $magentoProductAttributesHtml .= '<option class="empty" value=""></option>';
265
+ }
266
+
267
+ foreach ($variations['set'] as $attrKey => $attrData) {
268
+
269
+ $selected = '';
270
+ if ($attrKey == $amazonAttr) {
271
+ $selected = 'selected';
272
+ $magentoProductAttributesJs .= <<<JS
273
+ ListingGridHandlerObj.productSearchHandler.attributesChange({id:"magento_product_attribute_{$magentoAttr}_{$id}"});
274
+ JS;
275
+ }
276
+
277
+ $attrKey = Mage::helper('M2ePro')->escapeHtml($attrKey);
278
+ $magentoProductAttributesHtml .= '<option value="'.$attrKey.'" '.$selected.'>'
279
+ .$attrKey.'</option>';
280
+ }
281
+ $magentoProductAttributesHtml .= '</select><br/>';
282
+ $attributeId++;
283
+ }
284
+
285
+ $magentoProductAttributesJs .= '</script>';
286
+
287
+ $magentoProductAttributesHtml .= '<div id="variations_'.$id.'" style="display: none;">'.
288
+ json_encode($variations).
289
+ '</div>';
290
+ } else {
291
+
292
+ $matchedAttributes = json_encode($this->matcherAttributes->getMatchedAttributes());
293
+ $destinationAttributes = json_encode($destinationAttributes);
294
+
295
+ foreach ($variations['set'] as $attribute => $options) {
296
+ $variations['set'][$attribute] = array_values($options);
297
+ }
298
+
299
+ $amazonVariations = json_encode($variations);
300
+
301
+ $magentoAttributesText = Mage::helper('M2ePro')->__('Magento Attributes');
302
+ $amazonAttributesText = Mage::helper('M2ePro')->__('Amazon Attributes');
303
+
304
+ $searchHandler = 'ListingGridHandlerObj.productSearchHandler';
305
+
306
+ $value .= <<<HTML
307
+ <form id="matching_attributes_form_{$id}" action="javascript:void(0)">
308
+ <div class="matching-attributes-table" style="display:table;padding-left:10px;font-size: 11px;color: #808080;">
309
+ <div class="matching-attributes-table-header"
310
+ style="display: table-row; font-weight: bold;">
311
+ <div style="display:table-cell; width: 170px; padding-right: 10px;">
312
+ <span>{$magentoAttributesText}</span>
313
+ </div>
314
+ <div style="display:table-cell;">
315
+ <span>{$amazonAttributesText}</span>
316
+ </div>
317
+ </div>
318
+ </div>
319
+ </form>
320
+ </div>
321
+ HTML;
322
+
323
+ if ($this->matcherAttributes->isSourceAmountGreater()) {
324
+ $magentoProductVariationsSet = $this->listingProduct->getMagentoProduct()
325
+ ->getVariationInstance()->getVariationsTypeStandard();
326
+ $magentoProductVariationsSet = json_encode($magentoProductVariationsSet['set']);
327
+ $productAttributes = json_encode($this->listingProduct->getChildObject()
328
+ ->getVariationManager()->getTypeModel()->getProductAttributes());
329
+
330
+ $value .= <<<HTML
331
+ <script type="application/javascript">
332
+ {$searchHandler}.searchData[{$id}] = {};
333
+ {$searchHandler}.searchData[{$id}].matchingType = {$searchHandler}.MATCHING_TYPE_VIRTUAL_AMAZON;
334
+ {$searchHandler}.searchData[{$id}].matchedAttributes = {$matchedAttributes};
335
+ {$searchHandler}.searchData[{$id}].productAttributes = {$productAttributes};
336
+ {$searchHandler}.searchData[{$id}].destinationAttributes = {$destinationAttributes};
337
+ {$searchHandler}.searchData[{$id}].magentoVariationSet = {$magentoProductVariationsSet};
338
+ {$searchHandler}.searchData[{$id}].amazonVariation = {$amazonVariations};
339
+
340
+ ListingGridHandlerObj.productSearchHandler.renderMatchedAttributesVirtualView({$id});
341
+ </script>
342
+ HTML;
343
+
344
+ } else {
345
+ $value .= <<<HTML
346
+ <script type="application/javascript">
347
+ {$searchHandler}.searchData[{$id}] = {};
348
+ {$searchHandler}.searchData[{$id}].matchingType = {$searchHandler}.MATCHING_TYPE_VIRTUAL_MAGENTO;
349
+ {$searchHandler}.searchData[{$id}].matchedAttributes = {$matchedAttributes};
350
+ {$searchHandler}.searchData[{$id}].destinationAttributes = {$destinationAttributes};
351
+ {$searchHandler}.searchData[{$id}].amazonVariation = {$amazonVariations};
352
+
353
+ ListingGridHandlerObj.productSearchHandler.renderMatchedAttributesVirtualView({$id});
354
+ </script>
355
+ HTML;
356
+ }
357
+ }
358
+
359
+ return $value . $magentoProductAttributesHtml . $magentoProductAttributesJs;
360
+ }
361
+
362
+ $specificsHtml = '';
363
+ $specificsJs = '<script type="text/javascript">';
364
+
365
+ // match options for individual
366
+ if ($this->listingProduct->getChildObject()->getVariationManager()->isIndividualType() &&
367
+ $this->listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()
368
+ ) {
369
+ $channelVariations = array();
370
+ foreach ($variations['asins'] as $asin => $asinAttributes) {
371
+ $channelVariations[$asin] = $asinAttributes['specifics'];
372
+ }
373
+
374
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
375
+ $this->matcherAttributes->setDestinationAttributes(array_keys($variations['set']));
376
+
377
+ if ($this->matcherAttributes->isAmountEqual() && $this->matcherAttributes->isFullyMatched()) {
378
+ $matchedAttributes = $this->matcherAttributes->getMatchedAttributes();
379
+
380
+ $this->matcherOptions->setMagentoProduct($this->listingProduct->getMagentoProduct());
381
+ $this->matcherOptions->setDestinationOptions($channelVariations);
382
+ $this->matcherOptions->setMatchedAttributes($matchedAttributes);
383
+
384
+ $productOptions = $this->listingProduct->getChildObject()->getVariationManager()
385
+ ->getTypeModel()->getProductOptions();
386
+
387
+ $requestedChildAsin = $this->matcherOptions->getMatchedOptionGeneralId($productOptions);
388
+ }
389
+ }
390
+
391
+ if (empty($requestedChildAsin)) {
392
+ $requestedChildAsin = $row->getData('requested_child_id');
393
+ }
394
+
395
+ $selectedOptions = array();
396
+ if ($requestedChildAsin) {
397
+ $selectedOptions = $variations['asins'][$requestedChildAsin]['specifics'];
398
+ }
399
+
400
+ $specificsHtml .= '<form action="javascript:void(0);">';
401
+
402
+ $attributesNames = '<span style="margin-left: 10px;
403
+ min-width: 100px;
404
+ max-width: 170px;
405
+ font-size: 11px;
406
+ color: #808080;
407
+ display: inline-block;">';
408
+ $attributeValues = '<span style="margin-left: 5px; display: inline-block;">';
409
+ foreach ($variations['set'] as $specificName => $specific) {
410
+ $attributesNames .= '<span style="margin-bottom: 5px; display: inline-block;">'.
411
+ ucfirst(strtolower($specificName)).
412
+ '</span><br/>';
413
+ $attributeValues .= '<input type="hidden" value="' . Mage::helper('M2ePro')->escapeHtml($specificName) .
414
+ '" class="specifics_name_'.$id.'">';
415
+ $attributeValues .= '<select class="specifics_'.$id.'"
416
+ onchange="ListingGridHandlerObj.productSearchHandler.specificsChange(this)"
417
+ style="width: 170px; margin-bottom: 5px; font-size: 10px;"
418
+ id="specific_'.$specificName.'_'.$id.'">';
419
+ $attributeValues .= '<option class="empty" value=""></option>';
420
+
421
+ if (!empty($requestedChildAsin)) {
422
+ foreach ($specific as $option) {
423
+
424
+ $selected = '';
425
+ if ($selectedOptions[$specificName] == $option) {
426
+ $selected = 'selected';
427
+ }
428
+
429
+ $option = Mage::helper('M2ePro')->escapeHtml($option);
430
+ $attributeValues .= '<option value="'.$option.'" '.$selected.'>'.$option.'</option>';
431
+ }
432
+ }
433
+
434
+ $attributeValues .= '</select><br/>';
435
+
436
+ $specificsJs .= <<<JS
437
+ ListingGridHandlerObj.productSearchHandler.specificsChange({id:"specific_{$specificName}_{$id}"});
438
+ JS;
439
+ }
440
+
441
+ $specificsHtml .= $attributesNames . '</span>';
442
+ $specificsHtml .= $attributeValues . '</span>';
443
+ $specificsHtml .= '</form>';
444
+
445
+ $specificsJs .= '</script>';
446
+
447
+ $variationAsins = json_encode($variations['asins']);
448
+ $variationTree = json_encode($this->getChannelVariationsTree($variations));
449
+
450
+ $specificsJsonContainer = <<<HTML
451
+ <div id="parent_asin_{$id}" style="display: none">{$generalId}</div>
452
+ <div id="asins_{$id}" style="display: none;">{$variationAsins}</div>
453
+ <div id="channel_variations_tree_{$id}" style="display: none;">{$variationTree}</div>
454
+ HTML;
455
+
456
+ return $value . $specificsHtml . $specificsJsonContainer . $specificsJs;
457
+ }
458
+
459
+ public function callbackColumnPrice($value, $row, $column, $isExport)
460
+ {
461
+ if (empty($value) || $row->getData('is_variation_product')) {
462
+ $value = Mage::helper('M2ePro')->__('N/A');
463
+ } else {
464
+ $value = Mage::app()->getLocale()->currency($this->currency)->toCurrency($value);
465
+ }
466
+
467
+ return '<div style="margin-right: 5px;">'.$value.'</div>';
468
+ }
469
+
470
+ public function callbackColumnActions($value, $row, $column, $isExport)
471
+ {
472
+ $assignText = Mage::helper('M2ePro')->__('Assign');
473
+ $iconWarningPath = $this->getSkinUrl('M2ePro/images/warning.png');
474
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_notice.gif');
475
+
476
+ if (!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct()
477
+ || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
478
+ if (!$row->getData('is_variation_product')) {
479
+
480
+ return <<<HTML
481
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
482
+ {$this->productId}, '{$row->getData('general_id')}');">{$assignText}</a>
483
+ HTML;
484
+ }
485
+
486
+ if (!$row->getData('bad_parent')) {
487
+
488
+ $msg = Mage::helper('M2ePro')->__(
489
+ 'Please select necessary Options for this Amazon Product to be able to assign ASIN/ISBN.'
490
+ );
491
+
492
+ return <<<HTML
493
+ <span>
494
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
495
+ <img id="map_link_error_icon_{$row->getId()}"
496
+ class="tool-tip-image"
497
+ style="vertical-align: middle; display: none;"
498
+ src="{$iconWarningPath}">
499
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
500
+ <img src="{$iconHelpPath}">
501
+ <span>{$msg}</span>
502
+ </span>
503
+ </span>
504
+ <div id="template_map_link_{$row->getId()}" style="display: none;">
505
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
506
+ {$this->productId}, '%general_id%', '%options_data%'
507
+ );">{$assignText}</a>
508
+ </div>
509
+ HTML;
510
+ }
511
+ }
512
+
513
+ if ($row->getData('is_variation_product') && !$row->getData('bad_parent')) {
514
+
515
+ $msg = Mage::helper('M2ePro')->__(
516
+ 'Please map Amazon and Magento Attributes for this Amazon Product to be able to assign ASIN/ISBN.'
517
+ );
518
+
519
+ $variations = $row->getData('variations');
520
+ $destinationAttributes = array_keys($variations['set']);
521
+
522
+ $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
523
+ $this->matcherAttributes->setDestinationAttributes($destinationAttributes);
524
+
525
+ if ($this->matcherAttributes->isSourceAmountGreater()) {
526
+ $msg = Mage::helper('M2ePro')->__(
527
+ 'Please map Magento and Amazon Attributes for this Amazon Product to be able to assign ASIN/ISBN.
528
+ Be careful, as the number of Magento Attributes is more than the number of Attributes in Amazon
529
+ Parent Product. Thus you should select fixed Value for unmatched Magento Variational Attribute.'
530
+ );
531
+ } else if ($this->matcherAttributes->isDestinationAmountGreater()) {
532
+ $msg = Mage::helper('M2ePro')->__(
533
+ 'Please map Magento and Amazon Attributes for this Amazon Product to be able to assign ASIN/ISBN.
534
+ Be careful, as the number of Attributes in Amazon Parent Product is more than the number of
535
+ Magento Attributes. Thus you should select fixed Value for unmatched Amazon Variational Attribute.'
536
+ );
537
+ }
538
+
539
+ return <<<HTML
540
+ <span>
541
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
542
+ <img id="map_link_error_icon_{$row->getId()}"
543
+ class="tool-tip-image"
544
+ style="vertical-align: middle;"
545
+ src="{$iconWarningPath}">
546
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
547
+ <img src="{$iconHelpPath}">
548
+ <span>{$msg}</span>
549
+ </span>
550
+ </span>
551
+ <div id="template_map_link_{$row->getId()}" style="display: none;">
552
+ <a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
553
+ {$this->productId}, '{$row->getData('general_id')}', '%options_data%'
554
+ );">{$assignText}</a>
555
+ </div>
556
+ HTML;
557
+
558
+ }
559
+
560
+ $msg = Mage::helper('M2ePro')->__(
561
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
562
+ This Amazon Product has no Variations. <br/>
563
+ Only Amazon Parent/Child Products can be assigned in "All Variations" Mode.'
564
+ );
565
+
566
+ if ($row->getData('is_variation_product') && $row->getData('bad_parent')) {
567
+ $msg = Mage::helper('M2ePro')->__(
568
+ 'This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
569
+ Amazon Service (API) does not return all required information about this Amazon Product.'
570
+ );
571
+ }
572
+
573
+ return <<<HTML
574
+ <span>
575
+ <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
576
+ <img id="map_link_error_icon_{$row->getId()}"
577
+ class="tool-tip-image"
578
+ style="vertical-align: middle;"
579
+ src="{$iconWarningPath}">
580
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
581
+ <img src="{$iconHelpPath}">
582
+ <span>{$msg}</span>
583
+ </span>
584
+ </span>
585
+ HTML;
586
+ }
587
+
588
+ //########################################
589
+
590
+ protected function _toHtml()
591
+ {
592
+ $magentoGreaterLeftSideText = Mage::helper('M2ePro')->__('This Amazon Attribute and its Value are virtualized '.
593
+ 'based on the selected Magento Variational Attribute and its Value as physically this Amazon Attribute ' .
594
+ 'does not exist.');
595
+ $magentoGreaterRightSideText = Mage::helper('M2ePro')->__('Select a particular Option of the Attribute to fix '.
596
+ 'it for virtualized Amazon Attribute. Please, be thoughtful as only those Variations of Magento Product which '.
597
+ 'contains the selected Option can be sold on Amazon.');
598
+
599
+ $amazonGreaterLeftSideText = Mage::helper('M2ePro')->__('This Magento Attribute and its Value are virtualized '.
600
+ 'based on the selected Amazon Variational Attribute and its Value as physically this Magento Attribute ' .
601
+ 'does not exist.');
602
+ $amazonGreaterRightSideText = Mage::helper('M2ePro')->__('Select a particular Option of the Attribute to fix ' .
603
+ 'it for virtualized Magento Attribute. Please, be thoughtful as your offer will be available only for those ' .
604
+ 'Buyers who selected the same Option.');
605
+
606
+ $duplicateMagentoAttributesError = Mage::helper('M2ePro')->__('The Magento Attributes which you selected in ' .
607
+ 'your settings have the same Labels. Such combination is invalid. Please, add the valid combination ' .
608
+ 'of Attributes.');
609
+ $duplicateAmazonAttributesError = Mage::helper('M2ePro')->__('The Amazon Attributes which you selected in ' .
610
+ 'your settings have the same Labels. Such combination is invalid. Please, add the valid combination ' .
611
+ 'of Attributes.');
612
+
613
+ $changeOption = Mage::helper('M2ePro')->__('Change option');
614
+
615
+ $jsText = <<<HTML
616
+ <script type="text/javascript">
617
+ M2ePro.text.help_icon_magento_greater_left = '{$magentoGreaterLeftSideText}';
618
+ M2ePro.text.help_icon_magento_greater_right = '{$magentoGreaterRightSideText}';
619
+
620
+ M2ePro.text.help_icon_amazon_greater_left = '{$amazonGreaterLeftSideText}';
621
+ M2ePro.text.help_icon_amazon_greater_right = '{$amazonGreaterRightSideText}';
622
+
623
+ M2ePro.text.duplicate_magento_attribute_error = '{$duplicateMagentoAttributesError}';
624
+ M2ePro.text.duplicate_amazon_attribute_error = '{$duplicateAmazonAttributesError}';
625
+
626
+ M2ePro.text.change_option = '{$changeOption}';
627
+ </script>
628
+ HTML;
629
+
630
+ $javascriptsMain = <<<HTML
631
+ <script type="text/javascript">
632
+
633
+ $$('#amazonProductSearchGrid div.grid th').each(function(el) {
634
+ el.style.padding = '2px 2px';
635
+ });
636
+
637
+ $$('#amazonProductSearchGrid div.grid td').each(function(el) {
638
+ el.style.padding = '2px 2px';
639
+ });
640
+
641
+ </script>
642
+ HTML;
643
+
644
+ $toolTipIcon = $this->getSkinUrl('M2ePro/images/tool-tip-icon.png');
645
+ $helpIcon = $this->getSkinUrl('M2ePro/images/help.png');
646
+
647
+ $searchData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
648
+
649
+ $searchParamsHtml = <<<HTML
650
+ <input id="amazon_asin_search_type" type="hidden" value="{$searchData['type']}">
651
+ <input id="amazon_asin_search_value" type="hidden" value="{$searchData['value']}">
652
+
653
+ <div id="product_search_help_icon_tpl" style="display: none">
654
+ <img class="tool-tip-image" style="vertical-align: middle;" src="{$toolTipIcon}">
655
+ <span class="tool-tip-message tip-right" style="display: none;">
656
+ <img src="{$helpIcon}">
657
+ <span class="tool-tip-message-text"></span>
658
+ </span>
659
+ </div>
660
+ HTML;
661
+
662
+ return $jsText . parent::_toHtml() . $javascriptsMain . $searchParamsHtml;
663
+ }
664
+
665
+ //########################################
666
+
667
+ public function getGridUrl()
668
+ {
669
+ return $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid', array('_current'=>true));
670
+ }
671
+
672
+ public function getRowUrl($row)
673
+ {
674
+ return false;
675
+ }
676
+
677
+ //########################################
678
+
679
+ private function getChannelVariationsTree($variations)
680
+ {
681
+ $channelVariations = array();
682
+ foreach ($variations['asins'] as $asin => $asinAttributes) {
683
+ $channelVariations[$asin] = $asinAttributes['specifics'];
684
+ }
685
+
686
+ if (empty($channelVariations)) {
687
+ return new stdClass();
688
+ }
689
+
690
+ $firstAttribute = key($variations['set']);
691
+
692
+ return $this->prepareVariations(
693
+ $firstAttribute, $channelVariations, $variations['set']
694
+ );
695
+ }
696
+
697
+ private function prepareVariations($currentAttribute, $variations, $variationsSets,$filters = array())
698
+ {
699
+ $return = false;
700
+
701
+ $temp = array_flip(array_keys($variationsSets));
702
+
703
+ $lastAttributePosition = count($variationsSets) - 1;
704
+ $currentAttributePosition = $temp[$currentAttribute];
705
+
706
+ if ($currentAttributePosition != $lastAttributePosition) {
707
+
708
+ $temp = array_keys($variationsSets);
709
+ $nextAttribute = $temp[$currentAttributePosition + 1];
710
+
711
+ foreach ($variationsSets[$currentAttribute] as $option) {
712
+
713
+ $filters[$currentAttribute] = $option;
714
+
715
+ $result = $this->prepareVariations(
716
+ $nextAttribute,$variations,$variationsSets,$filters
717
+ );
718
+
719
+ if (!$result) {
720
+ continue;
721
+ }
722
+
723
+ $return[$currentAttribute][$option] = $result;
724
+ }
725
+
726
+ ksort($return[$currentAttribute]);
727
+
728
+ return $return;
729
+ }
730
+
731
+ $return = false;
732
+ foreach ($variations as $key => $magentoVariation) {
733
+ foreach ($magentoVariation as $attribute => $option) {
734
+
735
+ if ($attribute == $currentAttribute) {
736
+
737
+ if (count($variationsSets) != 1) {
738
+ continue;
739
+ }
740
+
741
+ $values = array_flip($variationsSets[$currentAttribute]);
742
+ $return = array($currentAttribute => $values);
743
+
744
+ foreach ($return[$currentAttribute] as &$option) {
745
+ $option = true;
746
+ }
747
+
748
+ return $return;
749
+ }
750
+
751
+ if ($option != $filters[$attribute]) {
752
+ unset($variations[$key]);
753
+ continue;
754
+ }
755
+
756
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
757
+ if ($tempAttribute == $currentAttribute) {
758
+ $option = $tempOption;
759
+ $return[$currentAttribute][$option] = true;
760
+ }
761
+ }
762
+ }
763
+ }
764
+
765
+ if (count($variations) < 1) {
766
+ return false;
767
+ }
768
+
769
+ ksort($return[$currentAttribute]);
770
+
771
+ return $return;
772
+ }
773
+
774
+ //########################################
775
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Main.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_Main
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/main.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ // ---------------------------------------
24
+ $data = array(
25
+ 'id' => 'productSearch_submit_button',
26
+ 'label' => Mage::helper('M2ePro')->__('Search'),
27
+ 'class' => 'productSearch_submit_button submit'
28
+ );
29
+ $buttonSubmitBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
30
+ $this->setChild('productSearch_submit_button', $buttonSubmitBlock);
31
+ // ---------------------------------------
32
+
33
+ // ---------------------------------------
34
+ $data = array(
35
+ 'id' => 'productSearch_back_button',
36
+ 'label' => Mage::helper('M2ePro')->__('Back'),
37
+ 'class' => 'productSearch_back_button'
38
+ );
39
+ $buttonBackBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
40
+ $this->setChild('productSearch_back_button', $buttonBackBlock);
41
+ // ---------------------------------------
42
+
43
+ // ---------------------------------------
44
+ $data = array(
45
+ 'id' => 'productSearch_cancel_button',
46
+ 'label' => Mage::helper('M2ePro')->__('Close'),
47
+ 'class' => 'productSearch_cancel_button'
48
+ );
49
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
50
+ $this->setChild('productSearch_cancel_button', $buttonCancelBlock);
51
+ // ---------------------------------------
52
+
53
+ $buttonResetBlock = $this->getChild('productSearch_cleanSuggest_button');
54
+
55
+ if (empty($buttonResetBlock)) {
56
+ // ---------------------------------------
57
+ $data = array(
58
+ 'id' => 'productSearch_cleanSuggest_button',
59
+ 'label' => Mage::helper('M2ePro')->__('Clear Search Results'),
60
+ 'class' => 'productSearch_cleanSuggest_button',
61
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndOpenSearchMenu()'
62
+ );
63
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
64
+ $this->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
65
+ // ---------------------------------------
66
+ }
67
+
68
+ parent::_beforeToHtml();
69
+ }
70
+
71
+ protected function _toHtml()
72
+ {
73
+ $vocabularyAttributesBlock = $this->getLayout()->createBlock(
74
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyAttributesPopup'
75
+ );
76
+
77
+ $vocabularyOptionsBlock = $this->getLayout()->createBlock(
78
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyOptionsPopup'
79
+ );
80
+
81
+ return $vocabularyAttributesBlock->toHtml() . $vocabularyOptionsBlock->toHtml() . parent::_toHtml();
82
+ }
83
+
84
+ //########################################
85
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/Menu.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_Menu
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ protected $listingProductId;
13
+
14
+ //########################################
15
+
16
+ /**
17
+ * @param mixed $listingProductId
18
+ * @return $this
19
+ */
20
+ public function setListingProductId($listingProductId)
21
+ {
22
+ $this->listingProductId = $listingProductId;
23
+
24
+ return $this;
25
+ }
26
+ /**
27
+ * @return mixed
28
+ */
29
+ public function getListingProductId()
30
+ {
31
+ return $this->listingProductId;
32
+ }
33
+
34
+ // ---------------------------------------
35
+
36
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
37
+ protected $listingProduct = null;
38
+
39
+ /**
40
+ * @return Ess_M2ePro_Model_Listing_Product|null
41
+ */
42
+ public function getListingProduct()
43
+ {
44
+ if (is_null($this->listingProduct)) {
45
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
46
+ ->getObject('Listing_Product', $this->getListingProductId());
47
+ }
48
+
49
+ return $this->listingProduct;
50
+ }
51
+
52
+ public function isIndividualFromBundleOrSimpleWithCustome()
53
+ {
54
+ if (!$this->getListingProduct()->getChildObject()->getVariationManager()->isIndividualType()) {
55
+ return false;
56
+ }
57
+
58
+ return $this->getListingProduct()->getMagentoProduct()->isBundleType() ||
59
+ $this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
60
+ }
61
+
62
+ public function isParentFromBundleOrSimpleWithCustome()
63
+ {
64
+ if (!$this->getListingProduct()->getChildObject()->getVariationManager()->isRelationParentType()) {
65
+ return false;
66
+ }
67
+
68
+ return $this->getListingProduct()->getMagentoProduct()->isBundleType() ||
69
+ $this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
70
+ }
71
+
72
+ public function __construct()
73
+ {
74
+ parent::__construct();
75
+
76
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/menu.phtml');
77
+ }
78
+
79
+ protected function _beforeToHtml()
80
+ {
81
+ // ---------------------------------------
82
+ $data = array(
83
+ 'id' => 'productSearchMenu_cancel_button',
84
+ 'label' => Mage::helper('M2ePro')->__('Close'),
85
+ 'class' => 'productSearchMenu_cancel_button'
86
+ );
87
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
88
+ $this->setChild('productSearchMenu_cancel_button', $buttonCancelBlock);
89
+ // ---------------------------------------
90
+
91
+ parent::_beforeToHtml();
92
+ }
93
+
94
+ //########################################
95
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/ProductSearch/SuggestedAsinGridHelp.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_ProductSearch_SuggestedAsinGridHelp
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonSuggestedAsinGridHelp');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/listing/product_search/suggested_asin_grid_help.phtml');
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Search extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('listingAmazonSearch');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_amazon_listing_search';
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
+ $headerText = Mage::helper('M2ePro')->__("Search %component_name% Listings Items", $componentName);
29
+ } else {
30
+ $headerText = Mage::helper('M2ePro')->__("Search Listings Items");
31
+ }
32
+
33
+ $this->_headerText = $headerText;
34
+ // ---------------------------------------
35
+
36
+ // Set buttons actions
37
+ // ---------------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ // ---------------------------------------
45
+
46
+ if (!is_null($this->getRequest()->getParam('back'))) {
47
+ // ---------------------------------------
48
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_amazon_listing/search');
49
+ $this->_addButton('back', array(
50
+ 'label' => Mage::helper('M2ePro')->__('Back'),
51
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
52
+ 'class' => 'back'
53
+ ));
54
+ // ---------------------------------------
55
+ }
56
+
57
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/search');
58
+
59
+ // ---------------------------------------
60
+ $url = $this->getUrl(
61
+ '*/adminhtml_common_listing/index',
62
+ array(
63
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON,
64
+ 'back'=> $backUrl
65
+ )
66
+ );
67
+ $this->_addButton('goto_listings', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Listings'),
69
+ 'onclick' => 'setLocation(\'' . $url . '\')',
70
+ 'class' => 'button_link'
71
+ ));
72
+ // ---------------------------------------
73
+
74
+ // ---------------------------------------
75
+ $this->_addButton('goto_templates', array(
76
+ 'label' => Mage::helper('M2ePro')->__('Policies'),
77
+ 'onclick' => '',
78
+ 'class' => 'button_link drop_down templates-drop-down'
79
+ ));
80
+ // ---------------------------------------
81
+
82
+ // ---------------------------------------
83
+ $url = $this->getUrl(
84
+ '*/adminhtml_common_log/listing',
85
+ array(
86
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON
87
+ )
88
+ );
89
+ $this->_addButton('view_log', array(
90
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
91
+ 'onclick' => 'window.open(\'' . $url . '\')',
92
+ 'class' => 'button_link'
93
+ ));
94
+ // ---------------------------------------
95
+ }
96
+
97
+ //########################################
98
+
99
+ protected function _toHtml()
100
+ {
101
+ return $this->getTemplatesButtonJavascript() . parent::_toHtml();
102
+ }
103
+
104
+ public function getGridHtml()
105
+ {
106
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_listing_search_help');
107
+ return $helpBlock->toHtml() . parent::getGridHtml();
108
+ }
109
+
110
+ //########################################
111
+
112
+ protected function getTemplatesButtonJavascript()
113
+ {
114
+ $data = array(
115
+ 'target_css_class' => 'templates-drop-down',
116
+ 'items' => $this->getTemplatesButtonDropDownItems()
117
+ );
118
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
119
+ $dropDownBlock->setData($data);
120
+
121
+ return $dropDownBlock->toHtml();
122
+ }
123
+
124
+ protected function getTemplatesButtonDropDownItems()
125
+ {
126
+ $items = array();
127
+
128
+ $filter = base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Amazon::NICK);
129
+
130
+ // ---------------------------------------
131
+ $url = $this->getUrl('*/adminhtml_common_template_sellingFormat/index', array('filter' => $filter));
132
+ $items[] = array(
133
+ 'url' => $url,
134
+ 'label' => Mage::helper('M2ePro')->__('Selling Format Policies'),
135
+ 'target' => '_blank'
136
+ );
137
+ // ---------------------------------------
138
+
139
+ // ---------------------------------------
140
+ $url = $this->getUrl('*/adminhtml_common_template_synchronization/index', array('filter' => $filter));
141
+ $items[] = array(
142
+ 'url' => $url,
143
+ 'label' => Mage::helper('M2ePro')->__('Synchronization Policies'),
144
+ 'target' => '_blank'
145
+ );
146
+ // ---------------------------------------
147
+
148
+ // ---------------------------------------
149
+ $url = $this->getUrl(
150
+ '*/adminhtml_common_amazon_template_description/index'
151
+ );
152
+ $items[] = array(
153
+ 'url' => $url,
154
+ 'label' => Mage::helper('M2ePro')->__('%amazon% Description Policies',
155
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()),
156
+ 'target' => '_blank'
157
+ );
158
+ // ---------------------------------------
159
+
160
+ return $items;
161
+ }
162
+
163
+ //########################################
164
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Search/Grid.php ADDED
@@ -0,0 +1,1048 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Search_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingSearchGrid');
20
+ // ---------------------------------------
21
+
22
+ // Set default values
23
+ // ---------------------------------------
24
+ $this->setDefaultSort('id');
25
+ $this->setDefaultDir('DESC');
26
+ $this->setSaveParametersInSession(true);
27
+ $this->setUseAjax(true);
28
+ // ---------------------------------------
29
+ }
30
+
31
+ //########################################
32
+
33
+ protected function _prepareCollection()
34
+ {
35
+ // Get collection products in listing
36
+ // ---------------------------------------
37
+ $listingProductCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
38
+ $listingProductCollection->getSelect()->distinct();
39
+ $listingProductCollection->getSelect()
40
+ ->join(array('l'=>Mage::getResourceModel('M2ePro/Listing')->getMainTable()),
41
+ '(`l`.`id` = `main_table`.`listing_id`)',
42
+ array('listing_title'=>'title','store_id','marketplace_id'))
43
+ ->join(array('al'=>Mage::getResourceModel('M2ePro/Amazon_Listing')->getMainTable()),
44
+ '(`al`.`listing_id` = `l`.`id`)',
45
+ array('template_selling_format_id'));
46
+ // ---------------------------------------
47
+
48
+ // only parents and individuals
49
+ $listingProductCollection->getSelect()->where('second_table.variation_parent_id IS NULL');
50
+
51
+ // Communicate with magento product table
52
+ // ---------------------------------------
53
+ $dbSelect = Mage::getResourceModel('core/config')->getReadConnection()
54
+ ->select()
55
+ ->from(Mage::getSingleton('core/resource')
56
+ ->getTableName('catalog_product_entity_varchar'),
57
+ new Zend_Db_Expr('MAX(`store_id`)'))
58
+ ->where("`entity_id` = `main_table`.`product_id`")
59
+ ->where("`attribute_id` = `ea`.`attribute_id`")
60
+ ->where("`store_id` = 0 OR `store_id` = `l`.`store_id`");
61
+
62
+ $listingProductCollection->getSelect()
63
+ //->join(array('csi'=>Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
64
+ // '(csi.product_id = `main_table`.product_id)',array('qty'))
65
+ ->join(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
66
+ '(cpe.entity_id = `main_table`.product_id)',
67
+ array('magento_sku'=>'sku'))
68
+ ->join(array('cisi'=>Mage::getSingleton('core/resource')
69
+ ->getTableName('cataloginventory_stock_item')),
70
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
71
+ array('is_in_stock'))
72
+ ->join(array('cpev'=>Mage::getSingleton('core/resource')
73
+ ->getTableName('catalog_product_entity_varchar')),
74
+ "(`cpev`.`entity_id` = `main_table`.product_id)",
75
+ array('value'))
76
+ ->join(array('ea'=>Mage::getSingleton('core/resource')->getTableName('eav_attribute')),
77
+ '(`cpev`.`attribute_id` = `ea`.`attribute_id` AND `ea`.`attribute_code` = \'name\')',
78
+ array())
79
+ ->where('`cpev`.`store_id` = ('.$dbSelect->__toString().')');
80
+ // ---------------------------------------
81
+
82
+ $listingProductCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
83
+ $listingProductCollection->getSelect()->columns(
84
+ array(
85
+ 'is_m2epro_listing' => new Zend_Db_Expr('1'),
86
+ 'magento_sku' => 'cpe.sku',
87
+ 'is_in_stock' => 'cisi.is_in_stock',
88
+ 'product_name' => 'cpev.value',
89
+ 'listing_title' => 'l.title',
90
+ 'store_id' => 'l.store_id',
91
+ 'account_id' => 'l.account_id',
92
+ 'marketplace_id' => 'l.marketplace_id',
93
+ 'template_selling_format_id' => 'al.template_selling_format_id',
94
+ 'listing_product_id' => 'main_table.id',
95
+ 'product_id' => 'main_table.product_id',
96
+ 'listing_id' => 'main_table.listing_id',
97
+ 'status' => 'main_table.status',
98
+ 'is_general_id_owner' => 'second_table.is_general_id_owner',
99
+ 'general_id' => 'second_table.general_id',
100
+ 'is_afn_channel' => 'second_table.is_afn_channel',
101
+ 'is_variation_parent' => 'second_table.is_variation_parent',
102
+ 'is_repricing' => 'second_table.is_repricing',
103
+ 'variation_child_statuses' => 'second_table.variation_child_statuses',
104
+ 'online_sku' => 'second_table.sku',
105
+ 'online_qty' => 'second_table.online_qty',
106
+ 'online_price' => 'second_table.online_price',
107
+ 'online_sale_price' => 'second_table.online_sale_price',
108
+ 'online_sale_price_start_date' => 'second_table.online_sale_price_start_date',
109
+ 'online_sale_price_end_date' => 'second_table.online_sale_price_end_date',
110
+ 'min_online_price' => 'IF(
111
+ (`t`.`variation_min_price` IS NULL),
112
+ IF(
113
+ `second_table`.`online_sale_price_start_date` IS NOT NULL AND
114
+ `second_table`.`online_sale_price_end_date` IS NOT NULL AND
115
+ `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND
116
+ `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(),
117
+ `second_table`.`online_sale_price`,
118
+ `second_table`.`online_price`
119
+ ),
120
+ `t`.`variation_min_price`
121
+ )',
122
+ 'max_online_price' => 'IF(
123
+ (`t`.`variation_max_price` IS NULL),
124
+ IF(
125
+ `second_table`.`online_sale_price_start_date` IS NOT NULL AND
126
+ `second_table`.`online_sale_price_end_date` IS NOT NULL AND
127
+ `second_table`.`online_sale_price_start_date` <= CURRENT_DATE() AND
128
+ `second_table`.`online_sale_price_end_date` >= CURRENT_DATE(),
129
+ `second_table`.`online_sale_price`,
130
+ `second_table`.`online_price`
131
+ ),
132
+ `t`.`variation_max_price`
133
+ )'
134
+ )
135
+ );
136
+ $listingProductCollection->getSelect()->joinLeft(
137
+ new Zend_Db_Expr('(
138
+ SELECT
139
+ `malp`.`variation_parent_id`,
140
+ MIN(
141
+ IF(
142
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
143
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
144
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
145
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
146
+ `malp`.`online_sale_price`,
147
+ `malp`.`online_price`
148
+ )
149
+ ) as variation_min_price,
150
+ MAX(
151
+ IF(
152
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
153
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
154
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
155
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
156
+ `malp`.`online_sale_price`,
157
+ `malp`.`online_price`
158
+ )
159
+ ) as variation_max_price
160
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
161
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
162
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
163
+ WHERE `mlp`.`status` IN (
164
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
165
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
166
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
167
+ GROUP BY `malp`.`variation_parent_id`
168
+ )'),
169
+ 'second_table.listing_product_id=t.variation_parent_id',
170
+ array(
171
+ 'variation_min_price' => 'variation_min_price',
172
+ 'variation_max_price' => 'variation_max_price',
173
+ )
174
+ );
175
+
176
+ // ---------------------------------------
177
+ $listingOtherCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Other');
178
+ $listingOtherCollection->getSelect()->distinct();
179
+
180
+ // add stock availability, type id, status & visibility to select
181
+ // ---------------------------------------
182
+ $listingOtherCollection->getSelect()
183
+ ->joinLeft(
184
+ array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()),
185
+ '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)',
186
+ array('is_in_stock'))
187
+ ->joinLeft(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
188
+ '(cpe.entity_id = `main_table`.product_id)',
189
+ array('magento_sku'=>'sku'));
190
+ // ---------------------------------------
191
+
192
+ $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
193
+ $listingOtherCollection->getSelect()->columns(
194
+ array(
195
+ 'is_m2epro_listing' => new Zend_Db_Expr(0),
196
+ 'magento_sku' => 'cpe.sku',
197
+ 'is_in_stock' => 'cisi.is_in_stock',
198
+ 'product_name' => 'second_table.title',
199
+ 'listing_title' => new Zend_Db_Expr('NULL'),
200
+ 'store_id' => new Zend_Db_Expr(0),
201
+ 'account_id' => 'main_table.account_id',
202
+ 'marketplace_id' => 'main_table.marketplace_id',
203
+ 'template_selling_format_id' => new Zend_Db_Expr('NULL'),
204
+ 'listing_product_id' => new Zend_Db_Expr('NULL'),
205
+ 'product_id' => 'main_table.product_id',
206
+ 'listing_id' => new Zend_Db_Expr('NULL'),
207
+ 'status' => 'main_table.status',
208
+ 'is_general_id_owner' => new Zend_Db_Expr('NULL'),
209
+ 'general_id' => 'second_table.general_id',
210
+ 'is_afn_channel' => 'second_table.is_afn_channel',
211
+ 'is_variation_parent' => new Zend_Db_Expr('NULL'),
212
+ 'is_repricing' => 'second_table.is_repricing',
213
+ 'variation_child_statuses' => new Zend_Db_Expr('NULL'),
214
+ 'online_sku' => 'second_table.sku',
215
+ 'online_qty' => 'second_table.online_qty',
216
+ 'online_price' => 'second_table.online_price',
217
+ 'online_sale_price' => new Zend_Db_Expr('NULL'),
218
+ 'online_sale_price_start_date' => new Zend_Db_Expr('NULL'),
219
+ 'online_sale_price_end_date' => new Zend_Db_Expr('NULL'),
220
+ 'min_online_price' => 'second_table.online_price',
221
+ 'max_online_price' => 'second_table.online_price',
222
+ 'variation_min_price' => new Zend_Db_Expr('NULL'),
223
+ 'variation_max_price' => new Zend_Db_Expr('NULL')
224
+ )
225
+ );
226
+ // ---------------------------------------
227
+
228
+ // ---------------------------------------
229
+ $selects = array(
230
+ $listingProductCollection->getSelect(),
231
+ $listingOtherCollection->getSelect()
232
+ );
233
+
234
+ $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
235
+ $unionSelect->union($selects);
236
+
237
+ $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
238
+ $resultCollection->getSelect()->reset()->from(
239
+ array('main_table' => $unionSelect),
240
+ array(
241
+ 'is_m2epro_listing',
242
+ 'magento_sku',
243
+ 'is_in_stock',
244
+ 'product_name',
245
+ 'listing_title',
246
+ 'store_id',
247
+ 'account_id',
248
+ 'marketplace_id',
249
+ 'template_selling_format_id',
250
+ 'listing_product_id',
251
+ 'product_id',
252
+ 'listing_id',
253
+ 'status',
254
+ 'is_general_id_owner',
255
+ 'general_id',
256
+ 'is_afn_channel',
257
+ 'is_variation_parent',
258
+ 'is_repricing',
259
+ 'variation_child_statuses',
260
+ 'online_sku',
261
+ 'online_qty',
262
+ 'online_price',
263
+ 'online_sale_price',
264
+ 'online_sale_price_start_date',
265
+ 'online_sale_price_end_date',
266
+ 'min_online_price',
267
+ 'max_online_price',
268
+ 'variation_min_price',
269
+ 'variation_max_price'
270
+ )
271
+ );
272
+
273
+ // Set collection to grid
274
+ $this->setCollection($resultCollection);
275
+
276
+ return parent::_prepareCollection();
277
+ }
278
+
279
+ protected function _prepareColumns()
280
+ {
281
+ $this->addColumn('product_id', array(
282
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
283
+ 'align' => 'right',
284
+ 'width' => '100px',
285
+ 'type' => 'number',
286
+ 'index' => 'product_id',
287
+ 'filter_index' => 'product_id',
288
+ 'frame_callback' => array($this, 'callbackColumnProductId')
289
+ ));
290
+
291
+ $this->addColumn('name', array(
292
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Listing / Product SKU'),
293
+ 'align' => 'left',
294
+ 'type' => 'text',
295
+ 'index' => 'product_name',
296
+ 'filter_index' => 'product_name',
297
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
298
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
299
+ ));
300
+
301
+ $this->addColumn('stock_availability',
302
+ array(
303
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
304
+ 'width' => '100px',
305
+ 'index' => 'is_in_stock',
306
+ 'filter_index' => 'is_in_stock',
307
+ 'type' => 'options',
308
+ 'sortable' => false,
309
+ 'options' => array(
310
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
311
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
312
+ ),
313
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
314
+ ));
315
+
316
+ if (Mage::helper('M2ePro/View_Common')->is3rdPartyShouldBeShown(Ess_M2ePro_Helper_Component_Amazon::NICK)) {
317
+ $this->addColumn('is_m2epro_listing', array(
318
+ 'header' => Mage::helper('M2ePro')->__('Listing Type'),
319
+ 'align' => 'left',
320
+ 'width' => '100px',
321
+ 'type' => 'options',
322
+ 'sortable' => false,
323
+ 'index' => 'is_m2epro_listing',
324
+ 'options' => array(
325
+ 1 => Mage::helper('M2ePro')->__('M2E Pro'),
326
+ 0 => Mage::helper('M2ePro')->__('3rd Party')
327
+ )
328
+ ));
329
+ }
330
+
331
+ $this->addColumn('sku', array(
332
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
333
+ 'align' => 'left',
334
+ 'width' => '150px',
335
+ 'type' => 'text',
336
+ 'index' => 'online_sku',
337
+ 'filter_index' => 'online_sku',
338
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
339
+ ));
340
+
341
+ $this->addColumn('general_id', array(
342
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
343
+ 'align' => 'left',
344
+ 'width' => '100px',
345
+ 'type' => 'text',
346
+ 'index' => 'general_id',
347
+ 'filter_index' => 'general_id',
348
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
349
+ ));
350
+
351
+ $this->addColumn('online_qty', array(
352
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
353
+ 'align' => 'right',
354
+ 'width' => '70px',
355
+ 'type' => 'number',
356
+ 'index' => 'online_qty',
357
+ 'filter_index' => 'online_qty',
358
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty'),
359
+ 'filter' => 'M2ePro/adminhtml_common_amazon_grid_column_filter_qty',
360
+ 'filter_condition_callback' => array($this, 'callbackFilterQty')
361
+ ));
362
+
363
+ $dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
364
+
365
+ if ($dir == 'desc') {
366
+ $priceSortField = 'max_online_price';
367
+ } else {
368
+ $priceSortField = 'min_online_price';
369
+ }
370
+
371
+ $priceColumn = array(
372
+ 'header' => Mage::helper('M2ePro')->__('Price'),
373
+ 'align' => 'right',
374
+ 'width' => '110px',
375
+ 'type' => 'number',
376
+ 'index' => $priceSortField,
377
+ 'filter_index' => $priceSortField,
378
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
379
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
380
+ );
381
+
382
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled()) {
383
+ $priceColumn['filter'] = 'M2ePro/adminhtml_common_amazon_grid_column_filter_price';
384
+ }
385
+
386
+ $this->addColumn('online_price', $priceColumn);
387
+
388
+ $this->addColumn('status', array(
389
+ 'header' => Mage::helper('M2ePro')->__('Status'),
390
+ 'width' => '125px',
391
+ 'index' => 'status',
392
+ 'filter_index' => 'status',
393
+ 'type' => 'options',
394
+ 'sortable' => false,
395
+ 'options' => array(
396
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
397
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
398
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
399
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
400
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
401
+ ),
402
+ 'frame_callback' => array($this, 'callbackColumnStatus')
403
+ ));
404
+
405
+ $this->addColumn('goto_listing_item', array(
406
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
407
+ 'align' => 'center',
408
+ 'width' => '50px',
409
+ 'type' => 'text',
410
+ 'filter' => false,
411
+ 'sortable' => false,
412
+ 'frame_callback' => array($this, 'callbackColumnActions')
413
+ ));
414
+
415
+ return parent::_prepareColumns();
416
+ }
417
+
418
+ //########################################
419
+
420
+ public function callbackColumnProductId($value, $row, $column, $isExport)
421
+ {
422
+ if (is_null($row->getData('product_id'))) {
423
+ return Mage::helper('M2ePro')->__('N/A');
424
+ }
425
+
426
+ $productId = (int)$row->getData('product_id');
427
+ $storeId = (int)$row->getData('store_id');
428
+
429
+ $withoutImageHtml = '<a href="'
430
+ .$this->getUrl('adminhtml/catalog_product/edit',
431
+ array('id' => $productId))
432
+ .'" target="_blank">'
433
+ .$productId
434
+ .'</a>';
435
+
436
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
437
+ ->getGroupValue('/view/',
438
+ 'show_products_thumbnails');
439
+ if (!$showProductsThumbnails) {
440
+ return $withoutImageHtml;
441
+ }
442
+
443
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
444
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
445
+ $magentoProduct->setProductId($productId);
446
+ $magentoProduct->setStoreId($storeId);
447
+
448
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
449
+ if (is_null($imageUrlResized)) {
450
+ return $withoutImageHtml;
451
+ }
452
+
453
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
454
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
455
+
456
+ return $withImageHtml;
457
+ }
458
+
459
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
460
+ {
461
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
462
+
463
+ if (!is_null($row->getData('listing_id'))) {
464
+ $urlParams = array();
465
+ $urlParams['id'] = $row->getData('listing_id');
466
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/search');
467
+
468
+ $listingUrl = $this->getUrl('*/adminhtml_common_amazon_listing/view',$urlParams);
469
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
470
+
471
+ if (strlen($listingTitle) > 50) {
472
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
473
+ }
474
+
475
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
476
+ $value .= '<strong>'
477
+ .Mage::helper('M2ePro')->__('Listing')
478
+ .': </strong> <a href="'
479
+ .$listingUrl
480
+ .'">'
481
+ .$listingTitle
482
+ .'</a>';
483
+ }
484
+
485
+ if (!is_null($row->getData('magento_sku'))) {
486
+ $tempSku = $row->getData('magento_sku');
487
+
488
+ $value .= '<br/><strong>'
489
+ . Mage::helper('M2ePro')->__('SKU')
490
+ . ':</strong> '
491
+ . Mage::helper('M2ePro')->escapeHtml($tempSku);
492
+ }
493
+
494
+ if (is_null($row->getData('listing_product_id'))) {
495
+ return $value;
496
+ }
497
+
498
+ $listingProductId = (int)$row->getData('listing_product_id');
499
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
500
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
501
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
502
+
503
+ if ($variationManager->isVariationParent()) {
504
+ $productAttributes = $listingProduct->getChildObject()->getVariationManager()
505
+ ->getTypeModel()->getProductAttributes();
506
+
507
+ $virtualProductAttributes = $variationManager->getTypeModel()->getVirtualProductAttributes();
508
+ $virtualChannelAttributes = $variationManager->getTypeModel()->getVirtualChannelAttributes();
509
+
510
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey;"><br/>';
511
+ $attributesStr = '';
512
+ if (empty($virtualProductAttributes) && empty($virtualChannelAttributes)) {
513
+ $attributesStr = implode(', ', $productAttributes);
514
+ } else {
515
+ foreach ($productAttributes as $attribute) {
516
+ if (in_array($attribute, array_keys($virtualProductAttributes))) {
517
+
518
+ $attributesStr .= '<span style="border-bottom: 2px dotted grey">' . $attribute .
519
+ ' (' . $virtualProductAttributes[$attribute] . ')</span>, ';
520
+
521
+ } else if (in_array($attribute, array_keys($virtualChannelAttributes))) {
522
+
523
+ $attributesStr .= '<span>' . $attribute .
524
+ ' (' . $virtualChannelAttributes[$attribute] . ')</span>, ';
525
+
526
+ } else {
527
+ $attributesStr .= $attribute . ', ';
528
+ }
529
+ }
530
+ $attributesStr = rtrim($attributesStr, ', ');
531
+ }
532
+ $value .= $attributesStr;
533
+ $value .= '</div>';
534
+ }
535
+
536
+ if ($variationManager->isIndividualType() &&
537
+ $variationManager->getTypeModel()->isVariationProductMatched()
538
+ ) {
539
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
540
+
541
+ $value .= '<br/>';
542
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
543
+ foreach ($productOptions as $attribute => $option) {
544
+ !$option && $option = '--';
545
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
546
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
547
+ }
548
+ $value .= '</div>';
549
+ $value .= '<br/>';
550
+ }
551
+
552
+ return $value;
553
+ }
554
+
555
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
556
+ {
557
+ if (is_null($row->getData('is_in_stock'))) {
558
+ return Mage::helper('M2ePro')->__('N/A');
559
+ }
560
+
561
+ if ((int)$row->getData('is_in_stock') <= 0) {
562
+ return '<span style="color: red;">'.$value.'</span>';
563
+ }
564
+
565
+ return $value;
566
+ }
567
+
568
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
569
+ {
570
+ if ((!$row->getData('is_variation_parent') &&
571
+ $row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
572
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
573
+
574
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
575
+ }
576
+
577
+ if (is_null($value) || $value === '') {
578
+ return Mage::helper('M2ePro')->__('N/A');
579
+ }
580
+
581
+ return $value;
582
+ }
583
+
584
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
585
+ {
586
+ if (empty($value)) {
587
+
588
+ if ((int)$row->getData('status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
589
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
590
+ }
591
+
592
+ if ($row->getData('is_general_id_owner')) {
593
+ return Mage::helper('M2ePro')->__('New ASIN/ISBN');
594
+ }
595
+
596
+ return Mage::helper('M2ePro')->__('N/A');
597
+ }
598
+
599
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($value, $row->getData('marketplace_id'));
600
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
601
+ }
602
+
603
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
604
+ {
605
+ if (!$row->getData('is_variation_parent')) {
606
+
607
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
608
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
609
+ }
610
+
611
+ if ((bool)$row->getData('is_afn_channel')) {
612
+ $sku = $row->getData('online_sku');
613
+
614
+ if (empty($sku)) {
615
+ return Mage::helper('M2ePro')->__('AFN');
616
+ }
617
+
618
+ $productId = Mage::helper('M2ePro')->generateUniqueHash();
619
+
620
+ $afn = Mage::helper('M2ePro')->__('AFN');
621
+ $total = Mage::helper('M2ePro')->__('Total');
622
+ $inStock = Mage::helper('M2ePro')->__('In Stock');
623
+ $accountId = $row->getData('account_id');
624
+
625
+ return <<<HTML
626
+ <div id="m2ePro_afn_qty_value_{$productId}">
627
+ <span class="m2ePro-online-sku-value" productId="{$productId}" style="display: none">{$sku}</span>
628
+ <span class="m2epro-empty-afn-qty-data" style="display: none">{$afn}</span>
629
+ <div class="m2epro-afn-qty-data" style="display: none">
630
+ <div class="total">{$total}: <span></span></div>
631
+ <div class="in-stock">{$inStock}: <span></span></div>
632
+ </div>
633
+ <a href="javascript:void(0)"
634
+ onclick="CommonAmazonListingAfnQtyHandlerObj.showAfnQty(this,'{$sku}','{$productId}',{$accountId})">
635
+ {$afn}
636
+ </a>
637
+ </div>
638
+ HTML;
639
+ }
640
+
641
+ if (is_null($value) || $value === '') {
642
+ return '<i style="color:gray;">receiving...</i>';
643
+ }
644
+
645
+ if ($value <= 0) {
646
+ return '<span style="color: red;">0</span>';
647
+ }
648
+
649
+ return $value;
650
+ }
651
+
652
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
653
+ $row->getData('general_id') == '') {
654
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
655
+ }
656
+
657
+ $variationChildStatuses = json_decode($row->getData('variation_child_statuses'), true);
658
+
659
+ $activeChildrenCount = 0;
660
+ foreach ($variationChildStatuses as $childStatus => $count) {
661
+ if ($childStatus == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
662
+ continue;
663
+ }
664
+ $activeChildrenCount += (int)$count;
665
+ }
666
+
667
+ if ($activeChildrenCount == 0) {
668
+ return Mage::helper('M2ePro')->__('N/A');
669
+ }
670
+
671
+ if (!(bool)$row->getData('is_afn_channel')) {
672
+ return $value;
673
+ }
674
+
675
+ if ($value == 0 && (bool)$row->getData('is_afn_channel')) {
676
+ return Mage::helper('M2ePro')->__('AFN');
677
+ }
678
+
679
+ return $value . '<br/>' . Mage::helper('M2ePro')->__('AFN');
680
+ }
681
+
682
+ public function callbackColumnPrice($value, $row, $column, $isExport)
683
+ {
684
+ if ((!$row->getData('is_variation_parent') &&
685
+ $row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
686
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
687
+
688
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
689
+ }
690
+
691
+ $repricingHtml ='';
692
+
693
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() &&
694
+ (int)$row->getData('is_repricing') === Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES) {
695
+ if ($row->getData('is_variation_parent')) {
696
+ $text = Mage::helper('M2ePro')->__(
697
+ 'Some Child Products are used by Amazon Repricing Tool.
698
+ The Price cannot be updated through the M2E Pro.'
699
+ );
700
+ } else {
701
+ $text = Mage::helper('M2ePro')->__(
702
+ 'This product is used by Amazon Repricing Tool.
703
+ The Price cannot be updated through the M2E Pro.'
704
+ );
705
+ }
706
+
707
+ $repricingHtml = <<<HTML
708
+ <span style="float:right; text-align: left;">
709
+ <img class="tool-tip-image"
710
+ style="vertical-align: middle; width: 16px;"
711
+ src="{$this->getSkinUrl('M2ePro/images/money.png')}">
712
+ <span class="tool-tip-message tool-tip-message tip-left" style="display:none;">
713
+ <img src="{$this->getSkinUrl('M2ePro/images/i_icon.png')}">
714
+ <span>{$text}</span>
715
+ </span>
716
+ </span>
717
+ HTML;
718
+ }
719
+
720
+ $onlineMinPrice = $row->getData('min_online_price');
721
+ $onlineMaxPrice = $row->getData('max_online_price');
722
+
723
+ if (is_null($onlineMinPrice) || $onlineMinPrice === '') {
724
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
725
+ $row->getData('is_variation_parent')
726
+ ) {
727
+ return Mage::helper('M2ePro')->__('N/A') . $repricingHtml;
728
+ } else {
729
+ return '<i style="color:gray;">receiving...</i>' . $repricingHtml;
730
+ }
731
+ }
732
+
733
+ $marketplaceId = $row->getData('marketplace_id');
734
+ $currency = Mage::helper('M2ePro/Component_Amazon')
735
+ ->getCachedObject('Marketplace',$marketplaceId)
736
+ ->getChildObject()
737
+ ->getDefaultCurrency();
738
+
739
+ if ($row->getData('is_variation_parent')) {
740
+ $onlineMinPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMinPrice);
741
+ $onlineMaxPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMaxPrice);
742
+
743
+ return $onlineMinPriceStr . (($onlineMinPrice != $onlineMaxPrice) ? ' - ' . $onlineMaxPriceStr : '')
744
+ . $repricingHtml;
745
+ }
746
+
747
+ $onlinePrice = $row->getData('online_price');
748
+ if ((float)$onlinePrice <= 0) {
749
+ $priceValue = '<span style="color: #f00;">0</span>';
750
+ } else {
751
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
752
+ }
753
+
754
+ $resultHtml = '';
755
+
756
+ $salePrice = $row->getData('online_sale_price');
757
+ if (!$row->getData('is_variation_parent') && (float)$salePrice > 0) {
758
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
759
+
760
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
761
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
762
+
763
+ if ($currentTimestamp <= $endDateTimestamp) {
764
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
765
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
766
+
767
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
768
+
769
+ $fromDate = Mage::app()->getLocale()->date(
770
+ $row->getData('online_sale_price_start_date'), $dateFormat
771
+ )->toString($dateFormat);
772
+ $toDate = Mage::app()->getLocale()->date(
773
+ $row->getData('online_sale_price_end_date'), $dateFormat
774
+ )->toString($dateFormat);
775
+
776
+ $intervalHtml = '<img class="tool-tip-image"
777
+ style="vertical-align: middle;"
778
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
779
+ text-align: left;
780
+ width: 110px;
781
+ background: #E3E3E3;">
782
+ <img src="'.$iconHelpPath.'">
783
+ <span style="color:gray;">
784
+ <strong>From:</strong> '.$fromDate.'<br/>
785
+ <strong>To:</strong> '.$toDate.'
786
+ </span>
787
+ </span>';
788
+
789
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
790
+
791
+ if ($currentTimestamp >= $startDateTimestamp &&
792
+ $currentTimestamp <= $endDateTimestamp &&
793
+ $salePrice < (float)$onlinePrice
794
+ ) {
795
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>' .
796
+ $repricingHtml;
797
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
798
+ } else {
799
+ $resultHtml .= $priceValue . $repricingHtml;
800
+ $resultHtml .= '<br/>'.$intervalHtml.
801
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
802
+ }
803
+ }
804
+ }
805
+
806
+ if (empty($resultHtml)) {
807
+ $resultHtml = $priceValue . $repricingHtml;
808
+ }
809
+
810
+ return $resultHtml;
811
+ }
812
+
813
+ public function callbackColumnStatus($value, $row, $column, $isExport)
814
+ {
815
+ switch ($row->getData('status')) {
816
+
817
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
818
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
819
+ $value = '<span style="color: gray;">' . $value . '</span>';
820
+ break;
821
+
822
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
823
+ $value = '<span style="color: green;">' . $value . '</span>';
824
+ break;
825
+
826
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
827
+ $value = '<span style="color: red;">'.$value.'</span>';
828
+ break;
829
+
830
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
831
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
832
+ break;
833
+
834
+ default:
835
+ break;
836
+ }
837
+
838
+ if (is_null($row->getData('listing_product_id'))) {
839
+ return $value;
840
+ }
841
+
842
+ $listingProductId = (int)$row->getData('listing_product_id');
843
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
844
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
845
+
846
+ $tempLocks = $listingProduct->getObjectLocks();
847
+
848
+ foreach ($tempLocks as $lock) {
849
+
850
+ switch ($lock->getTag()) {
851
+
852
+ case 'list_action':
853
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
854
+ break;
855
+
856
+ case 'relist_action':
857
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
858
+ break;
859
+
860
+ case 'revise_action':
861
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
862
+ break;
863
+
864
+ case 'stop_action':
865
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
866
+ break;
867
+
868
+ case 'stop_and_remove_action':
869
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
870
+ break;
871
+
872
+ case 'delete_and_remove_action':
873
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
874
+ break;
875
+
876
+ case 'switch_to_afn_action':
877
+ $value .= '<br/><span style="color: #605fff">[Switch to AFN in Progress...]</span>';
878
+ break;
879
+
880
+ case 'switch_to_mfn_action':
881
+ $value .= '<br/><span style="color: #605fff">[Switch to MFN in Progress...]</span>';
882
+ break;
883
+
884
+ default:
885
+ break;
886
+
887
+ }
888
+ }
889
+
890
+ return $value;
891
+ }
892
+
893
+ public function callbackColumnActions($value, $row, $column, $isExport)
894
+ {
895
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to Listing'));
896
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
897
+
898
+ if ($row->getData('is_m2epro_listing')) {
899
+ $url = $this->getUrl('*/adminhtml_common_amazon_listing/view/',array(
900
+ 'id' => $row->getData('listing_id'),
901
+ 'filter' => base64_encode(
902
+ 'product_id[from]='.(int)$row->getData('product_id')
903
+ .'&product_id[to]='.(int)$row->getData('product_id')
904
+ )
905
+ ));
906
+ } else {
907
+ $url = $this->getUrl('*/adminhtml_common_amazon_listing_other/view/', array(
908
+ 'account' => $row->getData('account_id'),
909
+ 'marketplace' => $row->getData('marketplace_id'),
910
+ 'filter' => base64_encode(
911
+ 'title='.$row->getData('online_sku')
912
+ )
913
+ ));
914
+ }
915
+
916
+ $html = <<<HTML
917
+ <div style="float:right; margin:5px 15px 0 0;">
918
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" alt="{$altTitle}" /></a>
919
+ </div>
920
+ HTML;
921
+
922
+ return $html;
923
+ }
924
+
925
+ //########################################
926
+
927
+ protected function callbackFilterTitle($collection, $column)
928
+ {
929
+ $value = $column->getFilter()->getValue();
930
+
931
+ if ($value == null) {
932
+ return;
933
+ }
934
+
935
+ $collection->getSelect()
936
+ ->where('product_name LIKE ? OR magento_sku LIKE ? OR listing_title LIKE ?', '%'.$value.'%');
937
+ }
938
+
939
+ protected function callbackFilterQty($collection, $column)
940
+ {
941
+ $value = $column->getFilter()->getValue();
942
+
943
+ if (empty($value)) {
944
+ return;
945
+ }
946
+
947
+ $where = '';
948
+
949
+ if (isset($value['from']) && $value['from'] != '') {
950
+ $where .= 'online_qty >= ' . $value['from'];
951
+ }
952
+
953
+ if (isset($value['to']) && $value['to'] != '') {
954
+ if (isset($value['from']) && $value['from'] != '') {
955
+ $where .= ' AND ';
956
+ }
957
+ $where .= 'online_qty <= ' . $value['to'];
958
+ }
959
+
960
+ if (!empty($value['afn'])) {
961
+ if (!empty($where)) {
962
+ $where = '(' . $where . ') OR ';
963
+ }
964
+ $where .= 'is_afn_channel = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_AFN_CHANNEL_YES;;
965
+ }
966
+
967
+ $collection->getSelect()->where($where);
968
+ }
969
+
970
+ protected function callbackFilterPrice($collection, $column)
971
+ {
972
+ $value = $column->getFilter()->getValue();
973
+
974
+ if (empty($value)) {
975
+ return;
976
+ }
977
+
978
+ $condition = '';
979
+
980
+ if (isset($value['from']) || isset($value['to'])) {
981
+
982
+ if (isset($value['from']) && $value['from'] != '') {
983
+ $condition = 'min_online_price >= \'' . $value['from'] . '\'';
984
+ }
985
+ if (isset($value['to']) && $value['to'] != '') {
986
+ if (isset($value['from']) && $value['from'] != '') {
987
+ $condition .= ' AND ';
988
+ }
989
+ $condition .= 'min_online_price <= \'' . $value['to'] . '\'';
990
+ }
991
+
992
+ $condition = '(' . $condition . ') OR (';
993
+
994
+ if (isset($value['from']) && $value['from'] != '') {
995
+ $condition .= 'max_online_price >= \'' . $value['from'] . '\'';
996
+ }
997
+ if (isset($value['to']) && $value['to'] != '') {
998
+ if (isset($value['from']) && $value['from'] != '') {
999
+ $condition .= ' AND ';
1000
+ }
1001
+ $condition .= 'max_online_price <= \'' . $value['to'] . '\'';
1002
+ }
1003
+
1004
+ $condition .= ')';
1005
+
1006
+ }
1007
+
1008
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() && !empty($value['is_repricing'])) {
1009
+ if (!empty($condition)) {
1010
+ $condition = '(' . $condition . ') OR ';
1011
+ }
1012
+ $condition .= 'is_repricing = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES;
1013
+ }
1014
+
1015
+ $collection->getSelect()->where($condition);
1016
+ }
1017
+
1018
+ //########################################
1019
+
1020
+ public function getGridUrl()
1021
+ {
1022
+ return $this->getUrl('*/adminhtml_common_amazon_listing/searchGrid', array('_current'=>true));
1023
+ }
1024
+
1025
+ public function getRowUrl($row)
1026
+ {
1027
+ return false;
1028
+ }
1029
+
1030
+ //########################################
1031
+
1032
+ protected function _toHtml() {
1033
+
1034
+ $getAFNQtyBySku = $this->getUrl('*/adminhtml_common_amazon_listing/getAFNQtyBySku');
1035
+
1036
+ $js = <<<HTML
1037
+ <script type="text/javascript">
1038
+ M2ePro.url.getAFNQtyBySku = '{$getAFNQtyBySku}';
1039
+
1040
+ CommonAmazonListingAfnQtyHandlerObj = new CommonAmazonListingAfnQtyHandler();
1041
+ </script>
1042
+ HTML;
1043
+
1044
+ return parent::_toHtml() . $js;
1045
+ }
1046
+
1047
+ //########################################
1048
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/Description/Grid.php ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Template_Description_Grid
10
+ extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+ const ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED = 1;
13
+ const ACTION_STATUS_VARIATIONS_NOT_SUPPORTED = 2;
14
+ const ACTION_STATUS_READY_TO_BE_ASSIGNED = 3;
15
+
16
+ protected $attributesSetsIds;
17
+ protected $marketplaceId;
18
+ protected $listingProduct;
19
+ protected $variationProductsIds;
20
+
21
+ protected $checkNewAsinAccepted = false;
22
+ protected $productsIds;
23
+ protected $mapToTemplateJsFn = 'ListingGridHandlerObj.templateDescriptionHandler.mapToTemplateDescription';
24
+
25
+ //########################################
26
+
27
+ /**
28
+ * @return string
29
+ */
30
+ public function getMapToTemplateJsFn()
31
+ {
32
+ return $this->mapToTemplateJsFn;
33
+ }
34
+
35
+ /**
36
+ * @param string $mapToTemplateLink
37
+ */
38
+ public function setMapToTemplateJsFn($mapToTemplateLink)
39
+ {
40
+ $this->mapToTemplateJsFn = $mapToTemplateLink;
41
+ }
42
+
43
+ // ---------------------------------------
44
+
45
+ /**
46
+ * @param boolean $checkNewAsinAccepted
47
+ */
48
+ public function setCheckNewAsinAccepted($checkNewAsinAccepted)
49
+ {
50
+ $this->checkNewAsinAccepted = $checkNewAsinAccepted;
51
+ }
52
+
53
+ /**
54
+ * @return boolean
55
+ */
56
+ public function getCheckNewAsinAccepted()
57
+ {
58
+ return (bool) $this->checkNewAsinAccepted;
59
+ }
60
+
61
+ // ---------------------------------------
62
+
63
+ /**
64
+ * @param mixed $productsIds
65
+ */
66
+ public function setProductsIds($productsIds)
67
+ {
68
+ $this->productsIds = $productsIds;
69
+ }
70
+
71
+ /**
72
+ * @return mixed
73
+ */
74
+ public function getProductsIds()
75
+ {
76
+ return $this->productsIds;
77
+ }
78
+
79
+ // ---------------------------------------
80
+
81
+ public function __construct()
82
+ {
83
+ parent::__construct();
84
+
85
+ $this->setId('amazonTemplateDescriptionGrid');
86
+
87
+ // Set default values
88
+ // ---------------------------------------
89
+ $this->setFilterVisibility(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
+ }
212
+
213
+ return '<span style="color: green;">' . Mage::helper('M2ePro')->__('Ready to be assigned') . '</span>';
214
+ }
215
+
216
+ public function callbackColumnAction($value, $row, $column, $isExport)
217
+ {
218
+ $assignText = Mage::helper('M2ePro')->__('Assign');
219
+ $mapToAsin = '';
220
+
221
+ if ($this->getCheckNewAsinAccepted()) {
222
+ $mapToAsin = ',1';
223
+ }
224
+
225
+ switch($row->getData('description_template_action_status')) {
226
+ case self::ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED:
227
+ return '<span style="color: #808080;">' . $assignText . '</span>';
228
+ break;
229
+ case self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED:
230
+ return '<span style="color: #808080;">' . $assignText . '</span>';
231
+ break;
232
+ }
233
+
234
+ return '<a href="javascript:void(0);"'
235
+ . 'onclick="' . $this->getMapToTemplateJsFn() . '(this, '
236
+ . $value . $mapToAsin .');">'.$assignText.'</a>';
237
+ }
238
+
239
+ //########################################
240
+
241
+ protected function _toHtml()
242
+ {
243
+ $productsIdsStr = implode(',', $this->getProductsIds());
244
+
245
+ $javascriptsMain = <<<HTML
246
+ <script type="text/javascript">
247
+
248
+ $$('#amazonTemplateDescriptionGrid div.grid th').each(function(el) {
249
+ el.style.padding = '5px 5px';
250
+ });
251
+
252
+ $$('#amazonTemplateDescriptionGrid div.grid td').each(function(el) {
253
+ el.style.padding = '5px 5px';
254
+ });
255
+
256
+ {$this->getJsObjectName()}.reloadParams = {$this->getJsObjectName()}.reloadParams || {};
257
+ {$this->getJsObjectName()}.reloadParams['products_ids'] = '{$productsIdsStr}';
258
+
259
+ </script>
260
+ HTML;
261
+
262
+ // ---------------------------------------
263
+ $templateDescriptionNewUrl = $this->getNewTemplateDescriptionUrl();
264
+
265
+ $data = array(
266
+ 'id' => 'templateDescription_addNew_button',
267
+ 'label' => Mage::helper('M2ePro')->__('Add New Description Policy'),
268
+ 'class' => 'templateDescription_addNew_button',
269
+ 'style' => 'float: right;',
270
+ 'onclick' => 'ListingGridHandlerObj.templateDescriptionHandler'
271
+ . '.createTemplateDescriptionInNewTab(\'' . $templateDescriptionNewUrl . '\')'
272
+ );
273
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
274
+ // ---------------------------------------
275
+
276
+ $buttonBlockHtml = ($this->canDisplayContainer()) ? $buttonBlock->toHtml(): '';
277
+
278
+ return parent::_toHtml() . $buttonBlockHtml . $javascriptsMain;
279
+ }
280
+
281
+ //########################################
282
+
283
+ public function getGridUrl()
284
+ {
285
+ return $this->getUrl('*/*/viewTemplateDescriptionsGrid', array(
286
+ '_current' => true,
287
+ '_query' => array(
288
+ 'check_is_new_asin_accepted' => $this->getCheckNewAsinAccepted()
289
+ )
290
+ ));
291
+ }
292
+
293
+ public function getRowUrl($row)
294
+ {
295
+ return false;
296
+ }
297
+
298
+ //########################################
299
+
300
+ protected function getMarketplaceId()
301
+ {
302
+ if (empty($this->marketplaceId)) {
303
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
304
+ $productsIds = $this->getProductsIds();
305
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $productsIds[0]);
306
+ $this->marketplaceId = $listingProduct->getListing()->getMarketplaceId();
307
+ }
308
+
309
+ return $this->marketplaceId;
310
+ }
311
+
312
+ // ---------------------------------------
313
+
314
+ protected function setNoTemplatesText()
315
+ {
316
+ $templateDescriptionEditUrl = $this->getNewTemplateDescriptionUrl();
317
+
318
+ $messageTxt = Mage::helper('M2ePro')->__('Description Policies are not found for current Marketplace.');
319
+ $linkTitle = Mage::helper('M2ePro')->__('Create New Description Policy.');
320
+
321
+ $message = <<<HTML
322
+ <p>{$messageTxt} <a href="javascript:void(0);"
323
+ id="templateDescription_addNew_link"
324
+ onclick="ListingGridHandlerObj.templateDescriptionHandler.createTemplateDescriptionInNewTab(
325
+ '{$templateDescriptionEditUrl}');">{$linkTitle}</a>
326
+ </p>
327
+ HTML;
328
+
329
+ $this->setEmptyText($message);
330
+ }
331
+
332
+ protected function getNewTemplateDescriptionUrl()
333
+ {
334
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/new', array(
335
+ 'is_new_asin_accepted' => $this->getCheckNewAsinAccepted(),
336
+ 'marketplace_id' => $this->getMarketplaceId()
337
+ ));
338
+ }
339
+
340
+ // ---------------------------------------
341
+
342
+ protected function getParentListingProduct()
343
+ {
344
+ $productIds = $this->getProductsIds();
345
+ if (count($productIds) == 1 && empty($this->listingProduct)) {
346
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product', $productIds[0]);
347
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
348
+ $this->listingProduct = $listingProduct;
349
+ }
350
+ }
351
+ return $this->listingProduct;
352
+ }
353
+
354
+ // ---------------------------------------
355
+
356
+ protected function getVariationsProductsIds()
357
+ {
358
+ if (is_null($this->variationProductsIds)) {
359
+ $this->variationProductsIds = array();
360
+
361
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Listing_Product_Collection $collection */
362
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
363
+ $collection->addFieldToFilter('additional_data', array('notnull' => true));
364
+ $collection->addFieldToFilter('id', array('in' => $this->getProductsIds()));
365
+ $collection->addFieldToFilter('is_variation_parent', 1);
366
+
367
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
368
+ $collection->getSelect()->columns(
369
+ array(
370
+ 'main_table.id'
371
+ )
372
+ );
373
+
374
+ $this->variationProductsIds = $collection->getData();
375
+ }
376
+
377
+ return $this->variationProductsIds;
378
+ }
379
+
380
+ //########################################
381
+
382
+ private function prepareCollection($collection)
383
+ {
384
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Template_Description_Collection $preparedCollection */
385
+ $preparedCollection = new Varien_Data_Collection();
386
+
387
+ $data = $collection->getData();
388
+ $preparedData = array();
389
+ foreach ($data as $item) {
390
+ if (!$this->getCheckNewAsinAccepted()) {
391
+ $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED;
392
+ $preparedData[] = $item;
393
+ continue;
394
+ }
395
+
396
+ if (!$item['is_new_asin_accepted']) {
397
+ $item['description_template_action_status'] = self::ACTION_STATUS_NEW_ASIN_NOT_ACCEPTED;
398
+ $preparedData[] = $item;
399
+ continue;
400
+ }
401
+
402
+ $variationProductsIds = $this->getVariationsProductsIds();
403
+
404
+ if (!empty($variationProductsIds)) {
405
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
406
+ $detailsModel->setMarketplaceId($this->getMarketplaceId());
407
+ $themes = $detailsModel->getVariationThemes($item['product_data_nick']);
408
+
409
+ if (empty($themes)) {
410
+ $item['description_template_action_status'] = self::ACTION_STATUS_VARIATIONS_NOT_SUPPORTED;
411
+ $preparedData[] = $item;
412
+ continue;
413
+ }
414
+ }
415
+
416
+ $item['description_template_action_status'] = self::ACTION_STATUS_READY_TO_BE_ASSIGNED;
417
+ $preparedData[] = $item;
418
+ continue;
419
+ }
420
+
421
+ if (!empty($preparedData)) {
422
+ usort($preparedData, function($a, $b)
423
+ {
424
+ return $a["description_template_action_status"] < $b["description_template_action_status"];
425
+ });
426
+
427
+ foreach ($preparedData as $item) {
428
+ $preparedCollection->addItem(new Varien_Object($item));
429
+ }
430
+ }
431
+
432
+ return $preparedCollection;
433
+ }
434
+
435
+ //########################################
436
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/Description/Main.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Template_Description_Main
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ protected $newAsin = false;
13
+ protected $messages = array();
14
+
15
+ //########################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+ $this->setTemplate('M2ePro/common/amazon/listing/template_description/main.phtml');
21
+ }
22
+
23
+ //########################################
24
+
25
+ /**
26
+ * @param array $messages
27
+ */
28
+ public function setMessages($messages)
29
+ {
30
+ $this->messages = $messages;
31
+ }
32
+
33
+ /**
34
+ * @return array
35
+ */
36
+ public function getMessages()
37
+ {
38
+ return $this->messages;
39
+ }
40
+
41
+ //########################################
42
+
43
+ /**
44
+ * @return boolean
45
+ */
46
+ public function isNewAsin()
47
+ {
48
+ return $this->newAsin;
49
+ }
50
+
51
+ /**
52
+ * @param boolean $newAsin
53
+ */
54
+ public function setNewAsin($newAsin)
55
+ {
56
+ $this->newAsin = $newAsin;
57
+ }
58
+
59
+ //########################################
60
+
61
+ public function getWarnings()
62
+ {
63
+ $warnings = '';
64
+ foreach ($this->getMessages() as $message) {
65
+ $warnings .= <<<HTML
66
+ <ul class="messages">
67
+ <li class="{$message['type']}-msg">
68
+ <ul>
69
+ <li>{$message['text']}</li>
70
+ </ul>
71
+ </li>
72
+ </ul>
73
+ HTML;
74
+ }
75
+ return $warnings;
76
+ }
77
+
78
+ //########################################
79
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/ShippingOverride.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Template_ShippingOverride
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ protected $messages = array();
13
+
14
+ //########################################
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+ $this->setTemplate('M2ePro/common/amazon/listing/template/shipping_override/main.phtml');
20
+ }
21
+
22
+ //########################################
23
+
24
+ /**
25
+ * @param array $messages
26
+ */
27
+ public function setMessages($messages)
28
+ {
29
+ $this->messages = $messages;
30
+ }
31
+
32
+ /**
33
+ * @return array
34
+ */
35
+ public function getMessages()
36
+ {
37
+ return $this->messages;
38
+ }
39
+
40
+ //########################################
41
+
42
+ public function getWarnings()
43
+ {
44
+ $warnings = '';
45
+ foreach ($this->getMessages() as $message) {
46
+ $warnings .= <<<HTML
47
+ <ul class="messages">
48
+ <li class="{$message['type']}-msg">
49
+ <ul>
50
+ <li>{$message['text']}</li>
51
+ </ul>
52
+ </li>
53
+ </ul>
54
+ HTML;
55
+ }
56
+ return $warnings;
57
+ }
58
+
59
+ //########################################
60
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Template/ShippingOverride/Grid.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Template_ShippingOverride_Grid
10
+ extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+ protected $marketplaceId;
13
+
14
+ //########################################
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ $this->setId('amazonTemplateShippingOverrideGrid');
21
+
22
+ // Set default values
23
+ // ---------------------------------------
24
+ $this->setFilterVisibility(false);
25
+ $this->setDefaultSort('id');
26
+ $this->setDefaultDir('ASC');
27
+ $this->setSaveParametersInSession(false);
28
+ $this->setUseAjax(true);
29
+ // ---------------------------------------
30
+ }
31
+
32
+ // ---------------------------------------
33
+
34
+ /**
35
+ * @return mixed
36
+ */
37
+ public function getMarketplaceId()
38
+ {
39
+ return $this->marketplaceId;
40
+ }
41
+
42
+ /**
43
+ * @param mixed $marketplaceId
44
+ */
45
+ public function setMarketplaceId($marketplaceId)
46
+ {
47
+ $this->marketplaceId = $marketplaceId;
48
+ }
49
+
50
+ // ---------------------------------------
51
+
52
+ protected function _prepareCollection()
53
+ {
54
+ $this->setNoTemplatesText();
55
+
56
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Template_Description_Collection $collection */
57
+ $collection = Mage::getModel('M2ePro/Amazon_Template_ShippingOverride')->getCollection();
58
+ $collection->addFieldToFilter('marketplace_id', $this->getMarketplaceId());
59
+
60
+ $this->setCollection($collection);
61
+
62
+ return parent::_prepareCollection();
63
+ }
64
+
65
+ protected function _prepareColumns()
66
+ {
67
+ $this->addColumn('title', array(
68
+ 'header' => Mage::helper('M2ePro')->__('Title'),
69
+ 'align' => 'left',
70
+ 'type' => 'text',
71
+ 'index' => 'title',
72
+ 'filter' => false,
73
+ 'sortable' => false,
74
+ 'frame_callback' => array($this, 'callbackColumnTitle')
75
+ ));
76
+
77
+ $this->addColumn('action', array(
78
+ 'header' => Mage::helper('M2ePro')->__('Action'),
79
+ 'align' => 'left',
80
+ 'type' => 'number',
81
+ 'width' => '55px',
82
+ 'index' => 'id',
83
+ 'filter' => false,
84
+ 'sortable' => false,
85
+ 'frame_callback' => array($this, 'callbackColumnAction')
86
+ ));
87
+ }
88
+
89
+ protected function _prepareLayout()
90
+ {
91
+ $this->setChild('refresh_button',
92
+ $this->getLayout()->createBlock('adminhtml/widget_button')
93
+ ->setData(array(
94
+ 'id' => 'shipping_override_template_refresh_btn',
95
+ 'label' => Mage::helper('M2ePro')->__('Refresh'),
96
+ 'onclick' => $this->getJsObjectName().'.reload()'
97
+ ))
98
+ );
99
+
100
+ return parent::_prepareLayout();
101
+ }
102
+
103
+ //########################################
104
+
105
+ public function getRefreshButtonHtml()
106
+ {
107
+ return $this->getChildHtml('refresh_button');
108
+ }
109
+
110
+ //########################################
111
+
112
+ public function getMainButtonsHtml()
113
+ {
114
+ return $this->getRefreshButtonHtml() . parent::getMainButtonsHtml();
115
+ }
116
+
117
+ //########################################
118
+
119
+ public function callbackColumnTitle($value, $row, $column, $isExport)
120
+ {
121
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_shippingOverride/edit', array(
122
+ 'id' => $row->getData('id')
123
+ ));
124
+
125
+ $title = Mage::helper('M2ePro')->escapeHtml($value);
126
+
127
+ return <<<HTML
128
+ <a target="_blank" href="{$templateDescriptionEditUrl}">{$title}</a>
129
+ HTML;
130
+
131
+ }
132
+
133
+ public function callbackColumnAction($value, $row, $column, $isExport)
134
+ {
135
+ $assignText = Mage::helper('M2ePro')->__('Assign');
136
+
137
+ return <<<HTML
138
+ <a href="javascript:void(0)"
139
+ class="assign-shipping-override-template"
140
+ templateShippingOverrideId="{$value}">
141
+ {$assignText}
142
+ </a>
143
+ HTML;
144
+
145
+ }
146
+
147
+ //########################################
148
+
149
+ protected function _toHtml()
150
+ {
151
+ $javascriptsMain = <<<HTML
152
+ <script type="text/javascript">
153
+
154
+ $$('#amazonTemplateShippingOverrideGrid div.grid th').each(function(el) {
155
+ el.style.padding = '5px 5px';
156
+ });
157
+
158
+ $$('#amazonTemplateShippingOverrideGrid div.grid td').each(function(el) {
159
+ el.style.padding = '5px 5px';
160
+ });
161
+
162
+ ListingGridHandlerObj.templateShippingOverrideHandler.newTemplateUrl='{$this->getNewTemplateShippingOverrideUrl()}';
163
+
164
+ </script>
165
+ HTML;
166
+
167
+ // ---------------------------------------
168
+ $data = array(
169
+ 'label' => Mage::helper('M2ePro')->__('Add New Shipping Override Policy'),
170
+ 'class' => 'new-shipping-override-template',
171
+ 'style' => 'float: right;'
172
+ );
173
+
174
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
175
+ // ---------------------------------------
176
+
177
+ $buttonBlockHtml = ($this->canDisplayContainer()) ? $buttonBlock->toHtml(): '';
178
+
179
+ return parent::_toHtml() . $buttonBlockHtml . $javascriptsMain;
180
+ }
181
+
182
+ //########################################
183
+
184
+ public function getGridUrl()
185
+ {
186
+ return $this->getUrl('*/*/viewTemplateShippingOverrideGrid', array(
187
+ '_current' => true,
188
+ '_query' => array(
189
+ 'marketplace_id' => $this->getMarketplaceId()
190
+ )
191
+ ));
192
+ }
193
+
194
+ public function getRowUrl($row)
195
+ {
196
+ return false;
197
+ }
198
+
199
+ //########################################
200
+
201
+ protected function setNoTemplatesText()
202
+ {
203
+ $messageTxt = Mage::helper('M2ePro')->__('Shipping Override Policies are not found for current Marketplace.');
204
+ $linkTitle = Mage::helper('M2ePro')->__('Create New Shipping Override Policy.');
205
+
206
+ $message = <<<HTML
207
+ <p>{$messageTxt} <a href="javascript:void(0);"
208
+ class="new-shipping-override-template">{$linkTitle}</a>
209
+ </p>
210
+ HTML;
211
+
212
+ $this->setEmptyText($message);
213
+ }
214
+
215
+ protected function getNewTemplateShippingOverrideUrl()
216
+ {
217
+ return $this->getUrl('*/adminhtml_common_amazon_template_shippingOverride/new', array(
218
+ 'marketplace_id' => $this->getMarketplaceId()
219
+ ));
220
+ }
221
+
222
+ //########################################
223
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs
10
+ extends Mage_Adminhtml_Block_Widget_Tabs
11
+ {
12
+ protected $listingProductId;
13
+
14
+ //########################################
15
+
16
+ /**
17
+ * @param mixed $listingProductId
18
+ */
19
+ public function setListingProductId($listingProductId)
20
+ {
21
+ $this->listingProductId = $listingProductId;
22
+ }
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;
36
+
37
+ /**
38
+ * @return Ess_M2ePro_Model_Listing_Product|null
39
+ */
40
+ public function getListingProduct()
41
+ {
42
+ if (empty($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
+ // ---------------------------------------
51
+
52
+ public function __construct()
53
+ {
54
+ parent::__construct();
55
+
56
+ // Initialization block
57
+ // ---------------------------------------
58
+ $this->setId('amazonVariationProductManageTabs');
59
+ // ---------------------------------------
60
+
61
+ $this->setTemplate('widget/tabshoriz.phtml');
62
+ $this->setDestElementId('variation_product_manage_tabs_container');
63
+ }
64
+
65
+ // ---------------------------------------
66
+
67
+ protected function _beforeToHtml()
68
+ {
69
+ $this->addTab('variations', array(
70
+ 'label' => Mage::helper('M2ePro')->__('Child Products'),
71
+ 'title' => Mage::helper('M2ePro')->__('Child Products'),
72
+ 'content' => $this->getLayout()
73
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_variations')
74
+ ->setListingProductId($this->getListingProductId())
75
+ ->toHtml()
76
+ ));
77
+
78
+ $settingsBlock = $this->getLayout()
79
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_settings')
80
+ ->setListingProductId($this->getListingProductId());
81
+ $settingsBlock->calculateWarnings();
82
+
83
+ $settingsBlockLabel = Mage::helper('M2ePro')->__('Settings');
84
+ $settingsBlockTitle = Mage::helper('M2ePro')->__('Settings');
85
+
86
+ $iconPath = $this->getSkinUrl('M2ePro/images/'. $settingsBlock->getMessagesType() .'.png');
87
+ $iconTitle = Mage::helper('M2ePro')->__('Action required.');
88
+ $iconStyle = 'vertical-align: middle;';
89
+
90
+ if (count($settingsBlock->getMessages()) == 0) {
91
+ $iconStyle .= 'display:none;';
92
+ }
93
+
94
+ $problemIcon = <<<HTML
95
+ <img style="{$iconStyle}" src="{$iconPath}" title="{$iconTitle}" alt="" width="16" height="15">&nbsp;
96
+ HTML;
97
+
98
+ $this->addTab('settings', array(
99
+ 'label' => $problemIcon . $settingsBlockLabel,
100
+ 'title' => $settingsBlockTitle,
101
+ 'content' => $this->getLayout()
102
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_settings')
103
+ ->setListingProductId($this->getListingProductId())
104
+ ->toHtml()
105
+ ));
106
+
107
+ $this->addTab('vocabulary', array(
108
+ 'label' => Mage::helper('M2ePro')->__('Advanced'),
109
+ 'title' => Mage::helper('M2ePro')->__('Advanced'),
110
+ 'content' => $this->getLayout()
111
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_variation_product_manage_tabs_vocabulary')
112
+ ->setListingProductId($this->getListingProductId())
113
+ ->toHtml()
114
+ ));
115
+
116
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
117
+ if (empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner()) {
118
+ $this->setActiveTab('settings');
119
+ } else {
120
+ $this->setActiveTab('variations');
121
+ }
122
+
123
+ return parent::_beforeToHtml();
124
+ }
125
+
126
+ protected function _toHtml()
127
+ {
128
+ $generalId = $this->getListingProduct()->getChildObject()->getGeneralId();
129
+
130
+ $showMask = 0;
131
+ if (!(empty($generalId) && $this->getListingProduct()->getChildObject()->isGeneralIdOwner())) {
132
+ $showMask = 1;
133
+ }
134
+
135
+ $data = array(
136
+ 'style' => 'float: right; margin-top: 7px; ',
137
+ 'label' => Mage::helper('M2ePro')->__('Close'),
138
+ 'onclick' => 'ListingGridHandlerObj.variationProductManageHandler.closeManageVariationsPopup()'
139
+ );
140
+ $closeBtn = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
141
+
142
+ $additionalJavascript = <<<HTML
143
+ <script type="text/javascript">
144
+ amazonVariationProductManageTabsJsTabs.moveTabContentInDest();
145
+
146
+ if (!{$showMask}) {
147
+ amazonVariationProductManageTabsJsTabs.tabs[0].hide();
148
+ }
149
+
150
+ ListingGridHandlerObj.variationProductManageHandler.loadVariationsGrid({$showMask});
151
+ </script>
152
+ HTML;
153
+
154
+ return parent::_toHtml() .
155
+ '<div id="variation_product_manage_tabs_container"></div>' .
156
+ $additionalJavascript .
157
+ $closeBtn->toHtml();
158
+ }
159
+
160
+ //########################################
161
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Settings.php ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Settings
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ const MESSAGE_TYPE_ERROR = 'error';
13
+ const MESSAGE_TYPE_WARNING = 'warning';
14
+
15
+ protected $warningsCalculated = false;
16
+
17
+ protected $channelThemes = null;
18
+ protected $childListingProducts = null;
19
+ protected $currentProductVariations = null;
20
+
21
+ // ---------------------------------------
22
+
23
+ protected $listingProductId;
24
+
25
+ //########################################
26
+
27
+ public function __construct()
28
+ {
29
+ parent::__construct();
30
+
31
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/settings.phtml');
32
+ }
33
+
34
+ //########################################
35
+
36
+ /**
37
+ * @param mixed $listingProductId
38
+ * @return $this
39
+ */
40
+ public function setListingProductId($listingProductId)
41
+ {
42
+ $this->listingProductId = $listingProductId;
43
+
44
+ return $this;
45
+ }
46
+ /**
47
+ * @return mixed
48
+ */
49
+ public function getListingProductId()
50
+ {
51
+ return $this->listingProductId;
52
+ }
53
+
54
+ // ---------------------------------------
55
+
56
+ protected $messages = array();
57
+ /**
58
+ * @param array $message
59
+ */
60
+ public function addMessage($message, $type = self::MESSAGE_TYPE_ERROR)
61
+ {
62
+ $this->messages[] = array(
63
+ 'type' => $type,
64
+ 'msg' => $message
65
+ );
66
+ }
67
+ /**
68
+ * @param array $messages
69
+ */
70
+ public function setMessages($messages)
71
+ {
72
+ $this->messages = $messages;
73
+ }
74
+ /**
75
+ * @return array
76
+ */
77
+ public function getMessages()
78
+ {
79
+ return $this->messages;
80
+ }
81
+
82
+ public function getMessagesType()
83
+ {
84
+ $type = self::MESSAGE_TYPE_WARNING;
85
+ foreach ($this->messages as $message) {
86
+ if ($message['type'] === self::MESSAGE_TYPE_ERROR) {
87
+ $type = $message['type'];
88
+ break;
89
+ }
90
+ }
91
+
92
+ return $type;
93
+ }
94
+
95
+ // ---------------------------------------
96
+
97
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
98
+ protected $listingProduct;
99
+
100
+ /**
101
+ * @return Ess_M2ePro_Model_Listing_Product|null
102
+ */
103
+ public function getListingProduct()
104
+ {
105
+ if (is_null($this->listingProduct)) {
106
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
107
+ ->getObject('Listing_Product', $this->getListingProductId());
108
+ }
109
+
110
+ return $this->listingProduct;
111
+ }
112
+
113
+ // ---------------------------------------
114
+
115
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
116
+ protected $listingProductTypeModel;
117
+
118
+ /**
119
+ * @return Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent|null
120
+ */
121
+ public function getListingProductTypeModel()
122
+ {
123
+ if (is_null($this->listingProductTypeModel)) {
124
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
125
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
126
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $typeModel */
127
+ $this->listingProductTypeModel = $amazonListingProduct->getVariationManager()->getTypeModel();
128
+ }
129
+
130
+ return $this->listingProductTypeModel;
131
+ }
132
+
133
+ // ---------------------------------------
134
+
135
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute $matcherAttribute */
136
+ protected $matcherAttributes;
137
+
138
+ /**
139
+ * @return Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Matcher_Attribute
140
+ */
141
+ public function getMatcherAttributes()
142
+ {
143
+ if (empty($this->matcherAttributes)) {
144
+ $this->matcherAttributes = Mage::getModel('M2ePro/Amazon_Listing_Product_Variation_Matcher_Attribute');
145
+ $this->matcherAttributes->setMagentoProduct($this->getListingProduct()->getMagentoProduct());
146
+ $this->matcherAttributes->setDestinationAttributes($this->getDestinationAttributes());
147
+ }
148
+
149
+ return $this->matcherAttributes;
150
+ }
151
+
152
+ // ---------------------------------------
153
+
154
+ public function getWarnings()
155
+ {
156
+ $warnings = '';
157
+ foreach ($this->getMessages() as $message) {
158
+ $warnings .= <<<HTML
159
+ <li class="{$message['type']}-msg">
160
+ <ul>
161
+ <li>{$message['msg']}</li>
162
+ </ul>
163
+ </li>
164
+ HTML;
165
+ }
166
+ return $warnings;
167
+ }
168
+
169
+ public function calculateWarnings()
170
+ {
171
+ if (!$this->warningsCalculated) {
172
+
173
+ $this->warningsCalculated = true;
174
+
175
+ if (!$this->hasGeneralId() && $this->isGeneralIdOwner()) {
176
+ if (!$this->hasChannelTheme() || !$this->hasMatchedAttributes()) {
177
+ $this->addMessage(
178
+ Mage::helper('M2ePro')
179
+ ->__('Creation of New Parent-Child Product is impossible because Variation Theme
180
+ or correspondence between Magento Product Attributes and Amazon Product Attributes
181
+ was not set. Please, specify a Variation Theme or correspondence between
182
+ Variation Attributes.'),
183
+ self::MESSAGE_TYPE_ERROR
184
+ );
185
+ }
186
+ } elseif ($this->hasGeneralId()) {
187
+ if (!$this->hasMatchedAttributes()) {
188
+ $this->addMessage(
189
+ Mage::helper('M2ePro')->__(
190
+ 'Selling of existing Child Products on Amazon is impossible because correspondence
191
+ between Magento Product Attributes and Amazon Product Attributes was not set.
192
+ Please, specify correspondence between Variation Attributes.'
193
+ ),
194
+ self::MESSAGE_TYPE_ERROR
195
+ );
196
+ }
197
+ if ($this->isGeneralIdOwner() && !$this->hasChannelTheme()) {
198
+ $this->addMessage(
199
+ Mage::helper('M2ePro')->__(
200
+ 'Creation of New Amazon Child Products feature is temporary unavailable because
201
+ Variation Theme was not set. Please, specify Variation Theme.'
202
+ ),
203
+ self::MESSAGE_TYPE_WARNING
204
+ );
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ // ---------------------------------------
211
+
212
+ protected function _beforeToHtml()
213
+ {
214
+ $this->calculateWarnings();
215
+
216
+ return parent::_beforeToHtml();
217
+ }
218
+
219
+ protected function _toHtml()
220
+ {
221
+ $vocabularyAttributesBlock = $this->getLayout()->createBlock(
222
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyAttributesPopup'
223
+ );
224
+
225
+ $vocabularyOptionsBlock = $this->getLayout()->createBlock(
226
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_vocabularyOptionsPopup'
227
+ );
228
+
229
+ return $vocabularyAttributesBlock->toHtml() . $vocabularyOptionsBlock->toHtml() . parent::_toHtml();
230
+ }
231
+
232
+ //########################################
233
+
234
+ public function isInAction()
235
+ {
236
+ $lockedObjects = $this->getListingProduct()->getObjectLocks();
237
+ return !empty($lockedObjects);
238
+ }
239
+
240
+ // ---------------------------------------
241
+
242
+ public function getProductAttributes()
243
+ {
244
+ return $this->getListingProductTypeModel()->getProductAttributes();
245
+ }
246
+
247
+ // ---------------------------------------
248
+
249
+ public function showGeneralIdActions()
250
+ {
251
+ return !$this->getListingProduct()->getMagentoProduct()->isBundleType() &&
252
+ !$this->getListingProduct()->getMagentoProduct()->isSimpleTypeWithCustomOptions();
253
+ }
254
+
255
+ // ---------------------------------------
256
+
257
+ public function hasGeneralId()
258
+ {
259
+ return $this->getListingProduct()->getChildObject()->getGeneralId() !== NULL;
260
+ }
261
+
262
+ public function getGeneralId()
263
+ {
264
+ return $this->getListingProduct()->getChildObject()->getGeneralId();
265
+ }
266
+
267
+ public function getGeneralIdLink()
268
+ {
269
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
270
+ $this->getGeneralId(),
271
+ $this->getListingProduct()->getListing()->getMarketplaceId()
272
+ );
273
+
274
+ return <<<HTML
275
+ <a href="{$url}" target="_blank" title="{$this->getGeneralId()}" >{$this->getGeneralId()}</a>
276
+ HTML;
277
+ }
278
+
279
+ public function isGeneralIdOwner()
280
+ {
281
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
282
+ }
283
+
284
+ // ---------------------------------------
285
+
286
+ public function getDescriptionTemplateLink()
287
+ {
288
+ $url = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
289
+ 'id' => $this->getListingProduct()->getChildObject()->getTemplateDescriptionId()
290
+ ));
291
+
292
+ $templateTitle = $this->getListingProduct()->getChildObject()->getDescriptionTemplate()->getTitle();
293
+
294
+ return <<<HTML
295
+ <a href="{$url}" target="_blank" title="{$templateTitle}" >{$templateTitle}</a>
296
+ HTML;
297
+ }
298
+
299
+ // ---------------------------------------
300
+
301
+ public function hasChannelTheme()
302
+ {
303
+ return $this->getListingProductTypeModel()->hasChannelTheme();
304
+ }
305
+
306
+ public function getChannelTheme()
307
+ {
308
+ return $this->getListingProductTypeModel()->getChannelTheme();
309
+ }
310
+
311
+ public function getChannelThemes()
312
+ {
313
+ if (!is_null($this->channelThemes)) {
314
+ return $this->channelThemes;
315
+ }
316
+
317
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
318
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
319
+ $descriptionTemplate = $amazonListingProduct->getAmazonDescriptionTemplate();
320
+
321
+ if (!$descriptionTemplate) {
322
+ return array();
323
+ }
324
+
325
+ $marketPlaceId = $this->getListingProduct()->getListing()->getMarketplaceId();
326
+
327
+ $detailsModel = Mage::getModel('M2ePro/Amazon_Marketplace_Details');
328
+ $detailsModel->setMarketplaceId($marketPlaceId);
329
+
330
+ $channelThemes = $detailsModel->getVariationThemes($descriptionTemplate->getProductDataNick());
331
+
332
+ $variationHelper = Mage::helper('M2ePro/Component_Amazon_Variation');
333
+ $themesUsageData = $variationHelper->getThemesUsageData();
334
+ $usedThemes = array();
335
+
336
+ if (!empty($themesUsageData[$marketPlaceId])) {
337
+ foreach ($themesUsageData[$marketPlaceId] as $theme => $count) {
338
+ if (!empty($channelThemes[$theme])) {
339
+ $usedThemes[$theme] = $channelThemes[$theme];
340
+ }
341
+ }
342
+ }
343
+
344
+ return $this->channelThemes = array_merge($usedThemes, $channelThemes);
345
+ }
346
+
347
+ public function getChannelThemeAttr()
348
+ {
349
+ $theme = $this->getChannelTheme();
350
+ $themes = $this->getChannelThemes();
351
+
352
+ if (!empty($themes[$theme])) {
353
+ return $themes[$theme]['attributes'];
354
+ }
355
+
356
+ return null;
357
+ }
358
+
359
+ public function getChannelThemeNote()
360
+ {
361
+ $theme = $this->getChannelTheme();
362
+ $themes = $this->getChannelThemes();
363
+
364
+ if (!empty($themes[$theme])) {
365
+ return $themes[$theme]['note'];
366
+ }
367
+
368
+ return null;
369
+ }
370
+
371
+ public function getChannelThemeAttrString()
372
+ {
373
+ $themesAttributes = $this->getChannelThemeAttr();
374
+
375
+ if (!empty($themesAttributes)) {
376
+ return implode(', ', $themesAttributes);
377
+ }
378
+
379
+ return Mage::helper('M2ePro')->__('Variation Theme not found.');
380
+ }
381
+
382
+ // ---------------------------------------
383
+
384
+ public function hasMatchedAttributes()
385
+ {
386
+ return $this->getListingProductTypeModel()->hasMatchedAttributes();
387
+ }
388
+
389
+ public function getMatchedAttributes()
390
+ {
391
+ if ($this->hasMatchedAttributes()) {
392
+ return $this->getListingProductTypeModel()->getMatchedAttributes();
393
+ }
394
+ return $this->getMatcherAttributes()->getMatchedAttributes();
395
+ }
396
+
397
+ public function getDestinationAttributes()
398
+ {
399
+ if (!$this->hasGeneralId() && $this->isGeneralIdOwner() && $this->hasChannelTheme()) {
400
+ return $this->getChannelThemeAttr();
401
+ }
402
+ return array_keys($this->getListingProductTypeModel()->getChannelAttributesSets());
403
+ }
404
+
405
+ // ---------------------------------------
406
+
407
+ public function getVirtualAttributes()
408
+ {
409
+ $typeModel = $this->getListingProductTypeModel();
410
+
411
+ if ($virtualProductAttributes = $typeModel->getVirtualProductAttributes()) {
412
+ return $virtualProductAttributes;
413
+ }
414
+
415
+ if ($virtualChannelAttributes = $typeModel->getVirtualChannelAttributes()) {
416
+ return $virtualChannelAttributes;
417
+ }
418
+
419
+ return array();
420
+ }
421
+
422
+ public function getVirtualProductAttributes()
423
+ {
424
+ $typeModel = $this->getListingProductTypeModel();
425
+
426
+ if ($virtualProductAttributes = $typeModel->getVirtualProductAttributes()) {
427
+ return $virtualProductAttributes;
428
+ }
429
+
430
+ return array();
431
+ }
432
+
433
+ public function getVirtualChannelAttributes()
434
+ {
435
+ $typeModel = $this->getListingProductTypeModel();
436
+
437
+ if ($virtualChannelAttributes = $typeModel->getVirtualChannelAttributes()) {
438
+ return $virtualChannelAttributes;
439
+ }
440
+
441
+ return array();
442
+ }
443
+
444
+ // ---------------------------------------
445
+
446
+ public function isChangeMatchedAttributesAllowed()
447
+ {
448
+ if ($this->isInAction() ) {
449
+ return false;
450
+ }
451
+ if ($this->hasMatchedAttributes()) {
452
+ $typeModel = $this->getListingProductTypeModel();
453
+
454
+ $realMatchedAttributes = $typeModel->getRealMatchedAttributes();
455
+
456
+ if (count($realMatchedAttributes) === 1) {
457
+ return false;
458
+ }
459
+ }
460
+
461
+ return true;
462
+ }
463
+
464
+ //########################################
465
+
466
+ public function getChildListingProducts()
467
+ {
468
+ if (!is_null($this->childListingProducts)) {
469
+ return $this->childListingProducts;
470
+ }
471
+
472
+ return $this->childListingProducts = $this->getListingProductTypeModel()->getChildListingsProducts();
473
+ }
474
+
475
+ public function getCurrentProductVariations()
476
+ {
477
+ if (!is_null($this->currentProductVariations)) {
478
+ return $this->currentProductVariations;
479
+ }
480
+
481
+ $magentoProductVariations = $this->getListingProduct()
482
+ ->getMagentoProduct()
483
+ ->getVariationInstance()
484
+ ->getVariationsTypeStandard();
485
+
486
+ $productVariations = array();
487
+
488
+ foreach ($magentoProductVariations['variations'] as $option) {
489
+ $productOption = array();
490
+
491
+ foreach ($option as $attribute) {
492
+ $productOption[$attribute['attribute']] = $attribute['option'];
493
+ }
494
+
495
+ $productVariations[] = $productOption;
496
+ }
497
+
498
+ return $this->currentProductVariations = $productVariations;
499
+ }
500
+
501
+ public function getCurrentChannelVariations()
502
+ {
503
+ return $this->getListingProductTypeModel()->getChannelVariations();
504
+ }
505
+
506
+ // ---------------------------------------
507
+
508
+ public function getAmazonVariationsSet()
509
+ {
510
+ $variations = $this->getCurrentChannelVariations();
511
+
512
+ if (is_null($variations)) {
513
+ return false;
514
+ }
515
+
516
+ $attributesOptions = array();
517
+
518
+ foreach ($variations as $variation) {
519
+ foreach ($variation as $attr => $option) {
520
+ if (!isset($attributesOptions[$attr])) {
521
+ $attributesOptions[$attr] = array();
522
+ }
523
+ if (!in_array($option, $attributesOptions[$attr])) {
524
+ $attributesOptions[$attr][] = $option;
525
+ }
526
+ }
527
+ }
528
+
529
+ ksort($attributesOptions);
530
+
531
+ return $attributesOptions;
532
+ }
533
+
534
+ // ---------------------------------------
535
+
536
+ public function getUsedChannelVariations()
537
+ {
538
+ $usedOptions = array();
539
+
540
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
541
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
542
+
543
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
544
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
545
+
546
+ if (!$childTypeModel->isVariationChannelMatched()) {
547
+ continue;
548
+ }
549
+
550
+ $usedOptions[] = $childTypeModel->getChannelOptions();
551
+ }
552
+
553
+ return $usedOptions;
554
+ }
555
+
556
+ public function getUsedProductVariations()
557
+ {
558
+ $usedOptions = array();
559
+
560
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
561
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
562
+
563
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
564
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
565
+
566
+ if (!$childTypeModel->isVariationProductMatched()) {
567
+ continue;
568
+ }
569
+
570
+ $usedOptions[] = $childTypeModel->getProductOptions();
571
+ }
572
+
573
+ return $usedOptions;
574
+ }
575
+
576
+ // ---------------------------------------
577
+
578
+ public function getUnusedProductVariations()
579
+ {
580
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
581
+ }
582
+
583
+ public function getUnusedChannelVariations()
584
+ {
585
+ return $this->getUnusedVariations($this->getCurrentChannelVariations(), $this->getUsedChannelVariations());
586
+ }
587
+
588
+ private function getUnusedVariations($currentVariations, $usedVariations)
589
+ {
590
+ if (empty($currentVariations)) {
591
+ return array();
592
+ }
593
+
594
+ if (empty($usedVariations)) {
595
+ return $currentVariations;
596
+ }
597
+
598
+ $unusedOptions = array();
599
+
600
+ foreach ($currentVariations as $id => $currentOption) {
601
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
602
+ continue;
603
+ }
604
+
605
+ $unusedOptions[$id] = $currentOption;
606
+ }
607
+
608
+ return $unusedOptions;
609
+ }
610
+
611
+ private function isVariationExistsInArray(array $needle, array $haystack)
612
+ {
613
+ foreach ($haystack as $option) {
614
+ if ($option != $needle) {
615
+ continue;
616
+ }
617
+
618
+ return true;
619
+ }
620
+
621
+ return false;
622
+ }
623
+
624
+ // ---------------------------------------
625
+
626
+ public function hasUnusedProductVariation()
627
+ {
628
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
629
+ }
630
+
631
+ public function hasUnusedChannelVariations()
632
+ {
633
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
634
+ }
635
+
636
+ // ---------------------------------------
637
+
638
+ public function hasChildWithEmptyProductOptions()
639
+ {
640
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
641
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
642
+
643
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
644
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
645
+
646
+ if (!$childTypeModel->isVariationProductMatched()) {
647
+ return true;
648
+ }
649
+ }
650
+
651
+ return false;
652
+ }
653
+
654
+ public function hasChildWithEmptyChannelOptions()
655
+ {
656
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
657
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
658
+
659
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
660
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
661
+
662
+ if (!$childTypeModel->isVariationChannelMatched()) {
663
+ return true;
664
+ }
665
+ }
666
+
667
+ return false;
668
+ }
669
+
670
+ //########################################
671
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ protected $listingProductId;
13
+
14
+ //########################################
15
+
16
+ /**
17
+ * @param mixed $listingProductId
18
+ * @return $this
19
+ */
20
+ public function setListingProductId($listingProductId)
21
+ {
22
+ $this->listingProductId = $listingProductId;
23
+
24
+ return $this;
25
+ }
26
+ /**
27
+ * @return mixed
28
+ */
29
+ public function getListingProductId()
30
+ {
31
+ return $this->listingProductId;
32
+ }
33
+
34
+ public function __construct()
35
+ {
36
+ parent::__construct();
37
+
38
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations.phtml');
39
+
40
+ return $this;
41
+ }
42
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Child/Form.php ADDED
@@ -0,0 +1,413 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations_Child_Form
10
+ extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ protected $childListingProducts = null;
13
+ protected $currentProductVariations = null;
14
+ protected $productVariationsTree = array();
15
+ protected $channelVariationsTree = array();
16
+
17
+ protected $listingProductId;
18
+
19
+ //########################################
20
+
21
+ /**
22
+ * @param mixed $listingProductId
23
+ * @return $this
24
+ */
25
+ public function setListingProductId($listingProductId)
26
+ {
27
+ $this->listingProductId = $listingProductId;
28
+
29
+ return $this;
30
+ }
31
+ /**
32
+ * @return mixed
33
+ */
34
+ public function getListingProductId()
35
+ {
36
+ return $this->listingProductId;
37
+ }
38
+
39
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
40
+ protected $listingProduct;
41
+
42
+ public function __construct()
43
+ {
44
+ parent::__construct();
45
+
46
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations/child/form.phtml');
47
+ }
48
+
49
+ // ---------------------------------------
50
+ /**
51
+ * @return Ess_M2ePro_Model_Listing_Product|null
52
+ */
53
+ public function getListingProduct()
54
+ {
55
+ if (empty($this->listingProduct)) {
56
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
57
+ ->getObject('Listing_Product', $this->getListingProductId());
58
+ }
59
+
60
+ return $this->listingProduct;
61
+ }
62
+
63
+ //########################################
64
+
65
+ public function isGeneralIdOwner()
66
+ {
67
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
68
+ }
69
+
70
+ // ---------------------------------------
71
+
72
+ public function hasChannelTheme()
73
+ {
74
+ return $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel()->hasChannelTheme();
75
+ }
76
+
77
+ public function hasUnusedChannelVariations()
78
+ {
79
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
80
+ }
81
+
82
+ // ---------------------------------------
83
+
84
+ public function getMatchedAttributes()
85
+ {
86
+ return $this->getListingProduct()->getChildObject()
87
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
88
+ }
89
+
90
+ public function getVirtualProductAttributes()
91
+ {
92
+ return $this->getListingProduct()->getChildObject()
93
+ ->getVariationManager()->getTypeModel()->getVirtualProductAttributes();
94
+ }
95
+
96
+ public function getVirtualChannelAttributes()
97
+ {
98
+ return $this->getListingProduct()->getChildObject()
99
+ ->getVariationManager()->getTypeModel()->getVirtualChannelAttributes();
100
+ }
101
+
102
+ // ---------------------------------------
103
+
104
+ public function getUnusedProductVariations()
105
+ {
106
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
107
+ }
108
+
109
+ public function getUnusedChannelVariations()
110
+ {
111
+ return $this->getUnusedVariations($this->getCurrentChannelVariations(), $this->getUsedChannelVariations());
112
+ }
113
+
114
+ private function getUnusedVariations($currentVariations, $usedVariations)
115
+ {
116
+ if (empty($currentVariations)) {
117
+ return array();
118
+ }
119
+
120
+ if (empty($usedVariations)) {
121
+ return $currentVariations;
122
+ }
123
+
124
+ $unusedOptions = array();
125
+
126
+ foreach ($currentVariations as $id => $currentOption) {
127
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
128
+ continue;
129
+ }
130
+
131
+ $unusedOptions[$id] = $currentOption;
132
+ }
133
+
134
+ return $unusedOptions;
135
+ }
136
+
137
+ private function isVariationExistsInArray(array $needle, array $haystack)
138
+ {
139
+ foreach ($haystack as $option) {
140
+ if ($option != $needle) {
141
+ continue;
142
+ }
143
+
144
+ return true;
145
+ }
146
+
147
+ return false;
148
+ }
149
+
150
+ // ---------------------------------------
151
+
152
+ public function getChildListingProducts()
153
+ {
154
+ if (!is_null($this->childListingProducts)) {
155
+ return $this->childListingProducts;
156
+ }
157
+
158
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
159
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
160
+ }
161
+
162
+ public function getCurrentProductVariations()
163
+ {
164
+ if (!is_null($this->currentProductVariations)) {
165
+ return $this->currentProductVariations;
166
+ }
167
+
168
+ $magentoProductVariations = $this->getListingProduct()
169
+ ->getMagentoProduct()
170
+ ->getVariationInstance()
171
+ ->getVariationsTypeStandard();
172
+
173
+ $productVariations = array();
174
+
175
+ foreach ($magentoProductVariations['variations'] as $option) {
176
+ $productOption = array();
177
+
178
+ foreach ($option as $attribute) {
179
+ $productOption[$attribute['attribute']] = $attribute['option'];
180
+ }
181
+
182
+ $productVariations[] = $productOption;
183
+ }
184
+
185
+ return $this->currentProductVariations = $productVariations;
186
+ }
187
+
188
+ public function getCurrentChannelVariations()
189
+ {
190
+ return $this->getListingProduct()->getChildObject()
191
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
192
+ }
193
+
194
+ // ---------------------------------------
195
+
196
+ public function getAttributesOptionsFromVariations($variations)
197
+ {
198
+ $attributesOptions = array();
199
+
200
+ foreach ($variations as $variation) {
201
+ foreach ($variation as $attr => $option) {
202
+ if (!isset($attributesOptions[$attr])) {
203
+ $attributesOptions[$attr] = array();
204
+ }
205
+ if (!in_array($option, $attributesOptions[$attr])) {
206
+ $attributesOptions[$attr][] = $option;
207
+ }
208
+ }
209
+ }
210
+
211
+ ksort($attributesOptions);
212
+
213
+ return $attributesOptions;
214
+ }
215
+
216
+ // ---------------------------------------
217
+
218
+ public function getUsedChannelVariations()
219
+ {
220
+ $usedOptions = array();
221
+
222
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
223
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
224
+
225
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
226
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
227
+
228
+ if (!$childTypeModel->isVariationChannelMatched()) {
229
+ continue;
230
+ }
231
+
232
+ $usedOptions[] = $childTypeModel->getChannelOptions();
233
+ }
234
+
235
+ return $usedOptions;
236
+ }
237
+
238
+ public function getUsedProductVariations()
239
+ {
240
+ $usedOptions = array();
241
+
242
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
243
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
244
+
245
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
246
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
247
+
248
+ if (!$childTypeModel->isVariationProductMatched()) {
249
+ continue;
250
+ }
251
+
252
+ $usedOptions[] = $childTypeModel->getProductOptions();
253
+ }
254
+
255
+ return $usedOptions;
256
+ }
257
+
258
+ // ---------------------------------------
259
+
260
+ public function getProductVariationsTree()
261
+ {
262
+ if (empty($this->productVariationsTree)) {
263
+
264
+ $matchedAttributes = $this->getMatchedAttributes();
265
+ $unusedVariations = $this->sortVariationsAttributes(
266
+ $this->getUnusedProductVariations(),
267
+ array_keys($matchedAttributes)
268
+ );
269
+ $variationsSets = $this->sortVariationAttributes(
270
+ $this->getAttributesOptionsFromVariations($unusedVariations),
271
+ array_keys($matchedAttributes)
272
+ );
273
+
274
+ $firstAttribute = key($matchedAttributes);
275
+
276
+ $this->productVariationsTree = $this->prepareVariations(
277
+ $firstAttribute,$unusedVariations,$variationsSets
278
+ );
279
+ }
280
+
281
+ return $this->productVariationsTree;
282
+ }
283
+
284
+ public function getChannelVariationsTree()
285
+ {
286
+ if (empty($this->channelVariationsTree)) {
287
+
288
+ $matchedAttributes = $this->getMatchedAttributes();
289
+ $unusedVariations = $this->sortVariationsAttributes(
290
+ $this->getUnusedChannelVariations(),
291
+ array_values($matchedAttributes)
292
+ );
293
+
294
+ if (empty($unusedVariations)) {
295
+ $this->channelVariationsTree = new stdClass();
296
+
297
+ return $this->channelVariationsTree;
298
+ }
299
+
300
+ $variationsSets = $this->sortVariationAttributes(
301
+ $this->getAttributesOptionsFromVariations($unusedVariations),
302
+ array_values($matchedAttributes)
303
+ );
304
+
305
+ $firstAttribute = $matchedAttributes[key($matchedAttributes)];
306
+
307
+ $this->channelVariationsTree = $this->prepareVariations(
308
+ $firstAttribute,$unusedVariations,$variationsSets
309
+ );
310
+ }
311
+
312
+ return $this->channelVariationsTree;
313
+ }
314
+
315
+ private function sortVariationsAttributes($variations, $sortTemplate)
316
+ {
317
+ foreach ($variations as $key => $variation) {
318
+ $variations[$key] = $this->sortVariationAttributes($variation, $sortTemplate);
319
+ }
320
+
321
+ return $variations;
322
+ }
323
+
324
+ private function sortVariationAttributes($variation, $sortTemplate)
325
+ {
326
+ $sortedData = array();
327
+
328
+ foreach ($sortTemplate as $attr) {
329
+ $sortedData[$attr] = $variation[$attr];
330
+ }
331
+
332
+ return $sortedData;
333
+ }
334
+
335
+ private function prepareVariations($currentAttribute,$magentoVariations,$variationsSets,$filters = array())
336
+ {
337
+ $return = false;
338
+
339
+ $temp = array_flip(array_keys($variationsSets));
340
+
341
+ $lastAttributePosition = count($variationsSets) - 1;
342
+ $currentAttributePosition = $temp[$currentAttribute];
343
+
344
+ if ($currentAttributePosition != $lastAttributePosition) {
345
+
346
+ $temp = array_keys($variationsSets);
347
+ $nextAttribute = $temp[$currentAttributePosition + 1];
348
+
349
+ foreach ($variationsSets[$currentAttribute] as $option) {
350
+
351
+ $filters[$currentAttribute] = $option;
352
+
353
+ $result = $this->prepareVariations(
354
+ $nextAttribute,$magentoVariations,$variationsSets,$filters
355
+ );
356
+
357
+ if (!$result) {
358
+ continue;
359
+ }
360
+
361
+ $return[$currentAttribute][$option] = $result;
362
+ }
363
+
364
+ ksort($return[$currentAttribute]);
365
+
366
+ return $return;
367
+ }
368
+
369
+ $return = false;
370
+ foreach ($magentoVariations as $key => $magentoVariation) {
371
+ foreach ($magentoVariation as $attribute => $option) {
372
+
373
+ if ($attribute == $currentAttribute) {
374
+
375
+ if (count($variationsSets) != 1) {
376
+ continue;
377
+ }
378
+
379
+ $values = array_flip($variationsSets[$currentAttribute]);
380
+ $return = array($currentAttribute => $values);
381
+
382
+ foreach ($return[$currentAttribute] as &$option) {
383
+ $option = true;
384
+ }
385
+
386
+ return $return;
387
+ }
388
+
389
+ if ($option != $filters[$attribute]) {
390
+ unset($magentoVariations[$key]);
391
+ continue;
392
+ }
393
+
394
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
395
+ if ($tempAttribute == $currentAttribute) {
396
+ $option = $tempOption;
397
+ $return[$currentAttribute][$option] = true;
398
+ }
399
+ }
400
+ }
401
+ }
402
+
403
+ if (count($magentoVariations) < 1) {
404
+ return false;
405
+ }
406
+
407
+ ksort($return[$currentAttribute]);
408
+
409
+ return $return;
410
+ }
411
+
412
+ //########################################
413
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Grid.php ADDED
@@ -0,0 +1,1785 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations_Grid
10
+ extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+ protected $childListingProducts = null;
13
+ protected $currentProductVariations = null;
14
+ protected $usedProductVariations = null;
15
+
16
+ protected $listingProductId;
17
+
18
+ //########################################
19
+
20
+ /**
21
+ * @param mixed $listingProductId
22
+ */
23
+ public function setListingProductId($listingProductId)
24
+ {
25
+ $this->listingProductId = $listingProductId;
26
+ }
27
+ /**
28
+ * @return mixed
29
+ */
30
+ public function getListingProductId()
31
+ {
32
+ return $this->listingProductId;
33
+ }
34
+
35
+ // ---------------------------------------
36
+
37
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
38
+ protected $listingProduct;
39
+
40
+ protected function getListingProduct()
41
+ {
42
+ if (empty($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
+ // ---------------------------------------
51
+
52
+ private $lockedDataCache = array();
53
+
54
+ //########################################
55
+
56
+ public function __construct()
57
+ {
58
+ parent::__construct();
59
+
60
+ // Initialization block
61
+ // ---------------------------------------
62
+ $this->setId('amazonVariationProductManageGrid');
63
+ $this->setDefaultSort('id');
64
+ $this->setDefaultDir('ASC');
65
+ $this->setUseAjax(true);
66
+ // ---------------------------------------
67
+ }
68
+
69
+ //########################################
70
+
71
+ protected function _prepareCollection()
72
+ {
73
+ // Get collection
74
+ // ---------------------------------------
75
+ /** @var Ess_M2ePro_Model_Mysql4_Amazon_Listing_Product_Collection $collection */
76
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Listing_Product');
77
+ $collection->getSelect()->distinct();
78
+ $collection->getSelect()->where("`second_table`.`variation_parent_id` = ?",(int)$this->getListingProductId());
79
+ // ---------------------------------------
80
+
81
+ $collection->getSelect()->joinLeft(
82
+ new Zend_Db_Expr('(
83
+ SELECT
84
+ mlpv.listing_product_id,
85
+ GROUP_CONCAT(`mlpvo`.`attribute`, \'==\', `mlpvo`.`product_id` SEPARATOR \'||\') as products_ids
86
+ FROM `'. Mage::getResourceModel('M2ePro/Listing_Product_Variation')->getMainTable() .'` as mlpv
87
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product_Variation_Option')->getMainTable() .
88
+ '` AS `mlpvo` ON (`mlpvo`.`listing_product_variation_id`=`mlpv`.`id`)
89
+ WHERE `mlpv`.`component_mode` = \'amazon\'
90
+ GROUP BY `mlpv`.`listing_product_id`
91
+ )'),
92
+ 'main_table.id=t.listing_product_id',
93
+ array(
94
+ 'products_ids' => 'products_ids',
95
+ )
96
+ );
97
+
98
+ // Set collection to grid
99
+ $this->setCollection($collection);
100
+
101
+ return parent::_prepareCollection();
102
+ }
103
+
104
+ protected function _prepareColumns()
105
+ {
106
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
107
+ $parentType = $this->getListingProduct()->getChildObject()->getVariationManager()->getTypeModel();
108
+
109
+ $channelAttributesSets = $parentType->getChannelAttributesSets();
110
+ $productAttributes = $parentType->getProductAttributes();
111
+
112
+ if ($parentType->hasMatchedAttributes()) {
113
+ $productAttributes = array_keys($parentType->getMatchedAttributes());
114
+ $channelAttributes = array_values($parentType->getMatchedAttributes());
115
+ } else if (!empty($channelAttributesSets)) {
116
+ $channelAttributes = array_keys($channelAttributesSets);
117
+ } else {
118
+ $channelAttributes = array();
119
+ }
120
+
121
+ $this->addColumn('product_options', array(
122
+ 'header' => Mage::helper('M2ePro')->__('Magento Variation'),
123
+ 'align' => 'left',
124
+ 'width' => '210px',
125
+ 'sortable' => false,
126
+ 'index' => 'additional_data',
127
+ 'filter_index' => 'additional_data',
128
+ 'frame_callback' => array($this, 'callbackColumnProductOptions'),
129
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
130
+ 'options' => $productAttributes,
131
+ 'filter_condition_callback' => array($this, 'callbackProductOptions')
132
+ ));
133
+
134
+ $this->addColumn('channel_options', array(
135
+ 'header' => Mage::helper('M2ePro')->__('Amazon Variation'),
136
+ 'align' => 'left',
137
+ 'width' => '210px',
138
+ 'sortable' => false,
139
+ 'index' => 'additional_data',
140
+ 'filter_index' => 'additional_data',
141
+ 'frame_callback' => array($this, 'callbackColumnChannelOptions'),
142
+ 'filter' => 'M2ePro/adminhtml_grid_column_filter_attributesOptions',
143
+ 'options' => $channelAttributes,
144
+ 'filter_condition_callback' => array($this, 'callbackChannelOptions')
145
+ ));
146
+
147
+ $this->addColumn('sku', array(
148
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
149
+ 'align' => 'left',
150
+ 'type' => 'text',
151
+ 'index' => 'sku',
152
+ 'filter_index' => 'sku',
153
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
154
+ ));
155
+
156
+ $this->addColumn('general_id', array(
157
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
158
+ 'align' => 'left',
159
+ 'width' => '100px',
160
+ 'type' => 'text',
161
+ 'index' => 'general_id',
162
+ 'filter_index' => 'general_id',
163
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
164
+ ));
165
+
166
+ $this->addColumn('online_qty', array(
167
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
168
+ 'align' => 'right',
169
+ 'width' => '70px',
170
+ 'type' => 'number',
171
+ 'index' => 'online_qty',
172
+ 'filter_index' => 'online_qty',
173
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty'),
174
+ 'filter' => 'M2ePro/adminhtml_common_amazon_grid_column_filter_qty',
175
+ 'filter_condition_callback' => array($this, 'callbackFilterQty')
176
+ ));
177
+
178
+ $this->addColumn('online_price', array(
179
+ 'header' => Mage::helper('M2ePro')->__('Price'),
180
+ 'align' => 'right',
181
+ 'width' => '70px',
182
+ 'type' => 'number',
183
+ 'index' => 'online_price',
184
+ 'filter_index' => 'online_price',
185
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
186
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
187
+ ));
188
+
189
+ $this->addColumn('status', array(
190
+ 'header' => Mage::helper('M2ePro')->__('Status'),
191
+ 'width' => '100px',
192
+ 'index' => 'status',
193
+ 'filter_index' => 'status',
194
+ 'type' => 'options',
195
+ 'sortable' => false,
196
+ 'options' => array(
197
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
198
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
199
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
200
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
201
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
202
+ ),
203
+ 'frame_callback' => array($this, 'callbackColumnStatus')
204
+ ));
205
+
206
+ return parent::_prepareColumns();
207
+ }
208
+
209
+ protected function _prepareMassaction()
210
+ {
211
+ // Set massaction identifiers
212
+ // ---------------------------------------
213
+ $this->setMassactionIdField('id');
214
+ $this->setMassactionIdFieldOnlyIndexValue(true);
215
+ // ---------------------------------------
216
+
217
+ // Set mass-action
218
+ // ---------------------------------------
219
+ $this->getMassactionBlock()->addItem('list', array(
220
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
221
+ 'url' => '',
222
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
223
+ ));
224
+
225
+ $this->getMassactionBlock()->addItem('revise', array(
226
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
227
+ 'url' => '',
228
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
229
+ ));
230
+
231
+ $this->getMassactionBlock()->addItem('relist', array(
232
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
233
+ 'url' => '',
234
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
235
+ ));
236
+
237
+ $this->getMassactionBlock()->addItem('stop', array(
238
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
239
+ 'url' => '',
240
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
241
+ ));
242
+
243
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
244
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
245
+ 'url' => '',
246
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
247
+ ));
248
+
249
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
250
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
251
+ 'url' => '',
252
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
253
+ ));
254
+
255
+ // ---------------------------------------
256
+
257
+ return parent::_prepareMassaction();
258
+ }
259
+
260
+ //########################################
261
+
262
+ public function callbackColumnProductOptions($additionalData, $row, $column, $isExport)
263
+ {
264
+ $html = '';
265
+
266
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $typeModel */
267
+ $typeModel = $row->getChildObject()->getVariationManager()->getTypeModel();
268
+
269
+ $html .= '<div class="product-options-main" style="font-size: 11px; color: grey; margin-left: 7px">';
270
+ $productOptions = $typeModel->getProductOptions();
271
+ if (!empty($productOptions)) {
272
+ $productsIds = $this->parseGroupedData($row->getData('products_ids'));
273
+ $uniqueProductsIds = count(array_unique($productsIds)) > 1;
274
+
275
+ $matchedAttributes = $typeModel->getParentTypeModel()->getMatchedAttributes();
276
+ if (!empty($matchedAttributes)) {
277
+
278
+ $sortedOptions = array();
279
+
280
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
281
+ $sortedOptions[$magentoAttr] = $productOptions[$magentoAttr];
282
+ }
283
+
284
+ $productOptions = $sortedOptions;
285
+ }
286
+
287
+ $virtualProductAttributes = array_keys($typeModel->getParentTypeModel()->getVirtualProductAttributes());
288
+
289
+ $html .= '<div class="m2ePro-variation-attributes product-options-list">';
290
+ if (!$uniqueProductsIds) {
291
+ $url = $this->getUrl('adminhtml/catalog_product/edit', array('id' => reset($productsIds)));
292
+ $html .= '<a href="' . $url . '" target="_blank">';
293
+ }
294
+ foreach ($productOptions as $attribute => $option) {
295
+
296
+ $style = '';
297
+ if (in_array($attribute, $virtualProductAttributes)) {
298
+ $style = 'border-bottom: 2px dotted grey';
299
+ }
300
+
301
+ !$option && $option = '--';
302
+ $optionHtml = '<span class="attribute-row" style="' . $style . '"><span class="attribute"><strong>' .
303
+ Mage::helper('M2ePro')->escapeHtml($attribute) .
304
+ '</strong></span>:&nbsp;<span class="value">' . Mage::helper('M2ePro')->escapeHtml($option) .
305
+ '</span></span>';
306
+
307
+ if ($uniqueProductsIds && $option !== '--') {
308
+ $url = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productsIds[$attribute]));
309
+ $html .= '<a href="' . $url . '" target="_blank">' . $optionHtml . '</a><br/>';
310
+ } else {
311
+ $html .= $optionHtml . '<br/>';
312
+ }
313
+ }
314
+ if (!$uniqueProductsIds) {
315
+ $html .= '</a>';
316
+ }
317
+ $html .= '</div>';
318
+ }
319
+
320
+ if ($this->canChangeProductVariation($row)) {
321
+
322
+ $listingProductId = $row->getId();
323
+ $attributes = $this->getListingProduct()->getChildObject()
324
+ ->getVariationManager()->getTypeModel()->getProductAttributes();
325
+ $variationsTree = $this->getProductVariationsTree($row);
326
+
327
+ sort($attributes);
328
+
329
+ $linkTitle = Mage::helper('M2ePro')->__('Change Variation');
330
+ $linkContent = Mage::helper('M2ePro')->__('Change Variation');
331
+
332
+ $attributes = Mage::helper('M2ePro')->escapeHtml(json_encode($attributes));
333
+ $variationsTree = Mage::helper('M2ePro')->escapeHtml(json_encode($variationsTree));
334
+
335
+ $html .= <<<HTML
336
+ <form action="javascript:void(0);" class="product-options-edit"></form>
337
+ <a href="javascript:"
338
+ onclick="ListingGridHandlerObj.editProductOptions(this, {$attributes}, {$variationsTree}, {$listingProductId})"
339
+ title="{$linkTitle}">{$linkContent}</a>
340
+ HTML;
341
+ }
342
+
343
+ $html .= '</div>';
344
+
345
+ return $html;
346
+ }
347
+
348
+ public function callbackColumnChannelOptions($additionalData, $row, $column, $isExport)
349
+ {
350
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
351
+ $amazonListingProduct = $row->getChildObject();
352
+
353
+ $typeModel = $amazonListingProduct->getVariationManager()->getTypeModel();
354
+
355
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $parentAmazonListingProduct */
356
+ $parentAmazonListingProduct = $typeModel->getParentListingProduct()->getChildObject();
357
+
358
+ $matchedAttributes = $parentAmazonListingProduct->getVariationManager()
359
+ ->getTypeModel()
360
+ ->getMatchedAttributes();
361
+
362
+ if (!$typeModel->isVariationChannelMatched()) {
363
+ if (!$typeModel->isVariationProductMatched() || !$amazonListingProduct->isGeneralIdOwner()) {
364
+ return '';
365
+ }
366
+
367
+ if (empty($matchedAttributes)) {
368
+ return '';
369
+ }
370
+
371
+ $options = array();
372
+
373
+ foreach ($typeModel->getProductOptions() as $attribute => $value) {
374
+ $options[$matchedAttributes[$attribute]] = $value;
375
+ }
376
+ } else {
377
+ $options = $typeModel->getChannelOptions();
378
+
379
+ if (!empty($matchedAttributes)) {
380
+
381
+ $sortedOptions = array();
382
+
383
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
384
+ $sortedOptions[$amazonAttr] = $options[$amazonAttr];
385
+ }
386
+
387
+ $options = $sortedOptions;
388
+ }
389
+ }
390
+
391
+ if (empty($options)) {
392
+ return '';
393
+ }
394
+
395
+ $generalId = $amazonListingProduct->getGeneralId();
396
+
397
+ $virtualChannelAttributes = array_keys($typeModel->getParentTypeModel()->getVirtualChannelAttributes());
398
+
399
+ $html = '<div class="m2ePro-variation-attributes" style="color: grey; margin-left: 7px">';
400
+
401
+ if (!empty($generalId)) {
402
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
403
+ $generalId,
404
+ $this->getListingProduct()->getListing()->getMarketplaceId()
405
+ );
406
+
407
+ $html .= '<a href="' . $url . '" target="_blank" title="' . $generalId . '" >';
408
+ }
409
+
410
+ foreach ($options as $attribute => $option) {
411
+ $style = '';
412
+ if (in_array($attribute, $virtualChannelAttributes)) {
413
+ $style = 'border-bottom: 2px dotted grey';
414
+ }
415
+
416
+ !$option && $option = '--';
417
+
418
+ $attrName = Mage::helper('M2ePro')->escapeHtml($attribute);
419
+ $optionName = Mage::helper('M2ePro')->escapeHtml($option);
420
+
421
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
422
+ $html .= <<<HTML
423
+ <span style="{$style}">{$attrName}:&nbsp;{$optionName}</span><br/>
424
+ HTML;
425
+ } else {
426
+ $html .= <<<HTML
427
+ <span style="{$style}"><b>{$attrName}</b>:&nbsp;{$optionName}</span><br/>
428
+ HTML;
429
+ }
430
+ }
431
+
432
+ if (!empty($generalId)) {
433
+ $html .= '</a>';
434
+ }
435
+
436
+ $html .= '</div>';
437
+
438
+ return $html;
439
+ }
440
+
441
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
442
+ {
443
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
444
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
445
+ }
446
+
447
+ if (is_null($value) || $value === '') {
448
+ $value = Mage::helper('M2ePro')->__('N/A');
449
+ }
450
+
451
+ if ($row->getData('defected_messages')) {
452
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
453
+
454
+ $msg = '';
455
+ foreach ($defectedMessages as $message) {
456
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
457
+ if (!empty($message['value'])) {
458
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
459
+ }
460
+ $msg .= '</p>';
461
+ }
462
+
463
+ $value .= <<<HTML
464
+ <span style="float:right;">
465
+ <img id="map_link_defected_message_icon_{$row->getId()}"
466
+ class="tool-tip-image"
467
+ style="vertical-align: middle;"
468
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
469
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
470
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
471
+ <span>{$msg}</span>
472
+ </span>
473
+ </span>
474
+ HTML;
475
+ }
476
+
477
+ return $value;
478
+ }
479
+
480
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
481
+ {
482
+ if (is_null($generalId) || $generalId === '') {
483
+
484
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
485
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
486
+ if ($amazonListingProduct->isGeneralIdOwner()) {
487
+ return Mage::helper('M2ePro')->__('New ASIN/ISBN');
488
+ }
489
+
490
+ return Mage::helper('M2ePro')->__('N/A');
491
+ }
492
+ return $this->getGeneralIdLink($generalId);
493
+ }
494
+
495
+ public function callbackColumnAvailableQty($qty, $row, $column, $isExport)
496
+ {
497
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
498
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
499
+ }
500
+
501
+ if ((bool)$row->getData('is_afn_channel')) {
502
+ $sku = $row->getData('sku');
503
+
504
+ if (empty($sku)) {
505
+ return Mage::helper('M2ePro')->__('AFN');
506
+ }
507
+
508
+ $productId = $row->getData('id');
509
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
510
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$productId);
511
+
512
+ $afn = Mage::helper('M2ePro')->__('AFN');
513
+ $total = Mage::helper('M2ePro')->__('Total');
514
+ $inStock = Mage::helper('M2ePro')->__('In Stock');
515
+ $accountId = $listingProduct->getListing()->getAccountId();
516
+
517
+ return <<<HTML
518
+ <div id="m2ePro_afn_qty_value_{$productId}">
519
+ <span class="m2ePro-online-sku-value" productId="{$productId}" style="display: none">{$sku}</span>
520
+ <span class="m2epro-empty-afn-qty-data" style="display: none">{$afn}</span>
521
+ <div class="m2epro-afn-qty-data" style="display: none">
522
+ <div class="total">{$total}: <span></span></div>
523
+ <div class="in-stock">{$inStock}: <span></span></div>
524
+ </div>
525
+ <a href="javascript:void(0)"
526
+ onclick="CommonAmazonListingAfnQtyHandlerObj.showAfnQty(this,'{$sku}','{$productId}',{$accountId})">
527
+ {$afn}
528
+ </a>
529
+ </div>
530
+ HTML;
531
+ }
532
+
533
+ if (is_null($qty) || $qty === '') {
534
+ return Mage::helper('M2ePro')->__('N/A');
535
+ }
536
+
537
+ return $qty;
538
+ }
539
+
540
+ public function callbackColumnPrice($value, $row, $column, $isExport)
541
+ {
542
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
543
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
544
+ }
545
+
546
+ if (is_null($value) || $value === '') {
547
+ return Mage::helper('M2ePro')->__('N/A');
548
+ }
549
+
550
+ $marketplaceId = $this->getListingProduct()->getListing()->getMarketplaceId();
551
+ $currency = Mage::helper('M2ePro/Component_Amazon')
552
+ ->getCachedObject('Marketplace',$marketplaceId)
553
+ ->getChildObject()
554
+ ->getDefaultCurrency();
555
+
556
+ if ((float)$value <= 0) {
557
+ $priceValue = '<span style="color: #f00;">0</span>';
558
+ } else {
559
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($value);
560
+ }
561
+
562
+ $resultHtml = '';
563
+
564
+ $salePrice = $row->getData('online_sale_price');
565
+ if ((float)$salePrice > 0) {
566
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
567
+
568
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
569
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
570
+
571
+ if ($currentTimestamp <= $endDateTimestamp) {
572
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
573
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
574
+
575
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
576
+
577
+ $fromDate = Mage::app()->getLocale()->date(
578
+ $row->getData('online_sale_price_start_date'), $dateFormat
579
+ )->toString($dateFormat);
580
+ $toDate = Mage::app()->getLocale()->date(
581
+ $row->getData('online_sale_price_end_date'), $dateFormat
582
+ )->toString($dateFormat);
583
+
584
+ $intervalHtml = '<img class="tool-tip-image"
585
+ style="vertical-align: middle;"
586
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
587
+ text-align: left;
588
+ width: 120px;
589
+ background: #E3E3E3;">
590
+ <img src="'.$iconHelpPath.'">
591
+ <span style="color:gray;">
592
+ <strong>From:</strong> '.$fromDate.'<br/>
593
+ <strong>To:</strong> '.$toDate.'
594
+ </span>
595
+ </span>';
596
+
597
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
598
+
599
+ if ($currentTimestamp >= $startDateTimestamp &&
600
+ $currentTimestamp <= $endDateTimestamp &&
601
+ $salePrice < (float)$value
602
+ ) {
603
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>';
604
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
605
+ } else {
606
+ $resultHtml .= $priceValue;
607
+ $resultHtml .= '<br/>'.$intervalHtml.
608
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
609
+ }
610
+ }
611
+ }
612
+
613
+ if (empty($resultHtml)) {
614
+ $resultHtml = $priceValue;
615
+ }
616
+
617
+ return $resultHtml;
618
+ }
619
+
620
+ public function callbackColumnStatus($value, $row, $column, $isExport)
621
+ {
622
+ $listingProductId = (int)$row->getData('id');
623
+
624
+ $html = $this->getViewLogIconHtml($row);
625
+
626
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
627
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
628
+
629
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
630
+ if (!empty($synchNote)) {
631
+
632
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
633
+
634
+ if (empty($html)) {
635
+ $html = <<<HTML
636
+ <span style="float:right;">
637
+ <img id="map_link_error_icon_{$row->getId()}"
638
+ class="tool-tip-image"
639
+ style="vertical-align: middle;"
640
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
641
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
642
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
643
+ <span>{$synchNote}</span>
644
+ </span>
645
+ </span>
646
+ HTML;
647
+ } else {
648
+ $html .= <<<HTML
649
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
650
+ HTML;
651
+ }
652
+ }
653
+
654
+ switch ($row->getData('status')) {
655
+
656
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
657
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
658
+ $html .= '<span style="color: gray;">' . $value . '</span>';
659
+ break;
660
+
661
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
662
+ $html .= '<span style="color: green;">' . $value . '</span>';
663
+ break;
664
+
665
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
666
+ $html .= '<span style="color: red;">'.$value.'</span>';
667
+ break;
668
+
669
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
670
+ $html .= '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
671
+ break;
672
+
673
+ default:
674
+ break;
675
+ }
676
+
677
+ $tempLocks = $this->getLockedData($row);
678
+ $tempLocks = $tempLocks['object_locks'];
679
+
680
+ foreach ($tempLocks as $lock) {
681
+
682
+ switch ($lock->getTag()) {
683
+
684
+ case 'list_action':
685
+ $html .= '<br/><span style="color: #605fff">[Listing...]</span>';
686
+ break;
687
+
688
+ case 'relist_action':
689
+ $html .= '<br/><span style="color: #605fff">[Relisting...]</span>';
690
+ break;
691
+
692
+ case 'revise_action':
693
+ $html .= '<br/><span style="color: #605fff">[Revising...]</span>';
694
+ break;
695
+
696
+ case 'stop_action':
697
+ $html .= '<br/><span style="color: #605fff">[Stopping...]</span>';
698
+ break;
699
+
700
+ case 'stop_and_remove_action':
701
+ $html .= '<br/><span style="color: #605fff">[Stopping...]</span>';
702
+ break;
703
+
704
+ case 'delete_and_remove_action':
705
+ $html .= '<br/><span style="color: #605fff">[Removing...]</span>';
706
+ break;
707
+
708
+ case 'switch_to_afn_action':
709
+ $html .= '<br/><span style="color: #605fff">[Switch to AFN in Progress...]</span>';
710
+ break;
711
+
712
+ case 'switch_to_mfn_action':
713
+ $html .= '<br/><span style="color: #605fff">[Switch to MFN in Progress...]</span>';
714
+ break;
715
+
716
+ default:
717
+ break;
718
+
719
+ }
720
+ }
721
+
722
+ return $html;
723
+ }
724
+
725
+ public function callbackProductOptions($collection, $column)
726
+ {
727
+ $values = $column->getFilter()->getValue();
728
+
729
+ if ($values == null && !is_array($values)) {
730
+ return;
731
+ }
732
+
733
+ foreach ($values as $value) {
734
+ if (is_array($value) && isset($value['value'])) {
735
+ $collection->addFieldToFilter(
736
+ 'additional_data',
737
+ array('regexp'=> '"variation_product_options":[^}]*'.$value['attr'].'":"' .
738
+ // trying to screen slashes that in json
739
+ addslashes(addslashes($value['value'])))
740
+ );
741
+ }
742
+ }
743
+ }
744
+
745
+ public function callbackChannelOptions($collection, $column)
746
+ {
747
+ $values = $column->getFilter()->getValue();
748
+
749
+ if ($values == null && !is_array($values)) {
750
+ return;
751
+ }
752
+
753
+ foreach ($values as $value) {
754
+ if (is_array($value) && isset($value['value'])) {
755
+ $collection->addFieldToFilter(
756
+ 'additional_data',
757
+ array('regexp'=> '"variation_channel_options":[^}]*'.$value['attr'].'":"' .
758
+ // trying to screen slashes that in json
759
+ addslashes(addslashes($value['value'])))
760
+ );
761
+ }
762
+ }
763
+ }
764
+
765
+ protected function callbackFilterQty($collection, $column)
766
+ {
767
+ $value = $column->getFilter()->getValue();
768
+
769
+ if (empty($value)) {
770
+ return;
771
+ }
772
+
773
+ $where = '';
774
+
775
+ if (isset($value['from']) && $value['from'] != '') {
776
+ $where .= 'online_qty >= ' . $value['from'];
777
+ }
778
+
779
+ if (isset($value['to']) && $value['to'] != '') {
780
+ if (isset($value['from']) && $value['from'] != '') {
781
+ $where .= ' AND ';
782
+ }
783
+ $where .= 'online_qty <= ' . $value['to'];
784
+ }
785
+
786
+ if (!empty($value['afn'])) {
787
+ if (!empty($where)) {
788
+ $where = '(' . $where . ') OR ';
789
+ }
790
+ $where .= 'is_afn_channel = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_AFN_CHANNEL_YES;;
791
+ }
792
+
793
+ $collection->getSelect()->where($where);
794
+ }
795
+
796
+ protected function callbackFilterPrice($collection, $column)
797
+ {
798
+ $value = $column->getFilter()->getValue();
799
+
800
+ if (empty($value)) {
801
+ return;
802
+ }
803
+
804
+ $from = $value['from'];
805
+ $to = $value['to'];
806
+
807
+ $collection->getSelect()->where(
808
+ '(online_price >= \''.$from.'\' AND online_price <= \''.$to.'\' AND
809
+ (
810
+ online_sale_price IS NULL OR
811
+ online_sale_price_start_date > NOW() OR
812
+ online_sale_price_end_date < NOW()
813
+ )) OR (online_sale_price >= \''.$from.'\' AND online_sale_price <= \''.$to.'\' AND
814
+ (
815
+ online_sale_price IS NOT NULL AND
816
+ online_sale_price_start_date < NOW() AND
817
+ online_sale_price_end_date > NOW()
818
+ ))'
819
+ );
820
+ }
821
+
822
+ //########################################
823
+
824
+ /**
825
+ * @param Ess_M2ePro_Model_Listing_Product $listingProduct
826
+ * @return string
827
+ */
828
+ public function getViewLogIconHtml($listingProduct)
829
+ {
830
+ $listingProductId = (int)$listingProduct->getId();
831
+
832
+ // Get last messages
833
+ // ---------------------------------------
834
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
835
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
836
+
837
+ $dbSelect = $connRead->select()
838
+ ->from(
839
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
840
+ array('action_id','action','type','description','create_date','initiator')
841
+ )
842
+ ->where('`listing_product_id` = ?', $listingProductId)
843
+ ->where('`action_id` IS NOT NULL')
844
+ ->order(array('id DESC'))
845
+ ->limit(30);
846
+
847
+ $logRows = $connRead->fetchAll($dbSelect);
848
+ // ---------------------------------------
849
+
850
+ // Get grouped messages by action_id
851
+ // ---------------------------------------
852
+ $actionsRows = array();
853
+ $tempActionRows = array();
854
+ $lastActionId = false;
855
+
856
+ foreach ($logRows as $row) {
857
+
858
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
859
+
860
+ if ($row['action_id'] !== $lastActionId) {
861
+ if (count($tempActionRows) > 0) {
862
+ $actionsRows[] = array(
863
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
864
+ 'date' => $this->getMainDateForActionId($tempActionRows),
865
+ 'action' => $this->getActionForAction($tempActionRows[0]),
866
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
867
+ 'items' => $tempActionRows
868
+ );
869
+ $tempActionRows = array();
870
+ }
871
+ $lastActionId = $row['action_id'];
872
+ }
873
+ $tempActionRows[] = $row;
874
+ }
875
+
876
+ if (count($tempActionRows) > 0) {
877
+ $actionsRows[] = array(
878
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
879
+ 'date' => $this->getMainDateForActionId($tempActionRows),
880
+ 'action' => $this->getActionForAction($tempActionRows[0]),
881
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
882
+ 'items' => $tempActionRows
883
+ );
884
+ }
885
+
886
+ if (count($actionsRows) <= 0) {
887
+ return '';
888
+ }
889
+
890
+ foreach ($actionsRows as &$actionsRow) {
891
+ usort($actionsRow['items'], function($a, $b)
892
+ {
893
+ $sortOrder = array(
894
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
895
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
896
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
897
+ );
898
+
899
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
900
+ });
901
+ }
902
+
903
+ $tips = array(
904
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
905
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
906
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
907
+ );
908
+
909
+ $icons = array(
910
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
911
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
912
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
913
+ );
914
+
915
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
916
+ 'entity_id' => (int)$listingProduct->getId(),
917
+ 'rows' => $actionsRows,
918
+ 'tips' => $tips,
919
+ 'icons' => $icons,
920
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
921
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
922
+ ));
923
+
924
+ return $summary->toHtml();
925
+ }
926
+
927
+ public function getActionForAction($actionRows)
928
+ {
929
+ $string = '';
930
+
931
+ switch ($actionRows['action']) {
932
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
933
+ $string = Mage::helper('M2ePro')->__('List');
934
+ break;
935
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
936
+ $string = Mage::helper('M2ePro')->__('Relist');
937
+ break;
938
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
939
+ $string = Mage::helper('M2ePro')->__('Revise');
940
+ break;
941
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
942
+ $string = Mage::helper('M2ePro')->__('Stop');
943
+ break;
944
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
945
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
946
+ break;
947
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
948
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
949
+ break;
950
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
951
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
952
+ break;
953
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
954
+ $string = Mage::helper('M2ePro')->__('Channel Change');
955
+ break;
956
+ case Ess_M2ePro_Model_Listing_Log::ACTION_SWITCH_TO_AFN_ON_COMPONENT:
957
+ $string = Mage::helper('M2ePro')->__('Switch to AFN');
958
+ break;
959
+ case Ess_M2ePro_Model_Listing_Log::ACTION_SWITCH_TO_MFN_ON_COMPONENT:
960
+ $string = Mage::helper('M2ePro')->__('Switch to MFN');
961
+ break;
962
+ }
963
+
964
+ return $string;
965
+ }
966
+
967
+ public function getInitiatorForAction($actionRows)
968
+ {
969
+ $string = '';
970
+
971
+ switch ((int)$actionRows['initiator']) {
972
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
973
+ $string = '';
974
+ break;
975
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
976
+ $string = Mage::helper('M2ePro')->__('Manual');
977
+ break;
978
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
979
+ $string = Mage::helper('M2ePro')->__('Automatic');
980
+ break;
981
+ }
982
+
983
+ return $string;
984
+ }
985
+
986
+ public function getMainTypeForActionId($actionRows)
987
+ {
988
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
989
+
990
+ foreach ($actionRows as $row) {
991
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
992
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
993
+ break;
994
+ }
995
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
996
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
997
+ }
998
+ }
999
+
1000
+ return $type;
1001
+ }
1002
+
1003
+ public function getMainDateForActionId($actionRows)
1004
+ {
1005
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
1006
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
1007
+ }
1008
+
1009
+ //########################################
1010
+
1011
+ public function getMainButtonsHtml()
1012
+ {
1013
+ $html = '';
1014
+ if ($this->getFilterVisibility()) {
1015
+ $html.= $this->getAddNewChildButtonsHtml();
1016
+ $html.= $this->getResetFilterButtonHtml();
1017
+ $html.= $this->getSearchButtonHtml();
1018
+ }
1019
+ return $html;
1020
+ }
1021
+
1022
+ public function getMassactionBlockHtml()
1023
+ {
1024
+ if ($this->isNewChildAllowed()) {
1025
+ $blockName = 'adminhtml_common_amazon_listing_variation_product_manage_tabs_variations_child_form';
1026
+ $form = $this->getLayout()->createBlock('M2ePro/'.$blockName);
1027
+ $form->setListingProductId($this->getListingProductId());
1028
+
1029
+ return $form->toHtml() . parent::getMassactionBlockHtml();
1030
+ }
1031
+
1032
+ return parent::getMassactionBlockHtml();
1033
+ }
1034
+
1035
+ private function getAddNewChildButtonsHtml()
1036
+ {
1037
+ if ($this->isNewChildAllowed()) {
1038
+
1039
+ // ---------------------------------------
1040
+ $data = array(
1041
+ 'label' => Mage::helper('adminhtml')->__('Add New Child Product'),
1042
+ 'onclick' => 'ListingGridHandlerObj.showNewChildForm('. !$this->hasUnusedChannelVariations() .')',
1043
+ 'class' => 'task',
1044
+ 'id' => 'add_new_child_button'
1045
+ );
1046
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
1047
+ $this->setChild('add_new_child_button', $buttonBlock);
1048
+ // ---------------------------------------
1049
+
1050
+ }
1051
+
1052
+ return $this->getChildHtml('add_new_child_button');
1053
+ }
1054
+
1055
+ protected function isNewChildAllowed()
1056
+ {
1057
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
1058
+ $amazonListingProduct = $this->getListingProduct()->getChildObject();
1059
+
1060
+ if (!$amazonListingProduct->getGeneralId()) {
1061
+ return false;
1062
+ }
1063
+
1064
+ if (!$amazonListingProduct->getVariationManager()->getTypeModel()->hasMatchedAttributes()) {
1065
+ return false;
1066
+ }
1067
+
1068
+ if (!$this->hasUnusedProductVariation()) {
1069
+ return false;
1070
+ }
1071
+
1072
+ if ($this->hasChildWithEmptyProductOptions()) {
1073
+ return false;
1074
+ }
1075
+
1076
+ if (!$this->isGeneralIdOwner() && !$this->hasUnusedChannelVariations()) {
1077
+ return false;
1078
+ }
1079
+
1080
+ if (!$this->isGeneralIdOwner() && $this->hasChildWithEmptyChannelOptions()) {
1081
+ return false;
1082
+ }
1083
+
1084
+ return true;
1085
+ }
1086
+
1087
+ public function isGeneralIdOwner()
1088
+ {
1089
+ return $this->getListingProduct()->getChildObject()->isGeneralIdOwner();
1090
+ }
1091
+
1092
+ public function getCurrentChannelVariations()
1093
+ {
1094
+ return $this->getListingProduct()->getChildObject()
1095
+ ->getVariationManager()->getTypeModel()->getChannelVariations();
1096
+ }
1097
+
1098
+ public function hasUnusedProductVariation()
1099
+ {
1100
+ return count($this->getChildListingProducts()) < count($this->getCurrentProductVariations());
1101
+ }
1102
+
1103
+ public function hasUnusedChannelVariations()
1104
+ {
1105
+ return count($this->getUsedChannelVariations()) < count($this->getCurrentChannelVariations());
1106
+ }
1107
+
1108
+ public function hasChildWithEmptyProductOptions()
1109
+ {
1110
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1111
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1112
+
1113
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1114
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1115
+
1116
+ if (!$childTypeModel->isVariationProductMatched()) {
1117
+ return true;
1118
+ }
1119
+ }
1120
+
1121
+ return false;
1122
+ }
1123
+
1124
+ public function hasChildWithEmptyChannelOptions()
1125
+ {
1126
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1127
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1128
+
1129
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1130
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1131
+
1132
+ if (!$childTypeModel->isVariationChannelMatched()) {
1133
+ return true;
1134
+ }
1135
+ }
1136
+
1137
+ return false;
1138
+ }
1139
+
1140
+ public function getUsedChannelVariations()
1141
+ {
1142
+ $usedOptions = array();
1143
+
1144
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1145
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1146
+
1147
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1148
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1149
+
1150
+ if (!$childTypeModel->isVariationChannelMatched()) {
1151
+ continue;
1152
+ }
1153
+
1154
+ $usedOptions[] = $childTypeModel->getChannelOptions();
1155
+ }
1156
+
1157
+ return $usedOptions;
1158
+ }
1159
+
1160
+ // ---------------------------------------
1161
+
1162
+ public function getGridUrl()
1163
+ {
1164
+ return $this->getUrl('*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsGridAjax', array(
1165
+ '_current' => true
1166
+ ));
1167
+ }
1168
+
1169
+ public function getRowUrl($row)
1170
+ {
1171
+ return false;
1172
+ }
1173
+
1174
+ //########################################
1175
+
1176
+ protected function _toHtml()
1177
+ {
1178
+ $listingId = $this->getListingProduct()->getListingId();
1179
+
1180
+ /** @var $helper Ess_M2ePro_Helper_Data */
1181
+ $helper = Mage::helper('M2ePro');
1182
+
1183
+ // ---------------------------------------
1184
+ $urls = array();
1185
+
1186
+ $path = 'adminhtml_common_log/listingProduct';
1187
+ $urls[$path] = $this->getUrl('*/' . $path, array(
1188
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
1189
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array('id' => $listingId))
1190
+ ));
1191
+
1192
+ $urls['adminhtml_common_amazon_listing_variation_product_manage/createNewChild'] = $this->getUrl(
1193
+ '*/adminhtml_common_amazon_listing_variation_product_manage/createNewChild');
1194
+
1195
+ $urls = json_encode($urls);
1196
+ // ---------------------------------------
1197
+
1198
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
1199
+
1200
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing', array(
1201
+ 'id' =>$listingId,
1202
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON,
1203
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array('id' => $listingId))
1204
+ ));
1205
+
1206
+ $checkLockListing = $this->getUrl('*/adminhtml_listing/checkLockListing', array('component' => $component));
1207
+ $lockListingNow = $this->getUrl('*/adminhtml_listing/lockListingNow', array('component' => $component));
1208
+ $unlockListingNow = $this->getUrl('*/adminhtml_listing/unlockListingNow', array('component' => $component));
1209
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
1210
+
1211
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
1212
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
1213
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
1214
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
1215
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopAndRemoveProducts');
1216
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
1217
+
1218
+ $setChildListingProductOptions = $this->getUrl(
1219
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setChildListingProductOptions');
1220
+
1221
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
1222
+ $taskCompletedSuccessMessage = $helper->escapeJs(
1223
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
1224
+ );
1225
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
1226
+ '"%task_title%" Task has completed with warnings.
1227
+ <a target="_blank" href="%url%">View Log</a> for details.'
1228
+ ));
1229
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
1230
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
1231
+ ));
1232
+
1233
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
1234
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
1235
+ 'Sending %product_title% Product(s) data on Amazon.'
1236
+ ));
1237
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
1238
+
1239
+ $listingLockedMessage = $helper->escapeJs(
1240
+ $helper->__('The Listing was locked by another process. Please try again later.')
1241
+ );
1242
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
1243
+
1244
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1245
+ ->__('Listing All Items On Amazon'));
1246
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1247
+ ->__('Listing Selected Items On Amazon'));
1248
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1249
+ ->__('Revising Selected Items On Amazon'));
1250
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1251
+ ->__('Relisting Selected Items On Amazon'));
1252
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
1253
+ ->__('Stopping Selected Items On Amazon'));
1254
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
1255
+ ->escapeJs(Mage::helper('M2ePro')
1256
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
1257
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
1258
+ ->escapeJs(Mage::helper('M2ePro')
1259
+ ->__('Removing From Amazon And Listing Selected Items'));
1260
+
1261
+ $selectItemsMessage = $helper->escapeJs($helper->__('Please select Items.'));
1262
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
1263
+
1264
+ $errorChangingProductOptions = $helper->escapeJs($helper->__('Please Select Product Options.'));
1265
+
1266
+ $successWord = $helper->escapeJs($helper->__('Success'));
1267
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
1268
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
1269
+ $errorWord = $helper->escapeJs($helper->__('Error'));
1270
+ $closeWord = $helper->escapeJs($helper->__('Close'));
1271
+ $confirmWord = $helper->escapeJs($helper->__('Confirm'));
1272
+ $cancelWord = $helper->escapeJs($helper->__('Cancel'));
1273
+
1274
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
1275
+
1276
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
1277
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
1278
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
1279
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
1280
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
1281
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy for Products'));
1282
+
1283
+ $getAFNQtyBySku = $this->getUrl('*/adminhtml_common_amazon_listing/getAFNQtyBySku');
1284
+
1285
+ $generalId = $this->getListingProduct()->getGeneralId();
1286
+ $hideMassAction = empty($generalId) ?
1287
+ '$(\'amazonVariationProductManageGrid_massaction-form\').hide();' : '';
1288
+
1289
+ $javascriptMain = <<<HTML
1290
+ <script type="text/javascript">
1291
+
1292
+ if (typeof M2ePro == 'undefined') {
1293
+ M2ePro = {};
1294
+ M2ePro.url = {};
1295
+ M2ePro.formData = {};
1296
+ M2ePro.customData = {};
1297
+ M2ePro.text = {};
1298
+ }
1299
+
1300
+ M2ePro.url.add({$urls});
1301
+
1302
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
1303
+
1304
+ M2ePro.url.checkLockListing = '{$checkLockListing}';
1305
+ M2ePro.url.lockListingNow = '{$lockListingNow}';
1306
+ M2ePro.url.unlockListingNow = '{$unlockListingNow}';
1307
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
1308
+
1309
+ M2ePro.url.runListProducts = '{$runListProducts}';
1310
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
1311
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
1312
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
1313
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
1314
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
1315
+ M2ePro.url.setChildListingProductOptions = '{$setChildListingProductOptions}';
1316
+
1317
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
1318
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
1319
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
1320
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
1321
+
1322
+ M2ePro.url.getAFNQtyBySku = '{$getAFNQtyBySku}';
1323
+
1324
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
1325
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
1326
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
1327
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
1328
+
1329
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
1330
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
1331
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
1332
+
1333
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
1334
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
1335
+
1336
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
1337
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
1338
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
1339
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
1340
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
1341
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
1342
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
1343
+
1344
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
1345
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
1346
+
1347
+ M2ePro.text.error_changing_product_options = '{$errorChangingProductOptions}';
1348
+
1349
+ M2ePro.text.success_word = '{$successWord}';
1350
+ M2ePro.text.notice_word = '{$noticeWord}';
1351
+ M2ePro.text.warning_word = '{$warningWord}';
1352
+ M2ePro.text.error_word = '{$errorWord}';
1353
+ M2ePro.text.close_word = '{$closeWord}';
1354
+ M2ePro.text.confirm_word = '{$confirmWord}';
1355
+ M2ePro.text.cancel_word = '{$cancelWord}';
1356
+
1357
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
1358
+
1359
+ M2ePro.text.confirm = '{$textConfirm}';
1360
+
1361
+ M2ePro.customData.componentMode = '{$component}';
1362
+ M2ePro.customData.gridId = 'amazonVariationProductManageGrid';
1363
+
1364
+ // fix for tool tip position in iframe
1365
+ MagentoFieldTip.prototype.changeToolTipPosition = function(element)
1366
+ {
1367
+ var toolTip = element.up().select('.tool-tip-message')[0];
1368
+
1369
+ var settings = {
1370
+ setHeight: false,
1371
+ setWidth: false,
1372
+ setLeft: true,
1373
+ offsetTop: 25,
1374
+ offsetLeft: -20
1375
+ };
1376
+
1377
+ if (element.up().getStyle('float') == 'right') {
1378
+ settings.offsetLeft += 18;
1379
+ }
1380
+ if (element.up().match('span')) {
1381
+ settings.offsetLeft += 15;
1382
+ }
1383
+
1384
+ toolTip.clonePosition(element, settings);
1385
+
1386
+ if (toolTip.hasClassName('tip-left')) {
1387
+ toolTip.style.left = (parseInt(toolTip.style.left) - toolTip.getWidth() - 10) + 'px';
1388
+ }
1389
+ };
1390
+
1391
+ Event.observe(window, 'load', function() {
1392
+
1393
+ CommonHandler.prototype.scroll_page_to_top = function() { return; }
1394
+
1395
+ ListingGridHandlerObj = new CommonAmazonListingVariationProductManageVariationsGridHandler(
1396
+ 'amazonVariationProductManageGrid',
1397
+ {$listingId}
1398
+ );
1399
+
1400
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
1401
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
1402
+
1403
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
1404
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
1405
+
1406
+ CommonAmazonListingAfnQtyHandlerObj = new CommonAmazonListingAfnQtyHandler();
1407
+
1408
+ setTimeout(function() {
1409
+ ListingGridHandlerObj.afterInitPage();
1410
+ }, 350);
1411
+ });
1412
+
1413
+ if (typeof ListingGridHandlerObj != 'undefined') {
1414
+ ListingGridHandlerObj.afterInitPage();
1415
+ }
1416
+
1417
+ {$hideMassAction}
1418
+
1419
+ </script>
1420
+ HTML;
1421
+
1422
+ $additionalCss = <<<HTML
1423
+ <style>
1424
+ body {
1425
+ background: none;
1426
+ }
1427
+
1428
+ .wrapper {
1429
+ min-width: inherit;
1430
+ }
1431
+
1432
+ .footer {
1433
+ display: none;
1434
+ }
1435
+
1436
+ .middle {
1437
+ padding: 0px;
1438
+ background: none;
1439
+ }
1440
+
1441
+ td.help_line .hl_close {
1442
+ margin-top: -6px;
1443
+ }
1444
+
1445
+ td.help_line .hl_header {
1446
+ padding: 0 0 10px !important;
1447
+ }
1448
+
1449
+ </style>
1450
+ HTML;
1451
+
1452
+ return '<div id="messages"></div>' .
1453
+ '<div id="listing_view_progress_bar"></div>' .
1454
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
1455
+ '<div id="listing_view_content_container">'.
1456
+ parent::_toHtml() .
1457
+ '</div>' . $javascriptMain . $additionalCss;
1458
+ }
1459
+
1460
+ //########################################
1461
+
1462
+ private function canChangeProductVariation(Ess_M2ePro_Model_Listing_Product $childListingProduct)
1463
+ {
1464
+ if (!$this->hasUnusedProductVariation()) {
1465
+ return false;
1466
+ }
1467
+
1468
+ $lockData = $this->getLockedData($childListingProduct);
1469
+ if ($lockData['in_action']) {
1470
+ return false;
1471
+ }
1472
+
1473
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonChildListingProduct */
1474
+ $amazonChildListingProduct = $childListingProduct->getChildObject();
1475
+
1476
+ if (!$amazonChildListingProduct->getGeneralId()) {
1477
+ return false;
1478
+ }
1479
+
1480
+ $childTypeModel = $amazonChildListingProduct->getVariationManager()->getTypeModel();
1481
+
1482
+ if ($childTypeModel->isVariationProductMatched() && $this->hasChildWithEmptyProductOptions()) {
1483
+ return false;
1484
+ }
1485
+
1486
+ return true;
1487
+ }
1488
+
1489
+ private function getLockedData($row)
1490
+ {
1491
+ $listingProductId = $row->getData('id');
1492
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1493
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
1494
+ $tempArray = array(
1495
+ 'object_locks' => $objectLocks,
1496
+ 'in_action' => !empty($objectLocks),
1497
+ );
1498
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1499
+ }
1500
+
1501
+ return $this->lockedDataCache[$listingProductId];
1502
+ }
1503
+
1504
+ //########################################
1505
+
1506
+ protected function getTemplateDescriptionLinkHtml($listingProduct)
1507
+ {
1508
+ $templateDescriptionEditUrl = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
1509
+ 'id' => $listingProduct->getChildObject()->getTemplateDescriptionId()
1510
+ ));
1511
+
1512
+ $helper = Mage::helper('M2ePro');
1513
+ $templateTitle = $listingProduct->getChildObject()->getDescriptionTemplate()->getTitle();
1514
+
1515
+ return <<<HTML
1516
+ <span style="font-size: 9px;">{$helper->__('Description Title')}:&nbsp;
1517
+ <a target="_blank" href="{$templateDescriptionEditUrl}">
1518
+ {$helper->escapeHtml($templateTitle)}</a>
1519
+ </span>
1520
+ <br/>
1521
+ HTML;
1522
+ }
1523
+
1524
+ //########################################
1525
+
1526
+ public function getProductVariationsTree($childProduct)
1527
+ {
1528
+ $unusedVariations = $this->getUnusedProductVariations();
1529
+
1530
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel */
1531
+ $childTypeModel = $childProduct->getChildObject()->getVariationManager()->getTypeModel();
1532
+
1533
+ if ($childTypeModel->isVariationProductMatched()) {
1534
+ $unusedVariations[] = $childTypeModel->getProductOptions();
1535
+ }
1536
+
1537
+ $variationsSets = $this->getAttributesVariationsSets($unusedVariations);
1538
+ $firstAttribute = key($variationsSets);
1539
+
1540
+ return $this->prepareVariations($firstAttribute,$unusedVariations,$variationsSets);
1541
+ }
1542
+
1543
+ private function prepareVariations($currentAttribute,$unusedVariations,$variationsSets,$filters = array())
1544
+ {
1545
+ $return = false;
1546
+
1547
+ $temp = array_flip(array_keys($variationsSets));
1548
+
1549
+ $lastAttributePosition = count($variationsSets) - 1;
1550
+ $currentAttributePosition = $temp[$currentAttribute];
1551
+
1552
+ if ($currentAttributePosition != $lastAttributePosition) {
1553
+
1554
+ $temp = array_keys($variationsSets);
1555
+ $nextAttribute = $temp[$currentAttributePosition + 1];
1556
+
1557
+ foreach ($variationsSets[$currentAttribute] as $option) {
1558
+
1559
+ $filters[$currentAttribute] = $option;
1560
+
1561
+ $result = $this->prepareVariations(
1562
+ $nextAttribute,$unusedVariations,$variationsSets,$filters
1563
+ );
1564
+
1565
+ if (!$result) {
1566
+ continue;
1567
+ }
1568
+
1569
+ $return[$currentAttribute][$option] = $result;
1570
+ }
1571
+
1572
+ ksort($return[$currentAttribute]);
1573
+
1574
+ return $return;
1575
+ }
1576
+
1577
+ $return = false;
1578
+ foreach ($unusedVariations as $key => $magentoVariation) {
1579
+ foreach ($magentoVariation as $attribute => $option) {
1580
+
1581
+ if ($attribute == $currentAttribute) {
1582
+
1583
+ if (count($variationsSets) != 1) {
1584
+ continue;
1585
+ }
1586
+
1587
+ $values = array_flip($variationsSets[$currentAttribute]);
1588
+ $return = array($currentAttribute => $values);
1589
+
1590
+ foreach ($return[$currentAttribute] as &$option) {
1591
+ $option = true;
1592
+ }
1593
+
1594
+ return $return;
1595
+ }
1596
+
1597
+ if ($option != $filters[$attribute]) {
1598
+ unset($unusedVariations[$key]);
1599
+ continue;
1600
+ }
1601
+
1602
+ foreach ($magentoVariation as $tempAttribute => $tempOption) {
1603
+ if ($tempAttribute == $currentAttribute) {
1604
+ $option = $tempOption;
1605
+ $return[$currentAttribute][$option] = true;
1606
+ }
1607
+ }
1608
+ }
1609
+ }
1610
+
1611
+ if (count($unusedVariations) < 1) {
1612
+ return false;
1613
+ }
1614
+
1615
+ ksort($return[$currentAttribute]);
1616
+
1617
+ return $return;
1618
+ }
1619
+
1620
+ //########################################
1621
+
1622
+ public function getCurrentProductVariations()
1623
+ {
1624
+
1625
+ if (!is_null($this->currentProductVariations)) {
1626
+ return $this->currentProductVariations;
1627
+ }
1628
+
1629
+ $magentoProductVariations = $this->getListingProduct()
1630
+ ->getMagentoProduct()
1631
+ ->getVariationInstance()
1632
+ ->getVariationsTypeStandard();
1633
+
1634
+ $productVariations = array();
1635
+
1636
+ foreach ($magentoProductVariations['variations'] as $option) {
1637
+ $productOption = array();
1638
+
1639
+ foreach ($option as $attribute) {
1640
+ $productOption[$attribute['attribute']] = $attribute['option'];
1641
+ }
1642
+
1643
+ $productVariations[] = $productOption;
1644
+ }
1645
+
1646
+ return $this->currentProductVariations = $productVariations;
1647
+ }
1648
+
1649
+ public function getUsedProductVariations()
1650
+ {
1651
+ if (is_null($this->usedProductVariations)) {
1652
+
1653
+ $usedOptions = array();
1654
+
1655
+ foreach ($this->getChildListingProducts() as $childListingProduct) {
1656
+ /** @var Ess_M2ePro_Model_Listing_Product $childListingProduct */
1657
+
1658
+ /**
1659
+ * @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $childTypeModel
1660
+ */
1661
+ $childTypeModel = $childListingProduct->getChildObject()->getVariationManager()->getTypeModel();
1662
+
1663
+ if (!$childTypeModel->isVariationProductMatched()) {
1664
+ continue;
1665
+ }
1666
+
1667
+ $usedOptions[] = $childTypeModel->getProductOptions();
1668
+ }
1669
+
1670
+ $this->usedProductVariations = $usedOptions;
1671
+ }
1672
+
1673
+ return $this->usedProductVariations;
1674
+ }
1675
+
1676
+ //########################################
1677
+
1678
+ public function getUnusedProductVariations()
1679
+ {
1680
+ return $this->getUnusedVariations($this->getCurrentProductVariations(), $this->getUsedProductVariations());
1681
+ }
1682
+
1683
+ private function getUnusedVariations($currentVariations, $usedVariations)
1684
+ {
1685
+ if (empty($currentVariations)) {
1686
+ return array();
1687
+ }
1688
+
1689
+ if (empty($usedVariations)) {
1690
+ return $currentVariations;
1691
+ }
1692
+
1693
+ $unusedOptions = array();
1694
+
1695
+ foreach ($currentVariations as $id => $currentOption) {
1696
+ if ($this->isVariationExistsInArray($currentOption, $usedVariations)) {
1697
+ continue;
1698
+ }
1699
+
1700
+ $unusedOptions[$id] = $currentOption;
1701
+ }
1702
+
1703
+ return $unusedOptions;
1704
+ }
1705
+
1706
+ private function isVariationExistsInArray(array $needle, array $haystack)
1707
+ {
1708
+ foreach ($haystack as $option) {
1709
+ if ($option != $needle) {
1710
+ continue;
1711
+ }
1712
+
1713
+ return true;
1714
+ }
1715
+
1716
+ return false;
1717
+ }
1718
+
1719
+ //########################################
1720
+
1721
+ public function getChildListingProducts()
1722
+ {
1723
+ if (!is_null($this->childListingProducts)) {
1724
+ return $this->childListingProducts;
1725
+ }
1726
+
1727
+ return $this->childListingProducts = $this->getListingProduct()->getChildObject()
1728
+ ->getVariationManager()->getTypeModel()->getChildListingsProducts();
1729
+ }
1730
+
1731
+ public function getAttributesVariationsSets($variations)
1732
+ {
1733
+ $attributesOptions = array();
1734
+
1735
+ foreach ($variations as $variation) {
1736
+ foreach ($variation as $attr => $option) {
1737
+ if (!isset($attributesOptions[$attr])) {
1738
+ $attributesOptions[$attr] = array();
1739
+ }
1740
+ if (!in_array($option, $attributesOptions[$attr])) {
1741
+ $attributesOptions[$attr][] = $option;
1742
+ }
1743
+ }
1744
+ }
1745
+
1746
+ ksort($attributesOptions);
1747
+
1748
+ return $attributesOptions;
1749
+ }
1750
+
1751
+ //########################################
1752
+
1753
+ protected function getGeneralIdLink($generalId)
1754
+ {
1755
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1756
+ $generalId,
1757
+ $this->getListingProduct()->getListing()->getMarketplaceId()
1758
+ );
1759
+
1760
+ return <<<HTML
1761
+ <a href="{$url}" target="_blank" title="{$generalId}" >{$generalId}</a>
1762
+ HTML;
1763
+ }
1764
+
1765
+ //########################################
1766
+
1767
+ private function parseGroupedData($data)
1768
+ {
1769
+ $result = array();
1770
+
1771
+ if (empty($data)) {
1772
+ return $result;
1773
+ }
1774
+
1775
+ $variationData = explode('||', $data);
1776
+ foreach ($variationData as $variationAttribute) {
1777
+ $value = explode('==', $variationAttribute);
1778
+ $result[$value[0]] = $value[1];
1779
+ }
1780
+
1781
+ return $result;
1782
+ }
1783
+
1784
+ //########################################
1785
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Variations/Help.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Variations_Help
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonListingViewHelp');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/variations/help.phtml');
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/Manage/Tabs/Vocabulary.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_Manage_Tabs_Vocabulary
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ protected $listingProductId;
13
+
14
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
15
+ protected $listingProduct;
16
+
17
+ //########################################
18
+
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/manage/tabs/vocabulary.phtml');
24
+
25
+ return $this;
26
+ }
27
+
28
+ //########################################
29
+
30
+ /**
31
+ * @param mixed $listingProductId
32
+ * @return $this
33
+ */
34
+ public function setListingProductId($listingProductId)
35
+ {
36
+ $this->listingProductId = $listingProductId;
37
+
38
+ return $this;
39
+ }
40
+ /**
41
+ * @return mixed
42
+ */
43
+ public function getListingProductId()
44
+ {
45
+ return $this->listingProductId;
46
+ }
47
+
48
+ // ---------------------------------------
49
+
50
+ /**
51
+ * @return Ess_M2ePro_Model_Listing_Product|null
52
+ */
53
+ public function getListingProduct()
54
+ {
55
+ if (is_null($this->listingProduct)) {
56
+ $this->listingProduct = Mage::helper('M2ePro/Component_Amazon')
57
+ ->getObject('Listing_Product', $this->getListingProductId());
58
+ }
59
+
60
+ return $this->listingProduct;
61
+ }
62
+
63
+ //########################################
64
+
65
+ public function prepareData()
66
+ {
67
+ $localVocabulary = array();
68
+ $fixedAttributes = array();
69
+ $matchedAttributes = $this->getListingProduct()->getChildObject()
70
+ ->getVariationManager()->getTypeModel()->getMatchedAttributes();
71
+ $magentoProductVariations = $this->getListingProduct()
72
+ ->getMagentoProduct()
73
+ ->getVariationInstance()
74
+ ->getVariationsTypeStandard();
75
+
76
+ $vocabularyHelper = Mage::helper('M2ePro/Component_Amazon_Vocabulary');
77
+ $vocabularyData = $vocabularyHelper->getLocalData();
78
+
79
+ if (empty($matchedAttributes)) {
80
+ return array(
81
+ 'local_vocabulary' => $localVocabulary,
82
+ 'fixed_attributes' => $fixedAttributes
83
+ );
84
+ }
85
+
86
+ foreach ($matchedAttributes as $magentoAttr => $channelAttr) {
87
+ foreach ($vocabularyData as $attribute => $attributeData) {
88
+
89
+ if (in_array($magentoAttr, $attributeData['names']) || $attribute == $channelAttr) {
90
+
91
+ if (!in_array($magentoAttr, $attributeData['names'])) {
92
+ $fixedAttributes[$magentoAttr][] = $attribute;
93
+ }
94
+
95
+ $localVocabulary[$magentoAttr][$attribute] = array();
96
+
97
+ if (!empty($attributeData['options'])) {
98
+ foreach ($magentoProductVariations['set'][$magentoAttr] as $magentoOption) {
99
+
100
+ foreach ($attributeData['options'] as $attributeOptions) {
101
+
102
+ if (in_array($magentoOption, $attributeOptions)) {
103
+ $localVocabulary[$magentoAttr][$attribute][$magentoOption][] = $attributeOptions;
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ if (!empty($fixedAttributes[$magentoAttr]) &&
110
+ in_array($attribute, $fixedAttributes[$magentoAttr]) &&
111
+ empty($localVocabulary[$magentoAttr][$attribute])) {
112
+
113
+ unset($localVocabulary[$magentoAttr][$attribute]);
114
+ if (empty($localVocabulary[$magentoAttr])) {
115
+ unset($localVocabulary[$magentoAttr]);
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ return array(
123
+ 'local_vocabulary' => $localVocabulary,
124
+ 'fixed_attributes' => $fixedAttributes
125
+ );
126
+ }
127
+
128
+ //########################################
129
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToIndividualPopup.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_SwitchToIndividualPopup
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonListingAddNewAsinManualPopup');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/switch_to_individual_popup.phtml');
24
+ }
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ parent::_beforeToHtml();
29
+
30
+ $data = array(
31
+ 'class' => 'switch-to-individual-btn',
32
+ 'label' => Mage::helper('M2ePro')->__('Yes')
33
+ );
34
+ $this->setChild(
35
+ 'yes_btn',
36
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
37
+ );
38
+
39
+ $data = array(
40
+ 'class' => 'switch-to-individual-popup-close',
41
+ 'label' => Mage::helper('M2ePro')->__('No')
42
+ );
43
+ $this->setChild(
44
+ 'no_btn',
45
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
46
+ );
47
+
48
+ return $this;
49
+ }
50
+
51
+ //########################################
52
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/SwitchToParentPopup.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_SwitchToParentPopup
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonListingAddNewAsinManualPopup');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/switch_to_parent_popup.phtml');
24
+ }
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ parent::_beforeToHtml();
29
+
30
+ $data = array(
31
+ 'class' => 'switch-to-parent-btn',
32
+ 'label' => Mage::helper('M2ePro')->__('Yes')
33
+ );
34
+ $this->setChild(
35
+ 'yes_btn',
36
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
37
+ );
38
+
39
+ $data = array(
40
+ 'class' => 'switch-to-parent-popup-close',
41
+ 'label' => Mage::helper('M2ePro')->__('No')
42
+ );
43
+ $this->setChild(
44
+ 'no_btn',
45
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
46
+ );
47
+
48
+ return $this;
49
+ }
50
+
51
+ //########################################
52
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyAttributesPopup.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_VocabularyAttributesPopup
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ // ---------------------------------------
18
+ $this->setId('amazonListingVocabularyAttributesPopup');
19
+ // ---------------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/vocabulary_attributes_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
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addAttributesToVocabulary(true)',
32
+ );
33
+ $this->setChild(
34
+ 'yes_btn',
35
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
36
+ );
37
+
38
+ $data = array(
39
+ 'class' => 'switch-to-individual-popup-close',
40
+ 'label' => Mage::helper('M2ePro')->__('No'),
41
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addAttributesToVocabulary(false)',
42
+ );
43
+ $this->setChild(
44
+ 'no_btn',
45
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
46
+ );
47
+
48
+ return $this;
49
+ }
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/Variation/Product/VocabularyOptionsPopup.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_Variation_Product_VocabularyOptionsPopup
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ public function __construct()
13
+ {
14
+ parent::__construct();
15
+
16
+ // Initialization block
17
+ // ---------------------------------------
18
+ $this->setId('amazonListingVocabularyAttributesPopup');
19
+ // ---------------------------------------
20
+
21
+ $this->setTemplate('M2ePro/common/amazon/listing/variation/product/vocabulary_options_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
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addOptionsToVocabulary(true)',
32
+ );
33
+ $this->setChild(
34
+ 'yes_btn',
35
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
36
+ );
37
+
38
+ $data = array(
39
+ 'class' => 'switch-to-individual-popup-close',
40
+ 'label' => Mage::helper('M2ePro')->__('No'),
41
+ 'onclick' => 'AmazonListingVariationProductManageHandlerObj.addOptionsToVocabulary(false)',
42
+ );
43
+ $this->setChild(
44
+ 'no_btn',
45
+ $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data)
46
+ );
47
+
48
+ return $this;
49
+ }
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View.php ADDED
@@ -0,0 +1,827 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ const VIEW_MODE_AMAZON = 'amazon';
12
+ const VIEW_MODE_MAGENTO = 'magento';
13
+ const VIEW_MODE_SELLERCENTRAL = 'sellercentral';
14
+ const VIEW_MODE_SETTINGS = 'settings';
15
+
16
+ const DEFAULT_VIEW_MODE = self::VIEW_MODE_AMAZON;
17
+
18
+ //########################################
19
+
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ // Initialization block
25
+ // ---------------------------------------
26
+ $this->setId('amazonListingView');
27
+ $this->_blockGroup = 'M2ePro';
28
+ $this->_controller = 'adminhtml_common_amazon_listing_view_' . $this->getViewMode();
29
+ // ---------------------------------------
30
+
31
+ // Set header text
32
+ // ---------------------------------------
33
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
34
+
35
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
36
+ $headerText = Mage::helper('M2ePro')->__(
37
+ 'View %component_name% Listing',
38
+ Mage::helper('M2ePro/Component_Amazon')->getTitle()
39
+ );
40
+ } else {
41
+ $headerText = Mage::helper('M2ePro')->__('View Listing ');
42
+ }
43
+
44
+ $this->_headerText = $headerText;
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 = $this->getUrl('*/adminhtml_common_log/listing', array(
59
+ 'id' => $listingData['id'],
60
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON
61
+ ));
62
+ $this->_addButton('view_log', array(
63
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
64
+ 'onclick' => 'window.open(\'' . $url . '\')',
65
+ 'class' => 'button_link'
66
+ ));
67
+ // ---------------------------------------
68
+
69
+ // ---------------------------------------
70
+ $this->_addButton('edit_settings', array(
71
+ 'label' => Mage::helper('M2ePro')->__('Edit Settings'),
72
+ 'onclick' => '',
73
+ 'class' => 'drop_down edit_settings_drop_down'
74
+ ));
75
+ // ---------------------------------------
76
+
77
+ // ---------------------------------------
78
+ $this->_addButton('add_products', array(
79
+ 'label' => Mage::helper('M2ePro')->__('Add Products'),
80
+ 'onclick' => '',
81
+ 'class' => 'add drop_down add_products_drop_down'
82
+ ));
83
+ // ---------------------------------------
84
+ }
85
+
86
+ //########################################
87
+
88
+ public function getViewMode()
89
+ {
90
+ $allowedModes = array(
91
+ self::VIEW_MODE_AMAZON,
92
+ self::VIEW_MODE_SETTINGS,
93
+ self::VIEW_MODE_MAGENTO,
94
+ self::VIEW_MODE_SELLERCENTRAL
95
+ );
96
+ $mode = $this->getParam('view_mode', self::DEFAULT_VIEW_MODE);
97
+
98
+ if (in_array($mode, $allowedModes)) {
99
+ return $mode;
100
+ }
101
+
102
+ return self::DEFAULT_VIEW_MODE;
103
+ }
104
+
105
+ protected function getParam($paramName, $default = NULL)
106
+ {
107
+ $session = Mage::helper('M2ePro/Data_Session');
108
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
109
+ $sessionParamName = $this->getId() . $listingData['id'] . $paramName;
110
+
111
+ if ($this->getRequest()->has($paramName)) {
112
+ $param = $this->getRequest()->getParam($paramName);
113
+ $session->setValue($sessionParamName, $param);
114
+ return $param;
115
+ } elseif ($param = $session->getValue($sessionParamName)) {
116
+ return $param;
117
+ }
118
+
119
+ return $default;
120
+ }
121
+
122
+ //########################################
123
+
124
+ protected function _toHtml()
125
+ {
126
+ return '<div id="listing_view_progress_bar"></div>' .
127
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
128
+ '<div id="listing_view_content_container">'.
129
+ parent::_toHtml() .
130
+ '</div>';
131
+ }
132
+
133
+ public function getGridHtml()
134
+ {
135
+ if ($this->getRequest()->isXmlHttpRequest()) {
136
+ return parent::getGridHtml();
137
+ }
138
+
139
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
140
+
141
+ /** @var $helper Ess_M2ePro_Helper_Data */
142
+ $helper = Mage::helper('M2ePro');
143
+
144
+ // ---------------------------------------
145
+ $urls = $helper->getControllerActions(
146
+ 'adminhtml_common_listing_autoAction', array(
147
+ 'listing_id' => $this->getRequest()->getParam('id'),
148
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK
149
+ )
150
+ );
151
+ $showAutoAction = json_encode((bool)$this->getRequest()->getParam('auto_actions'));
152
+
153
+ $path = 'adminhtml_common_log/listingProduct';
154
+ $urls[$path] = $this->getUrl('*/' . $path, array(
155
+ 'channel' => Ess_M2ePro_Helper_Component_Amazon::NICK,
156
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',array(
157
+ 'id' => $listingData['id']
158
+ ))
159
+ ));
160
+
161
+ $path = 'adminhtml_common_listing/duplicateProducts';
162
+ $urls[$path] = $this->getUrl('*/' . $path);
163
+
164
+ $urls = array_merge($urls, Mage::helper('M2ePro')->getControllerActions(
165
+ 'adminhtml_common_amazon_listing_repricing',
166
+ array(
167
+ 'id' => $listingData['id'],
168
+ 'account_id' => $listingData['account_id']
169
+ )
170
+ ));
171
+
172
+ $urls = json_encode($urls);
173
+ // ---------------------------------------
174
+
175
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
176
+
177
+ $temp = Mage::helper('M2ePro/Data_Session')->getValue('products_ids_for_list', true);
178
+ $productsIdsForList = empty($temp) ? '' : $temp;
179
+
180
+ $gridId = $this->getChild('grid')->getId();
181
+ $ignoreListings = json_encode(array($listingData['id']));
182
+
183
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
184
+ $marketplaceInstance = Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Marketplace',$marketplaceId);
185
+ $marketplace = json_encode($marketplaceInstance->getData());
186
+ $isNewAsinAvailable = json_encode($marketplaceInstance->getChildObject()->isNewAsinAvailable());
187
+
188
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing',array(
189
+ 'id' => $listingData['id'],
190
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_AMAZON,
191
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_amazon_listing/view',
192
+ array('id' =>$listingData['id']))
193
+ ));
194
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
195
+
196
+ $runListProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runListProducts');
197
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runReviseProducts');
198
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runRelistProducts');
199
+ $runStopProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopProducts');
200
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runStopAndRemoveProducts');
201
+ $runDeleteAndRemoveProducts = $this->getUrl('*/adminhtml_common_amazon_listing/runDeleteAndRemoveProducts');
202
+
203
+ $prepareData = $this->getUrl('*/adminhtml_listing_moving/prepareMoveToListing');
204
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_moving/moveToListingGrid');
205
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_moving/getFailedProductsGrid');
206
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_moving/tryToMoveToListing');
207
+ $moveToListing = $this->getUrl('*/adminhtml_listing_moving/moveToListing');
208
+
209
+ $marketplaceSynchUrl = $this->getUrl(
210
+ '*/adminhtml_common_marketplace/index',
211
+ array('tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON)
212
+ );
213
+
214
+ $getVariationEditPopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationEditPopup');
215
+ $getVariationManagePopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationManagePopup');
216
+
217
+ $variationEditActionUrl = $this->getUrl('*/adminhtml_common_listing/variationEdit');
218
+ $variationManageActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManage');
219
+ $variationManageGenerateActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManageGenerate');
220
+ $variationResetActionUrl = $this->getUrl('*/adminhtml_common_listing/variationReset');
221
+
222
+ $saveListingAdditionalDataActionUrl = $this->getUrl('*/adminhtml_listing/saveListingAdditionalData', array(
223
+ 'id' => $listingData['id']
224
+ ));
225
+
226
+ $popupTitle = $helper->escapeJs($helper->__('Moving Amazon Items'));
227
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Amazon Item'));
228
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
229
+
230
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
231
+ $taskCompletedSuccessMessage = $helper->escapeJs(
232
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
233
+ );
234
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
235
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
236
+ ));
237
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
238
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
239
+ ));
240
+
241
+ $lockedObjNoticeMessage = $helper->escapeJs($helper->__('Some Amazon request(s) are being processed now.'));
242
+ $sendingDataToAmazonMessage = $helper->escapeJs($helper->__(
243
+ 'Sending %product_title% Product(s) data on Amazon.')
244
+ );
245
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
246
+
247
+ $listingLockedMessage = $helper->escapeJs(
248
+ $helper->__('The Listing was locked by another process. Please try again later.')
249
+ );
250
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
251
+
252
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
253
+ ->__('Listing All Items On Amazon'));
254
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
255
+ ->__('Listing Selected Items On Amazon'));
256
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
257
+ ->__('Revising Selected Items On Amazon'));
258
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
259
+ ->__('Relisting Selected Items On Amazon'));
260
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
261
+ ->__('Stopping Selected Items On Amazon'));
262
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
263
+ ->escapeJs(Mage::helper('M2ePro')
264
+ ->__('Stopping On Amazon And Removing From Listing Selected Items'));
265
+ $deletingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
266
+ ->escapeJs(Mage::helper('M2ePro')
267
+ ->__('Removing From Amazon And Listing Selected Items'));
268
+
269
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
270
+ $productsWereNotMovedMessage = $helper->escapeJs(
271
+ $helper->__('Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
272
+ );
273
+ $someProductsWereNotMovedMessage = $helper->escapeJs(
274
+ $helper->__('Some Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
275
+ );
276
+
277
+ $selectItemsMessage = $helper->escapeJs(
278
+ $helper->__('Please select the Products you want to perform the Action on.')
279
+ );
280
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
281
+
282
+ $successWord = $helper->escapeJs($helper->__('Success'));
283
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
284
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
285
+ $errorWord = $helper->escapeJs($helper->__('Error'));
286
+ $closeWord = $helper->escapeJs($helper->__('Close'));
287
+
288
+ $assignString = Mage::helper('M2ePro')->__('Assign');
289
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
290
+
291
+ $searchAsinManual = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinManual');
292
+ $getSearchAsinMenu = $this->getUrl('*/adminhtml_common_amazon_listing/getSearchAsinMenu');
293
+ $suggestedAsinGridHmtl = $this->getUrl('*/adminhtml_common_amazon_listing/getSuggestedAsinGrid');
294
+ $getCategoriesByAsin = $this->getUrl('*/adminhtml_common_amazon_listing/getCategoriesByAsin');
295
+ $searchAsinAuto = $this->getUrl('*/adminhtml_common_amazon_listing/searchAsinAuto');
296
+ $getProductsSearchStatus = $this->getUrl('*/adminhtml_common_amazon_listing/getProductsSearchStatus');
297
+ $mapToAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToAsin');
298
+ $unmapFromAsin = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromAsin');
299
+ $mapToNewAsin = $this->getUrl('*/adminhtml_common_amazon_listing/mapToNewAsin');
300
+
301
+ $switchToAFN = $this->getUrl('*/adminhtml_common_amazon_listing/switchToAFN');
302
+ $switchToMFN = $this->getUrl('*/adminhtml_common_amazon_listing/switchToMFN');
303
+
304
+ $getAFNQtyBySku = $this->getUrl('*/adminhtml_common_amazon_listing/getAFNQtyBySku');
305
+
306
+ $variationProductManage = $this->getUrl(
307
+ '*/adminhtml_common_amazon_listing_variation_product_manage/index');
308
+ $variationProductSetGeneralIdOwner = $this->getUrl(
309
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setGeneralIdOwner');
310
+ $variationProductSetVariationTheme = $this->getUrl(
311
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setVariationTheme');
312
+ $variationProductSetMatchedAttributes = $this->getUrl(
313
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setMatchedAttributes');
314
+ $variationProductSetListingProductSku = $this->getUrl(
315
+ '*/adminhtml_common_amazon_listing_variation_product_manage/setListingProductSku');
316
+ $manageVariationViewTemplateDescriptionsGrid = $this->getUrl(
317
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewTemplateDescriptionsGrid');
318
+ $manageVariationMapToTemplateDescription = $this->getUrl(
319
+ '*/adminhtml_common_amazon_listing_variation_product_manage/mapToTemplateDescription');
320
+ $addAttributesToVocabularyUrl = $this->getUrl(
321
+ '*/adminhtml_common_amazon_listing_variation_product_manage/addAttributesToVocabulary'
322
+ );
323
+ $addOptionsToVocabularyUrl = $this->getUrl(
324
+ '*/adminhtml_common_amazon_listing_variation_product_manage/addOptionsToVocabulary'
325
+ );
326
+
327
+ $viewVocabularyAjax = $this->getUrl(
328
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewVocabularyAjax'
329
+ );
330
+ $saveAutoActionSettings = $this->getUrl(
331
+ '*/adminhtml_common_amazon_listing_variation_product_manage/saveAutoActionSettings'
332
+ );
333
+ $removeAttributeFromVocabulary = $this->getUrl(
334
+ '*/adminhtml_common_amazon_listing_variation_product_manage/removeAttributeFromVocabulary'
335
+ );
336
+ $removeOptionFromVocabulary = $this->getUrl(
337
+ '*/adminhtml_common_amazon_listing_variation_product_manage/removeOptionFromVocabulary'
338
+ );
339
+
340
+ $viewVariationsSettingsAjax = $this->getUrl(
341
+ '*/adminhtml_common_amazon_listing_variation_product_manage/viewVariationsSettingsAjax');
342
+
343
+ $newAsinUrl = $this->getUrl('*/adminhtml_common_amazon_template_newProduct',array(
344
+ 'marketplace_id' => Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id'),
345
+ ));
346
+
347
+ $mapToTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/mapToTemplateDescription');
348
+ $unmapFromTemplateDescription = $this->getUrl('*/adminhtml_common_amazon_listing/unmapFromTemplateDescription');
349
+ $validateProductsForTemplateDescriptionAssign = $this->getUrl(
350
+ '*/adminhtml_common_amazon_listing/validateProductsForTemplateDescriptionAssign');
351
+ $viewTemplateDescriptionsGrid = $this->getUrl('*/adminhtml_common_amazon_listing/viewTemplateDescriptionsGrid');
352
+ $templateDescriptionPopupTitle = $helper->escapeJs($helper->__('Assign Description Policy'));
353
+
354
+ $assignShippingOverrideTemplate = $this->getUrl(
355
+ '*/adminhtml_common_amazon_listing/assignShippingOverrideTemplate'
356
+ );
357
+ $unmapFromTemplateShippingOverride = $this->getUrl(
358
+ '*/adminhtml_common_amazon_listing/unassignShippingOverrideTemplate'
359
+ );
360
+ $viewTemplateShippingOverridePopup = $this->getUrl(
361
+ '*/adminhtml_common_amazon_listing/viewTemplateShippingOverridePopup'
362
+ );
363
+ $viewTemplateShippingOverrideGrid = $this->getUrl(
364
+ '*/adminhtml_common_amazon_listing/viewTemplateShippingOverrideGrid'
365
+ );
366
+
367
+ $templateShippingOverridePopupTitle = $helper->escapeJs($helper->__('Assign Shipping Override Policy'));
368
+
369
+ $enterProductSearchQueryMessage = $helper->escapeJs(
370
+ $helper->__('Please enter Product Title or ASIN/ISBN/UPC/EAN.')
371
+ );
372
+ $autoMapAsinSearchProducts = $helper->escapeJs($helper->__('Search %product_title% Product(s) on Amazon.'));
373
+ $autoMapAsinProgressTitle = $helper->escapeJs($helper->__('Automatic Assigning ASIN/ISBN to Item(s)'));
374
+ $autoMapAsinErrorMessage = $helper->escapeJs(
375
+ $helper->__('Server is currently unavailable. Please try again later.')
376
+ );
377
+ $newAsinNotAvailable = $helper->escapeJs(
378
+ $helper->__('The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.')
379
+ );
380
+ $notSynchronizedMarketplace = $helper->escapeJs(
381
+ $helper->__(
382
+ 'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
383
+ ).' '.
384
+ $helper->__(
385
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
386
+ )
387
+ );
388
+
389
+ $noVariationsLeftText = $helper->__('All variations are already added.');
390
+
391
+ $notSet = $helper->__('Not Set');
392
+ $setAttributes = $helper->__('Set Attributes');
393
+ $variationManageMatchedAttributesError = $helper->__('Please choose valid Attributes.');
394
+ $variationManageMatchedAttributesErrorDuplicateSelection =
395
+ $helper->__('You can not choose the same Attribute twice.');
396
+
397
+ $variationManageSkuPopUpTitle =
398
+ $helper->__('Enter Amazon Parent Product SKU');
399
+
400
+ $switchToIndividualModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
401
+ $switchToParentModePopUpTitle = $helper->__('Change "Manage Variations" Mode');
402
+
403
+ $emptySkuError = $helper->escapeJs($helper->__('Please enter Amazon Parent Product SKU.'));
404
+
405
+ $translations = json_encode(array(
406
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
407
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
408
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
409
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
410
+ ));
411
+
412
+ $javascriptsMain = <<<HTML
413
+ <script type="text/javascript">
414
+
415
+ if (typeof M2ePro == 'undefined') {
416
+ M2ePro = {};
417
+ M2ePro.url = {};
418
+ M2ePro.formData = {};
419
+ M2ePro.customData = {};
420
+ M2ePro.text = {};
421
+ }
422
+
423
+ M2ePro.url.add({$urls});
424
+ M2ePro.translator.add({$translations});
425
+
426
+ M2ePro.productsIdsForList = '{$productsIdsForList}';
427
+
428
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
429
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
430
+
431
+ M2ePro.url.runListProducts = '{$runListProducts}';
432
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
433
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
434
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
435
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
436
+ M2ePro.url.runDeleteAndRemoveProducts = '{$runDeleteAndRemoveProducts}';
437
+
438
+ M2ePro.url.searchAsinManual = '{$searchAsinManual}';
439
+ M2ePro.url.getSearchAsinMenu = '{$getSearchAsinMenu}';
440
+ M2ePro.url.searchAsinAuto = '{$searchAsinAuto}';
441
+ M2ePro.url.getProductsSearchStatus = '{$getProductsSearchStatus}';
442
+ M2ePro.url.suggestedAsinGrid = '{$suggestedAsinGridHmtl}';
443
+ M2ePro.url.getCategoriesByAsin = '{$getCategoriesByAsin}';
444
+ M2ePro.url.mapToAsin = '{$mapToAsin}';
445
+ M2ePro.url.unmapFromAsin = '{$unmapFromAsin}';
446
+ M2ePro.url.mapToNewAsin = '{$mapToNewAsin}';
447
+
448
+ M2ePro.url.switchToAFN = '{$switchToAFN}';
449
+ M2ePro.url.switchToMFN = '{$switchToMFN}';
450
+
451
+ M2ePro.url.getAFNQtyBySku = '{$getAFNQtyBySku}';
452
+
453
+ M2ePro.url.variationProductManage = '{$variationProductManage}';
454
+ M2ePro.url.variationProductSetGeneralIdOwner = '{$variationProductSetGeneralIdOwner}';
455
+ M2ePro.url.variationProductSetVariationTheme = '{$variationProductSetVariationTheme}';
456
+ M2ePro.url.variationProductSetMatchedAttributes = '{$variationProductSetMatchedAttributes}';
457
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
458
+ M2ePro.url.variationProductSetListingProductSku = '{$variationProductSetListingProductSku}';
459
+ M2ePro.url.manageVariationViewTemplateDescriptionsGrid = '{$manageVariationViewTemplateDescriptionsGrid}';
460
+ M2ePro.url.manageVariationMapToTemplateDescription = '{$manageVariationMapToTemplateDescription}';
461
+ M2ePro.url.viewVariationsSettingsAjax = '{$viewVariationsSettingsAjax}';
462
+ M2ePro.url.addAttributesToVocabulary = '{$addAttributesToVocabularyUrl}';
463
+ M2ePro.url.addOptionsToVocabulary = '{$addOptionsToVocabularyUrl}';
464
+ M2ePro.url.viewVocabularyAjax = '{$viewVocabularyAjax}';
465
+ M2ePro.url.saveAutoActionSettings = '{$saveAutoActionSettings}';
466
+ M2ePro.url.removeAttributeFromVocabulary = '{$removeAttributeFromVocabulary}';
467
+ M2ePro.url.removeOptionFromVocabulary = '{$removeOptionFromVocabulary}';
468
+
469
+ M2ePro.url.newAsin = '{$newAsinUrl}';
470
+
471
+ M2ePro.url.mapToTemplateDescription = '{$mapToTemplateDescription}';
472
+ M2ePro.url.unmapFromTemplateDescription = '{$unmapFromTemplateDescription}';
473
+ M2ePro.url.validateProductsForTemplateDescriptionAssign = '{$validateProductsForTemplateDescriptionAssign}';
474
+ M2ePro.url.viewTemplateDescriptionsGrid = '{$viewTemplateDescriptionsGrid}';
475
+
476
+ M2ePro.url.assignShippingOverrideTemplate = '{$assignShippingOverrideTemplate}';
477
+ M2ePro.url.unassignShippingOverrideTemplate = '{$unmapFromTemplateShippingOverride}';
478
+ M2ePro.url.viewTemplateShippingOverridePopup = '{$viewTemplateShippingOverridePopup}';
479
+ M2ePro.url.viewTemplateShippingOverrideGrid = '{$viewTemplateShippingOverrideGrid}';
480
+
481
+ M2ePro.url.prepareData = '{$prepareData}';
482
+ M2ePro.url.getGridHtml = '{$getMoveToListingGridHtml}';
483
+ M2ePro.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
484
+ M2ePro.url.tryToMoveToListing = '{$tryToMoveToListing}';
485
+ M2ePro.url.moveToListing = '{$moveToListing}';
486
+
487
+ M2ePro.url.marketplace_synch = '{$marketplaceSynchUrl}';
488
+
489
+ M2ePro.url.get_variation_edit_popup = '{$getVariationEditPopupUrl}';
490
+ M2ePro.url.get_variation_manage_popup = '{$getVariationManagePopupUrl}';
491
+
492
+ M2ePro.url.variation_edit_action = '{$variationEditActionUrl}';
493
+ M2ePro.url.variation_manage_action = '{$variationManageActionUrl}';
494
+ M2ePro.url.variation_manage_generate_action = '{$variationManageGenerateActionUrl}';
495
+ M2ePro.url.variation_reset_action = '{$variationResetActionUrl}';
496
+
497
+ M2ePro.url.save_listing_additional_data = '{$saveListingAdditionalDataActionUrl}';
498
+
499
+ M2ePro.text.popup_title = '{$popupTitle}';
500
+ M2ePro.text.popup_title_single = '{$popupTitleSingle}';
501
+ M2ePro.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
502
+
503
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
504
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
505
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
506
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
507
+
508
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
509
+ M2ePro.text.sending_data_message = '{$sendingDataToAmazonMessage}';
510
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
511
+
512
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
513
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
514
+
515
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
516
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
517
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
518
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
519
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
520
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
521
+ M2ePro.text.deleting_and_removing_selected_items_message = '{$deletingAndRemovingSelectedItemsMessage}';
522
+
523
+ M2ePro.text.successfully_moved = '{$successfullyMovedMessage}';
524
+ M2ePro.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
525
+ M2ePro.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
526
+
527
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
528
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
529
+
530
+ M2ePro.text.success_word = '{$successWord}';
531
+ M2ePro.text.notice_word = '{$noticeWord}';
532
+ M2ePro.text.warning_word = '{$warningWord}';
533
+ M2ePro.text.error_word = '{$errorWord}';
534
+ M2ePro.text.close_word = '{$closeWord}';
535
+
536
+ M2ePro.text.templateDescriptionPopupTitle = '{$templateDescriptionPopupTitle}';
537
+
538
+ M2ePro.text.templateShippingOverridePopupTitle = '{$templateShippingOverridePopupTitle}';
539
+
540
+ M2ePro.text.assign = '{$assignString}';
541
+ M2ePro.text.confirm = '{$textConfirm}';
542
+
543
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
544
+ M2ePro.text.automap_asin_search_products = '{$autoMapAsinSearchProducts}';
545
+ M2ePro.text.automap_asin_progress_title = '{$autoMapAsinProgressTitle}';
546
+ M2ePro.text.automap_error_message = '{$autoMapAsinErrorMessage}';
547
+
548
+ M2ePro.text.new_asin_not_available = '{$newAsinNotAvailable}';
549
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
550
+
551
+ M2ePro.text.no_variations_left = '{$noVariationsLeftText}';
552
+
553
+ M2ePro.text.not_set = '{$notSet}';
554
+ M2ePro.text.set_attributes = '{$setAttributes}';
555
+ M2ePro.text.variation_manage_matched_attributes_error = '{$variationManageMatchedAttributesError}';
556
+ M2ePro.text.variation_manage_matched_attributes_error_duplicate =
557
+ '{$variationManageMatchedAttributesErrorDuplicateSelection}';
558
+
559
+ M2ePro.text.variation_manage_matched_sku_popup_title = '{$variationManageSkuPopUpTitle}';
560
+ M2ePro.text.empty_sku_error = '{$emptySkuError}';
561
+
562
+ M2ePro.text.switch_to_individual_mode_popup_title = '{$switchToIndividualModePopUpTitle}';
563
+ M2ePro.text.switch_to_parent_mode_popup_title = '{$switchToParentModePopUpTitle}';
564
+
565
+ M2ePro.customData.componentMode = '{$component}';
566
+ M2ePro.customData.gridId = '{$gridId}';
567
+ M2ePro.customData.ignoreListings = '{$ignoreListings}';
568
+
569
+ M2ePro.customData.marketplace = {$marketplace};
570
+ M2ePro.customData.isNewAsinAvailable = {$isNewAsinAvailable};
571
+
572
+ Event.observe(window, 'load', function() {
573
+
574
+ ListingGridHandlerObj = new CommonAmazonListingGridHandler(
575
+ '{$gridId}',
576
+ {$listingData['id']}
577
+ );
578
+
579
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
580
+ ListingGridHandlerObj.movingHandler.setOptions(M2ePro);
581
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
582
+ ListingGridHandlerObj.templateDescriptionHandler.setOptions(M2ePro);
583
+ ListingGridHandlerObj.templateShippingOverrideHandler.setOptions(M2ePro);
584
+ ListingGridHandlerObj.variationProductManageHandler.setOptions(M2ePro);
585
+ ListingGridHandlerObj.fulfillmentHandler.setOptions(M2ePro);
586
+ ListingGridHandlerObj.repricingHandler.setOptions(M2ePro);
587
+
588
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
589
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
590
+
591
+ ListingProductVariationHandlerObj = new CommonListingProductVariationHandler(M2ePro,
592
+ ListingGridHandlerObj);
593
+
594
+ if (M2ePro.productsIdsForList) {
595
+ ListingGridHandlerObj.getGridMassActionObj().checkedString = M2ePro.productsIdsForList;
596
+ ListingGridHandlerObj.actionHandler.listAction();
597
+ }
598
+
599
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
600
+ if ({$showAutoAction}) {
601
+ ListingAutoActionHandlerObj.loadAutoActionHtml();
602
+ }
603
+
604
+ CommonAmazonListingAfnQtyHandlerObj = new CommonAmazonListingAfnQtyHandler();
605
+
606
+ });
607
+
608
+ </script>
609
+ HTML;
610
+
611
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_listing_view_help');
612
+ $productSearchBlock = $this->getLayout()
613
+ ->createBlock('M2ePro/adminhtml_common_amazon_listing_productSearch_main');
614
+
615
+ // ---------------------------------------
616
+ $data = array(
617
+ 'target_css_class' => 'edit_settings_drop_down',
618
+ 'items' => $this->getTemplatesButtonDropDownItems()
619
+ );
620
+ $templatesDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
621
+ $templatesDropDownBlock->setData($data);
622
+ // ---------------------------------------
623
+
624
+ // ---------------------------------------
625
+ $data = array(
626
+ 'target_css_class' => 'add_products_drop_down',
627
+ 'items' => $this->getAddProductsDropDownItems()
628
+ );
629
+ $addProductsDropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
630
+ $addProductsDropDownBlock->setData($data);
631
+ // ---------------------------------------
632
+
633
+ // ---------------------------------------
634
+ $listingSwitcher = $this->getLayout()->createBlock(
635
+ 'M2ePro/adminhtml_common_amazon_listing_view_listingSwitcher'
636
+ );
637
+ // ---------------------------------------
638
+
639
+ // ---------------------------------------
640
+ $viewHeaderBlock = $this->getLayout()->createBlock(
641
+ 'M2ePro/adminhtml_listing_view_header','',
642
+ array('listing' => Mage::helper('M2ePro/Component_Amazon')->getCachedObject('Listing',$listingData['id']))
643
+ );
644
+ // ---------------------------------------
645
+
646
+ // ---------------------------------------
647
+ $switchToIndividualPopup = $this->getLayout()->createBlock(
648
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToIndividualPopup');
649
+ // ---------------------------------------
650
+
651
+ // ---------------------------------------
652
+ $switchToParentPopup = $this->getLayout()->createBlock(
653
+ 'M2ePro/adminhtml_common_amazon_listing_variation_product_switchToParentPopup');
654
+ // ---------------------------------------
655
+
656
+ return $javascriptsMain
657
+ . $templatesDropDownBlock->toHtml()
658
+ . $listingSwitcher->toHtml()
659
+ . $addProductsDropDownBlock->toHtml()
660
+ . $helpBlock->toHtml()
661
+ . $viewHeaderBlock->toHtml()
662
+ . $productSearchBlock->toHtml()
663
+ . $switchToIndividualPopup->toHtml()
664
+ . $switchToParentPopup->toHtml()
665
+ . parent::getGridHtml();
666
+ }
667
+
668
+ public function getHeaderHtml()
669
+ {
670
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
671
+
672
+ // ---------------------------------------
673
+ $collection = Mage::getModel('M2ePro/Listing')->getCollection();
674
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
675
+ $collection->addFieldToFilter('id', array('neq' => $listingData['id']));
676
+ $collection->setPageSize(200);
677
+ $collection->setOrder('title', 'ASC');
678
+
679
+ $items = array();
680
+ foreach ($collection->getItems() as $item) {
681
+ $items[] = array(
682
+ 'label' => $item->getTitle(),
683
+ 'url' => $this->getUrl('*/*/view', array('id' => $item->getId()))
684
+ );
685
+ }
686
+ // ---------------------------------------
687
+
688
+ if (count($items) == 0) {
689
+ return parent::getHeaderHtml();
690
+ }
691
+
692
+ // ---------------------------------------
693
+ $data = array(
694
+ 'target_css_class' => 'listing-profile-title',
695
+ 'style' => 'max-height: 120px; overflow: auto; width: 200px;',
696
+ 'items' => $items
697
+ );
698
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
699
+ $dropDownBlock->setData($data);
700
+ // ---------------------------------------
701
+
702
+ return parent::getHeaderHtml() . $dropDownBlock->toHtml();
703
+ }
704
+
705
+ public function getHeaderText()
706
+ {
707
+ // ---------------------------------------
708
+ $changeProfile = Mage::helper('M2ePro')->__('Change Listing');
709
+ $headerText = parent::getHeaderText();
710
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
711
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($listingData['title']);
712
+ // ---------------------------------------
713
+
714
+ return <<<HTML
715
+ {$headerText} <a href="javascript: void(0);"
716
+ id="listing-profile-title"
717
+ class="listing-profile-title"
718
+ style="font-weight: bold;"
719
+ title="{$changeProfile}"><span class="drop_down_header">"{$listingTitle}"</span></a>
720
+ HTML;
721
+ }
722
+
723
+ protected function getTemplatesButtonDropDownItems()
724
+ {
725
+ $items = array();
726
+
727
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
728
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
729
+ '*/adminhtml_common_amazon_listing/view',
730
+ array(
731
+ 'id' => $listingData['id']
732
+ )
733
+ );
734
+
735
+ // ---------------------------------------
736
+ $url = $this->getUrl(
737
+ '*/adminhtml_common_amazon_listing/edit',
738
+ array(
739
+ 'id'=>$listingData['id'],
740
+ 'back'=>$backUrl,
741
+ 'tab' => 'selling'
742
+ )
743
+ );
744
+ $items[] = array(
745
+ 'url' => $url,
746
+ 'label' => Mage::helper('M2ePro')->__('Selling'),
747
+ 'target' => '_blank'
748
+ );
749
+ // ---------------------------------------
750
+
751
+ // ---------------------------------------
752
+ $url = $this->getUrl(
753
+ '*/adminhtml_common_amazon_listing/edit',
754
+ array(
755
+ 'id'=>$listingData['id'],
756
+ 'back'=>$backUrl,
757
+ 'tab' => 'search'
758
+ )
759
+ );
760
+ $items[] = array(
761
+ 'url' => $url,
762
+ 'label' => Mage::helper('M2ePro')->__('Search'),
763
+ 'target' => '_blank'
764
+ );
765
+ // ---------------------------------------
766
+
767
+ // ---------------------------------------
768
+ $items[] = array(
769
+ 'url' => 'javascript: void(0);',
770
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();',
771
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules')
772
+ );
773
+ // ---------------------------------------
774
+
775
+ return $items;
776
+ }
777
+
778
+ public function getAddProductsDropDownItems()
779
+ {
780
+ $items = array();
781
+
782
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
783
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_amazon_listing/view', array(
784
+ 'id' => $listingData['id']
785
+ ));
786
+
787
+ // ---------------------------------------
788
+ $url = $this->getUrl(
789
+ '*/adminhtml_common_listing_productAdd/index',
790
+ array(
791
+ 'id' => $listingData['id'],
792
+ 'back' => $backUrl,
793
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
794
+ 'clear' => 1,
795
+ 'step' => 2,
796
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
797
+ )
798
+ );
799
+ $items[] = array(
800
+ 'url' => $url,
801
+ 'label' => Mage::helper('M2ePro')->__('From Products List')
802
+ );
803
+ // ---------------------------------------
804
+
805
+ // ---------------------------------------
806
+ $url = $this->getUrl(
807
+ '*/adminhtml_common_listing_productAdd/index',
808
+ array(
809
+ 'id' => $listingData['id'],
810
+ 'back' => $backUrl,
811
+ 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK,
812
+ 'clear' => 1,
813
+ 'step' => 2,
814
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
815
+ )
816
+ );
817
+ $items[] = array(
818
+ 'url' => $url,
819
+ 'label' => Mage::helper('M2ePro')->__('From Categories')
820
+ );
821
+ // ---------------------------------------
822
+
823
+ return $items;
824
+ }
825
+
826
+ //########################################
827
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Amazon/Grid.php ADDED
@@ -0,0 +1,1760 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Amazon_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
11
+ {
12
+ /** @var $sellingFormatTemplate Ess_M2ePro_Model_Amazon_Template_SellingFormat */
13
+ private $sellingFormatTemplate = NULL;
14
+
15
+ private $lockedDataCache = array();
16
+
17
+ private $childProductsWarningsData;
18
+
19
+ private $hideSwitchToIndividualConfirm;
20
+ private $hideSwitchToParentConfirm;
21
+
22
+ //########################################
23
+
24
+ public function __construct()
25
+ {
26
+ parent::__construct();
27
+
28
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
29
+
30
+ $listing = Mage::helper('M2ePro/Component')->getUnknownObject('Listing', $listingData['id']);
31
+
32
+ $this->hideSwitchToIndividualConfirm =
33
+ $listing->getSetting('additional_data', 'hide_switch_to_individual_confirm', 0);
34
+
35
+ $this->hideSwitchToParentConfirm =
36
+ $listing->getSetting('additional_data', 'hide_switch_to_parent_confirm', 0);
37
+
38
+ // Initialization block
39
+ // ---------------------------------------
40
+ $this->setId('amazonListingViewAmazonGrid'.$listingData['id']);
41
+ // ---------------------------------------
42
+
43
+ $this->showAdvancedFilterProductsOption = false;
44
+
45
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
46
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
47
+ array('template')
48
+ );
49
+ }
50
+
51
+ //########################################
52
+
53
+ public function getMainButtonsHtml()
54
+ {
55
+ $data = array(
56
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
57
+ );
58
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
59
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
60
+ );
61
+ $viewModeSwitcherBlock->addData($data);
62
+
63
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
64
+ }
65
+
66
+ //########################################
67
+
68
+ protected function _prepareCollection()
69
+ {
70
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
71
+
72
+ // Get collection
73
+ // ---------------------------------------
74
+ /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
75
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
76
+ Mage::getModel('catalog/product')->getResource());
77
+ $collection->setListingProductModeOn();
78
+ $collection
79
+ ->addAttributeToSelect('name')
80
+ ->addAttributeToSelect('sku')
81
+ ->joinTable(
82
+ array('cisi' => 'cataloginventory/stock_item'),
83
+ 'product_id=entity_id',
84
+ array('qty' => 'qty'),
85
+ '{{table}}.stock_id=1',
86
+ 'left'
87
+ );
88
+
89
+ // ---------------------------------------
90
+
91
+ $collection->joinTable(
92
+ array('lp' => 'M2ePro/Listing_Product'),
93
+ 'product_id=entity_id',
94
+ array(
95
+ 'id' => 'id',
96
+ 'component_mode' => 'component_mode',
97
+ 'amazon_status' => 'status',
98
+ 'additional_data' => 'additional_data'
99
+ ),
100
+ array(
101
+ 'listing_id' => (int)$listingData['id']
102
+ )
103
+ );
104
+ $collection->joinTable(
105
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
106
+ 'listing_product_id=id',
107
+ array(
108
+ 'general_id' => 'general_id',
109
+ 'general_id_search_info' => 'general_id_search_info',
110
+ 'search_settings_status' => 'search_settings_status',
111
+ 'search_settings_data' => 'search_settings_data',
112
+ 'variation_child_statuses' => 'variation_child_statuses',
113
+ 'amazon_sku' => 'sku',
114
+ 'online_qty' => 'online_qty',
115
+ 'online_price' => 'online_price',
116
+ 'online_sale_price' => 'IF(
117
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
118
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
119
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
120
+ `alp`.`online_sale_price`,
121
+ NULL
122
+ )',
123
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
124
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
125
+ 'is_afn_channel' => 'is_afn_channel',
126
+ 'is_general_id_owner' => 'is_general_id_owner',
127
+ 'is_variation_parent' => 'is_variation_parent',
128
+ 'is_repricing' => 'is_repricing',
129
+ 'defected_messages' => 'defected_messages',
130
+ 'min_online_price' => 'IF(
131
+ (`t`.`variation_min_price` IS NULL),
132
+ IF(
133
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
134
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
135
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
136
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
137
+ `alp`.`online_sale_price`,
138
+ `alp`.`online_price`
139
+ ),
140
+ `t`.`variation_min_price`
141
+ )',
142
+ 'max_online_price' => 'IF(
143
+ (`t`.`variation_max_price` IS NULL),
144
+ IF(
145
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
146
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
147
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
148
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
149
+ `alp`.`online_sale_price`,
150
+ `alp`.`online_price`
151
+ ),
152
+ `t`.`variation_max_price`
153
+ )'
154
+ ),
155
+ '{{table}}.variation_parent_id is NULL'
156
+ );
157
+
158
+ $collection->getSelect()->joinLeft(
159
+ new Zend_Db_Expr('(
160
+ SELECT
161
+ `malp`.`variation_parent_id`,
162
+ MIN(
163
+ IF(
164
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
165
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
166
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
167
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
168
+ `malp`.`online_sale_price`,
169
+ `malp`.`online_price`
170
+ )
171
+ ) as variation_min_price,
172
+ MAX(
173
+ IF(
174
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
175
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
176
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
177
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
178
+ `malp`.`online_sale_price`,
179
+ `malp`.`online_price`
180
+ )
181
+ ) as variation_max_price
182
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
183
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
184
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
185
+ WHERE `mlp`.`status` IN (
186
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
187
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
188
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
189
+ GROUP BY `malp`.`variation_parent_id`
190
+ )'),
191
+ 'alp.listing_product_id=t.variation_parent_id',
192
+ array(
193
+ 'variation_min_price' => 'variation_min_price',
194
+ 'variation_max_price' => 'variation_max_price',
195
+ )
196
+ );
197
+
198
+ // ---------------------------------------
199
+
200
+ // Set collection to grid
201
+ $this->setCollection($collection);
202
+
203
+ return parent::_prepareCollection();
204
+ }
205
+
206
+ protected function _prepareColumns()
207
+ {
208
+ $this->addColumn('product_id', array(
209
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
210
+ 'align' => 'right',
211
+ 'width' => '100px',
212
+ 'type' => 'number',
213
+ 'index' => 'entity_id',
214
+ 'filter_index' => 'entity_id',
215
+ 'frame_callback' => array($this, 'callbackColumnProductId')
216
+ ));
217
+
218
+ $this->addColumn('name', array(
219
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
220
+ 'align' => 'left',
221
+ 'type' => 'text',
222
+ 'index' => 'name',
223
+ 'filter_index' => 'name',
224
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
225
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
226
+ ));
227
+
228
+ $this->addColumn('sku', array(
229
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
230
+ 'align' => 'left',
231
+ 'width' => '150px',
232
+ 'type' => 'text',
233
+ 'index' => 'amazon_sku',
234
+ 'filter_index' => 'amazon_sku',
235
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
236
+ ));
237
+
238
+ $this->addColumn('general_id', array(
239
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
240
+ 'align' => 'left',
241
+ 'width' => '140px',
242
+ 'type' => 'text',
243
+ 'index' => 'general_id',
244
+ 'filter_index' => 'general_id',
245
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
246
+ ));
247
+
248
+ $this->addColumn('online_qty', array(
249
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
250
+ 'align' => 'right',
251
+ 'width' => '70px',
252
+ 'type' => 'number',
253
+ 'index' => 'online_qty',
254
+ 'filter_index' => 'online_qty',
255
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty'),
256
+ 'filter' => 'M2ePro/adminhtml_common_amazon_grid_column_filter_qty',
257
+ 'filter_condition_callback' => array($this, 'callbackFilterQty')
258
+ ));
259
+
260
+ $dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
261
+
262
+ if ($dir == 'desc') {
263
+ $priceSortField = 'max_online_price';
264
+ } else {
265
+ $priceSortField = 'min_online_price';
266
+ }
267
+
268
+ $priceColumn = array(
269
+ 'header' => Mage::helper('M2ePro')->__('Price'),
270
+ 'align' => 'right',
271
+ 'width' => '110px',
272
+ 'type' => 'number',
273
+ 'index' => $priceSortField,
274
+ 'filter_index' => $priceSortField,
275
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
276
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
277
+ );
278
+
279
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled()) {
280
+ $priceColumn['filter'] = 'M2ePro/adminhtml_common_amazon_grid_column_filter_price';
281
+ }
282
+
283
+ $this->addColumn('online_price', $priceColumn);
284
+
285
+ $this->addColumn('status', array(
286
+ 'header' => Mage::helper('M2ePro')->__('Status'),
287
+ 'width' => '155px',
288
+ 'index' => 'amazon_status',
289
+ 'filter_index' => 'amazon_status',
290
+ 'type' => 'options',
291
+ 'sortable' => false,
292
+ 'options' => array(
293
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
294
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
295
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
296
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
297
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
298
+ ),
299
+ 'frame_callback' => array($this, 'callbackColumnStatus'),
300
+ 'filter_condition_callback' => array($this, 'callbackFilterStatus')
301
+ ));
302
+
303
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
304
+ $this->addColumn('developer_action', array(
305
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
306
+ 'align' => 'left',
307
+ 'width' => '100px',
308
+ 'type' => 'text',
309
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
310
+ 'index' => 'value',
311
+ 'filter' => false,
312
+ 'sortable' => false,
313
+ 'js_handler' => 'ListingGridHandlerObj'
314
+ ));
315
+ }
316
+
317
+ return parent::_prepareColumns();
318
+ }
319
+
320
+ protected function _prepareMassaction()
321
+ {
322
+ // Set massaction identifiers
323
+ // ---------------------------------------
324
+ $this->setMassactionIdField('id');
325
+ $this->setMassactionIdFieldOnlyIndexValue(true);
326
+ // ---------------------------------------
327
+
328
+ // Set mass-action
329
+ // ---------------------------------------
330
+ $groups = array(
331
+ 'actions' => Mage::helper('M2ePro')->__('Actions'),
332
+ 'asin_isbn' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
333
+ 'description_policy' => Mage::helper('M2ePro')->__('Description Policy'),
334
+ 'other' => Mage::helper('M2ePro')->__('Other'),
335
+ );
336
+
337
+ $this->getMassactionBlock()->setGroups($groups);
338
+
339
+ $this->getMassactionBlock()->addItem('list', array(
340
+ 'label' => Mage::helper('M2ePro')->__('List Item(s)'),
341
+ 'url' => '',
342
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
343
+ ), 'actions');
344
+
345
+ $this->getMassactionBlock()->addItem('revise', array(
346
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
347
+ 'url' => '',
348
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
349
+ ), 'actions');
350
+
351
+ $this->getMassactionBlock()->addItem('relist', array(
352
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
353
+ 'url' => '',
354
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
355
+ ), 'actions');
356
+
357
+ $this->getMassactionBlock()->addItem('stop', array(
358
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
359
+ 'url' => '',
360
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
361
+ ), 'actions');
362
+
363
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
364
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
365
+ 'url' => '',
366
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
367
+ ), 'actions');
368
+
369
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
370
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
371
+ 'url' => '',
372
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
373
+ ), 'actions');
374
+
375
+ $this->getMassactionBlock()->addItem('assignGeneralId', array(
376
+ 'label' => Mage::helper('M2ePro')->__('Search Automatically'),
377
+ 'url' => '',
378
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
379
+ ), 'asin_isbn');
380
+
381
+ $this->getMassactionBlock()->addItem('newGeneralId', array(
382
+ 'label' => Mage::helper('M2ePro')->__('Assign Settings for New ASIN/ISBN'),
383
+ 'url' => '',
384
+ ), 'asin_isbn');
385
+
386
+ $this->getMassactionBlock()->addItem('unassignGeneralId', array(
387
+ 'label' => Mage::helper('M2ePro')->__('Reset Information'),
388
+ 'url' => '',
389
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
390
+ ), 'asin_isbn');
391
+ // ---------------------------------------
392
+
393
+ return parent::_prepareMassaction();
394
+ }
395
+
396
+ //########################################
397
+
398
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
399
+ {
400
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
401
+
402
+ $value = '<span>'.$productTitle.'</span>';
403
+
404
+ $tempSku = $row->getData('sku');
405
+ is_null($tempSku)
406
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
407
+
408
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
409
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
410
+
411
+ $listingProductId = (int)$row->getData('id');
412
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
413
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
414
+
415
+ if (!$listingProduct->getChildObject()->getVariationManager()->isVariationProduct()) {
416
+ return $value;
417
+ }
418
+
419
+ $generalId = $row->getData('general_id');
420
+
421
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
422
+ $amazonListingProduct = $listingProduct->getChildObject();
423
+ $variationManager = $amazonListingProduct->getVariationManager();
424
+
425
+ if ($variationManager->isRelationParentType()) {
426
+
427
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
428
+ $virtualProductAttributes = $variationManager->getTypeModel()->getVirtualProductAttributes();
429
+ $virtualChannelAttributes = $variationManager->getTypeModel()->getVirtualChannelAttributes();
430
+
431
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
432
+ $attributesStr = '';
433
+ if (empty($virtualProductAttributes) && empty($virtualChannelAttributes)) {
434
+ $attributesStr = implode(', ', $productAttributes);
435
+ } else {
436
+ foreach ($productAttributes as $attribute) {
437
+ if (in_array($attribute, array_keys($virtualProductAttributes))) {
438
+
439
+ $attributesStr .= '<span style="border-bottom: 2px dotted grey">' . $attribute .
440
+ ' (' . $virtualProductAttributes[$attribute] . ')</span>, ';
441
+
442
+ } else if (in_array($attribute, array_keys($virtualChannelAttributes))) {
443
+
444
+ $attributesStr .= '<span>' . $attribute .
445
+ ' (' . $virtualChannelAttributes[$attribute] . ')</span>, ';
446
+
447
+ } else {
448
+ $attributesStr .= $attribute . ', ';
449
+ }
450
+ }
451
+ $attributesStr = rtrim($attributesStr, ', ');
452
+ }
453
+ $value .= $attributesStr;
454
+
455
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
456
+ $popupTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
457
+ Mage::helper('M2ePro')->__('Manage Magento Product Variations'))
458
+ );
459
+
460
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
461
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
462
+ );
463
+
464
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
465
+
466
+ $switchToIndividualJsMethod = <<<JS
467
+ ListingProductVariationHandlerObj
468
+ .setListingProductId({$listingProductId})
469
+ .showSwitchToIndividualModePopUp('{$popupTitle}');
470
+ JS;
471
+
472
+ if ($this->hideSwitchToIndividualConfirm) {
473
+ $switchToIndividualJsMethod = <<<JS
474
+ ListingProductVariationHandlerObj
475
+ .setListingProductId({$listingProductId})
476
+ .showManagePopup('{$popupTitle}');
477
+ JS;
478
+ }
479
+
480
+ $value .= <<<HTML
481
+ &nbsp;
482
+ <a href="javascript:"
483
+ onclick="{$switchToIndividualJsMethod}"
484
+ title="{$linkTitle}">
485
+ <img width="12" height="12" style="height: 12px; width: 12px; vertical-align: middle;" src="{$iconSettingsPath}">
486
+ </a>
487
+ HTML;
488
+ }
489
+
490
+ $value .= '</div>';
491
+
492
+ if (!empty($generalId) || $amazonListingProduct->isGeneralIdOwner()) {
493
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Parent $parentType */
494
+ $parentType = $variationManager->getTypeModel();
495
+
496
+ $linkContent = Mage::helper('M2ePro')->__('Manage Variations');
497
+ $vpmt = Mage::helper('M2ePro')->__('Manage Variations of &quot;%s&quot; ', $productTitle);
498
+ $vpmt = addslashes($vpmt);
499
+
500
+ if (!empty($generalId)) {
501
+ $vpmt .= '('. $generalId .')';
502
+ }
503
+
504
+ $problemStyle = '';
505
+ $problemIcon = '';
506
+
507
+ $linkTitle = Mage::helper('M2ePro')->__('Open Manage Variations Tool');
508
+
509
+ if (empty($generalId) && $amazonListingProduct->isGeneralIdOwner()) {
510
+ if (!$parentType->hasChannelTheme() || !$parentType->hasMatchedAttributes()) {
511
+
512
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
513
+ $problemStyle = 'style="font-weight: bold; color: #FF0000;" ';
514
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
515
+ $problemIcon = '<img style="vertical-align: middle;" src="'
516
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
517
+ }
518
+ } elseif (!empty($generalId)) {
519
+ if (!$parentType->hasMatchedAttributes()) {
520
+
521
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
522
+ $problemStyle = 'style="font-weight: bold;color: #FF0000;" ';
523
+ $iconPath = $this->getSkinUrl('M2ePro/images/error.png');
524
+ $problemIcon = '<img style="vertical-align: middle;" src="'
525
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
526
+ } elseif (($listingProduct->getChildObject()->isGeneralIdOwner() &&
527
+ !$parentType->hasChannelTheme()) ||
528
+ $this->hasChildWithWarning($listingProductId)) {
529
+
530
+ $linkTitle = Mage::helper('M2ePro')->__('Action Required');
531
+ $problemStyle = 'style="font-weight: bold;" ';
532
+ $iconPath = $this->getSkinUrl('M2ePro/images/warning.png');
533
+ $problemIcon = '<img style="vertical-align: middle;" src="'
534
+ . $iconPath . '" title="' . $linkTitle . '" alt="" width="16" height="16">';
535
+ }
536
+ }
537
+
538
+ $value .= <<<HTML
539
+ <div style="float: left; margin: 0 0 0 7px">
540
+ <a {$problemStyle}href="javascript:"
541
+ onclick="ListingGridHandlerObj.variationProductManageHandler.openPopUp({$listingProductId}, '{$vpmt}')"
542
+ title="{$linkTitle}">{$linkContent}</a>&nbsp;{$problemIcon}
543
+ </div>
544
+ HTML;
545
+ }
546
+
547
+ return $value;
548
+ }
549
+
550
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
551
+
552
+ if (!empty($productOptions)) {
553
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
554
+ foreach ($productOptions as $attribute => $option) {
555
+ !$option && $option = '--';
556
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
557
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
558
+ }
559
+ $value .= '</div>';
560
+ }
561
+
562
+ // ---------------------------------------
563
+ $hasInActionLock = $this->getLockedData($row);
564
+ $hasInActionLock = $hasInActionLock['in_action'];
565
+ // ---------------------------------------
566
+
567
+ if (!$hasInActionLock) {
568
+
569
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variation');
570
+ $linkTitle = Mage::helper('M2ePro')->__('Edit Variation');
571
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/pencil.png').'">';
572
+
573
+ $value .= <<<HTML
574
+ <div style="clear: both"></div>
575
+ <div style="margin: 0 0 0 7px; float: left;">
576
+ <a href="javascript:"
577
+ onclick="ListingProductVariationHandlerObj
578
+ .setListingProductId({$listingProductId})
579
+ .showEditPopup('{$popupTitle}');"
580
+ title="{$linkTitle}">{$linkContent}</a>
581
+ </div>
582
+ HTML;
583
+ }
584
+
585
+ $popupTitle = Mage::helper('M2ePro')->__('Manage Magento Product Variations') ;
586
+ $linkTitle = Mage::helper('M2ePro')->__('Add Another Variation(s)');
587
+ $linkContent = '<img width="12" height="12" src="'.$this->getSkinUrl('M2ePro/images/add.png').'">';
588
+
589
+ $value.= <<<HTML
590
+ <div style="margin: 0 0 0 7px; float: left;">
591
+ <a href="javascript:"
592
+ onclick="ListingProductVariationHandlerObj
593
+ .setListingProductId({$listingProductId})
594
+ .showManagePopup('{$popupTitle}');"
595
+ title="{$linkTitle}">{$linkContent}</a>
596
+ </div>
597
+ HTML;
598
+
599
+ if (empty($generalId) && !$amazonListingProduct->isGeneralIdOwner()) {
600
+ $linkTitle = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')->escapeHtml(
601
+ Mage::helper('M2ePro')->__('Change "Magento Variations" Mode'))
602
+ );
603
+
604
+ $iconSettingsPath = $this->getSkinUrl('M2ePro/images/settings.png');
605
+
606
+ $switchToParentJsMethod = <<<JS
607
+ ListingProductVariationHandlerObj
608
+ .setListingProductId({$listingProductId})
609
+ .showSwitchToParentModePopUp('{$popupTitle}');
610
+ JS;
611
+
612
+ if ($this->hideSwitchToParentConfirm) {
613
+ $switchToParentJsMethod = <<<JS
614
+ ListingProductVariationHandlerObj
615
+ .setListingProductId({$listingProductId})
616
+ .resetListingProductVariation();
617
+ JS;
618
+ }
619
+
620
+ $value .= <<<HTML
621
+ <div style="margin: 0 0 0 7px; float: left;">
622
+ <a href="javascript:"
623
+ onclick="{$switchToParentJsMethod}"
624
+ title="{$linkTitle}">
625
+ <img width="12" height="12" src="{$iconSettingsPath}">
626
+ </a>
627
+ </div>
628
+ HTML;
629
+ }
630
+
631
+ return $value;
632
+ }
633
+
634
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
635
+ {
636
+ if ((!$row->getData('is_variation_parent') &&
637
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
638
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
639
+
640
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
641
+ }
642
+
643
+ if (is_null($value) || $value === '') {
644
+ $value = Mage::helper('M2ePro')->__('N/A');
645
+ }
646
+
647
+ if (!$row->getData('is_variation_parent') && $row->getData('defected_messages')) {
648
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
649
+
650
+ $msg = '';
651
+ foreach ($defectedMessages as $message) {
652
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
653
+ if (!empty($message['value'])) {
654
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
655
+ }
656
+ $msg .= '</p>';
657
+ }
658
+
659
+ $value .= <<<HTML
660
+ <span style="float:right;">
661
+ <img id="map_link_defected_message_icon_{$row->getId()}"
662
+ class="tool-tip-image"
663
+ style="vertical-align: middle;"
664
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
665
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
666
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
667
+ <span>{$msg}</span>
668
+ </span>
669
+ </span>
670
+ HTML;
671
+ }
672
+
673
+ return $value;
674
+ }
675
+
676
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
677
+ {
678
+ if (empty($generalId)) {
679
+ if ($row->getData('is_general_id_owner') == 1) {
680
+ return $this->getGeneralIdColumnValueGeneralIdOwner($row);
681
+ }
682
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
683
+ }
684
+
685
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
686
+ }
687
+
688
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
689
+ {
690
+ if (!$row->getData('is_variation_parent')) {
691
+
692
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
693
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
694
+ }
695
+
696
+ if ((bool)$row->getData('is_afn_channel')) {
697
+ $sku = $row->getData('amazon_sku');
698
+
699
+ if (empty($sku)) {
700
+ return Mage::helper('M2ePro')->__('AFN');
701
+ }
702
+
703
+ $productId = $row->getData('id');
704
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
705
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$productId);
706
+
707
+ $afn = Mage::helper('M2ePro')->__('AFN');
708
+ $total = Mage::helper('M2ePro')->__('Total');
709
+ $inStock = Mage::helper('M2ePro')->__('In Stock');
710
+ $accountId = $listingProduct->getListing()->getAccountId();
711
+
712
+ return <<<HTML
713
+ <div id="m2ePro_afn_qty_value_{$productId}">
714
+ <span class="m2ePro-online-sku-value" productId="{$productId}" style="display: none">{$sku}</span>
715
+ <span class="m2epro-empty-afn-qty-data" style="display: none">{$afn}</span>
716
+ <div class="m2epro-afn-qty-data" style="display: none">
717
+ <div class="total">{$total}: <span></span></div>
718
+ <div class="in-stock">{$inStock}: <span></span></div>
719
+ </div>
720
+ <a href="javascript:void(0)"
721
+ onclick="CommonAmazonListingAfnQtyHandlerObj.showAfnQty(this,'{$sku}',{$productId}, {$accountId})">
722
+ {$afn}
723
+ </a>
724
+ </div>
725
+ HTML;
726
+ }
727
+
728
+ if (is_null($value) || $value === '') {
729
+ return '<i style="color:gray;">receiving...</i>';
730
+ }
731
+
732
+ if ($value <= 0) {
733
+ return '<span style="color: red;">0</span>';
734
+ }
735
+
736
+ return $value;
737
+ }
738
+
739
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
740
+ $row->getData('general_id') == '') {
741
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
742
+ }
743
+
744
+ $variationChildStatuses = json_decode($row->getData('variation_child_statuses'), true);
745
+
746
+ $activeChildrenCount = 0;
747
+ foreach ($variationChildStatuses as $childStatus => $count) {
748
+ if ($childStatus == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
749
+ continue;
750
+ }
751
+ $activeChildrenCount += (int)$count;
752
+ }
753
+
754
+ if ($activeChildrenCount == 0) {
755
+ return Mage::helper('M2ePro')->__('N/A');
756
+ }
757
+
758
+ if (!(bool)$row->getData('is_afn_channel')) {
759
+ return $value;
760
+ }
761
+
762
+ if ($value == 0 && (bool)$row->getData('is_afn_channel')) {
763
+ return Mage::helper('M2ePro')->__('AFN');
764
+ }
765
+
766
+ return $value . '<br/>' . Mage::helper('M2ePro')->__('AFN');
767
+ }
768
+
769
+ public function callbackColumnPrice($value, $row, $column, $isExport)
770
+ {
771
+ if ((!$row->getData('is_variation_parent') &&
772
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
773
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
774
+
775
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
776
+ }
777
+
778
+ $repricingHtml ='';
779
+
780
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() &&
781
+ (int)$row->getData('is_repricing') === Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES) {
782
+ if ($row->getData('is_variation_parent')) {
783
+ $text = Mage::helper('M2ePro')->__(
784
+ 'Some Child Products are used by Amazon Repricing Tool.
785
+ The Price cannot be updated through the M2E Pro.'
786
+ );
787
+ } else {
788
+ $text = Mage::helper('M2ePro')->__(
789
+ 'This product is used by Amazon Repricing Tool.
790
+ The Price cannot be updated through the M2E Pro.'
791
+ );
792
+ }
793
+
794
+ $repricingHtml = <<<HTML
795
+ <span style="float:right; text-align: left;">
796
+ <img class="tool-tip-image"
797
+ style="vertical-align: middle; width: 16px;"
798
+ src="{$this->getSkinUrl('M2ePro/images/money.png')}">
799
+ <span class="tool-tip-message tool-tip-message tip-left" style="display:none;">
800
+ <img src="{$this->getSkinUrl('M2ePro/images/i_icon.png')}">
801
+ <span>{$text}</span>
802
+ </span>
803
+ </span>
804
+ HTML;
805
+ }
806
+
807
+ $onlineMinPrice = $row->getData('min_online_price');
808
+ $onlineMaxPrice = $row->getData('max_online_price');
809
+
810
+ if (is_null($onlineMinPrice) || $onlineMinPrice === '') {
811
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED ||
812
+ $row->getData('is_variation_parent')
813
+ ) {
814
+ return Mage::helper('M2ePro')->__('N/A') . $repricingHtml;
815
+ } else {
816
+ return '<i style="color:gray;">receiving...</i>' . $repricingHtml;
817
+ }
818
+ }
819
+
820
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
821
+ $currency = Mage::helper('M2ePro/Component_Amazon')
822
+ ->getCachedObject('Marketplace',$marketplaceId)
823
+ ->getChildObject()
824
+ ->getDefaultCurrency();
825
+
826
+ if ($row->getData('is_variation_parent')) {
827
+ $onlineMinPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMinPrice);
828
+ $onlineMaxPriceStr = Mage::app()->getLocale()->currency($currency)->toCurrency($onlineMaxPrice);
829
+
830
+ return $onlineMinPriceStr . (($onlineMinPrice != $onlineMaxPrice) ? ' - ' . $onlineMaxPriceStr : '') .
831
+ $repricingHtml;
832
+ }
833
+
834
+ $onlinePrice = $row->getData('online_price');
835
+ if ((float)$onlinePrice <= 0) {
836
+ $priceValue = '<span style="color: #f00;">0</span>';
837
+ } else {
838
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
839
+ }
840
+
841
+ $resultHtml = '';
842
+
843
+ $salePrice = $row->getData('online_sale_price');
844
+ if (!$row->getData('is_variation_parent') && (float)$salePrice > 0) {
845
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
846
+
847
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
848
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
849
+
850
+ if ($currentTimestamp <= $endDateTimestamp) {
851
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
852
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
853
+
854
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
855
+
856
+ $fromDate = Mage::app()->getLocale()->date(
857
+ $row->getData('online_sale_price_start_date'), $dateFormat
858
+ )->toString($dateFormat);
859
+ $toDate = Mage::app()->getLocale()->date(
860
+ $row->getData('online_sale_price_end_date'), $dateFormat
861
+ )->toString($dateFormat);
862
+
863
+ $intervalHtml = '<img class="tool-tip-image"
864
+ style="vertical-align: middle;"
865
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
866
+ text-align: left;
867
+ width: 120px;
868
+ background: #E3E3E3;">
869
+ <img src="'.$iconHelpPath.'">
870
+ <span style="color:gray;">
871
+ <strong>From:</strong> '.$fromDate.'<br/>
872
+ <strong>To:</strong> '.$toDate.'
873
+ </span>
874
+ </span>';
875
+
876
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
877
+
878
+ if ($currentTimestamp >= $startDateTimestamp &&
879
+ $currentTimestamp <= $endDateTimestamp &&
880
+ $salePrice < (float)$onlinePrice
881
+ ) {
882
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>' .
883
+ $repricingHtml;
884
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
885
+ } else {
886
+ $resultHtml .= $priceValue . $repricingHtml;
887
+ $resultHtml .= '<br/>'.$intervalHtml.
888
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
889
+ }
890
+ }
891
+ }
892
+
893
+ if (empty($resultHtml)) {
894
+ $resultHtml = $priceValue . $repricingHtml;
895
+ }
896
+
897
+ return $resultHtml;
898
+ }
899
+
900
+ public function callbackColumnStatus($value, $row, $column, $isExport)
901
+ {
902
+ $listingProductId = (int)$row->getData('id');
903
+
904
+ $html = $this->getViewLogIconHtml($listingProductId);
905
+
906
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
907
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
908
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
909
+
910
+ $synchNote = $listingProduct->getSetting('additional_data', 'synch_template_list_rules_note');
911
+ if (!empty($synchNote)) {
912
+
913
+ $synchNote = Mage::helper('M2ePro/View')->getModifiedLogMessage($synchNote);
914
+
915
+ if (empty($html)) {
916
+ $html = <<<HTML
917
+ <span style="float:right;">
918
+ <img id="map_link_error_icon_{$row->getId()}"
919
+ class="tool-tip-image"
920
+ style="vertical-align: middle;"
921
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
922
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
923
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
924
+ <span>{$synchNote}</span>
925
+ </span>
926
+ </span>
927
+ HTML;
928
+ } else {
929
+ $html .= <<<HTML
930
+ <div id="synch_template_list_rules_note_{$listingProductId}" style="display: none">{$synchNote}</div>
931
+ HTML;
932
+ }
933
+ }
934
+
935
+ if (!$variationManager->isVariationParent()) {
936
+ return $html . $this->getProductStatus($row->getData('amazon_status')). $this->getLockedTag($row);
937
+ } else {
938
+
939
+ $statusUnknown = Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN;
940
+ $statusNotListed = Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED;
941
+ $statusListed = Ess_M2ePro_Model_Listing_Product::STATUS_LISTED;
942
+ $statusStopped = Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED;
943
+ $statusBlocked = Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED;
944
+
945
+ $generalId = $listingProduct->getGeneralId();
946
+ $variationChildStatuses = $row->getData('variation_child_statuses');
947
+ if (empty($generalId) || empty($variationChildStatuses)) {
948
+ return $html . $this->getProductStatus($statusNotListed) .
949
+ $this->getLockedTag($row);
950
+ }
951
+
952
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
953
+
954
+ $sortedStatuses = array();
955
+ if (isset($variationChildStatuses[$statusUnknown])) {
956
+ $sortedStatuses[$statusUnknown] = $variationChildStatuses[$statusUnknown];
957
+ }
958
+ if (isset($variationChildStatuses[$statusNotListed])) {
959
+ $sortedStatuses[$statusNotListed] = $variationChildStatuses[$statusNotListed];
960
+ }
961
+ if (isset($variationChildStatuses[$statusListed])) {
962
+ $sortedStatuses[$statusListed] = $variationChildStatuses[$statusListed];
963
+ }
964
+ if (isset($variationChildStatuses[$statusStopped])) {
965
+ $sortedStatuses[$statusStopped] = $variationChildStatuses[$statusStopped];
966
+ }
967
+ if (isset($variationChildStatuses[$statusBlocked])) {
968
+ $sortedStatuses[$statusBlocked] = $variationChildStatuses[$statusBlocked];
969
+ }
970
+
971
+ $linkTitle = Mage::helper('M2ePro')->__('Show all Child Products with such Status');
972
+
973
+ foreach ($sortedStatuses as $status => $productsCount) {
974
+ if (empty($productsCount)) {
975
+ continue;
976
+ }
977
+
978
+ $filter = base64_encode('status=' . $status);
979
+
980
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
981
+ $vpmt = Mage::helper('M2ePro')->__('Manage Variations of &quot;%s&quot; ', $productTitle);
982
+ $vpmt = addslashes($vpmt);
983
+
984
+ $generalId = $row->getData('general_id');
985
+ if (!empty($generalId)) {
986
+ $vpmt .= '('. $generalId .')';
987
+ }
988
+
989
+ $productsCount = <<<HTML
990
+ <a onclick="ListingGridHandlerObj.variationProductManageHandler.openPopUp({$listingProductId}, '{$vpmt}', '{$filter}')"
991
+ class="hover-underline"
992
+ title="{$linkTitle}"
993
+ href="javascript:void(0)">[{$productsCount}]</a>
994
+ HTML;
995
+
996
+ $html .= '' . $this->getProductStatus($status) . '&nbsp;'. $productsCount . '<br/>';
997
+ }
998
+
999
+ $html .= $this->getLockedTag($row);
1000
+ }
1001
+
1002
+ return $html;
1003
+ }
1004
+
1005
+ private function getProductStatus($status)
1006
+ {
1007
+ switch ($status) {
1008
+
1009
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
1010
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Unknown') . '</span>';
1011
+
1012
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
1013
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
1014
+
1015
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
1016
+ return '<span style="color: green;">' . Mage::helper('M2ePro')->__('Active') . '</span>';
1017
+
1018
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
1019
+ return'<span style="color: red;">' . Mage::helper('M2ePro')->__('Inactive') . '</span>';
1020
+
1021
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
1022
+ return'<span style="color: orange; font-weight: bold;">' .
1023
+ Mage::helper('M2ePro')->__('Inactive (Blocked)') . '</span>';
1024
+ }
1025
+
1026
+ return '';
1027
+ }
1028
+
1029
+ private function getLockedTag($row)
1030
+ {
1031
+ $html = '';
1032
+
1033
+ $tempLocks = $this->getLockedData($row);
1034
+ $tempLocks = $tempLocks['object_locks'];
1035
+
1036
+ $childCount = 0;
1037
+
1038
+ foreach ($tempLocks as $lock) {
1039
+
1040
+ switch ($lock->getTag()) {
1041
+
1042
+ case 'list_action':
1043
+ $html .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
1044
+ break;
1045
+
1046
+ case 'relist_action':
1047
+ $html .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
1048
+ break;
1049
+
1050
+ case 'revise_action':
1051
+ $html .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
1052
+ break;
1053
+
1054
+ case 'stop_action':
1055
+ $html .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
1056
+ break;
1057
+
1058
+ case 'stop_and_remove_action':
1059
+ $html .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
1060
+ break;
1061
+
1062
+ case 'delete_and_remove_action':
1063
+ $html .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
1064
+ break;
1065
+
1066
+ case 'switch_to_afn_action':
1067
+ $html .= '<br/><span style="color: #605fff">[Switch to AFN in Progress...]</span>';
1068
+ break;
1069
+
1070
+ case 'switch_to_mfn_action':
1071
+ $html .= '<br/><span style="color: #605fff">[Switch to MFN in Progress...]</span>';
1072
+ break;
1073
+
1074
+ case 'child_products_in_action':
1075
+ $childCount++;
1076
+ break;
1077
+
1078
+ default:
1079
+ break;
1080
+
1081
+ }
1082
+ }
1083
+
1084
+ if ($childCount > 0) {
1085
+ $html .= '<br/><span style="color: #605fff">[Child(s) in Action...]</span>';
1086
+ }
1087
+
1088
+ return $html;
1089
+ }
1090
+
1091
+ // ---------------------------------------
1092
+
1093
+ protected function callbackFilterTitle($collection, $column)
1094
+ {
1095
+ $value = $column->getFilter()->getValue();
1096
+
1097
+ if ($value == null) {
1098
+ return;
1099
+ }
1100
+
1101
+ $collection->addFieldToFilter(
1102
+ array(
1103
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
1104
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
1105
+ )
1106
+ );
1107
+ }
1108
+
1109
+ protected function callbackFilterQty($collection, $column)
1110
+ {
1111
+ $value = $column->getFilter()->getValue();
1112
+
1113
+ if (empty($value)) {
1114
+ return;
1115
+ }
1116
+
1117
+ $where = '';
1118
+
1119
+ if (isset($value['from']) && $value['from'] != '') {
1120
+ $where .= 'online_qty >= ' . $value['from'];
1121
+ }
1122
+
1123
+ if (isset($value['to']) && $value['to'] != '') {
1124
+ if (isset($value['from']) && $value['from'] != '') {
1125
+ $where .= ' AND ';
1126
+ }
1127
+ $where .= 'online_qty <= ' . $value['to'];
1128
+ }
1129
+
1130
+ if (!empty($value['afn'])) {
1131
+ if (!empty($where)) {
1132
+ $where = '(' . $where . ') OR ';
1133
+ }
1134
+ $where .= 'is_afn_channel = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_AFN_CHANNEL_YES;
1135
+ }
1136
+
1137
+ $collection->getSelect()->where($where);
1138
+ }
1139
+
1140
+ protected function callbackFilterPrice($collection, $column)
1141
+ {
1142
+ $value = $column->getFilter()->getValue();
1143
+
1144
+ if (empty($value)) {
1145
+ return;
1146
+ }
1147
+
1148
+ $condition = '';
1149
+
1150
+ if (isset($value['from']) || isset($value['to'])) {
1151
+
1152
+ if (isset($value['from']) && $value['from'] != '') {
1153
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
1154
+ }
1155
+ if (isset($value['to']) && $value['to'] != '') {
1156
+ if (isset($value['from']) && $value['from'] != '') {
1157
+ $condition .= ' AND ';
1158
+ }
1159
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
1160
+ }
1161
+
1162
+ $condition = '(' . $condition . ') OR (';
1163
+
1164
+ if (isset($value['from']) && $value['from'] != '') {
1165
+ $condition .= 'max_online_price >= \''.$value['from'].'\'';
1166
+ }
1167
+ if (isset($value['to']) && $value['to'] != '') {
1168
+ if (isset($value['from']) && $value['from'] != '') {
1169
+ $condition .= ' AND ';
1170
+ }
1171
+ $condition .= 'max_online_price <= \''.$value['to'].'\'';
1172
+ }
1173
+
1174
+ $condition .= ')';
1175
+
1176
+ }
1177
+
1178
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() && !empty($value['is_repricing'])) {
1179
+ if (!empty($condition)) {
1180
+ $condition = '(' . $condition . ') OR ';
1181
+ }
1182
+ $condition .= 'is_repricing = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES;
1183
+ }
1184
+
1185
+ $collection->getSelect()->having($condition);
1186
+ }
1187
+
1188
+ protected function callbackFilterStatus($collection, $column)
1189
+ {
1190
+ $value = $column->getFilter()->getValue();
1191
+
1192
+ if ($value == null) {
1193
+ return;
1194
+ }
1195
+
1196
+ $collection->getSelect()->where("lp.status = {$value} OR
1197
+ (alp.variation_child_statuses REGEXP '\"{$value}\":[^0]') AND alp.is_variation_parent = 1");
1198
+ }
1199
+
1200
+ // ---------------------------------------
1201
+
1202
+ public function getViewLogIconHtml($listingProductId)
1203
+ {
1204
+ $listingProductId = (int)$listingProductId;
1205
+
1206
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
1207
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
1208
+
1209
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
1210
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1211
+
1212
+ // Get last messages
1213
+ // ---------------------------------------
1214
+ $dbSelect = $connRead->select()
1215
+ ->from(
1216
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
1217
+ array('action_id','action','type','description','create_date','initiator','listing_product_id')
1218
+ )
1219
+ ->where('`action_id` IS NOT NULL')
1220
+ ->order(array('id DESC'))
1221
+ ->limit(30);
1222
+
1223
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
1224
+ $dbSelect->where('listing_product_id = ? OR parent_listing_product_id = ?', $listingProductId);
1225
+ } else {
1226
+ $dbSelect->where('listing_product_id = ?', $listingProductId);
1227
+ }
1228
+
1229
+ $logRows = $connRead->fetchAll($dbSelect);
1230
+ // ---------------------------------------
1231
+
1232
+ // Get grouped messages by action_id
1233
+ // ---------------------------------------
1234
+ $actionsRows = array();
1235
+ $tempActionRows = array();
1236
+ $lastActionId = false;
1237
+
1238
+ foreach ($logRows as $row) {
1239
+
1240
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
1241
+
1242
+ if ($row['action_id'] !== $lastActionId) {
1243
+ if (count($tempActionRows) > 0) {
1244
+ $actionsRows[] = array(
1245
+ 'action_id' => $lastActionId,
1246
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
1247
+ 'date' => $this->getMainDateForActionId($tempActionRows),
1248
+ 'action' => $this->getActionForAction($tempActionRows[0]),
1249
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
1250
+ 'items' => $tempActionRows
1251
+ );
1252
+ $tempActionRows = array();
1253
+ }
1254
+ $lastActionId = $row['action_id'];
1255
+ }
1256
+ $tempActionRows[] = $row;
1257
+ }
1258
+
1259
+ if (count($tempActionRows) > 0) {
1260
+ $actionsRows[] = array(
1261
+ 'action_id' => $lastActionId,
1262
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
1263
+ 'date' => $this->getMainDateForActionId($tempActionRows),
1264
+ 'action' => $this->getActionForAction($tempActionRows[0]),
1265
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
1266
+ 'items' => $tempActionRows
1267
+ );
1268
+ }
1269
+
1270
+ if (count($actionsRows) <= 0) {
1271
+ return '';
1272
+ }
1273
+
1274
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationParent()) {
1275
+ foreach ($actionsRows as &$actionsRow) {
1276
+ if (!empty($actionsRow['items']) && $actionsRow['items'][0]['listing_product_id']==$listingProductId) {
1277
+ continue;
1278
+ }
1279
+ $actionsRow['action_in_progress'] = $this->isActionInProgress($actionsRow['action_id']);
1280
+
1281
+ $descArr = array();
1282
+ foreach ($actionsRow['items'] as $key => &$item) {
1283
+ if (array_key_exists($item['description'], $descArr)) {
1284
+ $descArr[$item['description']]['count']++;
1285
+ unset($actionsRow['items'][$key]);
1286
+ continue;
1287
+ }
1288
+ $item['count'] = 1;
1289
+ $descArr[$item['description']] = $item;
1290
+ }
1291
+ $actionsRow['items'] = array_values($descArr);
1292
+ }
1293
+ }
1294
+
1295
+ foreach ($actionsRows as &$actionsRow) {
1296
+ usort($actionsRow['items'], function($a, $b)
1297
+ {
1298
+ $sortOrder = array(
1299
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
1300
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
1301
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
1302
+ );
1303
+
1304
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
1305
+ });
1306
+ }
1307
+
1308
+ $tips = array(
1309
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
1310
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
1311
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
1312
+ );
1313
+
1314
+ $icons = array(
1315
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
1316
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
1317
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
1318
+ );
1319
+
1320
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
1321
+ 'entity_id' => $listingProductId,
1322
+ 'rows' => $actionsRows,
1323
+ 'tips' => $tips,
1324
+ 'icons' => $icons,
1325
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
1326
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
1327
+ ));
1328
+
1329
+ return $summary->toHtml();
1330
+ }
1331
+
1332
+ public function getActionForAction($actionRows)
1333
+ {
1334
+ $string = '';
1335
+
1336
+ switch ($actionRows['action']) {
1337
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
1338
+ $string = Mage::helper('M2ePro')->__('List');
1339
+ break;
1340
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
1341
+ $string = Mage::helper('M2ePro')->__('Relist');
1342
+ break;
1343
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
1344
+ $string = Mage::helper('M2ePro')->__('Revise');
1345
+ break;
1346
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
1347
+ $string = Mage::helper('M2ePro')->__('Stop');
1348
+ break;
1349
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
1350
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
1351
+ break;
1352
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
1353
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
1354
+ break;
1355
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
1356
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
1357
+ break;
1358
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
1359
+ $string = Mage::helper('M2ePro')->__('Channel Change');
1360
+ break;
1361
+ case Ess_M2ePro_Model_Listing_Log::ACTION_SWITCH_TO_AFN_ON_COMPONENT:
1362
+ $string = Mage::helper('M2ePro')->__('Switch to AFN');
1363
+ break;
1364
+ case Ess_M2ePro_Model_Listing_Log::ACTION_SWITCH_TO_MFN_ON_COMPONENT:
1365
+ $string = Mage::helper('M2ePro')->__('Switch to MFN');
1366
+ break;
1367
+ }
1368
+
1369
+ return $string;
1370
+ }
1371
+
1372
+ public function getInitiatorForAction($actionRows)
1373
+ {
1374
+ $string = '';
1375
+
1376
+ switch ((int)$actionRows['initiator']) {
1377
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
1378
+ $string = '';
1379
+ break;
1380
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
1381
+ $string = Mage::helper('M2ePro')->__('Manual');
1382
+ break;
1383
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
1384
+ $string = Mage::helper('M2ePro')->__('Automatic');
1385
+ break;
1386
+ }
1387
+
1388
+ return $string;
1389
+ }
1390
+
1391
+ public function getMainTypeForActionId($actionRows)
1392
+ {
1393
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
1394
+
1395
+ foreach ($actionRows as $row) {
1396
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
1397
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
1398
+ break;
1399
+ }
1400
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
1401
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
1402
+ }
1403
+ }
1404
+
1405
+ return $type;
1406
+ }
1407
+
1408
+ public function getMainDateForActionId($actionRows)
1409
+ {
1410
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
1411
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
1412
+ }
1413
+
1414
+ public function isActionInProgress($actionId)
1415
+ {
1416
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
1417
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1418
+
1419
+ // Get last messages
1420
+ // ---------------------------------------
1421
+ $dbSelect = $connRead->select()
1422
+ ->from(
1423
+ Mage::getResourceModel('M2ePro/Processing_Request')->getMainTable()
1424
+ )
1425
+ ->where('responser_params REGEXP \'"logs_action_id":'.$actionId.'\'');
1426
+
1427
+ $result = $connRead->fetchAll($dbSelect);
1428
+
1429
+ return !empty($result);
1430
+ }
1431
+
1432
+ //########################################
1433
+
1434
+ public function getGridUrl()
1435
+ {
1436
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
1437
+ }
1438
+
1439
+ public function getRowUrl($row)
1440
+ {
1441
+ return false;
1442
+ }
1443
+
1444
+ //########################################
1445
+
1446
+ protected function _getStore()
1447
+ {
1448
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
1449
+
1450
+ // Get store filter
1451
+ // ---------------------------------------
1452
+ $storeId = $listing['store_id'];
1453
+ // ---------------------------------------
1454
+
1455
+ return Mage::app()->getStore((int)$storeId);
1456
+ }
1457
+
1458
+ //########################################
1459
+
1460
+ protected function _toHtml()
1461
+ {
1462
+ $javascriptsMain = <<<HTML
1463
+ <script type="text/javascript">
1464
+
1465
+ if (typeof ListingGridHandlerObj != 'undefined') {
1466
+ ListingGridHandlerObj.afterInitPage();
1467
+ }
1468
+
1469
+ Event.observe(window, 'load', function() {
1470
+ setTimeout(function() {
1471
+ ListingGridHandlerObj.afterInitPage();
1472
+ }, 350);
1473
+ });
1474
+
1475
+ </script>
1476
+ HTML;
1477
+
1478
+ return parent::_toHtml().$javascriptsMain;
1479
+ }
1480
+
1481
+ //########################################
1482
+
1483
+ private function getLockedData($row)
1484
+ {
1485
+ $listingProductId = $row->getData('id');
1486
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1487
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($listingProductId)->getObjectLocks();
1488
+ $tempArray = array(
1489
+ 'object_locks' => $objectLocks,
1490
+ 'in_action' => !empty($objectLocks),
1491
+ );
1492
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1493
+ }
1494
+
1495
+ return $this->lockedDataCache[$listingProductId];
1496
+ }
1497
+
1498
+ //########################################
1499
+
1500
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
1501
+ {
1502
+ // ---------------------------------------
1503
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1504
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
1505
+ }
1506
+ // ---------------------------------------
1507
+
1508
+ // ---------------------------------------
1509
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1510
+ // ---------------------------------------
1511
+
1512
+ // ---------------------------------------
1513
+ $lpId = $row->getData('id');
1514
+
1515
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('name'));
1516
+ if (strlen($productTitle) > 60) {
1517
+ $productTitle = substr($productTitle, 0, 60) . '...';
1518
+ }
1519
+ $productTitle = Mage::helper('M2ePro')->__('Assign ASIN/ISBN For &quot;%product_title%&quot;', $productTitle);
1520
+ $productTitle = Mage::helper('M2ePro')->escapeJs($productTitle);
1521
+ // ---------------------------------------
1522
+
1523
+ // ---------------------------------------
1524
+
1525
+ $searchSettingsStatus = $row->getData('search_settings_status');
1526
+
1527
+ // ---------------------------------------
1528
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
1529
+
1530
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN Search in Progress.');
1531
+ $iconSrc = $iconPath.'processing.gif';
1532
+
1533
+ return <<<HTML
1534
+ &nbsp;
1535
+ <a href="javascript: void(0);" title="{$tip}">
1536
+ <img src="{$iconSrc}" alt="">
1537
+ </a>
1538
+ HTML;
1539
+ }
1540
+ // ---------------------------------------
1541
+
1542
+ // ---------------------------------------
1543
+ $searchSettingsData = $row->getData('search_settings_data');
1544
+
1545
+ $suggestData = array();
1546
+ if (!is_null($searchSettingsData)) {
1547
+ $searchSettingsData = @json_decode($searchSettingsData,true);
1548
+ !empty($searchSettingsData['data']) && $suggestData = $searchSettingsData['data'];
1549
+
1550
+ }
1551
+ // ---------------------------------------
1552
+
1553
+ $na = Mage::helper('M2ePro')->__('N/A');
1554
+
1555
+ if (!empty($suggestData)) {
1556
+
1557
+ $tip = Mage::helper('M2ePro')->__('Choose ASIN/ISBN from the list');
1558
+ $iconSrc = $iconPath.'list.png';
1559
+
1560
+ return <<<HTML
1561
+ {$na} &nbsp;
1562
+ <a href="javascript:;" title="{$tip}"
1563
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(1,'{$productTitle}',{$lpId})">
1564
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1565
+ </a>
1566
+ HTML;
1567
+ }
1568
+
1569
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_NOT_FOUND) {
1570
+
1571
+ $tip = Mage::helper('M2ePro')->__(
1572
+ 'There were no Products found on Amazon according to the Listing Search Settings.'
1573
+ );
1574
+ $tip = Mage::helper('M2ePro')->escapeJs($tip);
1575
+
1576
+ $iconSrc = $iconPath.'error.png';
1577
+
1578
+ return <<<HTML
1579
+ {$na} &nbsp;
1580
+ <a href="javascript: void(0);" title="{$tip}"
1581
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId},'{$tip}');">
1582
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1583
+ </a>
1584
+ HTML;
1585
+ }
1586
+
1587
+ $tip = Mage::helper('M2ePro')->__('Search for ASIN/ISBN');
1588
+ $iconSrc = $iconPath.'search.png';
1589
+
1590
+ return <<<HTML
1591
+ {$na} &nbsp;
1592
+ <a href="javascript:;" title="{$tip}"
1593
+ onclick="ListingGridHandlerObj.productSearchHandler.openPopUp(0,'{$productTitle}',{$lpId});">
1594
+ <img src="{$iconSrc}" alt="" width="16" height="16">
1595
+ </a>
1596
+ HTML;
1597
+ }
1598
+
1599
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
1600
+ {
1601
+ $generalId = $row->getData('general_id');
1602
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
1603
+
1604
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
1605
+ $generalId,
1606
+ $marketplaceId
1607
+ );
1608
+
1609
+ $generalIdOwnerHtml = '';
1610
+ if ($row->getData('is_general_id_owner') == Ess_M2ePro_Model_Amazon_Listing_Product::IS_GENERAL_ID_OWNER_YES) {
1611
+
1612
+ $generalIdOwnerHtml = '<br/><span style="font-size: 10px; color: grey;">'.
1613
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
1614
+ '</span>';
1615
+ }
1616
+
1617
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
1618
+
1619
+ return <<<HTML
1620
+ <a href="{$url}" target="_blank">{$generalId}</a>{$generalIdOwnerHtml}
1621
+ HTML;
1622
+ }
1623
+
1624
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1625
+
1626
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
1627
+
1628
+ if (!empty($generalIdSearchInfo)) {
1629
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
1630
+ }
1631
+
1632
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
1633
+
1634
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
1635
+
1636
+ $text = <<<HTML
1637
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
1638
+ HTML;
1639
+
1640
+ } else {
1641
+
1642
+ $text = <<<HTML
1643
+ <a href="{$url}" target="_blank">{$generalId}</a>
1644
+ HTML;
1645
+
1646
+ }
1647
+
1648
+ // ---------------------------------------
1649
+ $hasInActionLock = $this->getLockedData($row);
1650
+ $hasInActionLock = $hasInActionLock['in_action'];
1651
+ // ---------------------------------------
1652
+
1653
+ if ($hasInActionLock) {
1654
+ return $text . $generalIdOwnerHtml;
1655
+ }
1656
+
1657
+ $listingProductId = (int)$row->getData('id');
1658
+
1659
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
1660
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$listingProductId);
1661
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
1662
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
1663
+ $variationChildStatuses = $row->getData('variation_child_statuses');
1664
+
1665
+ if ($variationManager->isVariationParent() && !empty($variationChildStatuses)) {
1666
+ $variationChildStatuses = json_decode($variationChildStatuses, true);
1667
+ unset($variationChildStatuses[Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED]);
1668
+
1669
+ foreach ($variationChildStatuses as $variationChildStatus) {
1670
+ if (!empty($variationChildStatus)) {
1671
+ return $text . $generalIdOwnerHtml;
1672
+ }
1673
+ }
1674
+ }
1675
+
1676
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1677
+ $iconSrc = $iconPath.'unassign.png';
1678
+
1679
+ $text .= <<<HTML
1680
+ &nbsp;
1681
+ <a href="javascript:;"
1682
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$listingProductId});"
1683
+ title="{$tip}">
1684
+ <img src="{$iconSrc}" width="16" height="16"/>
1685
+ </a>{$generalIdOwnerHtml}
1686
+ HTML;
1687
+
1688
+ return $text;
1689
+ }
1690
+
1691
+ private function getGeneralIdColumnValueGeneralIdOwner($row)
1692
+ {
1693
+ $text = Mage::helper('M2ePro')->__('New ASIN/ISBN');
1694
+
1695
+ // ---------------------------------------
1696
+ $hasInActionLock = $this->getLockedData($row);
1697
+ $hasInActionLock = $hasInActionLock['in_action'];
1698
+ // ---------------------------------------
1699
+
1700
+ if ($hasInActionLock) {
1701
+ return $text;
1702
+ }
1703
+
1704
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
1705
+
1706
+ $tip = Mage::helper('M2ePro')->__('Unassign ASIN/ISBN');
1707
+ $iconSrc = $iconPath.'unassign.png';
1708
+
1709
+ $lpId = $row->getData('id');
1710
+
1711
+ $text .= <<<HTML
1712
+ &nbsp;
1713
+ <a href="javascript:;"
1714
+ onclick="ListingGridHandlerObj.productSearchHandler.showUnmapFromGeneralIdPrompt({$lpId});"
1715
+ title="{$tip}"><img src="{$iconSrc}" width="16" height="16"/>
1716
+ </a>
1717
+ HTML;
1718
+ return $text;
1719
+ }
1720
+
1721
+ //########################################
1722
+
1723
+ protected function getChildProductsWarningsData()
1724
+ {
1725
+ if (is_null($this->childProductsWarningsData)) {
1726
+ $this->childProductsWarningsData = array();
1727
+
1728
+ $productsIds = array();
1729
+ foreach ($this->getCollection()->getData() as $row) {
1730
+ $productsIds[] = $row['id'];
1731
+ }
1732
+
1733
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1734
+ $tableAmazonListingProduct = Mage::getSingleton('core/resource')
1735
+ ->getTableName('m2epro_amazon_listing_product');
1736
+
1737
+ $select = $connRead->select();
1738
+ $select->distinct(true);
1739
+ $select->from(array('alp' => $tableAmazonListingProduct), array('variation_parent_id'))
1740
+ ->where('variation_parent_id IN (?)', $productsIds)
1741
+ ->where(
1742
+ 'is_variation_product_matched = 0 OR
1743
+ (general_id IS NOT NULL AND is_variation_channel_matched = 0)'
1744
+ );
1745
+
1746
+ $this->childProductsWarningsData = Mage::getResourceModel('core/config')
1747
+ ->getReadConnection()
1748
+ ->fetchCol($select);
1749
+ }
1750
+
1751
+ return $this->childProductsWarningsData;
1752
+ }
1753
+
1754
+ protected function hasChildWithWarning($listingProductId)
1755
+ {
1756
+ return in_array($listingProductId, $this->getChildProductsWarningsData());
1757
+ }
1758
+
1759
+ //########################################
1760
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Help.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Help extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonListingViewHelp');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/listing/view/help.phtml');
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ListingSwitcher.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_ListingSwitcher
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_View_ListingSwitcher_Abstract
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+
20
+ $this->setAddListingUrl('*/adminhtml_common_listing_create/index/step/1/component/amazon/');
21
+ }
22
+
23
+ //########################################
24
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Magento/Grid.php ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Magento_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('amazonListingViewMagentoGrid'.$listingData['id']);
23
+ // ---------------------------------------
24
+
25
+ $this->hideMassactionColumn = true;
26
+ $this->hideMassactionDropDown = true;
27
+ $this->showAdvancedFilterProductsOption = false;
28
+ }
29
+
30
+ //########################################
31
+
32
+ public function getMainButtonsHtml()
33
+ {
34
+ $data = array(
35
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
36
+ );
37
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
38
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
39
+ );
40
+ $viewModeSwitcherBlock->addData($data);
41
+
42
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
43
+ }
44
+
45
+ //########################################
46
+
47
+ protected function _prepareCollection()
48
+ {
49
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
50
+
51
+ // Get collection
52
+ // ---------------------------------------
53
+ /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
54
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
55
+ Mage::getModel('catalog/product')->getResource());
56
+ $collection->getSelect()->group('e.entity_id');
57
+ $collection
58
+ ->addAttributeToSelect('name')
59
+ ->joinTable(
60
+ array('cisi' => 'cataloginventory/stock_item'),
61
+ 'product_id=entity_id',
62
+ array('qty' => 'qty',
63
+ 'is_in_stock' => 'is_in_stock'),
64
+ '{{table}}.stock_id=1',
65
+ 'left'
66
+ );
67
+
68
+ // ---------------------------------------
69
+
70
+ $collection->joinTable(
71
+ array('lp' => 'M2ePro/Listing_Product'),
72
+ 'product_id=entity_id',
73
+ array(
74
+ 'id' => 'id',
75
+ 'amazon_status' => 'status',
76
+ 'additional_data' => 'additional_data'
77
+ ),
78
+ array(
79
+ 'listing_id' => (int)$listingData['id']
80
+ )
81
+ );
82
+ $collection->joinTable(
83
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
84
+ 'listing_product_id=id',
85
+ array(
86
+ 'general_id' => 'general_id',
87
+ 'amazon_sku' => 'sku',
88
+ 'online_qty' => 'online_qty',
89
+ 'online_price' => 'online_price',
90
+ 'online_sale_price' => 'online_sale_price',
91
+ 'is_afn_channel' => 'is_afn_channel'
92
+ ),
93
+ NULL,
94
+ 'left'
95
+ );
96
+ // ---------------------------------------
97
+
98
+ // Set filter store
99
+ // ---------------------------------------
100
+ $store = $this->_getStore();
101
+
102
+ if ($store->getId()) {
103
+ $collection->joinAttribute(
104
+ 'magento_price', 'catalog_product/price', 'entity_id', NULL, 'left', $store->getId()
105
+ );
106
+ $collection->joinAttribute(
107
+ 'status', 'catalog_product/status', 'entity_id', NULL, 'inner',$store->getId()
108
+ );
109
+ $collection->joinAttribute(
110
+ 'visibility', 'catalog_product/visibility', 'entity_id', NULL, 'inner',$store->getId()
111
+ );
112
+ $collection->joinAttribute(
113
+ 'thumbnail', 'catalog_product/thumbnail', 'entity_id', NULL, 'left',$store->getId()
114
+ );
115
+ } else {
116
+ $collection->addAttributeToSelect('price');
117
+ $collection->addAttributeToSelect('status');
118
+ $collection->addAttributeToSelect('visibility');
119
+ $collection->addAttributeToSelect('thumbnail');
120
+ }
121
+ // ---------------------------------------
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
+ 'type' => 'text',
149
+ 'index' => 'name',
150
+ 'filter_index' => 'name',
151
+ 'frame_callback' => array($this, 'callbackColumnProductTitle')
152
+ ));
153
+
154
+ $tempTypes = Mage::getSingleton('catalog/product_type')->getOptionArray();
155
+ unset($tempTypes['virtual']);
156
+
157
+ $this->addColumn('type', array(
158
+ 'header' => Mage::helper('M2ePro')->__('Type'),
159
+ 'align' => 'left',
160
+ 'width' => '90px',
161
+ 'type' => 'options',
162
+ 'sortable' => false,
163
+ 'index' => 'type_id',
164
+ 'filter_index' => 'type_id',
165
+ 'options' => $tempTypes
166
+ ));
167
+
168
+ $this->addColumn('is_in_stock', array(
169
+ 'header' => Mage::helper('M2ePro')->__('Stock Availability'),
170
+ 'align' => 'left',
171
+ 'width' => '90px',
172
+ 'type' => 'options',
173
+ 'sortable' => false,
174
+ 'index' => 'is_in_stock',
175
+ 'filter_index' => 'is_in_stock',
176
+ 'options' => array(
177
+ '1' => Mage::helper('M2ePro')->__('In Stock'),
178
+ '0' => Mage::helper('M2ePro')->__('Out of Stock')
179
+ ),
180
+ 'frame_callback' => array($this, 'callbackColumnIsInStock')
181
+ ));
182
+
183
+ $this->addColumn('sku', array(
184
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
185
+ 'align' => 'left',
186
+ 'width' => '90px',
187
+ 'type' => 'text',
188
+ 'index' => 'sku',
189
+ 'filter_index' => 'sku'
190
+ ));
191
+
192
+ $store = $this->_getStore();
193
+
194
+ $priceAttributeAlias = 'price';
195
+ if ($store->getId()) {
196
+ $priceAttributeAlias = 'magento_price';
197
+ }
198
+
199
+ $this->addColumn($priceAttributeAlias, array(
200
+ 'header' => Mage::helper('M2ePro')->__('Price'),
201
+ 'align' => 'right',
202
+ 'width' => '100px',
203
+ 'type' => 'price',
204
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
205
+ 'index' => $priceAttributeAlias,
206
+ 'filter_index' => $priceAttributeAlias,
207
+ 'frame_callback' => array($this, 'callbackColumnPrice')
208
+ ));
209
+
210
+ $this->addColumn('qty', array(
211
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
212
+ 'align' => 'right',
213
+ 'width' => '100px',
214
+ 'type' => 'number',
215
+ 'index' => 'qty',
216
+ 'filter_index' => 'qty',
217
+ 'frame_callback' => array($this, 'callbackColumnQty')
218
+ ));
219
+
220
+ $this->addColumn('visibility', array(
221
+ 'header' => Mage::helper('M2ePro')->__('Visibility'),
222
+ 'align' => 'left',
223
+ 'width' => '90px',
224
+ 'type' => 'options',
225
+ 'sortable' => false,
226
+ 'index' => 'visibility',
227
+ 'filter_index' => 'visibility',
228
+ 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray()
229
+ ));
230
+
231
+ $this->addColumn('status', array(
232
+ 'header' => Mage::helper('M2ePro')->__('Status'),
233
+ 'align' => 'left',
234
+ 'width' => '90px',
235
+ 'type' => 'options',
236
+ 'sortable' => false,
237
+ 'index' => 'status',
238
+ 'filter_index' => 'status',
239
+ 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
240
+ 'frame_callback' => array($this, 'callbackColumnStatus')
241
+ ));
242
+
243
+ if (!Mage::app()->isSingleStoreMode()) {
244
+
245
+ $this->addColumn('websites', array(
246
+ 'header' => Mage::helper('M2ePro')->__('Websites'),
247
+ 'align' => 'left',
248
+ 'width' => '90px',
249
+ 'type' => 'options',
250
+ 'sortable' => false,
251
+ 'index' => 'websites',
252
+ 'filter_index' => 'websites',
253
+ 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash()
254
+ ));
255
+ }
256
+
257
+ return parent::_prepareColumns();
258
+ }
259
+
260
+ //########################################
261
+
262
+ public function callbackColumnPrice($value, $row, $column, $isExport)
263
+ {
264
+ $rowVal = $row->getData();
265
+
266
+ if ($column->getId() == 'magento_price' &&
267
+ (!isset($rowVal['magento_price']) || (float)$rowVal['magento_price'] <= 0)
268
+ ) {
269
+ $value = '<span style="color: red;">0</span>';
270
+ }
271
+
272
+ if ($column->getId() == 'price' &&
273
+ (!isset($rowVal['price']) || (float)$rowVal['price'] <= 0)
274
+ ) {
275
+ $value = '<span style="color: red;">0</span>';
276
+ }
277
+
278
+ return $value;
279
+ }
280
+
281
+ //########################################
282
+
283
+ public function getGridUrl()
284
+ {
285
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
286
+ }
287
+
288
+ public function getRowUrl($row)
289
+ {
290
+ return false;
291
+ }
292
+
293
+ //########################################
294
+
295
+ protected function _addColumnFilterToCollection($column)
296
+ {
297
+ if ($this->getCollection()) {
298
+ if ($column->getId() == 'websites') {
299
+ $this->getCollection()->joinField('websites',
300
+ 'catalog/product_website',
301
+ 'website_id',
302
+ 'product_id=entity_id',
303
+ null,
304
+ 'left');
305
+ }
306
+ }
307
+ return parent::_addColumnFilterToCollection($column);
308
+ }
309
+
310
+ //########################################
311
+
312
+ protected function _getStore()
313
+ {
314
+ $listing = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
315
+
316
+ // Get store filter
317
+ // ---------------------------------------
318
+ $storeId = $listing['store_id'];
319
+ // ---------------------------------------
320
+
321
+ return Mage::app()->getStore((int)$storeId);
322
+ }
323
+
324
+ protected function _toHtml()
325
+ {
326
+ $javascriptsMain = <<<HTML
327
+ <script type="text/javascript">
328
+
329
+ if (typeof ListingGridHandlerObj != 'undefined') {
330
+ ListingGridHandlerObj.afterInitPage();
331
+ }
332
+
333
+ Event.observe(window, 'load', function() {
334
+ setTimeout(function() {
335
+ ListingGridHandlerObj.afterInitPage();
336
+ }, 350);
337
+ });
338
+
339
+ </script>
340
+ HTML;
341
+
342
+ return parent::_toHtml().$javascriptsMain;
343
+ }
344
+
345
+ //########################################
346
+
347
+ protected function isShowRuleBlock()
348
+ {
349
+ /** @var $ruleModel Ess_M2ePro_Model_Magento_Product_Rule */
350
+ $ruleModel = Mage::helper('M2ePro/Data_Global')->getValue('rule_model');
351
+ if ($ruleModel->isEmpty()) {
352
+ return false;
353
+ }
354
+
355
+ return parent::isShowRuleBlock();
356
+ }
357
+
358
+ //########################################
359
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/ModeSwitcher.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_ModeSwitcher
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_View_ModeSwitcher_Abstract
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonListingViewModeSwitcher');
21
+ // ---------------------------------------
22
+
23
+ $this->setData('component_nick', 'amazon');
24
+ $this->setData('component_label', 'Amazon');
25
+ }
26
+
27
+ protected function getMenuItems()
28
+ {
29
+ return array(
30
+ array(
31
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_AMAZON,
32
+ 'label' => Mage::helper('M2ePro')->__($this->getComponentLabel())
33
+ ),
34
+ array(
35
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_SETTINGS,
36
+ 'label' => Mage::helper('M2ePro')->__('Settings')
37
+ ),
38
+ array(
39
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_SELLERCENTRAL,
40
+ 'label' => Mage::helper('M2ePro')->__('Seller Сentral')
41
+ ),
42
+ array(
43
+ 'value' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View::VIEW_MODE_MAGENTO,
44
+ 'label' => Mage::helper('M2ePro')->__('Magento')
45
+ )
46
+ );
47
+ }
48
+
49
+ //########################################
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Sellercentral/Grid.php ADDED
@@ -0,0 +1,1135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Sellercentral_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
11
+ {
12
+ //########################################
13
+
14
+ /** @var $sellingFormatTemplate Ess_M2ePro_Model_Amazon_Template_SellingFormat */
15
+ private $sellingFormatTemplate = NULL;
16
+
17
+ private $lockedDataCache = array();
18
+
19
+ private $parentAsins;
20
+
21
+ //########################################
22
+
23
+ public function __construct()
24
+ {
25
+ parent::__construct();
26
+
27
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
28
+
29
+ // Initialization block
30
+ // ---------------------------------------
31
+ $this->setId('amazonListingViewSellercentralGrid'.$listingData['id']);
32
+ // ---------------------------------------
33
+
34
+ $this->showAdvancedFilterProductsOption = false;
35
+
36
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
37
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
38
+ array('template')
39
+ );
40
+ }
41
+
42
+ //########################################
43
+
44
+ public function getMainButtonsHtml()
45
+ {
46
+ $data = array(
47
+ 'current_view_mode' => $this->getParentBlock()->getViewMode()
48
+ );
49
+ $viewModeSwitcherBlock = $this->getLayout()->createBlock(
50
+ 'M2ePro/adminhtml_common_amazon_listing_view_modeSwitcher'
51
+ );
52
+ $viewModeSwitcherBlock->addData($data);
53
+
54
+ return $viewModeSwitcherBlock->toHtml() . parent::getMainButtonsHtml();
55
+ }
56
+
57
+ //########################################
58
+
59
+ protected function _prepareCollection()
60
+ {
61
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
62
+
63
+ // Get collection
64
+ // ---------------------------------------
65
+ /* @var $collection Ess_M2ePro_Model_Mysql4_Magento_Product_Collection */
66
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
67
+ Mage::getModel('catalog/product')->getResource());
68
+ $collection
69
+ ->setListingProductModeOn()
70
+ ->addAttributeToSelect('name')
71
+ ->addAttributeToSelect('sku')
72
+ ->joinTable(
73
+ array('cisi' => 'cataloginventory/stock_item'),
74
+ 'product_id=entity_id',
75
+ array(
76
+ 'qty' => 'qty',
77
+ 'is_in_stock' => 'is_in_stock'
78
+ ),
79
+ '{{table}}.stock_id=1',
80
+ 'left'
81
+ );
82
+
83
+ // ---------------------------------------
84
+
85
+ $collection->joinTable(
86
+ array('lp' => 'M2ePro/Listing_Product'),
87
+ 'product_id=entity_id',
88
+ array(
89
+ 'id' => 'id',
90
+ 'amazon_status' => 'status',
91
+ 'component_mode' => 'component_mode',
92
+ 'additional_data' => 'additional_data'
93
+ ),
94
+ array(
95
+ 'listing_id' => (int)$listingData['id'],
96
+ 'status' => array(
97
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED,
98
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED,
99
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED,
100
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN,
101
+ )
102
+ )
103
+ );
104
+ $collection->joinTable(
105
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
106
+ 'listing_product_id=id',
107
+ array(
108
+ 'general_id' => 'general_id',
109
+ 'search_settings_status' => 'search_settings_status',
110
+ 'amazon_sku' => 'sku',
111
+ 'online_qty' => 'online_qty',
112
+ 'online_price' => 'online_price',
113
+ 'online_sale_price' => 'IF(
114
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
115
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
116
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
117
+ `alp`.`online_sale_price`,
118
+ NULL
119
+ )',
120
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
121
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
122
+ 'is_afn_channel' => 'is_afn_channel',
123
+ 'is_general_id_owner' => 'is_general_id_owner',
124
+ 'is_variation_parent' => 'is_variation_parent',
125
+ 'is_repricing' => 'is_repricing',
126
+ 'variation_child_statuses' => 'variation_child_statuses',
127
+ 'variation_parent_id' => 'variation_parent_id',
128
+ 'defected_messages' => 'defected_messages',
129
+ 'min_online_price' => '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
+ ),
138
+ '{{table}}.is_variation_parent = 0'
139
+ );
140
+ // ---------------------------------------
141
+
142
+ // Set collection to grid
143
+ $this->setCollection($collection);
144
+
145
+ return parent::_prepareCollection();
146
+ }
147
+
148
+ protected function _prepareColumns()
149
+ {
150
+ $this->addColumn('product_id', array(
151
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
152
+ 'align' => 'right',
153
+ 'width' => '100px',
154
+ 'type' => 'number',
155
+ 'index' => 'entity_id',
156
+ 'filter_index' => 'entity_id',
157
+ 'frame_callback' => array($this, 'callbackColumnProductId')
158
+ ));
159
+
160
+ $this->addColumn('name', array(
161
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
162
+ 'align' => 'left',
163
+ 'type' => 'text',
164
+ 'index' => 'name',
165
+ 'filter_index' => 'name',
166
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
167
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
168
+ ));
169
+
170
+ $this->addColumn('sku', array(
171
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
172
+ 'align' => 'left',
173
+ 'width' => '150px',
174
+ 'type' => 'text',
175
+ 'index' => 'amazon_sku',
176
+ 'filter_index' => 'amazon_sku',
177
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
178
+ ));
179
+
180
+ $this->addColumn('general_id', array(
181
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
182
+ 'align' => 'left',
183
+ 'width' => '140px',
184
+ 'type' => 'text',
185
+ 'index' => 'general_id',
186
+ 'filter_index' => 'general_id',
187
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
188
+ ));
189
+
190
+ $this->addColumn('online_qty', array(
191
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
192
+ 'align' => 'right',
193
+ 'width' => '70px',
194
+ 'type' => 'number',
195
+ 'index' => 'online_qty',
196
+ 'filter_index' => 'online_qty',
197
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty'),
198
+ 'filter' => 'M2ePro/adminhtml_common_amazon_grid_column_filter_qty',
199
+ 'filter_condition_callback' => array($this, 'callbackFilterQty')
200
+ ));
201
+
202
+ $priceColumn = array(
203
+ 'header' => Mage::helper('M2ePro')->__('Price'),
204
+ 'align' => 'right',
205
+ 'width' => '110px',
206
+ 'type' => 'number',
207
+ 'index' => 'min_online_price',
208
+ 'filter_index' => 'min_online_price',
209
+ 'frame_callback' => array($this, 'callbackColumnPrice'),
210
+ 'filter_condition_callback' => array($this, 'callbackFilterPrice')
211
+ );
212
+
213
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled()) {
214
+ $priceColumn['filter'] = 'M2ePro/adminhtml_common_amazon_grid_column_filter_price';
215
+ }
216
+
217
+ $this->addColumn('online_price', $priceColumn);
218
+
219
+ $this->addColumn('status', array(
220
+ 'header' => Mage::helper('M2ePro')->__('Status'),
221
+ 'width' => '155px',
222
+ 'index' => 'amazon_status',
223
+ 'filter_index' => 'amazon_status',
224
+ 'type' => 'options',
225
+ 'sortable' => false,
226
+ 'options' => array(
227
+ Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN => Mage::helper('M2ePro')->__('Unknown'),
228
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
229
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive'),
230
+ Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED => Mage::helper('M2ePro')->__('Inactive (Blocked)')
231
+ ),
232
+ 'frame_callback' => array($this, 'callbackColumnStatus')
233
+ ));
234
+
235
+ if (Mage::helper('M2ePro/Module')->isDevelopmentMode()) {
236
+ $this->addColumn('developer_action', array(
237
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
238
+ 'align' => 'left',
239
+ 'width' => '100px',
240
+ 'type' => 'text',
241
+ 'renderer' => 'M2ePro/adminhtml_listing_view_grid_column_renderer_developerAction',
242
+ 'index' => 'value',
243
+ 'filter' => false,
244
+ 'sortable' => false,
245
+ 'js_handler' => 'ListingGridHandlerObj'
246
+ ));
247
+ }
248
+
249
+ return parent::_prepareColumns();
250
+ }
251
+
252
+ protected function _prepareMassaction()
253
+ {
254
+ // Set massaction identifiers
255
+ // ---------------------------------------
256
+ $this->setMassactionIdField('id');
257
+ $this->setMassactionIdFieldOnlyIndexValue(true);
258
+ // ---------------------------------------
259
+
260
+ // Set mass-action
261
+ // ---------------------------------------
262
+ $groups = array(
263
+ 'actions' => Mage::helper('M2ePro')->__('Actions'),
264
+ 'edit_fulfillment' => Mage::helper('M2ePro')->__('Fulfillment')
265
+ );
266
+
267
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled()) {
268
+ $groups['edit_repricing'] = Mage::helper('M2ePro')->__('Repricing Tool');
269
+ }
270
+
271
+ $this->getMassactionBlock()->setGroups($groups);
272
+
273
+ $this->getMassactionBlock()->addItem('revise', array(
274
+ 'label' => Mage::helper('M2ePro')->__('Revise Item(s)'),
275
+ 'url' => '',
276
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
277
+ ), 'actions');
278
+
279
+ $this->getMassactionBlock()->addItem('relist', array(
280
+ 'label' => Mage::helper('M2ePro')->__('Relist Item(s)'),
281
+ 'url' => '',
282
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
283
+ ), 'actions');
284
+
285
+ $this->getMassactionBlock()->addItem('stop', array(
286
+ 'label' => Mage::helper('M2ePro')->__('Stop Item(s)'),
287
+ 'url' => '',
288
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
289
+ ), 'actions');
290
+
291
+ $this->getMassactionBlock()->addItem('stopAndRemove', array(
292
+ 'label' => Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing'),
293
+ 'url' => '',
294
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
295
+ ), 'actions');
296
+
297
+ $this->getMassactionBlock()->addItem('deleteAndRemove', array(
298
+ 'label' => Mage::helper('M2ePro')->__('Remove from Channel & Listing'),
299
+ 'url' => '',
300
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
301
+ ), 'actions');
302
+
303
+ $this->getMassactionBlock()->addItem('switchToAfn', array(
304
+ 'label' => Mage::helper('M2ePro')->__('Switch to AFN'),
305
+ 'url' => '',
306
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
307
+ ), 'edit_fulfillment');
308
+
309
+ $this->getMassactionBlock()->addItem('switchToMfn', array(
310
+ 'label' => Mage::helper('M2ePro')->__('Switch to MFN'),
311
+ 'url' => '',
312
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
313
+ ), 'edit_fulfillment');
314
+
315
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled()) {
316
+ $this->getMassactionBlock()->addItem('addToRepricing', array(
317
+ 'label' => Mage::helper('M2ePro')->__('Add Item(s)'),
318
+ 'url' => '',
319
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
320
+ ), 'edit_repricing');
321
+
322
+ $this->getMassactionBlock()->addItem('editRepricing', array(
323
+ 'label' => Mage::helper('M2ePro')->__('Edit Item(s)'),
324
+ 'url' => '',
325
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
326
+ ), 'edit_repricing');
327
+
328
+ $this->getMassactionBlock()->addItem('removeFromRepricing', array(
329
+ 'label' => Mage::helper('M2ePro')->__('Remove Item(s)'),
330
+ 'url' => '',
331
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
332
+ ), 'edit_repricing');
333
+ }
334
+ // ---------------------------------------
335
+
336
+ return parent::_prepareMassaction();
337
+ }
338
+
339
+ //########################################
340
+
341
+ public function callbackColumnProductId($value, $row, $column, $isExport)
342
+ {
343
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
344
+
345
+ $storeId = (int)$listingData['store_id'];
346
+
347
+ $withoutImageHtml = '<a href="'
348
+ .$this->getUrl('adminhtml/catalog_product/edit',
349
+ array('id' => $value))
350
+ .'" target="_blank">'.$value.'</a>';
351
+
352
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
353
+ ->getGroupValue('/view/',
354
+ 'show_products_thumbnails');
355
+ if (!$showProductsThumbnails) {
356
+ return $withoutImageHtml;
357
+ }
358
+
359
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
360
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
361
+ $magentoProduct->setProductId($value);
362
+ $magentoProduct->setStoreId($storeId);
363
+
364
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
365
+ if (is_null($imageUrlResized)) {
366
+ return $withoutImageHtml;
367
+ }
368
+
369
+ $imageHtml = $value.'<hr style="border: 1px solid silver; border-bottom: none;"><img src="'.
370
+ $imageUrlResized.'" />';
371
+ $withImageHtml = str_replace('>'.$value.'<','>'.$imageHtml.'<',$withoutImageHtml);
372
+
373
+ return $withImageHtml;
374
+ }
375
+
376
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
377
+ {
378
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
379
+
380
+ $value = '<span>'.$productTitle.'</span>';
381
+
382
+ $tempSku = $row->getData('sku');
383
+ is_null($tempSku)
384
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
385
+
386
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
387
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
388
+
389
+ $listingProduct = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'));
390
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */
391
+ $variationManager = $listingProduct->getChildObject()->getVariationManager();
392
+
393
+ if (!$variationManager->isVariationProduct()) {
394
+ return $value;
395
+ }
396
+
397
+ if ($variationManager->isRelationChildType()) {
398
+ $typeModel = $variationManager->getTypeModel();
399
+
400
+ $productOptions = $typeModel->getProductOptions();
401
+ $channelOptions = $typeModel->getChannelOptions();
402
+
403
+ $parentTypeModel = $variationManager->getTypeModel()->getParentTypeModel();
404
+
405
+ $virtualProductAttributes = array_keys($parentTypeModel->getVirtualProductAttributes());
406
+ $virtualChannelAttributes = array_keys($parentTypeModel->getVirtualChannelAttributes());
407
+
408
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $parentAmazonListingProduct */
409
+ $parentAmazonListingProduct = $typeModel->getParentListingProduct()->getChildObject();
410
+
411
+ $matchedAttributes = $parentAmazonListingProduct->getVariationManager()
412
+ ->getTypeModel()
413
+ ->getMatchedAttributes();
414
+
415
+ if (!empty($matchedAttributes)) {
416
+
417
+ $sortedOptions = array();
418
+
419
+ foreach ($matchedAttributes as $magentoAttr => $amazonAttr) {
420
+ $sortedOptions[$amazonAttr] = $channelOptions[$amazonAttr];
421
+ }
422
+
423
+ $channelOptions = $sortedOptions;
424
+ }
425
+
426
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
427
+ Mage::helper('M2ePro')->__('Magento Variation') . '</div>';
428
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
429
+ foreach ($productOptions as $attribute => $option) {
430
+ $style = '';
431
+ if (in_array($attribute, $virtualProductAttributes)) {
432
+ $style = 'border-bottom: 2px dotted grey';
433
+ }
434
+
435
+ !$option && $option = '--';
436
+ $value .= '<span style="' . $style . '"><b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
437
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '</span><br/>';
438
+ }
439
+ $value .= '</div>';
440
+
441
+ $value .= '<div style="font-weight:bold;font-size: 11px;color: grey;margin-left: 7px;margin-top: 5px;">'.
442
+ Mage::helper('M2ePro')->__('Amazon Variation') . '</div>';
443
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 24px">';
444
+ foreach ($channelOptions as $attribute => $option) {
445
+ $style = '';
446
+ if (in_array($attribute, $virtualChannelAttributes)) {
447
+ $style = 'border-bottom: 2px dotted grey';
448
+ }
449
+
450
+ !$option && $option = '--';
451
+ $value .= '<span style="' . $style . '"><b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
452
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '</span><br/>';
453
+ }
454
+ $value .= '</div>';
455
+
456
+ return $value;
457
+ }
458
+
459
+ $productOptions = array();
460
+ if ($listingProduct->getChildObject()->getVariationManager()->getTypeModel()->isVariationProductMatched()) {
461
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()
462
+ ->getTypeModel()->getProductOptions();
463
+ }
464
+
465
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
466
+ foreach ($productOptions as $attribute => $option) {
467
+ !$option && $option = '--';
468
+ $value .= '<b>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
469
+ '</b>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
470
+ }
471
+ $value .= '</div>';
472
+
473
+ return $value;
474
+ }
475
+
476
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
477
+ {
478
+ if (is_null($value) || $value === '') {
479
+ $value = Mage::helper('M2ePro')->__('N/A');
480
+ }
481
+
482
+ if ($row->getData('defected_messages')) {
483
+ $defectedMessages = json_decode($row->getData('defected_messages'), true);
484
+
485
+ $msg = '';
486
+ foreach ($defectedMessages as $message) {
487
+ $msg .= '<p>'.$message['message'] . '&nbsp;';
488
+ if (!empty($message['value'])) {
489
+ $msg .= Mage::helper('M2ePro')->__('Current Value') . ': "' . $message['value'] . '"';
490
+ }
491
+ $msg .= '</p>';
492
+ }
493
+
494
+ $value .= <<<HTML
495
+ <span style="float:right;">
496
+ <img id="map_link_defected_message_icon_{$row->getId()}"
497
+ class="tool-tip-image"
498
+ style="vertical-align: middle;"
499
+ src="{$this->getSkinUrl('M2ePro/images/warning.png')}">
500
+ <span class="tool-tip-message tool-tip-warning tip-left" style="display:none;">
501
+ <img src="{$this->getSkinUrl('M2ePro/images/i_notice.gif')}">
502
+ <span>{$msg}</span>
503
+ </span>
504
+ </span>
505
+ HTML;
506
+ }
507
+
508
+ return $value;
509
+ }
510
+
511
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
512
+ {
513
+ if (is_null($value) || $value === '') {
514
+ return Mage::helper('M2ePro')->__('N/A');
515
+ }
516
+
517
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
518
+
519
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
520
+ $value,
521
+ $marketplaceId
522
+ );
523
+
524
+ $parentAsinHtml = '';
525
+ $variationParentId = $row->getData('variation_parent_id');
526
+ if (!empty($variationParentId)) {
527
+ $parentAsinHtml = '<br/><span style="display: block;
528
+ margin-bottom: 5px;
529
+ font-size: 10px;
530
+ color: grey;">'.
531
+ Mage::helper('M2ePro')->__('child ASIN/ISBN<br/>of parent %parent_asin%',
532
+ $this->getParentAsin($row->getData('id'))) . '</span>';
533
+ }
534
+
535
+ $generalIdOwnerHtml = '';
536
+ if ($row->getData('is_general_id_owner') == 1) {
537
+ $generalIdOwnerHtml = '<span style="font-size: 10px; color: grey; display: block;">'.
538
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
539
+ '</span>';
540
+ }
541
+ return <<<HTML
542
+ <a href="{$url}" target="_blank">{$value}</a>{$parentAsinHtml}{$generalIdOwnerHtml}
543
+ HTML;
544
+ }
545
+
546
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
547
+ {
548
+ if ((int)$row->getData('is_in_stock') <= 0) {
549
+ return '<span style="color: red;">'.$value.'</span>';
550
+ }
551
+
552
+ return $value;
553
+ }
554
+
555
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
556
+ {
557
+ if ((bool)$row->getData('is_afn_channel')) {
558
+ $sku = $row->getData('amazon_sku');
559
+
560
+ if (empty($sku)) {
561
+ return Mage::helper('M2ePro')->__('AFN');
562
+ }
563
+
564
+ $productId = $row->getData('id');
565
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
566
+ $listingProduct = Mage::helper('M2ePro/Component_Amazon')->getObject('Listing_Product',$productId);
567
+
568
+ $afn = Mage::helper('M2ePro')->__('AFN');
569
+ $total = Mage::helper('M2ePro')->__('Total');
570
+ $inStock = Mage::helper('M2ePro')->__('In Stock');
571
+ $accountId = $listingProduct->getListing()->getAccountId();
572
+
573
+ return <<<HTML
574
+ <div id="m2ePro_afn_qty_value_{$productId}">
575
+ <span class="m2ePro-online-sku-value" productId="{$productId}" style="display: none">{$sku}</span>
576
+ <span class="m2epro-empty-afn-qty-data" style="display: none">{$afn}</span>
577
+ <div class="m2epro-afn-qty-data" style="display: none">
578
+ <div class="total">{$total}: <span></span></div>
579
+ <div class="in-stock">{$inStock}: <span></span></div>
580
+ </div>
581
+ <a href="javascript:void(0)"
582
+ onclick="CommonAmazonListingAfnQtyHandlerObj.showAfnQty(this,'{$sku}',{$productId}, {$accountId})">
583
+ {$afn}
584
+ </a>
585
+ </div>
586
+ HTML;
587
+ }
588
+
589
+ if (is_null($value) || $value === '') {
590
+ return '<i style="color:gray;">receiving...</i>';
591
+ }
592
+
593
+ if ($value <= 0) {
594
+ return '<span style="color: red;">0</span>';
595
+ }
596
+
597
+ return $value;
598
+ }
599
+
600
+ public function callbackColumnPrice($value, $row, $column, $isExport)
601
+ {
602
+ $onlinePrice = $row->getData('online_price');
603
+
604
+ $repricingHtml ='';
605
+
606
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() &&
607
+ (int)$row->getData('is_repricing') === Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES) {
608
+ $text = Mage::helper('M2ePro')->__(
609
+ 'This product is used by Amazon Repricing Tool.
610
+ The Price cannot be updated through the M2E Pro.'
611
+ );
612
+
613
+ $repricingHtml = <<<HTML
614
+ <span style="float:right; text-align: left;">
615
+ <img class="tool-tip-image"
616
+ style="vertical-align: middle; width: 16px;"
617
+ src="{$this->getSkinUrl('M2ePro/images/money.png')}">
618
+ <span class="tool-tip-message tool-tip-message tip-left" style="display:none;">
619
+ <img src="{$this->getSkinUrl('M2ePro/images/i_icon.png')}">
620
+ <span>{$text}</span>
621
+ </span>
622
+ </span>
623
+ HTML;
624
+ }
625
+
626
+ if (is_null($onlinePrice) || $onlinePrice === '') {
627
+ if ($row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
628
+ return Mage::helper('M2ePro')->__('N/A') . $repricingHtml;
629
+ } else {
630
+ return '<i style="color:gray;">receiving...</i>' . $repricingHtml;
631
+ }
632
+ }
633
+
634
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
635
+ $currency = Mage::helper('M2ePro/Component_Amazon')
636
+ ->getCachedObject('Marketplace',$marketplaceId)
637
+ ->getChildObject()
638
+ ->getDefaultCurrency();
639
+
640
+ if ((float)$onlinePrice <= 0) {
641
+ $priceValue = '<span style="color: #f00;">0</span>';
642
+ } else {
643
+ $priceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($onlinePrice);
644
+ }
645
+
646
+ $resultHtml = '';
647
+
648
+ $salePrice = $row->getData('online_sale_price');
649
+ if ((float)$salePrice > 0) {
650
+ $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false,'Y-m-d 00:00:00'));
651
+
652
+ $startDateTimestamp = strtotime($row->getData('online_sale_price_start_date'));
653
+ $endDateTimestamp = strtotime($row->getData('online_sale_price_end_date'));
654
+
655
+ if ($currentTimestamp <= $endDateTimestamp) {
656
+ $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png');
657
+ $toolTipIconPath = $this->getSkinUrl('M2ePro/images/i_icon.png');
658
+
659
+ $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
660
+
661
+ $fromDate = Mage::app()->getLocale()->date(
662
+ $row->getData('online_sale_price_start_date'), $dateFormat
663
+ )->toString($dateFormat);
664
+ $toDate = Mage::app()->getLocale()->date(
665
+ $row->getData('online_sale_price_end_date'), $dateFormat
666
+ )->toString($dateFormat);
667
+
668
+ $intervalHtml = '<img class="tool-tip-image"
669
+ style="vertical-align: middle;"
670
+ src="'.$toolTipIconPath.'"><span class="tool-tip-message" style="display:none;
671
+ text-align: left;
672
+ width: 120px;
673
+ background: #E3E3E3;">
674
+ <img src="'.$iconHelpPath.'">
675
+ <span style="color:gray;">
676
+ <strong>From:</strong> '.$fromDate.'<br/>
677
+ <strong>To:</strong> '.$toDate.'
678
+ </span>
679
+ </span>';
680
+
681
+ $salePriceValue = Mage::app()->getLocale()->currency($currency)->toCurrency($salePrice);
682
+
683
+ if ($currentTimestamp >= $startDateTimestamp &&
684
+ $currentTimestamp <= $endDateTimestamp &&
685
+ $salePrice < (float)$onlinePrice
686
+ ) {
687
+ $resultHtml .= '<span style="color: grey; text-decoration: line-through;">'.$priceValue.'</span>' .
688
+ $repricingHtml;
689
+ $resultHtml .= '<br/>'.$intervalHtml.'&nbsp;'.$salePriceValue;
690
+ } else {
691
+ $resultHtml .= $priceValue . $repricingHtml;
692
+ $resultHtml .= '<br/>'.$intervalHtml.
693
+ '<span style="color:gray;">'.'&nbsp;'.$salePriceValue.'</span>';
694
+ }
695
+ }
696
+ }
697
+
698
+ if (empty($resultHtml)) {
699
+ $resultHtml = $priceValue . $repricingHtml;
700
+ }
701
+
702
+ return $resultHtml;
703
+ }
704
+
705
+ public function callbackColumnStatus($value, $row, $column, $isExport)
706
+ {
707
+ switch ($row->getData('amazon_status')) {
708
+
709
+ case Ess_M2ePro_Model_Listing_Product::STATUS_UNKNOWN:
710
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
711
+ $value = '<span style="color: gray;">' . $value . '</span>';
712
+ break;
713
+
714
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
715
+ $value = '<span style="color: green;">' . $value . '</span>';
716
+ break;
717
+
718
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
719
+ $value = '<span style="color: red;">'.$value.'</span>';
720
+ break;
721
+
722
+ case Ess_M2ePro_Model_Listing_Product::STATUS_BLOCKED:
723
+ $value = '<span style="color: orange; font-weight: bold;">'.$value.'</span>';
724
+ break;
725
+
726
+ default:
727
+ break;
728
+ }
729
+
730
+ $value .= $this->getViewLogIconHtml($row->getData('id'));
731
+
732
+ $tempLocks = $this->getLockedData($row);
733
+ $tempLocks = $tempLocks['object_locks'];
734
+
735
+ foreach ($tempLocks as $lock) {
736
+
737
+ switch ($lock->getTag()) {
738
+
739
+ case 'list_action':
740
+ $value .= '<br/><span style="color: #605fff">[List in Progress...]</span>';
741
+ break;
742
+
743
+ case 'relist_action':
744
+ $value .= '<br/><span style="color: #605fff">[Relist in Progress...]</span>';
745
+ break;
746
+
747
+ case 'revise_action':
748
+ $value .= '<br/><span style="color: #605fff">[Revise in Progress...]</span>';
749
+ break;
750
+
751
+ case 'stop_action':
752
+ $value .= '<br/><span style="color: #605fff">[Stop in Progress...]</span>';
753
+ break;
754
+
755
+ case 'stop_and_remove_action':
756
+ $value .= '<br/><span style="color: #605fff">[Stop And Remove in Progress...]</span>';
757
+ break;
758
+
759
+ case 'delete_and_remove_action':
760
+ $value .= '<br/><span style="color: #605fff">[Remove in Progress...]</span>';
761
+ break;
762
+
763
+ case 'switch_to_afn_action':
764
+ $value .= '<br/><span style="color: #605fff">[Switch to AFN in Progress...]</span>';
765
+ break;
766
+
767
+ case 'switch_to_mfn_action':
768
+ $value .= '<br/><span style="color: #605fff">[Switch to MFN in Progress...]</span>';
769
+ break;
770
+
771
+ default:
772
+ break;
773
+
774
+ }
775
+ }
776
+
777
+ return $value;
778
+ }
779
+
780
+ protected function callbackFilterTitle($collection, $column)
781
+ {
782
+ $value = $column->getFilter()->getValue();
783
+
784
+ if ($value == null) {
785
+ return;
786
+ }
787
+
788
+ $collection->addFieldToFilter(
789
+ array(
790
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
791
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
792
+ )
793
+ );
794
+ }
795
+
796
+ protected function callbackFilterQty($collection, $column)
797
+ {
798
+ $value = $column->getFilter()->getValue();
799
+
800
+ if (empty($value)) {
801
+ return;
802
+ }
803
+
804
+ $where = '';
805
+
806
+ if (isset($value['from']) && $value['from'] != '') {
807
+ $where .= 'online_qty >= ' . $value['from'];
808
+ }
809
+
810
+ if (isset($value['to']) && $value['to'] != '') {
811
+ if (isset($value['from']) && $value['from'] != '') {
812
+ $where .= ' AND ';
813
+ }
814
+ $where .= 'online_qty <= ' . $value['to'];
815
+ }
816
+
817
+ if (!empty($value['afn'])) {
818
+ if (!empty($where)) {
819
+ $where = '(' . $where . ') OR ';
820
+ }
821
+ $where .= 'is_afn_channel = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_AFN_CHANNEL_YES;
822
+ }
823
+
824
+ $collection->getSelect()->where($where);
825
+ }
826
+
827
+ protected function callbackFilterPrice($collection, $column)
828
+ {
829
+ $value = $column->getFilter()->getValue();
830
+
831
+ if (empty($value)) {
832
+ return;
833
+ }
834
+
835
+ $condition = '';
836
+
837
+ if (isset($value['from']) && $value['from'] != '') {
838
+ $condition = 'min_online_price >= \''.$value['from'].'\'';
839
+ }
840
+ if (isset($value['to']) && $value['to'] != '') {
841
+ if (isset($value['from']) && $value['from'] != '') {
842
+ $condition .= ' AND ';
843
+ }
844
+ $condition .= 'min_online_price <= \''.$value['to'].'\'';
845
+ }
846
+
847
+ if (Mage::helper('M2ePro/Component_Amazon')->isRepricingEnabled() && !empty($value['is_repricing'])) {
848
+ if (!empty($condition)) {
849
+ $condition = '(' . $condition . ') OR ';
850
+ }
851
+ $condition .= 'is_repricing = ' . Ess_M2ePro_Model_Amazon_Listing_Product::IS_REPRICING_YES;
852
+ }
853
+
854
+ $collection->getSelect()->having($condition);
855
+ }
856
+
857
+ // ---------------------------------------
858
+
859
+ public function getViewLogIconHtml($listingProductId)
860
+ {
861
+ $listingProductId = (int)$listingProductId;
862
+
863
+ // Get last messages
864
+ // ---------------------------------------
865
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
866
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
867
+
868
+ $dbSelect = $connRead->select()
869
+ ->from(
870
+ Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(),
871
+ array('action_id','action','type','description','create_date','initiator')
872
+ )
873
+ ->where('`listing_product_id` = ?',$listingProductId)
874
+ ->where('`action_id` IS NOT NULL')
875
+ ->order(array('id DESC'))
876
+ ->limit(30);
877
+
878
+ $logRows = $connRead->fetchAll($dbSelect);
879
+ // ---------------------------------------
880
+
881
+ // Get grouped messages by action_id
882
+ // ---------------------------------------
883
+ $actionsRows = array();
884
+ $tempActionRows = array();
885
+ $lastActionId = false;
886
+
887
+ foreach ($logRows as $row) {
888
+
889
+ $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']);
890
+
891
+ if ($row['action_id'] !== $lastActionId) {
892
+ if (count($tempActionRows) > 0) {
893
+ $actionsRows[] = array(
894
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
895
+ 'date' => $this->getMainDateForActionId($tempActionRows),
896
+ 'action' => $this->getActionForAction($tempActionRows[0]),
897
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
898
+ 'items' => $tempActionRows
899
+ );
900
+ $tempActionRows = array();
901
+ }
902
+ $lastActionId = $row['action_id'];
903
+ }
904
+ $tempActionRows[] = $row;
905
+ }
906
+
907
+ if (count($tempActionRows) > 0) {
908
+ $actionsRows[] = array(
909
+ 'type' => $this->getMainTypeForActionId($tempActionRows),
910
+ 'date' => $this->getMainDateForActionId($tempActionRows),
911
+ 'action' => $this->getActionForAction($tempActionRows[0]),
912
+ 'initiator' => $this->getInitiatorForAction($tempActionRows[0]),
913
+ 'items' => $tempActionRows
914
+ );
915
+ }
916
+
917
+ if (count($actionsRows) <= 0) {
918
+ return '';
919
+ }
920
+
921
+ foreach ($actionsRows as &$actionsRow) {
922
+ usort($actionsRow['items'], function($a, $b)
923
+ {
924
+ $sortOrder = array(
925
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1,
926
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2,
927
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3,
928
+ );
929
+
930
+ return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
931
+ });
932
+ }
933
+
934
+ $tips = array(
935
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.',
936
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).',
937
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'
938
+ );
939
+
940
+ $icons = array(
941
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
942
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
943
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
944
+ );
945
+
946
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
947
+ 'entity_id' => $listingProductId,
948
+ 'rows' => $actionsRows,
949
+ 'tips' => $tips,
950
+ 'icons' => $icons,
951
+ 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp',
952
+ 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp',
953
+ ));
954
+
955
+ return $summary->toHtml();
956
+ }
957
+
958
+ public function getActionForAction($actionRows)
959
+ {
960
+ $string = '';
961
+
962
+ switch ($actionRows['action']) {
963
+ case Ess_M2ePro_Model_Listing_Log::ACTION_LIST_PRODUCT_ON_COMPONENT:
964
+ $string = Mage::helper('M2ePro')->__('List');
965
+ break;
966
+ case Ess_M2ePro_Model_Listing_Log::ACTION_RELIST_PRODUCT_ON_COMPONENT:
967
+ $string = Mage::helper('M2ePro')->__('Relist');
968
+ break;
969
+ case Ess_M2ePro_Model_Listing_Log::ACTION_REVISE_PRODUCT_ON_COMPONENT:
970
+ $string = Mage::helper('M2ePro')->__('Revise');
971
+ break;
972
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_PRODUCT_ON_COMPONENT:
973
+ $string = Mage::helper('M2ePro')->__('Stop');
974
+ break;
975
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_PRODUCT_FROM_COMPONENT:
976
+ $string = Mage::helper('M2ePro')->__('Remove from Channel');
977
+ break;
978
+ case Ess_M2ePro_Model_Listing_Log::ACTION_STOP_AND_REMOVE_PRODUCT:
979
+ $string = Mage::helper('M2ePro')->__('Stop on Channel / Remove from Listing');
980
+ break;
981
+ case Ess_M2ePro_Model_Listing_Log::ACTION_DELETE_AND_REMOVE_PRODUCT:
982
+ $string = Mage::helper('M2ePro')->__('Remove from Channel & Listing');
983
+ break;
984
+ case Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE:
985
+ $string = Mage::helper('M2ePro')->__('Channel Change');
986
+ break;
987
+ case Ess_M2ePro_Model_Listing_Log::ACTION_SWITCH_TO_AFN_ON_COMPONENT:
988
+ $string = Mage::helper('M2ePro')->__('Switch to AFN');
989
+ break;
990
+ case Ess_M2ePro_Model_Listing_Log::ACTION_SWITCH_TO_MFN_ON_COMPONENT:
991
+ $string = Mage::helper('M2ePro')->__('Switch to MFN');
992
+ break;
993
+ }
994
+
995
+ return $string;
996
+ }
997
+
998
+ public function getInitiatorForAction($actionRows)
999
+ {
1000
+ $string = '';
1001
+
1002
+ switch ((int)$actionRows['initiator']) {
1003
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
1004
+ $string = '';
1005
+ break;
1006
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
1007
+ $string = Mage::helper('M2ePro')->__('Manual');
1008
+ break;
1009
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
1010
+ $string = Mage::helper('M2ePro')->__('Automatic');
1011
+ break;
1012
+ }
1013
+
1014
+ return $string;
1015
+ }
1016
+
1017
+ public function getMainTypeForActionId($actionRows)
1018
+ {
1019
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS;
1020
+
1021
+ foreach ($actionRows as $row) {
1022
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR) {
1023
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR;
1024
+ break;
1025
+ }
1026
+ if ($row['type'] == Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING) {
1027
+ $type = Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING;
1028
+ }
1029
+ }
1030
+
1031
+ return $type;
1032
+ }
1033
+
1034
+ public function getMainDateForActionId($actionRows)
1035
+ {
1036
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
1037
+ return Mage::app()->getLocale()->date(strtotime($actionRows[0]['create_date']))->toString($format);
1038
+ }
1039
+
1040
+ //########################################
1041
+
1042
+ public function getGridUrl()
1043
+ {
1044
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
1045
+ }
1046
+
1047
+ public function getRowUrl($row)
1048
+ {
1049
+ return false;
1050
+ }
1051
+
1052
+ //########################################
1053
+
1054
+ protected function _toHtml()
1055
+ {
1056
+ $javascriptsMain = <<<HTML
1057
+ <script type="text/javascript">
1058
+
1059
+ if (typeof ListingGridHandlerObj != 'undefined') {
1060
+ ListingGridHandlerObj.afterInitPage();
1061
+ }
1062
+
1063
+ Event.observe(window, 'load', function() {
1064
+ setTimeout(function() {
1065
+ ListingGridHandlerObj.afterInitPage();
1066
+ }, 350);
1067
+ });
1068
+
1069
+ </script>
1070
+ HTML;
1071
+
1072
+ return parent::_toHtml().$javascriptsMain;
1073
+ }
1074
+
1075
+ public function getEmptyText()
1076
+ {
1077
+ return Mage::helper('M2ePro')->__(
1078
+ 'Only Simple and Child Products listed on Amazon will be shown in Seller Сentral View Mode.'
1079
+ );
1080
+ }
1081
+
1082
+ //########################################
1083
+
1084
+ private function getLockedData($row)
1085
+ {
1086
+ $listingProductId = $row->getData('id');
1087
+ if (!isset($this->lockedDataCache[$listingProductId])) {
1088
+ $objectLocks = Mage::getModel('M2ePro/Listing_Product')->load($row->getData('id'))->getObjectLocks();
1089
+ $tempArray = array(
1090
+ 'object_locks' => $objectLocks,
1091
+ 'in_action' => !empty($objectLocks),
1092
+ );
1093
+ $this->lockedDataCache[$listingProductId] = $tempArray;
1094
+ }
1095
+
1096
+ return $this->lockedDataCache[$listingProductId];
1097
+ }
1098
+
1099
+ //########################################
1100
+
1101
+ private function getParentAsin($childId)
1102
+ {
1103
+ if (is_null($this->parentAsins)) {
1104
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
1105
+ $tableAmazonListingProduct = Mage::getSingleton('core/resource')
1106
+ ->getTableName('m2epro_amazon_listing_product');
1107
+
1108
+ $select = $connRead->select();
1109
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id','variation_parent_id'))
1110
+ ->where('listing_product_id IN (?)', $this->getCollection()->getAllIds())
1111
+ ->where('variation_parent_id IS NOT NULL');
1112
+
1113
+ $parentIds = Mage::getResourceModel('core/config')
1114
+ ->getReadConnection()
1115
+ ->fetchPairs($select);
1116
+
1117
+ $select = $connRead->select();
1118
+ $select->from(array('alp' => $tableAmazonListingProduct), array('listing_product_id', 'general_id'))
1119
+ ->where('listing_product_id IN (?)', $parentIds);
1120
+
1121
+ $parentAsins = Mage::getResourceModel('core/config')
1122
+ ->getReadConnection()
1123
+ ->fetchPairs($select);
1124
+
1125
+ $this->parentAsins = array();
1126
+ foreach ($parentIds as $childId => $parentId) {
1127
+ $this->parentAsins[$childId] = $parentAsins[$parentId];
1128
+ }
1129
+ }
1130
+
1131
+ return $this->parentAsins[$childId];
1132
+ }
1133
+
1134
+ //########################################
1135
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Listing/View/Settings/Grid.php ADDED
@@ -0,0 +1,702 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Listing_View_Settings_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('amazonListingViewSettingsGrid'.$listingData['id']);
23
+ // ---------------------------------------
24
+
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->setListingProductModeOn();
55
+ $collection
56
+ ->addAttributeToSelect('name')
57
+ ->addAttributeToSelect('sku')
58
+ ->joinTable(
59
+ array('cisi' => 'cataloginventory/stock_item'),
60
+ 'product_id=entity_id',
61
+ array('qty' => 'qty'),
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
+ 'component_mode' => 'component_mode',
74
+ 'amazon_status' => 'status',
75
+ 'additional_data' => 'additional_data'
76
+ ),
77
+ array(
78
+ 'listing_id' => (int)$listingData['id']
79
+ )
80
+ );
81
+ $collection->joinTable(
82
+ array('alp' => 'M2ePro/Amazon_Listing_Product'),
83
+ 'listing_product_id=id',
84
+ array(
85
+ 'template_shipping_override_id' => 'template_shipping_override_id',
86
+ 'template_description_id' => 'template_description_id',
87
+ 'general_id' => 'general_id',
88
+ 'general_id_search_info' => 'general_id_search_info',
89
+ 'search_settings_status' => 'search_settings_status',
90
+ 'search_settings_data' => 'search_settings_data',
91
+ 'variation_child_statuses' => 'variation_child_statuses',
92
+ 'amazon_sku' => 'sku',
93
+ 'online_qty' => 'online_qty',
94
+ 'online_price' => 'online_price',
95
+ 'online_sale_price' => 'IF(
96
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
97
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
98
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
99
+ `alp`.`online_sale_price`,
100
+ NULL
101
+ )',
102
+ 'online_sale_price_start_date' => 'online_sale_price_start_date',
103
+ 'online_sale_price_end_date' => 'online_sale_price_end_date',
104
+ 'is_afn_channel' => 'is_afn_channel',
105
+ 'is_general_id_owner' => 'is_general_id_owner',
106
+ 'is_variation_parent' => 'is_variation_parent',
107
+ 'defected_messages' => 'defected_messages',
108
+ 'min_online_price' => 'IF(
109
+ (`t`.`variation_min_price` IS NULL),
110
+ IF(
111
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
112
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
113
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
114
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
115
+ `alp`.`online_sale_price`,
116
+ `alp`.`online_price`
117
+ ),
118
+ `t`.`variation_min_price`
119
+ )',
120
+ 'max_online_price' => 'IF(
121
+ (`t`.`variation_max_price` IS NULL),
122
+ IF(
123
+ `alp`.`online_sale_price_start_date` IS NOT NULL AND
124
+ `alp`.`online_sale_price_end_date` IS NOT NULL AND
125
+ `alp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
126
+ `alp`.`online_sale_price_end_date` >= CURRENT_DATE(),
127
+ `alp`.`online_sale_price`,
128
+ `alp`.`online_price`
129
+ ),
130
+ `t`.`variation_max_price`
131
+ )'
132
+ ),
133
+ '{{table}}.variation_parent_id is NULL'
134
+ );
135
+
136
+ $collection->getSelect()->joinLeft(
137
+ new Zend_Db_Expr('(
138
+ SELECT
139
+ `malp`.`variation_parent_id`,
140
+ MIN(
141
+ IF(
142
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
143
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
144
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
145
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
146
+ `malp`.`online_sale_price`,
147
+ `malp`.`online_price`
148
+ )
149
+ ) as variation_min_price,
150
+ MAX(
151
+ IF(
152
+ `malp`.`online_sale_price_start_date` IS NOT NULL AND
153
+ `malp`.`online_sale_price_end_date` IS NOT NULL AND
154
+ `malp`.`online_sale_price_start_date` <= CURRENT_DATE() AND
155
+ `malp`.`online_sale_price_end_date` >= CURRENT_DATE(),
156
+ `malp`.`online_sale_price`,
157
+ `malp`.`online_price`
158
+ )
159
+ ) as variation_max_price
160
+ FROM `'. Mage::getResourceModel('M2ePro/Amazon_Listing_Product')->getMainTable() .'` as malp
161
+ INNER JOIN `'. Mage::getResourceModel('M2ePro/Listing_Product')->getMainTable() .'` AS `mlp`
162
+ ON (`malp`.`listing_product_id` = `mlp`.`id`)
163
+ WHERE `mlp`.`status` IN (
164
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_LISTED . ',
165
+ ' . Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED . '
166
+ ) AND `malp`.`variation_parent_id` IS NOT NULL
167
+ GROUP BY `malp`.`variation_parent_id`
168
+ )'),
169
+ 'alp.listing_product_id=t.variation_parent_id',
170
+ array(
171
+ 'variation_min_price' => 'variation_min_price',
172
+ 'variation_max_price' => 'variation_max_price',
173
+ )
174
+ );
175
+ $collection->joinTable(
176
+ array('td' => 'M2ePro/Template_Description'),
177
+ 'id=template_description_id',
178
+ array(
179
+ 'template_description_title' => 'title'
180
+ ),
181
+ null,
182
+ 'left'
183
+ );
184
+ $collection->joinTable(
185
+ array('tso' => 'M2ePro/Amazon_Template_ShippingOverride'),
186
+ 'id=template_shipping_override_id',
187
+ array(
188
+ 'template_shipping_override_title' => 'title'
189
+ ),
190
+ null,
191
+ 'left'
192
+ );
193
+
194
+ // ---------------------------------------
195
+
196
+ // Set collection to grid
197
+ $this->setCollection($collection);
198
+
199
+ return parent::_prepareCollection();
200
+ }
201
+
202
+ protected function _prepareColumns()
203
+ {
204
+ $this->addColumn('product_id', array(
205
+ 'header' => Mage::helper('M2ePro')->__('Product ID'),
206
+ 'align' => 'right',
207
+ 'width' => '100px',
208
+ 'type' => 'number',
209
+ 'index' => 'entity_id',
210
+ 'filter_index' => 'entity_id',
211
+ 'frame_callback' => array($this, 'callbackColumnProductId')
212
+ ));
213
+
214
+ $this->addColumn('name', array(
215
+ 'header' => Mage::helper('M2ePro')->__('Product Title / Product SKU'),
216
+ 'align' => 'left',
217
+ 'type' => 'text',
218
+ 'index' => 'name',
219
+ 'filter_index' => 'name',
220
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
221
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
222
+ ));
223
+
224
+ $this->addColumn('sku', array(
225
+ 'header' => Mage::helper('M2ePro')->__('SKU'),
226
+ 'align' => 'left',
227
+ 'width' => '150px',
228
+ 'type' => 'text',
229
+ 'index' => 'amazon_sku',
230
+ 'filter_index' => 'amazon_sku',
231
+ 'frame_callback' => array($this, 'callbackColumnAmazonSku')
232
+ ));
233
+
234
+ $this->addColumn('general_id', array(
235
+ 'header' => Mage::helper('M2ePro')->__('ASIN / ISBN'),
236
+ 'align' => 'left',
237
+ 'width' => '140px',
238
+ 'type' => 'text',
239
+ 'index' => 'general_id',
240
+ 'filter_index' => 'general_id',
241
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
242
+ ));
243
+
244
+ $this->addColumn('description_template', array(
245
+ 'header' => Mage::helper('M2ePro')->__('Description Policy'),
246
+ 'align' => 'left',
247
+ 'width' => '170px',
248
+ 'type' => 'text',
249
+ 'index' => 'template_description_title',
250
+ 'filter_index' => 'template_description_title',
251
+ 'frame_callback' => array($this, 'callbackColumnTemplateDescription')
252
+ ));
253
+
254
+ $this->addColumn('shipping_override_template', array(
255
+ 'header' => Mage::helper('M2ePro')->__('Shipping Override Policy'),
256
+ 'align' => 'left',
257
+ 'width' => '170px',
258
+ 'type' => 'text',
259
+ 'index' => 'template_shipping_override_title',
260
+ 'filter_index' => 'template_shipping_override_title',
261
+ 'frame_callback' => array($this, 'callbackColumnTemplateShippingOverride')
262
+ ));
263
+
264
+ $this->addColumn('actions', array(
265
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
266
+ 'align' => 'left',
267
+ 'width' => '100px',
268
+ 'type' => 'action',
269
+ 'index' => 'actions',
270
+ 'filter' => false,
271
+ 'sortable' => false,
272
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
273
+ 'field' => 'id',
274
+ 'group_order' => $this->getGroupOrder(),
275
+ 'actions' => $this->getColumnActionsItems()
276
+ ));
277
+
278
+ return parent::_prepareColumns();
279
+ }
280
+
281
+ //########################################
282
+
283
+ protected function getGroupOrder()
284
+ {
285
+ return array(
286
+ 'edit_template_description' => Mage::helper('M2ePro')->__('Description Policy'),
287
+ 'edit_template_shipping_override' => Mage::helper('M2ePro')->__('Shipping Override Policy'),
288
+ );
289
+ }
290
+
291
+ protected function getColumnActionsItems()
292
+ {
293
+ $helper = Mage::helper('M2ePro');
294
+
295
+ $actions = array(
296
+ 'assignTemplateDescription' => array(
297
+ 'caption' => $helper->__('Assign'),
298
+ 'group' => 'edit_template_description',
299
+ 'field' => 'id',
300
+ 'onclick_action' => 'ListingGridHandlerObj.actions[\'assignTemplateDescriptionIdAction\']'
301
+ ),
302
+
303
+ 'unassignTemplateDescription' => array(
304
+ 'caption' => $helper->__('Unassign'),
305
+ 'group' => 'edit_template_description',
306
+ 'field' => 'id',
307
+ 'onclick_action' => 'ListingGridHandlerObj.unassignTemplateDescriptionIdActionConfrim'
308
+ ),
309
+
310
+ 'assignTemplateShippingOverride' => array(
311
+ 'caption' => $helper->__('Assign'),
312
+ 'group' => 'edit_template_shipping_override',
313
+ 'field' => 'id',
314
+ 'onclick_action' => 'ListingGridHandlerObj.actions[\'assignTemplateShippingOverrideIdAction\']'
315
+ ),
316
+
317
+ 'unassignTemplateShippingOverride' => array(
318
+ 'caption' => $helper->__('Unassign'),
319
+ 'group' => 'edit_template_shipping_override',
320
+ 'field' => 'id',
321
+ 'onclick_action' => 'ListingGridHandlerObj.unassignTemplateShippingOverrideIdActionConfrim'
322
+ )
323
+ );
324
+
325
+ return $actions;
326
+ }
327
+
328
+ //########################################
329
+
330
+ protected function _prepareMassaction()
331
+ {
332
+ // Set massaction identifiers
333
+ // ---------------------------------------
334
+ $this->setMassactionIdField('id');
335
+ $this->setMassactionIdFieldOnlyIndexValue(true);
336
+ // ---------------------------------------
337
+
338
+ // Set mass-action
339
+ // ---------------------------------------
340
+ $groups = array(
341
+ 'description_policy' => Mage::helper('M2ePro')->__('Description Policy'),
342
+ 'shipping_override_policy' => Mage::helper('M2ePro')->__('Shipping Override Policy'),
343
+ 'other' => Mage::helper('M2ePro')->__('Other'),
344
+ );
345
+
346
+ $this->getMassactionBlock()->setGroups($groups);
347
+
348
+ $this->getMassactionBlock()->addItem('assignTemplateDescriptionId', array(
349
+ 'label' => Mage::helper('M2ePro')->__('Assign'),
350
+ 'url' => '',
351
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
352
+ ), 'description_policy');
353
+
354
+ $this->getMassactionBlock()->addItem('unassignTemplateDescriptionId', array(
355
+ 'label' => Mage::helper('M2ePro')->__('Unassign'),
356
+ 'url' => '',
357
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
358
+ ), 'description_policy');
359
+
360
+ $this->getMassactionBlock()->addItem('assignTemplateShippingOverrideId', array(
361
+ 'label' => Mage::helper('M2ePro')->__('Assign'),
362
+ 'url' => '',
363
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
364
+ ), 'shipping_override_policy');
365
+
366
+ $this->getMassactionBlock()->addItem('unassignTemplateShippingOverrideId', array(
367
+ 'label' => Mage::helper('M2ePro')->__('Unassign'),
368
+ 'url' => '',
369
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
370
+ ), 'shipping_override_policy');
371
+
372
+ $this->getMassactionBlock()->addItem('moving', array(
373
+ 'label' => Mage::helper('M2ePro')->__('Move Item(s) to Another Listing'),
374
+ 'url' => '',
375
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
376
+ ), 'other');
377
+
378
+ $this->getMassactionBlock()->addItem('duplicate', array(
379
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
380
+ 'url' => '',
381
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
382
+ ), 'other');
383
+ // ---------------------------------------
384
+
385
+ return parent::_prepareMassaction();
386
+ }
387
+
388
+ //########################################
389
+
390
+ public function callbackColumnProductId($value, $row, $column, $isExport)
391
+ {
392
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
393
+
394
+ $storeId = (int)$listingData['store_id'];
395
+
396
+ $withoutImageHtml = '<a href="'
397
+ .$this->getUrl('adminhtml/catalog_product/edit',
398
+ array('id' => $value))
399
+ .'" target="_blank">'.$value.'</a>';
400
+
401
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
402
+ ->getGroupValue('/view/',
403
+ 'show_products_thumbnails');
404
+ if (!$showProductsThumbnails) {
405
+ return $withoutImageHtml;
406
+ }
407
+
408
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
409
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
410
+ $magentoProduct->setProductId($value);
411
+ $magentoProduct->setStoreId($storeId);
412
+
413
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
414
+ if (is_null($imageUrlResized)) {
415
+ return $withoutImageHtml;
416
+ }
417
+
418
+ $imageHtml = $value.'<hr style="border: 1px solid silver; border-bottom: none;"><img src="'.
419
+ $imageUrlResized.'" />';
420
+ $withImageHtml = str_replace('>'.$value.'<','>'.$imageHtml.'<',$withoutImageHtml);
421
+
422
+ return $withImageHtml;
423
+ }
424
+
425
+ public function callbackColumnProductTitle($productTitle, $row, $column, $isExport)
426
+ {
427
+ $productTitle = Mage::helper('M2ePro')->escapeHtml($productTitle);
428
+
429
+ $value = '<span>'.$productTitle.'</span>';
430
+
431
+ $tempSku = $row->getData('sku');
432
+ is_null($tempSku)
433
+ && $tempSku = Mage::getModel('M2ePro/Magento_Product')->setProductId($row->getData('entity_id'))->getSku();
434
+
435
+ $value .= '<br/><strong>'.Mage::helper('M2ePro')->__('SKU') .
436
+ ':</strong> '.Mage::helper('M2ePro')->escapeHtml($tempSku) . '<br/>';
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()->getVariationManager()->isVariationProduct()) {
443
+ return $value;
444
+ }
445
+
446
+ /** @var Ess_M2ePro_Model_Amazon_Listing_Product $amazonListingProduct */
447
+ $amazonListingProduct = $listingProduct->getChildObject();
448
+ $variationManager = $amazonListingProduct->getVariationManager();
449
+
450
+ if ($variationManager->isRelationParentType()) {
451
+
452
+ $productAttributes = (array)$variationManager->getTypeModel()->getProductAttributes();
453
+ $virtualProductAttributes = $variationManager->getTypeModel()->getVirtualProductAttributes();
454
+ $virtualChannelAttributes = $variationManager->getTypeModel()->getVirtualChannelAttributes();
455
+
456
+ $value .= '<div style="font-size: 11px; font-weight: bold; color: grey; margin-left: 7px"><br/>';
457
+ $attributesStr = '';
458
+ if (empty($virtualProductAttributes) && empty($virtualChannelAttributes)) {
459
+ $attributesStr = implode(', ', $productAttributes);
460
+ } else {
461
+ foreach ($productAttributes as $attribute) {
462
+ if (in_array($attribute, array_keys($virtualProductAttributes))) {
463
+
464
+ $attributesStr .= '<span style="border-bottom: 2px dotted grey">' . $attribute .
465
+ ' (' . $virtualProductAttributes[$attribute] . ')</span>, ';
466
+
467
+ } else if (in_array($attribute, array_keys($virtualChannelAttributes))) {
468
+
469
+ $attributesStr .= '<span>' . $attribute .
470
+ ' (' . $virtualChannelAttributes[$attribute] . ')</span>, ';
471
+
472
+ } else {
473
+ $attributesStr .= $attribute . ', ';
474
+ }
475
+ }
476
+ $attributesStr = rtrim($attributesStr, ', ');
477
+ }
478
+ $value .= $attributesStr;
479
+
480
+ return $value;
481
+ }
482
+
483
+ $productOptions = $variationManager->getTypeModel()->getProductOptions();
484
+
485
+ if (!empty($productOptions)) {
486
+ $value .= '<div style="font-size: 11px; color: grey; margin-left: 7px"><br/>';
487
+ foreach ($productOptions as $attribute => $option) {
488
+ !$option && $option = '--';
489
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
490
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
491
+ }
492
+ $value .= '</div>';
493
+ }
494
+
495
+ return $value;
496
+ }
497
+
498
+ public function callbackColumnAmazonSku($value, $row, $column, $isExport)
499
+ {
500
+ if ((!$row->getData('is_variation_parent') &&
501
+ $row->getData('amazon_status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) ||
502
+ ($row->getData('is_variation_parent') && $row->getData('general_id') == '')) {
503
+
504
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
505
+ }
506
+
507
+ if (is_null($value) || $value === '') {
508
+ $value = Mage::helper('M2ePro')->__('N/A');
509
+ }
510
+
511
+ return $value;
512
+ }
513
+
514
+ // ---------------------------------------
515
+
516
+ public function callbackColumnGeneralId($generalId, $row, $column, $isExport)
517
+ {
518
+ if (empty($generalId)) {
519
+ if ($row->getData('is_general_id_owner') == 1) {
520
+ return Mage::helper('M2ePro')->__('New ASIN/ISBN');
521
+ }
522
+ return $this->getGeneralIdColumnValueEmptyGeneralId($row);
523
+ }
524
+
525
+ return $this->getGeneralIdColumnValueNotEmptyGeneralId($row);
526
+ }
527
+
528
+ private function getGeneralIdColumnValueEmptyGeneralId($row)
529
+ {
530
+ // ---------------------------------------
531
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
532
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
533
+ }
534
+
535
+ $iconPath = $this->getSkinUrl('M2ePro/images/search_statuses/');
536
+ $searchSettingsStatus = $row->getData('search_settings_status');
537
+
538
+ // ---------------------------------------
539
+ if ($searchSettingsStatus == Ess_M2ePro_Model_Amazon_Listing_Product::SEARCH_SETTINGS_STATUS_IN_PROGRESS) {
540
+
541
+ $tip = Mage::helper('M2ePro')->__('Automatic ASIN/ISBN Search in Progress.');
542
+ $iconSrc = $iconPath.'processing.gif';
543
+
544
+ return <<<HTML
545
+ &nbsp;
546
+ <a href="javascript: void(0);" title="{$tip}">
547
+ <img src="{$iconSrc}" alt="">
548
+ </a>
549
+ HTML;
550
+ }
551
+ // ---------------------------------------
552
+
553
+ return Mage::helper('M2ePro')->__('N/A');
554
+ }
555
+
556
+ private function getGeneralIdColumnValueNotEmptyGeneralId($row)
557
+ {
558
+ $generalId = $row->getData('general_id');
559
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
560
+
561
+ $url = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
562
+ $generalId,
563
+ $marketplaceId
564
+ );
565
+
566
+ $generalIdOwnerHtml = '';
567
+ if ($row->getData('is_general_id_owner') == Ess_M2ePro_Model_Amazon_Listing_Product::IS_GENERAL_ID_OWNER_YES) {
568
+
569
+ $generalIdOwnerHtml = '<br/><span style="font-size: 10px; color: grey;">'.
570
+ Mage::helper('M2ePro')->__('creator of ASIN/ISBN').
571
+ '</span>';
572
+ }
573
+
574
+ if ((int)$row->getData('amazon_status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
575
+
576
+ return <<<HTML
577
+ <a href="{$url}" target="_blank">{$generalId}</a>{$generalIdOwnerHtml}
578
+ HTML;
579
+ }
580
+
581
+ $generalIdSearchInfo = $row->getData('general_id_search_info');
582
+
583
+ if (!empty($generalIdSearchInfo)) {
584
+ $generalIdSearchInfo = @json_decode($generalIdSearchInfo, true);
585
+ }
586
+
587
+ if (!empty($generalIdSearchInfo['is_set_automatic'])) {
588
+
589
+ $tip = Mage::helper('M2ePro')->__('ASIN/ISBN was found automatically');
590
+
591
+ $text = <<<HTML
592
+ <a href="{$url}" target="_blank" title="{$tip}" style="color:#40AADB;">{$generalId}</a>
593
+ HTML;
594
+
595
+ } else {
596
+
597
+ $text = <<<HTML
598
+ <a href="{$url}" target="_blank">{$generalId}</a>
599
+ HTML;
600
+
601
+ }
602
+
603
+ return $text . $generalIdOwnerHtml;
604
+ }
605
+
606
+ // ---------------------------------------
607
+
608
+ public function callbackColumnTemplateDescription($value, $row, $column, $isExport)
609
+ {
610
+ $html = Mage::helper('M2ePro')->__('N/A');
611
+
612
+ if ($row->getData('template_description_id')) {
613
+
614
+ $url = $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array(
615
+ 'id' => $row->getData('template_description_id')
616
+ ));
617
+
618
+ $templateTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('template_description_title'));
619
+
620
+ return <<<HTML
621
+ <a target="_blank" href="{$url}">{$templateTitle}</a>
622
+ HTML;
623
+ }
624
+
625
+ return $html;
626
+ }
627
+
628
+ public function callbackColumnTemplateShippingOverride($value, $row, $column, $isExport)
629
+ {
630
+ $html = Mage::helper('M2ePro')->__('N/A');
631
+
632
+ if ($row->getData('template_shipping_override_id')) {
633
+
634
+ $url = $this->getUrl('*/adminhtml_common_amazon_template_shippingOverride/edit', array(
635
+ 'id' => $row->getData('template_shipping_override_id')
636
+ ));
637
+
638
+ $templateTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('template_shipping_override_title'));
639
+
640
+ return <<<HTML
641
+ <a target="_blank" href="{$url}">{$templateTitle}</a>
642
+ HTML;
643
+ }
644
+
645
+ return $html;
646
+ }
647
+
648
+ //########################################
649
+
650
+ protected function callbackFilterTitle($collection, $column)
651
+ {
652
+ $value = $column->getFilter()->getValue();
653
+
654
+ if ($value == null) {
655
+ return;
656
+ }
657
+
658
+ $collection->addFieldToFilter(
659
+ array(
660
+ array('attribute'=>'sku','like'=>'%'.$value.'%'),
661
+ array('attribute'=>'name', 'like'=>'%'.$value.'%')
662
+ )
663
+ );
664
+ }
665
+
666
+ //########################################
667
+
668
+ public function getGridUrl()
669
+ {
670
+ return $this->getUrl('*/adminhtml_common_amazon_listing/viewGrid', array('_current'=>true));
671
+ }
672
+
673
+ public function getRowUrl($row)
674
+ {
675
+ return false;
676
+ }
677
+
678
+ //########################################
679
+
680
+ protected function _toHtml()
681
+ {
682
+ $javascriptsMain = <<<HTML
683
+ <script type="text/javascript">
684
+
685
+ if (typeof ListingGridHandlerObj != 'undefined') {
686
+ ListingGridHandlerObj.afterInitPage();
687
+ }
688
+
689
+ Event.observe(window, 'load', function() {
690
+ setTimeout(function() {
691
+ ListingGridHandlerObj.afterInitPage();
692
+ }, 350);
693
+ });
694
+
695
+ </script>
696
+ HTML;
697
+
698
+ return parent::_toHtml().$javascriptsMain;
699
+ }
700
+
701
+ //########################################
702
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Marketplace/Form.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Marketplace_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonMarketplaceForm');
20
+ $this->setContainerId('magento_block_amazon_marketplaces');
21
+ $this->setTemplate('M2ePro/common/amazon/marketplace.phtml');
22
+ // ---------------------------------------
23
+ }
24
+
25
+ protected function _prepareForm()
26
+ {
27
+ return parent::_prepareForm();
28
+ }
29
+
30
+ //########################################
31
+
32
+ protected function _beforeToHtml()
33
+ {
34
+ // ---------------------------------------
35
+ /** @var Ess_M2ePro_Model_Marketplace[] $marketplaces */
36
+ $marketplaces = Mage::helper('M2ePro/Component_Amazon')->getCollection('Marketplace')
37
+ ->setOrder('group_title', 'ASC')
38
+ ->setOrder('sorder','ASC')
39
+ ->setOrder('title','ASC')
40
+ ->getItems();
41
+ $groups = array();
42
+ $storedStatuses = array();
43
+ $idGroup = 1;
44
+
45
+ $groupsOrder = array(
46
+ 'america' => 'America',
47
+ 'europe' => 'Europe',
48
+ 'asia_pacific' => 'Asia / Pacific'
49
+ );
50
+
51
+ foreach ($groupsOrder as $key => $groupOrderTitle) {
52
+ $groups[$key] = array(
53
+ 'id' => $idGroup++,
54
+ 'title' => $groupOrderTitle,
55
+ 'marketplaces' => array()
56
+ );
57
+
58
+ foreach ($marketplaces as $marketplace) {
59
+ if ($marketplace->getGroupTitle() != $groupOrderTitle) {
60
+ continue;
61
+ }
62
+
63
+ $storedStatuses[] = array(
64
+ 'marketplace_id' => $marketplace->getId(),
65
+ 'status' => $marketplace->getStatus()
66
+ );
67
+
68
+ $isLocked = (bool)Mage::helper('M2ePro/Component_Amazon')->getCollection('Account')
69
+ ->addFieldToFilter('marketplace_id', $marketplace->getId())
70
+ ->getSize();
71
+
72
+ $marketplace = array(
73
+ 'instance' => $marketplace,
74
+ 'params' => array('locked' => $isLocked)
75
+ );
76
+
77
+ $groups[$key]['marketplaces'][] = $marketplace;
78
+ }
79
+ }
80
+
81
+ $this->groups = $groups;
82
+ $this->storedStatuses = $storedStatuses;
83
+ // ---------------------------------------
84
+
85
+ // ---------------------------------------
86
+ $data = array(
87
+ 'label' => Mage::helper('M2ePro')->__('Update Now'),
88
+ 'onclick' => 'MarketplaceHandlerObj.runSingleSynchronization(this)',
89
+ 'class' => 'run_single_button'
90
+ );
91
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
92
+ $this->setChild('run_single_button', $buttonBlock);
93
+ // ---------------------------------------
94
+
95
+ return parent::_beforeToHtml();
96
+ }
97
+
98
+ //########################################
99
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_Edit_ShippingAddress
10
+ extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonOrderEditShippingAddress');
21
+ $this->_blockGroup = 'M2ePro';
22
+ $this->_controller = 'adminhtml_common_amazon_order_edit';
23
+ $this->_mode = 'shippingAddress';
24
+ // ---------------------------------------
25
+
26
+ // Set header text
27
+ // ---------------------------------------
28
+ $this->_headerText = Mage::helper('M2ePro')->__('Edit Shipping Address');
29
+ // ---------------------------------------
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
42
+ // ---------------------------------------
43
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
44
+ $this->_addButton('back', array(
45
+ 'label' => Mage::helper('M2ePro')->__('Back'),
46
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
47
+ 'class' => 'back'
48
+ ));
49
+ // ---------------------------------------
50
+ } else {
51
+ // ---------------------------------------
52
+ $url = $this->getUrl('*/*/view', array('id' => $this->getRequest()->getParam('id')));
53
+ $this->_addButton('back', array(
54
+ 'label' => Mage::helper('M2ePro')->__('Back'),
55
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
56
+ 'class' => 'back'
57
+ ));
58
+ // ---------------------------------------
59
+ }
60
+
61
+ // ---------------------------------------
62
+ $this->_addButton('save', array(
63
+ 'label' => Mage::helper('M2ePro')->__('Save Order Address'),
64
+ 'onclick' => 'CommonHandlerObj.save_click()',
65
+ 'class' => 'save'
66
+ ));
67
+ // ---------------------------------------
68
+ }
69
+
70
+ //########################################
71
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Edit/ShippingAddress/Form.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_Edit_ShippingAddress_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ private $order;
12
+
13
+ //########################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ // ---------------------------------------
21
+ $this->setId('amazonOrderEditShippingAddressForm');
22
+ // ---------------------------------------
23
+
24
+ $this->setTemplate('M2ePro/common/amazon/order/edit/shipping_address.phtml');
25
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
26
+ }
27
+
28
+ protected function _prepareForm()
29
+ {
30
+ $form = new Varien_Data_Form(array(
31
+ 'id' => 'edit_form',
32
+ 'action' => $this->getUrl('*/*/save'),
33
+ 'method' => 'post',
34
+ 'enctype' => 'multipart/form-data'
35
+ ));
36
+
37
+ $form->setUseContainer(true);
38
+ $this->setForm($form);
39
+
40
+ return parent::_prepareForm();
41
+ }
42
+
43
+ protected function _beforeToHtml()
44
+ {
45
+ try {
46
+ $regionCode = $this->order->getShippingAddress()->getRegionCode();
47
+ } catch (Exception $e) {
48
+ $regionCode = null;
49
+ }
50
+
51
+ $this->setData('countries', Mage::helper('M2ePro/Magento')->getCountries());
52
+ $this->setData('buyer_name', $this->order->getData('buyer_name'));
53
+ $this->setData('buyer_email', $this->order->getData('buyer_email'));
54
+ $this->setData('address', $this->order->getShippingAddress()->getData());
55
+ $this->setData('region_code', $regionCode);
56
+
57
+ return parent::_beforeToHtml();
58
+ }
59
+
60
+ //########################################
61
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/Grid.php ADDED
@@ -0,0 +1,590 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ /** @var $itemsCollection Ess_M2ePro_Model_Mysql4_Order_Item_Collection */
12
+ private $itemsCollection = NULL;
13
+
14
+ //########################################
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('amazonOrderGrid');
23
+ // ---------------------------------------
24
+
25
+ // Set default values
26
+ // ---------------------------------------
27
+ $this->setDefaultSort('purchase_create_date');
28
+ $this->setDefaultDir('DESC');
29
+ $this->setSaveParametersInSession(true);
30
+ $this->setUseAjax(true);
31
+ // ---------------------------------------
32
+ }
33
+
34
+ public function getMassactionBlockName()
35
+ {
36
+ return 'M2ePro/adminhtml_grid_massaction';
37
+ }
38
+
39
+ protected function _prepareCollection()
40
+ {
41
+ $collection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Order');
42
+
43
+ $collection->getSelect()
44
+ ->joinLeft(
45
+ array('so' => Mage::getSingleton('core/resource')->getTableName('sales/order')),
46
+ '(so.entity_id = `main_table`.magento_order_id)',
47
+ array('magento_order_num' => 'increment_id'));
48
+
49
+ // Add Filter By Account
50
+ // ---------------------------------------
51
+ if ($accountId = $this->getRequest()->getParam('amazonAccount')) {
52
+ $collection->addFieldToFilter('main_table.account_id', $accountId);
53
+ }
54
+ // ---------------------------------------
55
+
56
+ // Add Filter By Marketplace
57
+ // ---------------------------------------
58
+ if ($marketplaceId = $this->getRequest()->getParam('amazonMarketplace')) {
59
+ $collection->addFieldToFilter('main_table.marketplace_id', $marketplaceId);
60
+ }
61
+ // ---------------------------------------
62
+
63
+ // Add Not Created Magento Orders Filter
64
+ // ---------------------------------------
65
+ if ($this->getRequest()->getParam('not_created_only')) {
66
+ $collection->addFieldToFilter('magento_order_id', array('null' => true));
67
+ }
68
+ // ---------------------------------------
69
+
70
+ $this->setCollection($collection);
71
+ return parent::_prepareCollection();
72
+ }
73
+
74
+ protected function _afterLoadCollection()
75
+ {
76
+ $this->itemsCollection = Mage::helper('M2ePro/Component_Amazon')
77
+ ->getCollection('Order_Item')
78
+ ->addFieldToFilter('order_id', array('in' => $this->getCollection()->getColumnValues('id')));
79
+
80
+ return parent::_afterLoadCollection();
81
+ }
82
+
83
+ protected function _prepareColumns()
84
+ {
85
+ $this->addColumn('purchase_create_date', array(
86
+ 'header' => Mage::helper('M2ePro')->__('Sale Date'),
87
+ 'align' => 'left',
88
+ 'type' => 'datetime',
89
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
90
+ 'index' => 'purchase_create_date',
91
+ 'width' => '170px'
92
+ ));
93
+
94
+ $this->addColumn('magento_order_num', array(
95
+ 'header' => Mage::helper('M2ePro')->__('Magento Order #'),
96
+ 'align' => 'left',
97
+ 'index' => 'so.increment_id',
98
+ 'width' => '110px',
99
+ 'frame_callback' => array($this, 'callbackColumnMagentoOrder')
100
+ ));
101
+
102
+ $this->addColumn('amazon_order_id', array(
103
+ 'header' => Mage::helper('M2ePro')->__('Amazon Order #'),
104
+ 'align' => 'left',
105
+ 'width' => '110px',
106
+ 'index' => 'amazon_order_id',
107
+ 'frame_callback' => array($this, 'callbackColumnAmazonOrderId')
108
+ ));
109
+
110
+ $this->addColumn('amazon_order_items', array(
111
+ 'header' => Mage::helper('M2ePro')->__('Items'),
112
+ 'align' => 'left',
113
+ 'index' => 'amazon_order_items',
114
+ 'sortable' => false,
115
+ 'width' => '*',
116
+ 'frame_callback' => array($this, 'callbackColumnItems'),
117
+ 'filter_condition_callback' => array($this, 'callbackFilterItems')
118
+ ));
119
+
120
+ $this->addColumn('buyer', array(
121
+ 'header' => Mage::helper('M2ePro')->__('Buyer'),
122
+ 'align' => 'left',
123
+ 'index' => 'buyer_name',
124
+ 'width' => '120px',
125
+ 'frame_callback' => array($this, 'callbackColumnBuyer'),
126
+ 'filter_condition_callback' => array($this, 'callbackFilterBuyer')
127
+ ));
128
+
129
+ $this->addColumn('paid_amount', array(
130
+ 'header' => Mage::helper('M2ePro')->__('Total Paid'),
131
+ 'align' => 'left',
132
+ 'width' => '110px',
133
+ 'index' => 'paid_amount',
134
+ 'type' => 'number',
135
+ 'frame_callback' => array($this, 'callbackColumnTotal')
136
+ ));
137
+
138
+ $this->addColumn('is_afn_channel', array(
139
+ 'header' => Mage::helper('M2ePro')->__('Fulfillment'),
140
+ 'width' => '100px',
141
+ 'index' => 'is_afn_channel',
142
+ 'filter_index' => 'second_table.is_afn_channel',
143
+ 'type' => 'options',
144
+ 'sortable' => false,
145
+ 'options' => array(
146
+ 0 => Mage::helper('M2ePro')->__('Merchant'),
147
+ 1 => Mage::helper('M2ePro')->__('Amazon')
148
+ ),
149
+ 'frame_callback' => array($this, 'callbackColumnAfnChannel')
150
+ ));
151
+
152
+ $this->addColumn('reservation_state', array(
153
+ 'header' => Mage::helper('M2ePro')->__('Reservation'),
154
+ 'align' => 'left',
155
+ 'width' => '50px',
156
+ 'index' => 'reservation_state',
157
+ 'type' => 'options',
158
+ 'options' => array(
159
+ Ess_M2ePro_Model_Order_Reserve::STATE_UNKNOWN => Mage::helper('M2ePro')->__('Not Reserved'),
160
+ Ess_M2ePro_Model_Order_Reserve::STATE_PLACED => Mage::helper('M2ePro')->__('Reserved'),
161
+ Ess_M2ePro_Model_Order_Reserve::STATE_RELEASED => Mage::helper('M2ePro')->__('Released'),
162
+ Ess_M2ePro_Model_Order_Reserve::STATE_CANCELED => Mage::helper('M2ePro')->__('Canceled'),
163
+ )
164
+ ));
165
+
166
+ $helper = Mage::helper('M2ePro');
167
+
168
+ $this->addColumn('status', array(
169
+ 'header' => Mage::helper('M2ePro')->__('Status'),
170
+ 'align' => 'left',
171
+ 'width' => '50px',
172
+ 'index' => 'status',
173
+ 'filter_index' => 'second_table.status',
174
+ 'type' => 'options',
175
+ 'options' => array(
176
+ Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => $helper->__('Pending'),
177
+ Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED => $helper->__('Unshipped'),
178
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED_PARTIALLY => $helper->__('Partially Shipped'),
179
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => $helper->__('Shipped'),
180
+ Ess_M2ePro_Model_Amazon_Order::STATUS_INVOICE_UNCONFIRMED => $helper->__('Invoice Not Confirmed'),
181
+ Ess_M2ePro_Model_Amazon_Order::STATUS_UNFULFILLABLE => $helper->__('Unfulfillable'),
182
+ Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => $helper->__('Canceled')
183
+ ),
184
+ 'frame_callback' => array($this, 'callbackColumnStatus')
185
+ ));
186
+
187
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_order/index', array(
188
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
189
+ ));
190
+
191
+ $this->addColumn('action', array(
192
+ 'header' => Mage::helper('M2ePro')->__('Action'),
193
+ 'width' => '80px',
194
+ 'type' => 'action',
195
+ 'getter' => 'getId',
196
+ 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action',
197
+ 'actions' => array(
198
+ array(
199
+ 'caption' => Mage::helper('M2ePro')->__('View'),
200
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/view'),
201
+ 'field' => 'id'
202
+ ),
203
+ array(
204
+ 'caption' => Mage::helper('M2ePro')->__('Edit Shipping Address'),
205
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/editShippingAddress/back/'.$back.'/'),
206
+ 'field' => 'id'
207
+ ),
208
+ array(
209
+ 'caption' => Mage::helper('M2ePro')->__('Create Order'),
210
+ 'url' => array('base' => '*/adminhtml_common_amazon_order/createMagentoOrder'),
211
+ 'field' => 'id'
212
+ ),
213
+ array(
214
+ 'caption' => Mage::helper('M2ePro')->__('Mark As Shipped'),
215
+ 'field' => 'id',
216
+ 'onclick_action' => 'OrderMerchantFulfillmentHandlerObj.markAsShippedAction'
217
+ ),
218
+ array(
219
+ 'caption' => Mage::helper('M2ePro')->__('Amazon\'s Shipping Services'),
220
+ 'field' => 'id',
221
+ 'onclick_action' => 'OrderMerchantFulfillmentHandlerObj.getPopupAction'
222
+ )
223
+ ),
224
+ 'filter' => false,
225
+ 'sortable' => false,
226
+ 'is_system' => true
227
+ ));
228
+
229
+ return parent::_prepareColumns();
230
+ }
231
+
232
+ protected function _prepareMassaction()
233
+ {
234
+ // Set massaction identifiers
235
+ // ---------------------------------------
236
+ $this->setMassactionIdField('main_table.id');
237
+ $this->getMassactionBlock()->setFormFieldName('ids');
238
+ // ---------------------------------------
239
+
240
+ // Set mass-action
241
+ // ---------------------------------------
242
+ $this->getMassactionBlock()->addItem('reservation_place', array(
243
+ 'label' => Mage::helper('M2ePro')->__('Reserve QTY'),
244
+ 'url' => $this->getUrl('*/adminhtml_order/reservationPlace'),
245
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
246
+ ));
247
+
248
+ $this->getMassactionBlock()->addItem('reservation_cancel', array(
249
+ 'label' => Mage::helper('M2ePro')->__('Cancel QTY Reserve'),
250
+ 'url' => $this->getUrl('*/adminhtml_order/reservationCancel'),
251
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
252
+ ));
253
+
254
+ $this->getMassactionBlock()->addItem('ship', array(
255
+ 'label' => Mage::helper('M2ePro')->__('Mark Order(s) as Shipped'),
256
+ 'url' => $this->getUrl('*/adminhtml_common_amazon_order/updateShippingStatus'),
257
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
258
+ ));
259
+
260
+ $this->getMassactionBlock()->addItem('resend_shipping', array(
261
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
262
+ 'url' => $this->getUrl('*/adminhtml_order/resubmitShippingInfo'),
263
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
264
+ ));
265
+ // ---------------------------------------
266
+
267
+ return parent::_prepareMassaction();
268
+ }
269
+
270
+ //########################################
271
+
272
+ public function callbackColumnAmazonOrderId($value, $row, $column, $isExport)
273
+ {
274
+ $orderId = Mage::helper('M2ePro')->escapeHtml($row->getData('amazon_order_id'));
275
+ $url = Mage::helper('M2ePro/Component_Amazon')->getOrderUrl($orderId, $row->getData('marketplace_id'));
276
+
277
+ $primeImageHtml = '';
278
+ if ($row['is_prime']) {
279
+ $primeImageHtml = '<div><img src="' . $this->getSkinUrl('M2ePro/images/prime.png') . '" /></div>';
280
+ }
281
+
282
+ return <<<HTML
283
+ <a href="{$url}" target="_blank">{$orderId}</a> {$primeImageHtml}
284
+ HTML;
285
+ }
286
+
287
+ public function callbackColumnMagentoOrder($value, $row, $column, $isExport)
288
+ {
289
+ $magentoOrderId = $row['magento_order_id'];
290
+ $magentoOrderNumber = Mage::helper('M2ePro')->escapeHtml($row['magento_order_num']);
291
+
292
+ $returnString = Mage::helper('M2ePro')->__('N/A');
293
+
294
+ if ($row['magento_order_id']) {
295
+ if ($row['magento_order_num']) {
296
+ $orderUrl = $this->getUrl('adminhtml/sales_order/view', array('order_id' => $magentoOrderId));
297
+ $returnString = '<a href="' . $orderUrl . '" target="_blank">' . $magentoOrderNumber . '</a>';
298
+ } else {
299
+ $returnString = '<span style="color: red;">'.Mage::helper('M2ePro')->__('Deleted').'</span>';
300
+ }
301
+ }
302
+
303
+ return $returnString.$this->getViewLogIconHtml($row->getId());
304
+ }
305
+
306
+ private function getViewLogIconHtml($orderId)
307
+ {
308
+ $orderId = (int)$orderId;
309
+
310
+ // Prepare collection
311
+ // ---------------------------------------
312
+ $orderLogsCollection = Mage::getModel('M2ePro/Order_Log')->getCollection()
313
+ ->addFieldToFilter('order_id', $orderId)
314
+ ->setOrder('id', 'DESC');
315
+ $orderLogsCollection->getSelect()
316
+ ->limit(3);
317
+ // ---------------------------------------
318
+
319
+ // Prepare logs data
320
+ // ---------------------------------------
321
+ if ($orderLogsCollection->count() <= 0) {
322
+ return '';
323
+ }
324
+
325
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
326
+
327
+ $logRows = array();
328
+ foreach ($orderLogsCollection as $log) {
329
+ $logRows[] = array(
330
+ 'type' => $log->getData('type'),
331
+ 'text' => Mage::helper('M2ePro/View')->getModifiedLogMessage($log->getData('description')),
332
+ 'initiator' => $this->getInitiatorForAction($log->getData('initiator')),
333
+ 'date' => Mage::app()->getLocale()->date(strtotime($log->getData('create_date')))->toString($format)
334
+ );
335
+ }
336
+ // ---------------------------------------
337
+
338
+ $tips = array(
339
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Order Action was completed successfully.',
340
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Order Action was completed with error(s).',
341
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Order Action was completed with warning(s).'
342
+ );
343
+
344
+ $icons = array(
345
+ Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal',
346
+ Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error',
347
+ Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'
348
+ );
349
+
350
+ $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array(
351
+ 'entity_id' => $orderId,
352
+ 'rows' => $logRows,
353
+ 'tips' => $tips,
354
+ 'icons' => $icons,
355
+ 'view_help_handler' => 'OrderHandlerObj.viewOrderHelp',
356
+ 'hide_help_handler' => 'OrderHandlerObj.hideOrderHelp',
357
+ ));
358
+
359
+ return $summary->toHtml();
360
+ }
361
+
362
+ public function getInitiatorForAction($initiator)
363
+ {
364
+ $string = '';
365
+
366
+ switch ((int)$initiator) {
367
+ case Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN:
368
+ $string = '';
369
+ break;
370
+ case Ess_M2ePro_Helper_Data::INITIATOR_USER:
371
+ $string = Mage::helper('M2ePro')->__('Manual');
372
+ break;
373
+ case Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION:
374
+ $string = Mage::helper('M2ePro')->__('Automatic');
375
+ break;
376
+ }
377
+
378
+ return $string;
379
+ }
380
+
381
+ // ---------------------------------------
382
+
383
+ public function callbackColumnItems($value, $row, $column, $isExport)
384
+ {
385
+ /** @var $items Ess_M2ePro_Model_Order_Item[] */
386
+ $items = $this->itemsCollection->getItemsByColumnValue('order_id', $row->getData('id'));
387
+
388
+ $html = '';
389
+ $gridId = $this->getId();
390
+
391
+ foreach ($items as $item) {
392
+ if ($html != '') {
393
+ $html .= '<br/>';
394
+ }
395
+
396
+ $isShowEditLink = false;
397
+
398
+ $product = $item->getProduct();
399
+ if (!is_null($product)) {
400
+ /** @var Ess_M2ePro_Model_Magento_Product $magentoProduct */
401
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
402
+ $magentoProduct->setProduct($product);
403
+
404
+ $associatedProducts = $item->getAssociatedProducts();
405
+ $associatedOptions = $item->getAssociatedOptions();
406
+
407
+ if ($magentoProduct->isProductWithVariations()
408
+ && empty($associatedOptions)
409
+ && empty($associatedProducts)
410
+ ) {
411
+ $isShowEditLink = true;
412
+ }
413
+ }
414
+
415
+ $editItemHtml = '';
416
+ if ($isShowEditLink) {
417
+ $orderItemId = $item->getId();
418
+ $orderItemEditLabel = Mage::helper('M2ePro')->__('edit');
419
+
420
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
421
+
422
+ $editItemHtml = <<<HTML
423
+ <span>&nbsp;<a href="javascript:void(0);" onclick="{$js}">[{$orderItemEditLabel}]</a></span>
424
+ HTML;
425
+ }
426
+
427
+ $skuHtml = '';
428
+ if ($item->getSku()) {
429
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
430
+ $sku = Mage::helper('M2ePro')->escapeHtml($item->getSku());
431
+
432
+ $skuHtml = <<<STRING
433
+ <span style="padding-left: 10px;"><b>{$skuLabel}:</b>&nbsp;{$sku}</span><br/>
434
+ STRING;
435
+ }
436
+
437
+ $generalIdLabel = Mage::helper('M2ePro')->__($item->getIsIsbnGeneralId() ? 'ISBN' : 'ASIN');
438
+ $generalId = Mage::helper('M2ePro')->escapeHtml($item->getGeneralId());
439
+
440
+ $itemUrl = Mage::helper('M2ePro/Component_Amazon')->getItemUrl($item->getGeneralId(),
441
+ $row->getData('marketplace_id'));
442
+
443
+ $itemLink = '<a href="'.$itemUrl.'" target="_blank">'.$generalId.'</a>';
444
+
445
+ $generalIdHtml = <<<STRING
446
+ <span style="padding-left: 10px;"><b>{$generalIdLabel}:</b>&nbsp;{$itemLink}</span><br/>
447
+ STRING;
448
+
449
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($item->getTitle());
450
+ $qtyLabel = Mage::helper('M2ePro')->__('QTY');
451
+ $qtyHtml = <<<HTML
452
+ <span style="padding-left: 10px;"><b>{$qtyLabel}:</b> {$item->getQtyPurchased()}</span>
453
+ HTML;
454
+
455
+ $html .= <<<HTML
456
+ {$itemTitle}&nbsp;{$editItemHtml}<br/>
457
+ <small>{$generalIdHtml}{$skuHtml}{$qtyHtml}</small>
458
+ HTML;
459
+ }
460
+
461
+ return $html;
462
+ }
463
+
464
+ public function callbackColumnBuyer($value, $row, $column, $isExport)
465
+ {
466
+ if ($row->getData('buyer_name') == '') {
467
+ return Mage::helper('M2ePro')->__('N/A');
468
+ }
469
+
470
+ $html = Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_name'));
471
+
472
+ if ($row->getData('buyer_email') != '') {
473
+ $html .= '<br/>';
474
+ $html .= '&lt;' . Mage::helper('M2ePro')->escapeHtml($row->getData('buyer_email')) . '&gt;';
475
+ }
476
+
477
+ return $html;
478
+ }
479
+
480
+ public function callbackColumnTotal($value, $row, $column, $isExport)
481
+ {
482
+ $currency = $row->getData('currency');
483
+
484
+ if (empty($currency)) {
485
+ /** @var Ess_M2ePro_Model_Marketplace $marketplace */
486
+ $marketplace = Mage::helper('M2ePro/Component_Amazon')->getCachedObject(
487
+ 'Marketplace', $row->getData('marketplace_id')
488
+ );
489
+ /** @var Ess_M2ePro_Model_Amazon_Marketplace $amazonMarketplace */
490
+ $amazonMarketplace = $marketplace->getChildObject();
491
+
492
+ $currency = $amazonMarketplace->getDefaultCurrency();
493
+ }
494
+
495
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $row->getData('paid_amount'));
496
+ }
497
+
498
+ public function callbackColumnAfnChannel($value, $row, $column, $isExport)
499
+ {
500
+ switch ($row->getData('is_afn_channel')) {
501
+ case Ess_M2ePro_Model_Amazon_Listing_Product::IS_ISBN_GENERAL_ID_YES:
502
+ $value = '<span style="font-weight: bold;">' . $value . '</span>';
503
+ break;
504
+
505
+ default:
506
+ break;
507
+ }
508
+
509
+ return $value;
510
+ }
511
+
512
+ public function callbackColumnStatus($value, $row, $column, $isExport)
513
+ {
514
+ $status = $row->getData('status');
515
+
516
+ $statusColors = array(
517
+ Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => 'gray',
518
+ Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => 'green',
519
+ Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => 'red'
520
+ );
521
+
522
+ $color = isset($statusColors[$status]) ? $statusColors[$status] : 'black';
523
+ $value = '<span style="color: '.$color.';">'.$value.'</span>';
524
+
525
+ if ($row->isLockedObject('update_order_status')) {
526
+ $value .= '<br/>';
527
+ $value .= '<span style="color: gray;">['
528
+ .Mage::helper('M2ePro')->__('Status Update in Progress...').']</span>';
529
+ }
530
+
531
+ return $value;
532
+ }
533
+
534
+ //########################################
535
+
536
+ protected function callbackFilterItems($collection, $column)
537
+ {
538
+ $value = $column->getFilter()->getValue();
539
+ if ($value == null) {
540
+ return;
541
+ }
542
+
543
+ $orderItemsCollection = Mage::helper('M2ePro/Component_Amazon')->getCollection('Order_Item');
544
+
545
+ $orderItemsCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
546
+ $orderItemsCollection->getSelect()->columns('order_id');
547
+ $orderItemsCollection->getSelect()->distinct(true);
548
+
549
+ $orderItemsCollection->getSelect()->where('title LIKE ? OR sku LIKE ? or general_id LIKE ?', '%'.$value.'%');
550
+
551
+ $totalResult = $orderItemsCollection->getColumnValues('order_id');
552
+ $collection->addFieldToFilter('main_table.id', array('in' => $totalResult));
553
+ }
554
+
555
+ protected function callbackFilterBuyer($collection, $column)
556
+ {
557
+ $value = $column->getFilter()->getValue();
558
+ if ($value == null) {
559
+ return;
560
+ }
561
+
562
+ $collection
563
+ ->getSelect()
564
+ ->where('buyer_email LIKE ? OR buyer_name LIKE ?', '%'.$value.'%');
565
+ }
566
+
567
+ //########################################
568
+
569
+ public function getGridUrl()
570
+ {
571
+ return $this->getUrl('*/adminhtml_common_amazon_order/grid', array('_current' => true));
572
+ }
573
+
574
+ public function getRowUrl($row)
575
+ {
576
+ $back = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_order/index', array(
577
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_AMAZON
578
+ ));
579
+
580
+ return $this->getUrl('*/adminhtml_common_amazon_order/view', array('id' => $row->getId(), 'back' => $back));
581
+ }
582
+
583
+ protected function _toHtml()
584
+ {
585
+ return $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_order_merchantFulfillment')->toHtml()
586
+ . parent::_toHtml();
587
+ }
588
+
589
+ //########################################
590
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_MerchantFulfillment
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonOrderMerchantFulfillment');
20
+ // ---------------------------------------
21
+ $this->setTemplate('M2ePro/common/amazon/order/merchant_fulfillment.phtml');
22
+ }
23
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Breadcrumb.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_MerchantFulfillment_Breadcrumb
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonOrderMerchantFulfillmentBreadcrumb');
21
+ // ---------------------------------------
22
+ $this->setTemplate('M2ePro/common/amazon/order/merchant_fulfillment/breadcrumb.phtml');
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Configuration.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_MerchantFulfillment_Configuration
10
+ extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonOrderMerchantFulfillmentConfiguration');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/amazon/order/merchant_fulfillment/configuration.phtml');
23
+ }
24
+
25
+ //########################################
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ parent::_beforeToHtml();
30
+
31
+ // ---------------------------------------
32
+ $breadcrumb = $this->getLayout()
33
+ ->createBlock('M2ePro/adminhtml_common_amazon_order_merchantFulfillment_breadcrumb');
34
+ $breadcrumb->setData('step', 1);
35
+ $this->setChild('breadcrumb', $breadcrumb);
36
+ // ---------------------------------------
37
+
38
+ // ---------------------------------------
39
+ $data = array(
40
+ 'class' => 'next',
41
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
42
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.getShippingServicesAction()",
43
+ );
44
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
45
+ $this->setChild('continue_button', $buttonBlock);
46
+ // ---------------------------------------
47
+ }
48
+
49
+ //########################################
50
+
51
+ public function getCountries()
52
+ {
53
+ $preparedCountries = array();
54
+ $countries = Mage::helper('M2ePro/Magento')->getCountries();
55
+
56
+ foreach ($countries as $country) {
57
+ $preparedCountries[$country['iso2_code']] = $country['name'];
58
+ }
59
+
60
+ return $preparedCountries;
61
+ }
62
+
63
+ public function getOrderItems()
64
+ {
65
+ $data = array();
66
+ $totalWeight = 0;
67
+
68
+ foreach ($this->getData('order_items') as $parentOrderItem) {
69
+ /**
70
+ * @var $parentOrderItem Ess_M2ePro_Model_Order_Item
71
+ */
72
+ $parentOrderItem->getMagentoProduct();
73
+
74
+ $orderItem = $parentOrderItem->getChildObject();
75
+
76
+ $orderItemProduct = $parentOrderItem->getProduct();
77
+ if (!is_null($orderItemProduct)) {
78
+ $weight = $orderItemProduct->getTypeInstance()->getWeight();
79
+ if (!is_null($weight)) {
80
+ $totalWeight += $weight;
81
+ }
82
+ }
83
+
84
+ $data[] = array(
85
+ 'title' => $orderItem->getTitle(),
86
+ 'sku' => $orderItem->getSku(),
87
+ 'asin' => $orderItem->getGeneralId(),
88
+ 'qty' => $orderItem->getQtyPurchased(),
89
+ 'price' => $orderItem->getPrice(),
90
+ 'currency' => $orderItem->getCurrency(),
91
+ );
92
+ }
93
+
94
+ $this->setData('total_weight', $totalWeight);
95
+
96
+ return $data;
97
+ }
98
+
99
+ public function getShippingOriginData()
100
+ {
101
+ return array(
102
+ 'country_id' => Mage::getStoreConfig('shipping/origin/country_id'),
103
+ 'region_id' => Mage::getStoreConfig('shipping/origin/region_id'),
104
+ 'postal_code' => Mage::getStoreConfig('shipping/origin/postcode'),
105
+ 'city' => Mage::getStoreConfig('shipping/origin/city'),
106
+ 'street_line1' => Mage::getStoreConfig('shipping/origin/street_line1'),
107
+ 'street_line2' => Mage::getStoreConfig('shipping/origin/street_line2'),
108
+ );
109
+ }
110
+
111
+ public function getUserData()
112
+ {
113
+ $licenseFormDataRegistry = Mage::getModel('M2ePro/Registry')->load('/wizard/license_form_data/', 'key');
114
+ return $licenseFormDataRegistry->getValueFromJson();
115
+ }
116
+
117
+ //########################################
118
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Information.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_MerchantFulfillment_Information
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonOrderMerchantFulfillmentInformation');
20
+ // ---------------------------------------
21
+ $this->setTemplate('M2ePro/common/amazon/order/merchant_fulfillment/information.phtml');
22
+ }
23
+
24
+ //########################################
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ parent::_beforeToHtml();
29
+
30
+ // ---------------------------------------
31
+ if(is_null($this->getData('fulfillment_not_wizard'))) {
32
+ $breadcrumb = $this->getLayout()
33
+ ->createBlock('M2ePro/adminhtml_common_amazon_order_merchantFulfillment_breadcrumb');
34
+ $breadcrumb->setData('step', 3);
35
+ $this->setChild('breadcrumb', $breadcrumb);
36
+ }
37
+ // ---------------------------------------
38
+
39
+ // ---------------------------------------
40
+ $data = array(
41
+ 'class' => 'delete',
42
+ 'label' => Mage::helper('M2ePro')->__('Cancel'),
43
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.cancelShippingOfferAction()",
44
+ );
45
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
46
+ $this->setChild('cancel_button', $buttonBlock);
47
+ // ---------------------------------------
48
+
49
+ // ---------------------------------------]
50
+ $data = array(
51
+ 'class' => 'go',
52
+ 'label' => Mage::helper('M2ePro')->__('Print'),
53
+ 'onclick' => 'OrderMerchantFulfillmentHandlerObj.getShippingLabelAction()',
54
+ );
55
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
56
+ $this->setChild('print_button', $buttonBlock);
57
+ // ---------------------------------------
58
+
59
+ // ---------------------------------------
60
+ $data = array(
61
+ 'label' => Mage::helper('M2ePro')->__('Refresh'),
62
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.refreshDataAction()",
63
+ );
64
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
65
+ $this->setChild('refresh_button', $buttonBlock);
66
+ // ---------------------------------------
67
+
68
+ // ---------------------------------------
69
+ $data = array(
70
+ 'label' => Mage::helper('M2ePro')->__('Use Amazon\'s Shipping Services'),
71
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.resetDataAction()",
72
+ );
73
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
74
+ $this->setChild('try_again_button', $buttonBlock);
75
+ // ---------------------------------------
76
+
77
+ // ---------------------------------------
78
+ $data = array(
79
+ 'class' => 'close',
80
+ 'label' => Mage::helper('M2ePro')->__('Close'),
81
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.closePopUp()",
82
+ );
83
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
84
+ $this->setChild('close_button', $buttonBlock);
85
+ // ---------------------------------------
86
+ }
87
+
88
+ //########################################
89
+
90
+ public function getOrderItems()
91
+ {
92
+ $data = array();
93
+
94
+ foreach ($this->getData('order_items') as $parentOrderItem) {
95
+ /**
96
+ * @var $parentOrderItem Ess_M2ePro_Model_Order_Item
97
+ */
98
+ $orderItem = $parentOrderItem->getChildObject();
99
+
100
+ $data[] = array(
101
+ 'title' => $orderItem->getTitle(),
102
+ 'sku' => $orderItem->getSku(),
103
+ 'asin' => $orderItem->getGeneralId(),
104
+ 'qty' => $orderItem->getQtyPurchased(),
105
+ 'price' => $orderItem->getPrice(),
106
+ 'currency' => $orderItem->getCurrency(),
107
+ );
108
+ }
109
+
110
+ return $data;
111
+ }
112
+
113
+ //########################################
114
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Magento/Shipment.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_MerchantFulfillment_Magento_Shipment
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ /** @var Ess_M2ePro_Model_Order $order */
13
+ protected $order = NULL;
14
+
15
+ //########################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ // Initialization block
22
+ // ---------------------------------------
23
+ $this->setId('amazonOrderMerchantFulfillmentMagentoShipment');
24
+ // ---------------------------------------
25
+
26
+ $this->setTemplate('M2ePro/common/amazon/order/merchant_fulfillment/magento/shipment.phtml');
27
+ }
28
+
29
+ //########################################
30
+
31
+ public function setOrder(Ess_M2ePro_Model_Order $order)
32
+ {
33
+ $this->order = $order;
34
+ return $this;
35
+ }
36
+
37
+ public function getOrder()
38
+ {
39
+ return $this->order;
40
+ }
41
+
42
+ /**
43
+ * @return Ess_M2ePro_Model_Amazon_Order
44
+ */
45
+ public function getAmazonOrder()
46
+ {
47
+ return $this->order->getChildObject();
48
+ }
49
+
50
+ //########################################
51
+
52
+ public function canShowNotificationPopup()
53
+ {
54
+ $registry = Mage::getModel('M2ePro/Registry');
55
+ $registry->load('/amazon/order/merchant_fulfillment/disable_notification_popup/', 'key');
56
+ return !$registry->getValue();
57
+ }
58
+
59
+ //########################################
60
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/Message.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_MerchantFulfillment_Message
10
+ extends Mage_Adminhtml_Block_Template
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonOrderMerchantFulfillmentBreadcrumb');
21
+ // ---------------------------------------
22
+ $this->setTemplate('M2ePro/common/amazon/order/merchant_fulfillment/message.phtml');
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/MerchantFulfillment/ShippingServices.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_MerchantFulfillment_ShippingServices
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonOrderMerchantFulfillmentShippingServices');
20
+ // ---------------------------------------
21
+ $this->setTemplate('M2ePro/common/amazon/order/merchant_fulfillment/shipping_services.phtml');
22
+ }
23
+
24
+ //########################################
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ parent::_beforeToHtml();
29
+
30
+ // ---------------------------------------
31
+ $breadcrumb = $this->getLayout()
32
+ ->createBlock('M2ePro/adminhtml_common_amazon_order_merchantFulfillment_breadcrumb');
33
+ $breadcrumb->setData('step', 2);
34
+ $this->setChild('breadcrumb', $breadcrumb);
35
+ // ---------------------------------------
36
+
37
+ // ---------------------------------------
38
+ $data = array(
39
+ 'id' => 'fulfillment_save_shipping_services',
40
+ 'class' => 'next',
41
+ 'disabled'=> 'disabled',
42
+ 'label' => Mage::helper('M2ePro')->__('Continue'),
43
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.createShippingOfferAction()",
44
+ );
45
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
46
+ $this->setChild('continue_button', $buttonBlock);
47
+ // ---------------------------------------
48
+
49
+ // ---------------------------------------
50
+ $data = array(
51
+ 'class' => 'back',
52
+ 'label' => Mage::helper('M2ePro')->__('Back'),
53
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.getPopupAction()",
54
+ );
55
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
56
+ $this->setChild('back_button', $buttonBlock);
57
+ // ---------------------------------------
58
+ }
59
+
60
+ //########################################
61
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container
10
+ {
11
+ /** @var $order Ess_M2ePro_Model_Order */
12
+ protected $order = null;
13
+
14
+ //########################################
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('amazonOrderView');
23
+ $this->_blockGroup = 'M2ePro';
24
+ $this->_controller = 'adminhtml_common_amazon_order';
25
+ $this->_mode = 'view';
26
+ // ---------------------------------------
27
+
28
+ // Set header text
29
+ // ---------------------------------------
30
+ $this->_headerText = Mage::helper('M2ePro')->__('View Order Details');
31
+ // ---------------------------------------
32
+
33
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
34
+
35
+ // Set buttons actions
36
+ // ---------------------------------------
37
+ $this->removeButton('back');
38
+ $this->removeButton('reset');
39
+ $this->removeButton('delete');
40
+ $this->removeButton('add');
41
+ $this->removeButton('save');
42
+ $this->removeButton('edit');
43
+ // ---------------------------------------
44
+
45
+ // ---------------------------------------
46
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_order/index');
47
+ $this->_addButton('back', array(
48
+ 'label' => Mage::helper('M2ePro')->__('Back'),
49
+ 'onclick' => 'CommonHandlerObj.back_click(\''.$url.'\')',
50
+ 'class' => 'back'
51
+ ));
52
+ // ---------------------------------------
53
+
54
+ if ($this->order->getChildObject()->canUpdateShippingStatus() && !$this->order->getChildObject()->isPrime()) {
55
+ // ---------------------------------------
56
+ $url = $this->getUrl('*/*/updateShippingStatus', array('id' => $this->order->getId()));
57
+ $this->_addButton('update_shipping_status', array(
58
+ 'label' => Mage::helper('M2ePro')->__('Mark as Shipped'),
59
+ 'onclick' => "setLocation('".$url."');",
60
+ 'class' => 'scalable'
61
+ ));
62
+ // ---------------------------------------
63
+ }
64
+
65
+ if ($this->order->getReserve()->isPlaced()) {
66
+ // ---------------------------------------
67
+ $url = $this->getUrl('*/adminhtml_order/reservationCancel', array('ids' => $this->order->getId()));
68
+ $this->_addButton('reservation_cancel', array(
69
+ 'label' => Mage::helper('M2ePro')->__('Cancel QTY Reserve'),
70
+ 'onclick' => "confirmSetLocation(M2ePro.translator.translate('Are you sure?'), '".$url."');",
71
+ 'class' => 'scalable'
72
+ ));
73
+ // ---------------------------------------
74
+ } elseif ($this->order->isReservable()) {
75
+ // ---------------------------------------
76
+ $url = $this->getUrl('*/adminhtml_order/reservationPlace', array('ids' => $this->order->getId()));
77
+ $this->_addButton('reservation_place', array(
78
+ 'label' => Mage::helper('M2ePro')->__('Reserve QTY'),
79
+ 'onclick' => "confirmSetLocation(M2ePro.translator.translate('Are you sure?'), '".$url."');",
80
+ 'class' => 'scalable'
81
+ ));
82
+ // ---------------------------------------
83
+ }
84
+
85
+ if (is_null($this->order->getMagentoOrderId())) {
86
+ // ---------------------------------------
87
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId()));
88
+ $this->_addButton('order', array(
89
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
90
+ 'onclick' => "setLocation('".$url."');",
91
+ 'class' => 'scalable'
92
+ ));
93
+ // ---------------------------------------
94
+ } elseif (is_null($this->order->getMagentoOrder()) || $this->order->getMagentoOrder()->isCanceled()) {
95
+ // ---------------------------------------
96
+ $url = $this->getUrl('*/*/createMagentoOrder', array('id' => $this->order->getId(), 'force' => 'yes'));
97
+ $confirm = Mage::helper('M2ePro')->escapeJs(
98
+ Mage::helper('M2ePro')->__('Are you sure that you want to create new Magento Order?')
99
+ );
100
+
101
+ $this->_addButton('order', array(
102
+ 'label' => Mage::helper('M2ePro')->__('Create Order'),
103
+ 'onclick' => "confirmSetLocation('".$confirm."','".$url."');",
104
+ 'class' => 'scalable'
105
+ ));
106
+ // ---------------------------------------
107
+ }
108
+ }
109
+
110
+ //########################################
111
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Form.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_View_Form extends Ess_M2ePro_Block_Adminhtml_Widget_Container
10
+ {
11
+ public $shippingAddress = array();
12
+
13
+ public $realMagentoOrderId = NULL;
14
+
15
+ //########################################
16
+
17
+ public function __construct()
18
+ {
19
+ parent::__construct();
20
+
21
+ // Initialization block
22
+ // ---------------------------------------
23
+ $this->setId('amazonOrderViewForm');
24
+ $this->setTemplate('M2ePro/common/amazon/order.phtml');
25
+ // ---------------------------------------
26
+
27
+ /** @var $order Ess_M2ePro_Model_Order */
28
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
29
+ }
30
+
31
+ protected function _beforeToHtml()
32
+ {
33
+ // Magento order data
34
+ // ---------------------------------------
35
+ $this->realMagentoOrderId = NULL;
36
+
37
+ $magentoOrder = $this->order->getMagentoOrder();
38
+ if (!is_null($magentoOrder)) {
39
+ $this->realMagentoOrderId = $magentoOrder->getRealOrderId();
40
+ }
41
+ // ---------------------------------------
42
+
43
+ // ---------------------------------------
44
+ if (!is_null($magentoOrder) && $magentoOrder->hasShipments() && !$this->order->getChildObject()->isPrime()) {
45
+ $url = $this->getUrl('*/adminhtml_order/resubmitShippingInfo', array('id' => $this->order->getId()));
46
+ $data = array(
47
+ 'class' => '',
48
+ 'label' => Mage::helper('M2ePro')->__('Resend Shipping Information'),
49
+ 'onclick' => 'setLocation(\''.$url.'\');',
50
+ );
51
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
52
+ $this->setChild('resubmit_shipping_info', $buttonBlock);
53
+ }
54
+ // ---------------------------------------
55
+
56
+ // Shipping data
57
+ // ---------------------------------------
58
+ /** @var $shippingAddress Ess_M2ePro_Model_Amazon_Order_ShippingAddress */
59
+ $shippingAddress = $this->order->getShippingAddress();
60
+
61
+ $this->shippingAddress = $shippingAddress->getData();
62
+ $this->shippingAddress['country_name'] = $shippingAddress->getCountryName();
63
+ // ---------------------------------------
64
+
65
+ // Merchant Fulfillment
66
+ // ---------------------------------------
67
+ if (!$this->order->getChildObject()->isCanceled()
68
+ && !$this->order->getChildObject()->isPending()
69
+ && !$this->order->getChildObject()->isFulfilledByAmazon()
70
+ && $this->order->getMarketplace()->getChildObject()->isMerchantFulfillmentAvailable()) {
71
+ $orderId = $this->order->getId();
72
+ $data = array(
73
+ 'class' => '',
74
+ 'label' => Mage::helper('M2ePro')->__('Use Amazon\'s Shipping Services'),
75
+ 'onclick' => "OrderMerchantFulfillmentHandlerObj.getPopupAction({$orderId});",
76
+ 'style' => 'margin-top: 3px; margin-left: 6px;'
77
+ );
78
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
79
+ $this->setChild('use_amazons_shipping_services', $buttonBlock);
80
+ }
81
+ // ---------------------------------------
82
+
83
+ $this->setChild('item', $this->getLayout()->createBlock('M2ePro/adminhtml_common_amazon_order_view_item'));
84
+ $this->setChild('item_edit', $this->getLayout()->createBlock('M2ePro/adminhtml_order_item_edit'));
85
+ $this->setChild('log', $this->getLayout()->createBlock('M2ePro/adminhtml_order_view_log_grid'));
86
+
87
+ return parent::_beforeToHtml();
88
+ }
89
+
90
+ private function getStore()
91
+ {
92
+ if (is_null($this->order->getData('store_id'))) {
93
+ return null;
94
+ }
95
+
96
+ try {
97
+ $store = Mage::app()->getStore($this->order->getData('store_id'));
98
+ } catch (Exception $e) {
99
+ return null;
100
+ }
101
+
102
+ return $store;
103
+ }
104
+
105
+ public function isCurrencyAllowed()
106
+ {
107
+ $store = $this->getStore();
108
+
109
+ if (is_null($store)) {
110
+ return true;
111
+ }
112
+
113
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
114
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
115
+
116
+ return $currencyHelper->isAllowed($this->order->getChildObject()->getCurrency(), $store);
117
+ }
118
+
119
+ public function hasCurrencyConversionRate()
120
+ {
121
+ $store = $this->getStore();
122
+
123
+ if (is_null($store)) {
124
+ return true;
125
+ }
126
+
127
+ /** @var $currencyHelper Ess_M2ePro_Model_Currency */
128
+ $currencyHelper = Mage::getSingleton('M2ePro/Currency');
129
+
130
+ return $currencyHelper->getConvertRateFromBase($this->order->getChildObject()->getCurrency(), $store) != 0;
131
+ }
132
+
133
+ //########################################
134
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Order/View/Item.php ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Order_View_Item extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ /** @var $order Ess_M2ePro_Model_Order */
12
+ protected $order = null;
13
+
14
+ //########################################
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('amazonOrderViewItem');
23
+ // ---------------------------------------
24
+
25
+ // Set default values
26
+ // ---------------------------------------
27
+ $this->setDefaultSort('id');
28
+ $this->setDefaultDir('DESC');
29
+ $this->setPagerVisibility(false);
30
+ $this->setFilterVisibility(false);
31
+ $this->setUseAjax(true);
32
+ $this->_defaultLimit = 200;
33
+ // ---------------------------------------
34
+
35
+ $this->order = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
36
+ }
37
+
38
+ protected function _prepareCollection()
39
+ {
40
+ $collection = Mage::helper('M2ePro/Component_Amazon')
41
+ ->getCollection('Order_Item')
42
+ ->addFieldToFilter('order_id', $this->order->getId());
43
+
44
+ $collection->getSelect()->joinLeft(
45
+ array('cisi' => Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
46
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
47
+ array('is_in_stock')
48
+ );
49
+
50
+ $this->setCollection($collection);
51
+
52
+ return parent::_prepareCollection();
53
+ }
54
+
55
+ protected function _prepareColumns()
56
+ {
57
+ $this->addColumn('product_id', array(
58
+ 'header' => Mage::helper('M2ePro')->__('Product'),
59
+ 'align' => 'left',
60
+ 'width' => '*',
61
+ 'index' => 'product_id',
62
+ 'frame_callback' => array($this, 'callbackColumnProduct')
63
+ ));
64
+
65
+ $this->addColumn('stock_availability', array(
66
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
67
+ 'width' => '100px',
68
+ 'index' => 'is_in_stock',
69
+ 'filter_index' => 'cisi.is_in_stock',
70
+ 'type' => 'options',
71
+ 'sortable' => false,
72
+ 'options' => array(
73
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
74
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
75
+ ),
76
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
77
+ ));
78
+
79
+ $this->addColumn('original_price', array(
80
+ 'header' => Mage::helper('M2ePro')->__('Original Price'),
81
+ 'align' => 'left',
82
+ 'width' => '80px',
83
+ 'filter' => false,
84
+ 'sortable' => false,
85
+ 'frame_callback' => array($this, 'callbackColumnOriginalPrice')
86
+ ));
87
+
88
+ $this->addColumn('qty_purchased', array(
89
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
90
+ 'align' => 'left',
91
+ 'width' => '80px',
92
+ 'index' => 'qty_purchased'
93
+ ));
94
+
95
+ $this->addColumn('price', array(
96
+ 'header' => Mage::helper('M2ePro')->__('Price'),
97
+ 'align' => 'left',
98
+ 'width' => '80px',
99
+ 'index' => 'price',
100
+ 'frame_callback' => array($this, 'callbackColumnPrice')
101
+ ));
102
+
103
+ $this->addColumn('discount_amount', array(
104
+ 'header' => Mage::helper('M2ePro')->__('Promotions'),
105
+ 'align' => 'left',
106
+ 'width' => '80px',
107
+ 'filter' => false,
108
+ 'sortable' => false,
109
+ 'frame_callback' => array($this, 'callbackColumnDiscountAmount')
110
+ ));
111
+
112
+ if (Mage::getResourceModel('M2ePro/Amazon_Order')->hasGifts($this->order->getId())) {
113
+ $this->addColumn('gift_price', array(
114
+ 'header' => Mage::helper('M2ePro')->__('Gift Wrap Price'),
115
+ 'align' => 'left',
116
+ 'width' => '80px',
117
+ 'index' => 'gift_price',
118
+ 'frame_callback' => array($this, 'callbackColumnGiftPrice')
119
+ ));
120
+
121
+ $this->addColumn('gift_options', array(
122
+ 'header' => Mage::helper('M2ePro')->__('Gift Options'),
123
+ 'align' => 'left',
124
+ 'width' => '250px',
125
+ 'filter' => false,
126
+ 'sortable' => false,
127
+ 'frame_callback' => array($this, 'callbackColumnGiftOptions')
128
+ ));
129
+ }
130
+
131
+ $this->addColumn('row_total', array(
132
+ 'header' => Mage::helper('M2ePro')->__('Row Total'),
133
+ 'align' => 'left',
134
+ 'width' => '80px',
135
+ 'frame_callback' => array($this, 'callbackColumnRowTotal')
136
+ ));
137
+
138
+ return parent::_prepareColumns();
139
+ }
140
+
141
+ //########################################
142
+
143
+ /**
144
+ * @param $value
145
+ * @param $row Ess_M2ePro_Model_Order_Item
146
+ * @param $column
147
+ * @param $isExport
148
+ *
149
+ * @return string
150
+ */
151
+ public function callbackColumnProduct($value, $row, $column, $isExport)
152
+ {
153
+ $skuHtml = '';
154
+ if ($row->getSku()) {
155
+ $skuLabel = Mage::helper('M2ePro')->__('SKU');
156
+ $sku = Mage::helper('M2ePro')->escapeHtml($row->getSku());
157
+
158
+ $skuHtml = <<<HTML
159
+ <b>{$skuLabel}:</b> {$sku}<br/>
160
+ HTML;
161
+ }
162
+
163
+ $generalIdLabel = Mage::helper('M2ePro')->__($row->getIsIsbnGeneralId() ? 'ISBN' : 'ASIN');
164
+ $generalId = Mage::helper('M2ePro')->escapeHtml($row->getGeneralId());
165
+
166
+ $generalIdHtml = <<<HTML
167
+ <b>{$generalIdLabel}:</b> {$generalId}<br/>
168
+ HTML;
169
+
170
+ if ($row->getIsIsbnGeneralId() && !Mage::helper('M2ePro')->isISBN($row->getGeneralId())) {
171
+ $amazonLink = '';
172
+ } else {
173
+ $itemLinkText = Mage::helper('M2ePro')->__('View on Amazon');
174
+ $itemUrl = Mage::helper('M2ePro/Component_Amazon')->getItemUrl(
175
+ $row->getGeneralId(), $this->order->getData('marketplace_id')
176
+ );
177
+
178
+ $amazonLink = <<<HTML
179
+ <a href="{$itemUrl}" target="_blank">{$itemLinkText}</a>
180
+ HTML;
181
+ }
182
+
183
+ $productLink = '';
184
+ if ($productId = $row->getData('product_id')) {
185
+ $productUrl = $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId));
186
+ $productLink = ' | <a href="'.$productUrl.'" target="_blank">'.Mage::helper('M2ePro')->__('View').'</a>';
187
+ }
188
+
189
+ $orderItemId = (int)$row->getId();
190
+ $gridId = $this->getId();
191
+
192
+ $editLink = '';
193
+ if (!$row->getProductId() || $row->getMagentoProduct()->hasRequiredOptions()) {
194
+
195
+ if (!$row->getProductId()) {
196
+ $action = Mage::helper('M2ePro')->__('Map to Magento Product');
197
+ } else {
198
+ $action = Mage::helper('M2ePro')->__('Set Options');
199
+ }
200
+
201
+ $class = 'class="gray"';
202
+
203
+ $js = "{OrderEditItemHandlerObj.edit('{$gridId}', {$orderItemId});}";
204
+ $editLink = '<a href="javascript:void(0);" onclick="'.$js.'" '.$class.'>'.$action.'</a>';
205
+ }
206
+
207
+ $discardLink = '';
208
+ if ($row->getProductId()) {
209
+ $action = Mage::helper('M2ePro')->__('Unmap');
210
+
211
+ $js = "{OrderEditItemHandlerObj.unassignProduct('{$gridId}', {$orderItemId});}";
212
+ $discardLink = '<a href="javascript:void(0);" onclick="'.$js.'" class="gray">'.$action.'</a>';
213
+
214
+ if ($editLink) {
215
+ $discardLink = '&nbsp;|&nbsp;' . $discardLink;
216
+ }
217
+ }
218
+
219
+ $itemTitle = Mage::helper('M2ePro')->escapeHtml($row->getTitle());
220
+
221
+ return <<<HTML
222
+ <b>{$itemTitle}</b><br/>
223
+ <div style="padding-left: 10px;">
224
+ {$skuHtml}
225
+ {$generalIdHtml}
226
+ </div>
227
+ <div style="float: left;">{$amazonLink}{$productLink}</div>
228
+ <div style="float: right;">{$editLink}{$discardLink}</div>
229
+ HTML;
230
+ }
231
+
232
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
233
+ {
234
+ if (is_null($row->getData('is_in_stock'))) {
235
+ return Mage::helper('M2ePro')->__('N/A');
236
+ }
237
+
238
+ if ((int)$row->getData('is_in_stock') <= 0) {
239
+ return '<span style="color: red;">'.$value.'</span>';
240
+ }
241
+
242
+ return $value;
243
+ }
244
+
245
+ public function callbackColumnOriginalPrice($value, $row, $column, $isExport)
246
+ {
247
+ $productId = $row->getData('product_id');
248
+ $formattedPrice = Mage::helper('M2ePro')->__('N/A');
249
+
250
+ if ($productId && $product = Mage::getModel('catalog/product')->load($productId)) {
251
+ $formattedPrice = $product->getFormatedPrice();
252
+ }
253
+
254
+ return $formattedPrice;
255
+ }
256
+
257
+ public function callbackColumnPrice($value, $row, $column, $isExport)
258
+ {
259
+ $currency = $row->getData('currency');
260
+ if (empty($currency)) {
261
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
262
+ }
263
+
264
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $row->getData('price'));
265
+ }
266
+
267
+ public function callbackColumnGiftPrice($value, $row, $column, $isExport)
268
+ {
269
+ $currency = $row->getData('currency');
270
+ if (empty($currency)) {
271
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
272
+ }
273
+
274
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $row->getData('gift_price'));
275
+ }
276
+
277
+ public function callbackColumnDiscountAmount($value, $row, $column, $isExport)
278
+ {
279
+ $currency = $row->getData('currency');
280
+ if (empty($currency)) {
281
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
282
+ }
283
+
284
+ $discountDetails = $row->getData('discount_details');
285
+ if (empty($discountDetails)) {
286
+ Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, 0);
287
+ }
288
+
289
+ $discountDetails = @json_decode($row->getData('discount_details'), true);
290
+ if (empty($discountDetails['promotion']['value'])) {
291
+ Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, 0);
292
+ }
293
+
294
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice(
295
+ $currency, (int)$discountDetails['promotion']['value']
296
+ );
297
+ }
298
+
299
+ public function callbackColumnGiftOptions($value, $row, $column, $isExport)
300
+ {
301
+ if ($row->getData('gift_type') == '' && $row->getData('gift_message') == '') {
302
+ return Mage::helper('M2ePro')->__('N/A');
303
+ }
304
+
305
+ $giftType = Mage::helper('M2ePro')->escapeHtml($row->getData('gift_type'));
306
+ $giftTypeLabel = Mage::helper('M2ePro')->__('Gift Wrap Type');
307
+
308
+ $giftMessage = Mage::helper('M2ePro')->escapeHtml($row->getData('gift_message'));
309
+ $giftMessageLabel = Mage::helper('M2ePro')->__('Gift Message');
310
+
311
+ $resultHtml = '';
312
+ if (!empty($giftType)) {
313
+ $resultHtml .= "<strong>{$giftTypeLabel}: </strong>{$giftType}<br/>";
314
+ }
315
+
316
+ $resultHtml .= "<strong>{$giftMessageLabel}: </strong>{$giftMessage}";
317
+
318
+ return $resultHtml;
319
+ }
320
+
321
+ public function callbackColumnRowTotal($value, $row, $column, $isExport)
322
+ {
323
+ $currency = $row->getData('currency');
324
+ if (empty($currency)) {
325
+ $currency = $this->order->getMarketplace()->getChildObject()->getDefaultCurrency();
326
+ }
327
+
328
+ $price = (float)$row->getData('price') + (float)$row->getData('gift_price');
329
+ return Mage::getSingleton('M2ePro/Currency')->formatPrice($currency, $price * $row->getData('qty_purchased'));
330
+ }
331
+
332
+ public function getRowUrl($row)
333
+ {
334
+ return '';
335
+ }
336
+
337
+ public function getGridUrl()
338
+ {
339
+ return $this->getUrl('*/*/orderItemGrid', array('_current' => true));
340
+ }
341
+
342
+ //########################################
343
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Synchronization/Form.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Synchronization_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ private $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
12
+
13
+ //########################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ // ---------------------------------------
21
+ $this->setId('amazonSynchronizationForm');
22
+ $this->setContainerId('magento_block_amazon_synchronization');
23
+ $this->setTemplate('M2ePro/common/amazon/synchronization.phtml');
24
+ // ---------------------------------------
25
+ }
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ // ---------------------------------------
30
+ $this->templatesMode = Mage::helper('M2ePro/Module')->getSynchronizationConfig()
31
+ ->getGroupValue('/amazon/templates/', 'mode');
32
+ // ---------------------------------------
33
+
34
+ // ---------------------------------------
35
+ $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
36
+
37
+ $this->reviseAllInProcessingState = !is_null(
38
+ Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
39
+ '/amazon/templates/revise/total/', 'last_listing_product_id'
40
+ )
41
+ );
42
+
43
+ $this->reviseAllStartDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
44
+ '/amazon/templates/revise/total/', 'start_date'
45
+ );
46
+ $this->reviseAllStartDate && $this->reviseAllStartDate = Mage::app()->getLocale()
47
+ ->date(strtotime($this->reviseAllStartDate))
48
+ ->toString($format);
49
+
50
+ $this->reviseAllEndDate = Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
51
+ '/amazon/templates/revise/total/', 'end_date'
52
+ );
53
+ $this->reviseAllEndDate && $this->reviseAllEndDate = Mage::app()->getLocale()
54
+ ->date(strtotime($this->reviseAllEndDate))
55
+ ->toString($format);
56
+ // ---------------------------------------
57
+
58
+ // ---------------------------------------
59
+ $component = Ess_M2ePro_Helper_Component_Amazon::NICK;
60
+ $data = array(
61
+ 'class' => 'ok_button',
62
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
63
+ 'onclick' => "Windows.getFocusedWindow().close(); SynchronizationHandlerObj.runReviseAll('{$component}');",
64
+ );
65
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
66
+ $this->setChild('revise_all_confirm_popup_ok_button', $buttonBlock);
67
+ // ---------------------------------------
68
+
69
+ // ---------------------------------------
70
+ $this->inspectorMode = (int)Mage::helper('M2ePro/Module')->getSynchronizationConfig()->getGroupValue(
71
+ '/defaults/inspector/','mode'
72
+ );
73
+ // ---------------------------------------
74
+
75
+ return parent::_beforeToHtml();
76
+ }
77
+
78
+ //########################################
79
+
80
+ public function isShowReviseAll()
81
+ {
82
+ return Mage::helper('M2ePro/Module')->getConfig()->getGroupValue(
83
+ '/view/synchronization/revise_total/','show'
84
+ );
85
+ }
86
+
87
+ //########################################
88
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template extends Ess_M2ePro_Block_Adminhtml_Common_Template
10
+ {
11
+ protected $nick = Ess_M2ePro_Helper_Component_Amazon::NICK;
12
+
13
+ //########################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ // ---------------------------------------
21
+ $this->setId('commonAmazonTemplate');
22
+ // ---------------------------------------
23
+
24
+ }
25
+
26
+ protected function getAddButtonJavascript()
27
+ {
28
+ $data = array(
29
+ 'target_css_class' => 'add-button-drop-down',
30
+ 'items' => array(
31
+ array(
32
+ 'url' => $this->getUrl(
33
+ '*/adminhtml_common_template/new',
34
+ array(
35
+ 'channel' => $this->nick,
36
+ 'type' => Ess_M2ePro_Block_Adminhtml_Common_Template_Grid::TEMPLATE_SELLING_FORMAT,
37
+ )
38
+ ),
39
+ 'label' => Mage::helper('M2ePro')->__('Selling Format')
40
+ ),
41
+ array(
42
+ 'url' => $this->getUrl(
43
+ '*/adminhtml_common_template/new',
44
+ array(
45
+ 'channel' => $this->nick,
46
+ 'type' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Grid::TEMPLATE_SHIPPING_OVERRIDE
47
+ )
48
+ ),
49
+ 'label' => Mage::helper('M2ePro')->__('Shipping Override')
50
+ ),
51
+ array(
52
+ 'url' => $this->getUrl(
53
+ '*/adminhtml_common_template/new',
54
+ array(
55
+ 'channel' => $this->nick,
56
+ 'type' => Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Grid::TEMPLATE_DESCRIPTION
57
+ )
58
+ ),
59
+ 'label' => Mage::helper('M2ePro')->__('Description')
60
+ ),
61
+ array(
62
+ 'url' => $this->getUrl(
63
+ '*/adminhtml_common_template/new',
64
+ array(
65
+ 'channel' => $this->nick,
66
+ 'type' => Ess_M2ePro_Block_Adminhtml_Common_Template_Grid::TEMPLATE_SYNCHRONIZATION,
67
+ )
68
+ ),
69
+ 'label' => Mage::helper('M2ePro')->__('Synchronization')
70
+ )
71
+ )
72
+ );
73
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
74
+ $dropDownBlock->setData($data);
75
+
76
+ return $dropDownBlock->toHtml();
77
+ }
78
+
79
+ //########################################
80
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Edit.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Edit
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ //########################################
13
+
14
+ protected $_marketplaceId;
15
+ protected $_selectedCategory = array();
16
+
17
+ //########################################
18
+
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+
23
+ // Initialization block
24
+ // ---------------------------------------
25
+ $this->setId('amazonTemplateDescriptionCategoryChooserEdit');
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
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/edit.phtml');
40
+ // ---------------------------------------
41
+ }
42
+
43
+ //########################################
44
+
45
+ protected function _toHtml()
46
+ {
47
+ // ---------------------------------------
48
+ $data = array(
49
+ 'id' => 'category_edit_confirm_button',
50
+ 'class' => '',
51
+ 'label' => Mage::helper('M2ePro')->__('Confirm'),
52
+ 'onclick' => 'AmazonTemplateDescriptionCategoryChooserHandlerObj.confirmCategory();',
53
+ );
54
+ $doneButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
55
+ // ---------------------------------------
56
+
57
+ $cancelWord = Mage::helper('M2ePro')->__('Cancel');
58
+
59
+ $buttonsContainer = <<< HTML
60
+ <div id="chooser_buttons_container">
61
+ <a href="javascript:void(0)"
62
+ onclick="AmazonTemplateDescriptionCategoryChooserHandlerObj.cancelPopUp()">{$cancelWord}</a>
63
+ &nbsp;&nbsp;&nbsp;&nbsp;
64
+ {$doneButton->toHtml()}
65
+ <script type="text/javascript">amazonTemplateDescriptionCategoryChooserTabsJsTabs.moveTabContentInDest();</script>
66
+ </div>
67
+ HTML;
68
+
69
+ /** @var Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs $tabsBlock */
70
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs';
71
+ $tabsBlock = $this->getLayout()->createBlock($blockName);
72
+
73
+ return parent::_toHtml() .
74
+ $tabsBlock->toHtml() .
75
+ '<div id="chooser_tabs_container"></div>' .
76
+ $buttonsContainer;
77
+ }
78
+
79
+ //########################################
80
+
81
+ public function getSelectedCategory()
82
+ {
83
+ return $this->_selectedCategory;
84
+ }
85
+
86
+ public function setSelectedCategory(array $selectedCategory)
87
+ {
88
+ $this->_selectedCategory = $selectedCategory;
89
+ return $this;
90
+ }
91
+
92
+ // ---------------------------------------
93
+
94
+ public function setMarketplaceId($value)
95
+ {
96
+ $this->_marketplaceId = $value;
97
+ return $this;
98
+ }
99
+
100
+ //########################################
101
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs
10
+ extends Mage_Adminhtml_Block_Widget_Tabs
11
+ {
12
+ //########################################
13
+
14
+ const TAB_ID_RECENT = 'recent';
15
+ const TAB_ID_BROWSE = 'browse';
16
+ const TAB_ID_SEARCH = 'search';
17
+
18
+ //########################################
19
+
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ $this->setTemplate('widget/tabshoriz.phtml');
25
+ $this->setId('amazonTemplateDescriptionCategoryChooserTabs');
26
+ $this->setDestElementId('chooser_tabs_container');
27
+ }
28
+
29
+ //########################################
30
+
31
+ protected function _prepareLayout()
32
+ {
33
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs_recent';
34
+ !$this->isNeedToHideRecent() && $this->addTab(self::TAB_ID_RECENT, array(
35
+ 'label' => Mage::helper('M2ePro')->__('Recently Used'),
36
+ 'title' => Mage::helper('M2ePro')->__('Recently Used'),
37
+ 'content' => $this->getLayout()
38
+ ->createBlock($blockName)
39
+ ->toHtml(),
40
+ 'active' => true
41
+ ));
42
+
43
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs_browse';
44
+ $this->addTab(self::TAB_ID_BROWSE, array(
45
+ 'label' => Mage::helper('M2ePro')->__('Browse'),
46
+ 'title' => Mage::helper('M2ePro')->__('Browse'),
47
+ 'content' => $this->getLayout()
48
+ ->createBlock($blockName)
49
+ ->toHtml(),
50
+ 'active' => $this->isNeedToHideRecent() ? true : false
51
+ ));
52
+
53
+ $blockName = 'M2ePro/adminhtml_common_amazon_template_description_category_chooser_tabs_search';
54
+ $this->addTab(self::TAB_ID_SEARCH, array(
55
+ 'label' => Mage::helper('M2ePro')->__('Search'),
56
+ 'title' => Mage::helper('M2ePro')->__('Search'),
57
+ 'content' => $this->getLayout()
58
+ ->createBlock($blockName)
59
+ ->toHtml()
60
+ ));
61
+
62
+ return parent::_prepareLayout();
63
+ }
64
+
65
+ //########################################
66
+
67
+ public function isNeedToHideRecent()
68
+ {
69
+ return Mage::helper('M2ePro/Data_Global')->getValue('category_chooser_hide_recent', true);
70
+ }
71
+
72
+ //########################################
73
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Browse.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs_Browse
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateDescriptionCategoryChooserBrowse');
21
+ // ---------------------------------------
22
+
23
+ // Set template
24
+ // ---------------------------------------
25
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/tabs/browse.phtml');
26
+ // ---------------------------------------
27
+ }
28
+
29
+ //########################################
30
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Recent.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs_Recent
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ protected $_selectedCategory = array();
13
+
14
+ //########################################
15
+
16
+ public function __construct()
17
+ {
18
+ parent::__construct();
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('amazonTemplateDescriptionCategoryChooserRecent');
23
+ // ---------------------------------------
24
+
25
+ // Set template
26
+ // ---------------------------------------
27
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/tabs/recent.phtml');
28
+ // ---------------------------------------
29
+ }
30
+
31
+ //########################################
32
+
33
+ public function getCategories()
34
+ {
35
+ return Mage::helper('M2ePro/Component_Amazon_Category')->getRecent(
36
+ $this->getRequest()->getPost('marketplace_id'),
37
+ array('product_data_nick' => $this->getRequest()->getPost('product_data_nick'),
38
+ 'browsenode_id' => $this->getRequest()->getPost('browsenode_id'),
39
+ 'path' => $this->getRequest()->getPost('category_path'))
40
+ );
41
+ }
42
+
43
+ //########################################
44
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Chooser/Tabs/Search.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Chooser_Tabs_Search
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateDescriptionCategoryChooserSearch');
21
+ // ---------------------------------------
22
+
23
+ // Set template
24
+ // ---------------------------------------
25
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/chooser/tabs/search.phtml');
26
+ // ---------------------------------------
27
+ }
28
+
29
+ //########################################
30
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Specific_Add
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateDescriptionCategorySpecificAdd');
21
+ // ---------------------------------------
22
+
23
+ // Set buttons actions
24
+ // ---------------------------------------
25
+ $this->removeButton('back');
26
+ $this->removeButton('reset');
27
+ $this->removeButton('delete');
28
+ $this->removeButton('add');
29
+ $this->removeButton('save');
30
+ $this->removeButton('edit');
31
+ // ---------------------------------------
32
+
33
+ // ---------------------------------------
34
+ $this->setTemplate('M2ePro/common/amazon/template/description/category/specific/add.phtml');
35
+ // ---------------------------------------
36
+ }
37
+
38
+ //########################################
39
+
40
+ protected function _beforeToHtml()
41
+ {
42
+ $additionalTitle = $this->getRequest()->getParam('current_indexed_xpath');
43
+ $additionalTitle = explode('/', ltrim($additionalTitle, '/'));
44
+ array_shift($additionalTitle);
45
+ $additionalTitle = array_map(function($el) { return preg_replace('/-\d+/', '', $el); }, $additionalTitle);
46
+ $this->setData('additional_title', implode(' > ', $additionalTitle));
47
+
48
+ return parent::_beforeToHtml();
49
+ }
50
+
51
+ protected function _toHtml()
52
+ {
53
+ // ---------------------------------------
54
+ $data = array(
55
+ 'class' => 'specifics_done_button',
56
+ 'label' => Mage::helper('M2ePro')->__('Confirm')
57
+ );
58
+ $doneButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
59
+ // ---------------------------------------
60
+
61
+ $cancelWord = Mage::helper('M2ePro')->__('Cancel');
62
+ $buttonsContainer = <<< HTML
63
+ <div style="margin-top: 17px; text-align: right; position: absolute; left: 83.5%; top: 90%;">
64
+ <a href="javascript:void(0)" class="specifics_cancel_button">{$cancelWord}</a>
65
+ &nbsp;&nbsp;&nbsp;&nbsp;
66
+ {$doneButton->toHtml()}
67
+ </div>
68
+ HTML;
69
+ return parent::_toHtml() . $buttonsContainer;
70
+ }
71
+
72
+ //########################################
73
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Category/Specific/Add/Grid.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Category_Specific_Add_Grid
10
+ extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+ public $marketplaceId;
13
+ public $productDataNick;
14
+
15
+ public $currentXpath;
16
+
17
+ public $searchQuery;
18
+ public $onlyDesired = false;
19
+
20
+ public $selectedSpecifics = array();
21
+ public $renderedSpecifics = array();
22
+
23
+ //########################################
24
+
25
+ public function __construct()
26
+ {
27
+ parent::__construct();
28
+
29
+ // Initialization block
30
+ // ---------------------------------------
31
+ $this->setId('amazonTemplateDescriptionCategorySpecificAddGrid');
32
+ // ---------------------------------------
33
+
34
+ // Set default values
35
+ // ---------------------------------------
36
+ $this->setFilterVisibility(false);
37
+ $this->setPagerVisibility(false);
38
+ $this->setDefaultSort('id');
39
+ $this->setDefaultDir('ASC');
40
+ $this->setSaveParametersInSession(true);
41
+ $this->setUseAjax(true);
42
+ // ---------------------------------------
43
+ }
44
+
45
+ //########################################
46
+
47
+ protected function _prepareCollection()
48
+ {
49
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
50
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
51
+
52
+ $select = $connRead->select()
53
+ ->from(Mage::getSingleton('core/resource')->getTableName('m2epro_amazon_dictionary_specific'))
54
+ ->where('marketplace_id = ?', (int)$this->marketplaceId)
55
+ ->where('product_data_nick = ?', $this->productDataNick)
56
+ ->where('type != ?', Ess_M2ePro_Model_Amazon_Template_Description_Specific::DICTIONARY_TYPE_CONTAINER)
57
+ ->where('xpath LIKE ?', "{$this->currentXpath}/%")
58
+ ->order('title ASC');
59
+
60
+ if ($this->searchQuery) {
61
+ $select->where('title LIKE ?', "%{$this->searchQuery}%");
62
+ }
63
+
64
+ $filteredResult = array();
65
+
66
+ $queryStmt = $select->query();
67
+ while ($row = $queryStmt->fetch()) {
68
+
69
+ if (in_array($row['xpath'], $this->renderedSpecifics) ||
70
+ in_array($row['xpath'], $this->selectedSpecifics)) {
71
+ continue;
72
+ }
73
+
74
+ $row['data_definition'] = (array)json_decode($row['data_definition'], true);
75
+ $row['is_desired'] = !empty($row['data_definition']['is_desired']) && $row['data_definition']['is_desired'];
76
+
77
+ if ($this->onlyDesired && !$row['is_desired']) {
78
+ continue;
79
+ }
80
+
81
+ $filteredResult[] = $row;
82
+ }
83
+
84
+ usort($filteredResult, function($a, $b) {
85
+
86
+ if ($a['is_desired'] && !$b['is_desired']) {
87
+ return -1;
88
+ }
89
+
90
+ if ($b['is_desired'] && !$a['is_desired']) {
91
+ return 1;
92
+ }
93
+
94
+ return $a['title'] == $b['title'] ? 0 : ($a['title'] > $b['title'] ? 1 : -1);
95
+ });
96
+
97
+ $collection = new Varien_Data_Collection();
98
+ foreach ($filteredResult as $item) {
99
+ $collection->addItem(new Varien_Object($item));
100
+ }
101
+ $this->setCollection($collection);
102
+
103
+ return parent::_prepareCollection();
104
+ }
105
+
106
+ protected function _prepareColumns()
107
+ {
108
+ $this->addColumn('title', array(
109
+ 'header' => Mage::helper('M2ePro')->__('Specific'),
110
+ 'align' => 'left',
111
+ 'type' => 'text',
112
+ 'index' => 'title',
113
+ 'width' => '700px',
114
+ 'filter' => false,
115
+ 'sortable' => false,
116
+ 'frame_callback' => array($this, 'callbackColumnTitle')
117
+ ));
118
+
119
+ $this->addColumn('is_desired', array(
120
+ 'header' => Mage::helper('M2ePro')->__('Desired'),
121
+ 'align' => 'center',
122
+ 'type' => 'text',
123
+ 'index' => 'is_desired',
124
+ 'width' => '80px',
125
+ 'filter' => false,
126
+ 'sortable' => false,
127
+ 'frame_callback' => array($this, 'callbackColumnIsDesired')
128
+ ));
129
+
130
+ $this->addColumn('actions', array(
131
+ 'header' => Mage::helper('M2ePro')->__('Action'),
132
+ 'align' => 'center',
133
+ 'type' => 'text',
134
+ 'width' => '80px',
135
+ 'filter' => false,
136
+ 'sortable' => false,
137
+ 'frame_callback' => array($this, 'callbackColumnActions'),
138
+ ));
139
+ }
140
+
141
+ //########################################
142
+
143
+ public function callbackColumnTitle($title, $row, $column, $isExport)
144
+ {
145
+ strlen($title) > 60 && $title = substr($title, 0, 60) . '...';
146
+ $title = Mage::helper('M2ePro')->escapeHtml($title);
147
+
148
+ $path = explode('/', ltrim($row->getData('xpath'), '/'));
149
+ array_pop($path);
150
+ $path = implode(' > ', $path);
151
+ $path = Mage::helper('M2ePro')->escapeHtml($path);
152
+
153
+ $fullPath = $path;
154
+ strlen($path) > 135 && $path = substr($path, 0, 135) . '...';
155
+
156
+ $foundInWord = Mage::helper('M2ePro')->__('Found In: ');
157
+
158
+ return <<<HTML
159
+ <div style="margin-left: 3px">
160
+ <a href="javascript:void(0);" class="specific_search_result_row" xpath ="{$row->getData('xpath')}"
161
+ xml_tag = {$row->getData('xml_tag')}>
162
+ {$title}
163
+ </a><br/>
164
+ <span style="font-weight: bold;">{$foundInWord}</span>&nbsp;
165
+ <span title="{$fullPath}">{$path}</span><br/>
166
+ </div>
167
+ HTML;
168
+ }
169
+
170
+ public function callbackColumnIsDesired($value, $row, $column, $isExport)
171
+ {
172
+ return $value ? Mage::helper('M2ePro')->__('Yes') : Mage::helper('M2ePro')->__('No');
173
+ }
174
+
175
+ public function callbackColumnActions($value, $row, $column, $isExport)
176
+ {
177
+ $select = Mage::helper('M2ePro')->__('Select');
178
+ return <<<HTML
179
+ <a href="javascript:void(0);" class="specific_search_result_row" xpath = {$row->getData('xpath')}
180
+ xml_tag = {$row->getData('xml_tag')}>
181
+ {$select}
182
+ </a>
183
+ HTML;
184
+ }
185
+
186
+ //########################################
187
+
188
+ public function setMarketplaceId($marketplaceId)
189
+ {
190
+ $this->marketplaceId = $marketplaceId;
191
+ return $this;
192
+ }
193
+
194
+ public function setProductDataNick($productDataNick)
195
+ {
196
+ $this->productDataNick = $productDataNick;
197
+ return $this;
198
+ }
199
+
200
+ public function setCurrentXpath($indexedXpath)
201
+ {
202
+ $this->currentXpath = preg_replace('/-\d+/', '', $indexedXpath);
203
+ return $this;
204
+ }
205
+
206
+ public function setRenderedSpecifics(array $specifics)
207
+ {
208
+ $this->renderedSpecifics = $this->replaceWithDictionaryXpathes($specifics);
209
+ return $this;
210
+ }
211
+
212
+ public function setSelectedSpecifics(array $specifics)
213
+ {
214
+ $this->selectedSpecifics = $this->replaceWithDictionaryXpathes($specifics);
215
+ return $this;
216
+ }
217
+
218
+ public function setOnlyDesired($value)
219
+ {
220
+ $this->onlyDesired = $value;
221
+ return $this;
222
+ }
223
+
224
+ public function setSearchQuery($searchQuery)
225
+ {
226
+ $this-> searchQuery = $searchQuery;
227
+ return $this;
228
+ }
229
+
230
+ // ---------------------------------------
231
+
232
+ private function replaceWithDictionaryXpathes(array $xPathes)
233
+ {
234
+ return array_map(function($el) { return preg_replace('/-\d+/', '', $el); }, $xPathes);
235
+ }
236
+
237
+ //########################################
238
+
239
+ public function getGridUrl()
240
+ {
241
+ return false;
242
+ }
243
+
244
+ public function getRowUrl($row)
245
+ {
246
+ return false;
247
+ }
248
+
249
+ //########################################
250
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit
10
+ extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateDescriptionEdit');
21
+ $this->_blockGroup = 'M2ePro';
22
+ $this->_controller = 'adminhtml_common_amazon_template_description';
23
+ $this->_mode = 'edit';
24
+ // ---------------------------------------
25
+
26
+ // Set header text
27
+ // ---------------------------------------
28
+ $componentName = !Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()
29
+ ? ' ' . Mage::helper('M2ePro/Component_Amazon')->getTitle() : '';
30
+
31
+ if ($this->isEditMode()) {
32
+ $this->_headerText = Mage::helper('M2ePro')->__("Edit%s Description Policy", $componentName);
33
+ $this->_headerText .= ' "'.$this->escapeHtml(
34
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
35
+ } else {
36
+ $this->_headerText = Mage::helper('M2ePro')->__("Add%s Description Policy", $componentName);
37
+ }
38
+ // ---------------------------------------
39
+
40
+ // Set buttons actions
41
+ // ---------------------------------------
42
+ $this->removeButton('back');
43
+ $this->removeButton('reset');
44
+ $this->removeButton('delete');
45
+ $this->removeButton('add');
46
+ $this->removeButton('save');
47
+ $this->removeButton('edit');
48
+ // ---------------------------------------
49
+
50
+ // ---------------------------------------
51
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
52
+ $this->_addButton('back', array(
53
+ 'label' => Mage::helper('M2ePro')->__('Back'),
54
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
55
+ 'class' => 'back'
56
+ ));
57
+ // ---------------------------------------
58
+
59
+ if ($this->isEditMode()) {
60
+
61
+ $headId = 'common-amazon-template-description';
62
+ // ---------------------------------------
63
+ $this->_addButton('duplicate', array(
64
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
65
+ 'onclick' => "AmazonTemplateDescriptionHandlerObj.duplicate_click('{$headId}')",
66
+ 'class' => 'add M2ePro_duplicate_button'
67
+ ));
68
+ // ---------------------------------------
69
+
70
+ // ---------------------------------------
71
+ $this->_addButton('delete', array(
72
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
73
+ 'onclick' => 'CommonHandlerObj.delete_click()',
74
+ 'class' => 'delete M2ePro_delete_button'
75
+ ));
76
+ // ---------------------------------------
77
+ }
78
+
79
+ // ---------------------------------------
80
+ $this->_addButton('save', array(
81
+ 'label' => Mage::helper('M2ePro')->__('Save'),
82
+ 'onclick' => 'AmazonTemplateDescriptionHandlerObj.save_click()',
83
+ 'class' => 'save'
84
+ ));
85
+ // ---------------------------------------
86
+
87
+ // ---------------------------------------
88
+ $this->_addButton('save_and_continue', array(
89
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
90
+ 'onclick' => 'AmazonTemplateDescriptionHandlerObj.save_and_edit_click()',
91
+ 'class' => 'save'
92
+ ));
93
+ // ---------------------------------------
94
+ }
95
+
96
+ //########################################
97
+
98
+ private function isEditMode()
99
+ {
100
+ $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
101
+ return $templateModel && $templateModel->getId();
102
+ }
103
+
104
+ //########################################
105
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Form.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonTemplateDescriptionEditForm');
20
+ // ---------------------------------------
21
+ }
22
+
23
+ //########################################
24
+
25
+ protected function _prepareForm()
26
+ {
27
+ $form = new Varien_Data_Form(array(
28
+ 'id' => 'edit_form',
29
+ 'method' => 'post',
30
+ 'action' => $this->getUrl('*/*/save'),
31
+ 'enctype' => 'multipart/form-data'
32
+ ));
33
+
34
+ $form->setUseContainer(true);
35
+ $this->setForm($form);
36
+
37
+ return parent::_prepareForm();
38
+ }
39
+
40
+ //########################################
41
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('amazonTemplateDescriptionEditTabs');
20
+ // ---------------------------------------
21
+
22
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
23
+ $this->setDestElementId('edit_form');
24
+ }
25
+
26
+ //########################################
27
+
28
+ protected function _beforeToHtml()
29
+ {
30
+ $this->addTab('general', array(
31
+ 'label' => Mage::helper('M2ePro')->__('General'),
32
+ 'title' => Mage::helper('M2ePro')->__('General'),
33
+ 'content' => $this->getLayout()->createBlock(
34
+ 'M2ePro/adminhtml_common_amazon_template_description_edit_tabs_general'
35
+ )->toHtml(),
36
+ ));
37
+
38
+ $this->addTab('definition', array(
39
+ 'label' => Mage::helper('M2ePro')->__('Definition'),
40
+ 'title' => Mage::helper('M2ePro')->__('Definition'),
41
+ 'content' => $this->getLayout()->createBlock(
42
+ 'M2ePro/adminhtml_common_amazon_template_description_edit_tabs_definition'
43
+ )->toHtml(),
44
+ ));
45
+
46
+ $this->addTab('specifics', array(
47
+ 'label' => Mage::helper('M2ePro')->__('Specifics'),
48
+ 'title' => Mage::helper('M2ePro')->__('Specifics'),
49
+ 'content' => $this->getLayout()->createBlock(
50
+ 'M2ePro/adminhtml_common_amazon_template_description_edit_tabs_specifics'
51
+ )->toHtml(),
52
+ ));
53
+
54
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'general'));
55
+
56
+ return parent::_beforeToHtml();
57
+ }
58
+
59
+ //########################################
60
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Definition.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs_Definition
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateDescriptionEditTabsDefinition');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/template/description/tabs/definition.phtml');
24
+ }
25
+
26
+ //########################################
27
+
28
+ protected function _beforeToHtml()
29
+ {
30
+ // ---------------------------------------
31
+ $data = array(
32
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
33
+ 'onclick' => "AttributeHandlerObj.appendToText('select_attributes_for_title', 'title_template');",
34
+ 'class' => 'select_attributes_for_title_button'
35
+ );
36
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
37
+ $this->setChild('select_attributes_for_title_button', $buttonBlock);
38
+ // ---------------------------------------
39
+
40
+ // ---------------------------------------
41
+ $data = array(
42
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
43
+ 'onclick' => "AttributeHandlerObj.appendToTextarea('#' + $('select_attributes').value + '#');",
44
+ 'class' => 'add_product_attribute_button',
45
+ );
46
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
47
+ $this->setChild('add_product_attribute_button', $buttonBlock);
48
+ // ---------------------------------------
49
+
50
+ // ---------------------------------------
51
+ for ($i = 0; $i < 4; $i++) {
52
+ $button = $this->getMultiElementButton('target_audience', $i);
53
+ $this->setChild("select_attributes_for_target_audience_{$i}_button", $button);
54
+ }
55
+ // ---------------------------------------
56
+
57
+ // ---------------------------------------
58
+ for ($i = 0; $i < 5; $i++) {
59
+ $button = $this->getMultiElementButton('bullet_points', $i);
60
+ $this->setChild("select_attributes_for_bullet_points_{$i}_button", $button);
61
+ }
62
+ // ---------------------------------------
63
+
64
+ // ---------------------------------------
65
+ for ($i = 0; $i < 5; $i++) {
66
+ $button = $this->getMultiElementButton('search_terms', $i);
67
+ $this->setChild("select_attributes_for_search_terms_{$i}_button", $button);
68
+ }
69
+ // ---------------------------------------
70
+
71
+ // ---------------------------------------
72
+ $attributeHelper = Mage::helper('M2ePro/Magento_Attribute');
73
+ $this->setData('all_attributes', $attributeHelper->getAll());
74
+ $this->setData('general_attributes', $attributeHelper->getGeneralFromAllAttributeSets());
75
+ // ---------------------------------------
76
+
77
+ return parent::_beforeToHtml();
78
+ }
79
+
80
+ //########################################
81
+
82
+ private function getMultiElementButton($type, $index)
83
+ {
84
+ $onClick = <<<JS
85
+ AttributeHandlerObj.appendToText('select_attributes_for_{$type}_{$index}', '{$type}_{$index}');
86
+ AmazonTemplateDescriptionDefinitionHandlerObj.multi_element_keyup('{$type}',{value:' '});
87
+ JS;
88
+ $data = array(
89
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
90
+ 'onclick' => $onClick,
91
+ 'class' => "select_attributes_for_{$type}_{$index}_button"
92
+ );
93
+ return $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
94
+ }
95
+
96
+ //########################################
97
+
98
+ public function getForceAddedAttributeOptionHtml($attributeCode, $availableValues, $value = null)
99
+ {
100
+ if (empty($attributeCode) ||
101
+ Mage::helper('M2ePro/Magento_Attribute')->isExistInAttributesArray($attributeCode, $availableValues)) {
102
+ return '';
103
+ }
104
+
105
+ $attributeLabel = Mage::helper('M2ePro/Magento_Attribute')->getAttributeLabel($attributeCode);
106
+ $html = "<option %s selected=\"selected\">{$attributeLabel}</option>";
107
+
108
+ return is_null($value) ? sprintf($html, "value='{$attributeCode}'")
109
+ : sprintf($html, "attribute_code='{$attributeCode}' value='{$value}'");
110
+ }
111
+
112
+ // ---------------------------------------
113
+
114
+ public function getWeightUnits()
115
+ {
116
+ return array(
117
+ 'GR',
118
+ 'KG',
119
+ 'OZ',
120
+ 'LB',
121
+ 'MG'
122
+ );
123
+ }
124
+
125
+ public function getDimensionsUnits()
126
+ {
127
+ return array(
128
+ 'MM',
129
+ 'CM',
130
+ 'M',
131
+ 'IN',
132
+ 'FT'
133
+ );
134
+ }
135
+
136
+ //########################################
137
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/General.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs_General
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateDescriptionEditTabsGeneral');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/template/description/tabs/general.phtml');
24
+ }
25
+
26
+ //########################################
27
+
28
+ protected function _beforeToHtml()
29
+ {
30
+ $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
31
+
32
+ // ---------------------------------------
33
+ $marketplaces = Mage::helper('M2ePro/Component_Amazon')->getMarketplacesAvailableForAsinCreation();
34
+ $marketplaces = $marketplaces->toArray();
35
+ $this->setData('marketplaces', $marketplaces['items']);
36
+ // ---------------------------------------
37
+
38
+ // ---------------------------------------
39
+ $marketplaceLocked = $categoryLocked = $newAsinSwitcherLocked = false;
40
+
41
+ if ($templateModel && $templateModel->getId()) {
42
+ $marketplaceLocked = $templateModel->isLocked();
43
+ $categoryLocked = $templateModel->getChildObject()->isLockedForCategoryChange();
44
+ $newAsinSwitcherLocked = $templateModel->getChildObject()->isLockedForNewAsinCreation();
45
+ }
46
+
47
+ $this->setData('marketplace_locked', $marketplaceLocked);
48
+ $this->setData('category_locked', $categoryLocked);
49
+ $this->setData('new_asin_switcher_locked', $newAsinSwitcherLocked);
50
+ // ---------------------------------------
51
+
52
+ // ---------------------------------------
53
+ $attributeHelper = Mage::helper('M2ePro/Magento_Attribute');
54
+ $this->setData('all_attributes', $attributeHelper->getAll());
55
+ $this->setData('general_attributes', $attributeHelper->getGeneralFromAllAttributeSets());
56
+ // ---------------------------------------
57
+
58
+ return parent::_beforeToHtml();
59
+ }
60
+
61
+ //########################################
62
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Edit/Tabs/Specifics.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Edit_Tabs_Specifics
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateDescriptionEditTabsSpecifics');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/template/description/tabs/specifics.phtml');
24
+ }
25
+
26
+ //########################################
27
+
28
+ protected function _beforeToHtml()
29
+ {
30
+ // ---------------------------------------
31
+ $this->setData('attributes', Mage::helper('M2ePro/Magento_Attribute')->getAll());
32
+ // ---------------------------------------
33
+
34
+ return parent::_beforeToHtml();
35
+ }
36
+
37
+ //########################################
38
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Description/Grid.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Description_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('templateDescriptionGrid');
20
+ // ---------------------------------------
21
+
22
+ // Set default values
23
+ // ---------------------------------------
24
+ $this->setDefaultSort('id');
25
+ $this->setDefaultDir('ASC');
26
+ $this->setSaveParametersInSession(true);
27
+ $this->setUseAjax(true);
28
+ // ---------------------------------------
29
+ }
30
+
31
+ //########################################
32
+
33
+ protected function _prepareCollection()
34
+ {
35
+ $collection = Mage::getModel('M2ePro/Template_Description')->getCollection();
36
+ $collection->addFieldToFilter('main_table.component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
37
+
38
+ $collection->getSelect()->join(
39
+ array('atd' => Mage::getModel('M2ePro/Amazon_Template_Description')->getResource()->getMainTable()),
40
+ 'atd.template_description_id=main_table.id',
41
+ array('marketplace_id','category_path','browsenode_id','is_new_asin_accepted')
42
+ );
43
+
44
+ $collection->getSelect()->join(
45
+ array('mm' => Mage::getModel('M2ePro/Marketplace')->getResource()->getMainTable()),
46
+ 'mm.id=atd.marketplace_id',
47
+ array('status')
48
+ );
49
+
50
+ $collection->addFieldToFilter('mm.status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
51
+
52
+ $this->setCollection($collection);
53
+ return parent::_prepareCollection();
54
+ }
55
+
56
+ protected function _prepareColumns()
57
+ {
58
+ $this->addColumn('id', array(
59
+ 'header' => Mage::helper('M2ePro')->__('ID'),
60
+ 'align' => 'right',
61
+ 'type' => 'number',
62
+ 'width' => '50px',
63
+ 'index' => 'id',
64
+ 'filter_index' => 'main_table.id',
65
+ 'frame_callback' => array($this, 'callbackColumnId')
66
+ ));
67
+
68
+ $this->addColumn('title', array(
69
+ 'header' => Mage::helper('M2ePro')->__('Title / Category'),
70
+ 'align' => 'left',
71
+ 'type' => 'text',
72
+ 'width' => '500px',
73
+ 'index' => 'title',
74
+ 'filter_index' => 'main_table.title',
75
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
76
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
77
+ ));
78
+
79
+ $this->addColumn('new_asin', array(
80
+ 'header' => Mage::helper('M2ePro')->__('New ASIN / ISBN'),
81
+ 'align' => 'left',
82
+ 'type' => 'options',
83
+ 'options' => array(
84
+ '1' => Mage::helper('M2ePro')->__('Yes'),
85
+ '0' => Mage::helper('M2ePro')->__('No')
86
+ ),
87
+ 'width' => '50px',
88
+ 'index' => 'is_new_asin_accepted',
89
+ 'filter_index' => 'atd.is_new_asin_accepted'
90
+ ));
91
+
92
+ $this->addColumn('marketplace', array(
93
+ 'header' => Mage::helper('M2ePro')->__('Marketplace'),
94
+ 'align' => 'left',
95
+ 'type' => 'options',
96
+ 'options' => Mage::helper('M2ePro/Component_Amazon')->getMarketplacesAvailableForAsinCreation()
97
+ ->toOptionHash(),
98
+ 'width' => '100px',
99
+ 'index' => 'marketplace_id',
100
+ 'filter_index' => 'atd.marketplace_id'
101
+ ));
102
+
103
+ $this->addColumn('update_date', array(
104
+ 'header' => Mage::helper('M2ePro')->__('Update Date'),
105
+ 'align' => 'left',
106
+ 'width' => '80px',
107
+ 'type' => 'datetime',
108
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
109
+ 'index' => 'update_date',
110
+ 'filter_index' => 'main_table.update_date'
111
+ ));
112
+
113
+ $this->addColumn('create_date', array(
114
+ 'header' => Mage::helper('M2ePro')->__('Creation Date'),
115
+ 'align' => 'left',
116
+ 'width' => '80px',
117
+ 'type' => 'datetime',
118
+ 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM),
119
+ 'index' => 'create_date',
120
+ 'filter_index' => 'main_table.create_date'
121
+ ));
122
+
123
+ $this->addColumn('actions', array(
124
+ 'header' => Mage::helper('M2ePro')->__('Actions'),
125
+ 'align' => 'left',
126
+ 'width' => '100px',
127
+ 'type' => 'action',
128
+ 'index' => 'actions',
129
+ 'filter' => false,
130
+ 'sortable' => false,
131
+ 'getter' => 'getId',
132
+ 'actions' => array(
133
+ array(
134
+ 'caption' => Mage::helper('M2ePro')->__('Edit'),
135
+ 'url' => array('base'=> '*/*/edit'),
136
+ 'field' => 'id'
137
+ ),
138
+ array(
139
+ 'caption' => Mage::helper('M2ePro')->__('Delete'),
140
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?'),
141
+ 'url' => array('base' => '*/*/delete'),
142
+ 'field' => 'ids'
143
+ ),
144
+ )
145
+ ));
146
+ }
147
+
148
+ //########################################
149
+
150
+ protected function _prepareMassaction()
151
+ {
152
+ // Set massaction identifiers
153
+ // ---------------------------------------
154
+ $this->setMassactionIdField('main_table.id');
155
+ $this->getMassactionBlock()->setFormFieldName('ids');
156
+ // ---------------------------------------
157
+
158
+ // Set delete action
159
+ // ---------------------------------------
160
+ $this->getMassactionBlock()->addItem('delete', array(
161
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
162
+ 'url' => $this->getUrl('*/*/delete'),
163
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
164
+ ));
165
+ // ---------------------------------------
166
+
167
+ return parent::_prepareMassaction();
168
+ }
169
+
170
+ //########################################
171
+
172
+ public function callbackColumnId($value, $row, $column, $isExport)
173
+ {
174
+ return $value.'&nbsp;';
175
+ }
176
+
177
+ // ---------------------------------------
178
+
179
+ public function callbackColumnTitle($value, $row, $column, $isExport)
180
+ {
181
+ $titleWord = Mage::helper('M2ePro')->__('Title');
182
+ $title = Mage::helper('M2ePro')->escapeHtml($value);
183
+
184
+ $categoryWord = Mage::helper('M2ePro')->__('Category');
185
+ $categoryPath = !empty($row['category_path']) ? "{$row['category_path']} ({$row['browsenode_id']})"
186
+ : Mage::helper('M2ePro')->__('Not Set');
187
+ return <<<HTML
188
+ <span style="font-weight: bold">{$titleWord}</span>: {$title}
189
+ <div>
190
+ <span style="font-weight: bold">{$categoryWord}</span>: <span style="color: #505050">{$categoryPath}</span><br/>
191
+ </div>
192
+ HTML;
193
+ }
194
+
195
+ //########################################
196
+
197
+ protected function callbackFilterTitle($collection, $column)
198
+ {
199
+ $value = $column->getFilter()->getValue();
200
+
201
+ if ($value == null) {
202
+ return;
203
+ }
204
+
205
+ $collection->getSelect()->where(
206
+ '`atd`.`category_path` LIKE ? OR `atd`.`browsenode_id` LIKE ? OR `main_table`.`title` LIKE ?',
207
+ '%'. $value .'%'
208
+ );
209
+ }
210
+
211
+ //########################################
212
+
213
+ public function getGridUrl()
214
+ {
215
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/grid', array('_current'=>true));
216
+ }
217
+
218
+ public function getRowUrl($row)
219
+ {
220
+ return $this->getUrl('*/adminhtml_common_amazon_template_description/edit', array('id' => $row->getData('id')));
221
+ }
222
+
223
+ //########################################
224
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Grid.php ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Template_Grid
11
+ {
12
+ const TEMPLATE_SHIPPING_OVERRIDE = 'shipping_override';
13
+ const TEMPLATE_DESCRIPTION = 'description';
14
+
15
+ protected $nick = Ess_M2ePro_Helper_Component_Amazon::NICK;
16
+
17
+ private $enabledMarketplacesCollection = NULL;
18
+
19
+ //########################################
20
+
21
+ public function __construct()
22
+ {
23
+ parent::__construct();
24
+
25
+ // Initialization block
26
+ // ---------------------------------------
27
+ $this->setId('commonAmazonTemplateGrid');
28
+ // ---------------------------------------
29
+ }
30
+
31
+ //########################################
32
+
33
+ protected function _prepareCollection()
34
+ {
35
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
36
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
37
+
38
+ // Prepare selling format collection
39
+ // ---------------------------------------
40
+ $collectionSellingFormat = Mage::getModel('M2ePro/Template_SellingFormat')->getCollection();
41
+ $collectionSellingFormat->getSelect()->reset(Varien_Db_Select::COLUMNS);
42
+ $collectionSellingFormat->getSelect()->columns(
43
+ array(
44
+ 'id as template_id',
45
+ 'title',
46
+ new Zend_Db_Expr('\''.self::TEMPLATE_SELLING_FORMAT.'\' as `type`'),
47
+ new Zend_Db_Expr('\'0\' as `marketplace_id`'),
48
+ 'create_date',
49
+ 'update_date',
50
+ new Zend_Db_Expr('NULL as `category_path`'),
51
+ new Zend_Db_Expr('NULL as `browsenode_id`'),
52
+ new Zend_Db_Expr('NULL as `is_new_asin_accepted`')
53
+ )
54
+ );
55
+ $collectionSellingFormat->getSelect()->where('component_mode = (?)', $this->nick);
56
+ // ---------------------------------------
57
+
58
+ // Prepare synchronization collection
59
+ // ---------------------------------------
60
+ $collectionSynchronization = Mage::getModel('M2ePro/Template_Synchronization')->getCollection();
61
+ $collectionSynchronization->getSelect()->reset(Varien_Db_Select::COLUMNS);
62
+ $collectionSynchronization->getSelect()->columns(
63
+ array(
64
+ 'id as template_id',
65
+ 'title',
66
+ new Zend_Db_Expr('\''.self::TEMPLATE_SYNCHRONIZATION.'\' as `type`'),
67
+ new Zend_Db_Expr('\'0\' as `marketplace_id`'),
68
+ 'create_date',
69
+ 'update_date',
70
+ new Zend_Db_Expr('NULL as `category_path`'),
71
+ new Zend_Db_Expr('NULL as `browsenode_id`'),
72
+ new Zend_Db_Expr('NULL as `is_new_asin_accepted`')
73
+ )
74
+ );
75
+ $collectionSynchronization->getSelect()->where('component_mode = (?)', $this->nick);
76
+ // ---------------------------------------
77
+
78
+ // Prepare shipping override collection
79
+ // ---------------------------------------
80
+ $collectionShippingOverride = Mage::getModel('M2ePro/Amazon_Template_ShippingOverride')->getCollection();
81
+ $collectionShippingOverride->getSelect()->reset(Varien_Db_Select::COLUMNS);
82
+ $collectionShippingOverride->getSelect()->columns(
83
+ array(
84
+ 'id as template_id',
85
+ 'title',
86
+ new Zend_Db_Expr('\''.self::TEMPLATE_SHIPPING_OVERRIDE.'\' as `type`'),
87
+ 'marketplace_id',
88
+ 'create_date',
89
+ 'update_date',
90
+ new Zend_Db_Expr('NULL as `category_path`'),
91
+ new Zend_Db_Expr('NULL as `browsenode_id`'),
92
+ new Zend_Db_Expr('NULL as `is_new_asin_accepted`')
93
+ )
94
+ );
95
+ // ---------------------------------------
96
+
97
+ // Prepare shipping override collection
98
+ // ---------------------------------------
99
+ $collectionDescription = Mage::helper('M2ePro/Component_Amazon')->getCollection('Template_Description');
100
+
101
+ $collectionDescription->getSelect()->join(
102
+ array('mm' => Mage::getModel('M2ePro/Marketplace')->getResource()->getMainTable()),
103
+ 'mm.id=second_table.marketplace_id',
104
+ array()
105
+ );
106
+
107
+ $collectionDescription->addFieldToFilter('mm.status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
108
+
109
+ $collectionDescription->getSelect()->reset(Varien_Db_Select::COLUMNS);
110
+ $collectionDescription->getSelect()->columns(
111
+ array(
112
+ 'id as template_id',
113
+ 'title',
114
+ new Zend_Db_Expr('\''.self::TEMPLATE_DESCRIPTION.'\' as `type`'),
115
+ 'second_table.marketplace_id',
116
+ 'create_date',
117
+ 'update_date',
118
+ 'second_table.category_path',
119
+ 'second_table.browsenode_id',
120
+ 'second_table.is_new_asin_accepted'
121
+ )
122
+ );
123
+ // ---------------------------------------
124
+
125
+ // Prepare union select
126
+ // ---------------------------------------
127
+ $unionSelect = $connRead->select();
128
+ $unionSelect->union(array(
129
+ $collectionSellingFormat->getSelect(),
130
+ $collectionSynchronization->getSelect(),
131
+ $collectionDescription->getSelect(),
132
+ $collectionShippingOverride->getSelect()
133
+ ));
134
+ // ---------------------------------------
135
+
136
+ // Prepare result collection
137
+ // ---------------------------------------
138
+ $resultCollection = new Varien_Data_Collection_Db($connRead);
139
+ $resultCollection->getSelect()->reset()->from(
140
+ array('main_table' => $unionSelect),
141
+ array(
142
+ 'template_id',
143
+ 'title',
144
+ 'type',
145
+ 'marketplace_id',
146
+ 'create_date',
147
+ 'update_date',
148
+ 'category_path',
149
+ 'browsenode_id',
150
+ 'is_new_asin_accepted'
151
+ )
152
+ );
153
+ // ---------------------------------------
154
+
155
+ // echo $resultCollection->getSelectSql(true); exit;
156
+
157
+ $this->setCollection($resultCollection);
158
+
159
+ return parent::_prepareCollection();
160
+ }
161
+
162
+ //########################################
163
+
164
+ protected function _prepareColumns()
165
+ {
166
+ $this->addColumnAfter('marketplace', array(
167
+ 'header' => Mage::helper('M2ePro')->__('Marketplace'),
168
+ 'align' => 'left',
169
+ 'type' => 'options',
170
+ 'width' => '100px',
171
+ 'index' => 'marketplace_id',
172
+ 'filter_index' => 'marketplace_id',
173
+ 'filter_condition_callback' => array($this, 'callbackFilterMarketplace'),
174
+ 'frame_callback'=> array($this, 'callbackColumnMarketplace'),
175
+ 'options' => $this->getEnabledMarketplaceTitles()
176
+ ), 'type');
177
+
178
+ parent::_prepareColumns();
179
+
180
+ $options = array(
181
+ self::TEMPLATE_SELLING_FORMAT => Mage::helper('M2ePro')->__('Selling Format'),
182
+ self::TEMPLATE_SHIPPING_OVERRIDE => Mage::helper('M2ePro')->__('Shipping Override'),
183
+ self::TEMPLATE_DESCRIPTION => Mage::helper('M2ePro')->__('Description'),
184
+ self::TEMPLATE_SYNCHRONIZATION => Mage::helper('M2ePro')->__('Synchronization')
185
+ );
186
+
187
+ $this->getColumn('type')->setData('options', $options);
188
+
189
+ $this->getColumn('title')->setData('header', Mage::helper('M2ePro')->__('Title / Description Policy Category'));
190
+ $this->getColumn('title')->setData('frame_callback', array($this, 'callbackColumnTitle'));
191
+ $this->getColumn('title')->setData('filter_condition_callback', array($this, 'callbackFilterTitle'));
192
+
193
+ return $this;
194
+ }
195
+
196
+ //########################################
197
+
198
+ public function callbackColumnTitle($value, $row, $column, $isExport)
199
+ {
200
+ if ($row->getData('type') != self::TEMPLATE_DESCRIPTION) {
201
+ return $value;
202
+ }
203
+
204
+ $titleWord = Mage::helper('M2ePro')->__('Title');
205
+ $title = Mage::helper('M2ePro')->escapeHtml($value);
206
+
207
+ $categoryWord = Mage::helper('M2ePro')->__('Category');
208
+ $categoryPath = !empty($row['category_path']) ? "{$row['category_path']} ({$row['browsenode_id']})"
209
+ : Mage::helper('M2ePro')->__('Not Set');
210
+
211
+ $newAsin = Mage::helper('M2ePro')->__('New ASIN/ISBN');
212
+ $newAsinAccepted = Mage::helper('M2ePro')->__('No');
213
+ if ($row->getData('is_new_asin_accepted') == 1) {
214
+ $newAsinAccepted = Mage::helper('M2ePro')->__('Yes');
215
+ }
216
+
217
+ return <<<HTML
218
+ {$title}
219
+ <div>
220
+ <span style="font-weight: bold">{$newAsin}</span>: <span style="color: #505050">{$newAsinAccepted}</span><br/>
221
+ <span style="font-weight: bold">{$categoryWord}</span>: <span style="color: #505050">{$categoryPath}</span><br/>
222
+ </div>
223
+ HTML;
224
+ }
225
+
226
+ public function callbackColumnMarketplace($value, $row, $column, $isExport)
227
+ {
228
+ if (empty($value)) {
229
+ return Mage::helper('M2ePro')->__('Any');
230
+ }
231
+
232
+ return $value;
233
+ }
234
+
235
+ //########################################
236
+
237
+ protected function callbackFilterTitle($collection, $column)
238
+ {
239
+ $value = $column->getFilter()->getValue();
240
+
241
+ if ($value == null) {
242
+ return;
243
+ }
244
+
245
+ $collection->getSelect()->where(
246
+ 'category_path LIKE ? OR browsenode_id LIKE ? OR title LIKE ?',
247
+ '%'. $value .'%'
248
+ );
249
+ }
250
+
251
+ protected function callbackFilterMarketplace($collection, $column)
252
+ {
253
+ $value = $column->getFilter()->getValue();
254
+
255
+ if ($value == null) {
256
+ return;
257
+ }
258
+
259
+ $collection->getSelect()->where('marketplace_id = 0 OR marketplace_id = ?', (int)$value);
260
+ }
261
+
262
+ //########################################
263
+
264
+ public function getRowUrl($row)
265
+ {
266
+ return $this->getUrl(
267
+ '*/adminhtml_common_template/edit',
268
+ array(
269
+ 'id' => $row->getData('template_id'),
270
+ 'type' => $row->getData('type'),
271
+ 'back' => 1
272
+ )
273
+ );
274
+ }
275
+
276
+ //########################################
277
+
278
+ private function getEnabledMarketplacesCollection()
279
+ {
280
+ if (is_null($this->enabledMarketplacesCollection)) {
281
+ $collection = Mage::getModel('M2ePro/Marketplace')->getCollection();
282
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
283
+ $collection->addFieldToFilter('status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
284
+ $collection->setOrder('sorder', 'ASC');
285
+
286
+ $this->enabledMarketplacesCollection = $collection;
287
+ }
288
+
289
+ return $this->enabledMarketplacesCollection;
290
+ }
291
+
292
+ private function getEnabledMarketplaceTitles()
293
+ {
294
+ return $this->getEnabledMarketplacesCollection()->toOptionHash();
295
+ }
296
+
297
+ //########################################
298
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_SellingFormat_Edit
10
+ extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSellingFormatEdit');
21
+ $this->_blockGroup = 'M2ePro';
22
+ $this->_controller = 'adminhtml_common_amazon_template_sellingFormat';
23
+ $this->_mode = 'edit';
24
+ // ---------------------------------------
25
+
26
+ // Set header text
27
+ // ---------------------------------------
28
+ $helper = Mage::helper('M2ePro');
29
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
30
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
31
+ $headerTextEdit = $helper->__("Edit %component_name% Selling Format Policy", $componentName);
32
+ $headerTextAdd = $helper->__("Add %component_name% Selling Format Policy", $componentName);
33
+ } else {
34
+ $headerTextEdit = $helper->__("Edit Selling Format Policy");
35
+ $headerTextAdd = $helper->__("Add Selling Format Policy" );
36
+ }
37
+
38
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
39
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
40
+ ) {
41
+ $this->_headerText = $headerTextEdit;
42
+ $this->_headerText .= ' "'.$this->escapeHtml(
43
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
44
+ } else {
45
+ $this->_headerText = $headerTextAdd;
46
+ }
47
+ // ---------------------------------------
48
+
49
+ // Set buttons actions
50
+ // ---------------------------------------
51
+ $this->removeButton('back');
52
+ $this->removeButton('reset');
53
+ $this->removeButton('delete');
54
+ $this->removeButton('add');
55
+ $this->removeButton('save');
56
+ $this->removeButton('edit');
57
+ // ---------------------------------------
58
+
59
+ // ---------------------------------------
60
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
61
+ $this->_addButton('back', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Back'),
63
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.back_click(\'' . $url . '\')',
64
+ 'class' => 'back'
65
+ ));
66
+ // ---------------------------------------
67
+
68
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
69
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
70
+ ) {
71
+ // ---------------------------------------
72
+ $this->_addButton('duplicate', array(
73
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
74
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.duplicate_click'
75
+ .'(\'common-amazon-template-sellingFormat\')',
76
+ 'class' => 'add M2ePro_duplicate_button'
77
+ ));
78
+ // ---------------------------------------
79
+
80
+ // ---------------------------------------
81
+ $this->_addButton('delete', array(
82
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
83
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.delete_click()',
84
+ 'class' => 'delete M2ePro_delete_button'
85
+ ));
86
+ // ---------------------------------------
87
+ }
88
+
89
+ // ---------------------------------------
90
+ $this->_addButton('save', array(
91
+ 'label' => Mage::helper('M2ePro')->__('Save'),
92
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.save_click()',
93
+ 'class' => 'save'
94
+ ));
95
+ // ---------------------------------------
96
+
97
+ // ---------------------------------------
98
+ $this->_addButton('save_and_continue', array(
99
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
100
+ 'onclick' => 'AmazonTemplateSellingFormatHandlerObj.save_and_edit_click()',
101
+ 'class' => 'save'
102
+ ));
103
+ // ---------------------------------------
104
+ }
105
+
106
+ //########################################
107
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/SellingFormat/Edit/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_SellingFormat_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
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/ShippingOverride/Edit.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_ShippingOverride_Edit
10
+ extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateShippingOverrideEdit');
21
+ $this->_blockGroup = 'M2ePro';
22
+ $this->_controller = 'adminhtml_common_amazon_template_shippingOverride';
23
+ $this->_mode = 'edit';
24
+ // ---------------------------------------
25
+
26
+ // Set header text
27
+ // ---------------------------------------
28
+ $helper = Mage::helper('M2ePro');
29
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
30
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
31
+ $headerTextEdit = $helper->__("Edit %component_name% Shipping Override Policy", $componentName);
32
+ $headerTextAdd = $helper->__("Add %component_name% Shipping Override Policy", $componentName);
33
+ } else {
34
+ $headerTextEdit = $helper->__("Edit Shipping Override Policy");
35
+ $headerTextAdd = $helper->__("Add Shipping Override Policy" );
36
+ }
37
+
38
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
39
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
40
+ ) {
41
+ $this->_headerText = $headerTextEdit;
42
+ $this->_headerText .= ' "'.$this->escapeHtml(
43
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
44
+ } else {
45
+ $this->_headerText = $headerTextAdd;
46
+ }
47
+ // ---------------------------------------
48
+
49
+ // Set buttons actions
50
+ // ---------------------------------------
51
+ $this->removeButton('back');
52
+ $this->removeButton('reset');
53
+ $this->removeButton('delete');
54
+ $this->removeButton('add');
55
+ $this->removeButton('save');
56
+ $this->removeButton('edit');
57
+ // ---------------------------------------
58
+
59
+ // ---------------------------------------
60
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
61
+ $this->_addButton('back', array(
62
+ 'label' => Mage::helper('M2ePro')->__('Back'),
63
+ 'onclick' => 'AmazonTemplateShippingOverrideHandlerObj.back_click(\'' . $url . '\')',
64
+ 'class' => 'back'
65
+ ));
66
+ // ---------------------------------------
67
+
68
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
69
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
70
+ ) {
71
+ // ---------------------------------------
72
+ $this->_addButton('duplicate', array(
73
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
74
+ 'onclick' => 'AmazonTemplateShippingOverrideHandlerObj.duplicate_click'
75
+ .'(\'common-amazon-template-shippingOverride\')',
76
+ 'class' => 'add M2ePro_duplicate_button'
77
+ ));
78
+ // ---------------------------------------
79
+
80
+ // ---------------------------------------
81
+ $this->_addButton('delete', array(
82
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
83
+ 'onclick' => 'AmazonTemplateShippingOverrideHandlerObj.delete_click()',
84
+ 'class' => 'delete M2ePro_delete_button'
85
+ ));
86
+ // ---------------------------------------
87
+ }
88
+
89
+ // ---------------------------------------
90
+ $this->_addButton('save', array(
91
+ 'label' => Mage::helper('M2ePro')->__('Save'),
92
+ 'onclick' => 'AmazonTemplateShippingOverrideHandlerObj.save_click()',
93
+ 'class' => 'save'
94
+ ));
95
+ // ---------------------------------------
96
+
97
+ // ---------------------------------------
98
+ $this->_addButton('save_and_continue', array(
99
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
100
+ 'onclick' => 'AmazonTemplateShippingOverrideHandlerObj.save_and_edit_click()',
101
+ 'class' => 'save'
102
+ ));
103
+ // ---------------------------------------
104
+ }
105
+
106
+ //########################################
107
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/ShippingOverride/Edit/Form.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_ShippingOverride_Edit_Form
10
+ extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ private $enabledMarketplaces = NULL;
13
+ private $attributes = NULL;
14
+ private $overrideDictionaryData = NULL;
15
+
16
+ //########################################
17
+
18
+ public function __construct()
19
+ {
20
+ parent::__construct();
21
+
22
+ // Initialization block
23
+ // ---------------------------------------
24
+ $this->setId('amazonTemplateShippingOverrideEditForm');
25
+ // ---------------------------------------
26
+
27
+ $this->setTemplate('M2ePro/common/amazon/template/shippingOverride/form.phtml');
28
+ }
29
+
30
+ protected function _prepareForm()
31
+ {
32
+ $form = new Varien_Data_Form(array(
33
+ 'id' => 'edit_form',
34
+ 'action' => $this->getUrl('*/*/save'),
35
+ 'method' => 'post',
36
+ 'enctype' => 'multipart/form-data'
37
+ ));
38
+
39
+ $form->setUseContainer(true);
40
+ $this->setForm($form);
41
+
42
+ return parent::_prepareForm();
43
+ }
44
+
45
+ protected function _beforeToHtml()
46
+ {
47
+ parent::_beforeToHtml();
48
+
49
+ // ---------------------------------------
50
+ $buttonBlock = $this->getLayout()
51
+ ->createBlock('adminhtml/widget_button')
52
+ ->setData(array(
53
+ 'onclick' => 'AmazonTemplateShippingOverrideHandlerObj.addRow();',
54
+ 'class' => 'add add_shipping_override_rule_button'
55
+ ));
56
+ $this->setChild('add_shipping_override_rule_button', $buttonBlock);
57
+ // ---------------------------------------
58
+
59
+ // ---------------------------------------
60
+ $buttonBlock = $this->getLayout()
61
+ ->createBlock('adminhtml/widget_button')
62
+ ->setData(array(
63
+ 'label' => Mage::helper('M2ePro')->__('Remove'),
64
+ 'onclick' => 'AmazonTemplateShippingOverrideHandlerObj.removeRow(this);',
65
+ 'class' => 'delete icon-btn remove_shipping_override_rule_button'
66
+ ));
67
+ $this->setChild('remove_shipping_override_rule_button', $buttonBlock);
68
+ // ---------------------------------------
69
+ }
70
+
71
+ //########################################
72
+
73
+ public function getAttributes()
74
+ {
75
+ if (is_null($this->attributes)) {
76
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
77
+ }
78
+
79
+ return $this->attributes;
80
+ }
81
+
82
+ //########################################
83
+
84
+ public function getEnabledMarketplaces()
85
+ {
86
+ if (is_null($this->enabledMarketplaces)) {
87
+ $collection = Mage::getModel('M2ePro/Marketplace')->getCollection();
88
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Amazon::NICK);
89
+ $collection->addFieldToFilter('status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
90
+ $collection->setOrder('sorder', 'ASC');
91
+
92
+ $this->enabledMarketplaces = $collection;
93
+ }
94
+
95
+ return $this->enabledMarketplaces->getItems();
96
+ }
97
+
98
+ //########################################
99
+
100
+ public function getOverrideDictionaryData()
101
+ {
102
+ if (is_null($this->overrideDictionaryData)) {
103
+ /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */
104
+ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
105
+ $table = Mage::getSingleton('core/resource')->getTableName('m2epro_amazon_dictionary_shipping_override');
106
+
107
+ $this->overrideDictionaryData = $connRead->select()->from($table)->query()->fetchAll();
108
+ }
109
+
110
+ return $this->overrideDictionaryData;
111
+ }
112
+
113
+ //########################################
114
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit
10
+ extends Mage_Adminhtml_Block_Widget_Form_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSynchronizationEdit');
21
+ $this->_blockGroup = 'M2ePro';
22
+ $this->_controller = 'adminhtml_common_amazon_template_synchronization';
23
+ $this->_mode = 'edit';
24
+ // ---------------------------------------
25
+
26
+ // Set header text
27
+ // ---------------------------------------
28
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
29
+ $componentName = Mage::helper('M2ePro/Component_Amazon')->getTitle();
30
+ $headerTextEdit = Mage::helper('M2ePro')->__(
31
+ "Edit %component_name% Synchronization Policy",
32
+ $componentName
33
+ );
34
+ $headerTextAdd = Mage::helper('M2ePro')->__(
35
+ "Add %component_name% Synchronization Policy",
36
+ $componentName);
37
+ } else {
38
+ $headerTextEdit = Mage::helper('M2ePro')->__("Edit Synchronization Policy");
39
+ $headerTextAdd = Mage::helper('M2ePro')->__("Add Synchronization Policy");
40
+ }
41
+
42
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
43
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
44
+ ) {
45
+ $this->_headerText = $headerTextEdit;
46
+ $this->_headerText .= ' "'.$this->escapeHtml(
47
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()).'"';
48
+ } else {
49
+ $this->_headerText = $headerTextAdd;
50
+ }
51
+ // ---------------------------------------
52
+
53
+ // Set buttons actions
54
+ // ---------------------------------------
55
+ $this->removeButton('back');
56
+ $this->removeButton('reset');
57
+ $this->removeButton('delete');
58
+ $this->removeButton('add');
59
+ $this->removeButton('save');
60
+ $this->removeButton('edit');
61
+ // ---------------------------------------
62
+
63
+ // ---------------------------------------
64
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
65
+ $this->_addButton('back', array(
66
+ 'label' => Mage::helper('M2ePro')->__('Back'),
67
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.back_click(\'' . $url . '\')',
68
+ 'class' => 'back'
69
+ ));
70
+ // ---------------------------------------
71
+
72
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data')
73
+ && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
74
+ ) {
75
+ // ---------------------------------------
76
+ $this->_addButton('duplicate', array(
77
+ 'label' => Mage::helper('M2ePro')->__('Duplicate'),
78
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.duplicate_click'
79
+ .'(\'common-amazon-template-synchronization\')',
80
+ 'class' => 'add M2ePro_duplicate_button'
81
+ ));
82
+ // ---------------------------------------
83
+
84
+ // ---------------------------------------
85
+ $this->_addButton('delete', array(
86
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
87
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.delete_click()',
88
+ 'class' => 'delete M2ePro_delete_button'
89
+ ));
90
+ // ---------------------------------------
91
+ }
92
+
93
+ // ---------------------------------------
94
+ $this->_addButton('save', array(
95
+ 'label' => Mage::helper('M2ePro')->__('Save'),
96
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.save_click()',
97
+ 'class' => 'save'
98
+ ));
99
+ // ---------------------------------------
100
+
101
+ // ---------------------------------------
102
+ $this->_addButton('save_and_continue', array(
103
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
104
+ 'onclick' => 'AmazonTemplateSynchronizationHandlerObj.save_and_edit_click'
105
+ .'(\'\',\'amazonTemplateSynchronizationEditTabs\')',
106
+ 'class' => 'save'
107
+ ));
108
+ // ---------------------------------------
109
+ }
110
+
111
+ //########################################
112
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Form.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Form
10
+ extends Mage_Adminhtml_Block_Widget_Form
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSynchronizationEditForm');
21
+ // ---------------------------------------
22
+ }
23
+
24
+ protected function _prepareForm()
25
+ {
26
+ $form = new Varien_Data_Form(array(
27
+ 'id' => 'edit_form',
28
+ 'action' => $this->getUrl('*/*/save'),
29
+ 'method' => 'post',
30
+ 'enctype' => 'multipart/form-data'
31
+ ));
32
+
33
+ $form->setUseContainer(true);
34
+ $this->setForm($form);
35
+
36
+ return parent::_prepareForm();
37
+ }
38
+
39
+ //########################################
40
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs
10
+ extends Mage_Adminhtml_Block_Widget_Tabs
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSynchronizationEditTabs');
21
+ // ---------------------------------------
22
+
23
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
24
+ $this->setDestElementId('edit_form');
25
+ }
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ $this->addTab('list',array(
30
+ 'label' => Mage::helper('M2ePro')->__('List Rules'),
31
+ 'title' => Mage::helper('M2ePro')->__('List Rules'),
32
+ 'content' => $this->getLayout()
33
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_list')
34
+ ->toHtml()
35
+ ));
36
+
37
+ $this->addTab('revise',array(
38
+ 'label' => Mage::helper('M2ePro')->__('Revise Rules'),
39
+ 'title' => Mage::helper('M2ePro')->__('Revise Rules'),
40
+ 'content' => $this->getLayout()
41
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_revise')
42
+ ->toHtml()
43
+ ));
44
+
45
+ $this->addTab('relist',array(
46
+ 'label' => Mage::helper('M2ePro')->__('Relist Rules'),
47
+ 'title' => Mage::helper('M2ePro')->__('Relist Rules'),
48
+ 'content' => $this->getLayout()
49
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_relist')
50
+ ->toHtml()
51
+ ));
52
+
53
+ $this->addTab('stop',array(
54
+ 'label' => Mage::helper('M2ePro')->__('Stop Rules'),
55
+ 'title' => Mage::helper('M2ePro')->__('Stop Rules'),
56
+ 'content' => $this->getLayout()
57
+ ->createBlock('M2ePro/adminhtml_common_amazon_template_synchronization_edit_tabs_stop')
58
+ ->toHtml()
59
+ ));
60
+
61
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'list'));
62
+
63
+ return parent::_beforeToHtml();
64
+ }
65
+
66
+ //########################################
67
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/List.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_List
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSynchronizationEditTabsList');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/list.phtml');
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Relist.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_Relist
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSynchronizationEditTabsRelist');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/relist.phtml');
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Revise.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_Revise
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSynchronizationEditTabsRevise');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/revise.phtml');
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Amazon/Template/Synchronization/Edit/Tabs/Stop.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Amazon_Template_Synchronization_Edit_Tabs_Stop
10
+ extends Mage_Adminhtml_Block_Widget
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->setId('amazonTemplateSynchronizationEditTabsStop');
21
+ // ---------------------------------------
22
+
23
+ $this->setTemplate('M2ePro/common/amazon/template/synchronization/stop.phtml');
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyAccountEdit');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_buy_account';
22
+ $this->_mode = 'edit';
23
+ // ---------------------------------------
24
+
25
+ // Set header text
26
+ // ---------------------------------------
27
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
28
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
29
+ $headerTextEdit = $this->_headerText = Mage::helper('M2ePro')->__(
30
+ "Edit %component_name% Account",
31
+ $componentName
32
+ );
33
+ $headerTextAdd = $this->_headerText = Mage::helper('M2ePro')->__(
34
+ "Add %component_name% Account",
35
+ $componentName
36
+ );
37
+ } else {
38
+ $headerTextEdit = $this->_headerText = Mage::helper('M2ePro')->__("Edit Account");
39
+ $headerTextAdd = $this->_headerText = Mage::helper('M2ePro')->__("Add Account");
40
+ }
41
+
42
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
43
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
44
+ ) {
45
+ $this->_headerText = $headerTextEdit;
46
+ $this->_headerText .= ' "'.$this->escapeHtml(
47
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()
48
+ ).'"';
49
+ } else {
50
+ $this->_headerText = $headerTextAdd;
51
+ }
52
+ // ---------------------------------------
53
+
54
+ // Set buttons actions
55
+ // ---------------------------------------
56
+ $this->removeButton('back');
57
+ $this->removeButton('reset');
58
+ $this->removeButton('delete');
59
+ $this->removeButton('add');
60
+ $this->removeButton('save');
61
+ $this->removeButton('edit');
62
+
63
+ /* @var $wizardHelper Ess_M2ePro_Helper_Module_Wizard */
64
+ $wizardHelper = Mage::helper('M2ePro/Module_Wizard');
65
+
66
+ if ($wizardHelper->isActive('buy') &&
67
+ $wizardHelper->getStep('buy') == 'account'
68
+ ) {
69
+
70
+ // ---------------------------------------
71
+ $this->_addButton('save_and_continue', array(
72
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
73
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
74
+ 'class' => 'save'
75
+ ));
76
+ // ---------------------------------------
77
+
78
+ if ($this->getRequest()->getParam('id')) {
79
+ // ---------------------------------------
80
+ $url = $this->getUrl('*/adminhtml_common_buy_account/new', array('wizard' => true));
81
+ $this->_addButton('add_new_account', array(
82
+ 'label' => Mage::helper('M2ePro')->__('Add New Account'),
83
+ 'onclick' => 'setLocation(\''. $url .'\')',
84
+ 'class' => 'add_new_account'
85
+ ));
86
+ // ---------------------------------------
87
+
88
+ // ---------------------------------------
89
+ $this->_addButton('close', array(
90
+ 'label' => Mage::helper('M2ePro')->__('Complete This Step'),
91
+ 'onclick' => 'BuyAccountHandlerObj.completeStep();',
92
+ 'class' => 'close'
93
+ ));
94
+ // ---------------------------------------
95
+ }
96
+ } else {
97
+
98
+ if ((bool)$this->getRequest()->getParam('close_on_save',false)) {
99
+
100
+ if ($this->getRequest()->getParam('id')) {
101
+ $this->_addButton('save', array(
102
+ 'label' => Mage::helper('M2ePro')->__('Save And Close'),
103
+ 'onclick' => 'BuyAccountHandlerObj.saveAndClose()',
104
+ 'class' => 'save'
105
+ ));
106
+ } else {
107
+ $this->_addButton('save_and_continue', array(
108
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
109
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
110
+ 'class' => 'save'
111
+ ));
112
+ }
113
+ return;
114
+ }
115
+
116
+ // ---------------------------------------
117
+ $url = Mage::helper('M2ePro')->getBackUrl('list');
118
+ $this->_addButton('back', array(
119
+ 'label' => Mage::helper('M2ePro')->__('Back'),
120
+ 'onclick' => 'BuyAccountHandlerObj.back_click(\'' . $url .'\')',
121
+ 'class' => 'back'
122
+ ));
123
+ // ---------------------------------------
124
+
125
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
126
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
127
+ ) {
128
+ // ---------------------------------------
129
+ $this->_addButton('delete', array(
130
+ 'label' => Mage::helper('M2ePro')->__('Delete'),
131
+ 'onclick' => 'BuyAccountHandlerObj.delete_click()',
132
+ 'class' => 'delete M2ePro_delete_button'
133
+ ));
134
+ // ---------------------------------------
135
+ }
136
+
137
+ // ---------------------------------------
138
+ $this->_addButton('save', array(
139
+ 'label' => Mage::helper('M2ePro')->__('Save'),
140
+ 'onclick' => 'BuyAccountHandlerObj.save_click()',
141
+ 'class' => 'save'
142
+ ));
143
+ // ---------------------------------------
144
+
145
+ // ---------------------------------------
146
+ $this->_addButton('save_and_continue', array(
147
+ 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'),
148
+ 'onclick' => 'BuyAccountHandlerObj.save_and_edit_click(\'\',\'buyAccountEditTabs\')',
149
+ 'class' => 'save'
150
+ ));
151
+ // ---------------------------------------
152
+ }
153
+ }
154
+
155
+ //########################################
156
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Form.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyAccountEditForm');
20
+ // ---------------------------------------
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/*/save'),
28
+ 'method' => 'post',
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ //########################################
39
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyAccountEditTabs');
20
+ // ---------------------------------------
21
+
22
+ $this->setTitle(Mage::helper('M2ePro')->__('Configuration'));
23
+ $this->setDestElementId('edit_form');
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()
32
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_general')
33
+ ->toHtml(),
34
+ ));
35
+
36
+ $this->addTab('listingOther', array(
37
+ 'label' => Mage::helper('M2ePro')->__('3rd Party Listings'),
38
+ 'title' => Mage::helper('M2ePro')->__('3rd Party Listings'),
39
+ 'content' => $this->getLayout()
40
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_listingOther')
41
+ ->toHtml(),
42
+ ));
43
+
44
+ $this->addTab('orders', array(
45
+ 'label' => Mage::helper('M2ePro')->__('Orders'),
46
+ 'title' => Mage::helper('M2ePro')->__('Orders'),
47
+ 'content' => $this->getLayout()
48
+ ->createBlock('M2ePro/adminhtml_common_buy_account_edit_tabs_order')
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/Buy/Account/Edit/Tabs/General.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs_General extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyAccountEditTabsGeneral');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/buy/account/tabs/general.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ if (Mage::helper('M2ePro/Data_Global')->getValue('temp_data') &&
28
+ Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()
29
+ ) {
30
+
31
+ /** @var $accountObj Ess_M2ePro_Model_Account */
32
+ $accountObj = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
33
+
34
+ $this->synchronizeProcessing = $accountObj->isLockedObject('server_synchronize');
35
+
36
+ if (!$this->synchronizeProcessing) {
37
+ $accountId = $accountObj->getId();
38
+
39
+ Mage::helper('M2ePro/Data_Global')->unsetValue('temp_data');
40
+ Mage::helper('M2ePro/Data_Global')->setValue(
41
+ 'temp_data',
42
+ Mage::helper('M2ePro/Component_Buy')->getCachedObject('Account',$accountId)
43
+ );
44
+ }
45
+ } else {
46
+ $this->synchronizeProcessing = false;
47
+ }
48
+
49
+ $marketplaces = Mage::helper('M2ePro/Component_Buy')->getCollection('Marketplace')
50
+ ->addFieldToFilter('status', Ess_M2ePro_Model_Marketplace::STATUS_ENABLE);
51
+
52
+ $this->marketplace = true;
53
+ if ($marketplaces->getSize() <= 0) {
54
+ $this->marketplace = false;
55
+ }
56
+
57
+ // ---------------------------------------
58
+ $data = array(
59
+ 'label' => Mage::helper('M2ePro')->__('Update FTP Password'),
60
+ 'onclick' => 'BuyAccountHandlerObj.update_password(\'ftp\')',
61
+ 'class' => 'scalable'
62
+ );
63
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
64
+ $this->setChild('buy_update_ftp_password', $buttonBlock);
65
+ // ---------------------------------------
66
+
67
+ // ---------------------------------------
68
+ $data = array(
69
+ 'label' => Mage::helper('M2ePro')->__('Update Web Password'),
70
+ 'onclick' => 'BuyAccountHandlerObj.update_password(\'web\')',
71
+ 'class' => 'scalable'
72
+ );
73
+ $buttonBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
74
+ $this->setChild('buy_update_web_password', $buttonBlock);
75
+ // ---------------------------------------
76
+
77
+ return parent::_beforeToHtml();
78
+ }
79
+
80
+ //########################################
81
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/ListingOther.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs_ListingOther extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyAccountEditTabsListingOther');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/buy/account/tabs/listing_other.phtml');
23
+ }
24
+
25
+ protected function _beforeToHtml()
26
+ {
27
+ $this->attributes = Mage::helper('M2ePro/Magento_Attribute')->getGeneralFromAllAttributeSets();
28
+
29
+ return parent::_beforeToHtml();
30
+ }
31
+
32
+ //########################################
33
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Account/Edit/Tabs/Order.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Account_Edit_Tabs_Order extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ protected $_possibleMagentoStatuses = null;
12
+
13
+ //########################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ // Initialization block
20
+ // ---------------------------------------
21
+ $this->setId('buyAccountEditTabsOrder');
22
+ // ---------------------------------------
23
+
24
+ $this->setTemplate('M2ePro/common/buy/account/tabs/order.phtml');
25
+ }
26
+
27
+ protected function _beforeToHtml()
28
+ {
29
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
30
+ $magentoOrdersSettings = !empty($data['magento_orders_settings'])
31
+ ? json_decode($data['magento_orders_settings'], true) : array();
32
+
33
+ // ---------------------------------------
34
+ $temp = Mage::getModel('core/website')->getCollection()->setOrder('sort_order','ASC')->toArray();
35
+ $this->websites = $temp['items'];
36
+ // ---------------------------------------
37
+
38
+ // ---------------------------------------
39
+ $temp = Mage::getModel('customer/group')->getCollection()->toArray();
40
+ $this->groups = $temp['items'];
41
+ // ---------------------------------------
42
+
43
+ // ---------------------------------------
44
+ $selectedStore = !empty($magentoOrdersSettings['listing']['store_id'])
45
+ ? $magentoOrdersSettings['listing']['store_id'] : '';
46
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
47
+ 'id' => 'magento_orders_listings_store_id',
48
+ 'name' => 'magento_orders_settings[listing][store_id]',
49
+ 'selected' => $selectedStore
50
+ ));
51
+ $blockStoreSwitcher->hasDefaultOption(false);
52
+ $this->setChild('magento_orders_listings_store_id', $blockStoreSwitcher);
53
+ // ---------------------------------------
54
+
55
+ // ---------------------------------------
56
+ $selectedStore = !empty($magentoOrdersSettings['listing_other']['store_id'])
57
+ ? $magentoOrdersSettings['listing_other']['store_id'] : '';
58
+ $blockStoreSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_storeSwitcher', '', array(
59
+ 'id' => 'magento_orders_listings_other_store_id',
60
+ 'name' => 'magento_orders_settings[listing_other][store_id]',
61
+ 'selected' => $selectedStore
62
+ ));
63
+ $blockStoreSwitcher->hasDefaultOption(false);
64
+ $this->setChild('magento_orders_listings_other_store_id', $blockStoreSwitcher);
65
+ // ---------------------------------------
66
+
67
+ // ---------------------------------------
68
+ $productTaxClasses = Mage::getModel('tax/class')->getCollection()
69
+ ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)
70
+ ->toOptionArray();
71
+
72
+ $none = array('value' => Ess_M2ePro_Model_Magento_Product::TAX_CLASS_ID_NONE, 'label' => 'None');
73
+ array_unshift($productTaxClasses, $none);
74
+
75
+ $this->productTaxClasses = $productTaxClasses;
76
+ // ---------------------------------------
77
+
78
+ return parent::_beforeToHtml();
79
+ }
80
+
81
+ public function getMagentoOrderStatusList()
82
+ {
83
+ if (is_null($this->_possibleMagentoStatuses)) {
84
+ $this->_possibleMagentoStatuses = Mage::getSingleton('sales/order_config')->getStatuses();
85
+ }
86
+
87
+ return $this->_possibleMagentoStatuses;
88
+ }
89
+
90
+ //########################################
91
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListing');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_buy_listing';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ $this->_headerText = '';
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
+ $this->setTemplate('M2ePro/widget/grid/container/only_content.phtml');
40
+ }
41
+
42
+ //########################################
43
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Form.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Form
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Form
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->component = Ess_M2ePro_Helper_Component_Buy::NICK;
21
+ $this->setId('buyListingEditForm');
22
+ // ---------------------------------------
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/General.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Tabs_General
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_General
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->sessionKey = 'buy_listing_create';
21
+ $this->setId('buyListingAddTabsGeneral');
22
+ $this->setTemplate('M2ePro/common/buy/listing/add/tabs/general.phtml');
23
+ // ---------------------------------------
24
+ }
25
+
26
+ //########################################
27
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Search.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Tabs_Search
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Search
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->sessionKey = 'buy_listing_create';
21
+ $this->setId('buyListingAddTabsGeneral');
22
+ $this->setTemplate('M2ePro/common/buy/listing/add/tabs/search.phtml');
23
+ // ---------------------------------------
24
+ }
25
+
26
+ //########################################
27
+
28
+ protected function getDefaults()
29
+ {
30
+ return self::getDefaultFieldsValues();
31
+ }
32
+
33
+ static function getDefaultFieldsValues()
34
+ {
35
+ return array(
36
+ 'general_id_mode' => Ess_M2ePro_Model_Buy_Listing::GENERAL_ID_MODE_NOT_SET,
37
+ 'general_id_custom_attribute' => '',
38
+
39
+ 'search_by_magento_title_mode' => Ess_M2ePro_Model_Buy_Listing::SEARCH_BY_MAGENTO_TITLE_MODE_NONE
40
+ );
41
+ }
42
+
43
+ //########################################
44
+
45
+ public function isEditMode()
46
+ {
47
+ return !!$this->getRequest()->getParam('id');
48
+ }
49
+
50
+ //########################################
51
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Add/Tabs/Selling.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Add_Tabs_Selling
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_Tabs_Selling
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ // Initialization block
19
+ // ---------------------------------------
20
+ $this->component = Ess_M2ePro_Helper_Component_Buy::NICK;
21
+ $this->sessionKey = 'buy_listing_create';
22
+ $this->setId('buyListingAddTabsSelling');
23
+ $this->setTemplate('M2ePro/common/buy/listing/add/tabs/selling.phtml');
24
+ // ---------------------------------------
25
+ }
26
+
27
+ //########################################
28
+
29
+ protected function _beforeToHtml()
30
+ {
31
+ $buttonBlock = $this->getLayout()
32
+ ->createBlock('adminhtml/widget_button')
33
+ ->setData(array(
34
+ 'label' => Mage::helper('M2ePro')->__('Insert'),
35
+ 'onclick' => "BuyListingChannelSettingsHandlerObj.appendToText"
36
+ ."('condition_note_custom_attribute', 'condition_note_value');",
37
+ 'class' => 'condition_note_value_insert_button'
38
+ ));
39
+ $this->setChild('condition_note_value_insert_button', $buttonBlock);
40
+
41
+ return parent::_beforeToHtml();
42
+ }
43
+
44
+ //########################################
45
+
46
+ protected function getDefaults()
47
+ {
48
+ return self::getDefaultFieldsValues();
49
+ }
50
+
51
+ static function getDefaultFieldsValues()
52
+ {
53
+ return array(
54
+ 'sku_mode' => Ess_M2ePro_Model_Buy_Listing::SKU_MODE_DEFAULT,
55
+ 'sku_custom_attribute' => '',
56
+ 'sku_modification_mode' => Ess_M2ePro_Model_Buy_Listing::SKU_MODIFICATION_MODE_NONE,
57
+ 'sku_modification_custom_value' => '',
58
+ 'generate_sku_mode' => Ess_M2ePro_Model_Buy_Listing::GENERATE_SKU_MODE_NO,
59
+
60
+ 'template_selling_format_id' => '',
61
+ 'template_synchronization_id' => '',
62
+
63
+ 'shipping_standard_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
64
+ 'shipping_standard_value' => 0,
65
+ 'shipping_standard_custom_attribute' => '',
66
+
67
+ 'shipping_expedited_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
68
+ 'shipping_expedited_value' => 0,
69
+ 'shipping_expedited_custom_attribute' => '',
70
+
71
+ 'shipping_two_day_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
72
+ 'shipping_two_day_value' => 0,
73
+ 'shipping_two_day_custom_attribute' => '',
74
+
75
+ 'shipping_one_day_mode' => Ess_M2ePro_Model_Buy_Listing::SHIPPING_MODE_DEFAULT,
76
+ 'shipping_one_day_value' => 0,
77
+ 'shipping_one_day_custom_attribute' => '',
78
+
79
+ 'condition_mode' => Ess_M2ePro_Model_Buy_Listing::CONDITION_MODE_DEFAULT,
80
+ 'condition_value' => Ess_M2ePro_Model_Buy_Listing::CONDITION_NEW,
81
+ 'condition_custom_attribute' => '',
82
+ 'condition_note_mode' => Ess_M2ePro_Model_Buy_Listing::CONDITION_NOTE_MODE_NONE,
83
+ 'condition_note_value' => ''
84
+ );
85
+ }
86
+
87
+ //########################################
88
+
89
+ public function isEditMode()
90
+ {
91
+ return !!$this->getRequest()->getParam('id');
92
+ }
93
+
94
+ //########################################
95
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode
11
+ {
12
+ //########################################
13
+
14
+ public function getHelpPageUrl()
15
+ {
16
+ return Mage::helper('M2ePro/Module_Support')
17
+ ->getDocumentationUrl(NULL, 'pages/viewpage.action?pageId=18189166');
18
+ }
19
+
20
+ //########################################
21
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Category
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category
11
+ {
12
+ //########################################
13
+
14
+ protected function prepareGroupsGrid()
15
+ {
16
+ $groupGrid = $this->getLayout()
17
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_autoAction_mode_category_group_grid');
18
+ $groupGrid->prepareGrid();
19
+ $this->setChild('group_grid', $groupGrid);
20
+
21
+ return $groupGrid;
22
+ }
23
+
24
+ //########################################
25
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Form.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Category_Form
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Form
11
+ {
12
+ //########################################
13
+
14
+ //########################################
15
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Category/Group/Grid.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Category_Group_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Category_Group_Grid
11
+ {
12
+ //########################################
13
+
14
+ public function getGridUrl()
15
+ {
16
+ return $this->getUrl('*/adminhtml_common_listing_autoAction/getCategoryGroupGrid', array('_current' => true));
17
+ }
18
+
19
+ //########################################
20
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Global.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Global
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Global
11
+ {
12
+ //########################################
13
+
14
+ //########################################
15
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/AutoAction/Mode/Website.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_AutoAction_Mode_Website
10
+ extends Ess_M2ePro_Block_Adminhtml_Listing_AutoAction_Mode_Website
11
+ {
12
+ //########################################
13
+
14
+ //########################################
15
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingEdit');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_buy_listing';
22
+ $this->_mode = 'edit';
23
+ // ---------------------------------------
24
+
25
+ // Set header text
26
+ // ---------------------------------------
27
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
28
+
29
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
30
+ $headerText = Mage::helper('M2ePro')->__(
31
+ 'Edit %component_name% Listing Settings "%listing_title%"',
32
+ Mage::helper('M2ePro/Component_Buy')->getTitle(),
33
+ $this->escapeHtml($listingData['title'])
34
+ );
35
+ } else {
36
+ $headerText =Mage::helper('M2ePro')->__(
37
+ 'Edit Listing Settings "%listing_title%"',
38
+ $this->escapeHtml($listingData['title'])
39
+ );
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
+ if (!is_null($this->getRequest()->getParam('back'))) {
56
+ // ---------------------------------------
57
+ $url = Mage::helper('M2ePro')->getBackUrl(
58
+ '*/adminhtml_common_listing/index',
59
+ array(
60
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
61
+ )
62
+ );
63
+ $this->_addButton('back', array(
64
+ 'label' => Mage::helper('M2ePro')->__('Back'),
65
+ 'onclick' => 'CommonListingSettingsHandlerObj.back_click(\''.$url.'\')',
66
+ 'class' => 'back'
67
+ ));
68
+ // ---------------------------------------
69
+ }
70
+
71
+ // ---------------------------------------
72
+ $this->_addButton('auto_action', array(
73
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules'),
74
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();'
75
+ ));
76
+ // ---------------------------------------
77
+
78
+ $backUrl = Mage::helper('M2ePro')->getBackUrlParam('list');
79
+
80
+ // ---------------------------------------
81
+ $url = $this->getUrl(
82
+ '*/adminhtml_common_buy_listing/save',
83
+ array(
84
+ 'id' => $listingData['id'],
85
+ 'back' => Mage::helper('M2ePro')->getBackUrlParam('list')
86
+ )
87
+ );
88
+ $this->_addButton('save', array(
89
+ 'label' => Mage::helper('M2ePro')->__('Save'),
90
+ 'onclick' => 'CommonListingSettingsHandlerObj.save_click(\'' . $url . '\')',
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' => 'CommonListingSettingsHandlerObj.save_and_edit_click(\''.$url.'\', 1)',
99
+ 'class' => 'save'
100
+ ));
101
+ // ---------------------------------------
102
+ }
103
+
104
+ //########################################
105
+
106
+ protected function _beforeToHtml()
107
+ {
108
+ parent::_beforeToHtml();
109
+
110
+ // ---------------------------------------
111
+ $tabs = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_edit_tabs');
112
+ $this->setChild('tabs', $tabs);
113
+ // ---------------------------------------
114
+
115
+ return $this;
116
+ }
117
+
118
+ //########################################
119
+
120
+ public function getFormHtml()
121
+ {
122
+ $listing = Mage::helper('M2ePro/Component_Buy')->getCachedObject(
123
+ 'Listing', $this->getRequest()->getParam('id')
124
+ );
125
+
126
+ $viewHeaderBlock = $this->getLayout()->createBlock(
127
+ 'M2ePro/adminhtml_listing_view_header','',
128
+ array('listing' => $listing)
129
+ );
130
+
131
+ $tabs = $this->getChild('tabs');
132
+
133
+ $urls = Mage::helper('M2ePro')->getControllerActions(
134
+ 'adminhtml_common_listing_autoAction',
135
+ array(
136
+ 'listing_id' => $this->getRequest()->getParam('id'),
137
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK
138
+ )
139
+ );
140
+ $urls = json_encode($urls);
141
+
142
+ /** @var $helper Ess_M2ePro_Helper_Data */
143
+ $helper = Mage::helper('M2ePro');
144
+
145
+ $translations = json_encode(array(
146
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
147
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
148
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
149
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
150
+ ));
151
+
152
+ $js = <<<HTML
153
+ <script type="text/javascript">
154
+
155
+ M2ePro.url.add({$urls});
156
+ M2ePro.translator.add({$translations});
157
+
158
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
159
+
160
+ </script>
161
+ HTML;
162
+
163
+ return $viewHeaderBlock->toHtml() . $tabs->toHtml() . parent::getFormHtml() . $js;
164
+ }
165
+
166
+ //########################################
167
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Form.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingEditForm');
20
+ // ---------------------------------------
21
+ }
22
+
23
+ protected function _prepareForm()
24
+ {
25
+ $form = new Varien_Data_Form(array(
26
+ 'id' => 'edit_form',
27
+ 'action' => $this->getUrl('*/adminhtml_common_buy_listing/save'),
28
+ 'method' => 'post',
29
+ 'enctype' => 'multipart/form-data'
30
+ ));
31
+
32
+ $form->setUseContainer(true);
33
+ $this->setForm($form);
34
+
35
+ return parent::_prepareForm();
36
+ }
37
+
38
+ //########################################
39
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Edit/Tabs.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingEditTabs');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('widget/tabshoriz.phtml');
23
+ $this->setDestElementId('edit_form');
24
+ }
25
+
26
+ protected function _beforeToHtml()
27
+ {
28
+ $this->addTab('selling', array(
29
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
30
+ 'title' => Mage::helper('M2ePro')->__('Selling Settings'),
31
+ 'content' => $this->getLayout()
32
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_add_tabs_selling')
33
+ ->toHtml(),
34
+ ));
35
+
36
+ $this->addTab('search', array(
37
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
38
+ 'title' => Mage::helper('M2ePro')->__('Search Settings'),
39
+ 'content' => $this->getLayout()
40
+ ->createBlock('M2ePro/adminhtml_common_buy_listing_add_tabs_search')
41
+ ->toHtml(),
42
+ ));
43
+
44
+ $this->setActiveTab($this->getRequest()->getParam('tab', 'selling'));
45
+
46
+ return parent::_beforeToHtml();
47
+ }
48
+
49
+ //########################################
50
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Grid.php ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingGrid');
20
+ // ---------------------------------------
21
+ }
22
+
23
+ protected function _prepareCollection()
24
+ {
25
+ // Update statistic table values
26
+ Mage::getResourceModel('M2ePro/Listing')->updateStatisticColumns();
27
+ Mage::getResourceModel('M2ePro/Buy_Listing')->updateStatisticColumns();
28
+
29
+ // Get collection of listings
30
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing');
31
+
32
+ // Set global filters
33
+ // ---------------------------------------
34
+ $filterSellingFormatTemplate = $this->getRequest()->getParam('filter_buy_selling_format_template');
35
+ $filterSynchronizationTemplate = $this->getRequest()->getParam('filter_buy_synchronization_template');
36
+
37
+ if ($filterSellingFormatTemplate != 0) {
38
+ $collection->addFieldToFilter(
39
+ 'second_table.template_selling_format_id', (int)$filterSellingFormatTemplate
40
+ );
41
+ }
42
+
43
+ if ($filterSynchronizationTemplate != 0) {
44
+ $collection->addFieldToFilter(
45
+ 'second_table.template_synchronization_id', (int)$filterSynchronizationTemplate
46
+ );
47
+ }
48
+ // ---------------------------------------
49
+
50
+ // join accounts
51
+ // ---------------------------------------
52
+ $collection->getSelect()
53
+ ->join(array('a'=>Mage::getResourceModel('M2ePro/Account')->getMainTable()),
54
+ '(`a`.`id` = `main_table`.`account_id`)',
55
+ array('account_title'=>'title'));
56
+ // ---------------------------------------
57
+
58
+ $this->setCollection($collection);
59
+
60
+ return parent::_prepareCollection();
61
+ }
62
+
63
+ //########################################
64
+
65
+ protected function _prepareMassaction()
66
+ {
67
+ // Set massaction identifiers
68
+ // ---------------------------------------
69
+ $this->setMassactionIdField('main_table.id');
70
+ $this->getMassactionBlock()->setFormFieldName('ids');
71
+ // ---------------------------------------
72
+
73
+ // Set clear log action
74
+ // ---------------------------------------
75
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
76
+ '*/adminhtml_common_listing/index',
77
+ array(
78
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
79
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
80
+ )
81
+ );
82
+
83
+ $this->getMassactionBlock()->addItem('clear_logs', array(
84
+ 'label' => Mage::helper('M2ePro')->__('Clear Log(s)'),
85
+ 'url' => $this->getUrl('*/adminhtml_listing/clearLog', array('back' => $backUrl)),
86
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
87
+ ));
88
+ // ---------------------------------------
89
+
90
+ // Set remove listings action
91
+ // ---------------------------------------
92
+ $this->getMassactionBlock()->addItem('delete_listings', array(
93
+ 'label' => Mage::helper('M2ePro')->__('Delete Listing(s)'),
94
+ 'url' => $this->getUrl('*/adminhtml_common_buy_listing/delete', array('back' => $backUrl)),
95
+ 'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
96
+ ));
97
+ // ---------------------------------------
98
+
99
+ return parent::_prepareMassaction();
100
+ }
101
+
102
+ //########################################
103
+
104
+ protected function getColumnActionsItems()
105
+ {
106
+ $helper = Mage::helper('M2ePro');
107
+ $backUrl = $helper->makeBackUrlParam(
108
+ '*/adminhtml_common_listing/index',
109
+ array(
110
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
111
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
112
+ )
113
+ );
114
+
115
+ $actions = array(
116
+ 'manageProducts' => array(
117
+ 'caption' => $helper->__('Manage'),
118
+ 'group' => 'products_actions',
119
+ 'field' => 'id',
120
+ 'url' => array(
121
+ 'base' => '*/adminhtml_common_buy_listing/view',
122
+ 'params' => array('back' => $backUrl)
123
+ )
124
+ ),
125
+
126
+ 'addProductsFromProductsList' => array(
127
+ 'caption' => $helper->__('Add From Products List'),
128
+ 'group' => 'products_actions',
129
+ 'field' => 'id',
130
+ 'url' => array(
131
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
132
+ 'params' => array(
133
+ 'back' => $backUrl,
134
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
135
+ 'step' => 2,
136
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
137
+ )
138
+ )
139
+ ),
140
+
141
+ 'addProductsFromCategories' => array(
142
+ 'caption' => $helper->__('Add From Categories'),
143
+ 'group' => 'products_actions',
144
+ 'field' => 'id',
145
+ 'url' => array(
146
+ 'base' => '*/adminhtml_common_listing_productAdd/index',
147
+ 'params' => array(
148
+ 'back' => $backUrl,
149
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
150
+ 'step' => 2,
151
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
152
+ )
153
+ )
154
+ ),
155
+
156
+ 'automaticActions' => array(
157
+ 'caption' => $helper->__('Auto Add/Remove Rules'),
158
+ 'group' => 'products_actions',
159
+ 'field' => 'id',
160
+ 'url' => array(
161
+ 'base' => '*/adminhtml_common_buy_listing/view',
162
+ 'params' => array(
163
+ 'back' => $backUrl,
164
+ 'auto_actions' => 1
165
+ )
166
+ )
167
+ ),
168
+
169
+ 'viewLog' => array(
170
+ 'caption' => $helper->__('View Log'),
171
+ 'group' => 'other',
172
+ 'field' => 'id',
173
+ 'url' => array(
174
+ 'base' => '*/adminhtml_common_log/listing',
175
+ 'params' => array(
176
+ 'back' => $backUrl,
177
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_BUY
178
+ )
179
+ )
180
+ ),
181
+
182
+ 'clearLogs' => array(
183
+ 'caption' => $helper->__('Clear Log'),
184
+ 'confirm' => $helper->__('Are you sure?'),
185
+ 'group' => 'other',
186
+ 'field' => 'id',
187
+ 'url' => array(
188
+ 'base' => '*/adminhtml_listing/clearLog',
189
+ 'params' => array(
190
+ 'back' => $backUrl
191
+ )
192
+ )
193
+ ),
194
+
195
+ 'deleteListing' => array(
196
+ 'caption' => $helper->__('Delete Listing'),
197
+ 'confirm' => $helper->__('Are you sure?'),
198
+ 'group' => 'other',
199
+ 'field' => 'id',
200
+ 'url' => array(
201
+ 'base' => '*/adminhtml_common_buy_listing/delete',
202
+ 'params' => array(
203
+ 'back' => $backUrl
204
+ )
205
+ )
206
+ ),
207
+
208
+ 'editListingTitle' => array(
209
+ 'caption' => $helper->__('Title'),
210
+ 'group' => 'edit_actions',
211
+ 'confirm' => $helper->__('Are you sure?'),
212
+ 'field' => 'id',
213
+ 'onclick_action' => 'editListingTitle'
214
+ ),
215
+
216
+ 'sellingSetting' => array(
217
+ 'caption' => $helper->__('Selling'),
218
+ 'group' => 'edit_actions',
219
+ 'field' => 'id',
220
+ 'url' => array(
221
+ 'base' => '*/adminhtml_common_buy_listing/edit',
222
+ 'params' => array(
223
+ 'back' => $backUrl,
224
+ 'tab' => 'selling'
225
+ )
226
+ )
227
+ ),
228
+
229
+ 'searchSetting' => array(
230
+ 'caption' => $helper->__('Search'),
231
+ 'group' => 'edit_actions',
232
+ 'field' => 'id',
233
+ 'url' => array(
234
+ 'base' => '*/adminhtml_common_buy_listing/edit',
235
+ 'params' => array(
236
+ 'back' => $backUrl,
237
+ 'tab' => 'search'
238
+ )
239
+ )
240
+ )
241
+ );
242
+
243
+ return $actions;
244
+ }
245
+
246
+ //########################################
247
+
248
+ public function callbackColumnSoldProducts($value, $row, $column, $isExport)
249
+ {
250
+ return $this->getColumnValue($value);
251
+ }
252
+
253
+ public function callbackColumnTitle($value, $row, $column, $isExport)
254
+ {
255
+ $value = '<span id="listing_title_'.$row->getId().'">' .
256
+ Mage::helper('M2ePro')->escapeHtml($value) .
257
+ '</span>';
258
+
259
+ /* @var $row Ess_M2ePro_Model_Listing */
260
+ $accountTitle = $row->getData('account_title');
261
+
262
+ $storeModel = Mage::getModel('core/store')->load($row->getStoreId());
263
+ $storeView = $storeModel->getWebsite()->getName();
264
+ if (strtolower($storeView) != 'admin') {
265
+ $storeView .= ' > '.$storeModel->getGroup()->getName();
266
+ $storeView .= ' > '.$storeModel->getName();
267
+ } else {
268
+ $storeView = Mage::helper('M2ePro')->__('Admin (Default Values)');
269
+ }
270
+
271
+ $account = Mage::helper('M2ePro')->__('Account');
272
+ $store = Mage::helper('M2ePro')->__('Magento Store View');
273
+
274
+ $value .= <<<HTML
275
+ <div>
276
+ <span style="font-weight: bold">{$account}</span>: <span style="color: #505050">{$accountTitle}</span><br/>
277
+ <span style="font-weight: bold">{$store}</span>: <span style="color: #505050">{$storeView}</span>
278
+ </div>
279
+ HTML;
280
+
281
+ return $value;
282
+ }
283
+
284
+ //########################################
285
+
286
+ protected function callbackFilterTitle($collection, $column)
287
+ {
288
+ $value = $column->getFilter()->getValue();
289
+
290
+ if ($value == null) {
291
+ return;
292
+ }
293
+
294
+ $collection->getSelect()->where('main_table.title LIKE ? OR a.title LIKE ?','%'. $value .'%');
295
+ }
296
+
297
+ //########################################
298
+
299
+ public function getGridUrl()
300
+ {
301
+ return $this->getUrl('*/adminhtml_common_buy_listing/listingGrid', array('_current'=>true));
302
+ }
303
+
304
+ public function getRowUrl($row)
305
+ {
306
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
307
+ '*/adminhtml_common_listing/index',
308
+ array(
309
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_ManageListings::TAB_ID_LISTING,
310
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
311
+ )
312
+ );
313
+
314
+ return $this->getUrl(
315
+ '*/adminhtml_common_buy_listing/view',
316
+ array(
317
+ 'id' => $row->getId(),
318
+ 'back' => $backUrl
319
+ )
320
+ );
321
+ }
322
+
323
+ //########################################
324
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/Grid.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Common_Listing_Other_Grid
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setId('buyListingOtherGrid');
19
+ }
20
+
21
+ //########################################
22
+
23
+ protected function _prepareCollection()
24
+ {
25
+ $this->prepareCacheData();
26
+
27
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
28
+ $collection->getSelect()->group(array('account_id','marketplace_id'));
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
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_View extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListing');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_buy_listing_other_view';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
27
+ $this->_headerText = Mage::helper('M2ePro')->__(
28
+ '3rd Party %channel_title% Listings',
29
+ Mage::helper('M2ePro/Component_Buy')->getTitle()
30
+ );
31
+ } else {
32
+ $this->_headerText = Mage::helper('M2ePro')->__('3rd Party Listings');
33
+ }
34
+ // ---------------------------------------
35
+
36
+ // Set buttons actions
37
+ // ---------------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ // ---------------------------------------
45
+
46
+ // ---------------------------------------
47
+ if (!is_null($this->getRequest()->getParam('back'))) {
48
+ $url = Mage::helper('M2ePro')->getBackUrl();
49
+ $this->_addButton('back', array(
50
+ 'label' => Mage::helper('M2ePro')->__('Back'),
51
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
52
+ 'class' => 'back'
53
+ ));
54
+ }
55
+ // ---------------------------------------
56
+
57
+ }
58
+
59
+ //########################################
60
+
61
+ public function getGridHtml()
62
+ {
63
+ $accountId = $this->getRequest()->getParam('account');
64
+
65
+ // ---------------------------------------
66
+ $viewHeaderBlock = $this->getLayout()->createBlock(
67
+ 'M2ePro/adminhtml_listing_other_view_header','',
68
+ array(
69
+ 'account' => Mage::helper('M2ePro/Component_Buy')->getCachedObject('Account', $accountId),
70
+ 'marketplace' => Mage::helper('M2ePro/Component_Buy')->getMarketplace()
71
+ )
72
+ );
73
+ // ---------------------------------------
74
+
75
+ $mapToProductBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_listing_other_mapping');
76
+
77
+ return $viewHeaderBlock->toHtml() . $mapToProductBlock->toHtml() . parent::getGridHtml();
78
+ }
79
+
80
+ //########################################
81
+
82
+ protected function _toHtml()
83
+ {
84
+ /** @var $helper Ess_M2ePro_Helper_Data */
85
+ $helper = Mage::helper('M2ePro');
86
+ $componentMode = Ess_M2ePro_Helper_Component_Buy::NICK;
87
+
88
+ $logViewUrl = $this->getUrl(
89
+ '*/adminhtml_common_log/listingOther',
90
+ array(
91
+ 'filter' => base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Buy::NICK),
92
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_listing_other/index/tab/' . $componentMode)
93
+ )
94
+ );
95
+
96
+ $prepareData = $this->getUrl('*/adminhtml_listing_other_moving/prepareMoveToListing');
97
+ $createDefaultListingUrl = $this->getUrl('*/adminhtml_listing_other_moving/createDefaultListing');
98
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/moveToListingGrid');
99
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_other_moving/getFailedProductsGrid');
100
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_other_moving/tryToMoveToListing');
101
+ $moveToListing = $this->getUrl('*/adminhtml_listing_other_moving/moveToListing');
102
+
103
+ $mapAutoToProductUrl = $this->getUrl('*/adminhtml_listing_other_mapping/autoMap');
104
+
105
+ $removingProductsUrl = $this->getUrl('*/adminhtml_common_listing_other/removing');
106
+ $unmappingProductsUrl = $this->getUrl('*/adminhtml_listing_other_mapping/unmapping');
107
+
108
+ $someProductsWereNotMappedMessage = 'No matches were found. Please change the Mapping Attributes in <strong>';
109
+ $someProductsWereNotMappedMessage .= 'Configuration > Account > 3rd Party Listings</strong> ';
110
+ $someProductsWereNotMappedMessage .= 'or try to map manually.';
111
+ $someProductsWereNotMappedMessage = $helper->escapeJs($helper->__($someProductsWereNotMappedMessage));
112
+
113
+ $successfullyMappedMessage = $helper->escapeJs($helper->__('Product was successfully Mapped.'));
114
+
115
+ $createListing = $helper->escapeJs($helper->__(
116
+ 'Listings, which have the same Marketplace and Account were not found.'
117
+ ));
118
+ $createListing .= $helper->escapeJs($helper->__('Would you like to create one with Default Settings ?'));
119
+ $popupTitle = $helper->escapeJs($helper->__('Moving Rakuten.com Items'));
120
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Rakuten.com Item'));
121
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
122
+
123
+ $confirmMessage = $helper->escapeJs($helper->__('Are you sure?'));
124
+
125
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
126
+ $productsWereNotMovedMessage = $helper->escapeJs(
127
+ $helper->__('Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
128
+ );
129
+ $someProductsWereNotMovedMessage = $helper->escapeJs($helper->__(
130
+ 'Some of the Products were not Moved. <a target="_blank" href="%url%">View Log</a> for details.'
131
+ ));
132
+
133
+ $notEnoughDataMessage = $helper->escapeJs($helper->__('Not enough data.'));
134
+ $successfullyUnmappedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Unmapped.'));
135
+ $successfullyRemovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Removed.'));
136
+
137
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
138
+
139
+ $selectItemsMessage = $helper->escapeJs(
140
+ $helper->__('Please select the Products you want to perform the Action on.')
141
+ );
142
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
143
+
144
+ $processingDataMessage = $helper->escapeJs($helper->__('Processing %product_title% Product(s).'));
145
+
146
+ $successWord = $helper->escapeJs($helper->__('Success'));
147
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
148
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
149
+ $errorWord = $helper->escapeJs($helper->__('Error'));
150
+ $closeWord = $helper->escapeJs($helper->__('Close'));
151
+
152
+ $autoMapProgressTitle = $helper->escapeJs($helper->__('Map Item(s) to Products'));
153
+ $selectOnlyMapped = $helper->escapeJs($helper->__('Only Mapped Products must be selected.'));
154
+ $selectTheSameTypeProducts = $helper->escapeJs(
155
+ $helper->__('Selected Items must belong to the same Account and Marketplace.')
156
+ );
157
+
158
+ $translations = json_encode(array(
159
+
160
+ 'Mapping Product' => $helper->__('Mapping Product'),
161
+ 'Product does not exist.' => $helper->__('Product does not exist.'),
162
+ 'Please enter correct Product ID.' => $helper->__('Please enter correct Product ID.'),
163
+ 'Product(s) was successfully Mapped.' => $helper->__('Product(s) was successfully Mapped.'),
164
+ 'Please enter correct Product ID or SKU' => $helper->__('Please enter correct Product ID or SKU'),
165
+
166
+ 'Current version only supports Simple Products. Please, choose Simple Product.' => $helper->__(
167
+ 'Current version only supports Simple Products. Please, choose Simple Product.'
168
+ ),
169
+
170
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.' => $helper->__(
171
+ 'Item was not Mapped as the chosen %product_id% Simple Product has Custom Options.'
172
+ )
173
+
174
+ ));
175
+
176
+ $urls = json_encode(array(
177
+
178
+ 'adminhtml_common_log/listingOther' => $this->getUrl('*/adminhtml_common_log/listingOther',array(
179
+ 'back' => $helper->makeBackUrlParam('*/adminhtml_common_listing_other/index')
180
+ )),
181
+
182
+ 'adminhtml_listing_other_mapping/map' => $this->getUrl('*/adminhtml_listing_other_mapping/map'),
183
+
184
+ ));
185
+
186
+ $javascriptsMain = <<<HTML
187
+ <script type="text/javascript">
188
+
189
+ M2eProBuy = {};
190
+ M2eProBuy.url = {};
191
+ M2eProBuy.formData = {};
192
+ M2eProBuy.customData = {};
193
+ M2eProBuy.text = {};
194
+
195
+ M2ePro.url.add({$urls});
196
+ M2ePro.translator.add({$translations});
197
+
198
+ M2eProBuy.url.logViewUrl = '{$logViewUrl}';
199
+ M2eProBuy.url.prepareData = '{$prepareData}';
200
+ M2eProBuy.url.createDefaultListing = '{$createDefaultListingUrl}';
201
+ M2eProBuy.url.getGridHtml = '{$getMoveToListingGridHtml}';
202
+ M2eProBuy.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
203
+ M2eProBuy.url.tryToMoveToListing = '{$tryToMoveToListing}';
204
+ M2eProBuy.url.moveToListing = '{$moveToListing}';
205
+ M2eProBuy.url.mapAutoToProduct = '{$mapAutoToProductUrl}';
206
+ M2eProBuy.url.removingProducts = '{$removingProductsUrl}';
207
+ M2eProBuy.url.unmappingProducts = '{$unmappingProductsUrl}';
208
+
209
+ M2eProBuy.text.create_listing = '{$createListing}';
210
+ M2eProBuy.text.popup_title = '{$popupTitle}';
211
+ M2eProBuy.text.popup_title_single = '{$popupTitleSingle}';
212
+ M2eProBuy.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
213
+ M2eProBuy.text.confirm = '{$confirmMessage}';
214
+ M2eProBuy.text.successfully_moved = '{$successfullyMovedMessage}';
215
+ M2eProBuy.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
216
+ M2eProBuy.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
217
+ M2eProBuy.text.not_enough_data = '{$notEnoughDataMessage}';
218
+ M2eProBuy.text.successfully_unmapped = '{$successfullyUnmappedMessage}';
219
+ M2eProBuy.text.successfully_removed = '{$successfullyRemovedMessage}';
220
+
221
+ M2eProBuy.text.select_items_message = '{$selectItemsMessage}';
222
+ M2eProBuy.text.select_action_message = '{$selectActionMessage}';
223
+
224
+ M2eProBuy.text.automap_progress_title = '{$autoMapProgressTitle}';
225
+ M2eProBuy.text.processing_data_message = '{$processingDataMessage}';
226
+ M2eProBuy.text.successfully_mapped = '{$successfullyMappedMessage}';
227
+ M2eProBuy.text.failed_mapped = '{$someProductsWereNotMappedMessage}';
228
+
229
+ M2eProBuy.text.select_only_mapped_products = '{$selectOnlyMapped}';
230
+ M2eProBuy.text.select_the_same_type_products = '{$selectTheSameTypeProducts}';
231
+
232
+ M2eProBuy.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
233
+
234
+ M2eProBuy.text.success_word = '{$successWord}';
235
+ M2eProBuy.text.notice_word = '{$noticeWord}';
236
+ M2eProBuy.text.warning_word = '{$warningWord}';
237
+ M2eProBuy.text.error_word = '{$errorWord}';
238
+ M2eProBuy.text.close_word = '{$closeWord}';
239
+
240
+ M2eProBuy.customData.componentMode = '{$componentMode}';
241
+ M2eProBuy.customData.gridId = 'buyListingOtherGrid';
242
+
243
+ Event.observe(window,'load',function() {
244
+ ListingProgressBarObj = new ProgressBar('listing_other_progress_bar');
245
+ GridWrapperObj = new AreaWrapper('listing_other_content_container');
246
+
247
+ BuyListingOtherGridHandlerObj = new CommonBuyListingOtherGridHandler('buyListingOtherGrid');
248
+ BuyListingOtherMappingHandlerObj = new ListingOtherMappingHandler(
249
+ BuyListingOtherGridHandlerObj,
250
+ 'buy'
251
+ );
252
+
253
+ BuyListingOtherGridHandlerObj.movingHandler.setOptions(M2eProBuy);
254
+ BuyListingOtherGridHandlerObj.autoMappingHandler.setOptions(M2eProBuy);
255
+ BuyListingOtherGridHandlerObj.removingHandler.setOptions(M2eProBuy);
256
+ BuyListingOtherGridHandlerObj.unmappingHandler.setOptions(M2eProBuy);
257
+ });
258
+
259
+ </script>
260
+ HTML;
261
+
262
+ return $javascriptsMain.
263
+ '<div id="listing_other_progress_bar"></div>' .
264
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
265
+ '<div id="listing_other_content_container">' .
266
+ parent::_toHtml() .
267
+ '</div>';
268
+ }
269
+
270
+ //########################################
271
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Other/View/Grid.php ADDED
@@ -0,0 +1,530 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Other_View_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ /** @var $this->connRead Varien_Db_Adapter_Pdo_Mysql */
18
+ $this->connRead = Mage::getSingleton('core/resource')->getConnection('core_read');
19
+
20
+ // Initialization block
21
+ // ---------------------------------------
22
+ $this->setId('buyListingOtherGrid');
23
+ // ---------------------------------------
24
+
25
+ // Set default values
26
+ // ---------------------------------------
27
+ $this->setDefaultSort('id');
28
+ $this->setDefaultDir('DESC');
29
+ $this->setSaveParametersInSession(true);
30
+ $this->setUseAjax(true);
31
+ // ---------------------------------------
32
+ }
33
+
34
+ public function getMassactionBlockName()
35
+ {
36
+ return 'M2ePro/adminhtml_grid_massaction';
37
+ }
38
+
39
+ //########################################
40
+
41
+ protected function _prepareCollection()
42
+ {
43
+ $collection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
44
+
45
+ $collection->getSelect()->joinLeft(
46
+ array('mp' => Mage::getResourceModel('M2ePro/Marketplace')->getMainTable()),
47
+ 'mp.id = main_table.marketplace_id',
48
+ array('marketplace_title' => 'mp.title')
49
+ );
50
+
51
+ // Add Filter By Account
52
+ $accountFilter = $this->getRequest()->getParam('account');
53
+ if (!empty($accountFilter)) {
54
+ $collection->addFieldToFilter('account_id', $accountFilter);
55
+ }
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 = <<<HTML
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
+ HTML;
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,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Product extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingProduct');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_buy_listing_product';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+
28
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
29
+ $headerText = Mage::helper('M2ePro')->__(
30
+ 'Add Products To %component_name% Listing "%listing_title%"',
31
+ Mage::helper('M2ePro/Component_Buy')->getTitle(),
32
+ $this->escapeHtml($listingData['title'])
33
+ );
34
+ } else {
35
+ $headerText = Mage::helper('M2ePro')->__('Add Products To Listing "%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
+ // ---------------------------------------
54
+ if (is_null($this->getRequest()->getParam('back'))) {
55
+ $url = $this->getUrl(
56
+ '*/adminhtml_common_buy_listing/categoryProduct',
57
+ array(
58
+ 'id' => $listingData['id'],
59
+ 'save_categories' => $this->getRequest()->getParam('save_categories', 1),
60
+ 'selected_categories' => $this->getRequest()->getParam('selected_categories')
61
+ )
62
+ );
63
+ } else {
64
+ $url = Mage::helper('M2ePro')->getBackUrl(
65
+ '*/adminhtml_common_listing/index',
66
+ array(
67
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY
68
+ )
69
+ );
70
+ }
71
+ $this->_addButton('back', array(
72
+ 'label' => Mage::helper('M2ePro')->__('Back'),
73
+ 'onclick' => 'ProductGridHandlerObj.back_click(\''.$url.'\')',
74
+ 'class' => 'back'
75
+ ));
76
+ // ---------------------------------------
77
+
78
+ // ---------------------------------------
79
+ $this->_addButton('save', array(
80
+ 'label' => Mage::helper('M2ePro')->__('Save'),
81
+ 'onclick' => 'ProductGridHandlerObj.save_click(\'view\')',
82
+ 'class' => 'save'
83
+ ));
84
+ // ---------------------------------------
85
+ }
86
+
87
+ public function getGridHtml()
88
+ {
89
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_product_help');
90
+ return $helpBlock->toHtml() . parent::getGridHtml();
91
+ }
92
+
93
+ protected function _toHtml()
94
+ {
95
+ return '<div id="add_products_progress_bar"></div>'.
96
+ '<div id="add_products_container">'.
97
+ parent::_toHtml().
98
+ '</div>';
99
+ }
100
+
101
+ //########################################
102
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Product/Help.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Product_Help extends Mage_Adminhtml_Block_Widget
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingProductHelp');
20
+ // ---------------------------------------
21
+
22
+ $this->setTemplate('M2ePro/common/buy/listing/product/help.phtml');
23
+ }
24
+
25
+ //########################################
26
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Grid.php ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_ProductSearch_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ private $productId;
12
+
13
+ //########################################
14
+
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+
19
+ $this->productId = Mage::helper('M2ePro/Data_Global')->getValue('product_id');
20
+
21
+ // Initialization block
22
+ // ---------------------------------------
23
+ $this->setId('buyProductSearchGrid');
24
+ // ---------------------------------------
25
+
26
+ // Set default values
27
+ // ---------------------------------------
28
+ $this->setFilterVisibility(false);
29
+ $this->setPagerVisibility(false);
30
+ $this->setDefaultSort('id');
31
+ $this->setDefaultDir('ASC');
32
+ $this->setSaveParametersInSession(true);
33
+ $this->setUseAjax(true);
34
+ // ---------------------------------------
35
+ }
36
+
37
+ protected function _prepareCollection()
38
+ {
39
+ $data = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
40
+
41
+ $results = new Varien_Data_Collection();
42
+ foreach ($data['data'] as $index => $item) {
43
+ $temp = array(
44
+ 'id' => $index,
45
+ 'general_id' => isset($item['general_id']) ? $item['general_id'] : null,
46
+ 'title' => $item['title'],
47
+ 'image_url' => $item['image_url'],
48
+ 'price' => isset($item['price']) ? $item['price'] : null,
49
+ 'variations' => isset($item['variations']) ? $item['variations'] : null
50
+ );
51
+
52
+ $results->addItem(new Varien_Object($temp));
53
+ }
54
+
55
+ $this->setCollection($results);
56
+
57
+ return parent::_prepareCollection();
58
+ }
59
+
60
+ protected function _prepareColumns()
61
+ {
62
+ $this->addColumn('image', array(
63
+ 'header' => Mage::helper('M2ePro')->__('Image'),
64
+ 'align' => 'center',
65
+ 'type' => 'text',
66
+ 'width' => '80px',
67
+ 'index' => 'image_url',
68
+ 'filter' => false,
69
+ 'sortable' => false,
70
+ 'frame_callback' => array($this, 'callbackColumnImage')
71
+ ));
72
+
73
+ $this->addColumn('general_id', array(
74
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
75
+ 'align' => 'center',
76
+ 'type' => 'text',
77
+ 'width' => '75px',
78
+ 'index' => 'general_id',
79
+ 'filter' => false,
80
+ 'sortable' => false,
81
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
82
+ ));
83
+
84
+ $this->addColumn('title', array(
85
+ 'header' => Mage::helper('M2ePro')->__('Product Title'),
86
+ 'align' => 'left',
87
+ 'type' => 'text',
88
+ 'width' => '375px',
89
+ 'string_limit' => 10000,
90
+ 'index' => 'title',
91
+ 'filter' => false,
92
+ 'sortable' => false,
93
+ 'frame_callback' => array($this, 'callbackColumnTitle'),
94
+ ));
95
+
96
+ $this->addColumn('price',array(
97
+ 'header' => Mage::helper('catalog')->__('Price'),
98
+ 'width' => '60px',
99
+ 'align' => 'right',
100
+ 'index' => 'price',
101
+ 'filter' => false,
102
+ 'sortable' => false,
103
+ 'type' => 'text',
104
+ 'frame_callback' => array($this, 'callbackColumnPrice')
105
+ ));
106
+
107
+ $this->addColumn('actions', array(
108
+ 'header' => Mage::helper('M2ePro')->__('Action'),
109
+ 'align' => 'left',
110
+ 'type' => 'text',
111
+ 'width' => '78px',
112
+ 'filter' => false,
113
+ 'sortable' => false,
114
+ 'frame_callback' => array($this, 'callbackColumnActions'),
115
+ ));
116
+
117
+ }
118
+
119
+ //########################################
120
+
121
+ public function callbackColumnImage($value, $product, $column, $isExport)
122
+ {
123
+ return '<img width="75px" src="'.$value.'" />';
124
+ }
125
+
126
+ public function callbackColumnGeneralId($value, $product, $column, $isExport)
127
+ {
128
+ if (empty($value)) {
129
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl('%general_id%');
130
+ $templateHtml = '<a href="'.$url.'" target="_blank">%general_id%</a>';
131
+ return '<span id="buy_link_'.$product->getId().'">' . Mage::helper('M2ePro')->__('N/A') . '</span>' .
132
+ '<div id="template_buy_link_'.$product->getId().'" style="display: none;">'.$templateHtml.'</div>';
133
+ }
134
+
135
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
136
+
137
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
138
+ }
139
+
140
+ public function callbackColumnTitle($value, $row, $column, $isExport)
141
+ {
142
+ $value = '<div style="margin-left: 3px; margin-bottom: 10px;">'.
143
+ Mage::helper('M2ePro')->escapeHtml($value)."</div>";
144
+
145
+ $variations = $row->getData('variations');
146
+ if (is_null($variations)) {
147
+ return $value;
148
+ }
149
+
150
+ $specificsHtml = '';
151
+ $id = $row->getId();
152
+ foreach ($variations['set'] as $specificName => $specific) {
153
+ $specificsHtml .= '<span style="margin-left: 10px;
154
+ font-size: 11px;
155
+ color: #808080;
156
+ display: inline-block;
157
+ width: 100px;">'.
158
+ ucfirst(strtolower($specificName)).
159
+ ':</span>';
160
+ $specificsHtml .= '<select class="specifics_'.$id.'"
161
+ onchange="ListingGridHandlerObj.productSearchHandler.specificsChange(this)"
162
+ style="width: 150px; margin-left: 5px; margin-bottom: 5px; font-size: 10px;"
163
+ id="specific_'.$specificName.'_'.$id.'">';
164
+ $specificsHtml .= '<option value=""></option>';
165
+ foreach ($specific as $option) {
166
+ $specificsHtml .= '<option value="'.$option.'">'.$option.'</option>';
167
+ }
168
+ $specificsHtml .= '</select><br/>';
169
+ }
170
+
171
+ $specificsJsonContainer = '<div id="skus_'.$id.'" style="display: none;">'.
172
+ json_encode($variations['skus']).'</div>';
173
+
174
+ return $value . $specificsHtml . $specificsJsonContainer;
175
+ }
176
+
177
+ public function callbackColumnPrice($value, $row, $column, $isExport)
178
+ {
179
+ if (empty($value)) {
180
+ $value = Mage::helper('M2ePro')->__('N/A');
181
+ }
182
+
183
+ return '<div id="price_'.$row->getId().'" style="margin-right: 5px;">'.$value.'</div>';
184
+ }
185
+
186
+ public function callbackColumnActions($value, $row, $column, $isExport)
187
+ {
188
+ $assignText = Mage::helper('M2ePro')->__('Assign Rakuten.com SKU');
189
+ //->__('There is no such variation on Rakuten.com. Please, choose another variation.');
190
+ $naMessage = 'There is no such Variation on Rakuten.com. Please, choose another Variation.';
191
+ $naMessage = Mage::helper('M2ePro')->__($naMessage);
192
+
193
+ if (!is_null($row->getData('variations'))) {
194
+ $templateMapHtml =
195
+ '<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId('
196
+ .$this->productId
197
+ .', \'%general_id%\');">'.$assignText.'</a>';
198
+
199
+ $templateNaHtml = '<a href="javascript:void(0);" onclick="alert(\''.$naMessage.'\')">'.$assignText.'</a>';
200
+
201
+ return '<span id="map_link_'.$row->getId().'"><span style="color: #808080">'.$assignText.'</span></span>
202
+ <div id="template_map_link_'.$row->getId().'" style="display: none;">'.$templateMapHtml.'</div>
203
+ <div id="template_na_link_'.$row->getId().'" style="display: none;">'.$templateNaHtml.'</div>';
204
+ }
205
+
206
+ return '<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId('
207
+ .$this->productId
208
+ .', \''
209
+ .$row->getData('general_id')
210
+ .'\');">'.$assignText.'</a>';
211
+ }
212
+
213
+ //########################################
214
+
215
+ protected function _toHtml()
216
+ {
217
+ $javascriptsMain = <<<HTML
218
+ <script type="text/javascript">
219
+
220
+ $$('#buyProductSearchGrid div.grid th').each(function(el) {
221
+ el.style.padding = '2px 2px';
222
+ });
223
+
224
+ $$('#buyProductSearchGrid div.grid td').each(function(el) {
225
+ el.style.padding = '2px 2px';
226
+ });
227
+
228
+ </script>
229
+ HTML;
230
+
231
+ $searchData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
232
+
233
+ $searchParamsHtml = <<<HTML
234
+ <input id="buy_asin_search_type" type="hidden" value="{$searchData['type']}">
235
+ <input id="buy_asin_search_value" type="hidden" value="{$searchData['value']}">
236
+ HTML;
237
+
238
+ return parent::_toHtml() . $javascriptsMain . $searchParamsHtml;
239
+ }
240
+
241
+ //########################################
242
+
243
+ public function getGridUrl()
244
+ {
245
+ return $this->getUrl('*/adminhtml_common_buy_listing/getSuggestedBuyComSkuGrid', array('_current'=>true));
246
+ }
247
+
248
+ public function getRowUrl($row)
249
+ {
250
+ return false;
251
+ }
252
+
253
+ //########################################
254
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Main.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_ProductSearch_Main
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setTemplate('M2ePro/common/buy/listing/product_search/main.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ // ---------------------------------------
24
+ $data = array(
25
+ 'id' => 'productSearch_submit_button',
26
+ 'label' => Mage::helper('M2ePro')->__('Search'),
27
+ 'class' => 'productSearch_submit_button submit'
28
+ );
29
+ $buttonSubmitBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
30
+ $this->setChild('productSearch_submit_button', $buttonSubmitBlock);
31
+ // ---------------------------------------
32
+
33
+ // ---------------------------------------
34
+ $data = array(
35
+ 'id' => 'productSearch_back_button',
36
+ 'label' => Mage::helper('M2ePro')->__('Back'),
37
+ 'class' => 'productSearch_back_button'
38
+ );
39
+ $buttonBackBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
40
+ $this->setChild('productSearch_back_button', $buttonBackBlock);
41
+ // ---------------------------------------
42
+
43
+ // ---------------------------------------
44
+ $data = array(
45
+ 'id' => 'productSearch_cancel_button',
46
+ 'label' => Mage::helper('M2ePro')->__('Close'),
47
+ 'class' => 'productSearch_cancel_button'
48
+ );
49
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
50
+ $this->setChild('productSearch_cancel_button', $buttonCancelBlock);
51
+ // ---------------------------------------
52
+
53
+ // ---------------------------------------
54
+ $data = array(
55
+ 'id' => 'productSearch_cleanSuggest_button',
56
+ 'label' => Mage::helper('M2ePro')->__('Clear Search Results'),
57
+ 'class' => 'productSearch_cleanSuggest_button',
58
+ 'onclick' => 'ListingGridHandlerObj.productSearchHandler.clearSearchResultsAndOpenSearchMenu()'
59
+ );
60
+ $buttonResetBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
61
+ $this->setChild('productSearch_cleanSuggest_button', $buttonResetBlock);
62
+ // ---------------------------------------
63
+
64
+ parent::_beforeToHtml();
65
+ }
66
+
67
+ //########################################
68
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/ProductSearch/Menu.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_ProductSearch_Menu
10
+ extends Ess_M2ePro_Block_Adminhtml_Widget_Container
11
+ {
12
+ //########################################
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+
18
+ $this->setTemplate('M2ePro/common/buy/listing/product_search/menu.phtml');
19
+ }
20
+
21
+ protected function _beforeToHtml()
22
+ {
23
+ // ---------------------------------------
24
+ $data = array(
25
+ 'id' => 'productSearchMenu_cancel_button',
26
+ 'label' => Mage::helper('M2ePro')->__('Close'),
27
+ 'class' => 'productSearchMenu_cancel_button'
28
+ );
29
+ $buttonCancelBlock = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
30
+ $this->setChild('productSearchMenu_cancel_button', $buttonCancelBlock);
31
+ // ---------------------------------------
32
+
33
+ parent::_beforeToHtml();
34
+ }
35
+
36
+ //########################################
37
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Search extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('listingBuySearch');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_buy_listing_search';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
27
+ $componentName = Mage::helper('M2ePro/Component_Buy')->getTitle();
28
+ $headerText = Mage::helper('M2ePro')->__("Search %component_name% Listings Items", $componentName);
29
+ } else {
30
+ $headerText = Mage::helper('M2ePro')->__("Search Listings Items");
31
+ }
32
+
33
+ $this->_headerText = $headerText;
34
+ // ---------------------------------------
35
+
36
+ // Set buttons actions
37
+ // ---------------------------------------
38
+ $this->removeButton('back');
39
+ $this->removeButton('reset');
40
+ $this->removeButton('delete');
41
+ $this->removeButton('add');
42
+ $this->removeButton('save');
43
+ $this->removeButton('edit');
44
+ // ---------------------------------------
45
+
46
+ // ---------------------------------------
47
+ if (!is_null($this->getRequest()->getParam('back'))) {
48
+ $url = Mage::helper('M2ePro')->getBackUrl('*/adminhtml_common_buy_listing/search');
49
+ $this->_addButton('back', array(
50
+ 'label' => Mage::helper('M2ePro')->__('Back'),
51
+ 'onclick' => 'CommonHandlerObj.back_click(\'' . $url . '\')',
52
+ 'class' => 'back'
53
+ ));
54
+ }
55
+ // ---------------------------------------
56
+
57
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/search');
58
+
59
+ // ---------------------------------------
60
+ $url = $this->getUrl(
61
+ '*/adminhtml_common_listing/index',
62
+ array(
63
+ 'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_BUY,
64
+ 'back'=> $backUrl
65
+ )
66
+ );
67
+ $this->_addButton('goto_listings', array(
68
+ 'label' => Mage::helper('M2ePro')->__('Listings'),
69
+ 'onclick' => 'setLocation(\'' . $url . '\')',
70
+ 'class' => 'button_link'
71
+ ));
72
+ // ---------------------------------------
73
+
74
+ // ---------------------------------------
75
+ $this->_addButton('goto_templates', array(
76
+ 'label' => Mage::helper('M2ePro')->__('Policies'),
77
+ 'onclick' => '',
78
+ 'class' => 'button_link drop_down templates-drop-down'
79
+ ));
80
+ // ---------------------------------------
81
+
82
+ // ---------------------------------------
83
+ $url = $this->getUrl(
84
+ '*/adminhtml_common_log/listing',
85
+ array(
86
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_BUY
87
+ )
88
+ );
89
+ $this->_addButton('view_log', array(
90
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
91
+ 'onclick' => 'window.open(\'' . $url . '\')',
92
+ 'class' => 'button_link'
93
+ ));
94
+ // ---------------------------------------
95
+ }
96
+
97
+ //########################################
98
+
99
+ protected function _toHtml()
100
+ {
101
+ return $this->getTemplatesButtonJavascript() . parent::_toHtml();
102
+ }
103
+
104
+ public function getGridHtml()
105
+ {
106
+ $helpBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_common_listing_search_help');
107
+ return $helpBlock->toHtml() . parent::getGridHtml();
108
+ }
109
+
110
+ //########################################
111
+
112
+ protected function getTemplatesButtonJavascript()
113
+ {
114
+ $data = array(
115
+ 'target_css_class' => 'templates-drop-down',
116
+ 'items' => $this->getTemplatesButtonDropDownItems()
117
+ );
118
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
119
+ $dropDownBlock->setData($data);
120
+
121
+ return $dropDownBlock->toHtml();
122
+ }
123
+
124
+ protected function getTemplatesButtonDropDownItems()
125
+ {
126
+ $items = array();
127
+
128
+ $filter = base64_encode('component_mode=' . Ess_M2ePro_Helper_Component_Buy::NICK);
129
+
130
+ // ---------------------------------------
131
+ $url = $this->getUrl(
132
+ '*/adminhtml_common_template_sellingFormat/index',
133
+ array(
134
+ 'filter' => $filter
135
+ )
136
+ );
137
+ $items[] = array(
138
+ 'url' => $url,
139
+ 'label' => Mage::helper('M2ePro')->__('Selling Format Policies'),
140
+ 'target' => '_blank'
141
+ );
142
+ // ---------------------------------------
143
+
144
+ // ---------------------------------------
145
+ $url = $this->getUrl(
146
+ '*/adminhtml_common_template_synchronization/index',
147
+ array(
148
+ 'filter' => $filter
149
+ )
150
+ );
151
+ $items[] = array(
152
+ 'url' => $url,
153
+ 'label' => Mage::helper('M2ePro')->__('Synchronization Policies'),
154
+ 'target' => '_blank'
155
+ );
156
+ // ---------------------------------------
157
+
158
+ return $items;
159
+ }
160
+
161
+ //########################################
162
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/Search/Grid.php ADDED
@@ -0,0 +1,613 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_Search_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingSearchGrid');
20
+ // ---------------------------------------
21
+
22
+ // Set default values
23
+ // ---------------------------------------
24
+ $this->setDefaultSort('id');
25
+ $this->setDefaultDir('DESC');
26
+ $this->setSaveParametersInSession(true);
27
+ $this->setUseAjax(true);
28
+ // ---------------------------------------
29
+ }
30
+
31
+ //########################################
32
+
33
+ protected function _prepareCollection()
34
+ {
35
+ // Get collection products in listing
36
+ // ---------------------------------------
37
+ $listingProductCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Product');
38
+ $listingProductCollection->getSelect()->distinct();
39
+ $listingProductCollection->getSelect()
40
+ ->join(array('l'=>Mage::getResourceModel('M2ePro/Listing')->getMainTable()),
41
+ '(`l`.`id` = `main_table`.`listing_id`)',
42
+ array('listing_title'=>'title','store_id'))
43
+ ->join(array('bl'=>Mage::getResourceModel('M2ePro/Buy_Listing')->getMainTable()),
44
+ '(`bl`.`listing_id` = `l`.`id`)',
45
+ array('template_selling_format_id'));
46
+ // ---------------------------------------
47
+
48
+ // Communicate with magento product table
49
+ // ---------------------------------------
50
+ $dbSelect = Mage::getResourceModel('core/config')->getReadConnection()
51
+ ->select()
52
+ ->from(Mage::getSingleton('core/resource')
53
+ ->getTableName('catalog_product_entity_varchar'),
54
+ new Zend_Db_Expr('MAX(`store_id`)'))
55
+ ->where("`entity_id` = `main_table`.`product_id`")
56
+ ->where("`attribute_id` = `ea`.`attribute_id`")
57
+ ->where("`store_id` = 0 OR `store_id` = `l`.`store_id`");
58
+
59
+ $listingProductCollection->getSelect()
60
+ //->join(array('csi'=>Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
61
+ // '(csi.product_id = `main_table`.product_id)',array('qty'))
62
+ ->join(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
63
+ '(cpe.entity_id = `main_table`.product_id)',
64
+ array('magento_sku'=>'sku'))
65
+ ->join(array('cisi'=>Mage::getSingleton('core/resource')->getTableName('cataloginventory_stock_item')),
66
+ '(cisi.product_id = `main_table`.product_id AND cisi.stock_id = 1)',
67
+ array('is_in_stock'))
68
+ ->join(array('cpev'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_varchar')),
69
+ "(`cpev`.`entity_id` = `main_table`.product_id)",
70
+ array('value'))
71
+ ->join(array('ea'=>Mage::getSingleton('core/resource')->getTableName('eav_attribute')),
72
+ '(`cpev`.`attribute_id` = `ea`.`attribute_id` AND `ea`.`attribute_code` = \'name\')',
73
+ array())
74
+ ->where('`cpev`.`store_id` = ('.$dbSelect->__toString().')');
75
+ // ---------------------------------------
76
+
77
+ $listingProductCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
78
+ $listingProductCollection->getSelect()->columns(
79
+ array(
80
+ 'is_m2epro_listing' => new Zend_Db_Expr('1'),
81
+ 'magento_sku' => 'cpe.sku',
82
+ 'is_in_stock' => 'cisi.is_in_stock',
83
+ 'product_name' => 'cpev.value',
84
+ 'listing_title' => 'l.title',
85
+ 'store_id' => 'l.store_id',
86
+ 'account_id' => 'l.account_id',
87
+ 'marketplace_id' => 'l.marketplace_id',
88
+ 'listing_product_id' => 'main_table.id',
89
+ 'product_id' => 'main_table.product_id',
90
+ 'listing_id' => 'main_table.listing_id',
91
+ 'status' => 'main_table.status',
92
+ 'template_new_product_id' => 'second_table.template_new_product_id',
93
+ 'general_id' => 'second_table.general_id',
94
+ 'online_sku' => 'second_table.sku',
95
+ 'online_qty' => 'second_table.online_qty',
96
+ 'online_price' => 'second_table.online_price'
97
+ )
98
+ );
99
+
100
+ // ---------------------------------------
101
+ $listingOtherCollection = Mage::helper('M2ePro/Component_Buy')->getCollection('Listing_Other');
102
+ $listingOtherCollection->getSelect()->distinct();
103
+
104
+ // add stock availability, type id, status & visibility to select
105
+ // ---------------------------------------
106
+ $listingOtherCollection->getSelect()
107
+ ->joinLeft(
108
+ array('cisi' => Mage::getResourceModel('cataloginventory/stock_item')->getMainTable()),
109
+ '(`cisi`.`product_id` = `main_table`.`product_id` AND cisi.stock_id = 1)',
110
+ array('is_in_stock'))
111
+ ->joinLeft(array('cpe'=>Mage::getSingleton('core/resource')->getTableName('catalog_product_entity')),
112
+ '(cpe.entity_id = `main_table`.product_id)',
113
+ array('magento_sku'=>'sku'));
114
+ // ---------------------------------------
115
+
116
+ $listingOtherCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
117
+ $listingOtherCollection->getSelect()->columns(
118
+ array(
119
+ 'is_m2epro_listing' => new Zend_Db_Expr(0),
120
+ 'magento_sku' => 'cpe.sku',
121
+ 'is_in_stock' => 'cisi.is_in_stock',
122
+ 'product_name' => 'second_table.title',
123
+ 'listing_title' => new Zend_Db_Expr('NULL'),
124
+ 'store_id' => new Zend_Db_Expr(0),
125
+ 'account_id' => 'main_table.account_id',
126
+ 'marketplace_id' => 'main_table.marketplace_id',
127
+ 'listing_product_id' => new Zend_Db_Expr('NULL'),
128
+ 'product_id' => 'main_table.product_id',
129
+ 'listing_id' => new Zend_Db_Expr('NULL'),
130
+ 'status' => 'main_table.status',
131
+ 'template_new_product_id' => new Zend_Db_Expr('NULL'),
132
+ 'general_id' => 'second_table.general_id',
133
+ 'online_sku' => 'second_table.sku',
134
+ 'online_qty' => 'second_table.online_qty',
135
+ 'online_price' => 'second_table.online_price',
136
+ )
137
+ );
138
+ // ---------------------------------------
139
+
140
+ // ---------------------------------------
141
+ $selects = array(
142
+ $listingProductCollection->getSelect(),
143
+ $listingOtherCollection->getSelect()
144
+ );
145
+
146
+ $unionSelect = Mage::getResourceModel('core/config')->getReadConnection()->select();
147
+ $unionSelect->union($selects);
148
+
149
+ $resultCollection = new Varien_Data_Collection_Db(Mage::getResourceModel('core/config')->getReadConnection());
150
+ $resultCollection->getSelect()->reset()->from(
151
+ array('main_table' => $unionSelect),
152
+ array(
153
+ 'is_m2epro_listing',
154
+ 'magento_sku',
155
+ 'is_in_stock',
156
+ 'product_name',
157
+ 'listing_title',
158
+ 'store_id',
159
+ 'account_id',
160
+ 'marketplace_id',
161
+ 'listing_product_id',
162
+ 'product_id',
163
+ 'listing_id',
164
+ 'status',
165
+ 'template_new_product_id',
166
+ 'general_id',
167
+ 'online_sku',
168
+ 'online_qty',
169
+ 'online_price'
170
+ )
171
+ );
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
+ 'type' => 'text',
195
+ 'index' => 'product_name',
196
+ 'filter_index' => 'product_name',
197
+ 'frame_callback' => array($this, 'callbackColumnProductTitle'),
198
+ 'filter_condition_callback' => array($this, 'callbackFilterTitle')
199
+ ));
200
+
201
+ $this->addColumn('stock_availability',
202
+ array(
203
+ 'header'=> Mage::helper('M2ePro')->__('Stock Availability'),
204
+ 'width' => '100px',
205
+ 'index' => 'is_in_stock',
206
+ 'filter_index' => 'is_in_stock',
207
+ 'type' => 'options',
208
+ 'sortable' => false,
209
+ 'options' => array(
210
+ 1 => Mage::helper('M2ePro')->__('In Stock'),
211
+ 0 => Mage::helper('M2ePro')->__('Out of Stock')
212
+ ),
213
+ 'frame_callback' => array($this, 'callbackColumnStockAvailability')
214
+ ));
215
+
216
+ if (Mage::helper('M2ePro/View_Common')->is3rdPartyShouldBeShown(Ess_M2ePro_Helper_Component_Buy::NICK)) {
217
+ $this->addColumn('is_m2epro_listing', array(
218
+ 'header' => Mage::helper('M2ePro')->__('Listing Type'),
219
+ 'align' => 'left',
220
+ 'width' => '100px',
221
+ 'type' => 'options',
222
+ 'sortable' => false,
223
+ 'index' => 'is_m2epro_listing',
224
+ 'options' => array(
225
+ 1 => Mage::helper('M2ePro')->__('M2E Pro'),
226
+ 0 => Mage::helper('M2ePro')->__('3rd Party')
227
+ )
228
+ ));
229
+ }
230
+
231
+ $this->addColumn('sku', array(
232
+ 'header' => Mage::helper('M2ePro')->__('Reference ID'),
233
+ 'align' => 'left',
234
+ 'width' => '150px',
235
+ 'type' => 'text',
236
+ 'index' => 'online_sku',
237
+ 'filter_index' => 'online_sku',
238
+ 'frame_callback' => array($this, 'callbackColumnSku')
239
+ ));
240
+
241
+ $this->addColumn('general_id', array(
242
+ 'header' => Mage::helper('M2ePro')->__('Rakuten.com SKU'),
243
+ 'align' => 'left',
244
+ 'width' => '100px',
245
+ 'type' => 'text',
246
+ 'index' => 'general_id',
247
+ 'filter_index' => 'general_id',
248
+ 'frame_callback' => array($this, 'callbackColumnGeneralId')
249
+ ));
250
+
251
+ $this->addColumn('online_qty', array(
252
+ 'header' => Mage::helper('M2ePro')->__('QTY'),
253
+ 'align' => 'right',
254
+ 'width' => '70px',
255
+ 'type' => 'number',
256
+ 'index' => 'online_qty',
257
+ 'filter_index' => 'online_qty',
258
+ 'frame_callback' => array($this, 'callbackColumnAvailableQty')
259
+ ));
260
+
261
+ $this->addColumn('online_price', array(
262
+ 'header' => Mage::helper('M2ePro')->__('Price'),
263
+ 'align' => 'right',
264
+ 'width' => '70px',
265
+ 'type' => 'number',
266
+ 'index' => 'online_price',
267
+ 'filter_index' => 'online_price',
268
+ 'frame_callback' => array($this, 'callbackColumnPrice')
269
+ ));
270
+
271
+ $this->addColumn('status', array(
272
+ 'header' => Mage::helper('M2ePro')->__('Status'),
273
+ 'width' => '125px',
274
+ 'index' => 'status',
275
+ 'filter_index' => 'status',
276
+ 'type' => 'options',
277
+ 'sortable' => false,
278
+ 'options' => array(
279
+ Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED => Mage::helper('M2ePro')->__('Not Listed'),
280
+ Ess_M2ePro_Model_Listing_Product::STATUS_LISTED => Mage::helper('M2ePro')->__('Active'),
281
+ Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED => Mage::helper('M2ePro')->__('Inactive')
282
+ ),
283
+ 'frame_callback' => array($this, 'callbackColumnStatus')
284
+ ));
285
+
286
+ $this->addColumn('goto_listing_item', array(
287
+ 'header' => Mage::helper('M2ePro')->__('Manage'),
288
+ 'align' => 'center',
289
+ 'width' => '50px',
290
+ 'type' => 'text',
291
+ 'filter' => false,
292
+ 'sortable' => false,
293
+ 'frame_callback' => array($this, 'callbackColumnActions')
294
+ ));
295
+
296
+ return parent::_prepareColumns();
297
+ }
298
+
299
+ //########################################
300
+
301
+ public function callbackColumnProductId($value, $row, $column, $isExport)
302
+ {
303
+ if (is_null($row->getData('product_id'))) {
304
+ return Mage::helper('M2ePro')->__('N/A');
305
+ }
306
+
307
+ $productId = (int)$row->getData('product_id');
308
+ $storeId = (int)$row->getData('store_id');
309
+
310
+ $withoutImageHtml = '<a href="'
311
+ .$this->getUrl('adminhtml/catalog_product/edit',
312
+ array('id' => $productId))
313
+ .'" target="_blank">'
314
+ .$productId
315
+ .'</a>';
316
+
317
+ $showProductsThumbnails = (bool)(int)Mage::helper('M2ePro/Module')->getConfig()
318
+ ->getGroupValue('/view/','show_products_thumbnails');
319
+ if (!$showProductsThumbnails) {
320
+ return $withoutImageHtml;
321
+ }
322
+
323
+ /** @var $magentoProduct Ess_M2ePro_Model_Magento_Product */
324
+ $magentoProduct = Mage::getModel('M2ePro/Magento_Product');
325
+ $magentoProduct->setProductId($productId);
326
+ $magentoProduct->setStoreId($storeId);
327
+
328
+ $imageUrlResized = $magentoProduct->getThumbnailImageLink();
329
+ if (is_null($imageUrlResized)) {
330
+ return $withoutImageHtml;
331
+ }
332
+
333
+ $imageHtml = $productId.'<hr/><img src="'.$imageUrlResized.'" />';
334
+ $withImageHtml = str_replace('>'.$productId.'<','>'.$imageHtml.'<',$withoutImageHtml);
335
+
336
+ return $withImageHtml;
337
+ }
338
+
339
+ public function callbackColumnProductTitle($value, $row, $column, $isExport)
340
+ {
341
+ if (is_null($value) || $value === '') {
342
+ $value = '<i style="color:gray;">receiving...</i>';
343
+ } else {
344
+ $value = '<span>'.Mage::helper('M2ePro')->escapeHtml($value).'</span>';
345
+ }
346
+
347
+ if (!is_null($row->getData('listing_id'))) {
348
+ $urlParams = array();
349
+ $urlParams['id'] = $row->getData('listing_id');
350
+ $urlParams['back'] = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/search');
351
+
352
+ $listingUrl = $this->getUrl('*/adminhtml_common_buy_listing/view',$urlParams);
353
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($row->getData('listing_title'));
354
+
355
+ if (strlen($listingTitle) > 50) {
356
+ $listingTitle = substr($listingTitle, 0, 50) . '...';
357
+ }
358
+
359
+ $value .= '<br/><hr style="border:none; border-top:1px solid silver; margin: 2px 0px;"/>';
360
+ $value .= '<strong>'
361
+ .Mage::helper('M2ePro')->__('Listing')
362
+ .': </strong> <a href="'
363
+ .$listingUrl
364
+ .'">'
365
+ .$listingTitle
366
+ .'</a>';
367
+ }
368
+
369
+ if (!is_null($row->getData('magento_sku'))) {
370
+ $tempSku = $row->getData('magento_sku');
371
+
372
+ $value .= '<br/><strong>'
373
+ . Mage::helper('M2ePro')->__('SKU')
374
+ . ':</strong> '
375
+ . Mage::helper('M2ePro')->escapeHtml($tempSku);
376
+ }
377
+
378
+ if (is_null($row->getData('listing_product_id'))) {
379
+ return $value;
380
+ }
381
+
382
+ $listingProductId = (int)$row->getData('listing_product_id');
383
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
384
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
385
+
386
+ if ($listingProduct->getChildObject()->getVariationManager()->isVariationProduct() &&
387
+ $listingProduct->getChildObject()->getVariationManager()->isVariationProductMatched()
388
+ ) {
389
+ $productOptions = $listingProduct->getChildObject()->getVariationManager()->getProductOptions();
390
+
391
+ $value .= '<br/>';
392
+ $value .= '<div style="font-size: 11px; color: grey;"><br/>';
393
+ foreach ($productOptions as $attribute => $option) {
394
+ !$option && $option = '--';
395
+ $value .= '<strong>' . Mage::helper('M2ePro')->escapeHtml($attribute) .
396
+ '</strong>:&nbsp;' . Mage::helper('M2ePro')->escapeHtml($option) . '<br/>';
397
+ }
398
+ $value .= '</div>';
399
+ $value .= '<br/>';
400
+ }
401
+
402
+ return $value;
403
+ }
404
+
405
+ public function callbackColumnStockAvailability($value, $row, $column, $isExport)
406
+ {
407
+ if (is_null($row->getData('is_in_stock'))) {
408
+ return Mage::helper('M2ePro')->__('N/A');
409
+ }
410
+
411
+ if ((int)$row->getData('is_in_stock') <= 0) {
412
+ return '<span style="color: red;">'.$value.'</span>';
413
+ }
414
+
415
+ return $value;
416
+ }
417
+
418
+ public function callbackColumnSku($value, $row, $column, $isExport)
419
+ {
420
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
421
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
422
+ }
423
+
424
+ if (is_null($value) || $value === '') {
425
+ return Mage::helper('M2ePro')->__('N/A');
426
+ }
427
+ return $value;
428
+ }
429
+
430
+ public function callbackColumnGeneralId($value, $row, $column, $isExport)
431
+ {
432
+ if (empty($value)) {
433
+
434
+ if ($row->getData('status') != Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
435
+ return '<i style="color:gray;">receiving...</i>';
436
+ }
437
+
438
+ if ($row->getData('template_new_product_id')) {
439
+ return Mage::helper('M2ePro')->__('New SKU');
440
+ }
441
+
442
+ return Mage::helper('M2ePro')->__('N/A');
443
+ }
444
+
445
+ $url = Mage::helper('M2ePro/Component_Buy')->getItemUrl($value);
446
+ return '<a href="'.$url.'" target="_blank">'.$value.'</a>';
447
+ }
448
+
449
+ public function callbackColumnAvailableQty($value, $row, $column, $isExport)
450
+ {
451
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
452
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
453
+ }
454
+
455
+ if (is_null($value) || $value === '') {
456
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
457
+ }
458
+
459
+ if ($value <= 0) {
460
+ return '<span style="color: red;">0</span>';
461
+ }
462
+
463
+ return $value;
464
+ }
465
+
466
+ public function callbackColumnPrice($value, $row, $column, $isExport)
467
+ {
468
+ if ($row->getData('status') == Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED) {
469
+ return '<span style="color: gray;">' . Mage::helper('M2ePro')->__('Not Listed') . '</span>';
470
+ }
471
+
472
+ if (is_null($value) || $value === '') {
473
+ return '<i style="color:gray;">'.Mage::helper('M2ePro')->__('receiving...').'</i>';
474
+ }
475
+
476
+ if ((float)$value <= 0) {
477
+ return '<span style="color: #f00;">0</span>';
478
+ }
479
+
480
+ return Mage::app()->getLocale()->currency('USD')->toCurrency($value);
481
+ }
482
+
483
+ public function callbackColumnStatus($value, $row, $column, $isExport)
484
+ {
485
+ switch ($row->getData('status')) {
486
+
487
+ case Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED:
488
+ $value = '<span style="color: gray;">' . $value . '</span>';
489
+ break;
490
+
491
+ case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED:
492
+ $value = '<span style="color: green;">' . $value . '</span>';
493
+ break;
494
+
495
+ case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED:
496
+ $value = '<span style="color: red;">'.$value.'</span>';
497
+ break;
498
+
499
+ default:
500
+ break;
501
+ }
502
+
503
+ if (is_null($row->getData('listing_product_id'))) {
504
+ return $value;
505
+ }
506
+
507
+ $listingProductId = (int)$row->getData('listing_product_id');
508
+ /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */
509
+ $listingProduct = Mage::helper('M2ePro/Component_Buy')->getObject('Listing_Product',$listingProductId);
510
+
511
+ $tempLocks = $listingProduct->getObjectLocks();
512
+
513
+ foreach ($tempLocks as $lock) {
514
+
515
+ switch ($lock->getTag()) {
516
+
517
+ case 'new_sku_action':
518
+ $title = Mage::helper('M2ePro')->__('Add New SKU in Progress...');
519
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
520
+ break;
521
+
522
+ case 'list_action':
523
+ $title = Mage::helper('M2ePro')->__('List in Progress...');
524
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
525
+ break;
526
+
527
+ case 'relist_action':
528
+ $title = Mage::helper('M2ePro')->__('Relist in Progress...');
529
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
530
+ break;
531
+
532
+ case 'revise_action':
533
+ $title = Mage::helper('M2ePro')->__('Revise in Progress...');
534
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
535
+ break;
536
+
537
+ case 'stop_action':
538
+ $title = Mage::helper('M2ePro')->__('Stop in Progress...');
539
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
540
+ break;
541
+
542
+ case 'stop_and_remove_action':
543
+ $title = Mage::helper('M2ePro')->__('Stop And Remove in Progress...');
544
+ $value .= '<br/><span style="color: #605fff">['.$title.']</span>';
545
+ break;
546
+
547
+ default:
548
+ break;
549
+
550
+ }
551
+ }
552
+
553
+ return $value;
554
+ }
555
+
556
+ public function callbackColumnActions($value, $row, $column, $isExport)
557
+ {
558
+ $altTitle = Mage::helper('M2ePro')->escapeHtml(Mage::helper('M2ePro')->__('Go to Listing'));
559
+ $iconSrc = $this->getSkinUrl('M2ePro/images/goto_listing.png');
560
+
561
+ if ($row->getData('is_m2epro_listing')) {
562
+ $url = $this->getUrl('*/adminhtml_common_buy_listing/view/', array(
563
+ 'id'=>$row->getData('listing_id'),
564
+ 'filter'=>base64_encode(
565
+ 'product_id[from]='.(int)$row->getData('product_id')
566
+ .'&product_id[to]='.(int)$row->getData('product_id')
567
+ )
568
+ ));
569
+ } else {
570
+ $url = $this->getUrl('*/adminhtml_common_buy_listing_other/view/', array(
571
+ 'account' => $row->getData('account_id'),
572
+ 'marketplace' => $row->getData('marketplace_id'),
573
+ 'filter' => base64_encode(
574
+ 'title='.$row->getData('online_sku')
575
+ )
576
+ ));
577
+ }
578
+
579
+ $html = <<<HTML
580
+ <div style="float:right; margin:5px 15px 0 0;">
581
+ <a title="{$altTitle}" target="_blank" href="{$url}"><img src="{$iconSrc}" /></a>
582
+ </div>
583
+ HTML;
584
+
585
+ return $html;
586
+ }
587
+
588
+ protected function callbackFilterTitle($collection, $column)
589
+ {
590
+ $value = $column->getFilter()->getValue();
591
+
592
+ if ($value == null) {
593
+ return;
594
+ }
595
+
596
+ $collection->getSelect()
597
+ ->where('product_name LIKE ? OR magento_sku LIKE ? OR listing_title LIKE ?', '%'.$value.'%');
598
+ }
599
+
600
+ //########################################
601
+
602
+ public function getGridUrl()
603
+ {
604
+ return $this->getUrl('*/adminhtml_common_buy_listing/searchGrid', array('_current'=>true));
605
+ }
606
+
607
+ public function getRowUrl($row)
608
+ {
609
+ return false;
610
+ }
611
+
612
+ //########################################
613
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View.php ADDED
@@ -0,0 +1,600 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_View extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+ //########################################
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ // Initialization block
18
+ // ---------------------------------------
19
+ $this->setId('buyListingView');
20
+ $this->_blockGroup = 'M2ePro';
21
+ $this->_controller = 'adminhtml_common_buy_listing_view';
22
+ // ---------------------------------------
23
+
24
+ // Set header text
25
+ // ---------------------------------------
26
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
27
+
28
+ if (!Mage::helper('M2ePro/View_Common_Component')->isSingleActiveComponent()) {
29
+ $headerText = Mage::helper('M2ePro')->__(
30
+ 'View %component_name% Listing',
31
+ Mage::helper('M2ePro/Component_Buy')->getTitle()
32
+ );
33
+ } else {
34
+ $headerText = Mage::helper('M2ePro')->__('View Listing ');
35
+ }
36
+
37
+ $this->_headerText = $headerText;
38
+ // ---------------------------------------
39
+
40
+ // Set buttons actions
41
+ // ---------------------------------------
42
+ $this->removeButton('back');
43
+ $this->removeButton('reset');
44
+ $this->removeButton('delete');
45
+ $this->removeButton('add');
46
+ $this->removeButton('save');
47
+ $this->removeButton('edit');
48
+ // ---------------------------------------
49
+
50
+ // ---------------------------------------
51
+ $url = $this->getUrl('*/adminhtml_common_log/listing', array(
52
+ 'id' => $listingData['id'],
53
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_BUY
54
+ ));
55
+ $this->_addButton('view_log', array(
56
+ 'label' => Mage::helper('M2ePro')->__('View Log'),
57
+ 'onclick' => 'window.open(\'' . $url . '\')',
58
+ 'class' => 'button_link'
59
+ ));
60
+ // ---------------------------------------
61
+
62
+ // ---------------------------------------
63
+ $this->_addButton('edit_settings', array(
64
+ 'label' => Mage::helper('M2ePro')->__('Edit Settings'),
65
+ 'onclick' => '',
66
+ 'class' => 'drop_down edit_settings_drop_down'
67
+ ));
68
+ // ---------------------------------------
69
+
70
+ // ---------------------------------------
71
+ $this->_addButton('add_products', array(
72
+ 'label' => Mage::helper('M2ePro')->__('Add Products'),
73
+ 'onclick' => '',
74
+ 'class' => 'add drop_down add_products_drop_down'
75
+ ));
76
+ // ---------------------------------------
77
+ }
78
+
79
+ protected function _toHtml()
80
+ {
81
+ return '<div id="listing_view_progress_bar"></div>' .
82
+ '<div id="listing_container_errors_summary" class="errors_summary" style="display: none;"></div>' .
83
+ '<div id="listing_view_content_container">'.
84
+ parent::_toHtml() .
85
+ '</div>';
86
+ }
87
+
88
+ public function getGridHtml()
89
+ {
90
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
91
+
92
+ /** @var $helper Ess_M2ePro_Helper_Data */
93
+ $helper = Mage::helper('M2ePro');
94
+
95
+ // ---------------------------------------
96
+ $urls = $helper->getControllerActions(
97
+ 'adminhtml_common_listing_autoAction', array(
98
+ 'listing_id' => $this->getRequest()->getParam('id'),
99
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK
100
+ )
101
+ );
102
+ $showAutoAction = json_encode((bool)$this->getRequest()->getParam('auto_actions'));
103
+
104
+ $path = 'adminhtml_common_log/listingProduct';
105
+ $urls[$path] = $this->getUrl('*/' . $path, array(
106
+ 'channel' => Ess_M2ePro_Helper_Component_Buy::NICK,
107
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array('id' =>$listingData['id']))
108
+ ));
109
+
110
+ $path = 'adminhtml_common_listing/duplicateProducts';
111
+ $urls[$path] = $this->getUrl('*/' . $path);
112
+
113
+ $urls = json_encode($urls);
114
+ // ---------------------------------------
115
+
116
+ $component = Ess_M2ePro_Helper_Component_Buy::NICK;
117
+ $layout = $this->getLayout();
118
+
119
+ $temp = Mage::helper('M2ePro/Data_Session')->getValue('products_ids_for_list', true);
120
+ $productsIdsForList = empty($temp) ? '' : $temp;
121
+
122
+ $gridId = 'buyListingViewGrid' . $listingData['id'];
123
+ $ignoreListings = json_encode(array($listingData['id']));
124
+
125
+ $logViewUrl = $this->getUrl('*/adminhtml_common_log/listing', array(
126
+ 'id' => $listingData['id'],
127
+ 'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::CHANNEL_ID_BUY,
128
+ 'back'=>$helper->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array('id' =>$listingData['id']))
129
+ ));
130
+ $getErrorsSummary = $this->getUrl('*/adminhtml_listing/getErrorsSummary');
131
+
132
+ $runListProducts = $this->getUrl('*/adminhtml_common_buy_listing/runListProducts');
133
+ $runReviseProducts = $this->getUrl('*/adminhtml_common_buy_listing/runReviseProducts');
134
+ $runRelistProducts = $this->getUrl('*/adminhtml_common_buy_listing/runRelistProducts');
135
+ $runStopProducts = $this->getUrl('*/adminhtml_common_buy_listing/runStopProducts');
136
+ $runStopAndRemoveProducts = $this->getUrl('*/adminhtml_common_buy_listing/runStopAndRemoveProducts');
137
+
138
+ $prepareData = $this->getUrl('*/adminhtml_listing_moving/prepareMoveToListing');
139
+ $getMoveToListingGridHtml = $this->getUrl('*/adminhtml_listing_moving/moveToListingGrid');
140
+ $getFailedProductsGridHtml = $this->getUrl('*/adminhtml_listing_moving/getFailedProductsGrid');
141
+ $tryToMoveToListing = $this->getUrl('*/adminhtml_listing_moving/tryToMoveToListing');
142
+ $moveToListing = $this->getUrl('*/adminhtml_listing_moving/moveToListing');
143
+
144
+ $getVariationEditPopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationEditPopup');
145
+ $getVariationManagePopupUrl = $this->getUrl('*/adminhtml_common_listing/getVariationManagePopup');
146
+
147
+ $variationEditActionUrl = $this->getUrl('*/adminhtml_common_listing/variationEdit');
148
+ $variationManageActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManage');
149
+ $variationManageGenerateActionUrl = $this->getUrl('*/adminhtml_common_listing/variationManageGenerate');
150
+
151
+ $popupTitle = $helper->escapeJs($helper->__('Moving Rakuten.com Items'));
152
+ $popupTitleSingle = $helper->escapeJs($helper->__('Moving Rakuten.com Item'));
153
+ $failedProductsPopupTitle = $helper->escapeJs($helper->__('Products failed to move'));
154
+
155
+ $taskCompletedMessage = $helper->escapeJs($helper->__('Task completed. Please wait ...'));
156
+ $taskCompletedSuccessMessage = $helper->escapeJs(
157
+ $helper->__('"%task_title%" Task has successfully submitted to be processed.')
158
+ );
159
+ $taskCompletedWarningMessage = $helper->escapeJs($helper->__(
160
+ '"%task_title%" Task has completed with warnings. <a target="_blank" href="%url%">View Log</a> for details.'
161
+ ));
162
+ $taskCompletedErrorMessage = $helper->escapeJs($helper->__(
163
+ '"%task_title%" Task has completed with errors. <a target="_blank" href="%url%">View Log</a> for details.'
164
+ ));
165
+
166
+ $lockedObjNoticeMessage = $helper->escapeJs(
167
+ $helper->__('Some Rakuten.com request(s) are being processed now.')
168
+ );
169
+ $sendingDataToBuyMessage = $helper->escapeJs($helper->__(
170
+ 'Sending %product_title% Product(s) data on Rakuten.com.'
171
+ ));
172
+ $viewAllProductLogMessage = $helper->escapeJs($helper->__('View All Product Log.'));
173
+
174
+ $listingLockedMessage = $helper->escapeJs(
175
+ $helper->__('The Listing was locked by another process. Please try again later.')
176
+ );
177
+ $listingEmptyMessage = $helper->escapeJs($helper->__('Listing is empty.'));
178
+
179
+ $listingAllItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
180
+ ->__('Listing All Items On Rakuten.com'));
181
+ $listingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
182
+ ->__('Listing Selected Items On Rakuten.com'));
183
+ $revisingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
184
+ ->__('Revising Selected Items On Rakuten.com'));
185
+ $relistingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
186
+ ->__('Relisting Selected Items On Rakuten.com'));
187
+ $stoppingSelectedItemsMessage = Mage::helper('M2ePro')->escapeJs(Mage::helper('M2ePro')
188
+ ->__('Stopping Selected Items On Rakuten.com'));
189
+ $stoppingAndRemovingSelectedItemsMessage = Mage::helper('M2ePro')
190
+ ->escapeJs(Mage::helper('M2ePro')
191
+ ->__('Stopping On Rakuten.com And Removing From Listing Selected Items'));
192
+ $addNewSkuSelectedItemsMessage = Mage::helper('M2ePro')
193
+ ->escapeJs(Mage::helper('M2ePro')
194
+ ->__('Adding New SKU On Rakuten.com'));
195
+
196
+ $successfullyMovedMessage = $helper->escapeJs($helper->__('Product(s) was successfully Moved.'));
197
+ $productsWereNotMovedMessage = $helper->escapeJs(
198
+ $helper->__('Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
199
+ );
200
+ $someProductsWereNotMovedMessage = $helper->escapeJs(
201
+ $helper->__('Some Product(s) was not Moved. <a target="_blank" href="%url%">View Log</a> for details.')
202
+ );
203
+
204
+ $selectItemsMessage = $helper->escapeJs(
205
+ $helper->__('Please select the Products you want to perform the Action on.')
206
+ );
207
+ $selectActionMessage = $helper->escapeJs($helper->__('Please select Action.'));
208
+
209
+ $successWord = $helper->escapeJs($helper->__('Success'));
210
+ $noticeWord = $helper->escapeJs($helper->__('Notice'));
211
+ $warningWord = $helper->escapeJs($helper->__('Warning'));
212
+ $errorWord = $helper->escapeJs($helper->__('Error'));
213
+ $closeWord = $helper->escapeJs($helper->__('Close'));
214
+
215
+ $naString = Mage::helper('M2ePro')->__('N/A');
216
+ $assignString = Mage::helper('M2ePro')->__('Assign Rakuten.com SKU');
217
+
218
+ $textConfirm = $helper->escapeJs($helper->__('Are you sure?'));
219
+
220
+ $searchBuyComSkuManual = $this->getUrl('*/adminhtml_common_buy_listing/searchBuyComSkuManual');
221
+ $suggestedBuyComSkuGridHmtl = $this->getUrl('*/adminhtml_common_buy_listing/getSuggestedBuyComSkuGrid');
222
+ $searchBuyComSkuAuto = $this->getUrl('*/adminhtml_common_buy_listing/searchBuyComSkuAuto');
223
+ $mapToBuyComSku = $this->getUrl('*/adminhtml_common_buy_listing/mapToBuyComSku');
224
+ $unmapFromBuyComSku = $this->getUrl('*/adminhtml_common_buy_listing/unmapFromBuyComSku');
225
+
226
+ $newGeneralId = $this->getUrl('*/adminhtml_common_buy_template_newProduct');
227
+
228
+ $marketplaceId = Mage::helper('M2ePro/Data_Global')->getValue('marketplace_id');
229
+ $marketplaceInstance = Mage::helper('M2ePro/Component_Buy')->getCachedObject('Marketplace',$marketplaceId);
230
+ $marketplace = json_encode($marketplaceInstance->getData());
231
+
232
+ $marketplaceSynchUrl = $this->getUrl(
233
+ '*/adminhtml_common_marketplace/index',
234
+ array('tab' => Ess_M2ePro_Block_Adminhtml_Common_Marketplace::TAB_ID_RAKUTEN)
235
+ );
236
+ $notSynchronizedMarketplace = $helper->escapeJs(
237
+ $helper->__(
238
+ 'In order to use New SKU functionality, please re-synchronize Marketplace data.'
239
+ ).' '.
240
+ $helper->__(
241
+ 'Press "Save And Update" Button after redirect on Marketplace Page.'
242
+ )
243
+ );
244
+
245
+ $enterProductSearchQueryMessage = $helper->escapeJs(
246
+ $helper->__('Please enter Product Title or Rakuten.com SKU/ISBN/UPC.')
247
+ );
248
+ $autoMapBuyComSkuProgressTitle = $helper->escapeJs($helper->__('Assign Rakuten.com SKU to Item(s)'));
249
+ $autoMapBuyComSkuErrorMessage = $helper->escapeJs(
250
+ $helper->__('Server is currently unavailable. Please try again later.')
251
+ );
252
+
253
+ $noVariationsLeftText = $helper->__('All Variations are already added.');
254
+
255
+ $translations = json_encode(array(
256
+ 'Auto Add/Remove Rules' => $helper->__('Auto Add/Remove Rules'),
257
+ 'Based on Magento Categories' => $helper->__('Based on Magento Categories'),
258
+ 'You must select at least 1 Category.' => $helper->__('You must select at least 1 Category.'),
259
+ 'Rule with the same Title already exists.' => $helper->__('Rule with the same Title already exists.')
260
+ ));
261
+
262
+ $javascriptsMain = <<<HTML
263
+ <script type="text/javascript">
264
+
265
+ if (typeof M2ePro == 'undefined') {
266
+ M2ePro = {};
267
+ M2ePro.url = {};
268
+ M2ePro.formData = {};
269
+ M2ePro.customData = {};
270
+ M2ePro.text = {};
271
+ }
272
+
273
+ M2ePro.url.add({$urls});
274
+ M2ePro.translator.add({$translations});
275
+
276
+ M2ePro.productsIdsForList = '{$productsIdsForList}';
277
+
278
+ M2ePro.url.logViewUrl = '{$logViewUrl}';
279
+ M2ePro.url.getErrorsSummary = '{$getErrorsSummary}';
280
+
281
+ M2ePro.url.runListProducts = '{$runListProducts}';
282
+ M2ePro.url.runReviseProducts = '{$runReviseProducts}';
283
+ M2ePro.url.runRelistProducts = '{$runRelistProducts}';
284
+ M2ePro.url.runStopProducts = '{$runStopProducts}';
285
+ M2ePro.url.runStopAndRemoveProducts = '{$runStopAndRemoveProducts}';
286
+
287
+ M2ePro.url.searchBuyComSkuManual = '{$searchBuyComSkuManual}';
288
+ M2ePro.url.searchBuyComSkuAuto = '{$searchBuyComSkuAuto}';
289
+ M2ePro.url.suggestedBuyComSkuGrid = '{$suggestedBuyComSkuGridHmtl}';
290
+ M2ePro.url.mapToBuyComSku = '{$mapToBuyComSku}';
291
+ M2ePro.url.unmapFromBuyComSku = '{$unmapFromBuyComSku}';
292
+
293
+ M2ePro.url.prepareData = '{$prepareData}';
294
+ M2ePro.url.getGridHtml = '{$getMoveToListingGridHtml}';
295
+ M2ePro.url.getFailedProductsGridHtml = '{$getFailedProductsGridHtml}';
296
+ M2ePro.url.tryToMoveToListing = '{$tryToMoveToListing}';
297
+ M2ePro.url.moveToListing = '{$moveToListing}';
298
+
299
+ M2ePro.url.get_variation_edit_popup = '{$getVariationEditPopupUrl}';
300
+ M2ePro.url.get_variation_manage_popup = '{$getVariationManagePopupUrl}';
301
+
302
+ M2ePro.url.variation_edit_action = '{$variationEditActionUrl}';
303
+ M2ePro.url.variation_manage_action = '{$variationManageActionUrl}';
304
+ M2ePro.url.variation_manage_generate_action = '{$variationManageGenerateActionUrl}';
305
+
306
+ M2ePro.url.newGeneralId = '{$newGeneralId}';
307
+ M2ePro.url.marketplace_synch = '{$marketplaceSynchUrl}';
308
+
309
+ M2ePro.text.popup_title = '{$popupTitle}';
310
+ M2ePro.text.popup_title_single = '{$popupTitleSingle}';
311
+ M2ePro.text.failed_products_popup_title = '{$failedProductsPopupTitle}';
312
+
313
+ M2ePro.text.task_completed_message = '{$taskCompletedMessage}';
314
+ M2ePro.text.task_completed_success_message = '{$taskCompletedSuccessMessage}';
315
+ M2ePro.text.task_completed_warning_message = '{$taskCompletedWarningMessage}';
316
+ M2ePro.text.task_completed_error_message = '{$taskCompletedErrorMessage}';
317
+
318
+ M2ePro.text.locked_obj_notice = '{$lockedObjNoticeMessage}';
319
+ M2ePro.text.sending_data_message = '{$sendingDataToBuyMessage}';
320
+ M2ePro.text.view_all_product_log_message = '{$viewAllProductLogMessage}';
321
+
322
+ M2ePro.text.listing_locked_message = '{$listingLockedMessage}';
323
+ M2ePro.text.listing_empty_message = '{$listingEmptyMessage}';
324
+
325
+ M2ePro.text.listing_all_items_message = '{$listingAllItemsMessage}';
326
+ M2ePro.text.listing_selected_items_message = '{$listingSelectedItemsMessage}';
327
+ M2ePro.text.revising_selected_items_message = '{$revisingSelectedItemsMessage}';
328
+ M2ePro.text.relisting_selected_items_message = '{$relistingSelectedItemsMessage}';
329
+ M2ePro.text.stopping_selected_items_message = '{$stoppingSelectedItemsMessage}';
330
+ M2ePro.text.stopping_and_removing_selected_items_message = '{$stoppingAndRemovingSelectedItemsMessage}';
331
+ M2ePro.text.add_new_sku_selected_items_message = '{$addNewSkuSelectedItemsMessage}';
332
+
333
+ M2ePro.text.successfully_moved = '{$successfullyMovedMessage}';
334
+ M2ePro.text.products_were_not_moved = '{$productsWereNotMovedMessage}';
335
+ M2ePro.text.some_products_were_not_moved = '{$someProductsWereNotMovedMessage}';
336
+
337
+ M2ePro.text.select_items_message = '{$selectItemsMessage}';
338
+ M2ePro.text.select_action_message = '{$selectActionMessage}';
339
+
340
+ M2ePro.text.success_word = '{$successWord}';
341
+ M2ePro.text.notice_word = '{$noticeWord}';
342
+ M2ePro.text.warning_word = '{$warningWord}';
343
+ M2ePro.text.error_word = '{$errorWord}';
344
+ M2ePro.text.close_word = '{$closeWord}';
345
+
346
+ M2ePro.text.na = '{$naString}';
347
+ M2ePro.text.assign = '{$assignString}';
348
+
349
+ M2ePro.text.confirm = '{$textConfirm}';
350
+
351
+ M2ePro.text.enter_productSearch_query = '{$enterProductSearchQueryMessage}';
352
+ M2ePro.text.automap_buy_com_sku_progress_title = '{$autoMapBuyComSkuProgressTitle}';
353
+ M2ePro.text.automap_error_message = '{$autoMapBuyComSkuErrorMessage}';
354
+
355
+ M2ePro.text.no_variations_left = '{$noVariationsLeftText}';
356
+
357
+ M2ePro.text.not_synchronized_marketplace = '{$notSynchronizedMarketplace}';
358
+
359
+ M2ePro.customData.componentMode = '{$component}';
360
+ M2ePro.customData.gridId = '{$gridId}';
361
+ M2ePro.customData.ignoreListings = '{$ignoreListings}';
362
+
363
+ M2ePro.customData.marketplace = {$marketplace};
364
+
365
+ Event.observe(window, 'load', function() {
366
+
367
+ ListingGridHandlerObj = new CommonBuyListingGridHandler(
368
+ 'buyListingViewGrid{$listingData['id']}',
369
+ {$listingData['id']}
370
+ );
371
+
372
+ ListingGridHandlerObj.actionHandler.setOptions(M2ePro);
373
+ ListingGridHandlerObj.movingHandler.setOptions(M2ePro);
374
+ ListingGridHandlerObj.productSearchHandler.setOptions(M2ePro);
375
+
376
+ ListingProgressBarObj = new ProgressBar('listing_view_progress_bar');
377
+ GridWrapperObj = new AreaWrapper('listing_view_content_container');
378
+
379
+ ListingProductVariationHandlerObj = new CommonListingProductVariationHandler(M2ePro,
380
+ ListingGridHandlerObj);
381
+
382
+ if (M2ePro.productsIdsForList) {
383
+ ListingGridHandlerObj.getGridMassActionObj().checkedString = M2ePro.productsIdsForList;
384
+ ListingGridHandlerObj.actionHandler.listAction();
385
+ }
386
+
387
+ ListingAutoActionHandlerObj = new ListingAutoActionHandler();
388
+ if ({$showAutoAction}) {
389
+ ListingAutoActionHandlerObj.loadAutoActionHtml();
390
+ }
391
+
392
+ });
393
+
394
+ </script>
395
+ HTML;
396
+
397
+ $helpBlock = $layout->createBlock('M2ePro/adminhtml_common_buy_listing_view_help');
398
+ $productSearchMenuBlock = $layout->createBlock('M2ePro/adminhtml_common_buy_listing_productSearch_menu');
399
+ $productSearchBlock = $layout->createBlock('M2ePro/adminhtml_common_buy_listing_productSearch_main');
400
+
401
+ // ---------------------------------------
402
+ $data = array(
403
+ 'target_css_class' => 'edit_settings_drop_down',
404
+ 'items' => $this->getTemplatesButtonDropDownItems()
405
+ );
406
+ $templatesDropDownBlock = $layout->createBlock('M2ePro/adminhtml_widget_button_dropDown');
407
+ $templatesDropDownBlock->setData($data);
408
+ // ---------------------------------------
409
+
410
+ // ---------------------------------------
411
+ $data = array(
412
+ 'target_css_class' => 'add_products_drop_down',
413
+ 'items' => $this->getAddProductsDropDownItems()
414
+ );
415
+ $addProductsDropDownBlock = $layout->createBlock('M2ePro/adminhtml_widget_button_dropDown');
416
+ $addProductsDropDownBlock->setData($data);
417
+ // ---------------------------------------
418
+
419
+ // ---------------------------------------
420
+ $listingSwitcher = $this->getLayout()->createBlock('M2ePro/adminhtml_common_buy_listing_view_listingSwitcher');
421
+ // ---------------------------------------
422
+
423
+ // ---------------------------------------
424
+ $viewHeaderBlock = $this->getLayout()->createBlock(
425
+ 'M2ePro/adminhtml_listing_view_header','',
426
+ array('listing' => Mage::helper('M2ePro/Component_Buy')->getCachedObject('Listing',$listingData['id']))
427
+ );
428
+ // ---------------------------------------
429
+
430
+ return $javascriptsMain
431
+ . $templatesDropDownBlock->toHtml()
432
+ . $listingSwitcher->toHtml()
433
+ . $addProductsDropDownBlock->toHtml()
434
+ . $helpBlock->toHtml()
435
+ . $viewHeaderBlock->toHtml()
436
+ . $productSearchMenuBlock->toHtml()
437
+ . $productSearchBlock->toHtml()
438
+ . parent::getGridHtml();
439
+ }
440
+
441
+ public function getHeaderHtml()
442
+ {
443
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
444
+
445
+ // ---------------------------------------
446
+ $collection = Mage::getModel('M2ePro/Listing')->getCollection();
447
+ $collection->addFieldToFilter('component_mode', Ess_M2ePro_Helper_Component_Buy::NICK);
448
+ $collection->addFieldToFilter('id', array('neq' => $listingData['id']));
449
+ $collection->setPageSize(200);
450
+ $collection->setOrder('title', 'ASC');
451
+
452
+ $items = array();
453
+ foreach ($collection->getItems() as $item) {
454
+ $items[] = array(
455
+ 'label' => $item->getTitle(),
456
+ 'url' => $this->getUrl('*/*/view', array('id' => $item->getId()))
457
+ );
458
+ }
459
+ // ---------------------------------------
460
+
461
+ if (count($items) == 0) {
462
+ return parent::getHeaderHtml();
463
+ }
464
+
465
+ // ---------------------------------------
466
+ $data = array(
467
+ 'target_css_class' => 'listing-profile-title',
468
+ 'style' => 'max-height: 120px; overflow: auto; width: 200px;',
469
+ 'items' => $items
470
+ );
471
+ $dropDownBlock = $this->getLayout()->createBlock('M2ePro/adminhtml_widget_button_dropDown');
472
+ $dropDownBlock->setData($data);
473
+ // ---------------------------------------
474
+
475
+ return parent::getHeaderHtml() . $dropDownBlock->toHtml();
476
+ }
477
+
478
+ public function getHeaderText()
479
+ {
480
+ // ---------------------------------------
481
+ $changeProfile = Mage::helper('M2ePro')->__('Change Listing');
482
+ $headerText = parent::getHeaderText();
483
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
484
+ $listingTitle = Mage::helper('M2ePro')->escapeHtml($listingData['title']);
485
+ // ---------------------------------------
486
+
487
+ return <<<HTML
488
+ {$headerText} <a href="javascript: void(0);"
489
+ id="listing-profile-title"
490
+ class="listing-profile-title"
491
+ style="font-weight: bold;"
492
+ title="{$changeProfile}"><span class="drop_down_header">"{$listingTitle}"</span></a>
493
+ HTML;
494
+ }
495
+
496
+ protected function getTemplatesButtonDropDownItems()
497
+ {
498
+ $items = array();
499
+
500
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
501
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
502
+ '*/adminhtml_common_buy_listing/view',
503
+ array(
504
+ 'id' => $listingData['id']
505
+ )
506
+ );
507
+
508
+ // ---------------------------------------
509
+ $url = $this->getUrl(
510
+ '*/adminhtml_common_buy_listing/edit',
511
+ array(
512
+ 'id' => $listingData['id'],
513
+ 'back' => $backUrl,
514
+ 'tab' => 'selling'
515
+ )
516
+ );
517
+ $items[] = array(
518
+ 'url' => $url,
519
+ 'label' => Mage::helper('M2ePro')->__('Selling Settings'),
520
+ 'target' => '_blank'
521
+ );
522
+ // ---------------------------------------
523
+
524
+ // ---------------------------------------
525
+ $url = $this->getUrl(
526
+ '*/adminhtml_common_buy_listing/edit',
527
+ array(
528
+ 'id' => $listingData['id'],
529
+ 'back' => $backUrl,
530
+ 'tab' => 'search'
531
+ )
532
+ );
533
+ $items[] = array(
534
+ 'url' => $url,
535
+ 'label' => Mage::helper('M2ePro')->__('Search Settings'),
536
+ 'target' => '_blank'
537
+ );
538
+ // ---------------------------------------
539
+
540
+ // ---------------------------------------
541
+ $items[] = array(
542
+ 'url' => 'javascript: void(0);',
543
+ 'onclick' => 'ListingAutoActionHandlerObj.loadAutoActionHtml();',
544
+ 'label' => Mage::helper('M2ePro')->__('Auto Add/Remove Rules')
545
+ );
546
+ // ---------------------------------------
547
+
548
+ return $items;
549
+ }
550
+
551
+ public function getAddProductsDropDownItems()
552
+ {
553
+ $items = array();
554
+
555
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
556
+ $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('*/adminhtml_common_buy_listing/view', array(
557
+ 'id' => $listingData['id']
558
+ ));
559
+
560
+ // ---------------------------------------
561
+ $url = $this->getUrl(
562
+ '*/adminhtml_common_listing_productAdd/index',
563
+ array(
564
+ 'id' => $listingData['id'],
565
+ 'back' => $backUrl,
566
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
567
+ 'clear' => 1,
568
+ 'step' => 2,
569
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
570
+ )
571
+ );
572
+ $items[] = array(
573
+ 'url' => $url,
574
+ 'label' => Mage::helper('M2ePro')->__('From Products List')
575
+ );
576
+ // ---------------------------------------
577
+
578
+ // ---------------------------------------
579
+ $url = $this->getUrl(
580
+ '*/adminhtml_common_listing_productAdd/index',
581
+ array(
582
+ 'id' => $listingData['id'],
583
+ 'back' => $backUrl,
584
+ 'component' => Ess_M2ePro_Helper_Component_Buy::NICK,
585
+ 'clear' => 1,
586
+ 'step' => 2,
587
+ 'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
588
+ )
589
+ );
590
+ $items[] = array(
591
+ 'url' => $url,
592
+ 'label' => Mage::helper('M2ePro')->__('From Categories')
593
+ );
594
+ // ---------------------------------------
595
+
596
+ return $items;
597
+ }
598
+
599
+ //########################################
600
+ }
app/code/community/Ess/M2ePro/Block/Adminhtml/Common/Buy/Listing/View/Grid.php ADDED
@@ -0,0 +1,973 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * @author M2E Pro Developers Team
5
+ * @copyright 2011-2015 ESS-UA [M2E Pro]
6
+ * @license Commercial use is forbidden
7
+ */
8
+
9
+ class Ess_M2ePro_Block_Adminhtml_Common_Buy_Listing_View_Grid
10
+ extends Ess_M2ePro_Block_Adminhtml_Magento_Product_Grid_Abstract
11
+ {
12
+ public $hideMassactionColumn = false;
13
+
14
+ /** @var $sellingFormatTemplate Ess_M2ePro_Model_Buy_Template_SellingFormat */
15
+ private $sellingFormatTemplate = NULL;
16
+
17
+ private $lockedDataCache = array();
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('buyListingViewGrid'.$listingData['id']);
30
+ // ---------------------------------------
31
+
32
+ $this->showAdvancedFilterProductsOption = false;
33
+
34
+ $this->sellingFormatTemplate = Mage::helper('M2ePro/Component_Buy')->getCachedObject(
35
+ 'Template_SellingFormat', $listingData['template_selling_format_id'], NULL,
36
+ array('template')
37
+ );
38
+ }
39
+
40
+ //########################################
41
+
42
+ protected function _prepareCollection()
43
+ {
44
+ $listingData = Mage::helper('M2ePro/Data_Global')->getValue('temp_data');
45
+
46
+ // Get collection
47
+ // ---------------------------------------
48
+ /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */
49
+ $collection = Mage::getConfig()->getModelInstance('Ess_M2ePro_Model_Mysql4_Magento_Product_Collection',
50
+ Mage::getModel('catalog/product')->getResource());
51
+ $collection
52
+ ->setListingProductModeOn()
53
+ ->addAttributeToSelect('name')
54
+ ->addAttributeToSelect('sku')
55
+ ->joinTable(
56
+ array('cisi' => 'cataloginventory/stock_item'),
57
+ 'product_id=entity_id',
58
+ array('qty' => 'qty'),
59
+ '{{table}}.stock_id=1',
60
+ 'left'
61
+ );
62
+
63
+ // ---------------------------------------
64
+
65
+ $collection->joinTable(
66
+ array('lp' => 'M2ePro/Listing_Product'),
67
+ 'product_id=entity_id',
68
+ array(
69
+ 'id' => 'id',
70
+ 'listing_id' => 'listing_id',
71
+ 'component_mode' => 'component_mode',
72
+ 'buy_status' => 'status',
73
+ 'additional_data' => 'additional_data'
74
+ ),
75
+ array(
76
+ 'listing_id' => (int)$listingData['id']
77
+ )
78
+ );
79
+ $collection->joinTable(
80
+ array('blp' => 'M2ePro/Buy_Listing_Product'),
81
+ 'listing_product_id=id',
82
+ array(
83
+ 'template_new_product_id' => 'template_new_product_id',
84
+ 'general_id' => 'general_id',
85
+ 'buy_sku' => 'sku',
86
+ 'online_price' => 'online_price',
87
+ 'online_qty' => 'online_qty',
88
+ 'search_settings_status' => 'search_settings_status',
89
+ 'search_settings_data' =>