Skip to content

Commit

Permalink
6.39.0 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed May 5, 2023
1 parent 5dc853c commit 4f2e882
Show file tree
Hide file tree
Showing 35 changed files with 962 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected function _prepareCollection()
$filter = $this->getParam($this->getVarNameFilter(), null);
if (is_string($filter)) {
$this->addOrderCreateDateToFilter($collection, $filter);
$this->applyVatChangedFilters($collection, $filter);
}

$this->setCollection($collection);
Expand Down Expand Up @@ -287,18 +288,18 @@ public function callbackFilterMagentoOrderNumber($collection, $column)

protected function addOrderCreateDateToFilter($collection, $filter)
{
$data = $this->helper('adminhtml')->prepareFilterString($filter);
if (array_key_exists('order_create_date', $data)) {
$filterData = $this->helper('adminhtml')->prepareFilterString($filter);
if (array_key_exists('order_create_date', $filterData)) {
$column = $this->getColumn('create_date');

if (isset($column) && (!empty($data['order_create_date'])) && $column->getFilter()) {
$data['order_create_date']['locale'] = Mage::app()->getLocale()->getLocaleCode();
$column->getFilter()->setValue($data['order_create_date']);
if (isset($column) && (!empty($filterData['order_create_date'])) && $column->getFilter()) {
$filterData['order_create_date']['locale'] = Mage::app()->getLocale()->getLocaleCode();
$column->getFilter()->setValue($filterData['order_create_date']);
$field = ($column->getFilterIndex()) ? $column->getFilterIndex() : $column->getIndex();
$cond = $column->getFilter()->getCondition();
if ($field && isset($cond)) {
$date = new Zend_Date;
$date->set(Mage::helper('M2ePro/Order_Notification')->getNotificationDate(), Zend_Date::ISO_8601);
$date = new Zend_Date();
$date->set($filterData['order_create_date']['from_origin'], Zend_Date::ISO_8601);
$cond['from'] = $date;
$collection->addFieldToFilter($field, $cond);
}
Expand All @@ -325,5 +326,16 @@ protected function getComponentTitle()
return Mage::helper('M2ePro/Component_' . ucfirst($this->getComponentMode()))->getTitle();
}

//########################################
private function applyVatChangedFilters(Ess_M2ePro_Model_Resource_Order_Log_Collection $collection, $filter)
{
$filterData = $this->helper('adminhtml')->prepareFilterString($filter);
if (empty($filterData['orders_with_modified_vat'])) {
return;
}

$collection->addFieldToFilter(
'main_table.additional_data',
array('like' => '%' . \Ess_M2ePro_Model_Order::ADDITIONAL_DATA_KEY_VAT_REVERSE_CHARGE . '%')
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

/*
* @author M2E Pro Developers Team
* @copyright M2E LTD
* @license Commercial use is forbidden
*/

abstract class Ess_M2ePro_Block_Adminhtml_Notification_AbstractNotificationMessage extends Mage_Adminhtml_Block_Template
{
/** @var string */
protected $sinceDate;
/** @var int */
protected $failOrderCount;
/** @var string */
protected $skipUrl;
/** @var array */
protected $components;
/** @var array */
protected $logLinkFilters;

public function setSinceDate($date)
{
/** @var Mage_Core_Helper_Data $coreHelper */
$coreHelper = Mage::helper('core');

$this->sinceDate = $coreHelper->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_LONG);
}

public function setFailOrderCount($count)
{
$this->failOrderCount = $count;
}

public function setSkipUrl($skipUrl)
{
$this->skipUrl = $skipUrl;
}

public function setComponents(array $components)
{
$this->components = $components;
}

public function setLogLinkFilters(array $filters)
{
$this->logLinkFilters = $filters;
}

abstract protected function renderHtml();

/**
* @return string
*/
protected function _toHtml()
{
$this->getLayout()
->getBlock('head')
->addJs('M2ePro/Order/LogNotification.js');

return $this->renderHtml();
}

protected function makeLinksHtmlToComponentLogs()
{
/** @var $adminhtmlHelper */
$adminhtmlHelper = Mage::helper('adminhtml');

$componentLinks = array();
foreach ($this->components as $component) {
$title = $route = '';
switch ($component) {
case Ess_M2ePro_Helper_View_Amazon::NICK:
$title = 'Amazon orders logs';
$route = 'M2ePro/adminhtml_amazon_log/order';
break;
case Ess_M2ePro_Helper_View_Ebay::NICK:
$title = 'eBay orders logs';
$route = 'M2ePro/adminhtml_ebay_log/order';
break;
case Ess_M2ePro_Helper_View_Walmart::NICK:
$title = 'Walmart orders logs';
$route = 'M2ePro/adminhtml_walmart_log/order';
break;
}

$filterHash = http_build_query($this->logLinkFilters);
$filterHash = base64_encode($filterHash);

$url = $adminhtmlHelper->getUrl($route, array('filter' => $filterHash));

$componentLinks[] = sprintf('<a href="%s" target="_blank">%s</a>', $url, $title);
}

return implode(' / ', $componentLinks);
}

protected function makeSkipLink()
{
return <<<HTML
<script>
if (typeof LogNotificationObj == 'undefined') {
LogNotificationObj = new LogNotification()
}
</script>
<a href="javascript:void(0);" onclick="LogNotificationObj.skipLogToCurrentDate('{$this->skipUrl}')">
Skip this message
</a>
HTML;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* @author M2E Pro Developers Team
* @copyright M2E LTD
* @license Commercial use is forbidden
*/

class Ess_M2ePro_Block_Adminhtml_Notification_OrderNotCreated
extends Ess_M2ePro_Block_Adminhtml_Notification_AbstractNotificationMessage
{
protected function renderHtml()
{
return <<<TEMPLATE
Since {$this->sinceDate}, some Magento orders have not been created: {$this->failOrderCount},
check your {$this->makeLinksHtmlToComponentLogs()}.{$this->makeSkipLink()}.
TEMPLATE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* @author M2E Pro Developers Team
* @copyright M2E LTD
* @license Commercial use is forbidden
*/

class Ess_M2ePro_Block_Adminhtml_Notification_OrderVatChanged
extends Ess_M2ePro_Block_Adminhtml_Notification_AbstractNotificationMessage
{
protected function renderHtml()
{
return <<<MESAGE
Since {$this->sinceDate}, Amazon has applied reverse charge (0% VAT) to {$this->failOrderCount} orders,
check your {$this->makeLinksHtmlToComponentLogs()}. {$this->makeSkipLink()}.
MESAGE;
}
}
156 changes: 30 additions & 126 deletions app/code/community/Ess/M2ePro/Helper/Order/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,161 +14,65 @@ class Ess_M2ePro_Helper_Order_Notification extends Mage_Core_Helper_Abstract
const NOTIFICATIONS_EXTENSION_PAGES = 1;
const NOTIFICATIONS_MAGENTO_PAGES = 2;

/**
* @var Ess_M2ePro_Model_Resource_Order_Log_Collection
*/
protected $_collectionOrderLogs;

//########################################

public function buildMessage()
public function getNotificationMode()
{
Mage::getSingleton('core/layout')->getBlock('head')->addJs('M2ePro/Order/LogNotification.js');
$hasAmazonLog = false;
$hasEbayLog = false;
$hasWalmartLog = false;

foreach ($this->_collectionOrderLogs->getItems() as $item) {
if ($item->getData('component_mode') === Ess_M2ePro_Helper_View_Amazon::NICK) {
$hasAmazonLog = true;
} elseif ($item->getData('component_mode') === Ess_M2ePro_Helper_View_Ebay::NICK) {
$hasEbayLog = true;
} elseif ($item->getData('component_mode') === Ess_M2ePro_Helper_View_Walmart::NICK) {
$hasWalmartLog = true;
}
}


/** @var Ess_M2ePro_Model_Order_Log $orderLogFirst */
$orderLogFirst = $this->_collectionOrderLogs->getFirstItem();
/** @var Ess_M2ePro_Model_Order_Log $orderLogLast */
$orderLogLast = $this->_collectionOrderLogs->getLastItem();

$orderNotCreatedDate = Mage::helper('core')->formatDate(
$orderLogFirst->getData('create_date'), Mage_Core_Model_Locale::FORMAT_TYPE_LONG
);
$this->_collectionOrderLogs->clear();
$count = $this->_collectionOrderLogs->addFieldToSelect('order_id')->distinct(true)->count();

$message = <<<HTML
<script type="text/javascript">
if (typeof LogNotificationObj == 'undefined') {
LogNotificationObj = new LogNotification();
return (int)$this->getConfig()
->getGroupValue(self::NOTIFICATIONS_PATH, 'mode');
}
</script>
Since {$orderNotCreatedDate}, some Magento orders have not been created: {$count}, check your
HTML;

$filter = base64_encode(
'order_create_date[from]=' .
Mage::helper('core')->formatDate(
Mage::app()->getLocale()->storeDate(null, $orderLogFirst->getData('create_date'))
) . '&' .
'description=Magento Order was not created&' .
'magento_order_number=N/A&' .
'initiator=' . Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION
);

if ($hasEbayLog) {
$url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_ebay_log/order', array('filter' => $filter));
$message .= '<a href="' . $url . '" target="_blank">eBay orders logs</a>';
}

if ($hasAmazonLog) {
$url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_amazon_log/order', array('filter' => $filter));
if ($hasEbayLog) {
$message .= ' / ';
}

$message .= '<a href="' . $url . '" target="_blank"> Amazon orders logs</a>';
}

if ($hasWalmartLog) {
$url = Mage::helper('adminhtml')->getUrl('M2ePro/adminhtml_walmart_log/order', array('filter' => $filter));
if ($hasEbayLog || $hasAmazonLog) {
$message .= ' / ';
}

$message .= '<a href="' . $url . '" target="_blank">Walmart orders logs</a>';
}

$url = Mage::helper('adminhtml')->getUrl(
'M2ePro/adminhtml_order/skipLogNotificationToCurrentDate',
array('last_order_create_date' => $orderLogLast->getData('create_date'))
);

$message .= <<<HTML
. <a href="javascript:void(0);" onclick="LogNotificationObj.skipLogToCurrentDate('{$url}')">Skip this message</a>.
HTML;

return $message;
public function setNotificationMode($value)
{
$this->getConfig()
->setGroupValue(self::NOTIFICATIONS_PATH, 'mode', (int)$value);
}

//########################################

public function showNotification()
public function getOrderNotCreatedLastDate()
{
$this->_collectionOrderLogs = Mage::getModel('M2ePro/Order_Log')->getCollection()
->getLogsByDescription(
'Magento Order was not created',
Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION,
$this->getNotificationDate()
);

return ($this->_collectionOrderLogs->getSize()) ? true : false;
return $this->getConfig()
->getGroupValue(self::NOTIFICATIONS_PATH, 'order_not_created_last_date');
}

//########################################

public function getNotificationMode()
public function setOrderNotCreatedLastDate($value)
{
/** @var Ess_M2ePro_Model_Config_Manager $config */
$config = Mage::helper('M2ePro/Module')->getConfig();

return (int)$config->getGroupValue(self::NOTIFICATIONS_PATH, 'mode');
$this->getConfig()
->setGroupValue(self::NOTIFICATIONS_PATH, 'order_not_created_last_date', $value);
}

public function setNotificationMode($value)
public function getOrderChangedVatLastDate()
{
/** @var Ess_M2ePro_Model_Config_Manager $config */
$config = Mage::helper('M2ePro/Module')->getConfig();

$config->setGroupValue(self::NOTIFICATIONS_PATH, 'mode', (int)$value);
return $this->getConfig()
->getGroupValue(self::NOTIFICATIONS_PATH, 'order_changed_vat_last_date');
}

public function getNotificationDate()
public function setOrderChangedVatLastDate($value)
{
/** @var Ess_M2ePro_Model_Config_Manager $config */
$config = Mage::helper('M2ePro/Module')->getConfig();

return $config->getGroupValue(self::NOTIFICATIONS_PATH, 'last_date');
$this->getConfig()
->setGroupValue(self::NOTIFICATIONS_PATH, 'order_changed_vat_last_date', $value);
}

public function setNotificationDate($value)
/**
* @return Ess_M2ePro_Model_Config_Manager
*/
private function getConfig()
{
/** @var Ess_M2ePro_Model_Config_Manager $config */
$config = Mage::helper('M2ePro/Module')->getConfig();
/** @var Ess_M2ePro_Helper_Module $moduleHelper */
$moduleHelper = Mage::helper('M2ePro/Module');

$config->setGroupValue(self::NOTIFICATIONS_PATH, 'last_date', $value);
return $moduleHelper->getConfig();
}

//----------------------------------------

public function isNotificationDisabled()
{
return $this->getNotificationMode() == self::NOTIFICATIONS_DISABLED;
return $this->getNotificationMode() === self::NOTIFICATIONS_DISABLED;
}

public function isNotificationExtensionPages()
{
return $this->getNotificationMode() == self::NOTIFICATIONS_EXTENSION_PAGES;
return $this->getNotificationMode() === self::NOTIFICATIONS_EXTENSION_PAGES;
}

public function isNotificationMagentoPages()
{
return $this->getNotificationMode() == self::NOTIFICATIONS_MAGENTO_PAGES;
return $this->getNotificationMode() === self::NOTIFICATIONS_MAGENTO_PAGES;
}

//########################################
}
}
Loading

0 comments on commit 4f2e882

Please sign in to comment.