diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Grid/Column/Renderer/Price.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Grid/Column/Renderer/Price.php index a5ae362da..b9c2398bd 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Grid/Column/Renderer/Price.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Grid/Column/Renderer/Price.php @@ -95,10 +95,16 @@ class="m2epro-repricing-price-value" $salePrice = $row->getData('online_regular_sale_price'); if ((float)$salePrice > 0) { - $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false, 'Y-m-d 00:00:00')); - - $startDateTimestamp = strtotime($row->getData('online_regular_sale_price_start_date')); - $endDateTimestamp = strtotime($row->getData('online_regular_sale_price_end_date')); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimestamp = (int)$helper->createGmtDateTime( + $helper->getCurrentGmtDate(false, 'Y-m-d 00:00:00') + )->format('U'); + + $startDateTimestamp = (int)$helper->createGmtDateTime($row->getData('online_regular_sale_price_start_date')) + ->format('U'); + $endDateTimestamp = (int)$helper->createGmtDateTime($row->getData('online_regular_sale_price_end_date')) + ->format('U'); if ($currentTimestamp <= $endDateTimestamp) { $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png'); diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Grid.php index 7fcf4c2e6..64b138cff 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Grid.php @@ -8,16 +8,10 @@ class Ess_M2ePro_Block_Adminhtml_Amazon_Listing_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Grid { - /** @var Ess_M2ePro_Model_Resource_Amazon_Listing */ - protected $_amazonListingResourceModel; - - //######################################## - public function __construct() { parent::__construct(); $this->setId('amazonListingGrid'); - $this->_amazonListingResourceModel = Mage::getResourceModel('M2ePro/Amazon_Listing'); } protected function _prepareCollection() @@ -59,6 +53,32 @@ protected function _prepareCollection() ); // --------------------------------------- + $structureHelper = Mage::helper('M2ePro/Module_Database_Structure'); + + $m2eproListing = $structureHelper->getTableNameWithPrefix('m2epro_listing'); + $m2eproAmazonListing = $structureHelper->getTableNameWithPrefix('m2epro_amazon_listing'); + $m2eproListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_listing_product'); + + $sql = "SELECT + l.id AS listing_id, + COUNT(lp.id) AS products_total_count, + COUNT(CASE WHEN lp.status = 2 THEN lp.id END) AS products_active_count, + COUNT(CASE WHEN lp.status != 2 THEN lp.id END) AS products_inactive_count + FROM `{$m2eproListing}` AS `l` + INNER JOIN `{$m2eproAmazonListing}` AS `al` ON l.id = al.listing_id + LEFT JOIN `{$m2eproListingProduct}` AS `lp` ON l.id = lp.listing_id + GROUP BY listing_id"; + + $collection->getSelect()->joinLeft( + array('t' => new Zend_Db_Expr('('.$sql.')')), + 'main_table.id=t.listing_id', + array( + 'products_total_count' => 'products_total_count', + 'products_active_count' => 'products_active_count', + 'products_inactive_count' => 'products_inactive_count', + ) + ); + $this->setCollection($collection); return parent::_prepareCollection(); @@ -248,45 +268,6 @@ protected function getColumnActionsItems() //######################################## - public function callbackColumnTotalProducts($value, $row, $column, $isExport) - { - $value = $this->_amazonListingResourceModel->getStatisticTotalCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - - public function callbackColumnListedProducts($value, $row, $column, $isExport) - { - $value = $this->_amazonListingResourceModel->getStatisticActiveCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - - public function callbackColumnInactiveProducts($value, $row, $column, $isExport) - { - $value = $this->_amazonListingResourceModel->getStatisticInactiveCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - public function callbackColumnTitle($value, $row, $column, $isExport) { $value = '' . diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Search/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Search/Grid.php index 9d4f5400a..4d8ebc7cc 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Search/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/Search/Grid.php @@ -459,10 +459,16 @@ class="m2epro-repricing-price-value" $salePrice = $row->getData('online_regular_sale_price'); if (!$row->getData('is_variation_parent') && (float)$salePrice > 0 && !$row->getData('is_repricing')) { - $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false, 'Y-m-d 00:00:00')); - - $startDateTimestamp = strtotime($row->getData('online_regular_sale_price_start_date')); - $endDateTimestamp = strtotime($row->getData('online_regular_sale_price_end_date')); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimestamp = (int)$helper->createGmtDateTime( + $helper->getCurrentGmtDate(false, 'Y-m-d 00:00:00') + )->format('U'); + + $startDateTimestamp = (int)$helper->createGmtDateTime($row->getData('online_regular_sale_price_start_date')) + ->format('U'); + $endDateTimestamp = (int)$helper->createGmtDateTime($row->getData('online_regular_sale_price_end_date')) + ->format('U'); if ($currentTimestamp <= $endDateTimestamp) { $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png'); diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/View/Amazon/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/View/Amazon/Grid.php index 90add0a96..2b1a26555 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/View/Amazon/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Listing/View/Amazon/Grid.php @@ -868,12 +868,16 @@ class="m2epro-repricing-price-value" $salePrice = $row->getData('online_regular_sale_price'); if (!$row->getData('is_variation_parent') && (float)$salePrice > 0) { - $currentTimestamp = strtotime( - Mage::helper('M2ePro')->getCurrentGmtDate(false, 'Y-m-d 00:00:00') - ); - - $startDateTimestamp = strtotime($row->getData('online_regular_sale_price_start_date')); - $endDateTimestamp = strtotime($row->getData('online_regular_sale_price_end_date')); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimestamp = (int)$helper->createGmtDateTime( + $helper->getCurrentGmtDate(false, 'Y-m-d 00:00:00') + )->format('U'); + + $startDateTimestamp = (int)$helper->createGmtDateTime($row->getData('online_regular_sale_price_start_date')) + ->format('U'); + $endDateTimestamp = (int)$helper->createGmtDateTime($row->getData('online_regular_sale_price_end_date')) + ->format('U'); if ($currentTimestamp <= $endDateTimestamp) { $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_logo.png'); diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Order/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Order/Grid.php index 475634936..103a60069 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Order/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Order/Grid.php @@ -213,14 +213,18 @@ protected function _prepareColumns() 'filter_index' => 'second_table.status', 'type' => 'options', 'options' => array( - Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => $helper->__('Pending'), - Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING_RESERVED => $helper->__('Pending / QTY Reserved'), - Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED => $helper->__('Unshipped'), - Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED_PARTIALLY => $helper->__('Partially Shipped'), - Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => $helper->__('Shipped'), - Ess_M2ePro_Model_Amazon_Order::STATUS_INVOICE_UNCONFIRMED => $helper->__('Invoice Not Confirmed'), - Ess_M2ePro_Model_Amazon_Order::STATUS_UNFULFILLABLE => $helper->__('Unfulfillable'), - Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => $helper->__('Canceled'), + Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => $helper->__('Pending'), + Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING_RESERVED => + $helper->__('Pending / QTY Reserved'), + Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED => $helper->__('Unshipped'), + Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED_PARTIALLY => $helper->__('Partially Shipped'), + Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => $helper->__('Shipped'), + Ess_M2ePro_Model_Amazon_Order::STATUS_INVOICE_UNCONFIRMED => + $helper->__('Invoice Not Confirmed'), + Ess_M2ePro_Model_Amazon_Order::STATUS_UNFULFILLABLE => $helper->__('Unfulfillable'), + Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => $helper->__('Canceled'), + Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELLATION_REQUESTED => + $helper->__('Unshipped (Cancellation Requested)'), ), 'frame_callback' => array($this, 'callbackColumnStatus'), 'filter_condition_callback' => array($this, 'callbackFilterStatus') @@ -577,9 +581,10 @@ public function callbackColumnStatus($value, $row, $column, $isExport) $status = $row->getData('status'); $statusColors = array( - Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => 'gray', - Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => 'green', - Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => 'red' + Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => 'gray', + Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => 'green', + Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => 'red', + Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELLATION_REQUESTED => 'red' ); $color = isset($statusColors[$status]) ? $statusColors[$status] : 'black'; @@ -692,6 +697,12 @@ protected function callbackFilterStatus($collection, $column) array(Ess_M2ePro_Model_Order_Reserve::STATE_PLACED) ); break; + case Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELLATION_REQUESTED: + $collection->addFieldToFilter( + 'second_table.status', + array(Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELLATION_REQUESTED) + ); + break; } } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template.php index 422a00b70..7893ef52d 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template.php @@ -14,36 +14,27 @@ public function __construct() { parent::__construct(); - // Initialization block - // --------------------------------------- $this->setId('amazonTemplate'); $this->_blockGroup = 'M2ePro'; $this->_controller = 'adminhtml_amazon_template'; - // --------------------------------------- - // Set header text - // --------------------------------------- $this->_headerText = ''; - // --------------------------------------- - // Set buttons actions - // --------------------------------------- $this->removeButton('back'); $this->removeButton('reset'); $this->removeButton('delete'); $this->removeButton('save'); $this->removeButton('edit'); - // --------------------------------------- - // --------------------------------------- $this->_addButton( - 'add', array( - 'label' => Mage::helper('M2ePro')->__('Add Policy'), - 'onclick' => '', - 'class' => 'add add-button-drop-down' + 'add', + array( + 'id' => 'add_policy', + 'label' => Mage::helper('M2ePro')->__('Add Policy'), + 'onclick' => '', + 'class' => 'add add-button-drop-down' ) ); - // ------------------------------------- } public function getHeaderHtml() @@ -52,6 +43,7 @@ public function getHeaderHtml() 'target_css_class' => 'add-button-drop-down', 'items' => array( array( + 'id' => 'add_policy_selling', 'url' => $this->getUrl( '*/adminhtml_amazon_template/new', array( @@ -61,6 +53,7 @@ public function getHeaderHtml() 'label' => Mage::helper('M2ePro')->__('Selling') ), array( + 'id' => 'add_policy_description', 'url' => $this->getUrl( '*/adminhtml_amazon_template/new', array( @@ -70,6 +63,7 @@ public function getHeaderHtml() 'label' => Mage::helper('M2ePro')->__('Description') ), array( + 'id' => 'add_policy_synchronization', 'url' => $this->getUrl( '*/adminhtml_amazon_template/new', array( @@ -79,6 +73,7 @@ public function getHeaderHtml() 'label' => Mage::helper('M2ePro')->__('Synchronization') ), array( + 'id' => 'add_policy_shipping', 'url' => $this->getUrl( '*/adminhtml_amazon_template/new', array( diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Description/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Description/Edit.php index c71165a2b..751171c20 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Description/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Description/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Description Policy "%template_title%"', $componentName, + 'Edit %component_name% Description Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -54,10 +55,12 @@ public function __construct() $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'CommonObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'CommonObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); @@ -66,18 +69,22 @@ public function __construct() if (!$isSaveAndClose && $this->isEditMode()) { $headId = 'amazon-template-description'; $this->_addButton( - 'duplicate', array( - 'label' => Mage::helper('M2ePro')->__('Duplicate'), - 'onclick' => "AmazonTemplateDescriptionObj.duplicate_click('{$headId}')", - 'class' => 'add M2ePro_duplicate_button' + 'duplicate', + array( + 'id' => 'duplicate_button', + 'label' => Mage::helper('M2ePro')->__('Duplicate'), + 'onclick' => "AmazonTemplateDescriptionObj.duplicate_click('{$headId}')", + 'class' => 'add M2ePro_duplicate_button' ) ); $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'CommonObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'CommonObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); } @@ -88,6 +95,7 @@ public function __construct() $this->_addButton( 'save', array( + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'AmazonTemplateDescriptionObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -97,7 +105,9 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( + 'save', + array( + 'id' => 'save_button', 'label' => Mage::helper('M2ePro')->__('Save'), 'onclick' => 'AmazonTemplateDescriptionObj.save_click(' . '\'\',' @@ -109,7 +119,9 @@ public function __construct() ); $this->_addButton( - 'save_and_continue', array( + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), 'onclick' => 'AmazonTemplateDescriptionObj.save_and_edit_click(' . '\'\',' @@ -128,6 +140,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/ProductTaxCode/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/ProductTaxCode/Edit.php index 29827e8f6..f82ae5a4f 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/ProductTaxCode/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/ProductTaxCode/Edit.php @@ -30,7 +30,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Product Tax Code Policy "%template_title%"', $componentName, + 'Edit %component_name% Product Tax Code Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -65,10 +66,12 @@ public function __construct() // --------------------------------------- $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'AmazonTemplateProductTaxCodeObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'AmazonTemplateProductTaxCodeObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); // --------------------------------------- @@ -78,21 +81,25 @@ public function __construct() ) { // --------------------------------------- $this->_addButton( - 'duplicate', array( - 'label' => Mage::helper('M2ePro')->__('Duplicate'), - 'onclick' => 'AmazonTemplateProductTaxCodeObj.duplicate_click' - .'(\'amazon-template-TaxCode\')', - 'class' => 'add M2ePro_duplicate_button' + 'duplicate', + array( + 'id' => 'duplicate_button', + 'label' => Mage::helper('M2ePro')->__('Duplicate'), + 'onclick' => 'AmazonTemplateProductTaxCodeObj.duplicate_click' + . '(\'amazon-template-TaxCode\')', + 'class' => 'add M2ePro_duplicate_button' ) ); // --------------------------------------- // --------------------------------------- $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'AmazonTemplateProductTaxCodeObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'AmazonTemplateProductTaxCodeObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); // --------------------------------------- @@ -100,29 +107,33 @@ public function __construct() // --------------------------------------- $this->_addButton( - 'save', array( - 'label' => Mage::helper('M2ePro')->__('Save'), - 'onclick' => 'AmazonTemplateProductTaxCodeObj.save_click(' - . '\'\',' - . '\'' . $this->getSaveConfirmationText() . '\',' - . '\'' . Ess_M2ePro_Block_Adminhtml_Amazon_Template_Grid::TEMPLATE_PRODUCT_TAX_CODE . '\'' - . ')', - 'class' => 'save' + 'save', + array( + 'id' => 'save_button', + 'label' => Mage::helper('M2ePro')->__('Save'), + 'onclick' => 'AmazonTemplateProductTaxCodeObj.save_click(' + . '\'\',' + . '\'' . $this->getSaveConfirmationText() . '\',' + . '\'' . Ess_M2ePro_Block_Adminhtml_Amazon_Template_Grid::TEMPLATE_PRODUCT_TAX_CODE . '\'' + . ')', + 'class' => 'save' ) ); // --------------------------------------- // --------------------------------------- $this->_addButton( - 'save_and_continue', array( - 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), - 'onclick' => 'AmazonTemplateProductTaxCodeObj.save_and_edit_click(' - . '\'\',' - . 'undefined,' - . '\'' . $this->getSaveConfirmationText() . '\',' - . '\'' . Ess_M2ePro_Block_Adminhtml_Amazon_Template_Grid::TEMPLATE_PRODUCT_TAX_CODE . '\'' - . ')', - 'class' => 'save' + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', + 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), + 'onclick' => 'AmazonTemplateProductTaxCodeObj.save_and_edit_click(' + . '\'\',' + . 'undefined,' + . '\'' . $this->getSaveConfirmationText() . '\',' + . '\'' . Ess_M2ePro_Block_Adminhtml_Amazon_Template_Grid::TEMPLATE_PRODUCT_TAX_CODE . '\'' + . ')', + 'class' => 'save' ) ); // --------------------------------------- @@ -133,6 +144,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/SellingFormat/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/SellingFormat/Edit.php index f56face7d..4dd0dde63 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/SellingFormat/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/SellingFormat/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Selling Policy "%template_title%"', $componentName, + 'Edit %component_name% Selling Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -51,10 +52,12 @@ public function __construct() $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'AmazonTemplateSellingFormatObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'AmazonTemplateSellingFormatObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); @@ -63,19 +66,23 @@ public function __construct() if (!$isSaveAndClose && Mage::helper('M2ePro/Data_Global')->getValue('temp_data') && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) { $this->_addButton( - 'duplicate', array( - 'label' => Mage::helper('M2ePro')->__('Duplicate'), - 'onclick' => 'AmazonTemplateSellingFormatObj.duplicate_click' - .'(\'amazon-template-sellingFormat\')', - 'class' => 'add M2ePro_duplicate_button' + 'duplicate', + array( + 'id' => 'duplicate_button', + 'label' => Mage::helper('M2ePro')->__('Duplicate'), + 'onclick' => 'AmazonTemplateSellingFormatObj.duplicate_click' + . '(\'amazon-template-sellingFormat\')', + 'class' => 'add M2ePro_duplicate_button' ) ); $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'AmazonTemplateSellingFormatObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'AmazonTemplateSellingFormatObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); } @@ -86,7 +93,7 @@ public function __construct() $this->_addButton( 'save', array( - 'id' => 'save_and_close', + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'AmazonTemplateSellingFormatObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -96,7 +103,9 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( + 'save', + array( + 'id' => 'save_button', 'label' => Mage::helper('M2ePro')->__('Save'), 'onclick' => 'AmazonTemplateSellingFormatObj.save_click(' . '\'\',' @@ -108,7 +117,9 @@ public function __construct() ); $this->_addButton( - 'save_and_continue', array( + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), 'onclick' => 'AmazonTemplateSellingFormatObj.save_and_edit_click(' . '\'\',' @@ -127,6 +138,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Shipping/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Shipping/Edit.php index 7e7eccdc7..c5e5bcfb8 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Shipping/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Shipping/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Shipping Policy "%template_title%"', $componentName, + 'Edit %component_name% Shipping Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -57,10 +58,12 @@ public function __construct() // --------------------------------------- $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'AmazonTemplateShippingObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'AmazonTemplateShippingObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); // --------------------------------------- @@ -72,21 +75,25 @@ public function __construct() ) { // --------------------------------------- $this->_addButton( - 'duplicate', array( - 'label' => Mage::helper('M2ePro')->__('Duplicate'), - 'onclick' => 'AmazonTemplateShippingObj.duplicate_click' - .'(\'amazon-template-shipping\')', - 'class' => 'add M2ePro_duplicate_button' + 'duplicate', + array( + 'id' => 'duplicate_button', + 'label' => Mage::helper('M2ePro')->__('Duplicate'), + 'onclick' => 'AmazonTemplateShippingObj.duplicate_click' + . '(\'amazon-template-shipping\')', + 'class' => 'add M2ePro_duplicate_button' ) ); // --------------------------------------- // --------------------------------------- $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'AmazonTemplateShippingObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'AmazonTemplateShippingObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); // --------------------------------------- @@ -100,7 +107,7 @@ public function __construct() $this->_addButton( 'save', array( - 'id' => 'save_and_close', + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'AmazonTemplateShippingObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -110,27 +117,31 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( - 'label' => Mage::helper('M2ePro')->__('Save'), - 'onclick' => 'AmazonTemplateShippingObj.save_click(' + 'save', + array( + 'id' => 'save_button', + 'label' => Mage::helper('M2ePro')->__('Save'), + 'onclick' => 'AmazonTemplateShippingObj.save_click(' . '\'\',' . '\'' . $this->getSaveConfirmationText() . '\',' . '\'' . Ess_M2ePro_Block_Adminhtml_Amazon_Template_Grid::TEMPLATE_SHIPPING . '\'' . ')', - 'class' => 'save' + 'class' => 'save' ) ); $this->_addButton( - 'save_and_continue', array( - 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), - 'onclick' => 'AmazonTemplateShippingObj.save_and_edit_click(' + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', + 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), + 'onclick' => 'AmazonTemplateShippingObj.save_and_edit_click(' . '\'\',' . 'undefined,' . '\'' . $this->getSaveConfirmationText() . '\',' . '\'' . Ess_M2ePro_Block_Adminhtml_Amazon_Template_Grid::TEMPLATE_SHIPPING . '\'' . ')', - 'class' => 'save' + 'class' => 'save' ) ); } @@ -141,6 +152,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Synchronization/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Synchronization/Edit.php index f1bbe7b9d..978ed7f0a 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Synchronization/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Amazon/Template/Synchronization/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Synchronization Policy "%template_title%"', $componentName, + 'Edit %component_name% Synchronization Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -54,10 +55,12 @@ public function __construct() $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'AmazonTemplateSynchronizationObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'AmazonTemplateSynchronizationObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); @@ -66,19 +69,23 @@ public function __construct() if (!$isSaveAndClose && Mage::helper('M2ePro/Data_Global')->getValue('temp_data') && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) { $this->_addButton( - 'duplicate', array( - 'label' => Mage::helper('M2ePro')->__('Duplicate'), - 'onclick' => 'AmazonTemplateSynchronizationObj.duplicate_click' - .'(\'amazon-template-synchronization\')', - 'class' => 'add M2ePro_duplicate_button' + 'duplicate', + array( + 'id' => 'duplicate_button', + 'label' => Mage::helper('M2ePro')->__('Duplicate'), + 'onclick' => 'AmazonTemplateSynchronizationObj.duplicate_click' + . '(\'amazon-template-synchronization\')', + 'class' => 'add M2ePro_duplicate_button' ) ); $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'AmazonTemplateSynchronizationObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'AmazonTemplateSynchronizationObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); } @@ -89,7 +96,7 @@ public function __construct() $this->_addButton( 'save', array( - 'id' => 'save_and_close', + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'AmazonTemplateSynchronizationObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -99,7 +106,9 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( + 'save', + array( + 'id' => 'save_button', 'label' => Mage::helper('M2ePro')->__('Save'), 'onclick' => 'AmazonTemplateSynchronizationObj.save_click(' . '\'\',' @@ -111,7 +120,9 @@ public function __construct() ); $this->_addButton( - 'save_and_continue', array( + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), 'onclick' => 'AmazonTemplateSynchronizationObj.save_and_edit_click(' . '\'\',' @@ -130,6 +141,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Account/PickupStore/Edit/Tabs/BusinessHours.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Account/PickupStore/Edit/Tabs/BusinessHours.php index 6cc2ca341..ba987ecbd 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Account/PickupStore/Edit/Tabs/BusinessHours.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Account/PickupStore/Edit/Tabs/BusinessHours.php @@ -72,11 +72,16 @@ protected function prepareHoursData($hoursData, $key) $parsedSettings = array(); foreach ($data[$key] as $day => $daySettings) { - $fromHours = date('G', strtotime($daySettings['open'])); - $fromMinutes = date('i', strtotime($daySettings['open'])); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $openDateTime = $helper->createGmtDateTime($daySettings['open']); + $closeDateTime = $helper->createGmtDateTime($daySettings['close']); - $toHours = date('G', strtotime($daySettings['close'])); - $toMinutes = date('i', strtotime($daySettings['close'])); + $fromHours = $openDateTime->format('G'); + $fromMinutes = $openDateTime->format('i'); + + $toHours = $closeDateTime->format('G'); + $toMinutes = $closeDateTime->format('i'); $parsedSettings[$day] = array( 'from_hours' => $fromHours == 0 ? 24 : $fromHours, diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Feedback/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Feedback/Grid.php index bff9059e7..bc1daac6d 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Feedback/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Feedback/Grid.php @@ -190,7 +190,14 @@ public function callbackColumnEbayItemId($value, $row, $column, $isExport) public function callbackColumnBuyerFeedbackDate($value, $row, $column, $isExport) { - if (strtotime($row->getData('buyer_feedback_date')) < strtotime('2001-01-02')) { + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $buyerFeedbackDate = (int)$helper->createGmtDateTime($row->getData('buyer_feedback_date')) + ->format('U'); + $comparedDate = (int)$helper->createGmtDateTime('2001-01-02') + ->format('U'); + + if ($buyerFeedbackDate < $comparedDate) { return Mage::helper('M2ePro')->__('N/A'); } @@ -199,7 +206,14 @@ public function callbackColumnBuyerFeedbackDate($value, $row, $column, $isExport public function callbackColumnSellerFeedbackDate($value, $row, $column, $isExport) { - if (strtotime($row->getData('seller_feedback_date')) < strtotime('2001-01-02')) { + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $sellerFeedbackDate = (int)$helper->createGmtDateTime($row->getData('seller_feedback_date')) + ->format('U'); + $comparedDate = (int)$helper->createGmtDateTime('2001-01-02') + ->format('U'); + + if ($sellerFeedbackDate < $comparedDate) { return Mage::helper('M2ePro')->__('N/A'); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/Grid.php index 8586783aa..196decf55 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Listing/Grid.php @@ -10,16 +10,12 @@ class Ess_M2ePro_Block_Adminhtml_Ebay_Listing_Grid extends Ess_M2ePro_Block_Admi { const MASS_ACTION_ID_EDIT_PARTS_COMPATIBILITY = 'editPartsCompatibilityMode'; - /** @var Ess_M2ePro_Model_Resource_Ebay_Listing */ - protected $_ebayListingResourceModel; - //######################################## public function __construct() { parent::__construct(); $this->setId('ebayListingGrid'); - $this->_ebayListingResourceModel = Mage::getResourceModel('M2ePro/Ebay_Listing'); } protected function _prepareCollection() @@ -37,6 +33,36 @@ protected function _prepareCollection() array('marketplace_title'=>'title') ); + $structureHelper = Mage::helper('M2ePro/Module_Database_Structure'); + + $m2eproListing = $structureHelper->getTableNameWithPrefix('m2epro_listing'); + $m2eproEbayListing = $structureHelper->getTableNameWithPrefix('m2epro_ebay_listing'); + $m2eproListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_listing_product'); + $m2eproEbayListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_ebay_listing_product'); + + $sql = "SELECT + l.id AS listing_id, + COUNT(lp.id) AS products_total_count, + COUNT(CASE WHEN lp.status = 2 THEN lp.id END) AS products_active_count, + COUNT(CASE WHEN lp.status != 2 THEN lp.id END) AS products_inactive_count, + IFNULL(SUM(elp.online_qty_sold), 0) AS items_sold_count + FROM `{$m2eproListing}` AS `l` + INNER JOIN `{$m2eproEbayListing}` AS `el` ON l.id = el.listing_id + LEFT JOIN `{$m2eproListingProduct}` AS `lp` ON l.id = lp.listing_id + LEFT JOIN `{$m2eproEbayListingProduct}` AS `elp` ON lp.id = elp.listing_product_id + GROUP BY listing_id"; + + $collection->getSelect()->joinLeft( + array('t' => new Zend_Db_Expr('('.$sql.')')), + 'main_table.id=t.listing_id', + array( + 'products_total_count' => 'products_total_count', + 'products_active_count' => 'products_active_count', + 'products_inactive_count' => 'products_inactive_count', + 'items_sold_count' => 'items_sold_count' + ) + ); + $this->setCollection($collection); return parent::_prepareCollection(); @@ -87,6 +113,23 @@ protected function _prepareMassaction() //######################################## + protected function setColumns() + { + $this->addColumn( + 'items_sold_count', array( + 'header' => Mage::helper('M2ePro')->__('Sold QTY'), + 'align' => 'right', + 'width' => '100px', + 'type' => 'number', + 'index' => 'items_sold_count', + 'filter_index' => 't.items_sold_count', + 'frame_callback' => array($this, 'callbackColumnProductsCount') + ) + ); + + return $this; + } + protected function getColumnActionsItems() { $helper = Mage::helper('M2ePro'); @@ -211,45 +254,6 @@ protected function _prepareColumns() //######################################## - public function callbackColumnTotalProducts($value, $row, $column, $isExport) - { - $value = $this->_ebayListingResourceModel->getStatisticTotalCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - - public function callbackColumnListedProducts($value, $row, $column, $isExport) - { - $value = $this->_ebayListingResourceModel->getStatisticActiveCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - - public function callbackColumnInactiveProducts($value, $row, $column, $isExport) - { - $value = $this->_ebayListingResourceModel->getStatisticInactiveCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - public function callbackColumnTitle($value, $row, $column, $isExport) { $title = Mage::helper('M2ePro')->escapeHtml($value); diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template.php index 0e9125a56..f4ea35dc2 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template.php @@ -14,36 +14,27 @@ public function __construct() { parent::__construct(); - // Initialization block - // --------------------------------------- $this->setId('ebayTemplate'); $this->_blockGroup = 'M2ePro'; $this->_controller = 'adminhtml_ebay_template'; - // --------------------------------------- - // Set header text - // --------------------------------------- $this->_headerText = ''; - // --------------------------------------- - // Set buttons actions - // --------------------------------------- $this->removeButton('back'); $this->removeButton('reset'); $this->removeButton('delete'); $this->removeButton('save'); $this->removeButton('edit'); - // --------------------------------------- - // --------------------------------------- $this->_addButton( - 'add', array( - 'label' => Mage::helper('M2ePro')->__('Add Policy'), - 'onclick' => '', - 'class' => 'add add-button-drop-down' + 'add', + array( + 'id' => 'add_policy', + 'label' => Mage::helper('M2ePro')->__('Add Policy'), + 'onclick' => '', + 'class' => 'add add-button-drop-down' ) ); - // --------------------------------------- } //######################################## @@ -54,6 +45,7 @@ protected function getAddButtonJavascript() 'target_css_class' => 'add-button-drop-down', 'items' => array( array( + 'id' => 'add_policy_payment', 'url' => $this->getUrl( '*/adminhtml_ebay_template/new', array( @@ -64,6 +56,7 @@ protected function getAddButtonJavascript() 'label' => Mage::helper('M2ePro')->__('Payment') ), array( + 'id' => 'add_policy_shipping', 'url' => $this->getUrl( '*/adminhtml_ebay_template/new', array( @@ -74,6 +67,7 @@ protected function getAddButtonJavascript() 'label' => Mage::helper('M2ePro')->__('Shipping') ), array( + 'id' => 'add_policy_return', 'url' => $this->getUrl( '*/adminhtml_ebay_template/new', array( @@ -84,6 +78,7 @@ protected function getAddButtonJavascript() 'label' => Mage::helper('M2ePro')->__('Return') ), array( + 'id' => 'add_policy_selling', 'url' => $this->getUrl( '*/adminhtml_ebay_template/new', array( @@ -94,6 +89,7 @@ protected function getAddButtonJavascript() 'label' => Mage::helper('M2ePro')->__('Selling') ), array( + 'id' => 'add_policy_description', 'url' => $this->getUrl( '*/adminhtml_ebay_template/new', array( @@ -104,6 +100,7 @@ protected function getAddButtonJavascript() 'label' => Mage::helper('M2ePro')->__('Description') ), array( + 'id' => 'add_policy_synchronization', 'url' => $this->getUrl( '*/adminhtml_ebay_template/new', array( diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template/Edit.php index e347ac580..7ae72a857 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Ebay/Template/Edit.php @@ -74,10 +74,12 @@ public function __construct() if ((bool)$this->getRequest()->getParam('back', false)) { $url = $this->getUrl('*/adminhtml_ebay_template/index'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'EbayTemplateEditObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'EbayTemplateEditObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); } @@ -86,6 +88,7 @@ public function __construct() $this->_addButton( 'save', array( + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'EbayTemplateEditObj.saveAndClose(' . '\'' . $this->getUrl('*/adminhtml_ebay_template/save', array('_current' => true)) . '\',' @@ -113,10 +116,12 @@ public function __construct() } $this->_addButton( - 'duplicate', array( + 'duplicate', + array( + 'id' => 'duplicate_button', 'label' => Mage::helper('M2ePro')->__('Duplicate'), 'onclick' => 'EbayTemplateEditObj.duplicate_click( - \'ebay-template\', \''.$duplicateHeaderText.'\', \''.$nick.'\' + \'ebay-template\', \'' . $duplicateHeaderText . '\', \'' . $nick . '\' )', 'class' => 'add M2ePro_duplicate_button' ) @@ -126,7 +131,9 @@ public function __construct() if ($template->getId()) { $url = $this->getUrl('*/adminhtml_ebay_template/delete'); $this->_addButton( - 'delete', array( + 'delete', + array( + 'id' => 'delete_button', 'label' => Mage::helper('M2ePro')->__('Delete'), 'onclick' => 'EbayTemplateEditObj.delete_click(\'' . $url . '\')', 'class' => 'delete M2ePro_delete_button' @@ -146,7 +153,9 @@ public function __construct() $url = $this->getUrl('*/adminhtml_ebay_template/save'); $this->_addButton( - 'save', array( + 'save', + array( + 'id' => 'save_button', 'label' => Mage::helper('M2ePro')->__('Save'), 'onclick' => 'EbayTemplateEditObj.save_click(' . '\'' . $url . '\',' @@ -160,7 +169,9 @@ public function __construct() $backUrl = Mage::helper('M2ePro')->makeBackUrlParam('edit', array()); $url = $this->getUrl('*/adminhtml_ebay_template/save', array('back' => $backUrl)); $this->_addButton( - 'save_and_continue', array( + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), 'onclick' => 'EbayTemplateEditObj.save_and_edit_click(' . '\'' . $url . '\',' diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Grid.php index fe89076a7..b4742880a 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Grid.php @@ -62,8 +62,8 @@ protected function _prepareColumns() 'width' => '100px', 'type' => 'number', 'index' => 'products_total_count', - 'filter_index' => 'main_table.products_total_count', - 'frame_callback' => array($this, 'callbackColumnTotalProducts') + 'filter_index' => 't.products_total_count', + 'frame_callback' => array($this, 'callbackColumnProductsCount') ) ); @@ -74,8 +74,8 @@ protected function _prepareColumns() 'width' => '100px', 'type' => 'number', 'index' => 'products_active_count', - 'filter_index' => 'main_table.products_active_count', - 'frame_callback' => array($this, 'callbackColumnListedProducts') + 'filter_index' => 't.products_active_count', + 'frame_callback' => array($this, 'callbackColumnProductsCount') ) ); @@ -86,11 +86,13 @@ protected function _prepareColumns() 'width' => '100px', 'type' => 'number', 'index' => 'products_inactive_count', - 'filter_index' => 'main_table.products_inactive_count', - 'frame_callback' => array($this, 'callbackColumnInactiveProducts') + 'filter_index' => 't.products_inactive_count', + 'frame_callback' => array($this, 'callbackColumnProductsCount') ) ); + $this->setColumns(); + $this->addColumn( 'actions', array( 'header' => Mage::helper('M2ePro')->__('Actions'), @@ -110,6 +112,11 @@ protected function _prepareColumns() return parent::_prepareColumns(); } + protected function setColumns() + { + return null; + } + //######################################## public function callbackColumnTitle($value, $row, $column, $isExport) @@ -122,9 +129,9 @@ protected function callbackFilterTitle($collection, $column) return null; } - //######################################## + // --------------------------------------- - protected function getColumnValue($value) + public function callbackColumnProductsCount($value, $row, $column, $isExport) { if ($value === null || $value === '') { $value = Mage::helper('M2ePro')->__('N/A'); diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Moving/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Moving/Grid.php index 4eef70d8a..e9b197ecb 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Moving/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Listing/Moving/Grid.php @@ -138,16 +138,14 @@ public function callbackColumnStore($value, $row, $column, $isExport) return ' '.$storeName; } - public function callbackColumnSourceTotalItems($value, $row, $column, $isExport) + public function callbackColumnSource($value, $row, $column, $isExport) { - $componentMode = $this->getRequest()->getParam('componentMode'); - $value = Mage::getResourceModel('M2ePro/' . ucfirst($componentMode) . '_Listing')->getStatisticTotalCount($row->id); - - if ($value <= 0) { - $value = '0'; - } + return ' '.$value; + } - return $value; + public function callbackColumnSourceTotalItems($value, $row, $column, $isExport) + { + return $value.' '; } public function callbackColumnActions($value, $row, $column, $isExport) diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Listing/Grid.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Listing/Grid.php index b8e31d6d2..689f20e97 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Listing/Grid.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Listing/Grid.php @@ -8,16 +8,10 @@ class Ess_M2ePro_Block_Adminhtml_Walmart_Listing_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Grid { - /** @var Ess_M2ePro_Model_Resource_Walmart_Listing */ - protected $_walmartListingResourceModel; - - //######################################## - public function __construct() { parent::__construct(); $this->setId('walmartListingGrid'); - $this->_walmartListingResourceModel = Mage::getResourceModel('M2ePro/Walmart_Listing'); } protected function _prepareCollection() @@ -66,6 +60,32 @@ protected function _prepareCollection() ); // --------------------------------------- + $structureHelper = Mage::helper('M2ePro/Module_Database_Structure'); + + $m2eproListing = $structureHelper->getTableNameWithPrefix('m2epro_listing'); + $m2eproWalmartListing = $structureHelper->getTableNameWithPrefix('m2epro_walmart_listing'); + $m2eproListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_listing_product'); + + $sql = "SELECT + l.id AS listing_id, + COUNT(lp.id) AS products_total_count, + COUNT(CASE WHEN lp.status = 2 THEN lp.id END) AS products_active_count, + COUNT(CASE WHEN lp.status != 2 THEN lp.id END) AS products_inactive_count + FROM `{$m2eproListing}` AS `l` + INNER JOIN `{$m2eproWalmartListing}` AS `wl` ON l.id = wl.listing_id + LEFT JOIN `{$m2eproListingProduct}` AS `lp` ON l.id = lp.listing_id + GROUP BY listing_id"; + + $collection->getSelect()->joinLeft( + array('t' => new Zend_Db_Expr('('.$sql.')')), + 'main_table.id=t.listing_id', + array( + 'products_total_count' => 'products_total_count', + 'products_active_count' => 'products_active_count', + 'products_inactive_count' => 'products_inactive_count', + ) + ); + $this->setCollection($collection); return parent::_prepareCollection(); @@ -248,45 +268,6 @@ protected function getColumnActionsItems() //######################################## - public function callbackColumnTotalProducts($value, $row, $column, $isExport) - { - $value = $this->_walmartListingResourceModel->getStatisticTotalCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - - public function callbackColumnListedProducts($value, $row, $column, $isExport) - { - $value = $this->_walmartListingResourceModel->getStatisticActiveCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - - public function callbackColumnInactiveProducts($value, $row, $column, $isExport) - { - $value = $this->_walmartListingResourceModel->getStatisticInactiveCount($row->id); - - if ($value == 0) { - $value = '0'; - } - - return $value; - } - - //######################################## - public function callbackColumnTitle($value, $row, $column, $isExport) { $value = '' . diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template.php index 949571a6c..b41792731 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template.php @@ -14,36 +14,27 @@ public function __construct() { parent::__construct(); - // Initialization block - // --------------------------------------- $this->setId('walmartTemplate'); $this->_blockGroup = 'M2ePro'; $this->_controller = 'adminhtml_walmart_template'; - // --------------------------------------- - // Set header text - // --------------------------------------- $this->_headerText = ''; - // --------------------------------------- - // Set buttons actions - // --------------------------------------- $this->removeButton('back'); $this->removeButton('reset'); $this->removeButton('delete'); $this->removeButton('save'); $this->removeButton('edit'); - // --------------------------------------- - // --------------------------------------- $this->_addButton( - 'add', array( - 'label' => Mage::helper('M2ePro')->__('Add Policy'), - 'onclick' => '', - 'class' => 'add add-button-drop-down' + 'add', + array( + 'id' => 'add_policy', + 'label' => Mage::helper('M2ePro')->__('Add Policy'), + 'onclick' => '', + 'class' => 'add add-button-drop-down' ) ); - // ------------------------------------- } public function getHeaderHtml() @@ -52,6 +43,7 @@ public function getHeaderHtml() 'target_css_class' => 'add-button-drop-down', 'items' => array( array( + 'id' => 'add_policy_category', 'url' => $this->getUrl( '*/adminhtml_walmart_template/new', array( @@ -61,6 +53,7 @@ public function getHeaderHtml() 'label' => Mage::helper('M2ePro')->__('Category') ), array( + 'id' => 'add_policy_description', 'url' => $this->getUrl( '*/adminhtml_walmart_template/new', array( @@ -70,6 +63,7 @@ public function getHeaderHtml() 'label' => Mage::helper('M2ePro')->__('Description') ), array( + 'id' => 'add_policy_selling', 'url' => $this->getUrl( '*/adminhtml_walmart_template/new', array( @@ -79,6 +73,7 @@ public function getHeaderHtml() 'label' => Mage::helper('M2ePro')->__('Selling') ), array( + 'id' => 'add_policy_synchronization', 'url' => $this->getUrl( '*/adminhtml_walmart_template/new', array( diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Category/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Category/Edit.php index 3d757c3e3..de91e8223 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Category/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Category/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Category Policy "%template_title%"', $componentName, + 'Edit %component_name% Category Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -54,10 +55,12 @@ public function __construct() $url = Mage::helper('M2ePro')->getBackUrl('index'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'WalmartTemplateCategoryObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'WalmartTemplateCategoryObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); @@ -66,7 +69,9 @@ public function __construct() if (!$isSaveAndClose && $this->isEditMode()) { $headId = 'walmart-template-category'; $this->_addButton( - 'duplicate', array( + 'duplicate', + array( + 'id' => 'duplicate_button', 'label' => Mage::helper('M2ePro')->__('Duplicate'), 'onclick' => "WalmartTemplateCategoryObj.duplicate_click('{$headId}')", 'class' => 'add M2ePro_duplicate_button' @@ -74,10 +79,12 @@ public function __construct() ); $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'WalmartTemplateCategoryObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'WalmartTemplateCategoryObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); } @@ -88,7 +95,7 @@ public function __construct() $this->_addButton( 'save', array( - 'id' => 'save_and_close', + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'WalmartTemplateCategoryObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -98,27 +105,31 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( - 'label' => Mage::helper('M2ePro')->__('Save'), - 'onclick' => 'WalmartTemplateCategoryObj.save_click(' - . '\'\',' - . '\'' . $this->getSaveConfirmationText() . '\',' - . '\'' . Ess_M2ePro_Block_Adminhtml_Walmart_Template_Grid::TEMPLATE_CATEGORY . '\'' - . ')', - 'class' => 'save' + 'save', + array( + 'id' => 'save_button', + 'label' => Mage::helper('M2ePro')->__('Save'), + 'onclick' => 'WalmartTemplateCategoryObj.save_click(' + . '\'\',' + . '\'' . $this->getSaveConfirmationText() . '\',' + . '\'' . Ess_M2ePro_Block_Adminhtml_Walmart_Template_Grid::TEMPLATE_CATEGORY . '\'' + . ')', + 'class' => 'save' ) ); $this->_addButton( - 'save_and_continue', array( - 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), - 'onclick' => 'WalmartTemplateCategoryObj.save_and_edit_click(' - . '\'\',' - . 'undefined,' - . '\'' . $this->getSaveConfirmationText() . '\',' - . '\'' . Ess_M2ePro_Block_Adminhtml_Walmart_Template_Grid::TEMPLATE_CATEGORY . '\'' - . ')', - 'class' => 'save' + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', + 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), + 'onclick' => 'WalmartTemplateCategoryObj.save_and_edit_click(' + . '\'\',' + . 'undefined,' + . '\'' . $this->getSaveConfirmationText() . '\',' + . '\'' . Ess_M2ePro_Block_Adminhtml_Walmart_Template_Grid::TEMPLATE_CATEGORY . '\'' + . ')', + 'class' => 'save' ) ); } @@ -129,6 +140,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Description/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Description/Edit.php index afdb16779..a6b7968bf 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Description/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Description/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Description Policy "%template_title%"', $componentName, + 'Edit %component_name% Description Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -54,10 +55,12 @@ public function __construct() $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'CommonObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'CommonObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); @@ -66,7 +69,9 @@ public function __construct() if (!$isSaveAndClose && $this->isEditMode()) { $headId = 'walmart-template-description'; $this->_addButton( - 'duplicate', array( + 'duplicate', + array( + 'id' => 'duplicate_button', 'label' => Mage::helper('M2ePro')->__('Duplicate'), 'onclick' => "WalmartTemplateDescriptionObj.duplicate_click('{$headId}')", 'class' => 'add M2ePro_duplicate_button' @@ -74,10 +79,12 @@ public function __construct() ); $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'CommonObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'CommonObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); } @@ -88,7 +95,7 @@ public function __construct() $this->_addButton( 'save', array( - 'id' => 'save_and_close', + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'WalmartTemplateDescriptionObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -98,7 +105,9 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( + 'save', + array( + 'id' => 'save_button', 'label' => Mage::helper('M2ePro')->__('Save'), 'onclick' => 'WalmartTemplateDescriptionObj.save_click(' . '\'\',' @@ -110,7 +119,9 @@ public function __construct() ); $this->_addButton( - 'save_and_continue', array( + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), 'onclick' => 'WalmartTemplateDescriptionObj.save_and_edit_click(' . '\'\',' @@ -129,6 +140,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/SellingFormat/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/SellingFormat/Edit.php index 03aff7268..f314416bf 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/SellingFormat/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/SellingFormat/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Selling Policy "%template_title%"', $componentName, + 'Edit %component_name% Selling Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -51,10 +52,12 @@ public function __construct() $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'WalmartTemplateSellingFormatObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'WalmartTemplateSellingFormatObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); @@ -64,19 +67,23 @@ public function __construct() && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId() ) { $this->_addButton( - 'duplicate', array( - 'label' => Mage::helper('M2ePro')->__('Duplicate'), - 'onclick' => 'WalmartTemplateSellingFormatObj.duplicate_click' - .'(\'walmart-template-sellingFormat\')', - 'class' => 'add M2ePro_duplicate_button' + 'duplicate', + array( + 'id' => 'duplicate_button', + 'label' => Mage::helper('M2ePro')->__('Duplicate'), + 'onclick' => 'WalmartTemplateSellingFormatObj.duplicate_click' + . '(\'walmart-template-sellingFormat\')', + 'class' => 'add M2ePro_duplicate_button' ) ); $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'WalmartTemplateSellingFormatObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'WalmartTemplateSellingFormatObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); } @@ -87,7 +94,7 @@ public function __construct() $this->_addButton( 'save', array( - 'id' => 'save_and_close', + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'WalmartTemplateSellingFormatObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -97,7 +104,9 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( + 'save', + array( + 'id' => 'save_button', 'label' => Mage::helper('M2ePro')->__('Save'), 'onclick' => 'WalmartTemplateSellingFormatObj.save_click(' . '\'\',' @@ -109,7 +118,9 @@ public function __construct() ); $this->_addButton( - 'save_and_continue', array( + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), 'onclick' => 'WalmartTemplateSellingFormatObj.save_and_edit_click(' . '\'\',' @@ -128,6 +139,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Synchronization/Edit.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Synchronization/Edit.php index 4c003a425..12b6386ba 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Synchronization/Edit.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Walmart/Template/Synchronization/Edit.php @@ -25,7 +25,8 @@ public function __construct() if ($this->isEditMode()) { $this->_headerText = Mage::helper('M2ePro')->__( - 'Edit %component_name% Synchronization Policy "%template_title%"', $componentName, + 'Edit %component_name% Synchronization Policy "%template_title%"', + $componentName, $this->escapeHtml(Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getTitle()) ); } else { @@ -54,10 +55,12 @@ public function __construct() $url = Mage::helper('M2ePro')->getBackUrl('list'); $this->_addButton( - 'back', array( - 'label' => Mage::helper('M2ePro')->__('Back'), - 'onclick' => 'WalmartTemplateSynchronizationObj.back_click(\'' . $url . '\')', - 'class' => 'back' + 'back', + array( + 'id' => 'back_button', + 'label' => Mage::helper('M2ePro')->__('Back'), + 'onclick' => 'WalmartTemplateSynchronizationObj.back_click(\'' . $url . '\')', + 'class' => 'back' ) ); @@ -66,19 +69,23 @@ public function __construct() if (!$isSaveAndClose && Mage::helper('M2ePro/Data_Global')->getValue('temp_data') && Mage::helper('M2ePro/Data_Global')->getValue('temp_data')->getId()) { $this->_addButton( - 'duplicate', array( - 'label' => Mage::helper('M2ePro')->__('Duplicate'), - 'onclick' => 'WalmartTemplateSynchronizationObj.duplicate_click' - .'(\'walmart-template-synchronization\')', - 'class' => 'add M2ePro_duplicate_button' + 'duplicate', + array( + 'id' => 'duplicate_button', + 'label' => Mage::helper('M2ePro')->__('Duplicate'), + 'onclick' => 'WalmartTemplateSynchronizationObj.duplicate_click' + . '(\'walmart-template-synchronization\')', + 'class' => 'add M2ePro_duplicate_button' ) ); $this->_addButton( - 'delete', array( - 'label' => Mage::helper('M2ePro')->__('Delete'), - 'onclick' => 'WalmartTemplateSynchronizationObj.delete_click()', - 'class' => 'delete M2ePro_delete_button' + 'delete', + array( + 'id' => 'delete_button', + 'label' => Mage::helper('M2ePro')->__('Delete'), + 'onclick' => 'WalmartTemplateSynchronizationObj.delete_click()', + 'class' => 'delete M2ePro_delete_button' ) ); } @@ -89,7 +96,7 @@ public function __construct() $this->_addButton( 'save', array( - 'id' => 'save_and_close', + 'id' => 'save_and_close_button', 'label' => Mage::helper('M2ePro')->__('Save And Close'), 'onclick' => 'WalmartTemplateSynchronizationObj.saveAndClose(' . '\'' . $this->getUrl('*/*/save', array('_current' => true)) . '\',' @@ -99,7 +106,9 @@ public function __construct() ); } else { $this->_addButton( - 'save', array( + 'save', + array( + 'id' => 'save_button', 'label' => Mage::helper('M2ePro')->__('Save'), 'onclick' => 'WalmartTemplateSynchronizationObj.save_click(' . '\'\',' @@ -111,7 +120,9 @@ public function __construct() ); $this->_addButton( - 'save_and_continue', array( + 'save_and_continue', + array( + 'id' => 'save_and_continue_button', 'label' => Mage::helper('M2ePro')->__('Save And Continue Edit'), 'onclick' => 'WalmartTemplateSynchronizationObj.save_and_edit_click(' . '\'\',' @@ -130,6 +141,7 @@ public function __construct() protected function isEditMode() { $templateModel = Mage::helper('M2ePro/Data_Global')->getValue('temp_data'); + return $templateModel && $templateModel->getId(); } diff --git a/app/code/community/Ess/M2ePro/Block/Adminhtml/Widget/Button/DropDown.php b/app/code/community/Ess/M2ePro/Block/Adminhtml/Widget/Button/DropDown.php index 12d46791e..ebff0fdd8 100644 --- a/app/code/community/Ess/M2ePro/Block/Adminhtml/Widget/Button/DropDown.php +++ b/app/code/community/Ess/M2ePro/Block/Adminhtml/Widget/Button/DropDown.php @@ -36,13 +36,14 @@ public function getDropDownHtml() $url = $item['url']; $label = $item['label']; + $id = isset($item['id']) ? $item['id'] : ''; $target = isset($item['target']) ? $item['target'] : '_self'; $onclick = isset($item['onclick']) ? $item['onclick'] : ''; $style = (string)$this->getStyle(); $html .= <<{$label} +
  • {$label}
  • HTML; } diff --git a/app/code/community/Ess/M2ePro/CHANGELOG b/app/code/community/Ess/M2ePro/CHANGELOG index c3aff3aa3..3f23a40e0 100644 --- a/app/code/community/Ess/M2ePro/CHANGELOG +++ b/app/code/community/Ess/M2ePro/CHANGELOG @@ -1,4 +1,23 @@ -* 6.21.3 (27/04/2022) +* 6.22.1 (24/05/2022) + +Common: [Fixed] End Date expiration for Special Price was not detected and Product Price value wasn't submitted during the Revise action [#3435] +Common: [Improved] Some UI text updates [#3511] +eBay: [Added] Sold Qty column in the M2E Pro Listing grid [#3264] +Amazon: [Fixed] Unable to update the shipping status on Amazon without carrier and tracking number data [#3595] +Amazon: [Fixed] Undefined offset: 0 in Magento/Product/Rule/Condition/Product.php on line 101 when trying to use the Advanced Filter at the step of adding Magento Products to Listing [#3537] +Amazon: [Improved] Changes in the buyer-initiated order cancelation process [#3472] +Walmart: [Fixed] Error "Item (Ess\M2ePro\Model\Walmart\Listing\Product\Action\Processing) with the same ID already exists" [#1201] +Walmart: [Fixed] Unable to save Manual Variational Attributes/Options matches [#2931] + +* 6.22.0.1 (17/05/2022) + +Common: [Fixed] End Date expiration for Special Price was not detected and Product Price value wasn't submitted during the Revise action [#3435] +Amazon: [Fixed] Unable to update the shipping status on Amazon without carrier and tracking number data [#3595] +Amazon: [Fixed] Undefined offset: 0 in Magento/Product/Rule/Condition/Product.php on line 101 when trying to use the Advanced Filter at the step of adding Magento Products to Listing [#3537] +Amazon: [Improved] Changes in buyer-initiated order cancellation process [#3472] +eBay [Added] Sold Qty column in the M2E Pro Listing grid [#3264] + +* 6.21.3 (27/04/2022) Common: [Fixed] Issues with listing and mapping orders for Configurable Products with zero (0, 00, 000) size variations [#3350] eBay: [Fixed] "Invalid block type: Ess\M2ePro\Block\Adminhtml\Wizard\InstallationEbay\Notification" when downloading Rate Tables in the Shipping Policy [#3030] diff --git a/app/code/community/Ess/M2ePro/Helper/Client.php b/app/code/community/Ess/M2ePro/Helper/Client.php index a0d26bfcb..a4da2cfd3 100644 --- a/app/code/community/Ess/M2ePro/Helper/Client.php +++ b/app/code/community/Ess/M2ePro/Helper/Client.php @@ -51,7 +51,10 @@ public function updateLocationData($forceUpdate = false) { $dateLastCheck = Mage::helper('M2ePro/Module')->getRegistry()->getValue('/location/date_last_check/'); if ($dateLastCheck !== null) { - $dateLastCheck = strtotime($dateLastCheck); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $dateLastCheck = (int)$helper->createGmtDateTime($dateLastCheck) + ->format('U'); if (!$forceUpdate && Mage::helper('M2ePro')->getCurrentGmtDate(true) < $dateLastCheck + 60*60*24) { return; diff --git a/app/code/community/Ess/M2ePro/Helper/Data.php b/app/code/community/Ess/M2ePro/Helper/Data.php index 9257a9962..5021cc282 100644 --- a/app/code/community/Ess/M2ePro/Helper/Data.php +++ b/app/code/community/Ess/M2ePro/Helper/Data.php @@ -119,6 +119,11 @@ public function createCurrentGmtDateTime() // --------------------------------------- + /** + * @param $returnTimestamp + * @param $format + * @return int|string + */ public function getCurrentGmtDate($returnTimestamp = false, $format = null) { if ($returnTimestamp) { @@ -139,29 +144,6 @@ public function getCurrentTimezoneDate($returnTimestamp = false, $format = null) // --------------------------------------- - public function getDate($date, $returnTimestamp = false, $format = null) - { - if (is_numeric($date)) { - $result = (int)$date; - } else { - $result = strtotime($date); - } - - if ($format === null) { - $format = 'Y-m-d H:i:s'; - } - - $result = date($format, $result); - - if ($returnTimestamp) { - return strtotime($result); - } - - return $result; - } - - // --------------------------------------- - public function gmtDateToTimezone($dateGmt, $returnTimestamp = false, $format = null) { if ($returnTimestamp) { diff --git a/app/code/community/Ess/M2ePro/Helper/Magento.php b/app/code/community/Ess/M2ePro/Helper/Magento.php index bebdf229f..022f7885b 100644 --- a/app/code/community/Ess/M2ePro/Helper/Magento.php +++ b/app/code/community/Ess/M2ePro/Helper/Magento.php @@ -121,7 +121,7 @@ public function isCronWorking() { $minDateTime = new DateTime(Mage::helper('M2ePro')->getCurrentGmtDate(), new DateTimeZone('UTC')); $minDateTime->modify('-1 day'); - $minDateTime = Mage::helper('M2ePro')->getDate($minDateTime->format('U')); + $minDateTime = $minDateTime->format('Y-m-d H:i:s'); $collection = Mage::getModel('cron/schedule')->getCollection(); $collection->addFieldToFilter('executed_at', array('gt'=>$minDateTime)); diff --git a/app/code/community/Ess/M2ePro/Helper/Module/Cron.php b/app/code/community/Ess/M2ePro/Helper/Module/Cron.php index 688d352c1..a2191d925 100644 --- a/app/code/community/Ess/M2ePro/Helper/Module/Cron.php +++ b/app/code/community/Ess/M2ePro/Helper/Module/Cron.php @@ -76,7 +76,11 @@ public function isLastRunnerChangeMoreThan($interval, $isHours = false) return false; } - return Mage::helper('M2ePro')->getCurrentGmtDate(true) > strtotime($lastRunnerChange) + $interval; + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $lastRunnerChangeTimestamp = (int)$helper->createGmtDateTime($lastRunnerChange) + ->format('U'); + return $helper->getCurrentGmtDate(true) > $lastRunnerChangeTimestamp + $interval; } //######################################## @@ -102,7 +106,11 @@ public function isLastAccessMoreThan($interval, $isHours = false) return false; } - return Mage::helper('M2ePro')->getCurrentGmtDate(true) > strtotime($lastAccess) + $interval; + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $lastAccessTimestamp = (int)$helper->createGmtDateTime($lastAccess) + ->format('U'); + return $helper->getCurrentGmtDate(true) > $lastAccessTimestamp + $interval; } //######################################## @@ -128,7 +136,11 @@ public function isLastRunMoreThan($interval, $isHours = false) return false; } - return Mage::helper('M2ePro')->getCurrentGmtDate(true) > strtotime($lastRun) + $interval; + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $lastRunTimestamp = (int)$helper->createGmtDateTime($lastRun) + ->format('U'); + return $helper->getCurrentGmtDate(true) > $lastRunTimestamp + $interval; } //######################################## diff --git a/app/code/community/Ess/M2ePro/Helper/Module/Support.php b/app/code/community/Ess/M2ePro/Helper/Module/Support.php index f5ccc67e6..999d29c44 100644 --- a/app/code/community/Ess/M2ePro/Helper/Module/Support.php +++ b/app/code/community/Ess/M2ePro/Helper/Module/Support.php @@ -135,9 +135,6 @@ public function getSummaryInfo() ----- PHP INFO ----- {$this->getPhpInfo()} - ------ MYSQL INFO ----- -{$this->getMysqlInfo()} DATA; } @@ -156,18 +153,11 @@ public function getMainInfo() 'version' => Mage::helper('M2ePro/Module')->getPublicVersion() ); - $licenseKey = Mage::helper('M2ePro/Module_License')->getKey(); - $installationKey = Mage::helper('M2ePro/Module')->getInstallationKey(); - return << Mage::helper('M2ePro/Client')->getDomain(), 'ip' => Mage::helper('M2ePro/Client')->getIp(), - 'directory' => Mage::helper('M2ePro/Client')->getBaseDirectory() ); return <<getPhpSettings(); $phpInfo['api'] = Mage::helper('M2ePro/Client')->getPhpApiName(); $phpInfo['version'] = Mage::helper('M2ePro/Client')->getPhpVersion(); - $phpInfo['ini_file_location'] = Mage::helper('M2ePro/Client')->getPhpIniFileLoaded(); return <<getMysqlSettings(); - $mysqlInfo['api'] = Mage::helper('M2ePro/Client')->getMysqlApiName(); - $prefix = Mage::helper('M2ePro/Magento')->getDatabaseTablesPrefix(); - $mysqlInfo['prefix'] = $prefix != '' ? $prefix : 'Disabled'; - $mysqlInfo['version'] = Mage::helper('M2ePro/Client')->getMysqlVersion(); - $mysqlInfo['database'] = Mage::helper('M2ePro/Magento')->getDatabaseName(); - - return <<getCurrentIndex() != $this->getDefaultIndex()) { - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); + $currentTimeStamp = $helper->getCurrentGmtDate(true); $interval = self::MAX_INTERVAL_OF_RETURNING_TO_DEFAULT_BASEURL; $switchingDateTime = Mage::helper('M2ePro/Module')->getRegistry()->getValue( '/server/location/datetime_of_last_switching' ); - if ($switchingDateTime === null || strtotime($switchingDateTime) + $interval <= $currentTimeStamp) { + if ($switchingDateTime === null || + (int)$helper->createGmtDateTime($switchingDateTime)->format('U') + $interval <= $currentTimeStamp + ) { $this->setCurrentIndex($this->getDefaultIndex()); } } diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/Get/Items.php b/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/Get/Items.php index 536b7b632..7949dc503 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/Get/Items.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/Get/Items.php @@ -175,6 +175,11 @@ protected function prepareResponseData() $order['tax_registration_details'] = isset($orderData['tax_registration_details']) ? $orderData['tax_registration_details'] : array(); + $order['is_buyer_requested_cancel'] = isset($orderData['is_buyer_requested_cancel']) ? + (int)$orderData['is_buyer_requested_cancel'] : 0; + $order['buyer_cancel_reason'] = isset($orderData['buyer_cancel_reason']) ? + $orderData['buyer_cancel_reason'] : null; + $order['discount_details'] = isset($orderData['price']['discounts']) ? $orderData['price']['discounts'] : array(); diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/SendInvoice/ItemsRequester.php b/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/SendInvoice/ItemsRequester.php index 24acbcce9..5c5ccca17 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/SendInvoice/ItemsRequester.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Connector/Orders/SendInvoice/ItemsRequester.php @@ -50,9 +50,10 @@ public function process() array( 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK, 'server_hash' => $this->_processingServerHash, - 'expiration_date' => Mage::helper('M2ePro')->getDate( + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', Mage::helper('M2ePro')->getCurrentGmtDate(true) - + Ess_M2ePro_Model_Amazon_Order_Action_Processor::PENDING_REQUEST_MAX_LIFE_TIME + + Ess_M2ePro_Model_Amazon_Order_Action_Processor::PENDING_REQUEST_MAX_LIFE_TIME ) ) ); diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product.php index 009f4d2bc..406dafc2e 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product.php @@ -981,10 +981,17 @@ public function getRegularSalePriceInfo() return false; } - $startDateTimestamp = strtotime($startDate); - $endDateTimestamp = strtotime($endDate); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); - $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false, 'Y-m-d 00:00:00')); + $startDateTimestamp = (int)$helper->createGmtDateTime($startDate) + ->format('U'); + $endDateTimestamp = (int)$helper->createGmtDateTime($endDate) + ->format('U'); + + $currentTimestamp = (int)$helper->createGmtDateTime( + $helper->getCurrentGmtDate(false, 'Y-m-d 00:00:00') + )->format('U'); if ($currentTimestamp > $endDateTimestamp || $startDateTimestamp >= $endDateTimestamp @@ -1030,7 +1037,7 @@ protected function getRegularSalePriceStartDate() return false; } - return Mage::helper('M2ePro')->getDate($date, false, 'Y-m-d 00:00:00'); + return Mage::helper('M2ePro')->createGmtDateTime($date)->format('Y-m-d 00:00:00'); } protected function getRegularSalePriceEndDate() @@ -1051,7 +1058,7 @@ protected function getRegularSalePriceEndDate() $tempDate = new DateTime($date, new DateTimeZone('UTC')); $tempDate->modify('-1 day'); - $date = Mage::helper('M2ePro')->getDate($tempDate->format('U')); + $date = $tempDate->format('Y-m-d H:i:s'); } else { $src = $this->getAmazonSellingFormatTemplate()->getRegularSalePriceEndDateSource(); @@ -1066,7 +1073,7 @@ protected function getRegularSalePriceEndDate() return false; } - return Mage::helper('M2ePro')->getDate($date, false, 'Y-m-d 00:00:00'); + return Mage::helper('M2ePro')->createGmtDateTime($date)->format('Y-m-d 00:00:00'); } // --------------------------------------- diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Processor.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Processor.php index a2f99ecde..16f8df2c5 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Processor.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Action/Processor.php @@ -639,11 +639,13 @@ protected function processGroupedProcessingActions(array $processingActions, $ac $requestPendingSingle = Mage::getModel('M2ePro/Request_Pending_Single'); $requestPendingSingle->setData( array( - 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK, - 'server_hash' => $responseData['processing_id'], - 'expiration_date' => Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true)+self::PENDING_REQUEST_MAX_LIFE_TIME - ) + 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK, + 'server_hash' => $responseData['processing_id'], + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + + self::PENDING_REQUEST_MAX_LIFE_TIME + ) ) ); $requestPendingSingle->save(); diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/Parent/Processor/Sub/Selling.php b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/Parent/Processor/Sub/Selling.php index a4c4f9e65..34b868250 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/Parent/Processor/Sub/Selling.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/Parent/Processor/Sub/Selling.php @@ -61,10 +61,19 @@ protected function execute() $actualOnlineRegularPrice = $amazonListingProduct->getOnlineRegularPrice(); if ($regularSalePrice > 0) { - $startDateTimestamp = strtotime($amazonListingProduct->getOnlineRegularSalePriceStartDate()); - $endDateTimestamp = strtotime($amazonListingProduct->getOnlineRegularSalePriceEndDate()); - - $currentTimestamp = strtotime(Mage::helper('M2ePro')->getCurrentGmtDate(false, 'Y-m-d 00:00:00')); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + + $startDateTimestamp = (int)$helper->createGmtDateTime( + $amazonListingProduct->getOnlineRegularSalePriceStartDate() + )->format('U'); + $endDateTimestamp = (int)$helper->createGmtDateTime( + $amazonListingProduct->getOnlineRegularSalePriceEndDate() + )->format('U'); + + $currentTimestamp = (int)$helper->createGmtDateTime( + $helper->getCurrentGmtDate(false, 'Y-m-d 00:00:00') + )->format('U'); if ($currentTimestamp >= $startDateTimestamp && $currentTimestamp <= $endDateTimestamp && diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Magento/Product/Rule/Condition/Product.php b/app/code/community/Ess/M2ePro/Model/Amazon/Magento/Product/Rule/Condition/Product.php index a41e52b7c..d4bfa6a63 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Magento/Product/Rule/Condition/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Magento/Product/Rule/Condition/Product.php @@ -88,8 +88,11 @@ public function validateAttribute($validatedValue) return false; } + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); if ($this->getInputType() == 'date' && !empty($validatedValue) && !is_numeric($validatedValue)) { - $validatedValue = strtotime($validatedValue); + $validatedValue = (int)$helper->createGmtDateTime($validatedValue) + ->format('U'); } /** @@ -98,7 +101,8 @@ public function validateAttribute($validatedValue) $value = $this->getValueParsed(); if ($this->getInputType() == 'date' && !empty($value) && !is_numeric($value)) { - $value = strtotime($value); + $value = (int)$helper->createGmtDateTime($value) + ->format('U'); } // Comparison operator diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Order.php b/app/code/community/Ess/M2ePro/Model/Amazon/Order.php index 6a878d214..3ed600b38 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Order.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Order.php @@ -12,14 +12,15 @@ */ class Ess_M2ePro_Model_Amazon_Order extends Ess_M2ePro_Model_Component_Child_Amazon_Abstract { - const STATUS_PENDING = 0; - const STATUS_UNSHIPPED = 1; - const STATUS_SHIPPED_PARTIALLY = 2; - const STATUS_SHIPPED = 3; - const STATUS_UNFULFILLABLE = 4; - const STATUS_CANCELED = 5; - const STATUS_INVOICE_UNCONFIRMED = 6; - const STATUS_PENDING_RESERVED = 7; + const STATUS_PENDING = 0; + const STATUS_UNSHIPPED = 1; + const STATUS_SHIPPED_PARTIALLY = 2; + const STATUS_SHIPPED = 3; + const STATUS_UNFULFILLABLE = 4; + const STATUS_CANCELED = 5; + const STATUS_INVOICE_UNCONFIRMED = 6; + const STATUS_PENDING_RESERVED = 7; + const STATUS_CANCELLATION_REQUESTED = 8; const INVOICE_SOURCE_MAGENTO = 'magento'; const INVOICE_SOURCE_EXTENSION = 'extension'; @@ -153,6 +154,19 @@ public function getTaxRegistrationId() return $this->getData('tax_registration_id'); } + /** + * @return bool + */ + public function isBuyerRequestedCancel() + { + return (bool)$this->getData('is_buyer_requested_cancel'); + } + + public function getBuyerCancelReason() + { + return $this->getData('buyer_cancel_reason'); + } + /** * @return array * @throws Ess_M2ePro_Model_Exception_Logic @@ -329,7 +343,9 @@ public function isPending() */ public function isUnshipped() { - return $this->getStatus() == self::STATUS_UNSHIPPED; + $status = $this->getStatus(); + + return $status == self::STATUS_UNSHIPPED || $status == self::STATUS_CANCELLATION_REQUESTED; } /** @@ -372,6 +388,14 @@ public function isInvoiceUnconfirmed() return $this->getStatus() == self::STATUS_INVOICE_UNCONFIRMED; } + /** + * @return bool + */ + public function isCancellationRequested() + { + return $this->getStatus() == self::STATUS_CANCELLATION_REQUESTED; + } + //######################################## /** @@ -689,7 +713,7 @@ public function canUpdateShippingStatus(array $trackingDetails = array()) */ public function updateShippingStatus(array $trackingDetails = array(), array $items = array()) { - if (!$this->canUpdateShippingStatus($trackingDetails) || empty($trackingDetails['carrier_code'])) { + if (!$this->canUpdateShippingStatus($trackingDetails)) { return false; } @@ -697,10 +721,12 @@ public function updateShippingStatus(array $trackingDetails = array(), array $it $trackingDetails['fulfillment_date'] = Mage::helper('M2ePro')->getCurrentGmtDate(); } - $trackingDetails['carrier_title'] = Mage::helper('M2ePro/Component_Amazon')->getCarrierTitle( - $trackingDetails['carrier_code'], - isset($trackingDetails['carrier_title']) ? $trackingDetails['carrier_title'] : '' - ); + if (!empty($trackingDetails['carrier_code'])) { + $trackingDetails['carrier_title'] = Mage::helper('M2ePro/Component_Amazon')->getCarrierTitle( + $trackingDetails['carrier_code'], + isset($trackingDetails['carrier_title']) ? $trackingDetails['carrier_title'] : '' + ); + } if (!empty($trackingDetails['carrier_title'])) { if ($trackingDetails['carrier_title'] == Ess_M2ePro_Model_Order_Shipment_Handler::CUSTOM_CARRIER_CODE && @@ -819,12 +845,11 @@ public function refund(array $items = array()) 'items' => $items, ); - $totalItemsCount = $this->getParentObject()->getItemsCollection()->getSize(); $orderId = $this->getParentObject()->getId(); $action = Ess_M2ePro_Model_Order_Change::ACTION_CANCEL; if ($this->isShipped() || $this->isPartiallyShipped() || - count($items) != $totalItemsCount || $this->getParentObject()->isStatusUpdatingToShipped() + $this->getParentObject()->isStatusUpdatingToShipped() ) { if (empty($items)) { $this->getParentObject()->addErrorLog( @@ -840,6 +865,11 @@ public function refund(array $items = array()) $action = Ess_M2ePro_Model_Order_Change::ACTION_REFUND; } + if ($action == Ess_M2ePro_Model_Order_Change::ACTION_CANCEL && $this->isCancellationRequested()) { + $params['cancel_reason'] = + Ess_M2ePro_Model_Amazon_Order_Creditmemo_Handler::AMAZON_REFUND_REASON_BUYER_CANCELED; + } + Mage::getModel('M2ePro/Order_Change')->create( $orderId, $action, diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Order/Action/Processor.php b/app/code/community/Ess/M2ePro/Model/Amazon/Order/Action/Processor.php index ca485441a..edfb5a2e0 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Order/Action/Processor.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Order/Action/Processor.php @@ -130,11 +130,13 @@ protected function processAction($merchantId) $requestPendingSingle = Mage::getModel('M2ePro/Request_Pending_Single'); $requestPendingSingle->setData( array( - 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK, - 'server_hash' => $responseData['processing_id'], - 'expiration_date' => Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true)+self::PENDING_REQUEST_MAX_LIFE_TIME - ) + 'component' => Ess_M2ePro_Helper_Component_Amazon::NICK, + 'server_hash' => $responseData['processing_id'], + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + + self::PENDING_REQUEST_MAX_LIFE_TIME + ) ) ); $requestPendingSingle->save(); diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Order/Builder.php b/app/code/community/Ess/M2ePro/Model/Amazon/Order/Builder.php index 2243b888c..0f0e44c53 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Order/Builder.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Order/Builder.php @@ -67,6 +67,15 @@ protected function initializeData(array $data = array()) $this->setData('purchase_update_date', $data['purchase_update_date']); $this->setData('purchase_create_date', $data['purchase_create_date']); + + $this->setData('is_buyer_requested_cancel', $data['is_buyer_requested_cancel']); + $this->setData('buyer_cancel_reason', $data['buyer_cancel_reason']); + if ($data['is_buyer_requested_cancel'] && + $this->getData('status') == Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED + ) { + $this->setData('status', Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELLATION_REQUESTED); + } + // --------------------------------------- // Init sale data @@ -362,6 +371,21 @@ protected function createOrUpdateOrder() } } + if ($this->getData('status') == Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELLATION_REQUESTED) { + if ($reason = $this->getData('buyer_cancel_reason')) { + $noteText = 'A buyer requested order cancellation. Reason: ' . + Mage::helper('M2ePro')->escapeHtml($reason); + } else { + $noteText = 'A buyer requested order cancellation. The reason was not specified.'; + } + + /** @var Ess_M2ePro_Model_Order_Note $noteModel */ + $noteModel = Mage::getModel('M2ePro/Order_Note'); + $noteModel->setData('note', $noteText); + $noteModel->setData('order_id', $this->_order->getId()); + $noteModel->save(); + } + $this->_order->setAccount($this->_account); if ($this->_order->getChildObject()->isCanceled() && $this->_order->getReserve()->isPlaced()) { diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Order/Creditmemo/Handler.php b/app/code/community/Ess/M2ePro/Model/Amazon/Order/Creditmemo/Handler.php index d0c215042..83a02b34e 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Order/Creditmemo/Handler.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Order/Creditmemo/Handler.php @@ -10,6 +10,7 @@ class Ess_M2ePro_Model_Amazon_Order_Creditmemo_Handler extends Ess_M2ePro_Model_ { const AMAZON_REFUND_REASON_CUSTOMER_RETURN = 'CustomerReturn'; const AMAZON_REFUND_REASON_NO_INVENTORY = 'NoInventory'; + const AMAZON_REFUND_REASON_BUYER_CANCELED = 'BuyerCanceled'; //######################################## diff --git a/app/code/community/Ess/M2ePro/Model/Amazon/Template/SellingFormat/Builder.php b/app/code/community/Ess/M2ePro/Model/Amazon/Template/SellingFormat/Builder.php index 413f173cc..54133c2db 100644 --- a/app/code/community/Ess/M2ePro/Model/Amazon/Template/SellingFormat/Builder.php +++ b/app/code/community/Ess/M2ePro/Model/Amazon/Template/SellingFormat/Builder.php @@ -29,9 +29,9 @@ protected function prepareData() false, 'Y-m-d 00:00:00' ); } else { - $data['regular_sale_price_start_date_value'] = Mage::helper('M2ePro')->getDate( - $data['regular_sale_price_start_date_value'], false, 'Y-m-d 00:00:00' - ); + $data['regular_sale_price_start_date_value'] = Mage::helper('M2ePro') + ->createGmtDateTime($data['regular_sale_price_start_date_value']) + ->format('Y-m-d 00:00:00'); } if ($data['regular_sale_price_end_date_value'] === '') { @@ -39,9 +39,9 @@ protected function prepareData() false, 'Y-m-d 00:00:00' ); } else { - $data['regular_sale_price_end_date_value'] = Mage::helper('M2ePro')->getDate( - $data['regular_sale_price_end_date_value'], false, 'Y-m-d 00:00:00' - ); + $data['regular_sale_price_end_date_value'] = Mage::helper('M2ePro') + ->createGmtDateTime($data['regular_sale_price_end_date_value']) + ->format('Y-m-d 00:00:00'); } if (empty($data['is_business_customer_allowed'])) { diff --git a/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Partial/Runner.php b/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Partial/Runner.php index 6b4d2f97d..036cb6f03 100644 --- a/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Partial/Runner.php +++ b/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Partial/Runner.php @@ -104,12 +104,14 @@ protected function eventBefore() if (!$requestPendingPartial->getId()) { $requestPendingPartial->setData( array( - 'component' => $params['component'], - 'server_hash' => $params['server_hash'], - 'next_part' => 1, - 'expiration_date' => Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true)+self::PENDING_REQUEST_MAX_LIFE_TIME - ) + 'component' => $params['component'], + 'server_hash' => $params['server_hash'], + 'next_part' => 1, + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + + self::PENDING_REQUEST_MAX_LIFE_TIME + ) ) ); diff --git a/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Single/Runner.php b/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Single/Runner.php index 02cc4bbe6..ebf6558e5 100644 --- a/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Single/Runner.php +++ b/app/code/community/Ess/M2ePro/Model/Connector/Command/Pending/Processing/Single/Runner.php @@ -62,11 +62,13 @@ protected function eventBefore() if (!$requestPendingSingle->getId()) { $requestPendingSingle->setData( array( - 'component' => $params['component'], - 'server_hash' => $params['server_hash'], - 'expiration_date' => Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true)+static::PENDING_REQUEST_MAX_LIFE_TIME - ) + 'component' => $params['component'], + 'server_hash' => $params['server_hash'], + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + + static::PENDING_REQUEST_MAX_LIFE_TIME + ) ) ); diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Abstract.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Abstract.php index 74859a270..043e91461 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Abstract.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Abstract.php @@ -165,10 +165,13 @@ public function isPossibleToRun() return false; } - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimeStamp = $helper->getCurrentGmtDate(true); $startFrom = $this->getConfigValue('start_from'); - $startFrom = !empty($startFrom) ? strtotime($startFrom) : $currentTimeStamp; + $startFrom = !empty($startFrom) ? + (int)$helper->createGmtDateTime($startFrom)->format('U') : $currentTimeStamp; return $startFrom <= $currentTimeStamp && $this->isIntervalExceeded(); } @@ -249,8 +252,12 @@ protected function isIntervalExceeded() return true; } - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); - return $currentTimeStamp > strtotime($lastRun) + $this->getInterval(); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimeStamp = $helper->getCurrentGmtDate(true); + $lastRunTimestamp = (int)$helper->createGmtDateTime($lastRun)->format('U'); + + return $currentTimeStamp > $lastRunTimestamp + $this->getInterval(); } public function getInterval() diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Listing/SynchronizeInventory/Responser.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Listing/SynchronizeInventory/Responser.php index f6528a931..9c40c5c7a 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Listing/SynchronizeInventory/Responser.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Listing/SynchronizeInventory/Responser.php @@ -44,11 +44,17 @@ public function eventAfterExecuting() /** @var Ess_M2ePro_Model_Account $account */ $account = Mage::helper('M2ePro/Component_Amazon')->getObject('Account', $this->_params['account_id']); - $newSynchDate = Mage::helper('M2ePro')->getCurrentGmtDate(); + + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $newSynchDate = $helper->getCurrentGmtDate(); if ($this->getResponse()->getMessages() && $this->getResponse()->getMessages()->hasErrorEntities()) { + $newSynchTimestamp = (int)$helper->createGmtDateTime($newSynchDate) + ->format('U'); + //try download inventory again in an hour - $newSynchDate = date('Y-m-d H:i:s', strtotime($newSynchDate) + 3600); + $newSynchDate = date('Y-m-d H:i:s', $newSynchTimestamp + 3600); } $account->setData('inventory_last_synchronization', $newSynchDate)->save(); diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Order/Receive.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Order/Receive.php index cf3df8dd3..3e10bb03e 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Order/Receive.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Order/Receive.php @@ -147,8 +147,14 @@ protected function receiveAmazonOrdersData($merchantId, $accounts) $fromDate = $this->prepareFromDate($updateSinceTime); $toDate = $this->prepareToDate(); - if (strtotime($fromDate) >= strtotime($toDate)) { - $fromDate = new DateTime($toDate, new DateTimeZone('UTC')); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $fromTimestamp = (int)$helper->createGmtDateTime($fromDate) + ->format('U'); + $toTimestamp = (int)$helper->createGmtDateTime($toDate) + ->format('U'); + if ($fromTimestamp >= $toTimestamp) { + $fromDate = $helper->createGmtDateTime($toDate); $fromDate->modify('- 5 minutes'); $fromDate = $fromDate->format('Y-m-d H:i:s'); diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Repricing/Synchronize.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Repricing/Synchronize.php index 2e100de6a..5d7cd0d4b 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Repricing/Synchronize.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Amazon/Repricing/Synchronize.php @@ -255,10 +255,13 @@ protected function synchronizeActualPrice($account) */ protected function isPossibleToSynchronizeGeneral($account) { - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimeStamp = $helper->getCurrentGmtDate(true); $startDate = $this->getAccountData($account, self::REGISTRY_GENERAL_START_DATE); - $startDate = !empty($startDate) ? strtotime($startDate) : 0; + $startDate = !empty($startDate) ? + (int)$helper->createGmtDateTime($startDate)->format('U') : 0; $lastListingProductId = $this->getAccountData($account, self::REGISTRY_GENERAL_LAST_LISTING_PRODUCT_ID); $lastListingOtherId = $this->getAccountData($account, self::REGISTRY_GENERAL_LAST_LISTING_OTHER_ID); @@ -288,10 +291,13 @@ protected function isPossibleToSynchronizeGeneral($account) */ protected function isPossibleToSynchronizeActualPrice($account) { - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimeStamp = $helper->getCurrentGmtDate(true); $startDate = $this->getAccountData($account, self::REGISTRY_ACTUAL_PRICE_START_DATE); - $startDate = !empty($startDate) ? strtotime($startDate) : 0; + $startDate = !empty($startDate) ? + (int)$helper->createGmtDateTime($startDate)->format('U') : 0; $lastListingProductId = $this->getAccountData($account, self::REGISTRY_ACTUAL_PRICE_LAST_LISTING_PRODUCT_ID); $lastListingOtherId = $this->getAccountData($account, self::REGISTRY_ACTUAL_PRICE_LAST_LISTING_OTHER_ID); diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/DownloadNew.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/DownloadNew.php index f43166cbf..97647a07c 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/DownloadNew.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/DownloadNew.php @@ -100,7 +100,15 @@ protected function processAccount(Ess_M2ePro_Model_Account $account) ->from($tableFeedbacks, new Zend_Db_Expr('MAX(`seller_feedback_date`)')) ->where('`account_id` = ?', (int)$account->getId()); $maxSellerDate = $connRead->fetchOne($dbSelect); - if (strtotime($maxSellerDate) < strtotime('2001-01-02')) { + + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $comparedTimestamp = (int)$helper->createGmtDateTime('2001-01-02') + ->format('U'); + + $maxSellerTimestamp = (int)$helper->createGmtDateTime($maxSellerDate) + ->format('U'); + if ($maxSellerTimestamp < $comparedTimestamp) { $maxSellerDate = null; } @@ -108,7 +116,10 @@ protected function processAccount(Ess_M2ePro_Model_Account $account) ->from($tableFeedbacks, new Zend_Db_Expr('MAX(`buyer_feedback_date`)')) ->where('`account_id` = ?', (int)$account->getId()); $maxBuyerDate = $connRead->fetchOne($dbSelect); - if (strtotime($maxBuyerDate) < strtotime('2001-01-02')) { + + $maxBuyerTimestamp = (int)$helper->createGmtDateTime($maxBuyerDate) + ->format('U'); + if ($maxBuyerTimestamp < $comparedTimestamp) { $maxBuyerDate = null; } diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/SendResponse.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/SendResponse.php index ce5f850d1..1f3a8d845 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/SendResponse.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Feedbacks/SendResponse.php @@ -58,15 +58,22 @@ protected function filterLastAnswered(array $feedbacks) { $result = array(); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + foreach ($feedbacks as $feedback) { /** @var $feedback Ess_M2ePro_Model_Ebay_Feedback **/ $lastResponseAttemptDate = $feedback->getData('last_response_attempt_date'); - $currentGmtDate = Mage::helper('M2ePro')->getCurrentGmtDate(true); + $currentGmtDate = $helper->getCurrentGmtDate(true); - if ($lastResponseAttemptDate !== null && - strtotime($lastResponseAttemptDate) + self::ATTEMPT_INTERVAL > $currentGmtDate) { - continue; + if ($lastResponseAttemptDate !== null) { + $lastResponseAttemptTimestamp = (int)$helper->createGmtDateTime($lastResponseAttemptDate) + ->format('U'); + + if ($lastResponseAttemptTimestamp + self::ATTEMPT_INTERVAL > $currentGmtDate) { + continue; + } } $ebayAccount = $feedback->getEbayAccount(); diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/Channel/SynchronizeData.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/Channel/SynchronizeData.php index 32137c8e2..6e9ad3539 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/Channel/SynchronizeData.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/Channel/SynchronizeData.php @@ -229,11 +229,16 @@ protected function processResponseMessages(array $messages) protected function prepareSinceTime($sinceTime) { - $minTime = new DateTime('now', new DateTimeZone('UTC')); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + + $minTime = $helper->createCurrentGmtDateTime(); $minTime->modify("-1 month"); - if (empty($sinceTime) || strtotime($sinceTime) < (int)$minTime->format('U')) { - $sinceTime = new DateTime('now', new DateTimeZone('UTC')); + if (empty($sinceTime) || + (int)$helper->createGmtDateTime($sinceTime)->format('U') < (int)$minTime->format('U') + ) { + $sinceTime = $helper->createCurrentGmtDateTime(); $sinceTime = $sinceTime->format('Y-m-d H:i:s'); } diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/ResolveNonReceivedData.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/ResolveNonReceivedData.php index 84615057c..7230254f6 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/ResolveNonReceivedData.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Listing/Other/ResolveNonReceivedData.php @@ -168,6 +168,9 @@ protected function updateReceivedItems($listingOthers, Ess_M2ePro_Model_Account protected function updateNotReceivedItems($listingOthers, $toTimeReceived) { + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + foreach ($listingOthers as $listingOther) { /** @var Ess_M2ePro_Model_Ebay_Listing_Other $ebayListingOther */ $ebayListingOther = $listingOther->getChildObject(); @@ -180,10 +183,16 @@ protected function updateNotReceivedItems($listingOthers, $toTimeReceived) continue; } - if ($toTimeReceived !== null && - strtotime($ebayListingOther->getStartDate()) >= strtotime($toTimeReceived) - ) { - continue; + if ($toTimeReceived !== null) { + $startTimestamp = (int)$helper->createGmtDateTime( + $ebayListingOther->getStartDate() + )->format('U'); + $toTimeReceivedTimestamp = (int)$helper->createGmtDateTime($toTimeReceived) + ->format('U'); + + if ($startTimestamp >= $toTimeReceivedTimestamp) { + continue; + } } $onlineMainCategory === null && $ebayListingOther->setData('online_main_category', ''); diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Template/RemoveUnused.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Template/RemoveUnused.php index 7db82d6c1..530cf9943 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Template/RemoveUnused.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Ebay/Template/RemoveUnused.php @@ -73,7 +73,7 @@ protected function removeUnusedTemplates($templateNick) ); $minCreateDate = Mage::helper('M2ePro')->getCurrentGmtDate(true) - self::SAFE_CREATE_DATE_INTERVAL; - $minCreateDate = Mage::helper('M2ePro')->getDate($minCreateDate); + $minCreateDate = gmdate('Y-m-d H:i:s', $minCreateDate); $collection = $templateManager->getTemplateCollection(); $collection->getSelect()->where('`id` NOT IN ('.$unionSelect->__toString().')'); @@ -171,7 +171,7 @@ protected function removeCategoriesTemplates() ); $minCreateDate = Mage::helper('M2ePro')->getCurrentGmtDate(true) - self::SAFE_CREATE_DATE_INTERVAL; - $minCreateDate = Mage::helper('M2ePro')->getDate($minCreateDate); + $minCreateDate = gmdate('Y-m-d H:i:s', $minCreateDate); $collection = Mage::getModel('M2ePro/Ebay_Template_Category')->getCollection(); $collection->getSelect()->where('id NOT IN ('.$unionSelect->__toString().')'); @@ -292,7 +292,7 @@ protected function removeStoreCategoriesTemplates() ); $minCreateDate = Mage::helper('M2ePro')->getCurrentGmtDate(true) - self::SAFE_CREATE_DATE_INTERVAL; - $minCreateDate = Mage::helper('M2ePro')->getDate($minCreateDate); + $minCreateDate = gmdate('Y-m-d H:i:s', $minCreateDate); $collection = Mage::getModel('M2ePro/Ebay_Template_StoreCategory')->getCollection(); $collection->getSelect()->where('id NOT IN ('.$unionSelect->__toString().')'); diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Magento/Product/DetectSpecialPriceEndDate.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Magento/Product/DetectSpecialPriceEndDate.php index 621375980..34e66d498 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Magento/Product/DetectSpecialPriceEndDate.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Magento/Product/DetectSpecialPriceEndDate.php @@ -10,37 +10,26 @@ class Ess_M2ePro_Model_Cron_Task_Magento_Product_DetectSpecialPriceEndDate exten { const NICK = 'magento/product/detect_special_price_end_date'; - /** - * @var int (in seconds) - */ + /** @var int (in seconds) */ protected $_interval = 7200; - //######################################## - protected function performActions() { if ($this->getLastProcessedProductId() === null) { - $this->setLastProcessedProductId($this->getFirstProductId()); + $this->setLastProcessedProductId(0); } - $changedProductsPrice = array(); - $magentoProducts = $this->getChangedProductsPrice(); - - /** @var Mage_Catalog_Model_Product $magentoProduct */ - foreach ($magentoProducts as $magentoProduct) { - $changedProductsPrice[$magentoProduct->getId()] = array( - 'price' => $magentoProduct->getPrice() - ); - } + $changedProductsPrice = $this->getAllChangedProductsPrice(); if (!$changedProductsPrice) { - $this->setLastProcessedProductId($this->getFirstProductId()); + $this->setLastProcessedProductId(0); return; } /** @var Ess_M2ePro_Model_Resource_Listing_Product_Collection $collection */ $collection = Mage::getModel('M2ePro/Listing_Product')->getCollection(); $collection->addFieldToFilter('product_id', array('in' => array_keys($changedProductsPrice))); + $collection->addFieldToFilter('status', array('neq' => 0)); /** @var Ess_M2ePro_PublicServices_Product_SqlChange $changesModel */ $changesModel = Mage::getModel('M2ePro_PublicServices/Product_SqlChange'); @@ -50,6 +39,7 @@ protected function performActions() $currentPrice = (float)$this->getCurrentPrice($listingProduct); $newPrice = (float)$changedProductsPrice[$listingProduct->getProductId()]['price']; + if ($currentPrice == $newPrice) { continue; } @@ -59,12 +49,22 @@ protected function performActions() $changesModel->applyChanges(); - $lastMagentoProduct = array_pop($magentoProducts); - $this->setLastProcessedProductId((int)$lastMagentoProduct->getId()); + $lastMagentoProduct = $this->getArrayKeyLast($changedProductsPrice); + $this->setLastProcessedProductId((int)$lastMagentoProduct); } //######################################## + protected function getArrayKeyLast($array) + { + if (!is_array($array) || empty($array)) { + return NULL; + } + + $arrayKeys = array_keys($array); + return $arrayKeys[count($array)-1]; + } + protected function getCurrentPrice(Ess_M2ePro_Model_Listing_Product $listingProduct) { if ($listingProduct->isComponentModeAmazon()) { @@ -78,37 +78,60 @@ protected function getCurrentPrice(Ess_M2ePro_Model_Listing_Product $listingProd } } - //######################################## - - protected function getFirstProductId() + protected function getAllStoreIds() { - /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */ - $collection = Mage::getModel('catalog/product')->getCollection(); - $collection->setOrder('entity_id', 'asc'); - $collection->setPageSize(1); - $collection->setCurPage(1); + $storeIds = array(); + + /** @var Ess_M2ePro_Model_Resource_Listing_Collection $collectionListing */ + $collectionListing = Mage::getModel('M2ePro/Listing')->getCollection(); + $collectionListing->getSelect()->reset(Zend_Db_Select::COLUMNS); + $collectionListing->getSelect()->columns(array('store_id' => 'store_id')); + $collectionListing->getSelect()->group('store_id'); + + foreach ($collectionListing->getData() as $item){ + $storeIds[] = $item['store_id']; + } - return (int)$collection->getFirstItem()->getId(); + return $storeIds; } - protected function getChangedProductsPrice() + protected function getChangedProductsPrice($storeId) { $date = new DateTime('now', new DateTimeZone('UTC')); $date->modify('-1 day'); /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */ $collection = Mage::getModel('catalog/product')->getCollection(); + $collection->setStoreId($storeId); $collection->addAttributeToSelect('price'); $collection->addAttributeToFilter('special_price', array('notnull' => true)); - $collection->addAttributeToFilter('special_to_date', array('notnull' => true)); - $collection->addAttributeToFilter('special_to_date', array('lt' => $date->format('Y-m-d H:i:s'))); - $collection->addFieldToFilter('entity_id', array('gteq' => (int)$this->getLastProcessedProductId())); + $collection->addFieldToFilter('special_to_date', array('notnull' => true)); + $collection->addFieldToFilter('special_to_date', array('lt' => $date->format('Y-m-d H:i:s'))); + $collection->addFieldToFilter('entity_id', array('gt' => (int)$this->getLastProcessedProductId())); $collection->setOrder('entity_id', 'asc'); $collection->getSelect()->limit(1000); return $collection->getItems(); } + protected function getAllChangedProductsPrice() + { + $changedProductsPrice = array(); + + /** @var Mage_Catalog_Model_Product $magentoProduct */ + foreach ($this->getAllStoreIds() as $storeId) { + foreach ($this->getChangedProductsPrice($storeId) as $magentoProduct) { + $changedProductsPrice[$magentoProduct->getId()] = array( + 'price' => $magentoProduct->getPrice() + ); + } + } + + ksort($changedProductsPrice); + + return array_slice($changedProductsPrice, 0, 1000, true); + } + // --------------------------------------- protected function getLastProcessedProductId() @@ -127,4 +150,4 @@ protected function setLastProcessedProductId($magentoProductId) } //######################################## -} \ No newline at end of file +} diff --git a/app/code/community/Ess/M2ePro/Model/Cron/Task/Walmart/Listing/SynchronizeInventory/Responser.php b/app/code/community/Ess/M2ePro/Model/Cron/Task/Walmart/Listing/SynchronizeInventory/Responser.php index c8e588353..fc83b1044 100644 --- a/app/code/community/Ess/M2ePro/Model/Cron/Task/Walmart/Listing/SynchronizeInventory/Responser.php +++ b/app/code/community/Ess/M2ePro/Model/Cron/Task/Walmart/Listing/SynchronizeInventory/Responser.php @@ -44,11 +44,17 @@ public function eventAfterExecuting() /** @var Ess_M2ePro_Model_Account $account */ $account = Mage::helper('M2ePro/Component_Walmart')->getObject('Account', $this->_params['account_id']); - $newSynchDate = Mage::helper('M2ePro')->getCurrentGmtDate(); + + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $newSynchDate = $helper->getCurrentGmtDate(); if ($this->getResponse()->getMessages() && $this->getResponse()->getMessages()->hasErrorEntities()) { + $newSynchTimestamp = (int)$helper->createGmtDateTime($newSynchDate) + ->format('U'); + //try download inventory again in an hour - $newSynchDate = date('Y-m-d H:i:s', strtotime($newSynchDate) + 3600); + $newSynchDate = date('Y-m-d H:i:s', $newSynchTimestamp + 3600); } $account->setData('inventory_last_synchronization', $newSynchDate)->save(); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Account/Issue/AccessTokens.php b/app/code/community/Ess/M2ePro/Model/Ebay/Account/Issue/AccessTokens.php index 5bb787014..779206093 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Account/Issue/AccessTokens.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Account/Issue/AccessTokens.php @@ -53,8 +53,12 @@ public function getIssues() protected function getTradingApiTokenMessages(Ess_M2ePro_Model_Account $account) { - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentTimezoneDate(true); - $tokenExpirationTimeStamp = strtotime($account->getChildObject()->getTokenExpiredDate()); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimeStamp = $helper->getCurrentGmtDate(true); + $tokenExpirationTimeStamp = (int)$helper->createGmtDateTime( + $account->getChildObject()->getTokenExpiredDate() + )->format('U'); if ($tokenExpirationTimeStamp < $currentTimeStamp) { $tempMessage = Mage::helper('M2ePro')->__( @@ -128,8 +132,12 @@ protected function getTradingApiTokenMessages(Ess_M2ePro_Model_Account $account) protected function getSellApiTokenMessages(Ess_M2ePro_Model_Account $account) { - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentTimezoneDate(true); - $tokenExpirationTimeStamp = strtotime($account->getChildObject()->getSellApiTokenExpiredDate()); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimeStamp = $helper->getCurrentGmtDate(true); + $tokenExpirationTimeStamp = (int)$helper->createGmtDateTime( + $account->getChildObject()->getSellApiTokenExpiredDate() + )->format('U'); if ($tokenExpirationTimeStamp <= 0) { return array(); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Responser.php b/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Responser.php index 18717f5ef..64afa417e 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Responser.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Connector/Item/Responser.php @@ -414,11 +414,16 @@ protected function canPerformGetItemCall() $getItemLastCallDate = $additionalData['get_item_calls_statistic']['last_call_date']; } + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + if ($getItemCallsCount >= $maxAllowedGetItemCallsCount) { - $minAllowedDate = new DateTime('now', new DateTimeZone('UTC')); + $minAllowedDate = $helper->createCurrentGmtDateTime(); $minAllowedDate->modify('- 1 day'); - if (strtotime($getItemLastCallDate) > $minAllowedDate->format('U')) { + $getItemLastCallTimestamp = (int)$helper->createGmtDateTime($getItemLastCallDate)->format('U'); + $minAllowedTimestamp = (int)$minAllowedDate->format('U'); + if ($getItemLastCallTimestamp > $minAllowedTimestamp) { return false; } @@ -426,7 +431,7 @@ protected function canPerformGetItemCall() } $getItemCallsCount++; - $getItemLastCallDate = Mage::helper('M2ePro')->getCurrentGmtDate(); + $getItemLastCallDate = $helper->getCurrentGmtDate(); $additionalData['get_item_calls_statistic']['count'] = $getItemCallsCount; $additionalData['get_item_calls_statistic']['last_call_date'] = $getItemLastCallDate; diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Other/Updating.php b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Other/Updating.php index 20040b718..cf9db007a 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Other/Updating.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Listing/Other/Updating.php @@ -77,8 +77,12 @@ public function processResponseData($responseData) 'online_bids' => (int)$receivedItem['bidCount'], 'online_main_category' => null, 'online_categories_data' => null, - 'start_date' => (string)Mage::helper('M2ePro')->getDate($receivedItem['startTime']), - 'end_date' => (string)Mage::helper('M2ePro')->getDate($receivedItem['endTime']) + 'start_date' => (string)Mage::helper('M2ePro') + ->createGmtDateTime($receivedItem['startTime']) + ->format('Y-m-d H:i:s'), + 'end_date' => (string)Mage::helper('M2ePro') + ->createGmtDateTime($receivedItem['endTime']) + ->format('Y-m-d H:i:s') ); if (!empty($receivedItem['categories'])) { @@ -178,13 +182,15 @@ public function processResponseData($responseData) protected function updateToTimeLastSynchronization($responseData) { - $tempToTime = Mage::helper('M2ePro')->getCurrentGmtDate(); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $tempToTime = $helper->getCurrentGmtDate(); if (isset($responseData['to_time'])) { if (is_array($responseData['to_time'])) { $tempToTime = array(); foreach ($responseData['to_time'] as $tempToTime2) { - $tempToTime[] = strtotime($tempToTime2); + $tempToTime[] = (int)$helper->createGmtDateTime($tempToTime2)->format('U'); } sort($tempToTime, SORT_NUMERIC); @@ -196,7 +202,7 @@ protected function updateToTimeLastSynchronization($responseData) } if (!is_string($tempToTime) || empty($tempToTime)) { - $tempToTime = Mage::helper('M2ePro')->getCurrentGmtDate(); + $tempToTime = $helper->getCurrentGmtDate(); } $childAccountObject = $this->getAccount()->getChildObject(); diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayEndDate.php b/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayEndDate.php index 299384db6..379d9a147 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayEndDate.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayEndDate.php @@ -34,9 +34,13 @@ public function getValueByProductInstance(Mage_Catalog_Model_Product $product) return null; } - $endDate = new DateTime($endDate); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $endDate = $helper->createGmtDateTime($endDate); - return strtotime($endDate->format('Y-m-d')); + return (int)$helper->createGmtDateTime( + $endDate->format('Y-m-d') + )->format('U'); } /** diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayStartDate.php b/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayStartDate.php index dc89fd3e0..aea3cc78e 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayStartDate.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Magento/Product/Rule/Custom/EbayStartDate.php @@ -34,9 +34,13 @@ public function getValueByProductInstance(Mage_Catalog_Model_Product $product) return null; } - $startDate = new DateTime($startDate); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $startDate = $helper->createGmtDateTime($startDate); - return strtotime($startDate->format('Y-m-d')); + return (int)$helper->createGmtDateTime( + $startDate->format('Y-m-d') + )->format('U'); } /** diff --git a/app/code/community/Ess/M2ePro/Model/Ebay/Template/StoreCategory/Builder.php b/app/code/community/Ess/M2ePro/Model/Ebay/Template/StoreCategory/Builder.php index b980cfb90..9adb98102 100644 --- a/app/code/community/Ess/M2ePro/Model/Ebay/Template/StoreCategory/Builder.php +++ b/app/code/community/Ess/M2ePro/Model/Ebay/Template/StoreCategory/Builder.php @@ -12,17 +12,21 @@ class Ess_M2ePro_Model_Ebay_Template_StoreCategory_Builder extends Ess_M2ePro_Mo protected function prepareData() { - $allowedKeys = array_flip(array( + $data = array(); + + $keys = array( 'account_id', 'category_mode', 'category_id', 'category_attribute', 'category_path' - )); - - return array_filter( - array_intersect_key($this->_rawData, $allowedKeys) ); + + foreach ($keys as $key) { + isset($this->_rawData[$key]) && $data[$key] = $this->_rawData[$key]; + } + + return $data; } public function getDefaultData() diff --git a/app/code/community/Ess/M2ePro/Model/Exception/Connection.php b/app/code/community/Ess/M2ePro/Model/Exception/Connection.php index 266bccac9..55c2fed56 100644 --- a/app/code/community/Ess/M2ePro/Model/Exception/Connection.php +++ b/app/code/community/Ess/M2ePro/Model/Exception/Connection.php @@ -27,7 +27,9 @@ public function __construct($message, $additionalData = array()) */ public function handleRepeatTimeout($key) { - $currentDate = Mage::helper('M2ePro')->getCurrentGmtDate(); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentDate = $helper->getCurrentGmtDate(); $firstConnectionErrorDate = $this->getFirstConnectionErrorDate($key); if (empty($firstConnectionErrorDate)) { @@ -36,8 +38,8 @@ public function handleRepeatTimeout($key) return true; } - $currentDateTimeStamp = strtotime($currentDate); - $errorDateTimeStamp = strtotime($firstConnectionErrorDate); + $currentDateTimeStamp = (int)$helper->createGmtDateTime($currentDate)->format('U'); + $errorDateTimeStamp = (int)$helper->createGmtDateTime($firstConnectionErrorDate)->format('U'); if ($currentDateTimeStamp - $errorDateTimeStamp < self::CONNECTION_ERROR_REPEAT_TIMEOUT) { return true; } diff --git a/app/code/community/Ess/M2ePro/Model/Lock/Item/Manager.php b/app/code/community/Ess/M2ePro/Model/Lock/Item/Manager.php index a961920a9..515f05135 100644 --- a/app/code/community/Ess/M2ePro/Model/Lock/Item/Manager.php +++ b/app/code/community/Ess/M2ePro/Model/Lock/Item/Manager.php @@ -88,8 +88,11 @@ public function isInactiveMoreThanSeconds($maxInactiveInterval) return true; } - $currentTimestamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); - $updateTimestamp = strtotime($lockItem->getUpdateDate()); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $currentTimestamp = $helper->getCurrentGmtDate(true); + $updateTimestamp = (int)$helper->createGmtDateTime($lockItem->getUpdateDate()) + ->format('U'); if ($updateTimestamp < $currentTimestamp - $maxInactiveInterval) { return true; diff --git a/app/code/community/Ess/M2ePro/Model/Log/Clearing.php b/app/code/community/Ess/M2ePro/Model/Log/Clearing.php index e29acc23b..1573d7170 100644 --- a/app/code/community/Ess/M2ePro/Model/Log/Clearing.php +++ b/app/code/community/Ess/M2ePro/Model/Log/Clearing.php @@ -49,7 +49,7 @@ public function clearAllLog($log) } $timestamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); - $minTime = Mage::helper('M2ePro')->getDate($timestamp+60*60*24*365*10); + $minTime = gmdate('Y-m-d H:i:s', $timestamp+60*60*24*365*10); $this->clearLogByMinTime($log, $minTime); @@ -107,7 +107,7 @@ protected function getMinTimeByDays($days) $timeStamp = mktime($hours, $minutes, $seconds, $month, $day - $days, $year); - return Mage::helper('M2ePro')->getDate($timeStamp); + return gmdate('Y-m-d H:i:s', $timeStamp); } protected function clearLogByMinTime($log, $minTime) diff --git a/app/code/community/Ess/M2ePro/Model/Magento/Product.php b/app/code/community/Ess/M2ePro/Model/Magento/Product.php index a8d438206..7f6cdcaf6 100644 --- a/app/code/community/Ess/M2ePro/Model/Magento/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Magento/Product.php @@ -830,8 +830,12 @@ public function setSpecialPrice($value) */ public function isSpecialPriceActual() { - $fromDate = strtotime($this->getSpecialPriceFromDate()); - $toDate = strtotime($this->getSpecialPriceToDate()); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $fromDate = (int)$helper->createGmtDateTime($this->getSpecialPriceFromDate()) + ->format('U'); + $toDate = (int)$helper->createGmtDateTime($this->getSpecialPriceToDate()) + ->format('U'); $currentTimeStamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); return $currentTimeStamp >= $fromDate && $currentTimeStamp < $toDate && @@ -845,10 +849,9 @@ public function getSpecialPriceFromDate() $fromDate = $this->getProduct()->getSpecialFromDate(); if ($fromDate === null || $fromDate === false || $fromDate == '') { - $currentDateTime = Mage::helper('M2ePro')->getCurrentGmtDate(); - $fromDate = Mage::helper('M2ePro')->getDate($currentDateTime, false, 'Y-01-01 00:00:00'); + $fromDate = Mage::helper('M2ePro')->createCurrentGmtDateTime()->format('Y-01-01 00:00:00'); } else { - $fromDate = Mage::helper('M2ePro')->getDate($fromDate, false, 'Y-m-d 00:00:00'); + $fromDate = Mage::helper('M2ePro')->createGmtDateTime($fromDate)->format('Y-m-d 00:00:00'); } return $fromDate; @@ -863,13 +866,13 @@ public function getSpecialPriceToDate() $toDate = new DateTime($currentDateTime, new DateTimeZone('UTC')); $toDate->modify('+1 year'); - $toDate = Mage::helper('M2ePro')->getDate($toDate->format('U'), false, 'Y-01-01 00:00:00'); + $toDate = $toDate->format('Y-01-01 00:00:00'); } else { - $toDate = Mage::helper('M2ePro')->getDate($toDate, false, 'Y-m-d 00:00:00'); + $toDate = Mage::helper('M2ePro')->createGmtDateTime($toDate)->format('Y-m-d 00:00:00'); $toDate = new DateTime($toDate, new DateTimeZone('UTC')); $toDate->modify('+1 day'); - $toDate = Mage::helper('M2ePro')->getDate($toDate->format('U'), false, 'Y-m-d 00:00:00'); + $toDate = $toDate->format('Y-m-d 00:00:00'); } return $toDate; diff --git a/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Abstract.php b/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Abstract.php index 4a13bb346..ca81832ef 100644 --- a/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Abstract.php +++ b/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Abstract.php @@ -554,8 +554,12 @@ public function validateAttribute($validatedValue) return false; } + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + if ($this->getInputType() == 'date' && !empty($validatedValue) && !is_numeric($validatedValue)) { - $validatedValue = strtotime($validatedValue); + $validatedValue = (int)$helper->createGmtDateTime($validatedValue) + ->format('U'); } /** @@ -564,7 +568,8 @@ public function validateAttribute($validatedValue) $value = $this->getValueParsed(); if ($this->getInputType() == 'date' && !empty($value) && !is_numeric($value)) { - $value = strtotime($value); + $value = (int)$helper->createGmtDateTime($value) + ->format('U'); } /** diff --git a/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Product.php b/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Product.php index b73d7e33a..83496f0c9 100644 --- a/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Magento/Product/Rule/Condition/Product.php @@ -57,6 +57,9 @@ public function validate(Varien_Object $product) return $this->validateAttribute($product->getAvailableInCategories()); } + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + if (! isset($this->_entityAttributeValues[$product->getId()])) { if (!$product->getResource()) { return false; @@ -66,8 +69,12 @@ public function validate(Varien_Object $product) if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) { $oldValue = $this->getValue(); - $this->setValue(strtotime($this->getValue())); - $value = strtotime($product->getData($attrCode)); + + $this->setValue( + (int)$helper->createGmtDateTime($this->getValue())->format('U') + ); + $value = (int)$helper->createGmtDateTime($product->getData($attrCode)) + ->format('U'); $result = $this->validateAttribute($value); $this->setValue($oldValue); return $result; @@ -87,14 +94,21 @@ public function validate(Varien_Object $product) $productStoreId = 0; } + if (!isset($this->_entityAttributeValues[(int)$product->getId()][(int)$productStoreId])) { + return false; + } + $attributeValue = $this->_entityAttributeValues[(int)$product->getId()][(int)$productStoreId]; $attr = $product->getResource()->getAttribute($attrCode); if ($attr && $attr->getBackendType() == 'datetime') { - $attributeValue = strtotime($attributeValue); + $attributeValue = (int)$helper->createGmtDateTime($attributeValue) + ->format('U'); if (!is_int($this->getValueParsed())) { - $this->setValueParsed(strtotime($this->getValue())); + $this->setValueParsed( + (int)$helper->createGmtDateTime($this->getValue())->format('U') + ); } } else if ($attr && $attr->getFrontendInput() == 'multiselect') { $attributeValue = strlen($attributeValue) ? explode(',', $attributeValue) : array(); diff --git a/app/code/community/Ess/M2ePro/Model/OperationHistory.php b/app/code/community/Ess/M2ePro/Model/OperationHistory.php index 4ddd51cb4..22c91b6aa 100644 --- a/app/code/community/Ess/M2ePro/Model/OperationHistory.php +++ b/app/code/community/Ess/M2ePro/Model/OperationHistory.php @@ -345,8 +345,14 @@ public function getExecutionTreeDownInfo($nestingLevel = 0) protected function getTotalTime() { - $totalTime = strtotime($this->getObject()->getData('end_date')) - - strtotime($this->getObject()->getData('start_date')); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $endDateTimestamp = (int)$helper->createGmtDateTime($this->getObject()->getData('end_date')) + ->format('U'); + $startDateTimestamp = (int)$helper->createGmtDateTime($this->getObject()->getData('start_date')) + ->format('U'); + + $totalTime = $endDateTimestamp - $startDateTimestamp; if ($totalTime < 0) { return 'n/a'; diff --git a/app/code/community/Ess/M2ePro/Model/Order/Shipment/Handler.php b/app/code/community/Ess/M2ePro/Model/Order/Shipment/Handler.php index cd14f8354..c15ec1c63 100644 --- a/app/code/community/Ess/M2ePro/Model/Order/Shipment/Handler.php +++ b/app/code/community/Ess/M2ePro/Model/Order/Shipment/Handler.php @@ -131,7 +131,7 @@ protected function getTrackingDetails(Ess_M2ePro_Model_Order $order, Mage_Sales_ { $track = $shipment->getTracksCollection()->getLastItem(); $number = (string)trim($track->getData('number')); - if (empty($number)) { + if (empty($number) && $order->getComponentMode() != Ess_M2ePro_Helper_Component_Amazon::NICK) { return array(); } diff --git a/app/code/community/Ess/M2ePro/Model/Processing/Runner.php b/app/code/community/Ess/M2ePro/Model/Processing/Runner.php index 4c6fc05fb..fa633d054 100644 --- a/app/code/community/Ess/M2ePro/Model/Processing/Runner.php +++ b/app/code/community/Ess/M2ePro/Model/Processing/Runner.php @@ -100,8 +100,10 @@ protected function buildProcessingObject() $processingObject->setSettings('params', $this->getParams()); $processingObject->setData( - 'expiration_date', Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true)+static::MAX_LIFETIME + 'expiration_date', + gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + static::MAX_LIFETIME ) ); diff --git a/app/code/community/Ess/M2ePro/Model/Resource/Amazon/Listing.php b/app/code/community/Ess/M2ePro/Model/Resource/Amazon/Listing.php index d68302821..4e36adfc6 100644 --- a/app/code/community/Ess/M2ePro/Model/Resource/Amazon/Listing.php +++ b/app/code/community/Ess/M2ePro/Model/Resource/Amazon/Listing.php @@ -10,7 +10,6 @@ class Ess_M2ePro_Model_Resource_Amazon_Listing extends Ess_M2ePro_Model_Resource_Component_Child_Abstract { protected $_isPkAutoIncrement = false; - protected $_statisticDataCount = null; //######################################## @@ -20,75 +19,4 @@ public function _construct() } //######################################## - - public function getStatisticTotalCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['total'])) { - return 0; - } - - return (int)$statisticData[$listingId]['total']; - } - - //######################################## - - public function getStatisticActiveCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['active'])) { - return 0; - } - - return (int)$statisticData[$listingId]['active']; - } - - //######################################## - - public function getStatisticInactiveCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['inactive'])) { - return 0; - } - - return (int)$statisticData[$listingId]['inactive']; - } - - //######################################## - - protected function getStatisticData() - { - if ($this->_statisticDataCount) { - return $this->_statisticDataCount; - } - - $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); - $structureHelper = Mage::helper('M2ePro/Module_Database_Structure'); - - $m2eproListing = $structureHelper->getTableNameWithPrefix('m2epro_listing'); - $m2eproAmazonListing = $structureHelper->getTableNameWithPrefix('m2epro_amazon_listing'); - $m2eproListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_listing_product'); - - $sql = "SELECT - l.id AS listing_id, - COUNT(lp.id) AS total, - COUNT(CASE WHEN lp.status = 2 THEN lp.id END) AS active, - COUNT(CASE WHEN lp.status != 2 THEN lp.id END) AS inactive - FROM `{$m2eproListing}` AS `l` - INNER JOIN `{$m2eproAmazonListing}` AS `al` ON l.id = al.listing_id - LEFT JOIN `{$m2eproListingProduct}` AS `lp` ON l.id = lp.listing_id - GROUP BY listing_id;"; - - $result = $connRead->query($sql)->fetchAll(); - - $data = array(); - foreach($result as $value){ - $data[$value['listing_id']] = $value; - } - - return $this->_statisticDataCount = $data; - } - - //######################################## } diff --git a/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Listing.php b/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Listing.php index 8d4a36912..442e85f70 100644 --- a/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Listing.php +++ b/app/code/community/Ess/M2ePro/Model/Resource/Ebay/Listing.php @@ -10,7 +10,6 @@ class Ess_M2ePro_Model_Resource_Ebay_Listing extends Ess_M2ePro_Model_Resource_Component_Child_Abstract { protected $_isPkAutoIncrement = false; - protected $_statisticDataCount = null; //######################################## @@ -97,73 +96,4 @@ public function updateMotorsAttributesData( } //######################################## - - public function getStatisticTotalCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['total'])) { - return 0; - } - - return (int)$statisticData[$listingId]['total']; - } - - //######################################## - - public function getStatisticActiveCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['active'])) { - return 0; - } - - return (int)$statisticData[$listingId]['active']; - } - - //######################################## - - public function getStatisticInactiveCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['inactive'])) { - return 0; - } - - return (int)$statisticData[$listingId]['inactive']; - } - - //######################################## - - protected function getStatisticData() - { - if ($this->_statisticDataCount) { - return $this->_statisticDataCount; - } - - $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); - $structureHelper = Mage::helper('M2ePro/Module_Database_Structure'); - - $m2eproListing = $structureHelper->getTableNameWithPrefix('m2epro_listing'); - $m2eproEbayListing = $structureHelper->getTableNameWithPrefix('m2epro_ebay_listing'); - $m2eproListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_listing_product'); - - $sql = "SELECT - l.id AS listing_id, - COUNT(lp.id) AS total, - COUNT(CASE WHEN lp.status = 2 THEN lp.id END) AS active, - COUNT(CASE WHEN lp.status != 2 THEN lp.id END) AS inactive - FROM `{$m2eproListing}` AS `l` - INNER JOIN `{$m2eproEbayListing}` AS `el` ON l.id = el.listing_id - LEFT JOIN `{$m2eproListingProduct}` AS `lp` ON l.id = lp.listing_id - GROUP BY listing_id;"; - - $result = $connRead->query($sql)->fetchAll(); - - $data = array(); - foreach($result as $value){ - $data[$value['listing_id']] = $value; - } - - return $this->_statisticDataCount = $data; - } } diff --git a/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing.php b/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing.php index 81f08ebf6..566f999ae 100644 --- a/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing.php +++ b/app/code/community/Ess/M2ePro/Model/Resource/Walmart/Listing.php @@ -10,7 +10,6 @@ class Ess_M2ePro_Model_Resource_Walmart_Listing extends Ess_M2ePro_Model_Resource_Component_Child_Abstract { protected $_isPkAutoIncrement = false; - protected $_statisticDataCount = null; //######################################## @@ -20,75 +19,4 @@ public function _construct() } //######################################## - - public function getStatisticTotalCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['total'])) { - return 0; - } - - return (int)$statisticData[$listingId]['total']; - } - - //######################################## - - public function getStatisticActiveCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['active'])) { - return 0; - } - - return (int)$statisticData[$listingId]['active']; - } - - //######################################## - - public function getStatisticInactiveCount($listingId) - { - $statisticData = $this->getStatisticData(); - if (!isset($statisticData[$listingId]['inactive'])) { - return 0; - } - - return (int)$statisticData[$listingId]['inactive']; - } - - //######################################## - - protected function getStatisticData() - { - if ($this->_statisticDataCount) { - return $this->_statisticDataCount; - } - - $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); - $structureHelper = Mage::helper('M2ePro/Module_Database_Structure'); - - $m2eproListing = $structureHelper->getTableNameWithPrefix('m2epro_listing'); - $m2eproWalmartListing = $structureHelper->getTableNameWithPrefix('m2epro_walmart_listing'); - $m2eproListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_listing_product'); - - $sql = "SELECT - l.id AS listing_id, - COUNT(lp.id) AS total, - COUNT(CASE WHEN lp.status = 2 THEN lp.id END) AS active, - COUNT(CASE WHEN lp.status != 2 THEN lp.id END) AS inactive - FROM `{$m2eproListing}` AS `l` - INNER JOIN `{$m2eproWalmartListing}` AS `wl` ON l.id = wl.listing_id - LEFT JOIN `{$m2eproListingProduct}` AS `lp` ON l.id = lp.listing_id - GROUP BY listing_id;"; - - $result = $connRead->query($sql)->fetchAll(); - - $data = array(); - foreach($result as $value){ - $data[$value['listing_id']] = $value; - } - - return $this->_statisticDataCount = $data; - } - - //######################################## } diff --git a/app/code/community/Ess/M2ePro/Model/Servicing/Task/Analytics/Registry.php b/app/code/community/Ess/M2ePro/Model/Servicing/Task/Analytics/Registry.php index 17f7c5feb..9d50af1ff 100644 --- a/app/code/community/Ess/M2ePro/Model/Servicing/Task/Analytics/Registry.php +++ b/app/code/community/Ess/M2ePro/Model/Servicing/Task/Analytics/Registry.php @@ -18,7 +18,11 @@ public function isPlannedNow() $startedAt = $this->getStartedAt(); $finishedAt = $this->getFinishedAt(); - if (empty($plannedAt) || strtotime($plannedAt) > Mage::helper('M2ePro')->getCurrentGmtDate(true)) { + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + if (empty($plannedAt) || + (int)$helper->createGmtDateTime($plannedAt)->format('U') > $helper->getCurrentGmtDate(true) + ) { return false; } diff --git a/app/code/community/Ess/M2ePro/Model/Servicing/Task/Cron.php b/app/code/community/Ess/M2ePro/Model/Servicing/Task/Cron.php index 493d0754d..24ac034f3 100644 --- a/app/code/community/Ess/M2ePro/Model/Servicing/Task/Cron.php +++ b/app/code/community/Ess/M2ePro/Model/Servicing/Task/Cron.php @@ -40,15 +40,21 @@ public function isAllowed() } if ($helper->isRunnerMagento()) { - $currentTimeStamp = Mage::helper('M2ePro')->getCurrentGmtDate(true); + /** @var Ess_M2ePro_Helper_Data $dateHelper */ + $dateHelper = Mage::helper('M2ePro'); + + $currentTimeStamp = $dateHelper->getCurrentGmtDate(true); $lastTypeChange = $helper->getLastRunnerChange(); $lastRun = Mage::helper('M2ePro/Module')->getRegistry()->getValue('/servicing/cron/last_run/'); - if (($lastTypeChange === null || $currentTimeStamp > strtotime($lastTypeChange) + 86400) && - ($lastRun === null || $currentTimeStamp > strtotime($lastRun) + 86400)) { + if (($lastTypeChange === null || + $currentTimeStamp > (int)$dateHelper->createGmtDateTime($lastTypeChange)->format('U') + 86400) && + ($lastRun === null || + $currentTimeStamp > (int)$dateHelper->createGmtDateTime($lastRun)->format('U') + 86400) + ) { Mage::helper('M2ePro/Module')->getRegistry()->setValue( '/servicing/cron/last_run/', - Mage::helper('M2ePro')->getCurrentGmtDate() + $dateHelper->getCurrentGmtDate() ); return true; diff --git a/app/code/community/Ess/M2ePro/Model/Servicing/Task/Statistic.php b/app/code/community/Ess/M2ePro/Model/Servicing/Task/Statistic.php index 2ea301064..2bdabb706 100644 --- a/app/code/community/Ess/M2ePro/Model/Servicing/Task/Statistic.php +++ b/app/code/community/Ess/M2ePro/Model/Servicing/Task/Statistic.php @@ -31,12 +31,14 @@ public function isAllowed() { $lastRun = Mage::helper('M2ePro/Module')->getRegistry()->getValue('/servicing/statistic/last_run/'); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); if ($this->getInitiator() === Ess_M2ePro_Helper_Data::INITIATOR_DEVELOPER || $lastRun === null || - Mage::helper('M2ePro')->getCurrentGmtDate(true) > strtotime($lastRun) + self::RUN_INTERVAL) { + $helper->getCurrentGmtDate(true) > (int)$helper->createGmtDateTime($lastRun)->format('U') + self::RUN_INTERVAL) { Mage::helper('M2ePro/Module')->getRegistry()->setValue( '/servicing/statistic/last_run/', - Mage::helper('M2ePro')->getCurrentGmtDate() + $helper->getCurrentGmtDate() ); return true; @@ -628,18 +630,17 @@ protected function appendExtensionListingsProductsInfo(&$data) { $structureHelper = Mage::helper('M2ePro/Module_Database_Structure'); - $queryStmt = Mage::getSingleton('core/resource')->getConnection('core_read') - ->select() - ->from( - Mage::helper('M2ePro/Module_Database_Structure')->getTableNameWithPrefix('m2epro_listing'), - array( - 'component' => 'component_mode', - 'marketplace_id' => 'marketplace_id', - 'account_id' => 'account_id', - 'products_count' => 'products_total_count' - ) - ) - ->query(); + $m2eproListing = $structureHelper->getTableNameWithPrefix('m2epro_listing'); + $m2eproListingProduct = $structureHelper->getTableNameWithPrefix('m2epro_listing_product'); + + $sql = "SELECT + l.component_mode AS component, + l.marketplace_id AS marketplace_id, + l.account_id AS account_id, + (SELECT COUNT(*) FROM `{$m2eproListingProduct}` WHERE listing_id = l.id) AS products_count + FROM `{$m2eproListing}` AS `l`;"; + + $queryStmt = Mage::getSingleton('core/resource')->getConnection('core_read')->query($sql); $productTypes = array( Ess_M2ePro_Model_Magento_Product::TYPE_SIMPLE_ORIGIN, @@ -948,13 +949,14 @@ protected function appendExtensionOrdersInfo(&$data) ->query(); $statuses = array( - Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => 'pending', - Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED => 'unshipped', - Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED_PARTIALLY => 'shipped_partially', - Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => 'shipped', - Ess_M2ePro_Model_Amazon_Order::STATUS_UNFULFILLABLE => 'unfulfillable', - Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => 'canceled', - Ess_M2ePro_Model_Amazon_Order::STATUS_INVOICE_UNCONFIRMED => 'invoice_uncorfirmed' + Ess_M2ePro_Model_Amazon_Order::STATUS_PENDING => 'pending', + Ess_M2ePro_Model_Amazon_Order::STATUS_UNSHIPPED => 'unshipped', + Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED_PARTIALLY => 'shipped_partially', + Ess_M2ePro_Model_Amazon_Order::STATUS_SHIPPED => 'shipped', + Ess_M2ePro_Model_Amazon_Order::STATUS_UNFULFILLABLE => 'unfulfillable', + Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELED => 'canceled', + Ess_M2ePro_Model_Amazon_Order::STATUS_INVOICE_UNCONFIRMED => 'invoice_uncorfirmed', + Ess_M2ePro_Model_Amazon_Order::STATUS_CANCELLATION_REQUESTED => 'unshipped_cancellation_requested' ); while ($row = $queryStmt->fetch()) { diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Auto/Actions/Listing.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Auto/Actions/Listing.php index dfbbca1fa..29e386f8f 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Auto/Actions/Listing.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Auto/Actions/Listing.php @@ -187,8 +187,7 @@ protected function processAddedListingProduct(Ess_M2ePro_Model_Listing_Product $ $listingProduct->save(); if ($walmartListingProduct->getVariationManager()->isRelationParentType()) { - $processor = $walmartListingProduct->getVariationManager()->getTypeModel()->getProcessor(); - $processor->process(); + $walmartListingProduct->addVariationAttributes(); } } diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product.php index 29b95d574..248688f6c 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product.php @@ -836,7 +836,11 @@ private function getValidPromotionsData() $isValidPromotion = false; } - if (strtotime($promotionRow['end_date']) < strtotime($promotionRow['start_date'])) { + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $endDateTimestamp = (int)$helper->createGmtDateTime($promotionRow['end_date'])->format('U'); + $startDateTimestamp = (int)$helper->createGmtDateTime($promotionRow['start_date'])->format('U'); + if ($endDateTimestamp < $startDateTimestamp) { $message = <<getVariationManager()->isVariationProduct()) { + return; + } + + $matchedAttributes = $this->findLocalMatchedAttributesByMagentoAttributes( + $this->getVariationManager()->getTypeModel()->getProductAttributes() + ); + + if (empty($matchedAttributes)) { + return; + } + + $this->getVariationManager()->getTypeModel()->setMatchedAttributes($matchedAttributes); + $this->getVariationManager()->getTypeModel()->setChannelAttributes(array_values($matchedAttributes)); + $this->getVariationManager()->getTypeModel()->getProcessor()->process(); + } + + private function findLocalMatchedAttributesByMagentoAttributes($magentoAttributes) + { + if (empty($magentoAttributes)) { + return array(); + } + + $vocabularyHelper = Mage::helper('M2ePro/Component_Amazon_Vocabulary'); + $matchedAttributes = array(); + foreach ($magentoAttributes as $magentoAttr) { + foreach ($vocabularyHelper->getLocalData() as $attribute => $attributeData) { + if (in_array($magentoAttr, $attributeData['names'])) { + if (isset($matchedAttributes[$magentoAttr])) { + return array(); + } + $matchedAttributes[$magentoAttr] = $attribute; + } + } + } + + if (empty($matchedAttributes)) { + return array(); + } + + if (count($magentoAttributes) != count($matchedAttributes)) { + return array(); + } + + return $matchedAttributes; + } + + //######################################## } diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/List/Processor.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/List/Processor.php index 59b3a4b98..c0b7656df 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/List/Processor.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/List/Processor.php @@ -172,7 +172,7 @@ protected function executeCheckListResults() $actionCollection ->setInProgressFilter() ->addFieldToFilter('type', ActionProcessing::TYPE_ADD) - ->getSelect()->joinInner( + ->getSelect()->distinct()->joinInner( array('apl' => Mage::getModel('M2ePro/Walmart_Listing_Product_Action_ProcessingList') ->getResource()->getMainTable()), 'apl.listing_product_id = main_table.listing_product_id', @@ -385,11 +385,13 @@ protected function executeReadyForRelist() $requestPendingSingle = Mage::getModel('M2ePro/Request_Pending_Single'); $requestPendingSingle->setData( array( - 'component' => Ess_M2ePro_Helper_Component_Walmart::NICK, - 'server_hash' => $responseData['processing_id'], - 'expiration_date' => Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true) + self::PENDING_REQUEST_MAX_LIFE_TIME - ) + 'component' => Ess_M2ePro_Helper_Component_Walmart::NICK, + 'server_hash' => $responseData['processing_id'], + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + + self::PENDING_REQUEST_MAX_LIFE_TIME + ) ) ); $requestPendingSingle->save(); @@ -997,11 +999,13 @@ protected function processGroupedProcessingActions(array $processingActions, arr $requestPendingSingle = Mage::getModel('M2ePro/Request_Pending_Single'); $requestPendingSingle->setData( array( - 'component' => Ess_M2ePro_Helper_Component_Walmart::NICK, - 'server_hash' => $responseData['processing_id'], - 'expiration_date' => Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true)+self::PENDING_REQUEST_MAX_LIFE_TIME - ) + 'component' => Ess_M2ePro_Helper_Component_Walmart::NICK, + 'server_hash' => $responseData['processing_id'], + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + + self::PENDING_REQUEST_MAX_LIFE_TIME + ) ) ); $requestPendingSingle->save(); diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Processor.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Processor.php index 8a7aa363e..d8edac755 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Processor.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Processor.php @@ -634,11 +634,13 @@ protected function processGroupedProcessingActions(array $processingActions) $requestPendingSingle = Mage::getModel('M2ePro/Request_Pending_Single'); $requestPendingSingle->setData( array( - 'component' => Ess_M2ePro_Helper_Component_Walmart::NICK, - 'server_hash' => $responseData['processing_id'], - 'expiration_date' => Mage::helper('M2ePro')->getDate( - Mage::helper('M2ePro')->getCurrentGmtDate(true)+self::PENDING_REQUEST_MAX_LIFE_TIME - ) + 'component' => Ess_M2ePro_Helper_Component_Walmart::NICK, + 'server_hash' => $responseData['processing_id'], + 'expiration_date' => gmdate( + 'Y-m-d H:i:s', + Mage::helper('M2ePro')->getCurrentGmtDate(true) + + self::PENDING_REQUEST_MAX_LIFE_TIME + ) ) ); $requestPendingSingle->save(); diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php index 495543dac..166ed965d 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Listing/Product/Action/Type/Validator.php @@ -361,7 +361,9 @@ public function validateStartEndDates() return false; } - if (strtotime($endDate) < Mage::helper('M2ePro')->getCurrentGmtDate(true)) { + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + if ((int)$helper->createGmtDateTime($endDate)->format('U') < $helper->getCurrentGmtDate(true)) { $this->addMessage('End Date must be greater than current date'); return false; } diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Condition/Product.php b/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Condition/Product.php index a5b7f7593..0da07e137 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Condition/Product.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Condition/Product.php @@ -91,8 +91,11 @@ public function validateAttribute($validatedValue) return false; } + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + if ($this->getInputType() == 'date' && !empty($validatedValue) && !is_numeric($validatedValue)) { - $validatedValue = strtotime($validatedValue); + $validatedValue = (int)$helper->createGmtDateTime($validatedValue)->format('U'); } /** @@ -101,7 +104,7 @@ public function validateAttribute($validatedValue) $value = $this->getValueParsed(); if ($this->getInputType() == 'date' && !empty($value) && !is_numeric($value)) { - $value = strtotime($value); + $value = (int)$helper->createGmtDateTime($value)->format('U'); } // Comparison operator diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartEndDate.php b/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartEndDate.php index 40d56ff83..fe035ac12 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartEndDate.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartEndDate.php @@ -34,9 +34,11 @@ public function getValueByProductInstance(Mage_Catalog_Model_Product $product) return null; } - $date = new DateTime($date); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $date = $helper->createGmtDateTime($date); - return strtotime($date->format('Y-m-d')); + return (int)$helper->createGmtDateTime($date->format('Y-m-d'))->format('U'); } /** diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartStartDate.php b/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartStartDate.php index 00c3be6be..8c52f5220 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartStartDate.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Magento/Product/Rule/Custom/WalmartStartDate.php @@ -34,9 +34,11 @@ public function getValueByProductInstance(Mage_Catalog_Model_Product $product) return null; } - $date = new DateTime($date); + /** @var Ess_M2ePro_Helper_Data $helper */ + $helper = Mage::helper('M2ePro'); + $date = $helper->createGmtDateTime($date); - return strtotime($date->format('Y-m-d')); + return (int)$helper->createGmtDateTime($date->format('Y-m-d'))->format('U'); } /** diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Builder.php b/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Builder.php index c2b7a87f9..7cf805f17 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Builder.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Builder.php @@ -32,9 +32,9 @@ protected function prepareData() false, 'Y-m-d 00:00:00' ); } else { - $data['sale_time_start_date_value'] = Mage::helper('M2ePro')->getDate( - $data['sale_time_start_date_value'], false, 'Y-m-d 00:00:00' - ); + $data['sale_time_start_date_value'] = Mage::helper('M2ePro') + ->createGmtDateTime($data['sale_time_start_date_value']) + ->format('Y-m-d 00:00:00'); } if ($data['sale_time_end_date_value'] === '') { @@ -42,9 +42,9 @@ protected function prepareData() false, 'Y-m-d 00:00:00' ); } else { - $data['sale_time_end_date_value'] = Mage::helper('M2ePro')->getDate( - $data['sale_time_end_date_value'], false, 'Y-m-d 00:00:00' - ); + $data['sale_time_end_date_value'] = Mage::helper('M2ePro') + ->createGmtDateTime($data['sale_time_end_date_value']) + ->format('Y-m-d 00:00:00'); } $data['attributes'] = Mage::helper('M2ePro')->jsonEncode( diff --git a/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Promotion/Builder.php b/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Promotion/Builder.php index eba51298a..d1993153f 100644 --- a/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Promotion/Builder.php +++ b/app/code/community/Ess/M2ePro/Model/Walmart/Template/SellingFormat/Promotion/Builder.php @@ -32,9 +32,9 @@ public function getTemplateSellingFormatId() protected function prepareData() { if (!empty($this->_rawData['from_date']['value'])) { - $startDate = Mage::helper('M2ePro')->getDate( - $this->_rawData['from_date']['value'], false, 'Y-m-d H:i' - ); + $startDate = Mage::helper('M2ePro') + ->createGmtDateTime($this->_rawData['from_date']['value']) + ->format('Y-m-d H:i'); } else { $startDate = Mage::helper('M2ePro')->getCurrentGmtDate( false, 'Y-m-d H:i' @@ -42,9 +42,9 @@ protected function prepareData() } if (!empty($this->_rawData['to_date']['value'])) { - $endDate = Mage::helper('M2ePro')->getDate( - $this->_rawData['to_date']['value'], false, 'Y-m-d H:i' - ); + $endDate = Mage::helper('M2ePro') + ->createGmtDateTime($this->_rawData['to_date']['value']) + ->format('Y-m-d H:i'); } else { $endDate = Mage::helper('M2ePro')->getCurrentGmtDate( false, 'Y-m-d H:i' diff --git a/app/code/community/Ess/M2ePro/composer.json b/app/code/community/Ess/M2ePro/composer.json index 3d5ce24f2..3a2fd8780 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.21.3", + "version": "6.22.1", "license": "proprietary", "keywords": ["ebay", "amazon", "walmart", "magento"], "homepage": "https://www.m2epro.com/", diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/Order/MerchantFulfillmentController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/Order/MerchantFulfillmentController.php index dfe784076..3ff06ef7f 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/Order/MerchantFulfillmentController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Amazon/Order/MerchantFulfillmentController.php @@ -225,7 +225,9 @@ public function getShippingServicesAction() ); if ($post['must_arrive_by_date']) { - $mustArriveByDateTimestamp = strtotime($post['must_arrive_by_date']); + $mustArriveByDateTimestamp = (int)Mage::helper('M2ePro') + ->createGmtDateTime($post['must_arrive_by_date']) + ->format('U'); $mustArriveByDate = new DateTime(); $mustArriveByDate->setTimestamp($mustArriveByDateTimestamp); $requestData['arrive_by_date'] = $mustArriveByDate->format(DATE_ISO8601); diff --git a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/Listing/ProductAddController.php b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/Listing/ProductAddController.php index f40c04190..e00f7ca67 100644 --- a/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/Listing/ProductAddController.php +++ b/app/code/community/Ess/M2ePro/controllers/Adminhtml/Walmart/Listing/ProductAddController.php @@ -304,6 +304,8 @@ protected function review() $additionalData = $this->getListing()->getSettings('additional_data'); + $this->addVariationAttributes($additionalData['adding_listing_products_ids']); + Mage::helper('M2ePro/Data_Session')->setValue( 'added_products_ids', $additionalData['adding_listing_products_ids'] @@ -659,6 +661,19 @@ protected function setRuleData($prefix) Mage::helper('M2ePro/Data_Global')->setValue('rule_model', $ruleModel); } + + private function addVariationAttributes($productsIds) + { + $listingProductCollection = Mage::helper('M2ePro/Component_Walmart')->getCollection('Listing_Product'); + $listingProductCollection->addFieldToFilter('listing_product_id', array('in' => $productsIds)); + $listingProductCollection->addFieldToFilter('is_variation_product', 1); + + /** @var Ess_M2ePro_Model_Listing_Product $listingProduct */ + foreach ($listingProductCollection as $listingProduct) { + $listingProduct->getChildObject()->addVariationAttributes(); + } + } + protected function getHideProductsInOtherListingsPrefix() { $id = $this->getRequest()->getParam('id'); diff --git a/app/code/community/Ess/M2ePro/etc/config.xml b/app/code/community/Ess/M2ePro/etc/config.xml index 951b8c787..6211dbd8b 100644 --- a/app/code/community/Ess/M2ePro/etc/config.xml +++ b/app/code/community/Ess/M2ePro/etc/config.xml @@ -2,7 +2,7 @@ - 6.21.3 + 6.22.1 diff --git a/app/code/community/Ess/M2ePro/sql/Install/Amazon.php b/app/code/community/Ess/M2ePro/sql/Install/Amazon.php index 995a84788..a97631b3b 100644 --- a/app/code/community/Ess/M2ePro/sql/Install/Amazon.php +++ b/app/code/community/Ess/M2ePro/sql/Install/Amazon.php @@ -494,6 +494,8 @@ public function execute() `tax_details` TEXT DEFAULT NULL, `ioss_number` VARCHAR(72) DEFAULT NULL, `tax_registration_id` VARCHAR(72) DEFAULT NULL, + `is_buyer_requested_cancel` SMALLINT(4) UNSIGNED NOT NULL DEFAULT 0, + `buyer_cancel_reason` TEXT DEFAULT NULL, `discount_details` TEXT DEFAULT NULL, `qty_shipped` INT(11) UNSIGNED NOT NULL DEFAULT 0, `qty_unshipped` INT(11) UNSIGNED NOT NULL DEFAULT 0, diff --git a/app/code/community/Ess/M2ePro/sql/Install/Ebay.php b/app/code/community/Ess/M2ePro/sql/Install/Ebay.php index 20e8f6f13..219930088 100644 --- a/app/code/community/Ess/M2ePro/sql/Install/Ebay.php +++ b/app/code/community/Ess/M2ePro/sql/Install/Ebay.php @@ -294,8 +294,6 @@ public function execute() DROP TABLE IF EXISTS `{$this->_installer->getTable('m2epro_ebay_listing')}`; CREATE TABLE `{$this->_installer->getTable('m2epro_ebay_listing')}` ( `listing_id` INT(11) UNSIGNED NOT NULL, - `products_sold_count` INT(11) UNSIGNED NOT NULL DEFAULT 0, - `items_sold_count` INT(11) UNSIGNED NOT NULL DEFAULT 0, `auto_global_adding_template_category_id` INT(11) UNSIGNED DEFAULT NULL, `auto_global_adding_template_category_secondary_id` INT(11) UNSIGNED DEFAULT NULL, `auto_global_adding_template_store_category_id` INT(11) UNSIGNED DEFAULT NULL, @@ -323,8 +321,6 @@ public function execute() INDEX `auto_website_adding_template_store_category_id` (`auto_website_adding_template_store_category_id`), INDEX `auto_website_adding_template_store_category_secondary_id` (`auto_website_adding_template_store_category_secondary_id`), - INDEX `items_sold_count` (`items_sold_count`), - INDEX `products_sold_count` (`products_sold_count`), INDEX `template_description_id` (`template_description_id`), INDEX `template_payment_id` (`template_payment_id`), INDEX `template_return_policy_id` (`template_return_policy_id`), diff --git a/app/code/community/Ess/M2ePro/sql/Install/General.php b/app/code/community/Ess/M2ePro/sql/Install/General.php index 2e588200a..2d2def752 100644 --- a/app/code/community/Ess/M2ePro/sql/Install/General.php +++ b/app/code/community/Ess/M2ePro/sql/Install/General.php @@ -51,10 +51,6 @@ public function execute() `marketplace_id` INT(11) UNSIGNED NOT NULL, `title` VARCHAR(255) NOT NULL, `store_id` INT(11) UNSIGNED NOT NULL, - `products_total_count` INT(11) UNSIGNED NOT NULL DEFAULT 0, - `products_active_count` INT(11) UNSIGNED NOT NULL DEFAULT 0, - `products_inactive_count` INT(11) UNSIGNED NOT NULL DEFAULT 0, - `items_active_count` INT(11) UNSIGNED NOT NULL DEFAULT 0, `source_products` TINYINT(2) UNSIGNED NOT NULL DEFAULT 1, `additional_data` LONGTEXT DEFAULT NULL, `component_mode` VARCHAR(10) DEFAULT NULL, diff --git a/app/code/community/Ess/M2ePro/sql/Update/y22_m05/AmazonOrderCancellationNewFlow.php b/app/code/community/Ess/M2ePro/sql/Update/y22_m05/AmazonOrderCancellationNewFlow.php new file mode 100644 index 000000000..6ffcbaea5 --- /dev/null +++ b/app/code/community/Ess/M2ePro/sql/Update/y22_m05/AmazonOrderCancellationNewFlow.php @@ -0,0 +1,33 @@ +_installer->getTableModifier('amazon_order') + ->addColumn( + 'is_buyer_requested_cancel', + 'SMALLINT(5) UNSIGNED NOT NULL', + 0, + 'tax_registration_id', + false, + false + ) + ->addColumn( + 'buyer_cancel_reason', + 'TEXT', + null, + 'is_buyer_requested_cancel', + false, + false + ) + ->commit(); + } + + //######################################## +} diff --git a/app/code/community/Ess/M2ePro/sql/Update/y22_m05/DropListingColumns.php b/app/code/community/Ess/M2ePro/sql/Update/y22_m05/DropListingColumns.php new file mode 100644 index 000000000..fa4d5155f --- /dev/null +++ b/app/code/community/Ess/M2ePro/sql/Update/y22_m05/DropListingColumns.php @@ -0,0 +1,26 @@ +_installer->getTableModifier('listing') + ->dropColumn('products_total_count', true, false) + ->dropColumn('products_active_count', true, false) + ->dropColumn('products_inactive_count', true, false) + ->dropColumn('items_active_count', true, false) + ->commit(); + + $this->_installer->getTableModifier('ebay_listing') + ->dropColumn('products_sold_count', true, false) + ->dropColumn('items_sold_count', true, false) + ->commit(); + } + + //######################################## +} diff --git a/app/code/community/Ess/M2ePro/sql/Upgrade/v6_21_3__v6_22_0_1/Config.php b/app/code/community/Ess/M2ePro/sql/Upgrade/v6_21_3__v6_22_0_1/Config.php new file mode 100644 index 000000000..446519614 --- /dev/null +++ b/app/code/community/Ess/M2ePro/sql/Upgrade/v6_21_3__v6_22_0_1/Config.php @@ -0,0 +1,18 @@ +__('Pending') ?>
    - order->getChildObject()->isUnshipped()) { ?> + order->getChildObject()->isCancellationRequested()) { ?> + __('Unshipped (Cancellation Requested)') ?> + order->getChildObject()->isUnshipped()) { ?> __('Unshipped') ?> diff --git a/app/design/adminhtml/default/default/template/M2ePro/amazon/template/description/tabs/general.phtml b/app/design/adminhtml/default/default/template/M2ePro/amazon/template/description/tabs/general.phtml index 139a4059f..e4206029b 100644 --- a/app/design/adminhtml/default/default/template/M2ePro/amazon/template/description/tabs/general.phtml +++ b/app/design/adminhtml/default/default/template/M2ePro/amazon/template/description/tabs/general.phtml @@ -285,7 +285,7 @@ ); ?>