From ea47e8809973a4a85165550d2abe3c9785c78361 Mon Sep 17 00:00:00 2001 From: M2E Pro Date: Wed, 3 Nov 2021 08:10:04 +0000 Subject: [PATCH] 6.15.0 (FINAL RELEASE) --- .../ControlPanel/Inspection/Grid.php | 177 ++---- .../Ebay/Listing/View/Settings/Grid.php | 25 +- .../Block/Adminhtml/Ebay/Order/Grid.php | 10 +- .../Adminhtml/Log/Order/AbstractGrid.php | 23 +- app/code/community/Ess/M2ePro/CHANGELOG | 79 ++- .../Ess/M2ePro/Helper/Component/Ebay.php | 2 + .../M2ePro/Helper/Component/Ebay/Motors.php | 114 +++- .../Ess/M2ePro/Helper/Order/Notification.php | 92 ++- .../Product/Action/DataBuilder/Details.php | 3 +- .../Amazon/Listing/Product/Repricing.php | 3 +- .../M2ePro/Model/Amazon/Listing/Source.php | 4 +- .../Description/Definition/Source.php | 6 +- .../Amazon/Template/Description/Specific.php | 20 +- .../Template/Description/Specific/Source.php | 20 +- .../Model/ControlPanel/Inspection/Manager.php | 17 +- .../Product/ProcessScheduledActions.php | 19 + .../Ebay/Connector/Item/Revise/Responser.php | 7 +- .../Listing/Product/Action/Configurator.php | 28 + .../Product/Action/DataBuilder/Categories.php | 527 +--------------- .../Product/Action/DataBuilder/Parts.php | 562 ++++++++++++++++++ .../Product/Action/Type/List/Request.php | 2 +- .../Product/Action/Type/List/Response.php | 1 + .../Product/Action/Type/Relist/Request.php | 1 + .../Product/Action/Type/Relist/Response.php | 1 + .../Listing/Product/Action/Type/Request.php | 19 + .../Listing/Product/Action/Type/Response.php | 12 + .../Product/Action/Type/Revise/Request.php | 2 +- .../Product/Action/Type/Revise/Response.php | 1 + .../Checker/Abstract.php | 23 + .../Checker/Active.php | 38 ++ .../Ebay/Magento/Product/ChangeProcessor.php | 1 + .../Ess/M2ePro/Model/Ebay/Motor/Filter.php | 30 +- .../Ess/M2ePro/Model/Ebay/Motor/Group.php | 101 +++- .../Template/ChangeProcessor/Abstract.php | 1 + .../Model/Ebay/Template/Synchronization.php | 8 + .../Ebay/Template/Synchronization/Builder.php | 5 + .../Synchronization/ChangeProcessor.php | 33 +- .../Ebay/Template/Synchronization/Diff.php | 24 +- .../Ess/M2ePro/Model/Magento/Product.php | 10 +- .../M2ePro/Model/Magento/Product/Cache.php | 2 +- .../Model/Resource/Order/Log/Collection.php | 3 +- app/code/community/Ess/M2ePro/composer.json | 2 +- .../ControlPanel/InspectionController.php | 39 +- .../Adminhtml/Ebay/AccountController.php | 3 +- .../Adminhtml/Ebay/MotorController.php | 53 +- .../controllers/Adminhtml/OrderController.php | 5 +- app/code/community/Ess/M2ePro/etc/config.xml | 2 +- .../community/Ess/M2ePro/sql/Install/Ebay.php | 2 + .../y21_m10/PartsCompatibilityImprovement.php | 246 ++++++++ .../sql/Upgrade/v6_14_3_1__v6_15_0/Config.php | 19 + .../sql/Upgrade/v6_14_3__v6_14_3_1/Config.php | 21 + .../synchronization/form/tabs/revise.phtml | 18 +- composer.json | 2 +- js/M2ePro/Amazon/Listing/Create/Selling.js | 4 - js/M2ePro/ControlPanel/Inspection.js | 50 +- js/M2ePro/Walmart/Configuration/General.js | 4 +- 56 files changed, 1653 insertions(+), 873 deletions(-) create mode 100644 app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Parts.php create mode 100644 app/code/community/Ess/M2ePro/sql/Update/y21_m10/PartsCompatibilityImprovement.php create mode 100644 app/code/community/Ess/M2ePro/sql/Upgrade/v6_14_3_1__v6_15_0/Config.php create mode 100644 app/code/community/Ess/M2ePro/sql/Upgrade/v6_14_3__v6_14_3_1/Config.php diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/ControlPanel/Inspection/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/ControlPanel/Inspection/Grid.php index 1e1311754..ee0921456 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/ControlPanel/Inspection/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/ControlPanel/Inspection/Grid.php @@ -21,14 +21,6 @@ public function __construct() parent::__construct(); $this->setId('controlPanelInspectionsGrid'); - - $this->setDefaultSort('state'); - $this->setDefaultDir('DESC'); - $this->setDefaultFilter( - array( - 'state' => self::NOT_SUCCESS_FILTER - ) - ); $this->setSaveParametersInSession(true); $this->setUseAjax(true); } @@ -43,18 +35,16 @@ protected function _prepareCollection() foreach ($manager->getInspections() as $inspection) { /** @var Ess_M2ePro_Model_ControlPanel_Inspection_AbstractInspection $inspection */ $row = array( - 'id' => $manager->getId($inspection), - 'title' => $inspection->getTitle(), - 'description' => $inspection->getDescription(), - 'execution_speed' => $inspection->getExecutionSpeed(), - 'state' => (string)$inspection->getState(), - 'need_attention' => (string)(int)($inspection->getState() > Result::STATE_SUCCESS), - 'inspection' => $inspection + 'id' => $manager->getId($inspection), + 'title' => $inspection->getTitle(), + 'description' => $inspection->getDescription(), + 'inspection' => $inspection ); $collection->addItem(new Varien_Object($row)); } $this->setCollection($collection); + return parent::_prepareCollection(); } @@ -63,65 +53,62 @@ protected function _prepareColumns() $this->addColumn( 'title', array( - 'header' => Mage::helper('M2ePro')->__('Title'), - 'align' => 'left', - 'type' => 'text', - 'width' => '20%', - 'index' => 'title', - 'filter_index' => 'title', + 'header' => Mage::helper('M2ePro')->__('Title'), + 'align' => 'left', + 'type' => 'text', + 'width' => '20%', + 'index' => 'title', + 'filter_index' => 'title', 'filter_condition_callback' => array($this, 'callbackFilterLike'), - 'frame_callback' => array($this, 'callbackColumnTitle') + 'frame_callback' => array($this, 'callbackColumnTitle') ) ); $this->addColumn( 'details', array( - 'header' => Mage::helper('M2ePro')->__('Details'), - 'align' => 'left', - 'type' => 'text', - 'width' => '40%', - 'filter_index' => false, - 'frame_callback' => array($this, 'callbackColumnDetails') + 'header' => Mage::helper('M2ePro')->__('Details'), + 'align' => 'left', + 'type' => 'text', + 'column_css_class' => 'details', + 'width' => '40%', + 'filter_index' => false, ) ); $this->addColumn( - 'state', + 'actions', array( - 'header' => Mage::helper('M2ePro')->__('State'), - 'align' => 'right', - 'width' => '10%', - 'index' => 'state', - 'type' => 'options', - 'options' => array( - self::NOT_SUCCESS_FILTER => Mage::helper('M2ePro')->__('Error | Warning | Notice'), - Result::STATE_ERROR => Mage::helper('M2ePro')->__('Error'), - Result::STATE_WARNING => Mage::helper('M2ePro')->__('Warning'), - Result::STATE_NOTICE => Mage::helper('M2ePro')->__('Notice'), - Result::STATE_SUCCESS => Mage::helper('M2ePro')->__('Success'), + 'header' => Mage::helper('M2ePro')->__('Actions'), + 'align' => 'left', + 'width' => '150px', + 'type' => 'action', + 'index' => 'actions', + 'filter' => false, + 'sortable' => false, + 'getter' => 'getId', + 'renderer' => 'M2ePro/adminhtml_grid_column_renderer_action', + 'actions' => array( + 'checkAction' => array( + 'caption' => Mage::helper('M2ePro')->__('Check'), + 'field' => 'id', + 'onclick' => 'ControlPanelInspectionObj.checkAction()', + ) ), - 'filter_index' => 'state', - 'filter_condition_callback' => array($this, 'callbackFilterMatch'), - 'frame_callback' => array($this, 'callbackColumnState') ) ); $this->addColumn( - 'execution_speed', + 'id', array( - 'header' => Mage::helper('M2ePro')->__('Execution Speed'), - 'align' => 'right', - 'type' => 'options', - 'options' => array( - Manager::EXECUTION_SPEED_FAST => Mage::helper('M2ePro')->__('Fast'), - Manager::EXECUTION_SPEED_SLOW => Mage::helper('M2ePro')->__('Slow') - ), - 'width' => '10%', - 'index' => 'execution_speed', - 'filter_index' => 'execution_speed', - 'filter_condition_callback' => array($this, 'callbackFilterMatch'), - 'frame_callback' => array($this, 'callbackColumnSpeed') + 'header' => Mage::helper('M2ePro')->__('ID'), + 'align' => 'right', + 'width' => '100px', + 'type' => 'text', + 'index' => 'id', + 'column_css_class' => 'no-display id',//this sets a css class to the column row item + 'header_css_class' => 'no-display',//this sets a css class to the column header + ) ); @@ -146,7 +133,9 @@ protected function callbackFilterLike($collection, $column) } $this->getCollection()->addFilter( - $field, $value, Ess_M2ePro_Model_Collection_Custom::CONDITION_LIKE + $field, + $value, + Ess_M2ePro_Model_Collection_Custom::CONDITION_LIKE ); } @@ -164,7 +153,9 @@ protected function callbackFilterMatch($collection, $column) } $this->getCollection()->addFilter( - $field, $value, Ess_M2ePro_Model_Collection_Custom::CONDITION_MATCH + $field, + $value, + Ess_M2ePro_Model_Collection_Custom::CONDITION_MATCH ); } @@ -198,69 +189,23 @@ public function callbackColumnTitle($value, $row, $column, $isExport) HTML; } - public function callbackColumnDetails($value, $row, $column, $isExport) - { - /** @var Ess_M2ePro_Model_ControlPanel_Inspection_AbstractInspection $inspection */ - $inspection = $row->getData('inspection'); - - $html = ''; - foreach ($inspection->getResults() as $result) { - $html .= '
'; - $html .= <<getMarkupByResult($result->getState(), $result->getMessage())} -HTML; - if ($result->getMetadata()) { - $html .= <<[{$this->__('details')}] -
{$result->getMetadata()}
-HTML; - } - - $html .= '
'; - } - - return $html; - } - - public function callbackColumnState($value, $row, $column, $isExport) - { - return $this->getMarkupByResult($row->getData($column->getIndex()), $value); - } - - public function callbackColumnSpeed($value, $row, $column, $isExport) - { - /** @var Ess_M2ePro_Model_ControlPanel_Inspection_AbstractInspection $inspection */ - $inspection = $row->getData('inspection'); - - return <<[{$inspection->getTimeToExecute()} sec.] -HTML; - } - //######################################## - protected function getMarkupByResult($result, $text) + public function _toHtml() { - switch ($result) { - case Result::STATE_ERROR: - return "{$text}"; - - case Result::STATE_WARNING: - return "{$text}"; + $urls = Mage::helper('M2ePro')->jsonEncode( + array( + 'checkInspection' => $this->getUrl('M2ePro/adminhtml_controlPanel_Inspection/checkInspection') + ) + ); - case Result::STATE_NOTICE: - return "{$text}"; + $jsUrl = << - case Result::STATE_SUCCESS: - return "{$text}"; - } +M2ePro.url.add({$urls}); + +JS; - return $text; - } - - public function _toHtml() - { $css = << .data tr { @@ -272,7 +217,7 @@ public function _toHtml() HTML; - return $css . parent::_toHtml(); + return $jsUrl . $css . parent::_toHtml(); } //######################################## diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php index 7eed48502..ebee41ae1 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php @@ -719,10 +719,8 @@ public function callbackColumnMotorsAttribute($value, $row, $column, $isExport) $countOfFilters = count($motorsData['filters']); $countOfGroups = count($motorsData['groups']); - $showAll = false; - if ($countOfItems + $countOfFilters + $countOfGroups === 0) { - $showAll = true; + return Mage::helper('M2ePro')->__('N/A'); } if (Mage::helper('M2ePro/Component_Ebay_Motors')->isTypeBasedOnEpids($this->getMotorsType())) { @@ -736,55 +734,40 @@ public function callbackColumnMotorsAttribute($value, $row, $column, $isExport) $labelFilters = Mage::helper('M2ePro')->__('Filters'); $labelGroups = Mage::helper('M2ePro')->__('Groups'); - if ($showAll || $countOfItems > 0) { + if ($countOfItems > 0) { $html .= <<{$motorsTypeTitle}: {$countOfItems}
-HTML; - - if ($countOfItems) { - $html .= <<{$label}]
HTML; - } } - if ($showAll || $countOfFilters > 0) { + if ($countOfFilters > 0) { $html .= <<{$labelFilters}: {$countOfFilters}
-HTML; - - if ($countOfFilters) { - $html .= <<{$label}]
HTML; - } } - if ($showAll || $countOfGroups > 0) { + if ($countOfGroups > 0) { $html .= <<{$labelGroups}: {$countOfGroups}
-HTML; - - if ($countOfGroups) { - $html .= <<{$label}] HTML; - } } $html .= ''; diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Order/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Order/Grid.php index 7d81700f9..dba34050b 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Order/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Order/Grid.php @@ -719,11 +719,13 @@ protected function callbackFilterStatus($collection, $column) return; } - switch ($value) { - case Ess_M2ePro_Model_Ebay_Order::STATUS_CANCELED: - $collection->addFieldToFilter('cancellation_status', 1); - break; + if ($value == Ess_M2ePro_Model_Ebay_Order::STATUS_CANCELED) { + $collection->addFieldToFilter('cancellation_status', 1); + return; + } + $collection->addFieldToFilter('cancellation_status', 0); + switch ($value) { case Ess_M2ePro_Model_Ebay_Order::STATUS_SHIPPED: $collection->addFieldToFilter( 'shipping_status', diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Log/Order/AbstractGrid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Log/Order/AbstractGrid.php index 958fe5512..f8735f396 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Log/Order/AbstractGrid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Log/Order/AbstractGrid.php @@ -134,7 +134,8 @@ protected function _prepareColumns() 'width' => '150px', 'index' => 'so.increment_id', 'sortable' => false, - 'frame_callback' => array($this, 'callbackColumnMagentoOrderNumber') + 'frame_callback' => array($this, 'callbackColumnMagentoOrderNumber'), + 'filter_condition_callback' => array($this, 'callbackFilterMagentoOrderNumber') ) ); @@ -265,6 +266,23 @@ public function callbackFilterChannelOrderId($collection, $column) $collection->addFieldToFilter('main_table.order_id', array('in' => $ordersIds)); } + public function callbackFilterMagentoOrderNumber($collection, $column) + { + $cond = $column->getFilter()->getCondition(); + + if (empty($cond)) { + return; + } + + if ($column->getFilter()->getValue() == 'N/A') { + $collection->addFieldToFilter('mo.magento_order_id', array('null' => true)); + + return; + } + + $collection->addFieldToFilter('mo.magento_order_id', $cond); + } + //######################################## protected function addOrderCreateDateToFilter($collection, $filter) @@ -279,6 +297,9 @@ protected function addOrderCreateDateToFilter($collection, $filter) $field = ($column->getFilterIndex()) ? $column->getFilterIndex() : $column->getIndex(); $cond = $column->getFilter()->getCondition(); if ($field && isset($cond)) { + $date = new Zend_Date; + $date->set(Mage::helper('M2ePro/Order_Notification')->getNotificationDate(), Zend_Date::ISO_8601); + $cond['from'] = $date; $collection->addFieldToFilter($field, $cond); } } diff --git a/app/code/community/Ess/M2ePro/CHANGELOG b/app/code/community/Ess/M2ePro/CHANGELOG index b9554f36f..eb5dfb028 100644 --- a/app/code/community/Ess/M2ePro/CHANGELOG +++ b/app/code/community/Ess/M2ePro/CHANGELOG @@ -1,45 +1,60 @@ -* 6.14.3 (13/10/2021) +* 6.15.0 (03/11/2021) -eBay: [Fixed] Best Offer value is not updated during Automatic Revise after changing product price in Magento [#2523] -eBay: [Fixed] Magento Product cannot be saved after upgrade to 6.14.2 [#2988] +Common: [Improved] After skipping the message about the failure to create Magento orders, it reappears only if the same issue occurs with newly imported orders [#1222] +eBay: [Improved] Optimization of the eBay Parts Compatibility data storage and processing [#1203] +eBay: [Fixed] Internal Server Error(s) [The access Token cannot be retrieved. Please repeat the action again.] when trying to save the eBay account configurations [#1208] +eBay: [Fixed] Canceled orders appear along with Pending, Shipped, etc. orders when filtering them by a particular status in the grid [#2577] +Amazon: [Improved] Support for Magento Attributes of the Boolean type [#3010] +Amazon: [Fixed] Modification Value is not saved in the corresponding field when editing Selling Settings [#2963] +Walmart: [Fixed] Modification Value is not saved in the corresponding field when editing Selling Settings [#2963] + +* 6.14.3.1 (25/10/2021) + +eBay: [Improved] Optimization of the eBay Parts Compatibility data storage and processing [#1203] +Amazon: [Improved] Support for Magento Attributes of the Boolean type [#3010] + +* 6.14.3 (13/10/2021) + +eBay: [Fixed] Best Offer value is not updated during Automatic Revise after changing Price in Magento [#2523] +eBay: [Fixed] Unable to serialize value. Error: Malformed UTF-8 characters, possibly incorrectly encoded after upgrade to 6.14.2 [#2988] eBay: [Fixed] Product status is displayed as Inactive (Stopped) for Active eBay Items [#2926] eBay: [Fixed] Exception "Instance must be loaded first" occurs when importing Combined orders in Canceled status [#2574] Amazon: [Fixed] Item price is not updated during Manual Revise [#2518] -Walmart: [Fixed] Unmanaged Listings are not imported from the Channel [#1236] +Walmart: [Fixed] Undefined index: in Model/Listing/SynchronizeInventory/Walmart/ListingProductsHandler.php on line 56 when importing Unmanaged Listings from the Channel [#1236] * 6.14.2 (30/09/2021) -[eBay] [Fixed] eBay order was not refunded as per Magento credit memo creation [#1220] -[eBay] [Fixed] Magento Order was not created. Reason: Warning: A non-numeric value encountered [#2594] -[Amazon] [Fixed] Different Grand Totals in Amazon and Magento orders for Grouped Products listed as Set [#1218] -[Amazon] [Fixed] Internal Server Error(s) [Marketplace ID is not valid. It differs from the current.] occurs when trying to update the MWS token [#1215] -[Amazon] [Improved] Self-upload of Amazon invoices without receiving and checking the results of the GetFeedSubmissionResult command [#2939] +eBay: [Fixed] eBay order was not refunded as per Magento credit memo creation [#1220] +eBay: [Fixed] Magento Order was not created. Reason: Warning: A non-numeric value encountered [#2594] +Amazon: [Fixed] Different Grand Totals in Amazon and Magento orders for Grouped Products listed as Set [#1218] +Amazon: [Fixed] Internal Server Error(s) [Marketplace ID is not valid. It differs from the current.] occurs when trying to update the MWS token [#1215] +Amazon: [Improved] Self-upload of Amazon invoices without receiving and checking the results of the GetFeedSubmissionResult command [#2939] * 6.14.1 (r16362) (14/07/2021) -[Common] [Improved] Display shipping service in the beginning of the line in Magento Orders [M1-1354] -[Ebay] [Fixed] Magento Order was not created. Reason: Notice: Undefined index: delivery_date [M1-1361] -[Amazon] [Improved] Import IOSS for Amazon Orders [M1-1356] - -[Common] [Added] Add Ship By Date filter to Orders grid [M1-1282] -[Common] [Added] Display Ship By Date in Channel Orders [M1-1105] -[Common] [Added] Pass Ship By Date value to Magento Orders [M1-1286] -[Common] [Fixed] Exception after clicking the Ship button on the Magento Order View page if the order is created not via M2E Pro [M1-1313] -[Common] [Fixed] Syntax error or access violation: 1118 Row size too large. The maximum row size for the used table type, not counting BLOBs at the step of extension upgrade [M1-1126] -[Common] [Improved] Channel Orders grid and viewing Orders [M1-1073] -[Common] [Improved] Detect End Date expiration for Special Price and submit Product Price value during the Revise action [M1-1118] -[Common] [Improved] "Map" renamed to "Link" across the Unmanaged Listings functionality [M1-1083] -[Common] [Improved] Notification about the non-created Magento Orders appears only when actual errors are detected [M1-1204] -[eBay] [Fixed] Default set of Item Specifics is displayed as Custom after moving Products from Unmanaged Listings to M2E Pro Listings [M1-1294] -[eBay] [Fixed] MPN is submitted as variation specific when listing Variational Products [M1-1104] -[eBay] [Improved] Display IOSS/OSS number in Channel and Magento Orders [M1-1297] -[eBay] [Improved] Filter Products in Listings by Policy title [M1-1132] -[eBay] [Improved] Resend newly required specifics during the Relist or Revise actions after the error is received [M1-1238] -[eBay] [Improved] Sort products via the "Available QTY" filter in the Listing grid [M1-1058] -[eBay] [Improved] Variational Product data is updated automatically if the data is changed on eBay [M1-1211] -[Amazon] [Fixed] Column already exists: 1060 Duplicate column name 'is_repricing' error when trying to filter items on Repricing in Listing [M1-1288] -[Amazon] [Improved] Filter Products in Listings by Policy title [M1-1132] -[Walmart] [Fixed] "The Item was not listed due to the unexpected error on Walmart side" received instead of the actual error [M1-1169] +Common: [Improved] Display shipping service in the beginning of the line in Magento Orders [M1-1354] +Ebay: [Fixed] Magento Order was not created. Reason: Notice: Undefined index: delivery_date [M1-1361] +Amazon: [Improved] Import IOSS for Amazon Orders [M1-1356] + +Common: [Added] Add Ship By Date filter to Orders grid [M1-1282] +Common: [Added] Display Ship By Date in Channel Orders [M1-1105] +Common: [Added] Pass Ship By Date value to Magento Orders [M1-1286] +Common: [Fixed] Exception after clicking the Ship button on the Magento Order View page if the order is created not via M2E Pro [M1-1313] +Common: [Fixed] Syntax error or access violation: 1118 Row size too large. The maximum row size for the used table type, not counting BLOBs at the step of extension upgrade [M1-1126] +Common: [Improved] Channel Orders grid and viewing Orders [M1-1073] +Common: [Improved] Detect End Date expiration for Special Price and submit Product Price value during the Revise action [M1-1118] +Common: [Improved] "Map" renamed to "Link" across the Unmanaged Listings functionality [M1-1083] +Common: [Improved] Notification about the non-created Magento Orders appears only when actual errors are detected [M1-1204] +eBay: [Fixed] Default set of Item Specifics is displayed as Custom after moving Products from Unmanaged Listings to M2E Pro Listings [M1-1294] +eBay: [Fixed] MPN is submitted as variation specific when listing Variational Products [M1-1104] +eBay: [Improved] Display IOSS/OSS number in Channel and Magento Orders [M1-1297] +eBay: [Improved] Filter Products in Listings by Policy title [M1-1132] +eBay: [Improved] Resend newly required specifics during the Relist or Revise actions after the error is received [M1-1238] +eBay: [Improved] Sort products via the "Available QTY" filter in the Listing grid [M1-1058] +eBay: [Improved] Variational Product data is updated automatically if the data is changed on eBay [M1-1211] +Amazon: [Fixed] Column already exists: 1060 Duplicate column name 'is_repricing' error when trying to filter items on Repricing in Listing [M1-1288] +Amazon: [Improved] Filter Products in Listings by Policy title [M1-1132] +Walmart: [Fixed] "The Item was not listed due to the unexpected error on Walmart side" received instead of the actual error [M1-1169] * 6.13.2 (r16286) (08/06/2021) diff --git a/app/code/community/Ess/M2ePro/Helper/Component/Ebay.php b/app/code/community/Ess/M2ePro/Helper/Component/Ebay.php index 845a17507..2c9eadd4c 100644 --- a/app/code/community/Ess/M2ePro/Helper/Component/Ebay.php +++ b/app/code/community/Ess/M2ePro/Helper/Component/Ebay.php @@ -17,10 +17,12 @@ class Ess_M2ePro_Helper_Component_Ebay extends Mage_Core_Helper_Abstract const MARKETPLACE_UK = 3; const MARKETPLACE_AU = 4; const MARKETPLACE_BE_FR = 6; + const MARKETPLACE_FR = 7; const MARKETPLACE_DE = 8; const MARKETPLACE_MOTORS = 9; const MARKETPLACE_IT = 10; const MARKETPLACE_BE_NL = 11; + const MARKETPLACE_ES = 13; const LISTING_DURATION_GTC = 100; diff --git a/app/code/community/Ess/M2ePro/Helper/Component/Ebay/Motors.php b/app/code/community/Ess/M2ePro/Helper/Component/Ebay/Motors.php index 34b9e7b78..6fb4931a5 100644 --- a/app/code/community/Ess/M2ePro/Helper/Component/Ebay/Motors.php +++ b/app/code/community/Ess/M2ePro/Helper/Component/Ebay/Motors.php @@ -329,7 +329,8 @@ public function getDictionaryRecordCount($type) /** * @return bool */ - public function isKTypeMarketplacesEnabled() { + public function isKTypeMarketplacesEnabled() + { /** @var Ess_M2ePro_Model_Resource_Marketplace_Collection $marketplaceCollection */ $marketplaceCollection = Mage::helper('M2ePro/Component_Ebay')->getCollection('Marketplace'); @@ -340,4 +341,115 @@ public function isKTypeMarketplacesEnabled() { } //######################################## + + public function getGroupsAssociatedWithFilter($filterId) + { + $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); + $table = Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); + + $select = $connRead->select(); + $select->from(array('emftg' => $table), array('group_id')) + ->where('filter_id = ?', $filterId); + + return Mage::getResourceModel('core/config')->getReadConnection()->fetchCol($select); + } + + /** + * @return array + * @throws Ess_M2ePro_Model_Exception_Logic + */ + public function getAssociatedProducts($objectId, $objectType) + { + if ($objectType !== 'GROUP' && $objectType !== 'FILTER') { + throw new Ess_M2ePro_Model_Exception_Logic("Incorrect object type: $objectType"); + } + + $attributesIds = $this->getPartsCompatibilityAttributesIds(); + if (empty($attributesIds)) { + return array(); + } + + /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */ + $collection = Mage::getResourceModel('catalog/product_collection'); + + $sqlTemplateLike = "%\"$objectType\"|\"$objectId\"%"; + + $attributesIdsTemplate = implode(',', $attributesIds); + $collection->getSelect()->joinInner( + array( + 'pet' => Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('catalog_product_entity_text') + ), + '(`pet`.`entity_id` = `e`.`entity_id` AND pet.attribute_id IN(' . $attributesIdsTemplate . ') + AND value LIKE \'' . $sqlTemplateLike . '\')', + array('value' => 'pet.value') + ); + $collection->getSelect()->where('value IS NOT NULL'); + + $collection->getSelect()->joinInner( + array( + 'lp' => Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('M2ePro/Listing_Product') + ), + '(`lp`.`product_id` = `e`.`entity_id` AND `lp`.`component_mode` = "' . + Ess_M2ePro_Helper_Component_Ebay::NICK . '")', + array('listing_product_id' => 'lp.id') + ); + + $data = $collection->getData(); + $listingProductIds = array(); + foreach ($data as $product) { + $listingProductIds[] = $product['listing_product_id']; + } + + return array_unique($listingProductIds); + } + + public function resetOnlinePartsData($listingProductIds) + { + if (empty($listingProductIds)) { + return; + } + + /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */ + $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); + + $ebayListingProductTable = Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('m2epro_ebay_listing_product'); + + $connWrite->update( + $ebayListingProductTable, + array('online_parts_data' => ''), + array('listing_product_id IN(?)' => $listingProductIds) + ); + } + + public function getPartsCompatibilityAttributesIds() + { + $result = array(); + $keys = array( + 'motors_epids_attribute', + 'uk_epids_attribute', + 'de_epids_attribute', + 'au_epids_attribute', + 'ktypes_attribute' + ); + + /** @var Ess_M2ePro_Model_Config_Manager $config */ + $config = Mage::helper('M2ePro/Module')->getConfig(); + + foreach ($keys as $attributeConfigKey) { + $motorsEpidAttribute = $config->getGroupValue('/ebay/configuration/', $attributeConfigKey); + $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $motorsEpidAttribute); + + if ($attributeId = $attribute->getId()) { + $result[] = $attributeId; + } + } + + return $result; + } + + //######################################## } diff --git a/app/code/community/Ess/M2ePro/Helper/Order/Notification.php b/app/code/community/Ess/M2ePro/Helper/Order/Notification.php index 172a443c6..ef63a8afb 100644 --- a/app/code/community/Ess/M2ePro/Helper/Order/Notification.php +++ b/app/code/community/Ess/M2ePro/Helper/Order/Notification.php @@ -23,21 +23,7 @@ class Ess_M2ePro_Helper_Order_Notification extends Mage_Core_Helper_Abstract public function buildMessage() { - Mage::getSingleton('core/layout')->getBlock('head')->addJs( - 'M2ePro/Order/LogNotification.js' - ); - - $orderNotCreatedDate= explode(' ', $this->_collectionOrderLogs->getFirstItem()->getData('create_date')); - $message = << - if (typeof LogNotificationObj == 'undefined') { - LogNotificationObj = new LogNotification(); - } - - - Since {$orderNotCreatedDate[0]}, some Magento orders have not been created: - {$this->_collectionOrderLogs->getSize()}, check your -HTML; + Mage::getSingleton('core/layout')->getBlock('head')->addJs('M2ePro/Order/LogNotification.js'); $hasAmazonLog = false; $hasEbayLog = false; $hasWalmartLog = false; @@ -52,9 +38,35 @@ public function buildMessage() } } + + /** @var Ess_M2ePro_Model_Order_Log $orderLogFirst */ + $orderLogFirst = $this->_collectionOrderLogs->getFirstItem(); + /** @var Ess_M2ePro_Model_Order_Log $orderLogLast */ + $orderLogLast = $this->_collectionOrderLogs->getLastItem(); + + $orderNotCreatedDate = Mage::helper('core')->formatDate( + $orderLogFirst->getData('create_date'), Mage_Core_Model_Locale::FORMAT_TYPE_LONG + ); + $this->_collectionOrderLogs->clear(); + $count = $this->_collectionOrderLogs->addFieldToSelect('order_id')->distinct(true)->count(); + + $message = << + if (typeof LogNotificationObj == 'undefined') { + LogNotificationObj = new LogNotification(); + } + + + Since {$orderNotCreatedDate}, some Magento orders have not been created: {$count}, check your +HTML; + $filter = base64_encode( - 'order_create_date[from]=' . $this->getFormatDate($orderNotCreatedDate[0]) . '&' . + 'order_create_date[from]=' . + Mage::helper('core')->formatDate( + Mage::app()->getLocale()->storeDate(null, $orderLogFirst->getData('create_date')) + ) . '&' . 'description=Magento Order was not created&' . + 'magento_order_number=N/A&' . 'initiator=' . Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION ); @@ -65,15 +77,26 @@ public function buildMessage() if ($hasAmazonLog) { $url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_amazon_log/order', array('filter' => $filter)); - $message .= ' / Amazon orders logs'; + if ($hasEbayLog) { + $message .= ' / '; + } + + $message .= ' Amazon orders logs'; } if ($hasWalmartLog) { $url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_walmart_log/order', array('filter' => $filter)); - $message .= ' / Walmart orders logs'; + if ($hasEbayLog || $hasAmazonLog) { + $message .= ' / '; + } + + $message .= 'Walmart orders logs'; } - $url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_order/skipLogNotificationToCurrentDate'); + $url = Mage::helper('adminhtml')->getUrl( + 'M2ePro/adminhtml_order/skipLogNotificationToCurrentDate', + array('last_order_create_date' => $orderLogLast->getData('create_date')) + ); $message .= <<Skip this message. @@ -82,37 +105,6 @@ public function buildMessage() return $message; } - protected function getFormatDate($orderNotCreatedDate) - { - list($yyyy, $m, $d) = explode('-', $orderNotCreatedDate); - - $format = Zend_Locale_Data::getContent( - Mage::app()->getLocale()->getLocaleCode(), - 'date', - array('gregorian', 'short') - ); - - $datePosition = array(); - foreach (array('m', 'd', 'y') as $value) { - $datePosition[stripos($format, $value)] = $value; - } - - ksort($datePosition); - - $newDateFormat = ''; - foreach ($datePosition as $value) { - if ($value == 'd') { - $newDateFormat .= $d . '/'; - } elseif ($value == 'm') { - $newDateFormat .= $m . '/'; - } else { - $newDateFormat .= $yyyy . '/'; - } - }; - - return rtrim($newDateFormat, '/'); - } - //######################################## public function showNotification() diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/DataBuilder/Details.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/DataBuilder/Details.php index 34498d1a8..2338ea867 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/DataBuilder/Details.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/DataBuilder/Details.php @@ -289,7 +289,8 @@ protected function getProductData() foreach ($this->getDescriptionTemplate()->getSpecifics(true) as $specific) { $source = $specific->getSource($this->getAmazonListingProduct()->getActualMagentoProduct()); - if (!$specific->isRequired() && !$specific->isModeNone() && !$source->getValue()) { + if (!$specific->isRequired() && !$specific->isModeNone() + && ($source->getValue() === null || $source->getValue() === '' || $source->getValue() === array())) { continue; } diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Repricing.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Repricing.php index 7ed2269ae..9e7cba877 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Repricing.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Repricing.php @@ -364,7 +364,8 @@ public function isDisabled() if ($source['mode'] == Ess_M2ePro_Model_Amazon_Account_Repricing::DISABLE_MODE_ATTRIBUTE) { return filter_var( - $this->getActualMagentoProduct()->getAttributeValue($source['attribute']), FILTER_VALIDATE_BOOLEAN + $this->getActualMagentoProduct()->getAttributeValue($source['attribute'], false), + FILTER_VALIDATE_BOOLEAN ); } diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Source.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Source.php index ffa24ce30..39eb351fa 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Source.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Source.php @@ -380,7 +380,7 @@ public function getGiftWrap() } if ($this->getAmazonListing()->isGiftWrapModeAttribute()) { - $attributeValue = $this->getMagentoProduct()->getAttributeValue($src['attribute']); + $attributeValue = $this->getMagentoProduct()->getAttributeValue($src['attribute'], false); if ($attributeValue == Mage::helper('M2ePro')->__('Yes')) { $result = true; @@ -411,7 +411,7 @@ public function getGiftMessage() } if ($this->getAmazonListing()->isGiftMessageModeAttribute()) { - $attributeValue = $this->getMagentoProduct()->getAttributeValue($src['attribute']); + $attributeValue = $this->getMagentoProduct()->getAttributeValue($src['attribute'], false); if ($attributeValue == Mage::helper('M2ePro')->__('Yes')) { $result = true; diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Definition/Source.php b/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Definition/Source.php index e4f23d0d4..76ddc317c 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Definition/Source.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Definition/Source.php @@ -376,7 +376,7 @@ public function getItemDimensionsVolumeUnitOfMeasure() $unitOfMeasure = $src['custom_value']; if ($this->getDescriptionDefinitionTemplate()->isItemDimensionsVolumeUnitOfMeasureModeCustomAttribute()) { - $unitOfMeasure = trim($this->getMagentoProduct()->getAttributeValue($src['custom_attribute'])); + $unitOfMeasure = trim($this->getMagentoProduct()->getAttributeValue($src['custom_attribute'], false)); } return $unitOfMeasure; @@ -684,7 +684,7 @@ public function getVariationDifferenceImages() protected function getMagentoProductAttributeValue($attributeCode, $store) { if ($store === null) { - return $this->getMagentoProduct()->getAttributeValue($attributeCode); + return $this->getMagentoProduct()->getAttributeValue($attributeCode, false); } $currency = $this->getDescriptionDefinitionTemplate() @@ -702,4 +702,4 @@ protected function getMagentoProductAttributeValue($attributeCode, $store) } //######################################## -} \ No newline at end of file +} diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific.php b/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific.php index b8f269837..27efcb840 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific.php @@ -20,6 +20,7 @@ class Ess_M2ePro_Model_Amazon_Template_Description_Specific extends Ess_M2ePro_M const TYPE_INT = 'int'; const TYPE_FLOAT = 'float'; const TYPE_DATETIME = 'date_time'; + const TYPE_BOOLEAN = 'boolean'; /** * @var Ess_M2ePro_Model_Template_Description @@ -80,7 +81,7 @@ public function setDescriptionTemplate(Ess_M2ePro_Model_Template_Description $in */ public function getAmazonDescriptionTemplate() { - $this->getDescriptionTemplate()->getChildObject(); + return $this->getDescriptionTemplate()->getChildObject(); } //######################################## @@ -209,5 +210,20 @@ public function isTypeDateTime() return $this->getType() == self::TYPE_DATETIME; } + public function isTypeBoolean() + { + $value = $this->getData($this->getMode()); + + if ($this->getType() == self::TYPE_BOOLEAN || is_bool($value)) { + return true; + } + + if (is_string($value) && in_array($value, array('true', 'false'), true)) { + return true; + } + + return false; + } + //######################################## -} \ No newline at end of file +} diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific/Source.php b/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific/Source.php index 1563badb4..420c94bc9 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific/Source.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Template/Description/Specific/Source.php @@ -118,12 +118,13 @@ public function getValue() $value = $templateObj->getData($templateObj->getMode()); if ($templateObj->isModeCustomAttribute()) { - $value = $this->getMagentoProduct()->getAttributeValue($value); + $value = $this->getMagentoProduct()->getAttributeValue($value, false); } $templateObj->isTypeInt() && $value = (int)$value; $templateObj->isTypeFloat() && $value = (float)str_replace(',', '.', $value); $templateObj->isTypeDateTime() && $value = str_replace(' ', 'T', $value); + $templateObj->isTypeBoolean() && $value = $this->convertValueToBoolean($value); return $value; } @@ -141,7 +142,7 @@ public function getValueAttributes() $attributeValue = $attributeData['mode'] == DescriptionSpecific::DICTIONARY_MODE_CUSTOM_VALUE ? $attributeData['custom_value'] - : $this->getMagentoProduct()->getAttributeValue($attributeData['custom_attribute']); + : $this->getMagentoProduct()->getAttributeValue($attributeData['custom_attribute'], false); $attributes[$index] = array( 'name' => str_replace(' ', '', $attributeName), @@ -153,4 +154,17 @@ public function getValueAttributes() } //######################################## -} \ No newline at end of file + + private function convertValueToBoolean($value) + { + if ($value === true) { + $value = 'true'; + } elseif ($value === false) { + $value = 'false'; + } + + return $value; + } + + //######################################## +} diff --git a/app/code/community/Ess/M2ePro/Model/ControlPanel/Inspection/Manager.php b/app/code/community/Ess/M2ePro/Model/ControlPanel/Inspection/Manager.php index 597c18ec0..efb684648 100644 --- a/app/code/community/Ess/M2ePro/Model/ControlPanel/Inspection/Manager.php +++ b/app/code/community/Ess/M2ePro/Model/ControlPanel/Inspection/Manager.php @@ -34,7 +34,7 @@ public function __construct() protected function initInspections($dirName) { - $directoryIterator = new DirectoryIterator(__DIR__ .DS. $dirName); + $directoryIterator = new DirectoryIterator(__DIR__ . DS . $dirName); foreach ($directoryIterator as $item) { if ($item->isDot()) { continue; @@ -56,6 +56,15 @@ protected function initInspections($dirName) } } + public function runInspection($name) + { + /** @var Ess_M2ePro_Model_ControlPanel_Inspection_AbstractInspection $model */ + $modelName = "M2ePro/ControlPanel_Inspection_Inspector_" . $name; + $model = Mage::getModel($modelName); + + return $model->getResults(); + } + //######################################## /** @@ -120,8 +129,10 @@ public function getInspection($className) public function getId(Ess_M2ePro_Model_ControlPanel_Inspection_AbstractInspection $inspection) { - return get_class($inspection); + $fullName = explode('_', get_class($inspection)); + + return end($fullName); } //######################################## -} \ No newline at end of file +} diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php index 2ef752291..f39a37c64 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Product/ProcessScheduledActions.php @@ -21,6 +21,7 @@ class Ess_M2ePro_Model_Cron_Task_Ebay_Listing_Product_ProcessScheduledActions const REVISE_DESCRIPTION_PRIORITY = 50; const REVISE_IMAGES_PRIORITY = 50; const REVISE_CATEGORIES_PRIORITY = 50; + const REVISE_PARTS_PRIORITY = 50; const REVISE_PAYMENT_PRIORITY = 50; const REVISE_SHIPPING_PRIORITY = 50; const REVISE_RETURN_PRIORITY = 50; @@ -154,6 +155,7 @@ protected function getScheduledActionsForProcessing($limit) $this->getReviseDescriptionScheduledActionsPreparedCollection()->getSelect(), $this->getReviseImagesScheduledActionsPreparedCollection()->getSelect(), $this->getReviseCategoriesScheduledActionsPreparedCollection()->getSelect(), + $this->getRevisePartsScheduledActionsPreparedCollection()->getSelect(), $this->getRevisePaymentScheduledActionsPreparedCollection()->getSelect(), $this->getReviseShippingScheduledActionsPreparedCollection()->getSelect(), $this->getReviseReturnScheduledActionsPreparedCollection()->getSelect(), @@ -337,6 +339,23 @@ protected function getReviseCategoriesScheduledActionsPreparedCollection() ->addTagFilter('categories'); } + /** + * @return Ess_M2ePro_Model_Resource_Listing_Product_ScheduledAction_Collection + * @throws Ess_M2ePro_Model_Exception_Logic + */ + protected function getRevisePartsScheduledActionsPreparedCollection() + { + /** @var Ess_M2ePro_Model_Resource_Listing_Product_ScheduledAction_Collection $collection */ + $collection = Mage::getResourceModel('M2ePro/Listing_Product_ScheduledAction_Collection'); + + return $collection->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK) + ->getScheduledActionsPreparedCollection( + self::REVISE_PARTS_PRIORITY, + Ess_M2ePro_Model_Listing_Product::ACTION_REVISE + ) + ->addTagFilter('parts'); + } + /** * @return Ess_M2ePro_Model_Resource_Listing_Product_ScheduledAction_Collection * @throws Ess_M2ePro_Model_Exception_Logic diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Revise/Responser.php b/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Revise/Responser.php index cc1bfb6f5..1711344d4 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Revise/Responser.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Revise/Responser.php @@ -45,6 +45,11 @@ protected function getSuccessfulMessage() $isPlural = true; } + if ($this->getConfigurator()->isPartsAllowed()) { + $sequenceStrings[] = 'eBay Parts Compatibility'; + $isPlural = true; + } + if ($this->getConfigurator()->isPaymentAllowed()) { $sequenceStrings[] = 'Payment'; } @@ -260,4 +265,4 @@ public function eventAfterExecuting() } //######################################## -} \ No newline at end of file +} diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Configurator.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Configurator.php index a45b05c82..88caa8c80 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Configurator.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Configurator.php @@ -17,6 +17,7 @@ class Ess_M2ePro_Model_Ebay_Listing_Product_Action_Configurator const DATA_TYPE_DESCRIPTION = 'description'; const DATA_TYPE_IMAGES = 'images'; const DATA_TYPE_CATEGORIES = 'categories'; + const DATA_TYPE_PARTS = 'parts'; const DATA_TYPE_SHIPPING = 'shipping'; const DATA_TYPE_PAYMENT = 'payment'; const DATA_TYPE_RETURN = 'return'; @@ -39,6 +40,7 @@ public function getAllDataTypes() self::DATA_TYPE_DESCRIPTION, self::DATA_TYPE_IMAGES, self::DATA_TYPE_CATEGORIES, + self::DATA_TYPE_PARTS, self::DATA_TYPE_SHIPPING, self::DATA_TYPE_PAYMENT, self::DATA_TYPE_RETURN, @@ -257,6 +259,32 @@ public function disallowCategories() // --------------------------------------- + /** + * @return bool + */ + public function isPartsAllowed() + { + return $this->isAllowed(self::DATA_TYPE_PARTS); + } + + /** + * @return $this + */ + public function allowParts() + { + return $this->allow(self::DATA_TYPE_PARTS); + } + + /** + * @return $this + */ + public function disallowParts() + { + return $this->disallow(self::DATA_TYPE_PARTS); + } + + // --------------------------------------- + /** * @return bool */ diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Categories.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Categories.php index b4e499a85..6b817d9fb 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Categories.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Categories.php @@ -39,20 +39,6 @@ public function getData() $data = $this->getCategoriesData(); $data['item_specifics'] = $this->getItemSpecificsData(); - if ($this->getEbayListing()->isPartsCompatibilityModeEpids()) { - $motorsType = Mage::helper('M2ePro/Component_Ebay_Motors')->getEpidsTypeByMarketplace( - $this->getMarketplace()->getId() - ); - $tempData = $this->getMotorsData($motorsType); - $tempData !== false && $data['motors_epids'] = $tempData; - } - - if ($this->getEbayListing()->isPartsCompatibilityModeKtypes()) { - $motorsType = Ess_M2ePro_Helper_Component_Ebay_Motors::TYPE_KTYPE; - $tempData = $this->getMotorsData($motorsType); - $tempData !== false && $data['motors_ktypes'] = $tempData; - } - return $data; } @@ -99,9 +85,9 @@ public function getItemSpecificsData() $this->searchNotFoundAttributes(); $tempAttributeLabel = $specific->getSource($this->getMagentoProduct()) - ->getLabel(); + ->getLabel(); $tempAttributeValues = $specific->getSource($this->getMagentoProduct()) - ->getValues(); + ->getValues(); if (!$this->processNotFoundAttributes('Specifics')) { continue; @@ -125,492 +111,6 @@ public function getItemSpecificsData() return $data; } - public function getMotorsData($type) - { - $attribute = $this->getMotorsAttribute($type); - - if (empty($attribute)) { - return false; - } - - $this->searchNotFoundAttributes(); - - $rawData = $this->getRawMotorsData($type); - - if (!$this->processNotFoundAttributes('Compatibility')) { - return false; - } - - if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { - return $this->getPreparedMotorsEpidsData($rawData); - } - - if ($this->getMotorsHelper()->isTypeBasedOnKtypes($type)) { - return $this->getPreparedMotorsKtypesData($rawData); - } - - return null; - } - - //######################################## - - protected function getRawMotorsData($type) - { - $attributeValue = $this->getMagentoProduct()->getAttributeValue($this->getMotorsAttribute($type)); - - if (empty($attributeValue)) { - return array(); - } - - $motorsData = $this->getMotorsHelper()->parseAttributeValue($attributeValue); - - $motorsData = array_merge( - $this->prepareRawMotorsItems($motorsData['items'], $type), - $this->prepareRawMotorsFilters($motorsData['filters'], $type), - $this->prepareRawMotorsGroups($motorsData['groups'], $type) - ); - - return $this->filterDuplicatedData($motorsData, $type); - } - - protected function filterDuplicatedData($motorsData, $type) - { - $uniqueItems = array(); - $uniqueFilters = array(); - $uniqueFiltersInfo = array(); - - $itemType = $this->getMotorsHelper()->getIdentifierKey($type); - - foreach ($motorsData as $item) { - if ($item['type'] === $itemType) { - $uniqueItems[$item['id']] = $item; - continue; - } - - if (!in_array($item['info'], $uniqueFiltersInfo)) { - $uniqueFilters[] = $item; - $uniqueFiltersInfo[] = $item['info']; - } - } - - return array_merge( - $uniqueItems, - $uniqueFilters - ); - } - // --------------------------------------- - - protected function prepareRawMotorsItems($data, $type) - { - if (empty($data)) { - return array(); - } - - $typeIdentifier = $this->getMotorsHelper()->getIdentifierKey($type); - $select = Mage::getResourceModel('core/config')->getReadConnection() - ->select() - ->from($this->getMotorsHelper()->getDictionaryTable($type)) - ->where( - '`'.$typeIdentifier.'` IN (?)', - array_keys($data) - ); - - if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { - $select->where('scope = ?', $this->getMotorsHelper()->getEpidsScopeByType($type)); - } - - $queryStmt = $select->query(); - - $existedItems = array(); - while ($row = $queryStmt->fetch()) { - $existedItems[$row[$typeIdentifier]] = $row; - } - - foreach ($data as $typeId => $dataItem) { - $data[$typeId]['type'] = $typeIdentifier; - $data[$typeId]['info'] = isset($existedItems[$typeId]) ? $existedItems[$typeId] : array(); - } - - return $data; - } - - protected function prepareRawMotorsFilters($data, $type) - { - if (empty($data)) { - return array(); - } - - $result = array(); - $typeIdentifier = $this->getMotorsHelper()->getIdentifierKey($type); - - foreach ($data as $filterId) { - - /** @var Ess_M2ePro_Model_Ebay_Motor_Filter $filter */ - $filter = Mage::getModel('M2ePro/Ebay_Motor_Filter')->load($filterId); - - if ($filter->getType() != $type) { - continue; - } - - $conditions = $filter->getConditions(); - - $select = Mage::getResourceModel('core/config')->getReadConnection() - ->select() - ->from($this->getMotorsHelper()->getDictionaryTable($type)); - - if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { - $select->where('scope = ?', $this->getMotorsHelper()->getEpidsScopeByType($type)); - } - - foreach ($conditions as $key => $value) { - if ($key != 'year') { - $select->where('`'.$key.'` LIKE ?', '%'.$value.'%'); - continue; - } - - if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { - if (!empty($value['from'])) { - $select->where('`year` >= ?', $value['from']); - } - - if (!empty($value['to'])) { - $select->where('`year` <= ?', $value['to']); - } - } else { - $select->where('from_year <= ?', $value); - $select->where('to_year >= ?', $value); - } - } - - $filterData = $select->query()->fetchAll(); - - if (empty($filterData)) { - $result[] = array( - 'id' => $filterId, - 'type' => 'filter', - 'note' => $filter->getNote(), - 'info' => array() - ); - continue; - } - - if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { - if ($type == Ess_M2ePro_Helper_Component_Ebay_Motors::TYPE_EPID_MOTOR) { - $filterData = $this->groupEbayMotorsEpidsData($filterData, $conditions); - } - - foreach ($filterData as $group) { - $result[] = array( - 'id' => $filterId, - 'type' => 'filter', - 'note' => $filter->getNote(), - 'info' => $group - ); - } - - continue; - } - - foreach ($filterData as $item) { - $result[] = array( - 'id' => $item[$typeIdentifier], - 'type' => $typeIdentifier, - 'note' => $filter->getNote(), - 'info' => $item - ); - } - } - - return $result; - } - - protected function prepareRawMotorsGroups($data, $type) - { - if (empty($data)) { - return array(); - } - - $result = array(); - - foreach ($data as $groupId) { - - /** @var Ess_M2ePro_Model_Ebay_Motor_Group $group */ - $group = Mage::getModel('M2ePro/Ebay_Motor_Group')->load($groupId); - - if ($group->getType() != $type) { - continue; - } - - if (!$group->getId()) { - $result[] = array( - 'id' => $groupId, - 'type' => 'group', - 'note' => $group->getNote(), - 'info' => array() - ); - continue; - } - - if ($group->isModeItem()) { - $items = $this->prepareRawMotorsItems($group->getItems(), $type); - } else { - $items = $this->prepareRawMotorsFilters($group->getFiltersIds(), $type); - } - - $result = array_merge($result, $items); - } - - return $result; - } - - //######################################## - - protected function getPreparedMotorsEpidsData($data) - { - $ebayAttributes = $this->getEbayMotorsEpidsAttributes(); - - $preparedData = array(); - $emptySavedItems = array(); - - foreach ($data as $item) { - if (empty($item['info'])) { - $emptySavedItems[$item['type']][] = $item; - continue; - } - - $motorsList = array(); - $motorsData = $this->buildEpidData($item['info']); - - foreach ($motorsData as $key => $value) { - if ($value == '--') { - unset($motorsData[$key]); - continue; - } - - $name = $key; - - foreach ($ebayAttributes as $ebayAttribute) { - if ($ebayAttribute['title'] == $key) { - $name = $ebayAttribute['ebay_id']; - break; - } - } - - $motorsList[] = array( - 'name' => $name, - 'value' => $value - ); - } - - $preparedData[] = array( - 'epid' => isset($item['info']['epid']) ? $item['info']['epid'] : null, - 'list' => $motorsList, - 'note' => $item['note'], - ); - } - - if (!empty($emptySavedItems['epid'])) { - $tempItems = array(); - foreach ($emptySavedItems['epid'] as $tempItem) { - $tempItems[] = $tempItem['id']; - } - - $msg = Mage::helper('M2ePro')->__( - ' - Some ePID(s) which were saved in Parts Compatibility Magento Attribute - have been removed. Their Values were ignored and not sent on eBay', - implode(', ', $tempItems) - ); - $this->addWarningMessage($msg); - } - - if (!empty($emptySavedItems['filter'])) { - $tempItems = array(); - foreach ($emptySavedItems['filter'] as $tempItem) { - $tempItems[] = $tempItem['id']; - } - - $msg = Mage::helper('M2ePro')->__( - ' - Some ePID(s) Grid Filter(s) was removed, that is why its Settings were - ignored and can not be applied', - implode(', ', $tempItems) - ); - $this->addWarningMessage($msg); - } - - if (!empty($emptySavedItems['group'])) { - $tempItems = array(); - foreach ($emptySavedItems['group'] as $tempItem) { - $tempItems[] = $tempItem['id']; - } - - $msg = Mage::helper('M2ePro')->__( - ' - Some ePID(s) Group(s) was removed, that is why its Settings were - ignored and can not be applied', - implode(', ', $tempItems) - ); - $this->addWarningMessage($msg); - } - - return $preparedData; - } - - protected function getPreparedMotorsKtypesData($data) - { - $preparedData = array(); - $emptySavedItems = array(); - - foreach ($data as $item) { - if (empty($item['info'])) { - $emptySavedItems[$item['type']][] = $item; - continue; - } - - $preparedData[] = array( - 'ktype' => $item['id'], - 'note' => $item['note'], - ); - } - - if (!empty($emptySavedItems['ktype'])) { - $tempItems = array(); - foreach ($emptySavedItems['ktype'] as $tempItem) { - $tempItems[] = $tempItem['id']; - } - - $msg = Mage::helper('M2ePro')->__( - ' - Some kTypes(s) which were saved in Parts Compatibility Magento Attribute - have been removed. Their Values were ignored and not sent on eBay', - implode(', ', $tempItems) - ); - $this->addWarningMessage($msg); - } - - if (!empty($emptySavedItems['filter'])) { - $tempItems = array(); - foreach ($emptySavedItems['filter'] as $tempItem) { - $tempItems[] = $tempItem['id']; - } - - $msg = Mage::helper('M2ePro')->__( - ' - Some kTypes(s) Grid Filter(s) was removed, that is why its Settings - were ignored and can not be applied', - implode(', ', $tempItems) - ); - $this->addWarningMessage($msg); - } - - if (!empty($emptySavedItems['group'])) { - $tempItems = array(); - foreach ($emptySavedItems['group'] as $tempItem) { - $tempItems[] = $tempItem['id']; - } - - $msg = Mage::helper('M2ePro')->__( - ' - Some kTypes(s) Group(s) was removed, that is why its Settings were - ignored and can not be applied', - implode(', ', $tempItems) - ); - $this->addWarningMessage($msg); - } - - return $preparedData; - } - - // --------------------------------------- - - protected function groupEbayMotorsEpidsData($data, $condition) - { - $groupingFields = array_unique( - array_merge( - array('year', 'make', 'model'), - array_keys($condition) - ) - ); - - $groups = array(); - foreach ($data as $item) { - if (empty($groups)) { - $group = array(); - foreach ($groupingFields as $groupingField) { - $group[$groupingField] = $item[$groupingField]; - } - - ksort($group); - - $groups[] = $group; - continue; - } - - $newGroup = array(); - foreach ($groupingFields as $groupingField) { - $newGroup[$groupingField] = $item[$groupingField]; - } - - ksort($newGroup); - - if (!in_array($newGroup, $groups)) { - $groups[] = $newGroup; - } - } - - return $groups; - } - - protected function buildEpidData($resource) - { - $motorsData = array(); - - if (isset($resource['make'])) { - $motorsData['Make'] = $resource['make']; - } - - if (isset($resource['model'])) { - $motorsData['Model'] = $resource['model']; - } - - if (isset($resource['year'])) { - $motorsData['Year'] = $resource['year']; - } - - if (isset($resource['submodel'])) { - $motorsData['Submodel'] = $resource['submodel']; - } - - if (isset($resource['trim'])) { - $motorsData['Trim'] = $resource['trim']; - } - - if (isset($resource['engine'])) { - $motorsData['Engine'] = $resource['engine']; - } - - if (isset($resource['street_name'])) { - $motorsData['StreetName'] = $resource['street_name']; - } - - return $motorsData; - } - - protected function getEbayMotorsEpidsAttributes() - { - $categoryId = $this->getCategorySource()->getCategoryId(); - $categoryData = $this->getEbayMarketplace()->getCategory($categoryId); - - $features = !empty($categoryData['features']) ? - (array)Mage::helper('M2ePro')->jsonDecode($categoryData['features']) : array(); - - $attributes = !empty($features['parts_compatibility_attributes']) ? - $features['parts_compatibility_attributes'] : array(); - - return $attributes; - } - //######################################## /** @@ -620,7 +120,7 @@ protected function getCategoryTemplate() { if ($this->_categoryTemplate === null) { $this->_categoryTemplate = $this->getListingProduct()->getChildObject() - ->getCategoryTemplate(); + ->getCategoryTemplate(); } return $this->_categoryTemplate; @@ -633,7 +133,7 @@ protected function getCategorySecondaryTemplate() { if ($this->_categorySecondaryTemplate === null) { $this->_categorySecondaryTemplate = $this->getListingProduct()->getChildObject() - ->getCategorySecondaryTemplate(); + ->getCategorySecondaryTemplate(); } return $this->_categorySecondaryTemplate; @@ -646,7 +146,7 @@ protected function getStoreCategoryTemplate() { if ($this->_storeCategoryTemplate === null) { $this->_storeCategoryTemplate = $this->getListingProduct()->getChildObject() - ->getStoreCategoryTemplate(); + ->getStoreCategoryTemplate(); } return $this->_storeCategoryTemplate; @@ -659,7 +159,7 @@ protected function getStoreCategorySecondaryTemplate() { if ($this->_storeCategorySecondaryTemplate === null) { $this->_storeCategorySecondaryTemplate = $this->getListingProduct()->getChildObject() - ->getStoreCategorySecondaryTemplate(); + ->getStoreCategorySecondaryTemplate(); } return $this->_storeCategorySecondaryTemplate; @@ -667,21 +167,6 @@ protected function getStoreCategorySecondaryTemplate() //######################################## - /** - * @return Ess_M2ePro_Helper_Component_Ebay_Motors - */ - protected function getMotorsHelper() - { - return Mage::helper('M2ePro/Component_Ebay_Motors'); - } - - protected function getMotorsAttribute($type) - { - return $this->getMotorsHelper()->getAttribute($type); - } - - //######################################## - /** * @return Ess_M2ePro_Model_Ebay_Template_Category_Source */ diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Parts.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Parts.php new file mode 100644 index 000000000..d3d7069e2 --- /dev/null +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/DataBuilder/Parts.php @@ -0,0 +1,562 @@ +getEbayListing()->isPartsCompatibilityModeEpids()) { + $motorsType = Mage::helper('M2ePro/Component_Ebay_Motors')->getEpidsTypeByMarketplace( + $this->getMarketplace()->getId() + ); + $tempData = $this->getMotorsData($motorsType); + $tempData !== false && $data['motors_epids'] = $tempData; + } + + if ($this->getEbayListing()->isPartsCompatibilityModeKtypes()) { + $motorsType = Ess_M2ePro_Helper_Component_Ebay_Motors::TYPE_KTYPE; + $tempData = $this->getMotorsData($motorsType); + $tempData !== false && $data['motors_ktypes'] = $tempData; + } + + return $data; + } + + /** + * @return string + */ + public function getHash() + { + $attributeValue = ''; + + if ($this->getEbayListing()->isPartsCompatibilityModeEpids()) { + $motorsType = Mage::helper('M2ePro/Component_Ebay_Motors')->getEpidsTypeByMarketplace( + $this->getMarketplace()->getId() + ); + + $attributeValue = $this->getMagentoProduct()->getAttributeValue($this->getMotorsAttribute($motorsType)); + } else if ($this->getEbayListing()->isPartsCompatibilityModeKtypes()) { + $motorsType = Ess_M2ePro_Helper_Component_Ebay_Motors::TYPE_KTYPE; + + $attributeValue = $this->getMagentoProduct()->getAttributeValue($this->getMotorsAttribute($motorsType)); + } + + return $attributeValue ? md5($attributeValue) : null; // @codingStandardsIgnoreLine + } + + public function getMotorsData($type) + { + $attribute = $this->getMotorsAttribute($type); + + if (empty($attribute)) { + return false; + } + + $this->searchNotFoundAttributes(); + + $rawData = $this->getRawMotorsData($type); + + $attributes = $this->getMagentoProduct()->getNotFoundAttributes(); + if (!empty($attributes)) { + return array(); + } + + if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { + return $this->getPreparedMotorsEpidsData($rawData); + } + + if ($this->getMotorsHelper()->isTypeBasedOnKtypes($type)) { + return $this->getPreparedMotorsKtypesData($rawData); + } + + return null; + } + + //######################################## + + protected function getRawMotorsData($type) + { + $attributeValue = $this->getMagentoProduct()->getAttributeValue($this->getMotorsAttribute($type)); + + if (empty($attributeValue)) { + return array(); + } + + $motorsData = $this->getMotorsHelper()->parseAttributeValue($attributeValue); + + $motorsData = array_merge( + $this->prepareRawMotorsItems($motorsData['items'], $type), + $this->prepareRawMotorsFilters($motorsData['filters'], $type), + $this->prepareRawMotorsGroups($motorsData['groups'], $type) + ); + + return $this->filterDuplicatedData($motorsData, $type); + } + + protected function filterDuplicatedData($motorsData, $type) + { + $uniqueItems = array(); + $uniqueFilters = array(); + $uniqueFiltersInfo = array(); + + $itemType = $this->getMotorsHelper()->getIdentifierKey($type); + + foreach ($motorsData as $item) { + if ($item['type'] === $itemType) { + $uniqueItems[$item['id']] = $item; + continue; + } + + if (!in_array($item['info'], $uniqueFiltersInfo)) { + $uniqueFilters[] = $item; + $uniqueFiltersInfo[] = $item['info']; + } + } + + return array_merge( + $uniqueItems, + $uniqueFilters + ); + } + + // --------------------------------------- + + protected function prepareRawMotorsItems($data, $type) + { + if (empty($data)) { + return array(); + } + + $typeIdentifier = $this->getMotorsHelper()->getIdentifierKey($type); + $select = Mage::getResourceModel('core/config')->getReadConnection() + ->select() + ->from($this->getMotorsHelper()->getDictionaryTable($type)) + ->where( + '`' . $typeIdentifier . '` IN (?)', + array_keys($data) + ); + + if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { + $select->where('scope = ?', $this->getMotorsHelper()->getEpidsScopeByType($type)); + } + + $queryStmt = $select->query(); + + $existedItems = array(); + while ($row = $queryStmt->fetch()) { + $existedItems[$row[$typeIdentifier]] = $row; + } + + foreach ($data as $typeId => $dataItem) { + $data[$typeId]['type'] = $typeIdentifier; + $data[$typeId]['info'] = isset($existedItems[$typeId]) ? $existedItems[$typeId] : array(); + } + + return $data; + } + + protected function prepareRawMotorsFilters($filterIds, $type) + { + if (empty($filterIds)) { + return array(); + } + + $result = array(); + $typeIdentifier = $this->getMotorsHelper()->getIdentifierKey($type); + + $motorFilterCollection = Mage::getModel('M2ePro/Ebay_Motor_Filter')->getCollection(); + $motorFilterCollection->addFieldToFilter('id', array('in' => $filterIds)); + + /** @var Ess_M2ePro_Model_Ebay_Motor_Filter $filter */ + foreach ($motorFilterCollection->getItems() as $filter) { + if ($filter->getType() != $type) { + continue; + } + + $conditions = $filter->getConditions(); + + $select = Mage::getResourceModel('core/config')->getReadConnection() + ->select() + ->from($this->getMotorsHelper()->getDictionaryTable($type)); + + if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { + $select->where('scope = ?', $this->getMotorsHelper()->getEpidsScopeByType($type)); + } + + foreach ($conditions as $key => $value) { + if ($key != 'year') { + $select->where('`' . $key . '` LIKE ?', '%' . $value . '%'); + continue; + } + + if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { + if (!empty($value['from'])) { + $select->where('`year` >= ?', $value['from']); + } + + if (!empty($value['to'])) { + $select->where('`year` <= ?', $value['to']); + } + } else { + $select->where('from_year <= ?', $value); + $select->where('to_year >= ?', $value); + } + } + + $filterData = $select->query()->fetchAll(); + + if (empty($filterData)) { + $result[] = array( + 'id' => $filter->getId(), + 'type' => 'filter', + 'note' => $filter->getNote(), + 'info' => array() + ); + continue; + } + + if ($this->getMotorsHelper()->isTypeBasedOnEpids($type)) { + if ($type == Ess_M2ePro_Helper_Component_Ebay_Motors::TYPE_EPID_MOTOR) { + $filterData = $this->groupEbayMotorsEpidsData($filterData, $conditions); + } + + foreach ($filterData as $group) { + $result[] = array( + 'id' => $filter->getId(), + 'type' => 'filter', + 'note' => $filter->getNote(), + 'info' => $group + ); + } + + continue; + } + + foreach ($filterData as $item) { + if (isset($item[$typeIdentifier])) { + $result[] = array( + 'id' => $item[$typeIdentifier], + 'type' => $typeIdentifier, + 'note' => $filter->getNote(), + 'info' => $item + ); + } + } + } + + return $result; + } + + protected function prepareRawMotorsGroups($groupIds, $type) + { + if (empty($groupIds)) { + return array(); + } + + $result = array(); + + $motorGroupCollection = Mage::getModel('M2ePro/Ebay_Motor_Group')->getCollection(); + $motorGroupCollection->addFieldToFilter('id', array('in' => $groupIds)); + + /** @var Ess_M2ePro_Model_Ebay_Motor_Group $group */ + foreach ($motorGroupCollection->getItems() as $group) { + if ($group->getType() != $type) { + continue; + } + + if ($group->isModeItem()) { + $items = $this->prepareRawMotorsItems($group->getItems(), $type); + } else { + $items = $this->prepareRawMotorsFilters($group->getFiltersIds(), $type); + } + + $result = array_merge($result, $items); + } + + return $result; + } + + //######################################## + + protected function getPreparedMotorsEpidsData($data) + { + $ebayAttributes = $this->getEbayMotorsEpidsAttributes(); + + $preparedData = array(); + $emptySavedItems = array(); + + foreach ($data as $item) { + if (empty($item['info'])) { + $emptySavedItems[$item['type']][] = $item; + continue; + } + + $motorsList = array(); + $motorsData = $this->buildEpidData($item['info']); + + foreach ($motorsData as $key => $value) { + if ($value == '--') { + unset($motorsData[$key]); + continue; + } + + $name = $key; + + foreach ($ebayAttributes as $ebayAttribute) { + if ($ebayAttribute['title'] == $key) { + $name = $ebayAttribute['ebay_id']; + break; + } + } + + $motorsList[] = array( + 'name' => $name, + 'value' => $value + ); + } + + $preparedData[] = array( + 'epid' => isset($item['info']['epid']) ? $item['info']['epid'] : null, + 'list' => $motorsList, + 'note' => $item['note'], + ); + } + + if (!empty($emptySavedItems['epid'])) { + $tempItems = array(); + foreach ($emptySavedItems['epid'] as $tempItem) { + $tempItems[] = $tempItem['id']; + } + + $msg = Mage::helper('M2ePro')->__( + ' + Some ePID(s) which were saved in Parts Compatibility Magento Attribute + have been removed. Their Values were ignored and not sent on eBay', + implode(', ', $tempItems) + ); + $this->addWarningMessage($msg); + } + + if (!empty($emptySavedItems['filter'])) { + $tempItems = array(); + foreach ($emptySavedItems['filter'] as $tempItem) { + $tempItems[] = $tempItem['id']; + } + + $msg = Mage::helper('M2ePro')->__( + ' + Some ePID(s) Grid Filter(s) was removed, that is why its Settings were + ignored and can not be applied', + implode(', ', $tempItems) + ); + $this->addWarningMessage($msg); + } + + if (!empty($emptySavedItems['group'])) { + $tempItems = array(); + foreach ($emptySavedItems['group'] as $tempItem) { + $tempItems[] = $tempItem['id']; + } + + $msg = Mage::helper('M2ePro')->__( + ' + Some ePID(s) Group(s) was removed, that is why its Settings were + ignored and can not be applied', + implode(', ', $tempItems) + ); + $this->addWarningMessage($msg); + } + + return $preparedData; + } + + protected function getPreparedMotorsKtypesData($data) + { + $preparedData = array(); + $emptySavedItems = array(); + + foreach ($data as $item) { + if (empty($item['info'])) { + $emptySavedItems[$item['type']][] = $item; + continue; + } + + $preparedData[] = array( + 'ktype' => $item['id'], + 'note' => $item['note'], + ); + } + + if (!empty($emptySavedItems['ktype'])) { + $tempItems = array(); + foreach ($emptySavedItems['ktype'] as $tempItem) { + $tempItems[] = $tempItem['id']; + } + + $msg = Mage::helper('M2ePro')->__( + ' + Some kTypes(s) which were saved in Parts Compatibility Magento Attribute + have been removed. Their Values were ignored and not sent on eBay', + implode(', ', $tempItems) + ); + $this->addWarningMessage($msg); + } + + if (!empty($emptySavedItems['filter'])) { + $tempItems = array(); + foreach ($emptySavedItems['filter'] as $tempItem) { + $tempItems[] = $tempItem['id']; + } + + $msg = Mage::helper('M2ePro')->__( + ' + Some kTypes(s) Grid Filter(s) was removed, that is why its Settings + were ignored and can not be applied', + implode(', ', $tempItems) + ); + $this->addWarningMessage($msg); + } + + if (!empty($emptySavedItems['group'])) { + $tempItems = array(); + foreach ($emptySavedItems['group'] as $tempItem) { + $tempItems[] = $tempItem['id']; + } + + $msg = Mage::helper('M2ePro')->__( + ' + Some kTypes(s) Group(s) was removed, that is why its Settings were + ignored and can not be applied', + implode(', ', $tempItems) + ); + $this->addWarningMessage($msg); + } + + return $preparedData; + } + + // --------------------------------------- + + protected function groupEbayMotorsEpidsData($data, $condition) + { + $groupingFields = array_unique( + array_merge( + array('year', 'make', 'model'), + array_keys($condition) + ) + ); + + $groups = array(); + foreach ($data as $item) { + if (empty($groups)) { + $group = array(); + foreach ($groupingFields as $groupingField) { + $group[$groupingField] = $item[$groupingField]; + } + + ksort($group); + + $groups[] = $group; + continue; + } + + $newGroup = array(); + foreach ($groupingFields as $groupingField) { + $newGroup[$groupingField] = $item[$groupingField]; + } + + ksort($newGroup); + + if (!in_array($newGroup, $groups)) { + $groups[] = $newGroup; + } + } + + return $groups; + } + + protected function buildEpidData($resource) + { + $motorsData = array(); + + if (isset($resource['make'])) { + $motorsData['Make'] = $resource['make']; + } + + if (isset($resource['model'])) { + $motorsData['Model'] = $resource['model']; + } + + if (isset($resource['year'])) { + $motorsData['Year'] = $resource['year']; + } + + if (isset($resource['submodel'])) { + $motorsData['Submodel'] = $resource['submodel']; + } + + if (isset($resource['trim'])) { + $motorsData['Trim'] = $resource['trim']; + } + + if (isset($resource['engine'])) { + $motorsData['Engine'] = $resource['engine']; + } + + if (isset($resource['street_name'])) { + $motorsData['StreetName'] = $resource['street_name']; + } + + return $motorsData; + } + + protected function getEbayMotorsEpidsAttributes() + { + $categoryId = $this->getCategorySource()->getCategoryId(); + $categoryData = $this->getEbayMarketplace()->getCategory($categoryId); + + $features = !empty($categoryData['features']) ? + (array)Mage::helper('M2ePro')->jsonDecode($categoryData['features']) : array(); + + $attributes = !empty($features['parts_compatibility_attributes']) ? + $features['parts_compatibility_attributes'] : array(); + + return $attributes; + } + + //######################################## + + /** + * @return Ess_M2ePro_Helper_Component_Ebay_Motors + */ + protected function getMotorsHelper() + { + return Mage::helper('M2ePro/Component_Ebay_Motors'); + } + + protected function getMotorsAttribute($type) + { + return $this->getMotorsHelper()->getAttribute($type); + } + + //######################################## + + /** + * @return Ess_M2ePro_Model_Ebay_Template_Category_Source + */ + protected function getCategorySource() + { + return $this->getEbayListingProduct()->getCategoryTemplateSource(); + } +} diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php index 0c192de16..2caa0ca5f 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Request.php @@ -49,7 +49,6 @@ public function getActionData() } $data = array_merge( - array( 'sku' => $this->getSku(), 'item_uuid' => $uuid, @@ -62,6 +61,7 @@ public function getActionData() $this->getDescriptionData(), $this->getImagesData(), $this->getCategoriesData(), + $this->getPartsData(), $this->getPaymentData(), $this->getReturnData(), $this->getShippingData(), diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Response.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Response.php index 4e49b016f..773fe19df 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Response.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/List/Response.php @@ -42,6 +42,7 @@ public function processSuccess(array $response, array $responseParams = array()) $data = $this->appendDescriptionValues($data); $data = $this->appendImagesValues($data); $data = $this->appendCategoriesValues($data); + $data = $this->appendPartsValues($data); $data = $this->appendPaymentValues($data); $data = $this->appendShippingValues($data); $data = $this->appendReturnValues($data); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Request.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Request.php index 38b4e4fd6..e7490207e 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Request.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Request.php @@ -46,6 +46,7 @@ public function getActionData() $this->getQtyData(), $this->getPriceData(), $this->getCategoriesData(), + $this->getPartsData(), $this->getVariationsData() ); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Response.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Response.php index d53737a93..8962089c2 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Response.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Relist/Response.php @@ -16,6 +16,7 @@ class Ess_M2ePro_Model_Ebay_Listing_Product_Action_Type_Relist_Response const INSTRUCTION_TYPE_CHECK_DESCRIPTION = 'success_relist_check_description'; const INSTRUCTION_TYPE_CHECK_IMAGES = 'success_relist_check_images'; const INSTRUCTION_TYPE_CHECK_CATEGORIES = 'success_relist_check_categories'; + const INSTRUCTION_TYPE_CHECK_PARTS = 'success_relist_check_parts'; const INSTRUCTION_TYPE_CHECK_PAYMENT = 'success_relist_check_payment'; const INSTRUCTION_TYPE_CHECK_SHIPPING = 'success_relist_check_shipping'; const INSTRUCTION_TYPE_CHECK_RETURN = 'success_relist_check_return'; diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Request.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Request.php index 0570a48f2..5b79ad5c7 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Request.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Request.php @@ -22,6 +22,7 @@ abstract class Ess_M2ePro_Model_Ebay_Listing_Product_Action_Type_Request 'images', 'variations', 'categories', + 'parts', 'shipping', 'payment', 'return', @@ -485,6 +486,24 @@ public function getCategoriesData() return $data; } + /** + * @return array + */ + public function getPartsData() + { + if (!$this->getConfigurator()->isPartsAllowed()) { + return array(); + } + + $dataBuilder = $this->getDataBuilder('parts'); + $data = $dataBuilder->getData(); + $hash = $dataBuilder->getHash(); + + $this->addMetaData('parts_data_hash', $hash); + + return $data; + } + /** * @return array */ diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Response.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Response.php index 09e398b5f..802597502 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Response.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Response.php @@ -595,6 +595,18 @@ protected function appendCategoriesValues($data) return $data; } + protected function appendPartsValues($data) + { + $requestMetadata = $this->getRequestMetaData(); + if (!isset($requestMetadata['parts_data_hash'])) { + return $data; + } + + $data['online_parts_data'] = $requestMetadata['parts_data_hash']; + + return $data; + } + protected function appendPaymentValues($data) { $requestMetadata = $this->getRequestMetaData(); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Request.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Request.php index 844d090b7..8885d7e33 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Request.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Request.php @@ -17,7 +17,6 @@ class Ess_M2ePro_Model_Ebay_Listing_Product_Action_Type_Revise_Request public function getActionData() { $data = array_merge( - array( 'item_id' => $this->getEbayListingProduct()->getEbayItemIdReal() ), @@ -29,6 +28,7 @@ public function getActionData() $this->getDescriptionData(), $this->getImagesData(), $this->getCategoriesData(), + $this->getPartsData(), $this->getPaymentData(), $this->getReturnData(), $this->getShippingData(), diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Response.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Response.php index 2cd09103c..b77268e2f 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Response.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Action/Type/Revise/Response.php @@ -40,6 +40,7 @@ public function processSuccess(array $response, array $responseParams = array()) $data = $this->appendDescriptionValues($data); $data = $this->appendImagesValues($data); $data = $this->appendCategoriesValues($data); + $data = $this->appendPartsValues($data); $data = $this->appendPaymentValues($data); $data = $this->appendShippingValues($data); $data = $this->appendReturnValues($data); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Abstract.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Abstract.php index 0aca212e4..114625782 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Abstract.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Abstract.php @@ -25,6 +25,7 @@ protected function getReviseInstructionTypes() $this->getReviseDescriptionInstructionTypes(), $this->getReviseImagesInstructionTypes(), $this->getReviseCategoriesInstructionTypes(), + $this->getRevisePartsInstructionTypes(), $this->getReviseShippingInstructionTypes(), $this->getRevisePaymentInstructionTypes(), $this->getReviseReturnInstructionTypes(), @@ -180,6 +181,24 @@ protected function getReviseCategoriesInstructionTypes() ); } + protected function getRevisePartsInstructionTypes() + { + return array( + Ess_M2ePro_Model_Ebay_Magento_Product_ChangeProcessor::INSTRUCTION_TYPE_PARTS_DATA_CHANGED, + Ess_M2ePro_Model_Ebay_Template_ChangeProcessor_Abstract::INSTRUCTION_TYPE_PARTS_DATA_CHANGED, + Ess_M2ePro_Model_Ebay_Template_Synchronization_ChangeProcessor::INSTRUCTION_TYPE_REVISE_PARTS_ENABLED, + Ess_M2ePro_Model_Ebay_Template_Synchronization_ChangeProcessor:: + INSTRUCTION_TYPE_REVISE_PARTS_DISABLED, + Ess_M2ePro_Model_Listing::INSTRUCTION_TYPE_PRODUCT_MOVED_FROM_OTHER, + Ess_M2ePro_Model_Listing::INSTRUCTION_TYPE_PRODUCT_MOVED_FROM_LISTING, + Ess_M2ePro_Model_Listing::INSTRUCTION_TYPE_PRODUCT_REMAP_FROM_LISTING, + Ess_M2ePro_Model_Ebay_Listing_Product_Action_Type_Relist_Response::INSTRUCTION_TYPE_CHECK_PARTS, + Ess_M2ePro_PublicServices_Product_SqlChange::INSTRUCTION_TYPE_PRODUCT_CHANGED, + Ess_M2ePro_Model_Magento_Product_ChangeProcessor_Abstract::INSTRUCTION_TYPE_MAGMI_PLUGIN_PRODUCT_CHANGED, + Ess_M2ePro_Model_Cron_Task_Listing_Product_InspectDirectChanges::INSTRUCTION_TYPE, + ); + } + protected function getReviseShippingInstructionTypes() { return array( @@ -284,6 +303,10 @@ protected function getPropertiesDataFromInputInstructions() $propertiesData[] = 'categories'; } + if ($this->_input->hasInstructionWithTypes($this->getRevisePartsInstructionTypes())) { + $propertiesData[] = 'parts'; + } + if ($this->_input->hasInstructionWithTypes($this->getReviseShippingInstructionTypes())) { $propertiesData[] = 'shipping'; } diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Active.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Active.php index 29d59d33e..756bc952c 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Active.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Product/Instruction/SynchronizationTemplate/Checker/Active.php @@ -69,6 +69,7 @@ public function isAllowed() public function process(array $params = array()) { + /** @var Ess_M2ePro_Model_Listing_Product_ScheduledAction $scheduledAction */ $scheduledAction = $this->_input->getScheduledAction(); if ($scheduledAction === null) { $scheduledAction = Mage::getModel('M2ePro/Listing_Product_ScheduledAction'); @@ -97,6 +98,7 @@ public function process(array $params = array()) $actionType = Ess_M2ePro_Model_Listing_Product::ACTION_REVISE; $additionalData['params']['replaced_action'] = Ess_M2ePro_Model_Listing_Product::ACTION_STOP; + /** @var Ess_M2ePro_Model_Ebay_Listing_Product_Action_Configurator $configurator */ $configurator = Mage::getModel('M2ePro/Ebay_Listing_Product_Action_Configurator'); $configurator->disableAll()->allowQty()->allowVariations(); @@ -141,6 +143,7 @@ public function process(array $params = array()) return; } + /** @var Ess_M2ePro_Model_Ebay_Listing_Product_Action_Configurator $configurator */ $configurator = Mage::getModel('M2ePro/Ebay_Listing_Product_Action_Configurator'); $configurator->disableAll(); @@ -239,6 +242,16 @@ public function process(array $params = array()) } } + if ($this->_input->hasInstructionWithTypes($this->getRevisePartsInstructionTypes())) { + if ($this->isMeetRevisePartsRequirements()) { + $configurator->allowParts(); + $tags['parts'] = true; + } else { + $configurator->disallowParts(); + unset($tags['parts']); + } + } + if ($this->_input->hasInstructionWithTypes($this->getReviseShippingInstructionTypes())) { if ($this->isMeetReviseShippingRequirements()) { $configurator->allowShipping(); @@ -637,6 +650,31 @@ public function isMeetReviseCategoriesRequirements() // --------------------------------------- + public function isMeetRevisePartsRequirements() + { + $listingProduct = $this->_input->getListingProduct(); + + /** @var Ess_M2ePro_Model_Ebay_Listing_Product $ebayListingProduct */ + $ebayListingProduct = $listingProduct->getChildObject(); + + $ebaySynchronizationTemplate = $ebayListingProduct->getEbaySynchronizationTemplate(); + + if (!$ebaySynchronizationTemplate->isReviseUpdateParts()) { + return false; + } + + $actionDataBuilder = Mage::getModel('M2ePro/Ebay_Listing_Product_Action_DataBuilder_Parts'); + $actionDataBuilder->setListingProduct($listingProduct); + + if ($actionDataBuilder->getHash() == $ebayListingProduct->getData('online_parts_data')) { + return false; + } + + return true; + } + + // --------------------------------------- + public function isMeetRevisePaymentRequirements() { $listingProduct = $this->_input->getListingProduct(); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/ChangeProcessor.php b/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/ChangeProcessor.php index 3a3c00695..afc4b0cc2 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/ChangeProcessor.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/ChangeProcessor.php @@ -14,6 +14,7 @@ class Ess_M2ePro_Model_Ebay_Magento_Product_ChangeProcessor const INSTRUCTION_TYPE_DESCRIPTION_DATA_CHANGED = 'magento_product_description_data_changed'; const INSTRUCTION_TYPE_IMAGES_DATA_CHANGED = 'magento_product_images_data_changed'; const INSTRUCTION_TYPE_CATEGORIES_DATA_CHANGED = 'magento_product_categories_data_changed'; + const INSTRUCTION_TYPE_PARTS_DATA_CHANGED = 'magento_product_parts_data_changed'; const INSTRUCTION_TYPE_SHIPPING_DATA_CHANGED = 'magento_product_shipping_data_changed'; const INSTRUCTION_TYPE_OTHER_DATA_CHANGED = 'magento_product_other_data_changed'; diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Filter.php b/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Filter.php index 1b2acd8e8..f88aa88c7 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Filter.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Filter.php @@ -18,21 +18,33 @@ public function _construct() //######################################## - public function deleteInstance() + public function delete() { - if (!parent::deleteInstance()) { - return false; + /** @var Ess_M2ePro_Helper_Component_Ebay_Motors $ebayMotorsHelper */ + $ebayMotorsHelper = Mage::helper('M2ePro/Component_Ebay_Motors'); + $groupsIds = $ebayMotorsHelper->getGroupsAssociatedWithFilter($this->getId()); + + foreach ($groupsIds as $groupId) { + /** @var Ess_M2ePro_Model_Ebay_Motor_Group $group */ + $group = Mage::getModel('M2ePro/Ebay_Motor_Group')->load($groupId); + $group->removeFiltersByIds(array($this->getId())); } - /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */ - $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); + $associatedProductsIds = $ebayMotorsHelper->getAssociatedProducts($this->getId(), 'FILTER'); + $ebayMotorsHelper->resetOnlinePartsData($associatedProductsIds); - $filterGroupRelation = Mage::helper('M2ePro/Module_Database_Structure') - ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); + $temp = parent::deleteInstance(); + if ($temp) { + /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */ + $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); - $connWrite->delete($filterGroupRelation, array('filter_id = ?' => $this->getId())); + $filterGroupRelation = Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); - return true; + $connWrite->delete($filterGroupRelation, array('filter_id = ?' => $this->getId())); + } + + return $temp; } //######################################## diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Group.php b/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Group.php index 73a949062..11d88b3e5 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Group.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Motor/Group.php @@ -21,21 +21,26 @@ public function _construct() //######################################## - public function deleteInstance() + public function delete() { - if (!parent::deleteInstance()) { - return false; - } + /** @var Ess_M2ePro_Helper_Component_Ebay_Motors $ebayMotorsHelper */ + $ebayMotorsHelper = Mage::helper('M2ePro/Component_Ebay_Motors'); - /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */ - $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); + $associatedProductsIds = $ebayMotorsHelper->getAssociatedProducts($this->getId(), 'GROUP'); + $ebayMotorsHelper->resetOnlinePartsData($associatedProductsIds); - $filterGroupRelation = Mage::helper('M2ePro/Module_Database_Structure') - ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); + $temp = parent::deleteInstance(); + if ($temp) { + /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */ + $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); - $connWrite->delete($filterGroupRelation, array('group_id = ?' => $this->getId())); + $filterGroupRelation = Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); - return true; + $connWrite->delete($filterGroupRelation, array('group_id = ?' => $this->getId())); + } + + return $temp; } //######################################## @@ -150,4 +155,80 @@ public function getNote() } //######################################## + + /** + * @param array $itemsIds + * @throws Ess_M2ePro_Model_Exception_Logic + */ + public function removeItemsByIds($itemsIds) + { + $this->isLoaded(); + + if (!$this->isModeItem()) { + throw new Ess_M2ePro_Model_Exception_Logic( + 'Method should be used for item mode only instead of filter mode' + ); + } + + $items = $this->getItems(); + + foreach ($itemsIds as $itemId) { + unset($items[$itemId]); + } + + if (!empty($items)) { + $this->setItemsData(Mage::helper('M2ePro/Component_Ebay_Motors')->buildItemsAttributeValue($items)); + $this->save(); + } else { + $this->delete(); + } + + /** @var Ess_M2ePro_Helper_Component_Ebay_Motors $ebayMotorsHelper */ + $ebayMotorsHelper = Mage::helper('M2ePro/Component_Ebay_Motors'); + $associatedProductsIds = $ebayMotorsHelper->getAssociatedProducts($this->getId(), 'GROUP'); + $ebayMotorsHelper->resetOnlinePartsData($associatedProductsIds); + } + + /** + * @param array $filtersIds + * @throws Ess_M2ePro_Model_Exception_Logic + */ + public function removeFiltersByIds($filtersIds) + { + $this->isLoaded(); + $groupId = $this->getId(); + + if (!$this->isModeFilter()) { + throw new Ess_M2ePro_Model_Exception_Logic( + 'Method should be used for filter mode only instead of item mode' + ); + } + + /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */ + $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); + + $filterGroupRelation = Mage::helper('M2ePro/Module_Database_Structure') + ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); + + $connWrite->delete( + $filterGroupRelation, + array( + 'filter_id in (?)' => $filtersIds, + 'group_id = ?' => $groupId, + ) + ); + + /** @var Ess_M2ePro_Model_Ebay_Motor_Group $model */ + $model = Mage::getModel('M2ePro/Ebay_Motor_Group')->load($groupId); + $ids = $model->getFiltersIds(); + + if (empty($ids)) { + $model->delete(); + } + + /** @var Ess_M2ePro_Helper_Component_Ebay_Motors $ebayMotorsHelper */ + $ebayMotorsHelper = Mage::helper('M2ePro/Component_Ebay_Motors'); + $associatedProductsIds = $ebayMotorsHelper->getAssociatedProducts($this->getId(), 'GROUP'); + $ebayMotorsHelper->resetOnlinePartsData($associatedProductsIds); + } } diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Template/ChangeProcessor/Abstract.php b/app/code/community/Ess/M2ePro/Model/Ebay/Template/ChangeProcessor/Abstract.php index bd0c4a565..ae96a9e2a 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Template/ChangeProcessor/Abstract.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Template/ChangeProcessor/Abstract.php @@ -19,6 +19,7 @@ abstract class Ess_M2ePro_Model_Ebay_Template_ChangeProcessor_Abstract const INSTRUCTION_TYPE_IMAGES_DATA_CHANGED = 'template_images_data_changed'; const INSTRUCTION_TYPE_VARIATION_IMAGES_DATA_CHANGED = 'template_variation_images_data_changed'; const INSTRUCTION_TYPE_CATEGORIES_DATA_CHANGED = 'template_categories_data_changed'; + const INSTRUCTION_TYPE_PARTS_DATA_CHANGED = 'template_parts_data_changed'; const INSTRUCTION_TYPE_PAYMENT_DATA_CHANGED = 'template_payment_data_changed'; const INSTRUCTION_TYPE_SHIPPING_DATA_CHANGED = 'template_shipping_data_changed'; const INSTRUCTION_TYPE_RETURN_DATA_CHANGED = 'template_return_data_changed'; diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization.php b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization.php index a989a777f..9d955633d 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization.php @@ -200,6 +200,14 @@ public function isReviseUpdateCategories() return $this->getData('revise_update_categories') != 0; } + /** + * @return bool + */ + public function isReviseUpdateParts() + { + return $this->getData('revise_update_parts') != 0; + } + /** * @return bool */ diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Builder.php b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Builder.php index 1aa973559..47999daf0 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Builder.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Builder.php @@ -108,6 +108,10 @@ protected function prepareReviseData() $data['revise_update_categories'] = (int)$this->_rawData['revise_update_categories']; } + if (isset($this->_rawData['revise_update_parts'])) { + $data['revise_update_parts'] = (int)$this->_rawData['revise_update_parts']; + } + if (isset($this->_rawData['revise_update_shipping'])) { $data['revise_update_shipping'] = (int)$this->_rawData['revise_update_shipping']; } @@ -255,6 +259,7 @@ public function getDefaultData() 'revise_update_description' => 0, 'revise_update_images' => 0, 'revise_update_categories' => 0, + 'revise_update_parts' => 0, 'revise_update_shipping' => 0, 'revise_update_payment' => 0, 'revise_update_return' => 0, diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/ChangeProcessor.php b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/ChangeProcessor.php index a9188d931..fb6aa93b7 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/ChangeProcessor.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/ChangeProcessor.php @@ -31,6 +31,9 @@ class Ess_M2ePro_Model_Ebay_Template_Synchronization_ChangeProcessor const INSTRUCTION_TYPE_REVISE_CATEGORIES_ENABLED = 'template_synchronization_revise_categories_enabled'; const INSTRUCTION_TYPE_REVISE_CATEGORIES_DISABLED = 'template_synchronization_revise_categories_disabled'; + const INSTRUCTION_TYPE_REVISE_PARTS_ENABLED = 'template_synchronization_revise_parts_enabled'; + const INSTRUCTION_TYPE_REVISE_PARTS_DISABLED = 'template_synchronization_revise_parts_disabled'; + const INSTRUCTION_TYPE_REVISE_PAYMENT_ENABLED = 'template_synchronization_revise_payment_enabled'; const INSTRUCTION_TYPE_REVISE_PAYMENT_DISABLED = 'template_synchronization_revise_payment_disabled'; @@ -142,13 +145,27 @@ protected function getInstructionsData(Ess_M2ePro_Model_ActiveRecord_Diff $diff, if ($diff->isReviseCategoriesEnabled()) { $data[] = array( - 'type' => self::INSTRUCTION_TYPE_REVISE_CATEGORIES_ENABLED, - 'priority' => $status === Ess_M2ePro_Model_Listing_Product::STATUS_LISTED ? 30 : 5, + 'type' => self::INSTRUCTION_TYPE_REVISE_CATEGORIES_ENABLED, + 'priority' => $status === Ess_M2ePro_Model_Listing_Product::STATUS_LISTED ? 30 : 5, ); } elseif ($diff->isReviseCategoriesDisabled()) { $data[] = array( - 'type' => self::INSTRUCTION_TYPE_REVISE_CATEGORIES_DISABLED, - 'priority' => 5, + 'type' => self::INSTRUCTION_TYPE_REVISE_CATEGORIES_DISABLED, + 'priority' => 5, + ); + } + + //---------------------------------------- + + if ($diff->isRevisePartsEnabled()) { + $data[] = array( + 'type' => self::INSTRUCTION_TYPE_REVISE_PARTS_ENABLED, + 'priority' => $status === Ess_M2ePro_Model_Listing_Product::STATUS_LISTED ? 30 : 5, + ); + } elseif ($diff->isRevisePartsDisabled()) { + $data[] = array( + 'type' => self::INSTRUCTION_TYPE_REVISE_PARTS_DISABLED, + 'priority' => 5, ); } @@ -156,13 +173,13 @@ protected function getInstructionsData(Ess_M2ePro_Model_ActiveRecord_Diff $diff, if ($diff->isRevisePaymentEnabled()) { $data[] = array( - 'type' => self::INSTRUCTION_TYPE_REVISE_PAYMENT_ENABLED, - 'priority' => $status === Ess_M2ePro_Model_Listing_Product::STATUS_LISTED ? 30 : 5, + 'type' => self::INSTRUCTION_TYPE_REVISE_PAYMENT_ENABLED, + 'priority' => $status === Ess_M2ePro_Model_Listing_Product::STATUS_LISTED ? 30 : 5, ); } elseif ($diff->isRevisePaymentDisabled()) { $data[] = array( - 'type' => self::INSTRUCTION_TYPE_REVISE_PAYMENT_DISABLED, - 'priority' => 5, + 'type' => self::INSTRUCTION_TYPE_REVISE_PAYMENT_DISABLED, + 'priority' => 5, ); } diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Diff.php b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Diff.php index 50080fd0f..68bbb0f91 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Diff.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Template/Synchronization/Diff.php @@ -28,6 +28,8 @@ public function isReviseSettingsChanged() $this->isReviseImagesDisabled() || $this->isReviseCategoriesEnabled() || $this->isReviseCategoriesDisabled() || + $this->isRevisePartsEnabled() || + $this->isRevisePartsDisabled() || $this->isRevisePaymentEnabled() || $this->isRevisePaymentDisabled() || $this->isReviseShippingEnabled() || @@ -179,7 +181,27 @@ public function isReviseCategoriesDisabled() $oldSnapshotData = $this->_oldSnapshot; return !empty($oldSnapshotData['revise_update_categories']) - && empty($newSnapshotData['revise_update_categories']); + && empty($newSnapshotData['revise_update_categories']); + } + + //######################################## + + public function isRevisePartsEnabled() + { + $newSnapshotData = $this->_newSnapshot; + $oldSnapshotData = $this->_oldSnapshot; + + return empty($oldSnapshotData['revise_update_parts']) + && !empty($newSnapshotData['revise_update_parts']); + } + + public function isRevisePartsDisabled() + { + $newSnapshotData = $this->_newSnapshot; + $oldSnapshotData = $this->_oldSnapshot; + + return !empty($oldSnapshotData['revise_update_parts']) + && empty($newSnapshotData['revise_update_parts']); } //######################################## diff --git a/app/code/community/Ess/M2ePro/Model/Magento/Product.php b/app/code/community/Ess/M2ePro/Model/Magento/Product.php index d3e824fbb..fb0f1cc0e 100644 --- a/app/code/community/Ess/M2ePro/Model/Magento/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Magento/Product.php @@ -1187,7 +1187,7 @@ public function getAttributeFrontendInput($attributeCode) return $attribute->getFrontendInput(); } - public function getAttributeValue($attributeCode) + public function getAttributeValue($attributeCode, $convertBoolean = true) { $productObject = $this->getProduct(); @@ -1240,8 +1240,12 @@ public function getAttributeValue($attributeCode) // YES NO } else if ($attribute->getFrontendInput() == 'boolean') { - (bool)$value ? $value = Mage::helper('M2ePro')->__('Yes') : - $value = Mage::helper('M2ePro')->__('No'); + if ($convertBoolean) { + (bool)$value ? $value = Mage::helper('M2ePro')->__('Yes') : + $value = Mage::helper('M2ePro')->__('No'); + } else { + (bool)$value ? $value = 'true' : $value = 'false'; + } // PRICE } else if ($attribute->getFrontendInput() == 'price') { diff --git a/app/code/community/Ess/M2ePro/Model/Magento/Product/Cache.php b/app/code/community/Ess/M2ePro/Model/Magento/Product/Cache.php index b6e30eb97..3625af1aa 100644 --- a/app/code/community/Ess/M2ePro/Model/Magento/Product/Cache.php +++ b/app/code/community/Ess/M2ePro/Model/Magento/Product/Cache.php @@ -160,7 +160,7 @@ public function getQty($lifeMode = false) //######################################## - public function getAttributeValue($attributeCode) + public function getAttributeValue($attributeCode, $convertBoolean = true) { $args = func_get_args(); return $this->getMethodData(__FUNCTION__, $args); diff --git a/app/code/community/Ess/M2ePro/Model/Resource/Order/Log/Collection.php b/app/code/community/Ess/M2ePro/Model/Resource/Order/Log/Collection.php index e1fcef4e9..1282501d4 100644 --- a/app/code/community/Ess/M2ePro/Model/Resource/Order/Log/Collection.php +++ b/app/code/community/Ess/M2ePro/Model/Resource/Order/Log/Collection.php @@ -29,8 +29,7 @@ public function getLogsByDescription( $this->addFieldToFilter('main_table.type', Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR); if (!empty($lastFromDate)) { - $lastFromDate = new DateTime($lastFromDate, new DateTimeZone('UTC')); - $this->addFieldToFilter('main_table.create_date', array('gteq' => $lastFromDate->format('Y-m-d'))); + $this->addFieldToFilter('main_table.create_date', array('gteq' => $lastFromDate)); } return $this; diff --git a/app/code/community/Ess/M2ePro/composer.json b/app/code/community/Ess/M2ePro/composer.json index 8b2b912f8..8c900dce6 100644 --- a/app/code/community/Ess/M2ePro/composer.json +++ b/app/code/community/Ess/M2ePro/composer.json @@ -2,7 +2,7 @@ "name": "m2epro/magento1-extension", "description": "M2E Pro is a Magento trusted (TM), award-winning extension, which allows merchants of all sizes to fully integrate Magento based system(s) into eBay/Amazon/Walmart platforms.", "type": "magento-module", - "version": "6.14.3", + "version": "6.15.0", "license": "proprietary", "keywords": ["ebay", "amazon", "walmart", "magento"], "homepage": "https://www.m2epro.com/", diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/ControlPanel/InspectionController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/ControlPanel/InspectionController.php index 9c9846db0..e34b6d95a 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/ControlPanel/InspectionController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/ControlPanel/InspectionController.php @@ -18,7 +18,7 @@ public function phpInfoAction() public function cacheSettingsAction() { - return $this->getResponse()->setBody('
'.print_r(Mage::app()->getCache(), true).'
'); + return $this->getResponse()->setBody('
' . print_r(Mage::app()->getCache(), true) . '
'); } public function resourcesSettingsAction() @@ -43,7 +43,7 @@ public function resourcesSettingsAction() } } - return $this->getResponse()->setBody('
'.print_r($resourcesConfig, true).'
'); + return $this->getResponse()->setBody('
' . print_r($resourcesConfig, true) . '
'); } //######################################## @@ -54,12 +54,14 @@ public function cronScheduleTableAction() if ($this->getRequest()->isXmlHttpRequest()) { $block = $this->getLayout()->createBlock('M2ePro/adminhtml_ControlPanel_inspection_cronScheduleTable_grid'); + return $this->getResponse()->setBody($block->toHtml()); } $block = $this->getLayout()->createBlock('M2ePro/adminhtml_ControlPanel_inspection_cronScheduleTable'); $this->_addContent($block); + return $this->renderLayout(); } @@ -84,6 +86,7 @@ public function changeMaintenanceModeAction() } $this->_getSession()->addSuccess(Mage::helper('M2ePro')->__('Changed.')); + return $this->_redirectUrl(Mage::helper('M2ePro/View_ControlPanel')->getPageUrl()); } @@ -94,6 +97,7 @@ public function setMagentoCoreSetupValueAction() $version = $this->getRequest()->getParam('version'); if (!$version) { $this->_getSession()->addWarning('Version is not provided.'); + return $this->_redirectUrl(Mage::helper('M2ePro/View_ControlPanel')->getPageUrl()); } @@ -105,6 +109,7 @@ public function setMagentoCoreSetupValueAction() Ess_M2ePro_Model_Upgrade_MySqlSetup::MIN_SUPPORTED_VERSION_FOR_UPGRADE ) ); + return $this->_redirectUrl(Mage::helper('M2ePro/View_ControlPanel')->getPageUrl()); } @@ -120,6 +125,7 @@ public function setMagentoCoreSetupValueAction() Mage::helper('M2ePro/Magento')->clearCache(); $this->_getSession()->addSuccess(Mage::helper('M2ePro')->__('Extension upgrade was completed.')); + return $this->_redirectUrl(Mage::helper('M2ePro/View_ControlPanel')->getPageUrl()); } @@ -128,8 +134,37 @@ public function setMagentoCoreSetupValueAction() public function getInspectionsGridAction() { $grid = $this->loadLayout()->getLayout()->createBlock('M2ePro/adminhtml_controlPanel_inspection_grid'); + return $this->getResponse()->setBody($grid->toHtml()); } + public function checkInspectionAction() + { + /** @var Ess_M2ePro_Model_ControlPanel_Inspection_Manager $manager */ + $manager = Mage::getSingleton('M2ePro/ControlPanel_Inspection_Manager'); + $inspectionName = $this->getRequest()->getParam('name'); + $results = $manager->runInspection($inspectionName); + + $isSuccess = false; + $metadata = ''; + $message = Mage::helper('M2ePro')->__('Success'); + foreach ($results as $result) { + if ($result->isSuccess()) { + $isSuccess = true; + break; + } + $metadata = $result->getMetadata(); + $message = $result->getMessage(); + } + + $this->_addJsonContent( + array( + 'result' => $isSuccess, + 'metadata' => $metadata, + 'message' => $message + ) + ); + } + //######################################## } diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php index 82def9f86..f0735f0f9 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/AccountController.php @@ -504,8 +504,9 @@ protected function updateAccount($id, $data) try { $params = $this->getDataForServer($data); + $paramsOld = $this->getDataForServer($oldData); - if (!$this->isNeedSendDataToServer($params, $oldData)) { + if (!$this->isNeedSendDataToServer($params, $paramsOld)) { return $account; } diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/MotorController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/MotorController.php index 2deab81f6..bb7f693c0 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/MotorController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Ebay/MotorController.php @@ -266,18 +266,7 @@ public function removeItemFromGroupAction() /** @var Ess_M2ePro_Model_Ebay_Motor_Group $model */ $model = Mage::getModel('M2ePro/Ebay_Motor_Group')->load($groupId); - $items = $model->getItems(); - - foreach ($itemsIds as $itemId) { - unset($items[$itemId]); - } - - if (!empty($items)) { - $model->setItemsData(Mage::helper('M2ePro/Component_Ebay_Motors')->buildItemsAttributeValue($items)); - $model->save(); - } else { - $model->deleteInstance(); - } + $model->removeItemsByIds($itemsIds); $this->getResponse()->setBody(0); } @@ -330,26 +319,7 @@ public function removeFilterAction() ->addFieldToFilter('id', array('in' => $filtersIds)); foreach ($filters->getItems() as $filter) { - $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); - $table = Mage::helper('M2ePro/Module_Database_Structure') - ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); - - $select = $connRead->select(); - $select->from(array('emftg' => $table), array('group_id')) - ->where('filter_id IN (?)', $filter->getId()); - - $groupIds = Mage::getResourceModel('core/config')->getReadConnection()->fetchCol($select); - - $filter->deleteInstance(); - - foreach ($groupIds as $groupId) { - /** @var Ess_M2ePro_Model_Ebay_Motor_Group $group */ - $group = Mage::getModel('M2ePro/Ebay_Motor_Group')->load($groupId); - - if (count($group->getFiltersIds()) === 0) { - $group->deleteInstance(); - } - } + $filter->delete(); } $this->getResponse()->setBody(0); @@ -366,26 +336,9 @@ public function removeFilterFromGroupAction() $filtersIds = explode(',', $filtersIds); } - /** @var $connWrite Varien_Db_Adapter_Pdo_Mysql */ - $connWrite = Mage::getSingleton('core/resource')->getConnection('core_write'); - - $filterGroupRelation = Mage::helper('M2ePro/Module_Database_Structure') - ->getTableNameWithPrefix('m2epro_ebay_motor_filter_to_group'); - - $connWrite->delete( - $filterGroupRelation, array( - 'filter_id in (?)' => $filtersIds, - 'group_id = ?' => $groupId, - ) - ); - /** @var Ess_M2ePro_Model_Ebay_Motor_Group $model */ $model = Mage::getModel('M2ePro/Ebay_Motor_Group')->load($groupId); - $ids = $model->getFiltersIds(); - - if (empty($ids)) { - $model->deleteInstance(); - } + $model->removeFiltersByIds($filtersIds); $this->getResponse()->setBody(0); } diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/OrderController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/OrderController.php index 1f46009f5..ca7f1927c 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/OrderController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/OrderController.php @@ -691,11 +691,12 @@ public function deleteAction() public function skipLogNotificationToCurrentDateAction() { - $currentDate = new DateTime('now', new DateTimeZone('UTC')); + $lastOrderCreateDate = new DateTime($this->getRequest()->getParam('last_order_create_date'), new DateTimeZone('UTC')); + $lastOrderCreateDate->modify('+1 seconds'); /** @var Ess_M2ePro_Helper_Order_Notification $configHelper */ $configHelper = Mage::helper('M2ePro/Order_Notification'); - $configHelper->setNotificationDate($currentDate->format('Y-m-d')); + $configHelper->setNotificationDate($lastOrderCreateDate->format('Y-m-d H:i:s')); return $this->getResponse()->setBody(Mage::helper('M2ePro')->jsonEncode(array('result' => true))); } diff --git a/app/code/community/Ess/M2ePro/etc/config.xml b/app/code/community/Ess/M2ePro/etc/config.xml index 8bcf2a911..12238d3d7 100644 --- a/app/code/community/Ess/M2ePro/etc/config.xml +++ b/app/code/community/Ess/M2ePro/etc/config.xml @@ -2,7 +2,7 @@ - 6.14.3 + 6.15.0 diff --git a/app/code/community/Ess/M2ePro/sql/Install/Ebay.php b/app/code/community/Ess/M2ePro/sql/Install/Ebay.php index 998b38a00..4c8c8835a 100644 --- a/app/code/community/Ess/M2ePro/sql/Install/Ebay.php +++ b/app/code/community/Ess/M2ePro/sql/Install/Ebay.php @@ -412,6 +412,7 @@ public function execute() `online_bids` INT(11) UNSIGNED DEFAULT NULL, `online_main_category` VARCHAR(255) DEFAULT NULL, `online_categories_data` LONGTEXT DEFAULT NULL, + `online_parts_data` VARCHAR(32) DEFAULT NULL, `online_shipping_data` VARCHAR(40) DEFAULT NULL, `online_payment_data` VARCHAR(40) DEFAULT NULL, `online_return_data` VARCHAR(40) DEFAULT NULL, @@ -1114,6 +1115,7 @@ public function execute() `revise_update_description` TINYINT(2) UNSIGNED NOT NULL, `revise_update_images` TINYINT(2) UNSIGNED NOT NULL, `revise_update_categories` TINYINT(2) UNSIGNED NOT NULL, + `revise_update_parts` TINYINT(2) UNSIGNED NOT NULL, `revise_update_shipping` TINYINT(2) UNSIGNED NOT NULL, `revise_update_payment` TINYINT(2) UNSIGNED NOT NULL, `revise_update_return` TINYINT(2) UNSIGNED NOT NULL, diff --git a/app/code/community/Ess/M2ePro/sql/Update/y21_m10/PartsCompatibilityImprovement.php b/app/code/community/Ess/M2ePro/sql/Update/y21_m10/PartsCompatibilityImprovement.php new file mode 100644 index 000000000..5835450e3 --- /dev/null +++ b/app/code/community/Ess/M2ePro/sql/Update/y21_m10/PartsCompatibilityImprovement.php @@ -0,0 +1,246 @@ +_installer->getTableModifier('ebay_template_synchronization') + ->isColumnExists('revise_update_parts'); + + if ($isReviseUpdatePartsColumnExists) { + return; + } + + //---------------------------------------- + + $this->clearUnnecessaryData(); + $this->modifyDBScheme(); + + //---------------------------------------- + + $motorsAttributesKeys = array( + 'motors_epids_attribute', + 'uk_epids_attribute', + 'de_epids_attribute', + 'au_epids_attribute', + 'ktypes_attribute' + ); + + $query = $this->_installer->getConnection() + ->select() + ->from($this->_installer->getFullTableName('m2epro_config')) + ->where('`group` = ?', '/ebay/configuration/') + ->where('`key` IN (?)', $motorsAttributesKeys) + ->query(); + + $motorsAttributes = array(); + while ($row = $query->fetch()) { + if ($row['value']) { + $motorsAttributes[$row['key']] = $row['value']; + } + } + + //---------------------------------------- + + $listingsStmt = $this->_installer->getConnection() + ->select() + ->from( + array( + 'l' => $this->_installer->getFullTableName('m2epro_listing') + ), + array('id', 'marketplace_id') + ) + ->joinInner( + array('el' => $this->_installer->getFullTableName('m2epro_ebay_listing')), + 'l.id = el.listing_id', + array('parts_compatibility_mode') + ) + ->query(); + + $listingsInfo = array(); + while ($row = $listingsStmt->fetch()) { + $marketplaceId = $row['marketplace_id']; + if (!isset($listingsInfo[$marketplaceId])) { + $listingsInfo[$marketplaceId] = array(); + } + + $partsCompatibilityMode = $row['parts_compatibility_mode']; + if (!isset($listingsInfo[$marketplaceId][$partsCompatibilityMode])) { + $listingsInfo[$marketplaceId][$partsCompatibilityMode] = array(); + } + + $listingsInfo[$marketplaceId][$partsCompatibilityMode][] = $row['id']; + } + + foreach ($listingsInfo as $marketplaceId => $marketplaceInfo) { + foreach ($marketplaceInfo as $partsCompatibilityMode => $listingsIds) { + $attributeConfigKey = $this->getPartsCompatibilityAttributeConfigKey( + $marketplaceId, + $partsCompatibilityMode + ); + if (!$attributeConfigKey) { + continue; + } + + if (!isset($motorsAttributes[$attributeConfigKey]) || !$motorsAttributes[$attributeConfigKey]) { + continue; + } + + $attributeCode = $motorsAttributes[$attributeConfigKey]; + $template = implode(',', $listingsIds); + + $this->_installer->run( + <<_installer->getTable('m2epro_ebay_listing_product')}` AS `main` + INNER JOIN `{$this->_installer->getTable('m2epro_listing_product')}` AS `lp` + ON lp.id = main.listing_product_id + INNER JOIN `{$this->_installer->getTable('m2epro_listing')}` AS `l` ON lp.listing_id = l.id + AND l.id IN ({$template}) + INNER JOIN `{$this->_installer->getTable('m2epro_ebay_listing')}` AS `al` ON al.listing_id = lp.listing_id + INNER JOIN `{$this->_installer->getTable('eav_attribute')}` AS `ea` + ON ea.attribute_code = '$attributeCode' + LEFT JOIN `{$this->_installer->getTable('catalog_product_entity_text')}` AS `cpev_default` + ON cpev_default.attribute_id = ea.attribute_id + AND cpev_default.entity_id=lp.product_id AND cpev_default.store_id = 0 + LEFT JOIN `{$this->_installer->getTable('catalog_product_entity_text')}` AS `cpev` + ON cpev.attribute_id = ea.attribute_id AND cpev.entity_id=lp.product_id AND cpev.store_id = l.store_id +SET main.online_parts_data = MD5(IFNULL(cpev.value, cpev_default.value)) +WHERE IFNULL(cpev.value, cpev_default.value) IS NOT NULL; +SQL + ); + } + } + } + + //---------------------------------------- + + private function modifyDBScheme() + { + $this->_installer + ->getTableModifier('ebay_listing_product') + ->addColumn( + 'online_parts_data', + 'VARCHAR(32)', + null, + 'online_categories_data', + false, + false + ) + ->commit(); + + $this->_installer + ->getTableModifier('ebay_template_synchronization') + ->addColumn( + 'revise_update_parts', + 'TINYINT(2) UNSIGNED NOT NULL', + null, + 'revise_update_categories', + false, + false + ) + ->commit(); + + $this->_installer->run( + <<_installer->getTable('m2epro_ebay_template_synchronization')}` +SET `revise_update_parts` = `revise_update_categories`; +SQL + ); + } + + //---------------------------------------- + + private function clearUnnecessaryData() + { + // clear unnecessary data from online_categories_data (motors_epids) + $this->_installer->run( + <<_installer->getTable('m2epro_ebay_listing_product')}` +SET online_categories_data = CASE + WHEN INSTR(online_categories_data, 'motors_epids') > 0 + THEN CONCAT(SUBSTRING(online_categories_data, 1, INSTR(online_categories_data, 'motors_epids')-3), '}') + ELSE online_categories_data +END +WHERE online_categories_data IS NOT NULL; +SQL + ); + + // clear unnecessary data from online_categories_data (motors_ktypes) + $this->_installer->run( + <<_installer->getTable('m2epro_ebay_listing_product')}` +SET online_categories_data = CASE + WHEN INSTR(online_categories_data, 'motors_ktypes') > 0 + THEN CONCAT(SUBSTRING(online_categories_data, 1, INSTR(online_categories_data, 'motors_ktypes')-3), '}') + ELSE online_categories_data +END +WHERE online_categories_data IS NOT NULL; +SQL + ); + } + + //######################################## + + private function getPartsCompatibilityAttributeConfigKey($marketplaceId, $partsCompatibilityMode) + { + // https://docs.m2epro.com/help/m1/ebay-integration/parts-compatibility + // motors_epids_attribute, uk_epids_attribute, de_epids_attribute, au_epids_attribute, ktypes_attribute + $this->initEbayMarketplacesCache(); + + if ($marketplaceId === Ess_M2ePro_Helper_Component_Ebay::MARKETPLACE_MOTORS) { + return 'motors_epids_attribute'; + } else if ($marketplaceId === Ess_M2ePro_Helper_Component_Ebay::MARKETPLACE_UK) { + if ($partsCompatibilityMode == Ess_M2ePro_Model_Ebay_Listing::PARTS_COMPATIBILITY_MODE_EPIDS) { + return 'uk_epids_attribute'; + } else { + return 'ktypes_attribute'; + } + } else { + if (isset($this->ebayMarketplacesCache[$marketplaceId])) { + if ($this->ebayMarketplacesCache[$marketplaceId]['is_epid'] && + $this->ebayMarketplacesCache[$marketplaceId]['is_ktype'] + ) { + return $partsCompatibilityMode === Ess_M2ePro_Model_Ebay_Listing::PARTS_COMPATIBILITY_MODE_EPIDS ? + $this->ebayMarketplacesCache[$marketplaceId]['origin_country'] . '_epids_attribute' + : 'ktypes_attribute'; + } else { + return $this->ebayMarketplacesCache[$marketplaceId]['is_epid'] ? + $this->ebayMarketplacesCache[$marketplaceId]['origin_country'] . '_epids_attribute' + : 'ktypes_attribute'; + } + } else { + return null; + } + } + } + + private function initEbayMarketplacesCache() + { + if (!empty($this->ebayMarketplacesCache)) { + return; + } + + $query = $this->_installer->getConnection() + ->select() + ->from($this->_installer->getFullTableName('m2epro_ebay_marketplace')) + ->where('`is_epid` = 1 OR `is_ktype` = 1') + ->query(); + + while ($row = $query->fetch()) { + $this->ebayMarketplacesCache[$row['marketplace_id']] = array( + 'origin_country' => $row['origin_country'], + 'is_epid' => $row['is_epid'], + 'is_ktype' => $row['is_ktype'], + ); + } + } +} diff --git a/app/code/community/Ess/M2ePro/sql/Upgrade/v6_14_3_1__v6_15_0/Config.php b/app/code/community/Ess/M2ePro/sql/Upgrade/v6_14_3_1__v6_15_0/Config.php new file mode 100644 index 000000000..f747c1e3e --- /dev/null +++ b/app/code/community/Ess/M2ePro/sql/Upgrade/v6_14_3_1__v6_15_0/Config.php @@ -0,0 +1,19 @@ + + + + + + + +

