From c4b9e6afa432d60a800df6e9d0c57869535d15ea Mon Sep 17 00:00:00 2001
From: M2E Pro
Date: Tue, 13 Aug 2024 15:33:35 +0000
Subject: [PATCH] 1.66.0 (FINAL RELEASE)
---
Block/Adminhtml/Amazon/Account/Edit.php | 33 +--
.../Amazon/Account/Edit/Tabs/Order.php | 81 ++++--
.../Amazon/Listing/AllItems/Grid.php | 30 +++
Block/Adminhtml/Ebay/Account/Edit.php | 7 +
.../Ebay/Account/Edit/Tabs/Order.php | 98 +++----
.../Ebay/Category/View/Tabs/AbstractGrid.php | 13 +-
.../Ebay/Grid/Column/Renderer/OnlineSku.php | 45 ++++
.../Adminhtml/Ebay/Listing/AllItems/Grid.php | 44 +++-
.../Ebay/Listing/Edit/Tab/Categories.php | 11 -
.../Variation/Product/Manage/View/Grid.php | 2 +-
.../Adminhtml/Ebay/Listing/View/Ebay/Grid.php | 13 +-
.../Ebay/Listing/View/Settings/Grid.php | 11 +-
Block/Adminhtml/Ebay/Promotion/Grid.php | 149 ++++++-----
Block/Adminhtml/Walmart/Account/Edit.php | 16 +-
.../Walmart/Account/Edit/Tabs/Order.php | 117 ++++++---
.../Walmart/Listing/AllItems/Grid.php | 48 +++-
Controller/Adminhtml/Amazon/Account/Save.php | 109 ++++++--
.../Product/Add/CheckSearchResults.php | 17 +-
Controller/Adminhtml/Ebay/Account/Save.php | 98 ++++++-
.../Ebay/Promotion/OpenGridPromotion.php | 40 ++-
Controller/Adminhtml/Walmart/Account.php | 131 ----------
Controller/Adminhtml/Walmart/Account/Save.php | 247 ++++++++++++++++--
Helper/Module/Database/Tables.php | 9 +
Model/Account.php | 30 +--
Model/Amazon/Account.php | 26 ++
Model/Amazon/Account/Builder.php | 64 +++--
.../Account/MagentoOrderCreateService.php | 53 ++++
.../Amazon/AdvancedFilter/AllItemsOptions.php | 38 ++-
Model/Amazon/Order.php | 75 +++++-
Model/Amazon/Order/Item.php | 42 ++-
Model/Amazon/Order/Repository.php | 49 ++++
.../Amazon/Order/SendInvoice/Responser.php | 22 +-
.../Amazon/Order/Update/SellerOrderId.php | 18 +-
.../Cron/Task/Ebay/SynchronizePromotions.php | 117 +++++++++
Model/Cron/Task/Repository.php | 4 +
Model/Ebay/Account.php | 90 +++----
Model/Ebay/Account/Builder.php | 61 +++--
.../Account/MagentoOrderCreateService.php | 53 ++++
Model/Ebay/Account/Repository.php | 26 ++
Model/Ebay/AdvancedFilter/AllItemsOptions.php | 39 ++-
.../Promotion/Get/ItemsConnector.php | 1 +
Model/Ebay/Listing/Product/Repository.php | 44 ++++
Model/Ebay/Marketplace/Repository.php | 49 ++++
Model/Ebay/Order.php | 9 +-
Model/Ebay/Order/Item.php | 44 +++-
Model/Ebay/Order/Repository.php | 49 ++++
Model/Ebay/Promotion.php | 22 ++
Model/Ebay/Promotion/Collection.php | 11 +
Model/Ebay/Promotion/Create.php | 9 +-
.../Promotion/ExpiredPromotionsHandler.php | 89 +++++++
Model/Ebay/Promotion/ItemSynchronization.php | 190 ++++++++++++++
Model/Ebay/Promotion/Repository.php | 18 +-
Model/Ebay/Promotion/Synchronization.php | 7 +-
Model/Ebay/Promotion/TimingManager.php | 55 ++++
Model/Ebay/Promotion/Update.php | 8 +-
Model/Ebay/Promotion/UpdateFromChannel.php | 37 +--
Model/Listing/Log.php | 2 +-
Model/ResourceModel/Account.php | 19 +-
Model/ResourceModel/Amazon/Order.php | 19 +-
Model/ResourceModel/Ebay/Item.php | 21 +-
Model/ResourceModel/Ebay/Listing/Product.php | 1 +
.../Ebay/Listing/Product/Collection.php | 14 +-
.../Listing/Product/CollectionFactory.php | 3 +-
Model/ResourceModel/Ebay/Order.php | 22 +-
Model/ResourceModel/Listing.php | 1 +
Model/ResourceModel/Order.php | 20 +-
Model/ResourceModel/Walmart/Order.php | 20 +-
Model/Setup/Installer.php | 23 +-
Model/Setup/Upgrader.php | 1 +
Model/Walmart/Account.php | 49 ++--
Model/Walmart/Account/Builder.php | 58 ++--
.../Account/MagentoOrderCreateService.php | 53 ++++
.../AdvancedFilter/AllItemsOptions.php | 38 ++-
Model/Walmart/Order.php | 9 +-
Model/Walmart/Order/Item.php | 55 +++-
Model/Walmart/Order/Repository.php | 49 ++++
.../PreconditionsChecker/AbstractModel.php | 1 +
Setup/Update/Config.php | 3 +
.../AddDateOfInvoiceSendingToAmazonOrder.php | 18 ++
Setup/Upgrade/v1_65_2__v1_66_0/Config.php | 15 ++
composer.json | 2 +-
etc/module.xml | 2 +-
.../web/css/magento/form/datePicker.css | 7 +
view/adminhtml/web/js/Amazon/Account.js | 29 +-
view/adminhtml/web/js/Ebay/Account.js | 29 +-
view/adminhtml/web/js/Walmart/Account.js | 25 +-
86 files changed, 2601 insertions(+), 825 deletions(-)
create mode 100644 Block/Adminhtml/Ebay/Grid/Column/Renderer/OnlineSku.php
create mode 100644 Model/Amazon/Account/MagentoOrderCreateService.php
create mode 100644 Model/Amazon/Order/Repository.php
create mode 100644 Model/Cron/Task/Ebay/SynchronizePromotions.php
create mode 100644 Model/Ebay/Account/MagentoOrderCreateService.php
create mode 100644 Model/Ebay/Account/Repository.php
create mode 100644 Model/Ebay/Listing/Product/Repository.php
create mode 100644 Model/Ebay/Marketplace/Repository.php
create mode 100644 Model/Ebay/Order/Repository.php
create mode 100644 Model/Ebay/Promotion/ExpiredPromotionsHandler.php
create mode 100644 Model/Ebay/Promotion/ItemSynchronization.php
create mode 100644 Model/Ebay/Promotion/TimingManager.php
create mode 100644 Model/Walmart/Account/MagentoOrderCreateService.php
create mode 100644 Model/Walmart/Order/Repository.php
create mode 100644 Setup/Update/y24_m08/AddDateOfInvoiceSendingToAmazonOrder.php
create mode 100644 Setup/Upgrade/v1_65_2__v1_66_0/Config.php
create mode 100644 view/adminhtml/web/css/magento/form/datePicker.css
diff --git a/Block/Adminhtml/Amazon/Account/Edit.php b/Block/Adminhtml/Amazon/Account/Edit.php
index 672f1b417..51536ebbc 100644
--- a/Block/Adminhtml/Amazon/Account/Edit.php
+++ b/Block/Adminhtml/Amazon/Account/Edit.php
@@ -1,44 +1,23 @@
supportHelper = $supportHelper;
$this->globalDataHelper = $globalDataHelper;
$this->wizardHelper = $wizardHelper;
+
parent::__construct($context, $data);
}
@@ -145,10 +124,10 @@ public function _construct()
}
}
- //########################################
-
protected function _prepareLayout()
{
+ $this->css->addFile('magento/form/datePicker.css');
+
$this->jsTranslator->addTranslations([
'is_ready_for_document_generation' => __(
<<globalDataHelper->getValue('edit_account');
+ /** @var \Ess\M2ePro\Model\Amazon\Account|null $amazonAccount */
+ $amazonAccount = $account !== null ? $account->getChildObject() : null;
// ---------------------------------------
$websites = $this->storeWebsiteHelper->getWebsites(true);
@@ -140,7 +128,7 @@ protected function _prepareForm()
$none = ['value' => \Ess\M2ePro\Model\Magento\Product::TAX_CLASS_ID_NONE, 'label' => __('None')];
array_unshift($productTaxClasses, $none);
- $formData = $account !== null ? array_merge($account->getData(), $account->getChildObject()->getData()) : [];
+ $formData = $account !== null ? array_merge($account->getData(), $amazonAccount->getData()) : [];
$formData['magento_orders_settings'] = !empty($formData['magento_orders_settings'])
? \Ess\M2ePro\Helper\Json::decode($formData['magento_orders_settings']) : [];
@@ -228,6 +216,22 @@ protected function _prepareForm()
]
);
+ $fieldset->addField(
+ 'magento_orders_listings_create_from_date',
+ 'text',
+ [
+ 'container_id' => 'magento_orders_listings_create_from_date_container',
+ 'name' => 'magento_orders_settings[listing][create_from_date]',
+ 'label' => __('Create From Date'),
+ 'tooltip' => __(
+ 'Select the start date for channel orders to be created in Magento.'
+ . ' Orders purchased before this date will not be imported into Magento.'
+ ),
+ 'value' => $this->getMagentoOrdersListingsCreateFromDate($amazonAccount)
+ ->format('Y-m-d H:i:s')
+ ]
+ );
+
$fieldset->addField(
'magento_orders_listings_store_mode',
'select',
@@ -289,6 +293,22 @@ protected function _prepareForm()
]
);
+ $fieldset->addField(
+ 'magento_orders_listings_other_create_from_date',
+ 'text',
+ [
+ 'container_id' => 'magento_orders_listings_other_create_from_date_container',
+ 'name' => 'magento_orders_settings[listing_other][create_from_date]',
+ 'label' => __('Create From Date'),
+ 'tooltip' => __(
+ 'Select the start date for channel orders to be created in Magento.'
+ . ' Orders purchased before this date will not be imported into Magento.'
+ ),
+ 'value' => $this->getMagentoOrdersListingsOtherCreateFromDate($amazonAccount)
+ ->format('Y-m-d H:i:s'),
+ ]
+ );
+
$fieldset->addField(
'magento_orders_listings_other_store_id',
self::STORE_SWITCHER,
@@ -1077,4 +1097,35 @@ protected function _prepareForm()
return parent::_prepareForm();
}
+
+ private function getMagentoOrdersListingsCreateFromDate(
+ ?\Ess\M2ePro\Model\Amazon\Account $amazonAccount
+ ): \DateTime {
+ if ($amazonAccount === null) {
+ return \Ess\M2ePro\Helper\Date::createCurrentInCurrentZone();
+ }
+
+ return $amazonAccount
+ ->getMagentoOrdersListingsCreateFromDate()
+ ->setTimezone(self::getDateTimeZone());
+ }
+
+ private function getMagentoOrdersListingsOtherCreateFromDate(
+ ?\Ess\M2ePro\Model\Amazon\Account $amazonAccount
+ ): \DateTime {
+ if ($amazonAccount === null) {
+ return \Ess\M2ePro\Helper\Date::createCurrentInCurrentZone();
+ }
+
+ return $amazonAccount
+ ->getMagentoOrdersListingsOtherCreateFromDate()
+ ->setTimezone(self::getDateTimeZone());
+ }
+
+ public static function getDateTimeZone(): \DateTimeZone
+ {
+ return new \DateTimeZone(
+ \Ess\M2ePro\Helper\Date::getTimezone()->getConfigTimezone()
+ );
+ }
}
diff --git a/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php b/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php
index 833d5dfb4..f9929ef91 100644
--- a/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php
+++ b/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php
@@ -234,6 +234,7 @@ protected function _prepareAdvancedFilters()
$this->addProductTypeAdvancedFilter();
$this->addErrorsAdvancedFilter();
+ $this->addMagentoProductTypeAdvancedFilter();
parent::_prepareAdvancedFilters();
}
@@ -1817,4 +1818,33 @@ private function addTaxCodePolicyAdvancedFilter()
$this->addAdvancedFilter($filter);
}
+
+ private function addMagentoProductTypeAdvancedFilter(): void
+ {
+ $options = $this->advancedFilterAllItemsOptions->getMagentoProductTypeOptions();
+
+ if ($options->isEmpty()) {
+ return;
+ }
+
+ $filterCallback = function (
+ \Ess\M2ePro\Model\ResourceModel\Magento\Product\Collection $collection,
+ string $filterValue
+ ): void {
+ if (empty($filterValue)) {
+ return;
+ }
+
+ $collection->getSelect()->where('e.type_id = ?', $filterValue);
+ };
+
+ $filter = $this->advancedFilterFactory->createDropDownFilter(
+ 'magento_product_type',
+ __('Magento Product Type'),
+ $options,
+ $filterCallback
+ );
+
+ $this->addAdvancedFilter($filter);
+ }
}
diff --git a/Block/Adminhtml/Ebay/Account/Edit.php b/Block/Adminhtml/Ebay/Account/Edit.php
index 41cf5bd3c..e2ebfb213 100644
--- a/Block/Adminhtml/Ebay/Account/Edit.php
+++ b/Block/Adminhtml/Ebay/Account/Edit.php
@@ -65,4 +65,11 @@ protected function _construct()
$this->addButton('save_buttons', $saveButtons);
}
+
+ protected function _prepareLayout()
+ {
+ $this->css->addFile('magento/form/datePicker.css');
+
+ return parent::_prepareLayout();
+ }
}
diff --git a/Block/Adminhtml/Ebay/Account/Edit/Tabs/Order.php b/Block/Adminhtml/Ebay/Account/Edit/Tabs/Order.php
index 6eea6bea4..7d9d1b875 100644
--- a/Block/Adminhtml/Ebay/Account/Edit/Tabs/Order.php
+++ b/Block/Adminhtml/Ebay/Account/Edit/Tabs/Order.php
@@ -1,11 +1,5 @@
taxClass = $taxClass;
$this->supportHelper = $supportHelper;
$this->storeWebsite = $storeWebsite;
- $this->dataHelper = $dataHelper;
$this->magentoHelper = $magentoHelper;
$this->storeHelper = $storeHelper;
@@ -81,7 +49,8 @@ public function __construct(
protected function _prepareForm()
{
$account = $this->account;
-
+ /** @var \Ess\M2ePro\Model\Ebay\Account $ebayAccount */
+ $ebayAccount = $account->getChildObject();
$websites = $this->storeWebsite->getWebsites(true);
// ---------------------------------------
@@ -101,7 +70,7 @@ protected function _prepareForm()
$none = ['value' => \Ess\M2ePro\Model\Magento\Product::TAX_CLASS_ID_NONE, 'label' => $this->__('None')];
array_unshift($productTaxClasses, $none);
- $formData = array_merge($account->getData(), $account->getChildObject()->getData());
+ $formData = array_merge($account->getData(), $ebayAccount->getData());
$formData['magento_orders_settings'] = !empty($formData['magento_orders_settings'])
? \Ess\M2ePro\Helper\Json::decode($formData['magento_orders_settings']) : [];
@@ -162,6 +131,23 @@ protected function _prepareForm()
]
);
+ $fieldset->addField(
+ 'magento_orders_listings_create_from_date',
+ 'text',
+ [
+ 'container_id' => 'magento_orders_listings_create_from_date_container',
+ 'name' => 'magento_orders_settings[listing][create_from_date]',
+ 'label' => __('Create From Date'),
+ 'tooltip' => __(
+ 'Select the start date for channel orders to be created in Magento.'
+ . ' Orders purchased before this date will not be imported into Magento.'
+ ),
+ 'value' => $ebayAccount->getMagentoOrdersListingsCreateFromDate()
+ ->setTimezone(self::getDateTimeZone())
+ ->format('Y-m-d H:i:s'),
+ ]
+ );
+
$fieldset->addField(
'magento_orders_listings_store_mode',
'select',
@@ -222,6 +208,23 @@ protected function _prepareForm()
]
);
+ $fieldset->addField(
+ 'magento_orders_listings_other_create_from_date',
+ 'text',
+ [
+ 'container_id' => 'magento_orders_listings_other_create_from_date_container',
+ 'name' => 'magento_orders_settings[listing_other][create_from_date]',
+ 'label' => __('Create From Date'),
+ 'tooltip' => __(
+ 'Select the start date for channel orders to be created in Magento.'
+ . ' Orders purchased before this date will not be imported into Magento.'
+ ),
+ 'value' => $ebayAccount->getMagentoOrdersListingsOtherCreateFromDate()
+ ->setTimezone(self::getDateTimeZone())
+ ->format('Y-m-d H:i:s'),
+ ]
+ );
+
$fieldset->addField(
'magento_orders_listings_other_store_id',
self::STORE_SWITCHER,
@@ -837,4 +840,11 @@ protected function _prepareForm()
return parent::_prepareForm();
}
+
+ public static function getDateTimeZone(): \DateTimeZone
+ {
+ return new \DateTimeZone(
+ \Ess\M2ePro\Helper\Date::getTimezone()->getConfigTimezone()
+ );
+ }
}
diff --git a/Block/Adminhtml/Ebay/Category/View/Tabs/AbstractGrid.php b/Block/Adminhtml/Ebay/Category/View/Tabs/AbstractGrid.php
index c76f83f95..acd304222 100644
--- a/Block/Adminhtml/Ebay/Category/View/Tabs/AbstractGrid.php
+++ b/Block/Adminhtml/Ebay/Category/View/Tabs/AbstractGrid.php
@@ -71,6 +71,15 @@ protected function _prepareColumns()
]
);
+ $this->addColumn('online_sku', [
+ 'header' => __('Channel SKU'),
+ 'align' => 'left',
+ 'type' => 'text',
+ 'index' => 'online_sku',
+ 'escape' => false,
+ 'renderer' => \Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\OnlineSku::class,
+ ]);
+
$this->addColumn(
'is_custom_template',
[
@@ -215,9 +224,6 @@ public function callbackColumnTitle($value, $row, $column, $isExport)
->getSku();
}
- $onlineSku = $row->getData('online_sku');
- !empty($onlineSku) && $sku = $onlineSku;
-
$valueHtml .=
'
' . '' . $this->__('SKU') . ': ' . $this->escapeHtml($sku);
@@ -237,7 +243,6 @@ protected function callbackFilterTitle($collection, $column)
$collection->addFieldToFilter(
[
['attribute' => 'sku', 'like' => '%' . $value . '%'],
- ['attribute' => 'online_sku', 'like' => '%' . $value . '%'],
['attribute' => 'name', 'like' => '%' . $value . '%'],
['attribute' => 'online_title', 'like' => '%' . $value . '%'],
]
diff --git a/Block/Adminhtml/Ebay/Grid/Column/Renderer/OnlineSku.php b/Block/Adminhtml/Ebay/Grid/Column/Renderer/OnlineSku.php
new file mode 100644
index 000000000..7ec040de1
--- /dev/null
+++ b/Block/Adminhtml/Ebay/Grid/Column/Renderer/OnlineSku.php
@@ -0,0 +1,45 @@
+renderGeneral($row, false);
+ }
+
+ public function renderExport(\Magento\Framework\DataObject $row): string
+ {
+ return $this->renderGeneral($row, true);
+ }
+
+ public function renderGeneral(\Magento\Framework\DataObject $row, bool $isExport): string
+ {
+ $onlineSku = $this->_getValue($row);
+
+ if ($row->getChildObject() && ($onlineSku === null || $onlineSku === '')) {
+ $onlineSku = $row->getChildObject()->getData($this->getColumn()->getData('index'));
+ }
+
+ if ($row->getData('status') == \Ess\M2ePro\Model\Listing\Product::STATUS_NOT_LISTED) {
+ if ($isExport) {
+ return '';
+ }
+
+ return '' . __('Not Listed') . '';
+ }
+
+ if ($onlineSku === null || $onlineSku === '') {
+ if ($isExport) {
+ return '';
+ }
+
+ return (string)__('N/A');
+ }
+
+ return $onlineSku;
+ }
+}
diff --git a/Block/Adminhtml/Ebay/Listing/AllItems/Grid.php b/Block/Adminhtml/Ebay/Listing/AllItems/Grid.php
index 29d562079..94c9b4328 100644
--- a/Block/Adminhtml/Ebay/Listing/AllItems/Grid.php
+++ b/Block/Adminhtml/Ebay/Listing/AllItems/Grid.php
@@ -4,7 +4,6 @@
use Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\Qty as OnlineQty;
use Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product\Promotion as EbayListingProductPromotionResource;
-use Ess\M2ePro\Model\ResourceModel\Ebay\Promotion as EbayPromotionResource;
use Ess\M2ePro\Model\ResourceModel\Listing\Product\Variation\Option as ProductVariationOption;
class Grid extends \Ess\M2ePro\Block\Adminhtml\Magento\Grid\AbstractGrid
@@ -237,6 +236,15 @@ protected function _prepareColumns()
'filter_condition_callback' => [$this, 'callbackFilterTitle'],
]);
+ $this->addColumn('online_sku', [
+ 'header' => __('Channel SKU'),
+ 'align' => 'left',
+ 'type' => 'text',
+ 'index' => 'online_sku',
+ 'escape' => false,
+ 'renderer' => \Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\OnlineSku::class,
+ ]);
+
$this->addColumn('item_id', [
'header' => __('Item ID'),
'align' => 'left',
@@ -334,6 +342,7 @@ protected function _prepareAdvancedFilters()
$this->addErrorAdvancedFilter();
$this->addPromotionAdvancedFilter();
+ $this->addMagentoProductTypeAdvancedFilter();
parent::_prepareAdvancedFilters();
}
@@ -468,9 +477,6 @@ protected function getColumnProductTitleAdditionalHtml(\Magento\Catalog\Model\Pr
. ' ' . $marketplace->getTitle();
$sku = $row->getData('sku');
- $onlineSku = $row->getData('online_sku');
-
- !empty($onlineSku) && $sku = $onlineSku;
$sku = $this->dataHelper->escapeHtml($sku);
$skuWord = __('SKU');
@@ -636,7 +642,6 @@ protected function callbackFilterTitle(
$collection->addFieldToFilter([
['attribute' => 'sku', 'like' => '%' . $value . '%'],
- ['attribute' => 'online_sku', 'like' => '%' . $value . '%'],
['attribute' => 'name', 'like' => '%' . $value . '%'],
['attribute' => 'online_title', 'like' => '%' . $value . '%'],
['attribute' => 'listing_title', 'like' => '%' . $value . '%'],
@@ -1138,4 +1143,33 @@ private function addPromotionAdvancedFilter()
$this->addAdvancedFilter($filter);
}
+
+ private function addMagentoProductTypeAdvancedFilter(): void
+ {
+ $options = $this->advancedFilterAllItemsOptions->getMagentoProductTypeOptions();
+
+ if ($options->isEmpty()) {
+ return;
+ }
+
+ $filterCallback = function (
+ \Ess\M2ePro\Model\ResourceModel\Magento\Product\Collection $collection,
+ string $filterValue
+ ): void {
+ if (empty($filterValue)) {
+ return;
+ }
+
+ $collection->getSelect()->where('e.type_id = ?', $filterValue);
+ };
+
+ $filter = $this->advancedFilterFactory->createDropDownFilter(
+ 'magento_product_type',
+ __('Magento Product Type'),
+ $options,
+ $filterCallback
+ );
+
+ $this->addAdvancedFilter($filter);
+ }
}
diff --git a/Block/Adminhtml/Ebay/Listing/Edit/Tab/Categories.php b/Block/Adminhtml/Ebay/Listing/Edit/Tab/Categories.php
index fa210eb0b..7bcbbeb24 100644
--- a/Block/Adminhtml/Ebay/Listing/Edit/Tab/Categories.php
+++ b/Block/Adminhtml/Ebay/Listing/Edit/Tab/Categories.php
@@ -112,17 +112,6 @@ protected function _prepareLayout()
});
JS
);
-// $this->js->addOnReadyJs(
-// <<addColumn('online_sku', [
- 'header' => $this->__('SKU'),
+ 'header' => __('Channel SKU'),
'align' => 'left',
'width' => '150px',
'index' => 'online_sku',
diff --git a/Block/Adminhtml/Ebay/Listing/View/Ebay/Grid.php b/Block/Adminhtml/Ebay/Listing/View/Ebay/Grid.php
index 48f2f1e30..068c856b0 100644
--- a/Block/Adminhtml/Ebay/Listing/View/Ebay/Grid.php
+++ b/Block/Adminhtml/Ebay/Listing/View/Ebay/Grid.php
@@ -194,6 +194,15 @@ protected function _prepareColumns()
'filter_condition_callback' => [$this, 'callbackFilterTitle'],
]);
+ $this->addColumn('online_sku', [
+ 'header' => __('Channel SKU'),
+ 'align' => 'left',
+ 'type' => 'text',
+ 'index' => 'online_sku',
+ 'escape' => false,
+ 'renderer' => \Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\OnlineSku::class,
+ ]);
+
$this->addColumn('ebay_item_id', [
'header' => $this->__('Item ID'),
'align' => 'left',
@@ -369,9 +378,6 @@ public function callbackColumnTitle($value, $row, $column, $isExport)
->getSku();
}
- $onlineSku = $row->getData('online_sku');
- !empty($onlineSku) && $sku = $onlineSku;
-
if ($isExport) {
return $sku;
}
@@ -494,7 +500,6 @@ protected function callbackFilterTitle($collection, $column)
$collection->addFieldToFilter(
[
['attribute' => 'sku', 'like' => '%' . $value . '%'],
- ['attribute' => 'online_sku', 'like' => '%' . $value . '%'],
['attribute' => 'name', 'like' => '%' . $value . '%'],
['attribute' => 'online_title', 'like' => '%' . $value . '%'],
['attribute' => 'online_main_category', 'like' => '%' . $value . '%'],
diff --git a/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php b/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php
index d3679b72a..e0488d5fd 100644
--- a/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php
+++ b/Block/Adminhtml/Ebay/Listing/View/Settings/Grid.php
@@ -111,7 +111,7 @@ protected function _prepareCollection(): Grid
'product_id=entity_id',
[
'id' => 'id',
- 'ebay_status' => 'status',
+ 'status' => 'status',
'additional_data' => 'additional_data',
],
'{{table}}.listing_id=' . (int)$this->listing->getId()
@@ -320,6 +320,15 @@ protected function _prepareColumns(): Grid
'filter_condition_callback' => [$this, 'callbackFilterTitle'],
]);
+ $this->addColumn('online_sku', [
+ 'header' => __('Channel SKU'),
+ 'align' => 'left',
+ 'type' => 'text',
+ 'index' => 'online_sku',
+ 'escape' => false,
+ 'renderer' => \Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\OnlineSku::class,
+ ]);
+
if ($this->isMotorsAvailable() && $this->motorsAttribute) {
$this->addColumn('parts_motors_attribute_value', [
'header' => $this->__('Compatibility'),
diff --git a/Block/Adminhtml/Ebay/Promotion/Grid.php b/Block/Adminhtml/Ebay/Promotion/Grid.php
index d1f495c34..a561e7a54 100644
--- a/Block/Adminhtml/Ebay/Promotion/Grid.php
+++ b/Block/Adminhtml/Ebay/Promotion/Grid.php
@@ -4,9 +4,12 @@
namespace Ess\M2ePro\Block\Adminhtml\Ebay\Promotion;
+use Ess\M2ePro\Model\Ebay\Promotion;
+
class Grid extends \Ess\M2ePro\Block\Adminhtml\Magento\Grid\AbstractGrid
{
- private \Ess\M2ePro\Helper\Data\GlobalData $globalDataHelper;
+ private int $accountId;
+ private int $marketplaceId;
private \Ess\M2ePro\Model\ResourceModel\Ebay\Promotion\CollectionFactory $collectionFactory;
private \Ess\M2ePro\Model\Ebay\Promotion\DashboardUrlGenerator $dashboardUrlGenerator;
@@ -15,11 +18,11 @@ public function __construct(
\Ess\M2ePro\Model\ResourceModel\Ebay\Promotion\CollectionFactory $collectionFactory,
\Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context,
\Magento\Backend\Helper\Data $backendHelper,
- \Ess\M2ePro\Helper\Data\GlobalData $globalDataHelper,
array $data = []
) {
+ $this->accountId = $data['accountId'];
+ $this->marketplaceId = $data['marketplaceId'];
$this->collectionFactory = $collectionFactory;
- $this->globalDataHelper = $globalDataHelper;
$this->dashboardUrlGenerator = $dashboardUrlGenerator;
parent::__construct($context, $backendHelper, $data);
}
@@ -38,9 +41,7 @@ public function _construct(): void
$this->setDefaultSort('promotion_id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
- $this->setFilterVisibility(false);
- $this->setPagerVisibility(false);
- $this->setDefaultLimit(100);
+ $this->setDefaultLimit(20);
$this->setUseAjax(true);
// ---------------------------------------
}
@@ -49,11 +50,8 @@ protected function _prepareCollection(): Grid
{
$collection = $this->collectionFactory->create();
- $accountId = $this->globalDataHelper->getValue('accountId');
- $marketplaceId = $this->globalDataHelper->getValue('marketplaceId');
-
- $collection->addFieldToFilter('main_table.marketplace_id', $marketplaceId);
- $collection->addFieldToFilter('main_table.account_id', $accountId);
+ $collection->addFieldToFilter('main_table.marketplace_id', $this->marketplaceId);
+ $collection->addFieldToFilter('main_table.account_id', $this->accountId);
$this->setCollection($collection);
@@ -68,31 +66,30 @@ protected function _prepareColumns(): void
'type' => 'text',
'width' => '150px',
'index' => 'name',
- 'filter' => false,
- 'sortable' => false,
- 'frame_callback' => [$this, 'callbackColumnName'],
+ 'sortable' => true,
]);
$this->addColumn('type', [
'header' => __('Type'),
'align' => 'right',
- 'type' => 'text',
+ 'type' => 'options',
'width' => '75px',
'index' => 'type',
- 'filter' => false,
- 'sortable' => false,
- 'frame_callback' => [$this, 'callbackColumnType'],
+ 'filter_index' => 'type',
+ 'sortable' => true,
+ 'options' => $this->getFormattedPromotionTypeOptions(),
+ 'filter_condition_callback' => [$this, 'callbackFilterType'],
]);
$this->addColumn('status', [
'header' => __('Status'),
'align' => 'right',
- 'type' => 'text',
+ 'type' => 'options',
'width' => '75px',
'index' => 'status',
- 'filter' => false,
- 'sortable' => false,
- 'frame_callback' => [$this, 'callbackColumnStatus'],
+ 'sortable' => true,
+ 'options' => $this->getFormattedPromotionStatusOptions(),
+ 'filter_condition_callback' => [$this, 'callbackFilterStatus'],
]);
$this->addColumn('start_date', [
@@ -100,9 +97,10 @@ protected function _prepareColumns(): void
'align' => 'left',
'type' => 'datetime',
'index' => 'start_date',
- 'format' => \IntlDateFormatter::MEDIUM,
- 'filter' => false,
- 'sortable' => false,
+ 'filter' => \Ess\M2ePro\Block\Adminhtml\Magento\Grid\Column\Filter\Datetime::class,
+ 'sortable' => true,
+ 'filter_index' => 'start_date',
+ 'renderer' => \Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\DateTime::class,
]);
$this->addColumn('end_date', [
@@ -110,9 +108,10 @@ protected function _prepareColumns(): void
'align' => 'left',
'type' => 'datetime',
'index' => 'end_date',
- 'format' => \IntlDateFormatter::MEDIUM,
- 'filter' => false,
- 'sortable' => false,
+ 'filter' => \Ess\M2ePro\Block\Adminhtml\Magento\Grid\Column\Filter\Datetime::class,
+ 'sortable' => true,
+ 'filter_index' => 'end_date',
+ 'renderer' => \Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\DateTime::class,
]);
$this->addColumn('actions', [
@@ -126,19 +125,32 @@ protected function _prepareColumns(): void
]);
}
- public function callbackColumnName($value, $row, $column, $isExport): string
+ private function getFormattedPromotionTypeOptions(): array
{
- return $value;
+ return $this->formatOptions(Promotion::getTypes());
}
- public function callbackColumnType($value, $row, $column, $isExport): string
+ private function getFormattedPromotionStatusOptions(): array
{
- return $this->formatPromotionTypeOrStatus($value);
+ return $this->formatOptions(Promotion::getStatuses());
}
- public function callbackColumnStatus($value, $row, $column, $isExport): string
+ private function formatOptions(array $options): array
{
- return $this->formatPromotionTypeOrStatus($value);
+ $formattedOptions = [];
+ foreach ($options as $option) {
+ $formattedOptions[$option] = $this->formatPromotionTypeOrStatus($option);
+ }
+ return $formattedOptions;
+ }
+
+ private function formatPromotionTypeOrStatus(string $type): string
+ {
+ $parts = explode('_', $type);
+ $formattedParts = array_map(function ($part) {
+ return ucfirst(strtolower($part));
+ }, $parts);
+ return implode(' ', $formattedParts);
}
public function callbackColumnActions($value, $row, $column, $isExport): string
@@ -163,46 +175,61 @@ public function callbackColumnActions($value, $row, $column, $isExport): string
HTML;
}
- private function formatPromotionTypeOrStatus(string $type): string
+ public function callbackFilterType($collection, $column): void
{
- $parts = explode('_', $type);
+ $value = $column->getFilter()->getValue();
+ if ($value === null) {
+ return;
+ }
- $formattedParts = array_map(function ($part) {
- return ucfirst(strtolower($part));
- }, $parts);
+ $collection->addFieldToFilter('type', $value);
+ }
- return implode(' ', $formattedParts);
+ public function callbackFilterStatus($collection, $column): void
+ {
+ $value = $column->getFilter()->getValue();
+ if ($value === null) {
+ return;
+ }
+
+ $collection->addFieldToFilter('status', $value);
}
protected function getHelpBlockHtml(): string
{
- $helpBlockHtml = '';
-
- if ($this->canDisplayContainer()) {
- $content = __(
- <<In this section, you can manage your eBay promotions. Browse your active and scheduled promotions,
- apply them to your listings, or remove any that are no longer needed. To create a new promotion or
- modify existing ones, you can do so easily through your eBay Seller Hub
- (link).
- Important: Please be aware that adding new items to an existing promotion will
- overwrite any items that were previously included. Due to eBay API restrictions, each promotion can
- include a maximum of 500 items.
-HTML
- ,
- $this->dashboardUrlGenerator->generate((int)$this->globalDataHelper->getValue('marketplaceId'))
- );
-
- $helpBlockHtml = $this->getLayout()->createBlock(\Ess\M2ePro\Block\Adminhtml\HelpBlock::class)->setData([
- 'content' => $content,
- ])->toHtml();
+ if (!$this->canDisplayContainer()) {
+ return '';
}
- return $helpBlockHtml;
+ $content = __(
+ 'In this section, you can manage your eBay promotions. Browse your active and scheduled promotions,'
+ . ' apply them to your listings, or remove any that are no longer needed. To create a new promotion or'
+ . ' modify existing ones, you can do so easily through your eBay Seller Hub'
+ . ' (link).
'
+ . ' Important: Please be aware that adding new items to an existing promotion will'
+ . ' overwrite any items that were previously included. Due to eBay API restrictions, each promotion can'
+ . ' include a maximum of 500 items.
',
+ ['url' => $this->dashboardUrlGenerator->generate($this->marketplaceId)]
+ );
+
+ return $this->getLayout()->createBlock(\Ess\M2ePro\Block\Adminhtml\HelpBlock::class)
+ ->setData(['content' => $content,])
+ ->toHtml();
}
protected function _toHtml(): string
{
return $this->getHelpBlockHtml() . parent::_toHtml();
}
+
+ public function getGridUrl(): string
+ {
+ return $this->getUrl('*/ebay_promotion/openGridPromotion', [
+ '_current' => true,
+ '_query' => [
+ 'account_id' => $this->accountId,
+ 'marketplace_id' => $this->marketplaceId,
+ ],
+ ]);
+ }
}
diff --git a/Block/Adminhtml/Walmart/Account/Edit.php b/Block/Adminhtml/Walmart/Account/Edit.php
index 21e2e0526..490db7d83 100644
--- a/Block/Adminhtml/Walmart/Account/Edit.php
+++ b/Block/Adminhtml/Walmart/Account/Edit.php
@@ -1,21 +1,13 @@
globalDataHelper = $globalDataHelper;
$this->wizardHelper = $wizardHelper;
+
parent::__construct($context, $data);
}
@@ -151,12 +144,15 @@ public function _construct()
protected function _prepareLayout()
{
+ $this->css->addFile('magento/form/datePicker.css');
+
$this->js->add(
<<orderConfig = $orderConfig;
@@ -65,7 +34,6 @@ public function __construct(
$this->supportHelper = $supportHelper;
$this->storeWebsite = $storeWebsite;
$this->globalDataHelper = $globalDataHelper;
- $this->magentoHelper = $magentoHelper;
$this->storeHelper = $storeHelper;
parent::__construct($context, $registry, $formFactory, $data);
@@ -73,8 +41,12 @@ public function __construct(
protected function _prepareForm()
{
+ /** @var \Ess\M2ePro\Model\Account|null $account */
$account = $this->globalDataHelper->getValue('edit_account');
- $ordersSettings = $account !== null ? $account->getChildObject()->getData('magento_orders_settings') : [];
+ /** @var \Ess\M2ePro\Model\Walmart\Account|null $walmartAccount */
+ $walmartAccount = $account !== null ? $account->getChildObject() : null;
+
+ $ordersSettings = $walmartAccount !== null ? $walmartAccount->getData('magento_orders_settings') : [];
$ordersSettings = !empty($ordersSettings) ? \Ess\M2ePro\Helper\Json::decode($ordersSettings) : [];
// ---------------------------------------
@@ -156,6 +128,22 @@ protected function _prepareForm()
]
);
+ $fieldset->addField(
+ 'magento_orders_listings_create_from_date',
+ 'text',
+ [
+ 'container_id' => 'magento_orders_listings_create_from_date_container',
+ 'name' => 'magento_orders_settings[listing][create_from_date]',
+ 'label' => __('Create From Date'),
+ 'tooltip' => __(
+ 'Select the start date for channel orders to be created in Magento.'
+ . ' Orders purchased before this date will not be imported into Magento.'
+ ),
+ 'value' => $this->getMagentoOrdersListingsCreateFromDate($walmartAccount)
+ ->format('Y-m-d H:i:s')
+ ]
+ );
+
$fieldset->addField(
'magento_orders_listings_store_mode',
'select',
@@ -217,6 +205,22 @@ protected function _prepareForm()
]
);
+ $fieldset->addField(
+ 'magento_orders_listings_other_create_from_date',
+ 'text',
+ [
+ 'container_id' => 'magento_orders_listings_other_create_from_date_container',
+ 'name' => 'magento_orders_settings[listing_other][create_from_date]',
+ 'label' => __('Create From Date'),
+ 'tooltip' => __(
+ 'Select the start date for channel orders to be created in Magento.'
+ . ' Orders purchased before this date will not be imported into Magento.'
+ ),
+ 'value' => $this->getMagentoOrdersListingsOtherCreateFromDate($walmartAccount)
+ ->format('Y-m-d H:i:s'),
+ ]
+ );
+
$fieldset->addField(
'magento_orders_listings_other_store_id',
self::STORE_SWITCHER,
@@ -767,4 +771,35 @@ protected function _prepareForm()
return parent::_prepareForm();
}
+
+ private function getMagentoOrdersListingsCreateFromDate(
+ ?\Ess\M2ePro\Model\Walmart\Account $walmartAccount
+ ): \DateTime {
+ if ($walmartAccount === null) {
+ return \Ess\M2ePro\Helper\Date::createCurrentInCurrentZone();
+ }
+
+ return $walmartAccount
+ ->getMagentoOrdersListingsCreateFromDate()
+ ->setTimezone(self::getDateTimeZone());
+ }
+
+ private function getMagentoOrdersListingsOtherCreateFromDate(
+ ?\Ess\M2ePro\Model\Walmart\Account $walmartAccount
+ ): \DateTime {
+ if ($walmartAccount === null) {
+ return \Ess\M2ePro\Helper\Date::createCurrentInCurrentZone();
+ }
+
+ return $walmartAccount
+ ->getMagentoOrdersListingsOtherCreateFromDate()
+ ->setTimezone(self::getDateTimeZone());
+ }
+
+ public static function getDateTimeZone(): \DateTimeZone
+ {
+ return new \DateTimeZone(
+ \Ess\M2ePro\Helper\Date::getTimezone()->getConfigTimezone()
+ );
+ }
}
diff --git a/Block/Adminhtml/Walmart/Listing/AllItems/Grid.php b/Block/Adminhtml/Walmart/Listing/AllItems/Grid.php
index c74ffc110..52e412a40 100644
--- a/Block/Adminhtml/Walmart/Listing/AllItems/Grid.php
+++ b/Block/Adminhtml/Walmart/Listing/AllItems/Grid.php
@@ -33,12 +33,12 @@ class Grid extends \Ess\M2ePro\Block\Adminhtml\Magento\Grid\AbstractGrid
/** @var \Ess\M2ePro\Model\ResourceModel\Walmart\Listing */
private $walmartListingResource;
/** @var \Ess\M2ePro\Model\Walmart\AdvancedFilter\AllItemsOptions */
- private $advancedFiltersAllItemsOptions;
+ private $advancedFilterAllItemsOptions;
/** @var \Ess\M2ePro\Block\Adminhtml\Widget\Grid\AdvancedFilter\FilterFactory */
private $advancedFilterFactory;
public function __construct(
- \Ess\M2ePro\Model\Walmart\AdvancedFilter\AllItemsOptions $advancedFiltersAllItemsOptions,
+ \Ess\M2ePro\Model\Walmart\AdvancedFilter\AllItemsOptions $advancedFilterAllItemsOptions,
\Ess\M2ePro\Block\Adminhtml\Widget\Grid\AdvancedFilter\FilterFactory $advancedFilterFactory,
\Ess\M2ePro\Model\ResourceModel\Listing $listingResource,
\Ess\M2ePro\Model\ResourceModel\Walmart\Listing $walmartListingResource,
@@ -62,7 +62,7 @@ public function __construct(
$this->listingProductResource = $listingProductResource;
$this->walmartListingProductResource = $walmartListingProductResource;
$this->walmartListingResource = $walmartListingResource;
- $this->advancedFiltersAllItemsOptions = $advancedFiltersAllItemsOptions;
+ $this->advancedFilterAllItemsOptions = $advancedFilterAllItemsOptions;
$this->advancedFilterFactory = $advancedFilterFactory;
parent::__construct($context, $backendHelper, $data);
@@ -301,6 +301,7 @@ protected function _prepareAdvancedFilters()
$this->addDescriptionPolicyAdvancedFilter();
$this->addCategoryAdvancedFilter();
+ $this->addMagentoProductTypeAdvancedFilter();
parent::_prepareAdvancedFilters();
}
@@ -1105,7 +1106,7 @@ public function getRowUrl($item)
private function addMarketplaceAdvancedFilter(): void
{
- $options = $this->advancedFiltersAllItemsOptions->getMarketplaceOptions();
+ $options = $this->advancedFilterAllItemsOptions->getMarketplaceOptions();
if ($options->isEmpty()) {
return;
}
@@ -1133,7 +1134,7 @@ private function addMarketplaceAdvancedFilter(): void
private function addAccountAdvancedFilter(): void
{
- $options = $this->advancedFiltersAllItemsOptions->getAccountOptions();
+ $options = $this->advancedFilterAllItemsOptions->getAccountOptions();
if ($options->isEmpty()) {
return;
}
@@ -1161,7 +1162,7 @@ private function addAccountAdvancedFilter(): void
private function addSellingPolicyAdvancedFilter(): void
{
- $options = $this->advancedFiltersAllItemsOptions->getSellingPolicyOptions();
+ $options = $this->advancedFilterAllItemsOptions->getSellingPolicyOptions();
if ($options->isEmpty()) {
return;
}
@@ -1191,7 +1192,7 @@ private function addSellingPolicyAdvancedFilter(): void
private function addSynchronizationPolicyAdvancedFilter()
{
- $options = $this->advancedFiltersAllItemsOptions->getSynchronizationPolicyOptions();
+ $options = $this->advancedFilterAllItemsOptions->getSynchronizationPolicyOptions();
if ($options->isEmpty()) {
return;
}
@@ -1221,7 +1222,7 @@ private function addSynchronizationPolicyAdvancedFilter()
private function addDescriptionPolicyAdvancedFilter()
{
- $options = $this->advancedFiltersAllItemsOptions->getDescriptionPolicyOptions();
+ $options = $this->advancedFilterAllItemsOptions->getDescriptionPolicyOptions();
if ($options->isEmpty()) {
return;
}
@@ -1251,7 +1252,7 @@ private function addDescriptionPolicyAdvancedFilter()
private function addCategoryAdvancedFilter()
{
- $options = $this->advancedFiltersAllItemsOptions->getCategoryOptions();
+ $options = $this->advancedFilterAllItemsOptions->getCategoryOptions();
if ($options->isEmpty()) {
return;
}
@@ -1276,4 +1277,33 @@ private function addCategoryAdvancedFilter()
$this->addAdvancedFilter($filter);
}
+
+ private function addMagentoProductTypeAdvancedFilter(): void
+ {
+ $options = $this->advancedFilterAllItemsOptions->getMagentoProductTypeOptions();
+
+ if ($options->isEmpty()) {
+ return;
+ }
+
+ $filterCallback = function (
+ \Ess\M2ePro\Model\ResourceModel\Magento\Product\Collection $collection,
+ string $filterValue
+ ): void {
+ if (empty($filterValue)) {
+ return;
+ }
+
+ $collection->getSelect()->where('e.type_id = ?', $filterValue);
+ };
+
+ $filter = $this->advancedFilterFactory->createDropDownFilter(
+ 'magento_product_type',
+ __('Magento Product Type'),
+ $options,
+ $filterCallback
+ );
+
+ $this->addAdvancedFilter($filter);
+ }
}
diff --git a/Controller/Adminhtml/Amazon/Account/Save.php b/Controller/Adminhtml/Amazon/Account/Save.php
index d439a2ff7..3bea1090b 100644
--- a/Controller/Adminhtml/Amazon/Account/Save.php
+++ b/Controller/Adminhtml/Amazon/Account/Save.php
@@ -6,27 +6,22 @@
class Save extends \Ess\M2ePro\Controller\Adminhtml\Amazon\Account
{
- /** @var \Ess\M2ePro\Helper\Magento */
- private $magentoHelper;
- /** @var \Ess\M2ePro\Model\Amazon\Account\Builder */
- private $accountBuilder;
- /** @var \Ess\M2ePro\Helper\Module\Wizard */
- private $helperWizard;
- /** @var \Ess\M2ePro\Helper\Data */
- private $helperData;
- /** @var \Ess\M2ePro\Helper\Module\Exception */
- private $exceptionHelper;
- /** @var \Ess\M2ePro\Helper\Module\Support */
- private $supportHelper;
- /** @var \Ess\M2ePro\Model\Amazon\Account\MerchantSetting\CreateService */
- private $accountMerchantSettingsCreateService;
+ private \Ess\M2ePro\Model\Amazon\Account\MagentoOrderCreateService $magentoOrderCreateService;
+ private \Ess\M2ePro\Helper\Magento $magentoHelper;
+ private \Ess\M2ePro\Model\Amazon\Account\Builder $accountBuilder;
+ private \Ess\M2ePro\Helper\Module\Wizard $helperWizard;
+ private \Ess\M2ePro\Helper\Url $urlHelper;
+ private \Ess\M2ePro\Helper\Module\Exception $exceptionHelper;
+ private \Ess\M2ePro\Helper\Module\Support $supportHelper;
+ private \Ess\M2ePro\Model\Amazon\Account\MerchantSetting\CreateService $accountMerchantSettingsCreateService;
public function __construct(
+ \Ess\M2ePro\Model\Amazon\Account\MagentoOrderCreateService $magentoOrderCreateService,
\Ess\M2ePro\Helper\Magento $magentoHelper,
\Ess\M2ePro\Model\Amazon\Account\Builder $accountBuilder,
\Ess\M2ePro\Model\Amazon\Account\MerchantSetting\CreateService $accountMerchantSettingsCreateService,
\Ess\M2ePro\Helper\Module\Wizard $helperWizard,
- \Ess\M2ePro\Helper\Data $helperData,
+ \Ess\M2ePro\Helper\Url $urlHelper,
\Ess\M2ePro\Helper\Module\Exception $exceptionHelper,
\Ess\M2ePro\Helper\Module\Support $supportHelper,
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Amazon\Factory $amazonFactory,
@@ -34,10 +29,11 @@ public function __construct(
) {
parent::__construct($amazonFactory, $context);
+ $this->magentoOrderCreateService = $magentoOrderCreateService;
$this->magentoHelper = $magentoHelper;
$this->accountBuilder = $accountBuilder;
$this->helperWizard = $helperWizard;
- $this->helperData = $helperData;
+ $this->urlHelper = $urlHelper;
$this->exceptionHelper = $exceptionHelper;
$this->supportHelper = $supportHelper;
$this->accountMerchantSettingsCreateService = $accountMerchantSettingsCreateService;
@@ -56,6 +52,8 @@ public function execute()
/** @var \Ess\M2ePro\Model\Account $account */
$account = $this->amazonFactory->getObjectLoaded('Account', $id);
+ /** @var \Ess\M2ePro\Model\Amazon\Account $amazonAccount */
+ $amazonAccount = $account->getChildObject();
if (empty($id) || !$account->getId()) {
$this->messageManager->addErrorMessage(__('Account does not exists.'));
@@ -63,6 +61,8 @@ public function execute()
return $this->_redirect('*/*/index');
}
+ $previousMagentoOrdersSettings = $this->getPreviousMagentoOrdersSettings($amazonAccount);
+
try {
$this->updateAccount($account, $formData);
} catch (\Throwable $e) {
@@ -78,6 +78,12 @@ public function execute()
return $this->_redirect('*/*/index');
}
+ try {
+ $this->createMagentoOrders($amazonAccount, $previousMagentoOrdersSettings);
+ } catch (\Throwable $e) {
+ $this->exceptionHelper->process($e);
+ }
+
if ($this->isAjax()) {
$this->setJsonContent([
'success' => true,
@@ -86,7 +92,7 @@ public function execute()
return $this->getResult();
}
- $this->messageManager->addSuccess(__('Account was saved'));
+ $this->messageManager->addSuccessMessage(__('Account was saved'));
$routerParams = ['id' => $account->getId(), '_current' => true];
if (
@@ -96,15 +102,12 @@ public function execute()
$routerParams['wizard'] = true;
}
- return $this->_redirect($this->helperData->getBackUrl('list', [], ['edit' => $routerParams]));
+ return $this->_redirect($this->urlHelper->getBackUrl('list', [], ['edit' => $routerParams]));
}
- /**
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
private function updateAccount(\Ess\M2ePro\Model\Account $account, array $data): void
{
- $this->accountBuilder->build($account, $data);
+ $this->saveAccount($account, $data);
if ($this->magentoHelper->isMSISupportingVersion()) {
$this->accountMerchantSettingsCreateService->update(
@@ -119,4 +122,66 @@ private function updateAccount(\Ess\M2ePro\Model\Account $account, array $data):
);
}
}
+
+ private function saveAccount(\Ess\M2ePro\Model\Account $account, array $data): void
+ {
+ $data['magento_orders_settings']['listing']['create_from_date'] = new \DateTime(
+ $data['magento_orders_settings']['listing']['create_from_date'],
+ \Ess\M2ePro\Block\Adminhtml\Amazon\Account\Edit\Tabs\Order::getDateTimeZone()
+ );
+
+ $data['magento_orders_settings']['listing_other']['create_from_date'] = new \DateTime(
+ $data['magento_orders_settings']['listing_other']['create_from_date'],
+ \Ess\M2ePro\Block\Adminhtml\Amazon\Account\Edit\Tabs\Order::getDateTimeZone()
+ );
+
+ $this->accountBuilder->build($account, $data);
+ }
+
+ private function getPreviousMagentoOrdersSettings(\Ess\M2ePro\Model\Amazon\Account $amazonAccount): array
+ {
+ return [
+ 'listing' => [
+ 'is_enabled' => $amazonAccount->isMagentoOrdersListingsModeEnabled(),
+ 'create_from_date' => $amazonAccount->getMagentoOrdersListingsCreateFromDate(),
+ ],
+ 'listing_other' => [
+ 'is_enabled' => $amazonAccount->isMagentoOrdersListingsOtherModeEnabled(),
+ 'create_from_date' => $amazonAccount->getMagentoOrdersListingsOtherCreateFromDate(),
+ ],
+ ];
+ }
+
+ private function createMagentoOrders(
+ \Ess\M2ePro\Model\Amazon\Account $amazonAccount,
+ array $previousMagentoOrdersSettings
+ ): void {
+ if (
+ $amazonAccount->isMagentoOrdersListingsModeEnabled()
+ && (
+ $previousMagentoOrdersSettings['listing']['is_enabled'] === false
+ || $amazonAccount->getMagentoOrdersListingsCreateFromDate()->format('Y-m-d H:i:s')
+ !== $previousMagentoOrdersSettings['listing']['create_from_date']->format('Y-m-d H:i:s')
+ )
+ ) {
+ $this->magentoOrderCreateService->createMagentoOrdersListingsByFromDate(
+ (int)$amazonAccount->getId(),
+ $amazonAccount->getMagentoOrdersListingsCreateFromDate()
+ );
+ }
+
+ if (
+ $amazonAccount->isMagentoOrdersListingsOtherModeEnabled()
+ && (
+ $previousMagentoOrdersSettings['listing_other']['is_enabled'] === false
+ || $amazonAccount->getMagentoOrdersListingsOtherCreateFromDate()->format('Y-m-d H:i:s')
+ !== $previousMagentoOrdersSettings['listing_other']['create_from_date']->format('Y-m-d H:i:s')
+ )
+ ) {
+ $this->magentoOrderCreateService->createMagentoOrdersListingsOtherByFromDate(
+ (int)$amazonAccount->getId(),
+ $amazonAccount->getMagentoOrdersListingsOtherCreateFromDate()
+ );
+ }
+ }
}
diff --git a/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php b/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php
index 084db7794..01dd13237 100644
--- a/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php
+++ b/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php
@@ -1,16 +1,7 @@
filterProductsForNewAsin($listingProductsIds);
if (
- empty($listingProductsIds) ||
- !$this->getListing()->getMarketplace()->getChildObject()->isNewAsinAvailable()
+ empty($listingProductsIds)
+ || !$this->getListing()->getMarketplace()->getChildObject()->isNewAsinAvailable()
) {
$redirectUrl = $this->getUrl('*/*/index', [
- 'step' => 5,
+ 'step' => 6,
'id' => $this->getRequest()->getParam('id'),
'wizard' => $this->getRequest()->getParam('wizard'),
]);
@@ -47,7 +38,7 @@ public function execute()
$this->setJsonContent([
'redirect' => $this->getUrl('*/*/index', [
'id' => $this->getRequest()->getParam('id'),
- 'step' => $showNewAsinStep ? 4 : 5,
+ 'step' => $showNewAsinStep ? 4 : 6,
'wizard' => $this->getRequest()->getParam('wizard'),
]),
]);
diff --git a/Controller/Adminhtml/Ebay/Account/Save.php b/Controller/Adminhtml/Ebay/Account/Save.php
index 4a01babb5..984e92a55 100644
--- a/Controller/Adminhtml/Ebay/Account/Save.php
+++ b/Controller/Adminhtml/Ebay/Account/Save.php
@@ -4,18 +4,16 @@
class Save extends \Ess\M2ePro\Controller\Adminhtml\Ebay\Account
{
- /** @var \Ess\M2ePro\Helper\Module\Exception */
- private $helperException;
-
- /** @var \Ess\M2ePro\Helper\Data */
- private $helperData;
- /** @var \Ess\M2ePro\Model\Ebay\Account\Update */
- private $accountUpdate;
+ private \Ess\M2ePro\Model\Ebay\Account\MagentoOrderCreateService $magentoOrderCreateService;
+ private \Ess\M2ePro\Helper\Module\Exception $helperException;
+ private \Ess\M2ePro\Model\Ebay\Account\Update $accountUpdate;
+ private \Ess\M2ePro\Helper\Url $urlHelper;
public function __construct(
+ \Ess\M2ePro\Model\Ebay\Account\MagentoOrderCreateService $magentoOrderCreateService,
\Ess\M2ePro\Model\Ebay\Account\Update $accountUpdate,
\Ess\M2ePro\Helper\Module\Exception $helperException,
- \Ess\M2ePro\Helper\Data $helperData,
+ \Ess\M2ePro\Helper\Url $urlHelper,
\Ess\M2ePro\Model\Ebay\Account\Store\Category\Update $storeCategoryUpdate,
\Ess\M2ePro\Helper\Component\Ebay\Category\Store $componentEbayCategoryStore,
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Ebay\Factory $ebayFactory,
@@ -23,9 +21,10 @@ public function __construct(
) {
parent::__construct($storeCategoryUpdate, $componentEbayCategoryStore, $ebayFactory, $context);
+ $this->magentoOrderCreateService = $magentoOrderCreateService;
$this->accountUpdate = $accountUpdate;
$this->helperException = $helperException;
- $this->helperData = $helperData;
+ $this->urlHelper = $urlHelper;
}
public function execute()
@@ -39,10 +38,15 @@ public function execute()
$id = (int)$this->getRequest()->getParam('id');
$data = $post->toArray();
+ /** @var \Ess\M2ePro\Model\Account $account */
$account = $this->ebayFactory->getObjectLoaded('Account', $id);
+ /** @var \Ess\M2ePro\Model\Ebay\Account $ebayAccount */
+ $ebayAccount = $account->getChildObject();
+
+ $previousMagentoOrdersSettings = $this->getPreviousMagentoOrdersSettings($ebayAccount);
try {
- $account = $this->accountUpdate->updateSettings($account, $data);
+ $account = $this->updateSettings($account, $data);
} catch (\Throwable $exception) {
$this->helperException->process($exception);
@@ -60,11 +64,17 @@ public function execute()
return $this->getResult();
}
- $this->messageManager->addError($message);
+ $this->messageManager->addErrorMessage($message);
return $this->_redirect('*/ebay_account');
}
+ try {
+ $this->createMagentoOrders($ebayAccount, $previousMagentoOrdersSettings);
+ } catch (\Throwable $exception) {
+ $this->helperException->process($exception);
+ }
+
if ($this->isAjax()) {
$this->setJsonContent([
'success' => true,
@@ -73,10 +83,10 @@ public function execute()
return $this->getResult();
}
- $this->messageManager->addSuccess($this->__('Account was saved'));
+ $this->messageManager->addSuccessMessage(__('Account was saved'));
return $this->_redirect(
- $this->helperData->getBackUrl(
+ $this->urlHelper->getBackUrl(
'list',
[],
[
@@ -88,4 +98,66 @@ public function execute()
)
);
}
+
+ private function updateSettings(\Ess\M2ePro\Model\Account $account, array $data): \Ess\M2ePro\Model\Account
+ {
+ $data['magento_orders_settings']['listing']['create_from_date'] = new \DateTime(
+ $data['magento_orders_settings']['listing']['create_from_date'],
+ \Ess\M2ePro\Block\Adminhtml\Ebay\Account\Edit\Tabs\Order::getDateTimeZone()
+ );
+
+ $data['magento_orders_settings']['listing_other']['create_from_date'] = new \DateTime(
+ $data['magento_orders_settings']['listing_other']['create_from_date'],
+ \Ess\M2ePro\Block\Adminhtml\Ebay\Account\Edit\Tabs\Order::getDateTimeZone()
+ );
+
+ return $this->accountUpdate->updateSettings($account, $data);
+ }
+
+ private function getPreviousMagentoOrdersSettings(\Ess\M2ePro\Model\Ebay\Account $ebayAccount): array
+ {
+ return [
+ 'listing' => [
+ 'is_enabled' => $ebayAccount->isMagentoOrdersListingsModeEnabled(),
+ 'create_from_date' => $ebayAccount->getMagentoOrdersListingsCreateFromDate(),
+ ],
+ 'listing_other' => [
+ 'is_enabled' => $ebayAccount->isMagentoOrdersListingsOtherModeEnabled(),
+ 'create_from_date' => $ebayAccount->getMagentoOrdersListingsOtherCreateFromDate(),
+ ],
+ ];
+ }
+
+ private function createMagentoOrders(
+ \Ess\M2ePro\Model\Ebay\Account $ebayAccount,
+ array $previousMagentoOrdersSettings
+ ): void {
+ if (
+ $ebayAccount->isMagentoOrdersListingsModeEnabled()
+ && (
+ $previousMagentoOrdersSettings['listing']['is_enabled'] === false
+ || $ebayAccount->getMagentoOrdersListingsCreateFromDate()->format('Y-m-d H:i:s')
+ !== $previousMagentoOrdersSettings['listing']['create_from_date']->format('Y-m-d H:i:s')
+ )
+ ) {
+ $this->magentoOrderCreateService->createMagentoOrdersListingsByFromDate(
+ (int)$ebayAccount->getId(),
+ $ebayAccount->getMagentoOrdersListingsCreateFromDate()
+ );
+ }
+
+ if (
+ $ebayAccount->isMagentoOrdersListingsOtherModeEnabled()
+ && (
+ $previousMagentoOrdersSettings['listing_other']['is_enabled'] === false
+ || $ebayAccount->getMagentoOrdersListingsOtherCreateFromDate()->format('Y-m-d H:i:s')
+ !== $previousMagentoOrdersSettings['listing_other']['create_from_date']->format('Y-m-d H:i:s')
+ )
+ ) {
+ $this->magentoOrderCreateService->createMagentoOrdersListingsOtherByFromDate(
+ (int)$ebayAccount->getId(),
+ $ebayAccount->getMagentoOrdersListingsOtherCreateFromDate()
+ );
+ }
+ }
}
diff --git a/Controller/Adminhtml/Ebay/Promotion/OpenGridPromotion.php b/Controller/Adminhtml/Ebay/Promotion/OpenGridPromotion.php
index 7ceb2d739..b30b52384 100644
--- a/Controller/Adminhtml/Ebay/Promotion/OpenGridPromotion.php
+++ b/Controller/Adminhtml/Ebay/Promotion/OpenGridPromotion.php
@@ -6,34 +6,24 @@
class OpenGridPromotion extends \Ess\M2ePro\Controller\Adminhtml\Listing
{
- private \Ess\M2ePro\Helper\Data\GlobalData $globalData;
-
- public function __construct(
- \Ess\M2ePro\Helper\Data\GlobalData $globalData,
- \Ess\M2ePro\Controller\Adminhtml\Context $context
- ) {
- parent::__construct($context);
-
- $this->globalData = $globalData;
- }
-
- public function execute()
+ public function execute(): \Magento\Framework\Controller\ResultInterface
{
- $this->globalData->setValue(
- 'accountId',
- $this->getRequest()->getParam('account_id')
- );
-
- $this->globalData->setValue(
- 'marketplaceId',
- $this->getRequest()->getParam('marketplace_id')
- );
-
- $block = $this->getLayout()->createBlock(
- \Ess\M2ePro\Block\Adminhtml\Ebay\Promotion\Grid::class
+ $accountId = (int)$this->getRequest()->getParam('account_id');
+ $marketplaceId = (int)$this->getRequest()->getParam('marketplace_id');
+
+ /** @var \Ess\M2ePro\Block\Adminhtml\Ebay\Promotion\Grid $grid */
+ $grid = $this->getLayout()->createBlock(
+ \Ess\M2ePro\Block\Adminhtml\Ebay\Promotion\Grid::class,
+ '',
+ [
+ 'data' => [
+ 'accountId' => $accountId,
+ 'marketplaceId' => $marketplaceId
+ ]
+ ]
);
- $this->setAjaxContent($block->toHtml());
+ $this->setAjaxContent($grid->toHtml());
return $this->getResult();
}
diff --git a/Controller/Adminhtml/Walmart/Account.php b/Controller/Adminhtml/Walmart/Account.php
index 04e5fd4f0..dd2cd7f40 100644
--- a/Controller/Adminhtml/Walmart/Account.php
+++ b/Controller/Adminhtml/Walmart/Account.php
@@ -1,11 +1,5 @@
_authorization->isAllowed('Ess_M2ePro::walmart_configuration_accounts');
}
-
- protected function addAccount($data)
- {
- $searchField = empty($data['client_id']) ? 'consumer_id' : 'client_id';
- $searchValue = empty($data['client_id']) ? $data['consumer_id'] : $data['client_id'];
-
- if ($this->isAccountExists($searchField, $searchValue)) {
- throw new \Ess\M2ePro\Model\Exception(
- 'An account with the same Walmart Client ID already exists.'
- );
- }
-
- /** @var \Ess\M2ePro\Model\Account $account */
- $account = $this->walmartFactory->getObject('Account');
-
- $this->modelFactory->getObject('Walmart_Account_Builder')->build($account, $data);
-
- try {
- $params = $this->getDataForServer($data);
-
- /** @var \Ess\M2ePro\Model\Walmart\Connector\Dispatcher $dispatcherObject */
- $dispatcherObject = $this->modelFactory->getObject('Walmart_Connector_Dispatcher');
-
- /** @var \Ess\M2ePro\Model\Walmart\Connector\Account\Add\EntityRequester $connectorObj */
- $connectorObj = $dispatcherObject->getConnector(
- 'account',
- 'add',
- 'entityRequester',
- $params,
- $account
- );
- $dispatcherObject->process($connectorObj);
- $responseData = $connectorObj->getResponseData();
-
- $account->getChildObject()->addData(
- [
- 'server_hash' => $responseData['hash'],
- 'info' => \Ess\M2ePro\Helper\Json::encode($responseData['info']),
- ]
- );
- $account->getChildObject()->save();
- } catch (\Exception $exception) {
- $account->delete();
-
- throw $exception;
- }
-
- return $account;
- }
-
- protected function updateAccount($id, $data)
- {
- /** @var \Ess\M2ePro\Model\Account $account */
- $account = $this->walmartFactory->getObjectLoaded('Account', $id);
-
- $oldData = array_merge($account->getOrigData(), $account->getChildObject()->getOrigData());
-
- $this->modelFactory->getObject('Walmart_Account_Builder')->build($account, $data);
-
- try {
- $params = $this->getDataForServer($data);
-
- if (!$this->isNeedSendDataToServer($params, $oldData)) {
- return $account;
- }
-
- /** @var \Ess\M2ePro\Model\Walmart\Connector\Dispatcher $dispatcherObject */
- $dispatcherObject = $this->modelFactory->getObject('Walmart_Connector_Dispatcher');
-
- /** @var \Ess\M2ePro\Model\Walmart\Connector\Account\Update\EntityRequester $connectorObj */
- $connectorObj = $dispatcherObject->getConnector(
- 'account',
- 'update',
- 'entityRequester',
- $params,
- $account
- );
- $dispatcherObject->process($connectorObj);
- $responseData = $connectorObj->getResponseData();
-
- $account->getChildObject()->addData(
- [
- 'info' => \Ess\M2ePro\Helper\Json::encode($responseData['info']),
- ]
- );
- $account->getChildObject()->save();
- } catch (\Exception $exception) {
- $this->modelFactory->getObject('Walmart_Account_Builder')->build($account, $oldData);
-
- throw $exception;
- }
-
- return $account;
- }
-
- protected function getDataForServer($data)
- {
- $params = [
- 'marketplace_id' => (int)$data['marketplace_id'],
- ];
-
- if ($data['marketplace_id'] == \Ess\M2ePro\Helper\Component\Walmart::MARKETPLACE_US) {
- $params['client_id'] = $data['client_id'];
- $params['client_secret'] = $data['client_secret'];
- } else {
- $params['consumer_id'] = $data['consumer_id'];
- $params['private_key'] = $data['private_key'];
- }
-
- return $params;
- }
-
- protected function isNeedSendDataToServer($newData, $oldData)
- {
- return !empty(array_diff_assoc($newData, $oldData));
- }
-
- protected function isAccountExists($search, $value)
- {
- /** @var \Ess\M2ePro\Model\ResourceModel\Account\Collection $collection */
- $collection = $this->walmartFactory->getObject('Account')->getCollection()
- ->addFieldToFilter($search, $value);
-
- return $collection->getSize();
- }
}
diff --git a/Controller/Adminhtml/Walmart/Account/Save.php b/Controller/Adminhtml/Walmart/Account/Save.php
index 48b733dce..cc2c247a0 100644
--- a/Controller/Adminhtml/Walmart/Account/Save.php
+++ b/Controller/Adminhtml/Walmart/Account/Save.php
@@ -1,28 +1,24 @@
accountBuilder = $accountBuilder;
+ $this->magentoOrderCreateService = $magentoOrderCreateService;
+ $this->connectorDispatcher = $connectorDispatcher;
$this->helperWizard = $helperWizard;
$this->helperException = $helperException;
- $this->helperData = $helperData;
+ $this->urlHelper = $urlHelper;
}
public function execute()
@@ -47,13 +46,15 @@ public function execute()
$data = $post->toArray();
try {
- $account = $id ? $this->updateAccount($id, $data) : $this->addAccount($data);
- } catch (\Exception $exception) {
+ $account = $id
+ ? $this->updateAccount((int)$id, $data)
+ : $this->addAccount($data);
+ } catch (\Throwable $exception) {
$this->helperException->process($exception);
- $message = $this->__(
- 'The Walmart access obtaining is currently unavailable.
Reason: %error_message%',
- $exception->getMessage()
+ $message = __(
+ 'The Walmart access obtaining is currently unavailable.
Reason: %error_message',
+ ['error_message' => $exception->getMessage()]
);
if ($this->isAjax()) {
@@ -65,7 +66,7 @@ public function execute()
return $this->getResult();
}
- $this->messageManager->addError($message);
+ $this->messageManager->addErrorMessage($message);
return $this->_redirect('*/walmart_account');
}
@@ -78,7 +79,7 @@ public function execute()
return $this->getResult();
}
- $this->messageManager->addSuccess($this->__('Account was saved'));
+ $this->messageManager->addSuccessMessage(__('Account was saved'));
$routerParams = [
'id' => $account->getId(),
@@ -86,12 +87,208 @@ public function execute()
];
if (
- $this->helperWizard->isActive(\Ess\M2ePro\Helper\View\Walmart::WIZARD_INSTALLATION_NICK) &&
- $this->helperWizard->getStep(\Ess\M2ePro\Helper\View\Walmart::WIZARD_INSTALLATION_NICK) == 'account'
+ $this->helperWizard->isActive(\Ess\M2ePro\Helper\View\Walmart::WIZARD_INSTALLATION_NICK)
+ && $this->helperWizard->getStep(\Ess\M2ePro\Helper\View\Walmart::WIZARD_INSTALLATION_NICK) == 'account'
) {
$routerParams['wizard'] = true;
}
- return $this->_redirect($this->helperData->getBackUrl('list', [], ['edit' => $routerParams]));
+ return $this->_redirect($this->urlHelper->getBackUrl('list', [], ['edit' => $routerParams]));
+ }
+
+ private function updateAccount(int $id, array $data): \Ess\M2ePro\Model\Account
+ {
+ /** @var \Ess\M2ePro\Model\Account $account */
+ $account = $this->walmartFactory->getObjectLoaded('Account', $id);
+ /** @var \Ess\M2ePro\Model\Walmart\Account $account */
+ $walmartAccount = $account->getChildObject();
+
+ $oldData = array_merge($account->getOrigData(), $walmartAccount->getOrigData());
+
+ $previousMagentoOrdersSettings = $this->getPreviousMagentoOrdersSettings($walmartAccount);
+
+ $this->saveAccount($account, $data);
+
+ try {
+ $this->updateAccountOnServer($account, $data, $oldData);
+ } catch (\Throwable $exception) {
+ $this->accountBuilder->build($account, $oldData);
+
+ throw $exception;
+ }
+
+ try {
+ $this->createMagentoOrders($walmartAccount, $previousMagentoOrdersSettings);
+ } catch (\Throwable $exception) {
+ $this->helperException->process($exception);
+ }
+
+ return $account;
+ }
+
+ private function saveAccount(\Ess\M2ePro\Model\Account $account, array $data): void
+ {
+ $data['magento_orders_settings']['listing']['create_from_date'] = new \DateTime(
+ $data['magento_orders_settings']['listing']['create_from_date'],
+ \Ess\M2ePro\Block\Adminhtml\Walmart\Account\Edit\Tabs\Order::getDateTimeZone()
+ );
+
+ $data['magento_orders_settings']['listing_other']['create_from_date'] = new \DateTime(
+ $data['magento_orders_settings']['listing_other']['create_from_date'],
+ \Ess\M2ePro\Block\Adminhtml\Walmart\Account\Edit\Tabs\Order::getDateTimeZone()
+ );
+
+ $this->accountBuilder->build($account, $data);
+ }
+
+ private function updateAccountOnServer(\Ess\M2ePro\Model\Account $account, array $data, array $oldData): void
+ {
+ $params = $this->getDataForServer($data);
+
+ if (!$this->isNeedSendDataToServer($params, $oldData)) {
+ return;
+ }
+
+ /** @var \Ess\M2ePro\Model\Walmart\Connector\Account\Update\EntityRequester $connectorObj */
+ $connectorObj = $this->connectorDispatcher->getConnector(
+ 'account',
+ 'update',
+ 'entityRequester',
+ $params,
+ $account
+ );
+ $this->connectorDispatcher->process($connectorObj);
+ $responseData = $connectorObj->getResponseData();
+
+ $account->getChildObject()->addData(
+ [
+ 'info' => \Ess\M2ePro\Helper\Json::encode($responseData['info']),
+ ]
+ );
+ $account->getChildObject()->save();
+ }
+
+ private function isNeedSendDataToServer($newData, $oldData): bool
+ {
+ return !empty(array_diff_assoc($newData, $oldData));
+ }
+
+ private function getDataForServer(array $data): array
+ {
+ $params = [
+ 'marketplace_id' => (int)$data['marketplace_id'],
+ ];
+
+ if ($data['marketplace_id'] == \Ess\M2ePro\Helper\Component\Walmart::MARKETPLACE_US) {
+ $params['client_id'] = $data['client_id'];
+ $params['client_secret'] = $data['client_secret'];
+ } else {
+ $params['consumer_id'] = $data['consumer_id'];
+ $params['private_key'] = $data['private_key'];
+ }
+
+ return $params;
+ }
+
+ private function getPreviousMagentoOrdersSettings(\Ess\M2ePro\Model\Walmart\Account $walmartAccount): array
+ {
+ return [
+ 'listing' => [
+ 'is_enabled' => $walmartAccount->isMagentoOrdersListingsModeEnabled(),
+ 'create_from_date' => $walmartAccount->getMagentoOrdersListingsCreateFromDate(),
+ ],
+ 'listing_other' => [
+ 'is_enabled' => $walmartAccount->isMagentoOrdersListingsOtherModeEnabled(),
+ 'create_from_date' => $walmartAccount->getMagentoOrdersListingsOtherCreateFromDate(),
+ ],
+ ];
+ }
+
+ private function createMagentoOrders(
+ \Ess\M2ePro\Model\Walmart\Account $walmartAccount,
+ array $previousMagentoOrdersSettings
+ ): void {
+ if (
+ $walmartAccount->isMagentoOrdersListingsModeEnabled()
+ && (
+ $previousMagentoOrdersSettings['listing']['is_enabled'] === false
+ || $walmartAccount->getMagentoOrdersListingsCreateFromDate()->format('Y-m-d H:i:s')
+ !== $previousMagentoOrdersSettings['listing']['create_from_date']->format('Y-m-d H:i:s')
+ )
+ ) {
+ $this->magentoOrderCreateService->createMagentoOrdersListingsByFromDate(
+ (int)$walmartAccount->getId(),
+ $walmartAccount->getMagentoOrdersListingsCreateFromDate()
+ );
+ }
+
+ if (
+ $walmartAccount->isMagentoOrdersListingsOtherModeEnabled()
+ && (
+ $previousMagentoOrdersSettings['listing_other']['is_enabled'] === false
+ || $walmartAccount->getMagentoOrdersListingsOtherCreateFromDate()->format('Y-m-d H:i:s')
+ !== $previousMagentoOrdersSettings['listing_other']['create_from_date']->format('Y-m-d H:i:s')
+ )
+ ) {
+ $this->magentoOrderCreateService->createMagentoOrdersListingsOtherByFromDate(
+ (int)$walmartAccount->getId(),
+ $walmartAccount->getMagentoOrdersListingsOtherCreateFromDate()
+ );
+ }
+ }
+
+ private function addAccount(array $data): \Ess\M2ePro\Model\Account
+ {
+ $searchField = empty($data['client_id']) ? 'consumer_id' : 'client_id';
+ $searchValue = empty($data['client_id']) ? $data['consumer_id'] : $data['client_id'];
+
+ if ($this->isAccountExists($searchField, $searchValue)) {
+ throw new \Ess\M2ePro\Model\Exception(
+ 'An account with the same Walmart Client ID already exists.'
+ );
+ }
+
+ /** @var \Ess\M2ePro\Model\Account $account */
+ $account = $this->walmartFactory->getObject('Account');
+
+ $this->accountBuilder->build($account, $data);
+
+ try {
+ $params = $this->getDataForServer($data);
+
+ /** @var \Ess\M2ePro\Model\Walmart\Connector\Account\Add\EntityRequester $connectorObj */
+ $connectorObj = $this->connectorDispatcher->getConnector(
+ 'account',
+ 'add',
+ 'entityRequester',
+ $params,
+ $account
+ );
+ $this->connectorDispatcher->process($connectorObj);
+ $responseData = $connectorObj->getResponseData();
+
+ $account->getChildObject()->addData(
+ [
+ 'server_hash' => $responseData['hash'],
+ 'info' => \Ess\M2ePro\Helper\Json::encode($responseData['info']),
+ ]
+ );
+ $account->getChildObject()->save();
+ } catch (\Throwable $exception) {
+ $account->delete();
+
+ throw $exception;
+ }
+
+ return $account;
+ }
+
+ private function isAccountExists($search, $value): bool
+ {
+ /** @var \Ess\M2ePro\Model\ResourceModel\Account\Collection $collection */
+ $collection = $this->walmartFactory->getObject('Account')->getCollection()
+ ->addFieldToFilter($search, $value);
+
+ return (bool)$collection->getSize();
}
}
diff --git a/Helper/Module/Database/Tables.php b/Helper/Module/Database/Tables.php
index c91aa5202..e531b848d 100644
--- a/Helper/Module/Database/Tables.php
+++ b/Helper/Module/Database/Tables.php
@@ -8,6 +8,8 @@ class Tables
{
public const PREFIX = 'm2epro_';
+ public const TABLE_ACCOUNT = self::PREFIX . 'account';
+
public const TABLE_MARKETPLACE = self::PREFIX . 'marketplace';
public const TABLE_LISTING = self::PREFIX . 'listing';
@@ -15,6 +17,9 @@ class Tables
public const TABLE_LISTING_PRODUCT_INSTRUCTION = self::PREFIX . 'listing_product_instruction';
public const TABLE_LISTING_AUTO_CATEGORY = self::PREFIX . 'listing_auto_category';
+ public const TABLE_ORDER = self::PREFIX . 'order';
+
+ public const TABLE_EBAY_ITEM = self::PREFIX . 'ebay_item';
public const TABLE_EBAY_LISTING = self::PREFIX . 'ebay_listing';
public const TABLE_EBAY_LISTING_PRODUCT = self::PREFIX . 'ebay_listing_product';
public const TABLE_EBAY_LISTING_PRODUCT_PROMOTION = self::PREFIX . 'ebay_listing_product_promotion';
@@ -26,6 +31,7 @@ class Tables
public const TABLE_EBAY_MARKETPLACE = self::PREFIX . 'ebay_marketplace';
public const TABLE_EBAY_DICTIONARY_MARKETPLACE = self::PREFIX . 'ebay_dictionary_marketplace';
public const TABLE_EBAY_VIDEO = self::PREFIX . 'ebay_video';
+ public const TABLE_EBAY_ORDER = self::PREFIX . 'ebay_order';
public const TABLE_EBAY_BUNDLE_OPTIONS_MAPPING = self::PREFIX . 'ebay_bundle_options_mapping';
@@ -34,8 +40,11 @@ class Tables
public const TABLE_AMAZON_ACCOUNT_MERCHANT_SETTING = self::PREFIX . 'amazon_account_merchant_setting';
public const TABLE_AMAZON_MARKETPLACE = self::PREFIX . 'amazon_marketplace';
public const TABLE_AMAZON_LISTING_PRODUCT = self::PREFIX . 'amazon_listing_product';
+ public const TABLE_AMAZON_ORDER = self::PREFIX . 'amazon_order';
public const TABLE_AMAZON_ORDER_ITEM = self::PREFIX . 'amazon_order_item';
+ public const TABLE_WALMART_ORDER = self::PREFIX . 'walmart_order';
+
/** @var \Magento\Framework\App\ResourceConnection */
private $resourceConnection;
/** @var \Ess\M2ePro\Helper\Module\Database\Structure */
diff --git a/Model/Account.php b/Model/Account.php
index 1084e4978..d4e400030 100644
--- a/Model/Account.php
+++ b/Model/Account.php
@@ -1,32 +1,23 @@
_init(\Ess\M2ePro\Model\ResourceModel\Account::class);
}
- //########################################
-
/**
* @param bool $onlyMainConditions
*
@@ -49,8 +40,6 @@ public function isLocked($onlyMainConditions = false)
->getSize();
}
- //########################################
-
public function save($reloadOnCreate = false)
{
$this->getHelper('Data_Cache_Permanent')->removeTagValues('account');
@@ -58,15 +47,11 @@ public function save($reloadOnCreate = false)
return parent::save($reloadOnCreate);
}
- //########################################
-
public function getListings()
{
return $this->getRelatedComponentItems('Listing', 'account_id', true);
}
- //########################################
-
/**
* @param bool $asObjects
* @param array $filters
@@ -109,8 +94,6 @@ public function getOrders($asObjects = false, array $filters = [])
return $orders;
}
- //########################################
-
public function getTitle()
{
return $this->getData('title');
@@ -136,5 +119,14 @@ public function isCacheEnabled()
return true;
}
- //########################################
+ public function getCreateDate(): \DateTime
+ {
+ if ($this->getDataByKey(ResourceAccount::COLUMN_CREATE_DATE) === null) {
+ throw new \LogicException('Create Date must be set');
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt(
+ $this->getDataByKey(ResourceAccount::COLUMN_CREATE_DATE)
+ );
+ }
}
diff --git a/Model/Amazon/Account.php b/Model/Amazon/Account.php
index 40e9af7ae..77fd8df8a 100644
--- a/Model/Amazon/Account.php
+++ b/Model/Amazon/Account.php
@@ -576,6 +576,19 @@ public function isMagentoOrdersListingsModeEnabled(): bool
return $this->getSetting('magento_orders_settings', ['listing', 'mode'], 1) == 1;
}
+ public function getMagentoOrdersListingsCreateFromDate(): \DateTime
+ {
+ $date = $this->getSetting('magento_orders_settings', ['listing', 'create_from_date']);
+ if ($date === null) {
+ /** @var \Ess\M2ePro\Model\Account $parentObject */
+ $parentObject = $this->getParentObject();
+
+ return $parentObject->getCreateDate();
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt($date);
+ }
+
/**
* @return bool
*/
@@ -608,6 +621,19 @@ public function isMagentoOrdersListingsOtherModeEnabled(): bool
return $this->getSetting('magento_orders_settings', ['listing_other', 'mode'], 1) == 1;
}
+ public function getMagentoOrdersListingsOtherCreateFromDate(): \DateTime
+ {
+ $date = $this->getSetting('magento_orders_settings', ['listing_other', 'create_from_date']);
+ if ($date === null) {
+ /** @var \Ess\M2ePro\Model\Account $parentObject */
+ $parentObject = $this->getParentObject();
+
+ return $parentObject->getCreateDate();
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt($date);
+ }
+
/**
* @return int
*/
diff --git a/Model/Amazon/Account/Builder.php b/Model/Amazon/Account/Builder.php
index 4e96f28a8..336bd51f3 100644
--- a/Model/Amazon/Account/Builder.php
+++ b/Model/Amazon/Account/Builder.php
@@ -1,26 +1,13 @@
magentoStoreHelper = $magentoStoreHelper;
}
- /**
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
protected function prepareData(): array
{
$data = [];
@@ -157,13 +140,20 @@ protected function prepareData(): array
$keys = [
'mode',
+ 'create_from_date',
'store_mode',
'store_id',
];
foreach ($keys as $key) {
- if (isset($tempSettings[$key])) {
- $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
+ if (!isset($tempSettings[$key])) {
+ continue;
+ }
+
+ if ($key === 'create_from_date') {
+ $tempSettings[$key] = $this->convertDate($tempSettings[$key]);
}
+
+ $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
}
// Unmanaged orders settings
@@ -174,14 +164,21 @@ protected function prepareData(): array
$keys = [
'mode',
+ 'create_from_date',
'product_mode',
'product_tax_class_id',
'store_id',
];
foreach ($keys as $key) {
- if (isset($tempSettings[$key])) {
- $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
+ if (!isset($tempSettings[$key])) {
+ continue;
}
+
+ if ($key === 'create_from_date') {
+ $tempSettings[$key] = $this->convertDate($tempSettings[$key]);
+ }
+
+ $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
}
// order number settings
@@ -194,7 +191,7 @@ protected function prepareData(): array
$data['magento_orders_settings'][$tempKey]['source'] = $tempSettings['source'];
}
- if (!empty($tempSettings['apply_to_amazon'])) {
+ if (isset($tempSettings['apply_to_amazon'])) {
$data['magento_orders_settings'][$tempKey]['apply_to_amazon'] = $tempSettings['apply_to_amazon'];
}
@@ -401,10 +398,24 @@ protected function prepareData(): array
}
/**
- * @return array
+ * @param \DateTime|string $date
*/
+ private function convertDate($date): string
+ {
+ if (is_string($date)) {
+ return $date;
+ }
+
+ $date = clone $date;
+
+ return $date->setTimezone(new \DateTimeZone(\Ess\M2ePro\Helper\Date::getTimezone()->getDefaultTimezone()))
+ ->format('Y-m-d H:i:s');
+ }
+
public function getDefaultData(): array
{
+ $currentGmtDate = \Ess\M2ePro\Helper\Date::createCurrentGmt()->format('Y-m-d H:i:s');
+
return [
// general
'title' => '',
@@ -424,11 +435,13 @@ public function getDefaultData(): array
'magento_orders_settings' => [
'listing' => [
'mode' => 1,
+ 'create_from_date' => $currentGmtDate,
'store_mode' => Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT,
'store_id' => null,
],
'listing_other' => [
'mode' => 1,
+ 'create_from_date' => $currentGmtDate,
'product_mode' => Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE,
'product_tax_class_id' => \Ess\M2ePro\Model\Magento\Product::TAX_CLASS_ID_NONE,
'store_id' => $this->magentoStoreHelper->getDefaultStoreId(),
@@ -502,9 +515,6 @@ public function getDefaultData(): array
];
}
- /**
- * @return bool
- */
private function isNeedExcludeStates(): bool
{
if ($this->rawData['marketplace_id'] != \Ess\M2ePro\Helper\Component\Amazon::MARKETPLACE_US) {
diff --git a/Model/Amazon/Account/MagentoOrderCreateService.php b/Model/Amazon/Account/MagentoOrderCreateService.php
new file mode 100644
index 000000000..ea0f2ff7c
--- /dev/null
+++ b/Model/Amazon/Account/MagentoOrderCreateService.php
@@ -0,0 +1,53 @@
+amazonOrderRepository = $amazonOrderRepository;
+ $this->orderCreator = $orderCreator;
+ $this->exceptionHelper = $exceptionHelper;
+ }
+
+ public function createMagentoOrdersListingsByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $this->createByFromDate($accountId, $fromDate);
+ }
+
+ public function createMagentoOrdersListingsOtherByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $this->createByFromDate($accountId, $fromDate);
+ }
+
+ private function createByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $fromDate->setTimezone(
+ new \DateTimeZone(\Ess\M2ePro\Helper\Date::getTimezone()->getDefaultTimezone())
+ );
+ $toDate = \Ess\M2ePro\Helper\Date::createCurrentGmt();
+
+ $orders = $this->amazonOrderRepository->retrieveWithoutMagentoOrders(
+ $accountId,
+ $fromDate,
+ $toDate
+ );
+ foreach ($orders as $order) {
+ try {
+ $this->orderCreator->createMagentoOrder($order);
+ } catch (\Throwable $e) {
+ $this->exceptionHelper->process($e);
+ }
+ }
+ }
+}
diff --git a/Model/Amazon/AdvancedFilter/AllItemsOptions.php b/Model/Amazon/AdvancedFilter/AllItemsOptions.php
index d90adc9c6..624de6a20 100644
--- a/Model/Amazon/AdvancedFilter/AllItemsOptions.php
+++ b/Model/Amazon/AdvancedFilter/AllItemsOptions.php
@@ -36,6 +36,8 @@ class AllItemsOptions
private $optionFactory;
/** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductTaxCode */
private $taxCodeResource;
+ private \Magento\Catalog\Model\ResourceModel\Product $magentoProductResource;
+ private \Magento\Catalog\Model\Product\Type $magentoProductType;
public function __construct(
DropDownFilter\OptionCollectionFactory $optionCollectionFactory,
@@ -52,7 +54,9 @@ public function __construct(
\Ess\M2ePro\Model\Tag\ListingProduct\Repository $tagRelationRepository,
\Ess\M2ePro\Model\ResourceModel\Marketplace $marketplaceResource,
\Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductTaxCode $taxCodeResource,
- \Ess\M2ePro\Model\ResourceModel\Account $accountResource
+ \Ess\M2ePro\Model\ResourceModel\Account $accountResource,
+ \Magento\Catalog\Model\ResourceModel\Product $magentoProductResource,
+ \Magento\Catalog\Model\Product\Type $magentoProductType
) {
$this->amazonListingResource = $amazonListingResource;
$this->amazonListingProductResource = $amazonListingProductResource;
@@ -69,6 +73,8 @@ public function __construct(
$this->optionCollectionFactory = $optionCollectionFactory;
$this->optionFactory = $optionFactory;
$this->taxCodeResource = $taxCodeResource;
+ $this->magentoProductResource = $magentoProductResource;
+ $this->magentoProductType = $magentoProductType;
}
public function getAccountOptions(): DropDownFilter\OptionCollection
@@ -311,6 +317,36 @@ public function getTaxCodeOptions(): DropDownFilter\OptionCollection
return $optionCollection;
}
+ public function getMagentoProductTypeOptions(): DropDownFilter\OptionCollection
+ {
+ $select = $this->getBaseSelect();
+ $select->joinInner(
+ ['mp' => $this->magentoProductResource->getEntityTable()],
+ sprintf(
+ 'mp.entity_id = listing_product.%s',
+ \Ess\M2ePro\Model\ResourceModel\Listing\Product::PRODUCT_ID_FIELD
+ ),
+ ['type_id']
+ );
+
+ $select->group('mp.type_id');
+ $select->order('mp.type_id');
+
+ $optionsData = $select->query()->fetchAll();
+ $magentoProductTypes = $this->magentoProductType->getOptionArray();
+
+ $optionCollection = $this->optionCollectionFactory->create();
+ foreach ($optionsData as $optionData) {
+ $optionLabel = $magentoProductTypes[($optionData['type_id'])];
+ $optionValue = $optionData['type_id'];
+
+ $option = $this->optionFactory->create($optionLabel, $optionValue);
+ $optionCollection->addOption($option);
+ }
+
+ return $optionCollection;
+ }
+
private function getBaseSelect(): \Magento\Framework\DB\Select
{
$select = $this->listingResource->getConnection()->select();
diff --git a/Model/Amazon/Order.php b/Model/Amazon/Order.php
index f4975980b..a4c642b6c 100644
--- a/Model/Amazon/Order.php
+++ b/Model/Amazon/Order.php
@@ -2,8 +2,8 @@
namespace Ess\M2ePro\Model\Amazon;
-use Ess\M2ePro\Model\Amazon\Order\Tax\ProductPriceTaxFactory;
use Magento\Sales\Model\Order\Creditmemo;
+use Ess\M2ePro\Model\ResourceModel\Amazon\Order as ResourceAmazonOrder;
/**
* @method \Ess\M2ePro\Model\Order getParentObject()
@@ -24,6 +24,8 @@ class Order extends \Ess\M2ePro\Model\ActiveRecord\Component\Child\Amazon\Abstra
public const INVOICE_SOURCE_MAGENTO = 'magento';
public const INVOICE_SOURCE_EXTENSION = 'extension';
+ private const DATE_INTERVAL_IN_HOURS_FOR_INVOICE_SENDING_FROM_REPORT = 24;
+
/** @var \Ess\M2ePro\Model\Magento\Order\ShipmentFactory */
private $shipmentFactory;
/** @var \Ess\M2ePro\Model\Amazon\Order\ShippingAddressFactory */
@@ -45,8 +47,7 @@ class Order extends \Ess\M2ePro\Model\ActiveRecord\Component\Child\Amazon\Abstra
private $subTotalPrice = null;
/** @var null|float */
private $grandTotalPrice = null;
- /** @var mixed */
- private $creditmemoFactor;
+ private \Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory;
/** @var \Magento\Sales\Model\Service\CreditmemoService */
private $creditmemoService;
@@ -180,6 +181,13 @@ public function getShippingAddress()
])->setData($address);
}
+ public function getPurchaseCreateDate(): \DateTime
+ {
+ return \Ess\M2ePro\Helper\Date::createDateInCurrentZone(
+ $this->getDataByKey(ResourceAmazonOrder::COLUMN_PURCHASE_CREATE_DATE)
+ );
+ }
+
/**
* @return array
*/
@@ -429,6 +437,42 @@ public function isInvoiceUnconfirmed()
return $this->getStatus() == self::STATUS_INVOICE_UNCONFIRMED;
}
+ //----------------------------------
+
+ public function isInvoiceSent(): bool
+ {
+ return (bool)$this->getDataByKey(ResourceAmazonOrder::COLUMN_IS_INVOICE_SENT);
+ }
+
+ public function isExistsDateOfInvoiceSent(): bool
+ {
+ return $this->getDataByKey(ResourceAmazonOrder::COLUMN_DATE_OF_INVOICE_SENDING) !== null;
+ }
+
+ public function getDateOfInvoiceSent(): \DateTime
+ {
+ if (!$this->isExistsDateOfInvoiceSent()) {
+ throw new \LogicException('Date Of Invoice Sent is not set');
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt(
+ $this->getDataByKey(ResourceAmazonOrder::COLUMN_DATE_OF_INVOICE_SENDING)
+ );
+ }
+
+ public function markThatInvoiceSentToChannel(): self
+ {
+ $this->setData(ResourceAmazonOrder::COLUMN_IS_INVOICE_SENT, 1);
+ $this->setData(
+ ResourceAmazonOrder::COLUMN_DATE_OF_INVOICE_SENDING,
+ \Ess\M2ePro\Helper\Date::createCurrentGmt()->format('Y-m-d H:i:s')
+ );
+
+ return $this;
+ }
+
+ //----------------------------------
+
/**
* @return bool
*/
@@ -1028,7 +1072,7 @@ public function sendInvoice()
return true;
}
- public function canSendInvoiceFromReport()
+ public function canSendInvoiceFromReport(): bool
{
if (!$this->getAmazonAccount()->getMarketplace()->getChildObject()->isVatCalculationServiceAvailable()) {
return false;
@@ -1047,6 +1091,29 @@ public function canSendInvoiceFromReport()
return false;
}
+ if (!$this->canSendInvoiceFromReportAgain()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private function canSendInvoiceFromReportAgain(): bool
+ {
+ if (!$this->isInvoiceSent()) {
+ return true;
+ }
+
+ $limitDateOfInvoiceSent = \M2E\AmazonMcf\Helper\Date::createCurrentGmt()->modify(
+ sprintf('-%d hours', self::DATE_INTERVAL_IN_HOURS_FOR_INVOICE_SENDING_FROM_REPORT)
+ );
+ if (
+ $this->isExistsDateOfInvoiceSent()
+ && $this->getDateOfInvoiceSent() > $limitDateOfInvoiceSent
+ ) {
+ return false;
+ }
+
return true;
}
diff --git a/Model/Amazon/Order/Item.php b/Model/Amazon/Order/Item.php
index 2ee52392d..a312d9e03 100644
--- a/Model/Amazon/Order/Item.php
+++ b/Model/Amazon/Order/Item.php
@@ -334,17 +334,15 @@ public function isReservable(): bool
return $this->isOrdersCreationEnabled();
}
- /**
- * @return bool
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
private function isOrdersCreationEnabled(): bool
{
$channelItem = $this->getChannelItem();
- $isOtherListingsEnabled = $this->getAmazonAccount()->isMagentoOrdersListingsOtherModeEnabled();
if ($channelItem === null) {
- return $isOtherListingsEnabled;
+ return $this->isOrdersCreationEnabledForListingsOther(
+ $this->getAmazonAccount(),
+ $this->getAmazonOrder()
+ );
}
if (
@@ -354,10 +352,38 @@ private function isOrdersCreationEnabled(): bool
$channelItem->getMarketplaceId()
)
) {
- return $isOtherListingsEnabled;
+ return $this->isOrdersCreationEnabledForListingsOther(
+ $this->getAmazonAccount(),
+ $this->getAmazonOrder()
+ );
+ }
+
+ return $this->isOrdersCreationEnabledForListings(
+ $this->getAmazonAccount(),
+ $this->getAmazonOrder()
+ );
+ }
+
+ private function isOrdersCreationEnabledForListingsOther(
+ \Ess\M2ePro\Model\Amazon\Account $amazonAccount,
+ \Ess\M2ePro\Model\Amazon\Order $amazonOrder
+ ): bool {
+ if (!$amazonAccount->isMagentoOrdersListingsOtherModeEnabled()) {
+ return false;
+ }
+
+ return $amazonOrder->getPurchaseCreateDate() >= $amazonAccount->getMagentoOrdersListingsOtherCreateFromDate();
+ }
+
+ private function isOrdersCreationEnabledForListings(
+ \Ess\M2ePro\Model\Amazon\Account $amazonAccount,
+ \Ess\M2ePro\Model\Amazon\Order $amazonOrder
+ ): bool {
+ if (!$amazonAccount->isMagentoOrdersListingsModeEnabled()) {
+ return false;
}
- return $this->getAmazonAccount()->isMagentoOrdersListingsModeEnabled();
+ return $amazonOrder->getPurchaseCreateDate() >= $amazonAccount->getMagentoOrdersListingsCreateFromDate();
}
/**
diff --git a/Model/Amazon/Order/Repository.php b/Model/Amazon/Order/Repository.php
new file mode 100644
index 000000000..e46102788
--- /dev/null
+++ b/Model/Amazon/Order/Repository.php
@@ -0,0 +1,49 @@
+orderCollectionFactory = $orderCollectionFactory;
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Order[]
+ */
+ public function retrieveWithoutMagentoOrders(
+ int $accountId,
+ \DateTime $fromPurchaseDate,
+ \DateTime $toPurchaseDate
+ ): array {
+ $collection = $this->orderCollectionFactory
+ ->createWithAmazonChildMode()
+ ->addFieldToFilter(
+ AmazonOrderResource::COLUMN_PURCHASE_CREATE_DATE,
+ ['gteq' => $fromPurchaseDate->format('Y-m-d H:i:s')]
+ )
+ ->addFieldToFilter(
+ AmazonOrderResource::COLUMN_PURCHASE_CREATE_DATE,
+ ['lteq' => $toPurchaseDate->format('Y-m-d H:i:s')]
+ )
+ ->addFieldToFilter(
+ OrderResource::COLUMN_MAGENTO_ORDER_ID,
+ ['null' => true]
+ )
+ ->addFieldToFilter(
+ OrderResource::COLUMN_ACCOUNT_ID,
+ ['eq' => $accountId]
+ );
+
+ return array_values($collection->getItems());
+ }
+}
diff --git a/Model/Cron/Task/Amazon/Order/SendInvoice/Responser.php b/Model/Cron/Task/Amazon/Order/SendInvoice/Responser.php
index 4f6bd803f..787885f52 100644
--- a/Model/Cron/Task/Amazon/Order/SendInvoice/Responser.php
+++ b/Model/Cron/Task/Amazon/Order/SendInvoice/Responser.php
@@ -1,18 +1,9 @@
orderChange = $this->activeRecordFactory->getObject('Order\Change')->load($params['order']['change_id']);
}
- //########################################
-
public function failDetected($messageText)
{
parent::failDetected($messageText);
@@ -95,8 +82,6 @@ protected function processResponseMessages(array $messages = [])
}
}
- //########################################
-
protected function processResponseData()
{
$this->order->getLog()->setInitiator($this->orderChange->getCreatorType());
@@ -121,7 +106,10 @@ protected function processResponseData()
$this->orderChange->delete();
if ($this->params['order']['document_type'] == AmazonOrderInvoice::DOCUMENT_TYPE_INVOICE) {
- $this->order->getChildObject()->setData('is_invoice_sent', 1)->save();
+ /** @var \Ess\M2ePro\Model\Amazon\Order $amazonOrder */
+ $amazonOrder = $this->order->getChildObject();
+ $amazonOrder->markThatInvoiceSentToChannel()
+ ->save();
$this->order->addSuccessLog(
'Invoice #%document_number% was sent.',
[
@@ -162,6 +150,4 @@ protected function logErrorMessage(\Ess\M2ePro\Model\Response\Message $message)
);
}
}
-
- //########################################
}
diff --git a/Model/Cron/Task/Amazon/Order/Update/SellerOrderId.php b/Model/Cron/Task/Amazon/Order/Update/SellerOrderId.php
index ad8dab520..67fddfadc 100644
--- a/Model/Cron/Task/Amazon/Order/Update/SellerOrderId.php
+++ b/Model/Cron/Task/Amazon/Order/Update/SellerOrderId.php
@@ -103,13 +103,9 @@ protected function performActions()
return;
}
- // Processing orders from last day
- $backToDate = new \DateTime('now', new \DateTimeZone('UTC'));
- $backToDate->modify('-1 day');
-
- // Processing orders from last 7 days for orders of replacement
- $backToReplacementDate = new \DateTime('now', new \DateTimeZone('UTC'));
- $backToReplacementDate->modify('-7 day');
+ // Processing orders from last 30 day
+ $backToDate = \Ess\M2ePro\Helper\Date::createCurrentGmt();
+ $backToDate->modify('-30 day');
$connection = $this->resource->getConnection();
@@ -123,8 +119,7 @@ protected function performActions()
$collection = $this->getOrderCollection(
$enabledAccountIds,
$enabledMerchantId,
- $backToDate->format('Y-m-d H:i:s'),
- $backToReplacementDate->format('Y-m-d H:i:s')
+ $backToDate->format('Y-m-d H:i:s')
);
foreach ($collection->getItems() as $orderData) {
@@ -195,7 +190,7 @@ protected function performActions()
* @return \Ess\M2ePro\Model\ResourceModel\Order\Collection
* @throws \Magento\Framework\Exception\LocalizedException
*/
- private function getOrderCollection($enabledAccountIds, $enabledMerchantId, $date, $replacementDate)
+ private function getOrderCollection($enabledAccountIds, $enabledMerchantId, $date)
{
/** @var \Ess\M2ePro\Model\ResourceModel\Order\Collection $collection */
$collection = $this->orderCollectionFactory->create();
@@ -227,8 +222,7 @@ private function getOrderCollection($enabledAccountIds, $enabledMerchantId, $dat
$collection->addFieldToFilter('second_table.status', ['neq' => Order::STATUS_CANCELED]);
$collection->addFieldToFilter('second_table.seller_order_id', ['null' => true]);
$collection->addFieldToFilter('maa.merchant_id', ['eq' => $enabledMerchantId]);
- $where = "(`main_table`.`create_date` > '{$date}' AND `second_table`.`is_replacement` = 0)";
- $where .= " OR (`main_table`.`create_date` > '{$replacementDate}' AND `second_table`.`is_replacement` = 1)";
+ $where = "`main_table`.`create_date` > '{$date}'";
$collection->getSelect()->where($where);
$collection->getSelect()->limit(self::ORDERS_PER_MERCHANT);
diff --git a/Model/Cron/Task/Ebay/SynchronizePromotions.php b/Model/Cron/Task/Ebay/SynchronizePromotions.php
new file mode 100644
index 000000000..830e8be12
--- /dev/null
+++ b/Model/Cron/Task/Ebay/SynchronizePromotions.php
@@ -0,0 +1,117 @@
+serverMaintenanceHelper = $serverMaintenanceHelper;
+ $this->promotionsSynchronization = $promotionsSynchronization;
+ $this->timingManager = $timingManager;
+ $this->marketplaceRepository = $marketplaceRepository;
+ $this->accountRepository = $accountRepository;
+ }
+
+ public function isPossibleToRun(): bool
+ {
+ if ($this->serverMaintenanceHelper->isNow()) {
+ return false;
+ }
+
+ return parent::isPossibleToRun();
+ }
+
+ protected function performActions(): void
+ {
+ $accounts = $this->accountRepository->getAll();
+
+ if (empty($accounts)) {
+ return;
+ }
+
+ foreach ($accounts as $account) {
+ $marketplaces = $this->marketplaceRepository->findMarketplacesWithExistListing($account);
+
+ if (empty($marketplaces)) {
+ continue;
+ }
+
+ foreach ($marketplaces as $marketplace) {
+ $this->getOperationHistory()->addText(
+ 'Starting account "' . $account->getTitle() . '" and marketplace "' . $marketplace->getTitle()
+ );
+
+ if (!$this->timingManager->isAttemptIntervalExceeded($account->getId(), $marketplace->getId())) {
+ continue;
+ }
+
+ $this->getOperationHistory()->addTimePoint(
+ __METHOD__ . 'process' . $account->getId() . $marketplace->getId(),
+ 'Process account ' . $account->getTitle() . ' and marketplace ' . $marketplace->getTitle()
+ );
+
+ try {
+ $this->promotionsSynchronization->process($account->getChildObject(), $marketplace);
+
+ $this->timingManager->setLastProcessed($account->getId(), $marketplace->getId());
+ } catch (\Throwable $exception) {
+ $message = (string)__(
+ 'The "SynchronizePromotion" Action for eBay Account "%account" and Marketplace "%marketplace"'
+ . ' was completed with error.',
+ [
+ 'account' => $account->getTitle(),
+ 'marketplace' => $marketplace->getTitle(),
+ ]
+ );
+
+ $this->processTaskAccountException($message, __FILE__, __LINE__);
+ $this->processTaskException($exception);
+ }
+
+ $this->getOperationHistory()->saveTimePoint(
+ __METHOD__ . 'process' . $account->getId() . $marketplace->getId()
+ );
+ }
+ }
+ }
+}
diff --git a/Model/Cron/Task/Repository.php b/Model/Cron/Task/Repository.php
index 99c6ef7bd..af3f11fb5 100644
--- a/Model/Cron/Task/Repository.php
+++ b/Model/Cron/Task/Repository.php
@@ -182,6 +182,10 @@ class Repository extends \Ess\M2ePro\Model\AbstractModel
'component' => \Ess\M2ePro\Helper\Component\Ebay::NICK,
'group' => self::GROUP_EBAY,
],
+ \Ess\M2ePro\Model\Cron\Task\Ebay\SynchronizePromotions::NICK => [
+ 'component' => \Ess\M2ePro\Helper\Component\Ebay::NICK,
+ 'group' => self::GROUP_EBAY,
+ ],
//----------------------------------------
diff --git a/Model/Ebay/Account.php b/Model/Ebay/Account.php
index 91e16da62..07b6b900e 100644
--- a/Model/Ebay/Account.php
+++ b/Model/Ebay/Account.php
@@ -1,11 +1,5 @@
shippingTemplateCollectionFactory = $shippingTemplateCollectionFactory;
- $this->componentEbayCategory = $componentEbayCategory;
- }
-
public function _construct()
{
parent::_construct();
$this->_init(\Ess\M2ePro\Model\ResourceModel\Ebay\Account::class);
}
- //########################################
+ // ----------------------------------------
public function save()
{
@@ -115,7 +75,7 @@ public function save()
return parent::save();
}
- //########################################
+ // ----------------------------------------
/**
* @param bool $asObjects
@@ -165,7 +125,7 @@ public function getEbayItems($asObjects = false, array $filters = [])
return $this->getRelatedSimpleItems('Ebay\Item', 'account_id', $asObjects, $filters);
}
- //########################################
+ // ----------------------------------------
/**
* @return bool
@@ -177,7 +137,7 @@ public function hasFeedbackTemplate()
->getSize();
}
- //########################################
+ // ----------------------------------------
/**
* @return int
@@ -283,7 +243,7 @@ public function isFeedbacksAutoResponseOnlyPositive()
return $this->getFeedbacksAutoResponseOnlyPositive() == 1;
}
- //########################################
+ // ----------------------------------------
/**
* @return int
@@ -424,7 +384,7 @@ public function getOtherListingsMappingItemIdAttribute()
return $setting;
}
- //########################################
+ // ----------------------------------------
/**
* @return bool
@@ -520,7 +480,7 @@ public function isOtherListingsMappingItemIdModeCustomAttribute()
return $this->getOtherListingsMappingItemIdMode() == self::OTHER_LISTINGS_MAPPING_ITEM_ID_MODE_CUSTOM_ATTRIBUTE;
}
- //########################################
+ // ----------------------------------------
/**
* @param int $marketplaceId
@@ -534,7 +494,7 @@ public function getRelatedStoreId($marketplaceId)
return $storeId !== null ? (int)$storeId : \Magento\Store\Model\Store::DEFAULT_STORE_ID;
}
- //########################################
+ // ----------------------------------------
/**
* @return bool
@@ -544,6 +504,19 @@ public function isMagentoOrdersListingsModeEnabled()
return $this->getSetting('magento_orders_settings', ['listing', 'mode'], 1) == 1;
}
+ public function getMagentoOrdersListingsCreateFromDate(): \DateTime
+ {
+ $date = $this->getSetting('magento_orders_settings', ['listing', 'create_from_date']);
+ if ($date === null) {
+ /** @var \Ess\M2ePro\Model\Account $parentObject */
+ $parentObject = $this->getParentObject();
+
+ return $parentObject->getCreateDate();
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt($date);
+ }
+
/**
* @return bool
*/
@@ -578,6 +551,19 @@ public function isMagentoOrdersListingsOtherModeEnabled()
return $this->getSetting('magento_orders_settings', ['listing_other', 'mode'], 1) == 1;
}
+ public function getMagentoOrdersListingsOtherCreateFromDate(): \DateTime
+ {
+ $date = $this->getSetting('magento_orders_settings', ['listing_other', 'create_from_date']);
+ if ($date === null) {
+ /** @var \Ess\M2ePro\Model\Account $parentObject */
+ $parentObject = $this->getParentObject();
+
+ return $parentObject->getCreateDate();
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt($date);
+ }
+
/**
* @return int
*/
@@ -1014,7 +1000,7 @@ public function isSkipEvtinModeOn()
return (bool)$this->getData('skip_evtin');
}
- //########################################
+ // ----------------------------------------
/**
* @return array
@@ -1069,7 +1055,7 @@ public function getOutOfStockControl()
return false;
}
- //########################################
+ // ----------------------------------------
public function getRateTables()
{
@@ -1215,7 +1201,7 @@ public function buildEbayStoreCategoriesTree()
return $this->buildEbayStoreCategoriesTreeRec($this->getEbayStoreCategories(), 0);
}
- //########################################
+ // ----------------------------------------
public function updateShippingDiscountProfiles($marketplaceId)
{
@@ -1255,7 +1241,7 @@ public function updateShippingDiscountProfiles($marketplaceId)
)->save();
}
- //########################################
+ // ----------------------------------------
public function isCacheEnabled()
{
diff --git a/Model/Ebay/Account/Builder.php b/Model/Ebay/Account/Builder.php
index 38ce5671d..1210caf54 100644
--- a/Model/Ebay/Account/Builder.php
+++ b/Model/Ebay/Account/Builder.php
@@ -1,37 +1,22 @@
activeRecordFactory = $activeRecordFactory;
- $this->ebayFactory = $ebayFactory;
parent::__construct($helperFactory, $modelFactory);
- }
- //########################################
+ $this->activeRecordFactory = $activeRecordFactory;
+ }
protected function prepareData()
{
@@ -181,13 +166,20 @@ protected function prepareData()
$keys = [
'mode',
+ 'create_from_date',
'store_mode',
'store_id',
];
foreach ($keys as $key) {
- if (isset($tempSettings[$key])) {
- $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
+ if (!isset($tempSettings[$key])) {
+ continue;
+ }
+
+ if ($key === 'create_from_date') {
+ $tempSettings[$key] = $this->convertDate($tempSettings[$key]);
}
+
+ $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
}
// Unmanaged orders settings
@@ -198,14 +190,21 @@ protected function prepareData()
$keys = [
'mode',
+ 'create_from_date',
'product_mode',
'product_tax_class_id',
'store_id',
];
foreach ($keys as $key) {
- if (isset($tempSettings[$key])) {
- $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
+ if (!isset($tempSettings[$key])) {
+ continue;
+ }
+
+ if ($key === 'create_from_date') {
+ $tempSettings[$key] = $this->convertDate($tempSettings[$key]);
}
+
+ $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
}
// order number settings
@@ -404,10 +403,24 @@ protected function prepareData()
}
/**
- * @return array
+ * @param \DateTime|string $date
*/
+ private function convertDate($date): string
+ {
+ if (is_string($date)) {
+ return $date;
+ }
+
+ $date = clone $date;
+
+ return $date->setTimezone(new \DateTimeZone(\Ess\M2ePro\Helper\Date::getTimezone()->getDefaultTimezone()))
+ ->format('Y-m-d H:i:s');
+ }
+
public function getDefaultData(): array
{
+ $currentGmtDate = \Ess\M2ePro\Helper\Date::createCurrentGmt()->format('Y-m-d H:i:s');
+
return [
'title' => '',
'user_id' => '',
@@ -429,11 +442,13 @@ public function getDefaultData(): array
'magento_orders_settings' => [
'listing' => [
'mode' => 1,
+ 'create_from_date' => $currentGmtDate,
'store_mode' => Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT,
'store_id' => null,
],
'listing_other' => [
'mode' => 1,
+ 'create_from_date' => $currentGmtDate,
'product_mode' => Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE,
'product_tax_class_id' => \Ess\M2ePro\Model\Magento\Product::TAX_CLASS_ID_NONE,
'store_id' => null,
diff --git a/Model/Ebay/Account/MagentoOrderCreateService.php b/Model/Ebay/Account/MagentoOrderCreateService.php
new file mode 100644
index 000000000..c0054bbc2
--- /dev/null
+++ b/Model/Ebay/Account/MagentoOrderCreateService.php
@@ -0,0 +1,53 @@
+ebayOrderRepository = $ebayOrderRepository;
+ $this->orderCreator = $orderCreator;
+ $this->exceptionHelper = $exceptionHelper;
+ }
+
+ public function createMagentoOrdersListingsByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $this->createByFromDate($accountId, $fromDate);
+ }
+
+ public function createMagentoOrdersListingsOtherByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $this->createByFromDate($accountId, $fromDate);
+ }
+
+ private function createByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $fromDate->setTimezone(
+ new \DateTimeZone(\Ess\M2ePro\Helper\Date::getTimezone()->getDefaultTimezone())
+ );
+ $toDate = \Ess\M2ePro\Helper\Date::createCurrentGmt();
+
+ $orders = $this->ebayOrderRepository->retrieveWithoutMagentoOrders(
+ $accountId,
+ $fromDate,
+ $toDate
+ );
+ foreach ($orders as $order) {
+ try {
+ $this->orderCreator->createMagentoOrder($order);
+ } catch (\Throwable $e) {
+ $this->exceptionHelper->process($e);
+ }
+ }
+ }
+}
diff --git a/Model/Ebay/Account/Repository.php b/Model/Ebay/Account/Repository.php
new file mode 100644
index 000000000..727369804
--- /dev/null
+++ b/Model/Ebay/Account/Repository.php
@@ -0,0 +1,26 @@
+accountCollectionFactory = $accountCollectionFactory;
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Account[]
+ */
+ public function getAll(): array
+ {
+ $accountsCollection = $this->accountCollectionFactory->createWithEbayChildMode();
+
+ return array_values($accountsCollection->getItems());
+ }
+}
diff --git a/Model/Ebay/AdvancedFilter/AllItemsOptions.php b/Model/Ebay/AdvancedFilter/AllItemsOptions.php
index 80755767a..89ab49472 100644
--- a/Model/Ebay/AdvancedFilter/AllItemsOptions.php
+++ b/Model/Ebay/AdvancedFilter/AllItemsOptions.php
@@ -36,9 +36,10 @@ class AllItemsOptions
private $listingProductResource;
/** @var \Ess\M2ePro\Model\Tag\ListingProduct\Repository */
private $tagRelationRepository;
-
private \Ess\M2ePro\Model\ResourceModel\Ebay\Promotion $promotionResource;
private \Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product\Promotion $listingProductPromotionResource;
+ private \Magento\Catalog\Model\ResourceModel\Product $magentoProductResource;
+ private \Magento\Catalog\Model\Product\Type $magentoProductType;
public function __construct(
DropDownFilter\OptionCollectionFactory $optionCollectionFactory,
@@ -57,7 +58,9 @@ public function __construct(
\Ess\M2ePro\Model\ResourceModel\Marketplace $marketplaceResource,
\Ess\M2ePro\Model\ResourceModel\Account $accountResource,
\Ess\M2ePro\Model\ResourceModel\Ebay\Promotion $promotionResource,
- \Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product\Promotion $listingProductPromotionResource
+ \Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product\Promotion $listingProductPromotionResource,
+ \Magento\Catalog\Model\ResourceModel\Product $magentoProductResource,
+ \Magento\Catalog\Model\Product\Type $magentoProductType
) {
$this->ebayListingResource = $ebayListingResource;
$this->ebayListingProductResource = $ebayListingProductResource;
@@ -76,6 +79,8 @@ public function __construct(
$this->optionFactory = $optionFactory;
$this->promotionResource = $promotionResource;
$this->listingProductPromotionResource = $listingProductPromotionResource;
+ $this->magentoProductResource = $magentoProductResource;
+ $this->magentoProductType = $magentoProductType;
}
public function getAccountOptions(): DropDownFilter\OptionCollection
@@ -408,6 +413,36 @@ public function getPromotionOptions(): DropDownFilter\OptionCollection
return $optionCollection;
}
+ public function getMagentoProductTypeOptions(): DropDownFilter\OptionCollection
+ {
+ $select = $this->getBaseSelect();
+ $select->joinInner(
+ ['mp' => $this->magentoProductResource->getEntityTable()],
+ sprintf(
+ 'mp.entity_id = listing_product.%s',
+ \Ess\M2ePro\Model\ResourceModel\Listing\Product::PRODUCT_ID_FIELD
+ ),
+ ['type_id']
+ );
+
+ $select->group('mp.type_id');
+ $select->order('mp.type_id');
+
+ $optionsData = $select->query()->fetchAll();
+ $magentoProductTypes = $this->magentoProductType->getOptionArray();
+
+ $optionCollection = $this->optionCollectionFactory->create();
+ foreach ($optionsData as $optionData) {
+ $optionLabel = $magentoProductTypes[($optionData['type_id'])];
+ $optionValue = $optionData['type_id'];
+
+ $option = $this->optionFactory->create($optionLabel, $optionValue);
+ $optionCollection->addOption($option);
+ }
+
+ return $optionCollection;
+ }
+
private function getBaseSelect(): \Magento\Framework\DB\Select
{
$select = $this->listingResource->getConnection()->select();
diff --git a/Model/Ebay/Connector/Promotion/Get/ItemsConnector.php b/Model/Ebay/Connector/Promotion/Get/ItemsConnector.php
index 98d2f94e2..5abb11402 100644
--- a/Model/Ebay/Connector/Promotion/Get/ItemsConnector.php
+++ b/Model/Ebay/Connector/Promotion/Get/ItemsConnector.php
@@ -52,6 +52,7 @@ protected function prepareResponseData(): void
$this->createDateTime($promotion['start_date']),
$this->createDateTime($promotion['end_date']),
$discounts,
+ $promotion['listing_ids']
);
$this->responseData[] = $channelPromotion;
diff --git a/Model/Ebay/Listing/Product/Repository.php b/Model/Ebay/Listing/Product/Repository.php
new file mode 100644
index 000000000..988bf715a
--- /dev/null
+++ b/Model/Ebay/Listing/Product/Repository.php
@@ -0,0 +1,44 @@
+ebayListingProductCollectionFactory = $ebayListingProductCollectionFactory;
+ $this->ebayItemResource = $ebayItemResource;
+ }
+
+ public function findByItemId(string $itemId): ?\Ess\M2ePro\Model\Ebay\Listing\Product
+ {
+ $collection = $this->ebayListingProductCollectionFactory->create();
+
+ $collection->join(
+ ['elp' => $this->ebayItemResource->getMainTable()],
+ sprintf(
+ 'main_table.%s = elp.%s',
+ \Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product::COLUMN_EBAY_ITEM_ID,
+ \Ess\M2ePro\Model\ResourceModel\Ebay\Item::COLUMN_ID
+ ),
+ []
+ );
+
+ $collection->addFieldToFilter(\Ess\M2ePro\Model\ResourceModel\Ebay\Item::COLUMN_ITEM_ID, $itemId);
+
+ $item = $collection->getFirstItem();
+
+ if ($item->isObjectNew()) {
+ return null;
+ }
+
+ return $item;
+ }
+}
diff --git a/Model/Ebay/Marketplace/Repository.php b/Model/Ebay/Marketplace/Repository.php
new file mode 100644
index 000000000..12119c1f7
--- /dev/null
+++ b/Model/Ebay/Marketplace/Repository.php
@@ -0,0 +1,49 @@
+marketplaceCollectionFactory = $marketplaceCollectionFactory;
+ $this->listingResource = $listingResource;
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Marketplace[]
+ */
+ public function findMarketplacesWithExistListing(\Ess\M2ePro\Model\Account $account): array
+ {
+ $marketplaceCollection = $this->marketplaceCollectionFactory->createWithEbayChildMode();
+ $marketplaceCollection->join(
+ ['l' => $this->listingResource->getMainTable()],
+ sprintf(
+ 'main_table.%s = l.%s',
+ \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_ID,
+ \Ess\M2ePro\Model\ResourceModel\Listing::COLUMN_MARKETPLACE_ID
+ ),
+ []
+ );
+
+ $marketplaceCollection->addFieldToFilter(
+ \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_STATUS,
+ \Ess\M2ePro\Model\Marketplace::STATUS_ENABLE
+ );
+ $marketplaceCollection->addFieldToFilter(
+ \Ess\M2ePro\Model\ResourceModel\Listing::COLUMN_ACCOUNT_ID,
+ $account->getId()
+ );
+
+ $marketplaceCollection->getSelect()->group(\Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_ID);
+
+ return array_values($marketplaceCollection->getItems());
+ }
+}
diff --git a/Model/Ebay/Order.php b/Model/Ebay/Order.php
index 9e0eb0109..53fbf60e8 100644
--- a/Model/Ebay/Order.php
+++ b/Model/Ebay/Order.php
@@ -1,15 +1,10 @@
getData('purchase_create_date');
+ return $this->getData(ResourceEbayOrder::COLUMN_PURCHASE_CREATE_DATE);
}
/**
diff --git a/Model/Ebay/Order/Item.php b/Model/Ebay/Order/Item.php
index 3c34e6278..8518d2ecb 100644
--- a/Model/Ebay/Order/Item.php
+++ b/Model/Ebay/Order/Item.php
@@ -359,13 +359,15 @@ public function isReservable()
return $this->isOrdersCreationEnabled();
}
- protected function isOrdersCreationEnabled(): bool
+ private function isOrdersCreationEnabled(): bool
{
$channelItem = $this->getChannelItem();
- $isOtherListingsEnabled = $this->getEbayAccount()->isMagentoOrdersListingsOtherModeEnabled();
if ($channelItem === null) {
- return $isOtherListingsEnabled;
+ return $this->isOrdersCreationEnabledForListingsOther(
+ $this->getEbayAccount(),
+ $this->getEbayOrder()
+ );
}
if (
@@ -375,10 +377,42 @@ protected function isOrdersCreationEnabled(): bool
$channelItem->getMarketplaceId()
)
) {
- return $isOtherListingsEnabled;
+ return $this->isOrdersCreationEnabledForListingsOther(
+ $this->getEbayAccount(),
+ $this->getEbayOrder()
+ );
+ }
+
+ return $this->isOrdersCreationEnabledForListings(
+ $this->getEbayAccount(),
+ $this->getEbayOrder()
+ );
+ }
+
+ private function isOrdersCreationEnabledForListingsOther(
+ \Ess\M2ePro\Model\Ebay\Account $ebayAccount,
+ \Ess\M2ePro\Model\Ebay\Order $ebayOrder
+ ): bool {
+ if (!$ebayAccount->isMagentoOrdersListingsOtherModeEnabled()) {
+ return false;
}
- return $this->getEbayAccount()->isMagentoOrdersListingsModeEnabled();
+ $purchaseCreateDate = \Ess\M2ePro\Helper\Date::createDateGmt($ebayOrder->getPurchaseCreateDate());
+
+ return $purchaseCreateDate >= $ebayAccount->getMagentoOrdersListingsOtherCreateFromDate();
+ }
+
+ private function isOrdersCreationEnabledForListings(
+ \Ess\M2ePro\Model\Ebay\Account $ebayAccount,
+ \Ess\M2ePro\Model\Ebay\Order $ebayOrder
+ ): bool {
+ if (!$ebayAccount->isMagentoOrdersListingsModeEnabled()) {
+ return false;
+ }
+
+ $purchaseCreateDate = \Ess\M2ePro\Helper\Date::createDateGmt($ebayOrder->getPurchaseCreateDate());
+
+ return $purchaseCreateDate >= $ebayAccount->getMagentoOrdersListingsCreateFromDate();
}
public function getAssociatedProductId()
diff --git a/Model/Ebay/Order/Repository.php b/Model/Ebay/Order/Repository.php
new file mode 100644
index 000000000..379b22d14
--- /dev/null
+++ b/Model/Ebay/Order/Repository.php
@@ -0,0 +1,49 @@
+orderCollectionFactory = $orderCollectionFactory;
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Order[]
+ */
+ public function retrieveWithoutMagentoOrders(
+ int $accountId,
+ \DateTime $fromPurchaseDate,
+ \DateTime $toPurchaseDate
+ ): array {
+ $collection = $this->orderCollectionFactory
+ ->createWithEbayChildMode()
+ ->addFieldToFilter(
+ EbayOrderResource::COLUMN_PURCHASE_CREATE_DATE,
+ ['gteq' => $fromPurchaseDate->format('Y-m-d H:i:s')]
+ )
+ ->addFieldToFilter(
+ EbayOrderResource::COLUMN_PURCHASE_CREATE_DATE,
+ ['lteq' => $toPurchaseDate->format('Y-m-d H:i:s')]
+ )
+ ->addFieldToFilter(
+ OrderResource::COLUMN_MAGENTO_ORDER_ID,
+ ['null' => true]
+ )
+ ->addFieldToFilter(
+ OrderResource::COLUMN_ACCOUNT_ID,
+ ['eq' => $accountId]
+ );
+
+ return array_values($collection->getItems());
+ }
+}
diff --git a/Model/Ebay/Promotion.php b/Model/Ebay/Promotion.php
index ad9207b88..543392b34 100644
--- a/Model/Ebay/Promotion.php
+++ b/Model/Ebay/Promotion.php
@@ -235,4 +235,26 @@ private function validateStatus(string $status): void
);
}
}
+
+ public static function getTypes(): array
+ {
+ return [
+ self::TYPE_CODED_COUPON,
+ self::TYPE_MARKDOWN_SALE,
+ self::TYPE_ORDER_DISCOUNT,
+ self::TYPE_VOLUME_DISCOUNT,
+ ];
+ }
+
+ public static function getStatuses(): array
+ {
+ return [
+ self::STATUS_SCHEDULED,
+ self::STATUS_RUNNING,
+ self::STATUS_PAUSED,
+ self::STATUS_DRAFT,
+ self::STATUS_ENDED,
+ self::STATUS_INVALID,
+ ];
+ }
}
diff --git a/Model/Ebay/Promotion/Collection.php b/Model/Ebay/Promotion/Collection.php
index e06fd84b3..db2f68071 100644
--- a/Model/Ebay/Promotion/Collection.php
+++ b/Model/Ebay/Promotion/Collection.php
@@ -46,4 +46,15 @@ public function getAll(): array
{
return array_values($this->promotions);
}
+
+ public function getByPromotionId(string $promotionId): ?\Ess\M2ePro\Model\Ebay\Promotion
+ {
+ foreach ($this->promotions as $promotion) {
+ if ($promotion->getPromotionId() === $promotionId) {
+ return $promotion;
+ }
+ }
+
+ return null;
+ }
}
diff --git a/Model/Ebay/Promotion/Create.php b/Model/Ebay/Promotion/Create.php
index 5c4de441e..ab342cea0 100644
--- a/Model/Ebay/Promotion/Create.php
+++ b/Model/Ebay/Promotion/Create.php
@@ -9,15 +9,18 @@ class Create
private Repository $repository;
private \Ess\M2ePro\Model\Ebay\PromotionFactory $factory;
private DiscountFactory $discountFactory;
+ private \Ess\M2ePro\Model\Ebay\Promotion\ItemSynchronization $itemSynchronizationService;
public function __construct(
Repository $repository,
\Ess\M2ePro\Model\Ebay\PromotionFactory $factory,
- \Ess\M2ePro\Model\Ebay\Promotion\DiscountFactory $discountFactory
+ \Ess\M2ePro\Model\Ebay\Promotion\DiscountFactory $discountFactory,
+ \Ess\M2ePro\Model\Ebay\Promotion\ItemSynchronization $itemSynchronizationService
) {
$this->repository = $repository;
$this->factory = $factory;
$this->discountFactory = $discountFactory;
+ $this->itemSynchronizationService = $itemSynchronizationService;
}
public function process(
@@ -40,9 +43,13 @@ public function process(
$this->repository->create($promotion);
+ $this->itemSynchronizationService->createItems($promotion, $channelPromotion->getItems());
+
+ /*
if ($promotion->isTypeWithDiscounts()) {
$this->createDiscounts($promotion, $channelPromotion->getDiscounts());
}
+ */
return $promotion;
}
diff --git a/Model/Ebay/Promotion/ExpiredPromotionsHandler.php b/Model/Ebay/Promotion/ExpiredPromotionsHandler.php
new file mode 100644
index 000000000..44dc9b418
--- /dev/null
+++ b/Model/Ebay/Promotion/ExpiredPromotionsHandler.php
@@ -0,0 +1,89 @@
+repository = $repository;
+ $this->listingProductFactory = $listingProductFactory;
+ $this->logFactory = $logFactory;
+ }
+
+ public function process(
+ \Ess\M2ePro\Model\Ebay\Account $ebayAccount,
+ \Ess\M2ePro\Model\Marketplace $marketplace
+ ): void {
+ $expiredPromotions = $this->repository->findExpiredPromotions();
+
+ if (empty($expiredPromotions)) {
+ return;
+ }
+
+ foreach ($expiredPromotions as $promotion) {
+ $this->removeExpiredPromotion($promotion, $ebayAccount, $marketplace);
+ }
+ }
+
+ private function removeExpiredPromotion(
+ \Ess\M2ePro\Model\Ebay\Promotion $promotion,
+ \Ess\M2ePro\Model\Ebay\Account $ebayAccount,
+ \Ess\M2ePro\Model\Marketplace $marketplace
+ ): void {
+ $listingProductPromotions = $this->repository->findListingProductsByAccountAndMarketplaceAndPromotion(
+ (int)$ebayAccount->getId(),
+ (int)$marketplace->getId(),
+ $promotion->getId()
+ );
+
+ foreach ($listingProductPromotions as $listingProductPromotion) {
+ $this->repository->removeListingProductPromotion($listingProductPromotion);
+
+ $listingProduct = $this->loadListingProduct((int)$listingProductPromotion->getListingProductId());
+
+ $this->writeLog($listingProduct, $promotion);
+ }
+
+ $this->repository->remove($promotion);
+ }
+
+ private function loadListingProduct(int $listingProductId): \Ess\M2ePro\Model\Listing\Product
+ {
+ $listingProduct = $this->listingProductFactory->create();
+ $listingProduct->load($listingProductId);
+
+ return $listingProduct;
+ }
+
+ private function writeLog(
+ \Ess\M2ePro\Model\Listing\Product $listingProduct,
+ \Ess\M2ePro\Model\Ebay\Promotion $promotion
+ ): void {
+ /** @var \Ess\M2ePro\Model\Ebay\Listing\Log $log */
+ $log = $this->logFactory->create();
+ $log->setComponentMode($listingProduct->getComponentMode());
+ $log->addProductMessage(
+ $listingProduct->getListingId(),
+ $listingProduct->getProductId(),
+ $listingProduct->getId(),
+ \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION,
+ null,
+ \Ess\M2ePro\Model\Listing\Log::ACTION_PROMOTION,
+ (string)__(
+ 'Promotion "%promotion_name" has ended. The Item is no longer being promoted',
+ ['promotion_name' => $promotion->getName()]
+ ),
+ \Ess\M2ePro\Model\Log\AbstractModel::TYPE_INFO
+ );
+ }
+}
diff --git a/Model/Ebay/Promotion/ItemSynchronization.php b/Model/Ebay/Promotion/ItemSynchronization.php
new file mode 100644
index 000000000..1c3cbed4e
--- /dev/null
+++ b/Model/Ebay/Promotion/ItemSynchronization.php
@@ -0,0 +1,190 @@
+listingProductFactory = $listingProductFactory;
+ $this->repository = $repository;
+ $this->logFactory = $logFactory;
+ $this->listingProductPromotionFactory = $listingProductPromotionFactory;
+ $this->ebayListingProductRepository = $ebayListingProductRepository;
+ }
+
+ public function syncItems(
+ \Ess\M2ePro\Model\Ebay\Promotion $promotion,
+ \Ess\M2ePro\Model\Ebay\Promotion\Channel\Promotion $channelPromotion
+ ): void {
+ $channelItems = $channelPromotion->getItems();
+ $existItems = $this->getItemsIds($promotion);
+
+ $itemsToAdd = $this->getItemsToAdd($channelItems, $existItems);
+ $listingProductPromotionToRemove = $this->getListingProductPromotionToRemove($channelItems, $existItems);
+
+ $this->addItems($promotion, $itemsToAdd);
+ $this->removeItems($promotion, $listingProductPromotionToRemove);
+ }
+
+ public function createItems(
+ \Ess\M2ePro\Model\Ebay\Promotion $promotion,
+ array $channelItems
+ ): void {
+ $this->addItems($promotion, $channelItems);
+ }
+
+ private function getItemsIds(\Ess\M2ePro\Model\Ebay\Promotion $promotion): array
+ {
+ $listingProductPromotions = $this->repository->findListingProductsByAccountAndMarketplaceAndPromotion(
+ $promotion->getAccountId(),
+ $promotion->getMarketplaceId(),
+ $promotion->getId()
+ );
+
+ $items = [];
+
+ foreach ($listingProductPromotions as $listingProductPromotion) {
+ $listingProduct = $this->loadListingProduct($listingProductPromotion->getListingProductId());
+ $itemId = $listingProduct->getChildObject()->getEbayItem()->getItemId();
+
+ if (empty($itemId)) {
+ continue;
+ }
+
+ $items[$itemId] = $listingProductPromotion;
+ }
+
+ return $items;
+ }
+
+ private function loadListingProduct(int $listingProductId): \Ess\M2ePro\Model\Listing\Product
+ {
+ $listingProduct = $this->listingProductFactory->create();
+ $listingProduct->load($listingProductId);
+
+ return $listingProduct;
+ }
+
+ // ----------------------------------------
+
+ private function getItemsToAdd(array $channelItems, array $existItems): array
+ {
+ $itemsToAdd = [];
+ foreach ($channelItems as $itemId) {
+ if (!array_key_exists($itemId, $existItems)) {
+ $itemsToAdd[] = $itemId;
+ }
+ }
+
+ return $itemsToAdd;
+ }
+
+ private function getListingProductPromotionToRemove(array $channelItems, array $existItems): array
+ {
+ $listingProductPromotionToRemove = [];
+ foreach ($existItems as $itemId => $listingProductPromotion) {
+ if (!in_array((string)$itemId, $channelItems, true)) {
+ $listingProductPromotionToRemove[] = $listingProductPromotion;
+ }
+ }
+
+ return $listingProductPromotionToRemove;
+ }
+
+ // ----------------------------------------
+
+ private function addItems(\Ess\M2ePro\Model\Ebay\Promotion $promotion, array $itemsIds): void
+ {
+ foreach ($itemsIds as $itemId) {
+ $ebayListingProduct = $this->ebayListingProductRepository->findByItemId($itemId);
+
+ if ($ebayListingProduct === null) {
+ continue;
+ }
+
+ $listingProduct = $ebayListingProduct->getParentObject();
+
+ $this->createListingProductPromotion($promotion, $listingProduct);
+
+ $message = (string)__(
+ 'Item was added to Promotion "%promotion_name"',
+ ['promotion_name' => $promotion->getName()]
+ );
+ $this->writeLog($listingProduct, $message);
+ }
+ }
+
+ private function createListingProductPromotion(
+ \Ess\M2ePro\Model\Ebay\Promotion $promotion,
+ \Ess\M2ePro\Model\Listing\Product $listingProduct
+ ): void {
+ $listingProductPromotion = $this->listingProductPromotionFactory->create();
+ $listingProductPromotion->init(
+ $promotion->getAccountId(),
+ $promotion->getMarketplaceId(),
+ (int)$listingProduct->getId(),
+ $promotion->getId(),
+ null
+ );
+
+ $this->repository->createListingProductPromotion($listingProductPromotion);
+ }
+
+ // ----------------------------------------
+
+ private function removeItems(\Ess\M2ePro\Model\Ebay\Promotion $promotion, array $listingProductPromotions): void
+ {
+ foreach ($listingProductPromotions as $listingProductPromotion) {
+ $this->removeListingProductPromotion($promotion, $listingProductPromotion);
+ }
+ }
+
+ private function removeListingProductPromotion(
+ \Ess\M2ePro\Model\Ebay\Promotion $promotion,
+ \Ess\M2ePro\Model\Ebay\Listing\Product\Promotion $listingProductPromotion
+ ): void {
+ $this->repository->removeListingProductPromotion($listingProductPromotion);
+
+ $listingProduct = $this->loadListingProduct($listingProductPromotion->getListingProductId());
+
+ $message = (string)__(
+ 'Item was removed from Promotion "%promotion_name"',
+ ['promotion_name' => $promotion->getName()]
+ );
+ $this->writeLog($listingProduct, $message);
+ }
+
+ private function writeLog(
+ \Ess\M2ePro\Model\Listing\Product $listingProduct,
+ string $message
+ ): void {
+ /** @var \Ess\M2ePro\Model\Ebay\Listing\Log $log */
+ $log = $this->logFactory->create();
+ $log->setComponentMode($listingProduct->getComponentMode());
+
+ $log->addProductMessage(
+ $listingProduct->getListingId(),
+ $listingProduct->getProductId(),
+ $listingProduct->getId(),
+ \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION,
+ null,
+ \Ess\M2ePro\Model\Listing\Log::ACTION_PROMOTION,
+ $message,
+ \Ess\M2ePro\Model\Log\AbstractModel::TYPE_INFO
+ );
+ }
+}
diff --git a/Model/Ebay/Promotion/Repository.php b/Model/Ebay/Promotion/Repository.php
index 8f1f5b02c..357e9f3b4 100644
--- a/Model/Ebay/Promotion/Repository.php
+++ b/Model/Ebay/Promotion/Repository.php
@@ -80,14 +80,18 @@ public function findByAccountAndMarketplace(int $accountId, int $marketplaceId):
return $result;
}
- public function removePromotionsByAccount(int $accountId): void
+ /**
+ * @return \Ess\M2ePro\Model\Ebay\Promotion[]
+ */
+ public function findExpiredPromotions(): array
{
- $this->promotionResource
- ->getConnection()
- ->delete(
- $this->promotionResource->getMainTable(),
- ["account_id <= '$accountId'"],
- );
+ $collection = $this->promotionCollectionFactory->create();
+ $collection->addFieldToFilter(
+ EbayPromotionResource::COLUMN_END_DATE,
+ ['lt' => \Ess\M2ePro\Helper\Date::createCurrentGmt()->format('Y-m-d H:i:s')]
+ );
+
+ return array_values($collection->getItems());
}
public function createDiscount(\Ess\M2ePro\Model\Ebay\Promotion\Discount $discount): void
diff --git a/Model/Ebay/Promotion/Synchronization.php b/Model/Ebay/Promotion/Synchronization.php
index cccc6a926..bbbad47db 100644
--- a/Model/Ebay/Promotion/Synchronization.php
+++ b/Model/Ebay/Promotion/Synchronization.php
@@ -11,19 +11,22 @@ class Synchronization
private \Ess\M2ePro\Model\Ebay\Promotion\Delete $deleteService;
private \Ess\M2ePro\Model\Ebay\Promotion\UpdateFromChannel $updateFromChannelService;
private \Ess\M2ePro\Model\Ebay\Promotion\Create $createService;
+ private \Ess\M2ePro\Model\Ebay\Promotion\ExpiredPromotionsHandler $expiredPromotionHandler;
public function __construct(
\Ess\M2ePro\Model\Ebay\Promotion\Repository $repository,
\Ess\M2ePro\Model\Ebay\Promotion\Channel\Retrieve $retrieverFromChannel,
\Ess\M2ePro\Model\Ebay\Promotion\Delete $deleteService,
\Ess\M2ePro\Model\Ebay\Promotion\UpdateFromChannel $updateFromChannelService,
- \Ess\M2ePro\Model\Ebay\Promotion\Create $createService
+ \Ess\M2ePro\Model\Ebay\Promotion\Create $createService,
+ \Ess\M2ePro\Model\Ebay\Promotion\ExpiredPromotionsHandler $expiredPromotionHandler
) {
$this->repository = $repository;
$this->retrieverFromChannel = $retrieverFromChannel;
$this->deleteService = $deleteService;
$this->updateFromChannelService = $updateFromChannelService;
$this->createService = $createService;
+ $this->expiredPromotionHandler = $expiredPromotionHandler;
}
public function process(
@@ -37,6 +40,8 @@ public function process(
(int)$marketplace->getId()
);
+ $this->expiredPromotionHandler->process($ebayAccount, $marketplace);
+
$this->remove($channelPromotionsCollection, $existPromotionsCollection);
$this->update($channelPromotionsCollection, $existPromotionsCollection);
$this->create($channelPromotionsCollection, $existPromotionsCollection, $ebayAccount, $marketplace);
diff --git a/Model/Ebay/Promotion/TimingManager.php b/Model/Ebay/Promotion/TimingManager.php
new file mode 100644
index 000000000..3e8d9c7d0
--- /dev/null
+++ b/Model/Ebay/Promotion/TimingManager.php
@@ -0,0 +1,55 @@
+registryManager = $registryManager;
+ }
+
+ public function isAttemptIntervalExceeded(string $accountId, string $marketplaceId): bool
+ {
+ $lastUpdate = $this->getLastProcessed($accountId, $marketplaceId);
+
+ if ($lastUpdate === null) {
+ return true;
+ }
+
+ $now = \Ess\M2ePro\Helper\Date::createCurrentGmt();
+
+ return $now->getTimestamp() - $lastUpdate->getTimestamp() > self::ATTEMPT_INTERVAL;
+ }
+
+ public function setLastProcessed(string $accountId, string $marketplaceId): void
+ {
+ $this->registryManager->setValue(
+ $this->getKey($accountId, $marketplaceId),
+ \Ess\M2ePro\Helper\Date::createCurrentGmt()->format('Y-m-d H:i:s')
+ );
+ }
+
+ private function getLastProcessed(string $accountId, string $marketplaceId): ?\DateTime
+ {
+ $lastProcessedToDate = $this->registryManager->getValue($this->getKey($accountId, $marketplaceId));
+
+ if ($lastProcessedToDate !== null) {
+ $lastProcessedToDate = \Ess\M2ePro\Helper\Date::createDateGmt($lastProcessedToDate);
+ }
+
+ return $lastProcessedToDate;
+ }
+
+ private function getKey(string $accountId, string $marketplaceId): string
+ {
+ return "/ebay/promotions/synchronize/{$accountId}/{$marketplaceId}/";
+ }
+}
diff --git a/Model/Ebay/Promotion/Update.php b/Model/Ebay/Promotion/Update.php
index 7b1279f56..1a15d6e34 100644
--- a/Model/Ebay/Promotion/Update.php
+++ b/Model/Ebay/Promotion/Update.php
@@ -109,7 +109,7 @@ private function processListingProducts(
array $listingProducts,
array $existListingProductPromotions,
array $itemsWithErrors
- ) {
+ ): void {
foreach ($listingProducts as $listingProduct) {
$itemId = $listingProduct->getChildObject()->getEbayItem()->getItemId();
$listingProductId = $listingProduct->getId();
@@ -122,7 +122,7 @@ private function processListingProducts(
'Item was removed from Promotion "%promotion_name"',
['promotion_name' => $promotion->getName()]
);
- $this->writeLog($listingProduct, $message, \Ess\M2ePro\Model\Log\AbstractModel::TYPE_INFO);
+ $this->writeLog($listingProduct, $message, \Ess\M2ePro\Model\Log\AbstractModel::TYPE_SUCCESS);
} else {
$message = (string)__(
'Item was not added to Promotion "%promotion_name"',
@@ -235,10 +235,10 @@ private function removeListingProductPromotion(
$listingProduct = $this->loadListingProduct($listingProductPromotion->getListingProductId());
$message = (string)__(
- 'Item was removed from Promotion "%promotion_name',
+ 'Item was removed from Promotion "%promotion_name"',
['promotion_name' => $promotion->getName()]
);
- $this->writeLog($listingProduct, $message, \Ess\M2ePro\Model\Log\AbstractModel::TYPE_INFO);
+ $this->writeLog($listingProduct, $message, \Ess\M2ePro\Model\Log\AbstractModel::TYPE_SUCCESS);
}
/**
diff --git a/Model/Ebay/Promotion/UpdateFromChannel.php b/Model/Ebay/Promotion/UpdateFromChannel.php
index 05c376fef..9f458be55 100644
--- a/Model/Ebay/Promotion/UpdateFromChannel.php
+++ b/Model/Ebay/Promotion/UpdateFromChannel.php
@@ -7,29 +7,34 @@
class UpdateFromChannel
{
private Repository $repository;
+ private \Ess\M2ePro\Model\Ebay\Promotion\ItemSynchronization $itemSynchronizationService;
- public function __construct(Repository $repository)
- {
+ public function __construct(
+ Repository $repository,
+ \Ess\M2ePro\Model\Ebay\Promotion\ItemSynchronization $itemSynchronizationService
+ ) {
$this->repository = $repository;
+ $this->itemSynchronizationService = $itemSynchronizationService;
}
public function process(
\Ess\M2ePro\Model\Ebay\Promotion $promotion,
\Ess\M2ePro\Model\Ebay\Promotion\Channel\Promotion $channel
): void {
- if (!$this->nothingUpdate($promotion, $channel)) {
- return;
+ if ($this->hasChanges($promotion, $channel)) {
+ $promotion->setName($channel->getName())
+ ->setType($channel->getType())
+ ->setStatus($channel->getStatus())
+ ->setPriority($channel->getPriority())
+ ->setStartDate($channel->getStartDate())
+ ->setEndDate($channel->getEndDate());
+
+ $this->repository->save($promotion);
}
- $promotion->setName($channel->getName())
- ->setType($channel->getType())
- ->setStatus($channel->getStatus())
- ->setPriority($channel->getPriority())
- ->setStartDate($channel->getStartDate())
- ->setEndDate($channel->getEndDate());
-
- $this->repository->save($promotion);
+ $this->itemSynchronizationService->syncItems($promotion, $channel);
+ /*
if (!$promotion->isTypeWithDiscounts()) {
return;
}
@@ -37,16 +42,16 @@ public function process(
$existDiscounts = $this->repository->findDiscountsByPromotionId($promotion->getId());
$channelDiscounts = $channel->getDiscounts();
- // todo
if (!$this->isDiscountsChanged($existDiscounts, $channelDiscounts)) {
return;
}
- //$this->removeDiscountsAndListingProductPromotions($promotion);
- //$this->createDiscounts($promotion, $channelDiscounts);
+ $this->removeDiscountsAndListingProductPromotions($promotion);
+ $this->createDiscounts($promotion, $channelDiscounts);
+ */
}
- private function nothingUpdate(\Ess\M2ePro\Model\Ebay\Promotion $promotion, Channel\Promotion $channel): bool
+ private function hasChanges(\Ess\M2ePro\Model\Ebay\Promotion $promotion, Channel\Promotion $channel): bool
{
// todo check discounts if exist
return $promotion->getName() !== $channel->getName()
diff --git a/Model/Listing/Log.php b/Model/Listing/Log.php
index f1f57a6c5..c0b9c4c6a 100644
--- a/Model/Listing/Log.php
+++ b/Model/Listing/Log.php
@@ -104,7 +104,7 @@ class Log extends \Ess\M2ePro\Model\Log\AbstractModel
public const _ACTION_CHANGE_PRODUCT_QTY_IN_MAGENTO_SOURCE = 'Update of FBA Product QTY in Magento Store';
public const ACTION_PROMOTION = 38;
- public const _ACTION_PROMOTION = 'Promotion';
+ public const _ACTION_PROMOTION = 'Update Promotion';
public const ACTION_VIDEO = 39;
public const _ACTION_VIDEO = 'Upload Product Video on Channel';
diff --git a/Model/ResourceModel/Account.php b/Model/ResourceModel/Account.php
index 14fb8f1f1..4922b1f3a 100644
--- a/Model/ResourceModel/Account.php
+++ b/Model/ResourceModel/Account.php
@@ -1,24 +1,19 @@
_init('m2epro_account', 'id');
+ $this->_init(
+ \Ess\M2ePro\Helper\Module\Database\Tables::TABLE_ACCOUNT,
+ self::COLUMN_ID
+ );
}
-
- //########################################
}
diff --git a/Model/ResourceModel/Amazon/Order.php b/Model/ResourceModel/Amazon/Order.php
index d7500b9a0..c4863205c 100644
--- a/Model/ResourceModel/Amazon/Order.php
+++ b/Model/ResourceModel/Amazon/Order.php
@@ -4,19 +4,24 @@
class Order extends \Ess\M2ePro\Model\ResourceModel\ActiveRecord\Component\Child\AbstractModel
{
+ public const COLUMN_ORDER_ID = 'order_id';
+ public const COLUMN_AMAZON_ORDER_ID = 'amazon_order_id';
+ public const COLUMN_IS_INVOICE_SENT = 'is_invoice_sent';
+ public const COLUMN_DATE_OF_INVOICE_SENDING = 'date_of_invoice_sending';
+ public const COLUMN_PURCHASE_CREATE_DATE = 'purchase_create_date';
+
/** @var bool */
protected $_isPkAutoIncrement = false;
- //########################################
-
public function _construct()
{
- $this->_init('m2epro_amazon_order', 'order_id');
+ $this->_init(
+ \Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_ORDER,
+ self::COLUMN_ORDER_ID
+ );
$this->_isPkAutoIncrement = false;
}
- //########################################
-
public function hasGifts($orderId)
{
/** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Order\Collection $collection */
@@ -29,8 +34,6 @@ public function hasGifts($orderId)
return $collection->getSize();
}
- //########################################
-
public function getItemsTotal($orderId): float
{
/** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Order\Collection $collection */
@@ -45,6 +48,4 @@ public function getItemsTotal($orderId): float
return round((float)$collection->getFirstItem()->getData('items_total'), 2);
}
-
- //########################################
}
diff --git a/Model/ResourceModel/Ebay/Item.php b/Model/ResourceModel/Ebay/Item.php
index 5864fde15..2d0d29ee9 100644
--- a/Model/ResourceModel/Ebay/Item.php
+++ b/Model/ResourceModel/Ebay/Item.php
@@ -1,24 +1,19 @@
_init('m2epro_ebay_item', 'id');
+ $this->_init(
+ \Ess\M2ePro\Helper\Module\Database\Tables::TABLE_EBAY_ITEM,
+ self::COLUMN_ID
+ );
}
-
- //########################################
}
diff --git a/Model/ResourceModel/Ebay/Listing/Product.php b/Model/ResourceModel/Ebay/Listing/Product.php
index 31e5490f9..e3e318412 100644
--- a/Model/ResourceModel/Ebay/Listing/Product.php
+++ b/Model/ResourceModel/Ebay/Listing/Product.php
@@ -5,6 +5,7 @@
class Product extends \Ess\M2ePro\Model\ResourceModel\ActiveRecord\Component\Child\AbstractModel
{
public const COLUMN_LISTING_PRODUCT_ID = 'listing_product_id';
+ public const COLUMN_EBAY_ITEM_ID = 'ebay_item_id';
public const COLUMN_TEMPLATE_SYNCHRONIZATION_ID = 'template_synchronization_id';
public const COLUMN_ONLINE_PRODUCT_IDENTIFIERS_HASH = 'online_product_identifiers_hash';
diff --git a/Model/ResourceModel/Ebay/Listing/Product/Collection.php b/Model/ResourceModel/Ebay/Listing/Product/Collection.php
index b154ec30d..5c2402a4d 100644
--- a/Model/ResourceModel/Ebay/Listing/Product/Collection.php
+++ b/Model/ResourceModel/Ebay/Listing/Product/Collection.php
@@ -1,21 +1,15 @@
_init(
@@ -23,6 +17,4 @@ public function _construct()
\Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product::class
);
}
-
- //########################################
}
diff --git a/Model/ResourceModel/Ebay/Listing/Product/CollectionFactory.php b/Model/ResourceModel/Ebay/Listing/Product/CollectionFactory.php
index f872ab756..9939caa3f 100644
--- a/Model/ResourceModel/Ebay/Listing/Product/CollectionFactory.php
+++ b/Model/ResourceModel/Ebay/Listing/Product/CollectionFactory.php
@@ -6,8 +6,7 @@
class CollectionFactory
{
- /** @var \Magento\Framework\ObjectManagerInterface */
- private $objectManager;
+ private \Magento\Framework\ObjectManagerInterface $objectManager;
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
{
diff --git a/Model/ResourceModel/Ebay/Order.php b/Model/ResourceModel/Ebay/Order.php
index 377fd3e40..cb64c4958 100644
--- a/Model/ResourceModel/Ebay/Order.php
+++ b/Model/ResourceModel/Ebay/Order.php
@@ -1,28 +1,24 @@
_init('m2epro_ebay_order', 'order_id');
+ $this->_init(
+ \Ess\M2ePro\Helper\Module\Database\Tables::TABLE_EBAY_ORDER,
+ self::COLUMN_ORDER_ID
+ );
$this->_isPkAutoIncrement = false;
}
- //########################################
-
public function getOrdersContainingItemsFromOrder($accountId, array $items)
{
// Prepare item_id-transaction_id pairs for sql
@@ -71,8 +67,6 @@ public function getOrdersContainingItemsFromOrder($accountId, array $items)
return $collection->getItems();
}
- //########################################
-
public function getCancellationCandidatesChannelIds($accountId, \DateTime $startDate, \DateTime $endDate)
{
/** @var \Ess\M2ePro\Model\ResourceModel\ActiveRecord\Collection\AbstractModel $collection */
@@ -98,6 +92,4 @@ public function getCancellationCandidatesChannelIds($accountId, \DateTime $start
return $ebayOrdersIds;
}
-
- //########################################
}
diff --git a/Model/ResourceModel/Listing.php b/Model/ResourceModel/Listing.php
index ce7657546..8d8a20945 100644
--- a/Model/ResourceModel/Listing.php
+++ b/Model/ResourceModel/Listing.php
@@ -6,6 +6,7 @@ class Listing extends ActiveRecord\Component\Parent\AbstractModel
{
public const COLUMN_ID = 'id';
public const COLUMN_ACCOUNT_ID = 'account_id';
+ public const COLUMN_MARKETPLACE_ID = 'marketplace_id';
public function _construct()
{
diff --git a/Model/ResourceModel/Order.php b/Model/ResourceModel/Order.php
index 71762775a..3f7475d26 100644
--- a/Model/ResourceModel/Order.php
+++ b/Model/ResourceModel/Order.php
@@ -1,24 +1,18 @@
_init('m2epro_order', 'id');
+ $this->_init(
+ \Ess\M2ePro\Helper\Module\Database\Tables::TABLE_ORDER,
+ self::COLUMN_ID
+ );
}
-
- //########################################
}
diff --git a/Model/ResourceModel/Walmart/Order.php b/Model/ResourceModel/Walmart/Order.php
index 0ae76807a..e4d89e06f 100644
--- a/Model/ResourceModel/Walmart/Order.php
+++ b/Model/ResourceModel/Walmart/Order.php
@@ -4,12 +4,13 @@
class Order extends \Ess\M2ePro\Model\ResourceModel\ActiveRecord\Component\Child\AbstractModel
{
+ public const COLUMN_ORDER_ID = 'order_id';
+ public const COLUMN_PURCHASE_CREATE_DATE = 'purchase_create_date';
public const COLUMN_IS_TRIED_TO_ACKNOWLEDGE = 'is_tried_to_acknowledge';
+ private \Ess\M2ePro\Model\ActiveRecord\Component\Parent\Walmart\Factory $walmartFactory;
/** @var bool */
protected $_isPkAutoIncrement = false;
- /** @var \Ess\M2ePro\Model\ActiveRecord\Component\Parent\Walmart\Factory */
- protected $walmartFactory;
public function __construct(
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Walmart\Factory $walmartFactory,
@@ -19,21 +20,20 @@ public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
$connectionName = null
) {
- $this->walmartFactory = $walmartFactory;
-
parent::__construct($helperFactory, $activeRecordFactory, $parentFactory, $context, $connectionName);
- }
- //########################################
+ $this->walmartFactory = $walmartFactory;
+ }
public function _construct()
{
- $this->_init('m2epro_walmart_order', 'order_id');
+ $this->_init(
+ \Ess\M2ePro\Helper\Module\Database\Tables::TABLE_WALMART_ORDER,
+ self::COLUMN_ORDER_ID
+ );
$this->_isPkAutoIncrement = false;
}
- //########################################
-
public function getItemsTotal($orderId)
{
/** @var \Ess\M2ePro\Model\ResourceModel\Walmart\Order\Collection $collection */
@@ -47,6 +47,4 @@ public function getItemsTotal($orderId)
return round((float)$collection->getFirstItem()->getData('items_total'), 2);
}
-
- //########################################
}
diff --git a/Model/Setup/Installer.php b/Model/Setup/Installer.php
index 6f288ed02..ffd0e8fd1 100644
--- a/Model/Setup/Installer.php
+++ b/Model/Setup/Installer.php
@@ -9645,15 +9645,18 @@ private function installAmazonSchema()
->setOption('row_format', 'dynamic');
$this->getConnection()->createTable($amazonMarketplaceTable);
- $amazonOrderTable = $this->getConnection()->newTable($this->getFullTableName('amazon_order'))
+ #region amazon_order
+ $amazonOrderTable = $this->getConnection()->newTable(
+ $this->getFullTableName(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_ORDER)
+ )
->addColumn(
- 'order_id',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Order::COLUMN_ORDER_ID,
Table::TYPE_INTEGER,
null,
['unsigned' => true, 'primary' => true, 'nullable' => false]
)
->addColumn(
- 'amazon_order_id',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Order::COLUMN_AMAZON_ORDER_ID,
Table::TYPE_TEXT,
255,
['nullable' => false]
@@ -9701,11 +9704,17 @@ private function installAmazonSchema()
['unsigned' => true, 'nullable' => false, 'default' => 0]
)
->addColumn(
- 'is_invoice_sent',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Order::COLUMN_IS_INVOICE_SENT,
Table::TYPE_SMALLINT,
null,
['unsigned' => true, 'nullable' => false, 'default' => 0]
)
+ ->addColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Order::COLUMN_DATE_OF_INVOICE_SENDING,
+ Table::TYPE_DATETIME,
+ null,
+ ['default' => null]
+ )
->addColumn(
'is_credit_memo_sent',
Table::TYPE_SMALLINT,
@@ -9878,7 +9887,10 @@ private function installAmazonSchema()
->addIndex('seller_order_id', 'seller_order_id')
->addIndex('is_prime', 'is_prime')
->addIndex('is_business', 'is_business')
- ->addIndex('is_invoice_sent', 'is_invoice_sent')
+ ->addIndex(
+ 'is_invoice_sent',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Order::COLUMN_IS_INVOICE_SENT,
+ )
->addIndex('is_credit_memo_sent', 'is_credit_memo_sent')
->addIndex('buyer_email', 'buyer_email')
->addIndex('buyer_name', 'buyer_name')
@@ -9891,6 +9903,7 @@ private function installAmazonSchema()
->setOption('collate', 'utf8_general_ci')
->setOption('row_format', 'dynamic');
$this->getConnection()->createTable($amazonOrderTable);
+ #endregion
$amazonOrderItemTable = $this->getConnection()->newTable($this->getFullTableName('amazon_order_item'))
->addColumn(
diff --git a/Model/Setup/Upgrader.php b/Model/Setup/Upgrader.php
index 14ab41817..387bf03e7 100644
--- a/Model/Setup/Upgrader.php
+++ b/Model/Setup/Upgrader.php
@@ -206,6 +206,7 @@ class Upgrader
'1.64.1' => ['1.65.0'],
'1.65.0' => ['1.65.1'],
'1.65.1' => ['1.65.2'],
+ '1.65.2' => ['1.66.0'],
];
//########################################
diff --git a/Model/Walmart/Account.php b/Model/Walmart/Account.php
index e21e7ab84..26e597775 100644
--- a/Model/Walmart/Account.php
+++ b/Model/Walmart/Account.php
@@ -1,15 +1,8 @@
_init(\Ess\M2ePro\Model\ResourceModel\Walmart\Account::class);
}
- //########################################
-
public function getWalmartItems($asObjects = false, array $filters = [])
{
return $this->getRelatedSimpleItems('Walmart\Item', 'account_id', $asObjects, $filters);
}
- //########################################
-
public function getProcessingList(): array
{
return $this->getRelatedSimpleItems('Walmart_Listing_Product_Action_ProcessingList', 'account_id', true);
@@ -124,8 +109,6 @@ public function setMarketplace(\Ess\M2ePro\Model\Marketplace $instance)
$this->marketplaceModel = $instance;
}
- //########################################
-
public function getServerHash()
{
return $this->getData('server_hash');
@@ -203,7 +186,7 @@ public function getDecodedInfo()
return $tempInfo === null ? null : \Ess\M2ePro\Helper\Json::decode($tempInfo);
}
- //########################################
+ // ----------------------------------------
/**
* @return int
@@ -447,7 +430,7 @@ public function getOtherListingsMappingTitleAttribute()
return $setting;
}
- //########################################
+ // ----------------------------------------
/**
* @return bool
@@ -579,7 +562,7 @@ public function isOtherListingsMappingUpcModeCustomAttribute()
return $this->getOtherListingsMappingUpcMode() == self::OTHER_LISTINGS_MAPPING_UPC_MODE_CUSTOM_ATTRIBUTE;
}
- //########################################
+ // ----------------------------------------
/**
* @return bool
@@ -589,6 +572,19 @@ public function isMagentoOrdersListingsModeEnabled()
return $this->getSetting('magento_orders_settings', ['listing', 'mode'], 1) == 1;
}
+ public function getMagentoOrdersListingsCreateFromDate(): \DateTime
+ {
+ $date = $this->getSetting('magento_orders_settings', ['listing', 'create_from_date']);
+ if ($date === null) {
+ /** @var \Ess\M2ePro\Model\Account $parentObject */
+ $parentObject = $this->getParentObject();
+
+ return $parentObject->getCreateDate();
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt($date);
+ }
+
/**
* @return bool
*/
@@ -623,6 +619,19 @@ public function isMagentoOrdersListingsOtherModeEnabled()
return $this->getSetting('magento_orders_settings', ['listing_other', 'mode'], 1) == 1;
}
+ public function getMagentoOrdersListingsOtherCreateFromDate(): \DateTime
+ {
+ $date = $this->getSetting('magento_orders_settings', ['listing_other', 'create_from_date']);
+ if ($date === null) {
+ /** @var \Ess\M2ePro\Model\Account $parentObject */
+ $parentObject = $this->getParentObject();
+
+ return $parentObject->getCreateDate();
+ }
+
+ return \Ess\M2ePro\Helper\Date::createDateGmt($date);
+ }
+
/**
* @return int
*/
diff --git a/Model/Walmart/Account/Builder.php b/Model/Walmart/Account/Builder.php
index ba26cc363..1da3685dd 100644
--- a/Model/Walmart/Account/Builder.php
+++ b/Model/Walmart/Account/Builder.php
@@ -1,22 +1,11 @@
convertDate($tempSettings[$key]);
}
+
+ $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
}
// Unmanaged orders settings
@@ -184,14 +180,21 @@ protected function prepareData()
$keys = [
'mode',
+ 'create_from_date',
'product_mode',
'product_tax_class_id',
'store_id',
];
foreach ($keys as $key) {
- if (isset($tempSettings[$key])) {
- $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
+ if (!isset($tempSettings[$key])) {
+ continue;
+ }
+
+ if ($key === 'create_from_date') {
+ $tempSettings[$key] = $this->convertDate($tempSettings[$key]);
}
+
+ $data['magento_orders_settings'][$tempKey][$key] = $tempSettings[$key];
}
// order number settings
@@ -366,8 +369,25 @@ protected function prepareData()
return $data;
}
+ /**
+ * @param \DateTime|string $date
+ */
+ private function convertDate($date): string
+ {
+ if (is_string($date)) {
+ return $date;
+ }
+
+ $date = clone $date;
+
+ return $date->setTimezone(new \DateTimeZone(\Ess\M2ePro\Helper\Date::getTimezone()->getDefaultTimezone()))
+ ->format('Y-m-d H:i:s');
+ }
+
public function getDefaultData()
{
+ $currentGmtDate = \Ess\M2ePro\Helper\Date::createCurrentGmt()->format('Y-m-d H:i:s');
+
return [
'title' => '',
'marketplace_id' => 0,
@@ -383,7 +403,7 @@ public function getDefaultData()
'other_listings_mapping_settings' => [
'sku' => [
'mode' => Account::OTHER_LISTINGS_MAPPING_SKU_MODE_DEFAULT,
- 'priority' => 1
+ 'priority' => 1,
],
],
'mapping_sku_mode' => Account::OTHER_LISTINGS_MAPPING_SKU_MODE_DEFAULT,
@@ -392,11 +412,13 @@ public function getDefaultData()
'magento_orders_settings' => [
'listing' => [
'mode' => 1,
+ 'create_from_date' => $currentGmtDate,
'store_mode' => Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT,
'store_id' => null,
],
'listing_other' => [
'mode' => 1,
+ 'create_from_date' => $currentGmtDate,
'product_mode' => Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE,
'product_tax_class_id' => \Ess\M2ePro\Model\Magento\Product::TAX_CLASS_ID_NONE,
'store_id' => null,
@@ -434,8 +456,8 @@ public function getDefaultData()
'shipping_address_region_override' => 1,
],
'qty_reservation' => [
- 'days' => 1
- ]
+ 'days' => 1,
+ ],
],
'create_magento_invoice' => 1,
'create_magento_shipment' => 1,
diff --git a/Model/Walmart/Account/MagentoOrderCreateService.php b/Model/Walmart/Account/MagentoOrderCreateService.php
new file mode 100644
index 000000000..c48e746c0
--- /dev/null
+++ b/Model/Walmart/Account/MagentoOrderCreateService.php
@@ -0,0 +1,53 @@
+walmartOrderRepository = $walmartOrderRepository;
+ $this->orderCreator = $orderCreator;
+ $this->exceptionHelper = $exceptionHelper;
+ }
+
+ public function createMagentoOrdersListingsByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $this->createByFromDate($accountId, $fromDate);
+ }
+
+ public function createMagentoOrdersListingsOtherByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $this->createByFromDate($accountId, $fromDate);
+ }
+
+ private function createByFromDate(int $accountId, \DateTime $fromDate): void
+ {
+ $fromDate->setTimezone(
+ new \DateTimeZone(\Ess\M2ePro\Helper\Date::getTimezone()->getDefaultTimezone())
+ );
+ $toDate = \Ess\M2ePro\Helper\Date::createCurrentGmt();
+
+ $orders = $this->walmartOrderRepository->retrieveWithoutMagentoOrders(
+ $accountId,
+ $fromDate,
+ $toDate
+ );
+ foreach ($orders as $order) {
+ try {
+ $this->orderCreator->createMagentoOrder($order);
+ } catch (\Throwable $e) {
+ $this->exceptionHelper->process($e);
+ }
+ }
+ }
+}
diff --git a/Model/Walmart/AdvancedFilter/AllItemsOptions.php b/Model/Walmart/AdvancedFilter/AllItemsOptions.php
index 509a3fe29..32ea71b89 100644
--- a/Model/Walmart/AdvancedFilter/AllItemsOptions.php
+++ b/Model/Walmart/AdvancedFilter/AllItemsOptions.php
@@ -30,6 +30,8 @@ class AllItemsOptions
private $listingResource;
/** @var \Ess\M2ePro\Model\ResourceModel\Listing\Product */
private $listingProductResource;
+ private \Magento\Catalog\Model\ResourceModel\Product $magentoProductResource;
+ private \Magento\Catalog\Model\Product\Type $magentoProductType;
public function __construct(
DropDownFilter\OptionCollectionFactory $optionCollectionFactory,
@@ -43,7 +45,9 @@ public function __construct(
\Ess\M2ePro\Model\ResourceModel\Template\Description $descriptionPolicyResource,
\Ess\M2ePro\Model\ResourceModel\Walmart\Template\Category $walmartCategoryResource,
\Ess\M2ePro\Model\ResourceModel\Marketplace $marketplaceResource,
- \Ess\M2ePro\Model\ResourceModel\Account $accountResource
+ \Ess\M2ePro\Model\ResourceModel\Account $accountResource,
+ \Magento\Catalog\Model\ResourceModel\Product $magentoProductResource,
+ \Magento\Catalog\Model\Product\Type $magentoProductType
) {
$this->walmartListingResource = $walmartListingResource;
$this->walmartListingProductResource = $walmartListingProductResource;
@@ -57,6 +61,8 @@ public function __construct(
$this->listingProductResource = $listingProductResource;
$this->optionCollectionFactory = $optionCollectionFactory;
$this->optionFactory = $optionFactory;
+ $this->magentoProductResource = $magentoProductResource;
+ $this->magentoProductType = $magentoProductType;
}
public function getAccountOptions(): DropDownFilter\OptionCollection
@@ -236,6 +242,36 @@ public function getCategoryOptions(): DropDownFilter\OptionCollection
return $optionCollection;
}
+ public function getMagentoProductTypeOptions(): DropDownFilter\OptionCollection
+ {
+ $select = $this->getBaseSelect();
+ $select->joinInner(
+ ['mp' => $this->magentoProductResource->getEntityTable()],
+ sprintf(
+ 'mp.entity_id = listing_product.%s',
+ \Ess\M2ePro\Model\ResourceModel\Listing\Product::PRODUCT_ID_FIELD
+ ),
+ ['type_id']
+ );
+
+ $select->group('mp.type_id');
+ $select->order('mp.type_id');
+
+ $optionsData = $select->query()->fetchAll();
+ $magentoProductTypes = $this->magentoProductType->getOptionArray();
+
+ $optionCollection = $this->optionCollectionFactory->create();
+ foreach ($optionsData as $optionData) {
+ $optionLabel = $magentoProductTypes[($optionData['type_id'])];
+ $optionValue = $optionData['type_id'];
+
+ $option = $this->optionFactory->create($optionLabel, $optionValue);
+ $optionCollection->addOption($option);
+ }
+
+ return $optionCollection;
+ }
+
private function getBaseSelect(): \Magento\Framework\DB\Select
{
$select = $this->listingResource->getConnection()->select();
diff --git a/Model/Walmart/Order.php b/Model/Walmart/Order.php
index 03f4a620c..33adc94f6 100644
--- a/Model/Walmart/Order.php
+++ b/Model/Walmart/Order.php
@@ -3,9 +3,9 @@
namespace Ess\M2ePro\Model\Walmart;
use Magento\Sales\Model\Order\Creditmemo;
+use Ess\M2ePro\Model\ResourceModel\Walmart\Order as ResourceWalmartOrder;
/**
- * Class \Ess\M2ePro\Model\Walmart\Order
* @method \Ess\M2ePro\Model\Order getParentObject()
* @method \Ess\M2ePro\Model\ResourceModel\Walmart\Order getResource()
*/
@@ -23,7 +23,7 @@ class Order extends \Ess\M2ePro\Model\ActiveRecord\Component\Child\Walmart\Abstr
private $subTotalPrice = null;
private $grandTotalPrice = null;
- /** @var \Ess\M2ePro\Model\Walmart\Order\ShippingAddressFactory */
+ /** @var \Ess\M2ePro\Model\Walmart\Order\ShippingAddressFactory */
protected $shippingAddressFactory;
/** @var \Magento\Sales\Model\Order\Email\Sender\OrderSender */
private $orderSender;
@@ -355,6 +355,11 @@ public function isReservable(): bool
return true;
}
+ public function getPurchaseCreateDate(): string
+ {
+ return $this->getDataByKey(ResourceWalmartOrder::COLUMN_PURCHASE_CREATE_DATE);
+ }
+
public function isWalmartFulfillment(): bool
{
return (bool)$this->getData('is_wfs');
diff --git a/Model/Walmart/Order/Item.php b/Model/Walmart/Order/Item.php
index 9dc5a54b4..eef6357a1 100644
--- a/Model/Walmart/Order/Item.php
+++ b/Model/Walmart/Order/Item.php
@@ -1,20 +1,13 @@
getChannelItem();
- $isOtherListingsEnabled = $this->getWalmartAccount()->isMagentoOrdersListingsOtherModeEnabled();
if ($channelItem === null) {
- return $isOtherListingsEnabled;
+ return $this->isOrdersCreationEnabledForListingsOther(
+ $this->getWalmartAccount(),
+ $this->getWalmartOrder()
+ );
}
if (
@@ -242,10 +237,42 @@ private function isOrdersCreationEnabled(): bool
$channelItem->getMarketplaceId()
)
) {
- return $isOtherListingsEnabled;
+ return $this->isOrdersCreationEnabledForListingsOther(
+ $this->getWalmartAccount(),
+ $this->getWalmartOrder()
+ );
}
- return $this->getWalmartAccount()->isMagentoOrdersListingsModeEnabled();
+ return $this->isOrdersCreationEnabledForListings(
+ $this->getWalmartAccount(),
+ $this->getWalmartOrder()
+ );
+ }
+
+ private function isOrdersCreationEnabledForListingsOther(
+ \Ess\M2ePro\Model\Walmart\Account $walmartAccount,
+ \Ess\M2ePro\Model\Walmart\Order $walmartOrder
+ ): bool {
+ if (!$walmartAccount->isMagentoOrdersListingsOtherModeEnabled()) {
+ return false;
+ }
+
+ $purchaseCreateDate = \Ess\M2ePro\Helper\Date::createDateGmt($walmartOrder->getPurchaseCreateDate());
+
+ return $purchaseCreateDate >= $walmartAccount->getMagentoOrdersListingsOtherCreateFromDate();
+ }
+
+ private function isOrdersCreationEnabledForListings(
+ \Ess\M2ePro\Model\Walmart\Account $walmartAccount,
+ \Ess\M2ePro\Model\Walmart\Order $walmartOrder
+ ): bool {
+ if (!$walmartAccount->isMagentoOrdersListingsModeEnabled()) {
+ return false;
+ }
+
+ $purchaseCreateDate = \Ess\M2ePro\Helper\Date::createDateGmt($walmartOrder->getPurchaseCreateDate());
+
+ return $purchaseCreateDate >= $walmartAccount->getMagentoOrdersListingsCreateFromDate();
}
/**
diff --git a/Model/Walmart/Order/Repository.php b/Model/Walmart/Order/Repository.php
new file mode 100644
index 000000000..e46f05232
--- /dev/null
+++ b/Model/Walmart/Order/Repository.php
@@ -0,0 +1,49 @@
+orderCollectionFactory = $orderCollectionFactory;
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Order[]
+ */
+ public function retrieveWithoutMagentoOrders(
+ int $accountId,
+ \DateTime $fromPurchaseDate,
+ \DateTime $toPurchaseDate
+ ): array {
+ $collection = $this->orderCollectionFactory
+ ->createWithWalmartChildMode()
+ ->addFieldToFilter(
+ WalmartOrderResource::COLUMN_PURCHASE_CREATE_DATE,
+ ['gteq' => $fromPurchaseDate->format('Y-m-d H:i:s')]
+ )
+ ->addFieldToFilter(
+ WalmartOrderResource::COLUMN_PURCHASE_CREATE_DATE,
+ ['lteq' => $toPurchaseDate->format('Y-m-d H:i:s')]
+ )
+ ->addFieldToFilter(
+ OrderResource::COLUMN_MAGENTO_ORDER_ID,
+ ['null' => true]
+ )
+ ->addFieldToFilter(
+ OrderResource::COLUMN_ACCOUNT_ID,
+ ['eq' => $accountId]
+ );
+
+ return array_values($collection->getItems());
+ }
+}
diff --git a/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php b/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php
index 8c44e34d1..5cdd87603 100644
--- a/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php
+++ b/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php
@@ -74,6 +74,7 @@ abstract class AbstractModel
'6.63.*',
'6.64.*',
'6.65.*',
+ '6.66.*',
];
/** @var \Ess\M2ePro\Model\ActiveRecord\Factory */
diff --git a/Setup/Update/Config.php b/Setup/Update/Config.php
index f7a17cf95..645bde0ae 100644
--- a/Setup/Update/Config.php
+++ b/Setup/Update/Config.php
@@ -373,6 +373,9 @@ public function getFeaturesList(): array
'EnableVatCalculationServiceForPolandAndSweden',
'AddEbayVideo',
],
+ 'y24_m08' => [
+ 'AddDateOfInvoiceSendingToAmazonOrder',
+ ],
];
}
diff --git a/Setup/Update/y24_m08/AddDateOfInvoiceSendingToAmazonOrder.php b/Setup/Update/y24_m08/AddDateOfInvoiceSendingToAmazonOrder.php
new file mode 100644
index 000000000..5b38db3b8
--- /dev/null
+++ b/Setup/Update/y24_m08/AddDateOfInvoiceSendingToAmazonOrder.php
@@ -0,0 +1,18 @@
+getTableModifier(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_ORDER)
+ ->addColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Order::COLUMN_DATE_OF_INVOICE_SENDING,
+ 'DATETIME',
+ 'NULL'
+ );
+ }
+}
diff --git a/Setup/Upgrade/v1_65_2__v1_66_0/Config.php b/Setup/Upgrade/v1_65_2__v1_66_0/Config.php
new file mode 100644
index 000000000..c25eb7b11
--- /dev/null
+++ b/Setup/Upgrade/v1_65_2__v1_66_0/Config.php
@@ -0,0 +1,15 @@
+
-
+
diff --git a/view/adminhtml/web/css/magento/form/datePicker.css b/view/adminhtml/web/css/magento/form/datePicker.css
new file mode 100644
index 000000000..7e7c23da2
--- /dev/null
+++ b/view/adminhtml/web/css/magento/form/datePicker.css
@@ -0,0 +1,7 @@
+._has-datepicker {
+ max-width: 19rem !important;
+}
+
+._has-datepicker + .ui-datepicker-trigger {
+ margin-left: -4.6rem !important;
+}
diff --git a/view/adminhtml/web/js/Amazon/Account.js b/view/adminhtml/web/js/Amazon/Account.js
index 16adc0328..8853e5914 100755
--- a/view/adminhtml/web/js/Amazon/Account.js
+++ b/view/adminhtml/web/js/Amazon/Account.js
@@ -1,5 +1,6 @@
define([
- 'M2ePro/Common'
+ 'M2ePro/Common',
+ 'mage/calendar'
], function() {
window.AmazonAccount = Class.create(Common, {
@@ -7,8 +8,6 @@ define([
// ---------------------------------------
initialize: function() {
- var self = this;
-
this.setValidationCheckRepetitionValue('M2ePro-account-title',
M2ePro.translator.translate('The specified Title is already used for other Account. Account Title must be unique.'),
'Account', 'title', 'id',
@@ -86,6 +85,26 @@ define([
return checkResult;
}, M2ePro.translator.translate('is_ready_for_document_generation'));
+
+ this.initMagentoOrdersCreateFromDate()
+ },
+
+ initMagentoOrdersCreateFromDate: function () {
+ const listingsCreateFromDate = jQuery('#magento_orders_listings_create_from_date');
+ listingsCreateFromDate.calendar({
+ showsTime: true,
+ dateFormat: 'yy-mm-dd',
+ timeFormat: 'HH:mm:00',
+ showButtonPanel: false,
+ }).datepicker('setDate', listingsCreateFromDate.val());
+
+ const listingsOtherCreateFromDate = jQuery('#magento_orders_listings_other_create_from_date');
+ listingsOtherCreateFromDate.calendar({
+ showsTime: true,
+ dateFormat: 'yy-mm-dd',
+ timeFormat: 'HH:mm:00',
+ showButtonPanel: false,
+ }).datepicker('setDate', listingsOtherCreateFromDate.val());
},
initObservers: function() {
@@ -278,8 +297,10 @@ define([
var self = AmazonAccountObj;
if ($('magento_orders_listings_mode').value == 1) {
+ $('magento_orders_listings_create_from_date_container').show();
$('magento_orders_listings_store_mode_container').show();
} else {
+ $('magento_orders_listings_create_from_date_container').hide();
$('magento_orders_listings_store_mode_container').hide();
$('magento_orders_listings_store_mode').value = M2ePro.php.constant('Ess_M2ePro_Model_Amazon_Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT');
}
@@ -302,9 +323,11 @@ define([
if ($('magento_orders_listings_other_mode').value == 1) {
$('magento_orders_listings_other_product_mode_container').show();
+ $('magento_orders_listings_other_create_from_date_container').show();
$('magento_orders_listings_other_store_id_container').show();
} else {
$('magento_orders_listings_other_product_mode_container').hide();
+ $('magento_orders_listings_other_create_from_date_container').hide();
$('magento_orders_listings_other_store_id_container').hide();
$('magento_orders_listings_other_product_mode').value = M2ePro.php.constant('Ess_M2ePro_Model_Amazon_Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE');
$('magento_orders_listings_other_store_id').value = '';
diff --git a/view/adminhtml/web/js/Ebay/Account.js b/view/adminhtml/web/js/Ebay/Account.js
index bf2ab29fd..f14150632 100644
--- a/view/adminhtml/web/js/Ebay/Account.js
+++ b/view/adminhtml/web/js/Ebay/Account.js
@@ -2,7 +2,8 @@ define([
'Magento_Ui/js/modal/modal',
'M2ePro/Common',
'extjs/ext-tree-checkbox',
- 'mage/adminhtml/form'
+ 'mage/adminhtml/form',
+ 'mage/calendar'
], function(modal) {
window.EbayAccount = Class.create(Common, {
@@ -83,6 +84,26 @@ define([
'If Yes is chosen, you must select at least one Attribute for Product Linking.'
)
);
+
+ this.initMagentoOrdersCreateFromDate();
+ },
+
+ initMagentoOrdersCreateFromDate: function () {
+ const listingsCreateFromDate = jQuery('#magento_orders_listings_create_from_date');
+ listingsCreateFromDate.calendar({
+ showsTime: true,
+ dateFormat: 'yy-mm-dd',
+ timeFormat: 'HH:mm:00',
+ showButtonPanel: false,
+ }).datepicker('setDate', listingsCreateFromDate.val());
+
+ const listingsOtherCreateFromDate = jQuery('#magento_orders_listings_other_create_from_date');
+ listingsOtherCreateFromDate.calendar({
+ showsTime: true,
+ dateFormat: 'yy-mm-dd',
+ timeFormat: 'HH:mm:00',
+ showButtonPanel: false,
+ }).datepicker('setDate', listingsOtherCreateFromDate.val());
},
initObservers: function() {
@@ -106,8 +127,6 @@ define([
.simulate('change');
}
- //$('ebayAccountEditTabs_listingOther').removeClassName('changed');
-
if ($('ebayAccountEditTabs_order')) {
$('magento_orders_listings_mode')
@@ -383,8 +402,10 @@ define([
var self = EbayAccountObj;
if ($('magento_orders_listings_mode').value == 1) {
+ $('magento_orders_listings_create_from_date_container').show();
$('magento_orders_listings_store_mode_container').show();
} else {
+ $('magento_orders_listings_create_from_date_container').hide();
$('magento_orders_listings_store_mode_container').hide();
$('magento_orders_listings_store_mode').value = M2ePro.php.constant('\\Ess\\M2ePro\\Model\\Ebay\\Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT');
}
@@ -406,9 +427,11 @@ define([
var self = EbayAccountObj;
if ($('magento_orders_listings_other_mode').value == 1) {
+ $('magento_orders_listings_other_create_from_date_container').show();
$('magento_orders_listings_other_product_mode_container').show();
$('magento_orders_listings_other_store_id_container').show();
} else {
+ $('magento_orders_listings_other_create_from_date_container').hide();
$('magento_orders_listings_other_product_mode_container').hide();
$('magento_orders_listings_other_store_id_container').hide();
$('magento_orders_listings_other_product_mode').value = M2ePro.php.constant('\\Ess\\M2ePro\\Model\\Ebay\\Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE');
diff --git a/view/adminhtml/web/js/Walmart/Account.js b/view/adminhtml/web/js/Walmart/Account.js
index c164dd80b..9bff407d2 100644
--- a/view/adminhtml/web/js/Walmart/Account.js
+++ b/view/adminhtml/web/js/Walmart/Account.js
@@ -1,5 +1,6 @@
define([
- 'M2ePro/Common'
+ 'M2ePro/Common',
+ 'mage/calendar'
], function() {
window.WalmartAccount = Class.create(Common, {
@@ -147,6 +148,24 @@ define([
}, M2ePro.translator.translate('M2E Pro was not able to get access to the Walmart Account'));
},
+ initMagentoOrdersCreateFromDate: function () {
+ const listingsCreateFromDate = jQuery('#magento_orders_listings_create_from_date');
+ listingsCreateFromDate.calendar({
+ showsTime: true,
+ dateFormat: 'yy-mm-dd',
+ timeFormat: 'HH:mm:00',
+ showButtonPanel: false,
+ }).datepicker('setDate', listingsCreateFromDate.val());
+
+ const listingsOtherCreateFromDate = jQuery('#magento_orders_listings_other_create_from_date');
+ listingsOtherCreateFromDate.calendar({
+ showsTime: true,
+ dateFormat: 'yy-mm-dd',
+ timeFormat: 'HH:mm:00',
+ showButtonPanel: false,
+ }).datepicker('setDate', listingsOtherCreateFromDate.val());
+ },
+
initObservers: function() {
$('marketplace_id')
.observe('change', WalmartAccountObj.changeMarketplace)
@@ -345,8 +364,10 @@ define([
var self = WalmartAccountObj;
if ($('magento_orders_listings_mode').value == 1) {
+ $('magento_orders_listings_create_from_date_container').show();
$('magento_orders_listings_store_mode_container').show();
} else {
+ $('magento_orders_listings_create_from_date_container').hide();
$('magento_orders_listings_store_mode_container').hide();
$('magento_orders_listings_store_mode').value = M2ePro.php.constant('\\Ess\\M2ePro\\Model\\Walmart\\Account::MAGENTO_ORDERS_LISTINGS_STORE_MODE_DEFAULT');
}
@@ -368,10 +389,12 @@ define([
var self = WalmartAccountObj;
if ($('magento_orders_listings_other_mode').value == 1) {
+ $('magento_orders_listings_other_create_from_date_container').show();
$('magento_orders_listings_other_product_mode_container').show();
$('magento_orders_listings_other_store_id_container').show();
} else {
$('magento_orders_listings_other_product_mode_container').hide();
+ $('magento_orders_listings_other_create_from_date_container').hide();
$('magento_orders_listings_other_store_id_container').hide();
$('magento_orders_listings_other_product_mode').value = M2ePro.php.constant('\\Ess\\M2ePro\\Model\\Walmart\\Account::MAGENTO_ORDERS_LISTINGS_OTHER_PRODUCT_MODE_IGNORE');
$('magento_orders_listings_other_store_id').value = '';