+ __('Automatically revises Parts Compatibility data on eBay once the related data is modified.'); ?> +

+ + + @@ -263,4 +279,4 @@ More detailed information on how to work with this Page can be found __('Cancel') ?>   - \ No newline at end of file + diff --git a/composer.json b/composer.json index 8b2b912f8..8c900dce6 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "m2epro/magento1-extension", "description": "M2E Pro is a Magento trusted (TM), award-winning extension, which allows merchants of all sizes to fully integrate Magento based system(s) into eBay/Amazon/Walmart platforms.", "type": "magento-module", - "version": "6.14.3", + "version": "6.15.0", "license": "proprietary", "keywords": ["ebay", "amazon", "walmart", "magento"], "homepage": "https://www.m2epro.com/", diff --git a/js/M2ePro/Amazon/Listing/Create/Selling.js b/js/M2ePro/Amazon/Listing/Create/Selling.js index 54305ce17..6c6729d46 100644 --- a/js/M2ePro/Amazon/Listing/Create/Selling.js +++ b/js/M2ePro/Amazon/Listing/Create/Selling.js @@ -68,10 +68,6 @@ window.AmazonListingCreateSelling = Class.create(Common, { // --------------------------------------- sku_modification_mode_change: function () { - if ($('sku_modification_mode').value == M2ePro.php.constant('Ess_M2ePro_Model_Amazon_Listing::SKU_MODIFICATION_MODE_TEMPLATE')) { - $('sku_modification_custom_value').value = '%value%'; - } - if ($('sku_modification_mode').value == M2ePro.php.constant('Ess_M2ePro_Model_Amazon_Listing::SKU_MODIFICATION_MODE_NONE')) { $('sku_modification_custom_value').up('span').hide(); } else { diff --git a/js/M2ePro/ControlPanel/Inspection.js b/js/M2ePro/ControlPanel/Inspection.js index 195e0b958..a47b8ea86 100644 --- a/js/M2ePro/ControlPanel/Inspection.js +++ b/js/M2ePro/ControlPanel/Inspection.js @@ -2,8 +2,7 @@ window.ControlPanelInspection = Class.create(Common, { // --------------------------------------- - showMetaData: function(element) - { + showMetaData: function(element) { var content = '
' + element.next().innerHTML + '
' + @@ -26,21 +25,54 @@ window.ControlPanelInspection = Class.create(Common, { }); }, - removeRow: function (element) { + removeRow: function(element) { var form = element.up('form'), - url = form.getAttribute('action'), + url = form.getAttribute('action'), data = Form.serialize(form); form.querySelectorAll("input:checked").forEach(function(element) { element.up('tr').remove(); }); - new Ajax.Request( url , { + new Ajax.Request(url, { method: 'post', - asynchronous : true, - parameters : data + asynchronous: true, + parameters: data }); - } + }, + + checkAction: function() { + var tr = event.target.closest("tr"), + id = tr.querySelector(".id").textContent, + details = tr.querySelector(".details"); + + new Ajax.Request(M2ePro.url.get('checkInspection'), { + method: 'post', + parameters: { + name: id.trim() + }, + asynchronous: true, + onSuccess: function(transport) { + if (!transport.responseText.isJSON()) { + details.innerHTML = "Internal Error occured" + + " check system log"; + } + + var response = transport.responseText.evalJSON(); + if (response) { + if (response['result'] === true) { + details.innerHTML = "" + response['message'] + ""; + } else { + details.innerHTML = "" + response['message'] + ""; + details.innerHTML += '  \n' + + 'details\n' + + '
' + response['metadata'] + '
'; + } + } + } + }); + } // --------------------------------------- -}); \ No newline at end of file +}); diff --git a/js/M2ePro/Walmart/Configuration/General.js b/js/M2ePro/Walmart/Configuration/General.js index 4af04de6d..ff5a74b12 100644 --- a/js/M2ePro/Walmart/Configuration/General.js +++ b/js/M2ePro/Walmart/Configuration/General.js @@ -42,9 +42,7 @@ window.WalmartConfigurationGeneral = Class.create(Common, { { var self = WalmartConfigurationGeneralObj; - if ($('sku_modification_mode').value == self.SKU_MODIFICATION_MODE_TEMPLATE) { - $('sku_modification_custom_value').value = '%value%'; - } else { + if ($('sku_modification_mode').value != self.SKU_MODIFICATION_MODE_TEMPLATE) { $('sku_modification_custom_value').value = ''; }