From 9276f12cbedecfdc663b797ebab04fdd7319ef73 Mon Sep 17 00:00:00 2001
From: M2E Pro
Date: Thu, 12 Sep 2024 15:03:04 +0000
Subject: [PATCH] 1.67.0 (FINAL RELEASE)
---
.../Amazon/Listing/AllItems/Grid.php | 16 +-
.../Listing/AutoAction/Mode/Category/Form.php | 36 +-
.../Listing/AutoAction/Mode/GlobalMode.php | 20 +-
.../Listing/AutoAction/Mode/Website.php | 29 +-
.../Amazon/Listing/Product/Add/SearchAsin.php | 4 -
.../Product/Template/ProductType/Grid.php | 20 +-
.../Variation/Manage/Tabs/Settings/Form.php | 6 +-
Block/Adminhtml/Amazon/Listing/View.php | 10 -
Block/Adminhtml/Amazon/Marketplace.php | 76 ----
.../Amazon/Marketplace/Edit/Form.php | 228 ----------
Block/Adminhtml/Amazon/Template/Grid.php | 6 -
.../Adminhtml/Amazon/Template/ProductType.php | 138 ------
.../Template/ProductType/ActionColumn.php | 60 +++
.../ProductType/Button/AddNewButton.php | 28 ++
.../ProductType/Button/RefreshAmazonData.php | 45 ++
.../Amazon/Template/ProductType/Edit.php | 139 +++---
.../Amazon/Template/ProductType/Edit/Data.php | 18 +-
.../ProductType/Edit/FieldTemplates.php | 15 +-
.../Amazon/Template/ProductType/Edit/Form.php | 16 +-
.../Amazon/Template/ProductType/Edit/Tabs.php | 32 +-
.../ProductType/Edit/Tabs/General.php | 79 +---
.../Edit/Tabs/General/SearchPopup.php | 11 -
.../ProductType/Edit/Tabs/Template.php | 16 +-
.../Amazon/Template/ProductType/Grid.php | 266 -----------
.../Amazon/Template/ProductType/HelpBlock.php | 35 ++
.../RefreshAmazonDataProgressBar.php | 13 +
Block/Adminhtml/General.php | 8 -
Block/Adminhtml/Walmart/Listing/Unmanaged.php | 2 +-
.../Wizard/MigrationToInnodb/Installation.php | 6 -
.../Amazon/Account/AfterGetToken.php | 5 -
.../AutoAction/GetProductTypesList.php | 47 +-
.../Adminhtml/Amazon/Listing/Create/Index.php | 26 +-
.../Product/Add/CheckSearchResults.php | 5 +-
.../Variation/Manage/SetGeneralIdOwner.php | 28 +-
.../Variation/Manage/SetVariationTheme.php | 29 +-
.../Adminhtml/Amazon/Marketplace/Index.php | 30 --
.../Amazon/Marketplace/RunSynchNow.php | 49 --
.../Adminhtml/Amazon/Marketplace/Save.php | 38 --
.../Marketplace/Sync/GetMarketplaceList.php | 37 ++
.../Marketplace/Sync/GetProductTypeList.php | 49 ++
.../Marketplace/Sync/MarketplaceLoader.php | 29 ++
.../Amazon/Marketplace/Sync/UpdateDetails.php | 38 ++
.../Marketplace/Sync/UpdateProductType.php | 40 ++
.../Marketplace/SynchGetExecutingInfo.php | 35 +-
.../Adminhtml/Amazon/Template/ProductType.php | 9 +-
.../Amazon/Template/ProductType/Delete.php | 39 +-
.../Amazon/Template/ProductType/Edit.php | 56 +--
.../ProductType/GetProductTypeInfo.php | 78 ++--
.../Amazon/Template/ProductType/Grid.php | 10 +-
.../Amazon/Template/ProductType/Index.php | 15 +-
.../Template/ProductType/IsUniqueTitle.php | 30 +-
.../Amazon/Template/ProductType/Save.php | 65 +--
.../ProductType/SearchProductTypePopup.php | 53 +--
.../General/IsMarketplaceEnabled.php | 6 -
.../AmazonMigrationToProductTypes/Accept.php | 40 +-
.../AmazonMigrationToProductTypes/Index.php | 6 -
.../Wizard/MigrationToInnodb/RunSynchNow.php | 39 +-
Helper/Component/Amazon.php | 15 -
Helper/Component/Amazon/ProductType.php | 426 +-----------------
Helper/Component/Amazon/Variation.php | 23 +-
Helper/Component/Amazon/Vocabulary.php | 8 +-
Helper/Module/Database/Structure.php | 16 -
Helper/Module/Database/Tables.php | 6 +
Helper/View/Amazon/Controller.php | 22 +-
.../Component/Parent/AbstractModel.php | 4 +-
Model/Amazon/Connector/DispatcherFactory.php | 9 +-
.../Marketplace/Get/InfoWithDetails.php | 28 ++
.../Connector/Marketplace/Get/Specifics.php | 58 ---
.../Amazon/Connector/ProductType/Get/Info.php | 35 ++
Model/Amazon/Connector/Protocol.php | 14 +-
Model/Amazon/Dashboard/Sales/Calculator.php | 20 +-
Model/Amazon/Dictionary/Marketplace.php | 72 +--
.../Dictionary/Marketplace/Repository.php | 56 +++
.../Amazon/Dictionary/MarketplaceFactory.php | 26 ++
.../Amazon/Dictionary/MarketplaceService.php | 127 ++++++
Model/Amazon/Dictionary/ProductType.php | 239 +++++-----
.../Dictionary/ProductType/Repository.php | 188 ++++++++
.../Amazon/Dictionary/ProductTypeFactory.php | 45 ++
.../Amazon/Dictionary/ProductTypeService.php | 105 +++++
Model/Amazon/Listing/Auto/Actions/Listing.php | 44 +-
Model/Amazon/Listing/Product.php | 42 +-
.../Action/Type/ListAction/Response.php | 9 +-
.../Listing/Product/Variation/Manager.php | 11 +-
.../Variation/Manager/AbstractModel.php | 32 +-
.../Variation/Manager/Type/Individual.php | 12 -
.../Manager/Type/Relation/ChildRelation.php | 9 -
.../Manager/Type/Relation/ParentRelation.php | 57 +--
.../Relation/ParentRelation/Processor.php | 16 +-
Model/Amazon/Marketplace.php | 8 -
Model/Amazon/Marketplace/Details.php | 106 -----
Model/Amazon/Marketplace/Issue/NotUpdated.php | 156 -------
.../Issue/ProductTypeOutOfDate.php | 100 ++++
.../Issue/ProductTypeOutOfDate/Cache.php | 42 ++
Model/Amazon/Marketplace/Repository.php | 104 +++++
Model/Amazon/Marketplace/Synchronization.php | 311 -------------
.../Marketplace/SynchronizationFactory.php | 25 -
Model/Amazon/Marketplace/Updater.php | 50 --
Model/Amazon/Order.php | 7 +
.../ProductType/AttributesValidator.php | 14 +-
.../ProductType/CategoryFinder/Repository.php | 70 ++-
Model/Amazon/Template/ProductType.php | 104 ++---
Model/Amazon/Template/ProductType/Builder.php | 24 +-
.../Template/ProductType/Repository.php | 282 ++++++++++++
Model/Amazon/Template/ProductTypeFactory.php | 14 +-
.../Order/Receive/Details/Responser.php | 2 +-
.../Receive/InvoiceDataReport/Responser.php | 92 ++--
Model/Ebay/Connector/Item/Responser.php | 3 +-
Model/Ebay/Dashboard/Sales/Calculator.php | 20 +-
.../Listing/Product/Variation/Resolver.php | 11 +-
Model/Exception/EntityNotFound.php | 9 +
.../Notification/Channel/Magento/Session.php | 16 +-
Model/M2ePro/Connector/Protocol.php | 14 +-
Model/Magento/Order/Updater.php | 133 ++----
Model/Marketplace.php | 4 +-
Model/MarketplaceFactory.php | 9 +-
.../Account/CollectionFactory.php | 5 +-
.../Component/Parent/AbstractModel.php | 10 +-
Model/ResourceModel/Amazon/Account.php | 1 +
.../Amazon/Dictionary/Marketplace.php | 19 +-
.../Dictionary/Marketplace/Collection.php | 24 +-
.../Marketplace/CollectionFactory.php | 5 +-
.../Amazon/Dictionary/ProductType.php | 24 +-
.../Dictionary/ProductType/Collection.php | 61 +--
.../ProductType/CollectionFactory.php | 5 +-
.../ResourceModel/Amazon/Listing/Product.php | 4 +-
Model/ResourceModel/Amazon/Marketplace.php | 1 -
.../Amazon/Template/ProductType.php | 34 +-
.../Template/ProductType/Collection.php | 126 +-----
.../ProductType/CollectionFactory.php | 9 +-
.../Template/ProductType/Grid/Collection.php | 134 ++++++
Model/ResourceModel/Marketplace.php | 26 +-
.../ResourceModel/Marketplace/Collection.php | 20 +-
.../Marketplace/CollectionFactory.php | 21 +-
.../Ui/Grid/SearchResultTrait.php | 41 ++
Model/Servicing/Task/Marketplaces.php | 144 +++---
Model/Setup/Installer.php | 101 ++---
Model/Setup/Upgrader.php | 1 +
Model/Synchronization/Log.php | 27 +-
Model/Synchronization/LogFactory.php | 20 +
Model/Walmart/Dashboard/Sales/Calculator.php | 20 +-
.../PreconditionsChecker/AbstractModel.php | 1 +
Setup/Update/Config.php | 16 +-
.../AddAmazonMarketplaceSaudiArabia.php | 2 +-
.../UpdateAmazonDictionaryProductType.php | 177 ++++++++
...sNewAsinAvailableFromAmazonMarketplace.php | 16 +
Setup/Upgrade/v1_66_2__v1_67_0/Config.php | 16 +
Ui/DataProvider.php | 33 ++
.../Component/Listing/Column/Marketplace.php | 41 ++
.../Component/Listing/Column/Title.php | 53 +++
.../Component/Listing/Select/Marketplace.php | 31 ++
composer.json | 2 +-
etc/di.xml | 12 +
etc/module.xml | 2 +-
...epro_amazon_template_producttype_index.xml | 27 ++
.../layout/m2epro_general_handler.xml | 11 +
...epro_amazon_template_product_type_grid.xml | 140 ++++++
.../web/js/Amazon/Listing/Create/General.js | 61 +--
.../web/js/Amazon/Listing/Product/Search.js | 5 -
.../web/js/Amazon/Marketplace/Sync.js | 172 +++++++
.../Amazon/MarketplaceUpdateSynchProgress.js | 34 --
.../web/js/MarketplaceBuildUpdate.js | 127 ------
161 files changed, 3469 insertions(+), 4206 deletions(-)
delete mode 100755 Block/Adminhtml/Amazon/Marketplace.php
delete mode 100755 Block/Adminhtml/Amazon/Marketplace/Edit/Form.php
delete mode 100644 Block/Adminhtml/Amazon/Template/ProductType.php
create mode 100644 Block/Adminhtml/Amazon/Template/ProductType/ActionColumn.php
create mode 100644 Block/Adminhtml/Amazon/Template/ProductType/Button/AddNewButton.php
create mode 100644 Block/Adminhtml/Amazon/Template/ProductType/Button/RefreshAmazonData.php
delete mode 100644 Block/Adminhtml/Amazon/Template/ProductType/Grid.php
create mode 100644 Block/Adminhtml/Amazon/Template/ProductType/HelpBlock.php
create mode 100644 Block/Adminhtml/Amazon/Template/ProductType/RefreshAmazonDataProgressBar.php
delete mode 100755 Controller/Adminhtml/Amazon/Marketplace/Index.php
delete mode 100755 Controller/Adminhtml/Amazon/Marketplace/RunSynchNow.php
delete mode 100755 Controller/Adminhtml/Amazon/Marketplace/Save.php
create mode 100644 Controller/Adminhtml/Amazon/Marketplace/Sync/GetMarketplaceList.php
create mode 100644 Controller/Adminhtml/Amazon/Marketplace/Sync/GetProductTypeList.php
create mode 100644 Controller/Adminhtml/Amazon/Marketplace/Sync/MarketplaceLoader.php
create mode 100644 Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateDetails.php
create mode 100644 Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateProductType.php
create mode 100644 Model/Amazon/Connector/Marketplace/Get/InfoWithDetails.php
delete mode 100644 Model/Amazon/Connector/Marketplace/Get/Specifics.php
create mode 100644 Model/Amazon/Connector/ProductType/Get/Info.php
create mode 100644 Model/Amazon/Dictionary/Marketplace/Repository.php
create mode 100644 Model/Amazon/Dictionary/MarketplaceFactory.php
create mode 100644 Model/Amazon/Dictionary/MarketplaceService.php
create mode 100644 Model/Amazon/Dictionary/ProductType/Repository.php
create mode 100644 Model/Amazon/Dictionary/ProductTypeFactory.php
create mode 100644 Model/Amazon/Dictionary/ProductTypeService.php
delete mode 100644 Model/Amazon/Marketplace/Details.php
delete mode 100644 Model/Amazon/Marketplace/Issue/NotUpdated.php
create mode 100644 Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate.php
create mode 100644 Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate/Cache.php
create mode 100644 Model/Amazon/Marketplace/Repository.php
delete mode 100644 Model/Amazon/Marketplace/Synchronization.php
delete mode 100644 Model/Amazon/Marketplace/SynchronizationFactory.php
delete mode 100644 Model/Amazon/Marketplace/Updater.php
create mode 100644 Model/Amazon/Template/ProductType/Repository.php
create mode 100644 Model/Exception/EntityNotFound.php
create mode 100644 Model/ResourceModel/Amazon/Template/ProductType/Grid/Collection.php
create mode 100644 Model/ResourceModel/Ui/Grid/SearchResultTrait.php
create mode 100644 Model/Synchronization/LogFactory.php
create mode 100644 Setup/Update/y24_m08/UpdateAmazonDictionaryProductType.php
create mode 100644 Setup/Update/y24_m09/RemoveIsNewAsinAvailableFromAmazonMarketplace.php
create mode 100644 Setup/Upgrade/v1_66_2__v1_67_0/Config.php
create mode 100644 Ui/DataProvider.php
create mode 100644 Ui/Template/ProductType/Component/Listing/Column/Marketplace.php
create mode 100644 Ui/Template/ProductType/Component/Listing/Column/Title.php
create mode 100644 Ui/Template/ProductType/Component/Listing/Select/Marketplace.php
create mode 100644 view/adminhtml/layout/m2epro_amazon_template_producttype_index.xml
create mode 100644 view/adminhtml/layout/m2epro_general_handler.xml
create mode 100644 view/adminhtml/ui_component/m2epro_amazon_template_product_type_grid.xml
create mode 100644 view/adminhtml/web/js/Amazon/Marketplace/Sync.js
delete mode 100644 view/adminhtml/web/js/Amazon/MarketplaceUpdateSynchProgress.js
delete mode 100755 view/adminhtml/web/js/MarketplaceBuildUpdate.js
diff --git a/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php b/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php
index f9929ef91..2395745ac 100644
--- a/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php
+++ b/Block/Adminhtml/Amazon/Listing/AllItems/Grid.php
@@ -344,25 +344,17 @@ private function getSubSelectForAmazonListingProductsWithTags(int $tagId): \Mage
{
$collection = $this->amazonProductCollectionFactory->create();
$collection->distinct(true);
- $collection->joinLeft(
- ['main_table_child' => $this->amazonProductResource->getMainTable()],
- 'main_table.listing_product_id = main_table_child.variation_parent_id'
- );
$collection->join(
['tag_rel' => $this->tagRelationResource->getMainTable()],
'main_table.listing_product_id = tag_rel.listing_product_id'
- . ' OR main_table_child.listing_product_id = tag_rel.listing_product_id'
- );
- $collection->join(
- ['tag' => $this->tagResource->getMainTable()],
- 'tag.id = tag_rel.tag_id'
);
- $collection->getSelect()->where('main_table.variation_parent_id IS NULL');
- $collection->getSelect()->where('tag.id = ?', $tagId);
+ $collection->getSelect()->where('tag_rel.tag_id = ?', $tagId);
$collection->getSelect()->reset('columns');
- $collection->getSelect()->columns('main_table.listing_product_id');
+ $collection->getSelect()->columns(
+ new \Zend_Db_Expr('IFNULL(main_table.variation_parent_id, main_table.listing_product_id)')
+ );
return $collection->getSelect();
}
diff --git a/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Category/Form.php b/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Category/Form.php
index 27c861418..4f466bcb4 100755
--- a/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Category/Form.php
+++ b/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Category/Form.php
@@ -1,38 +1,21 @@
amazonTemplateProductTypeRepository = $amazonTemplateProductTypeRepository;
parent::__construct($context, $registry, $formFactory, $dataHelper, $data);
- $this->amazonProductTypeCollectionFactory = $amazonProductTypeCollectionFactory;
}
public function _construct()
@@ -45,8 +28,6 @@ public function _construct()
// ---------------------------------------
}
- //########################################
-
protected function _prepareForm()
{
$form = $this->_formFactory->create([
@@ -155,16 +136,15 @@ protected function _prepareForm()
]
);
- $collection = $this->amazonProductTypeCollectionFactory->create();
- $collection->appendFilterMarketplaceId($this->getListing()->getMarketplaceId());
-
- $productTypeTemplates = $collection->getData();
+ $productTypeTemplates = $this->amazonTemplateProductTypeRepository->findByMarketplaceId(
+ $this->getListing()->getMarketplaceId()
+ );
$options = [['label' => '', 'value' => '', 'attrs' => ['class' => 'empty']]];
foreach ($productTypeTemplates as $template) {
$options[] = [
- 'label' => $this->_escaper->escapeHtml($template['title']),
- 'value' => $template['id'],
+ 'label' => $this->_escaper->escapeHtml($template->getTitle()),
+ 'value' => $template->getId(),
];
}
diff --git a/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/GlobalMode.php b/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/GlobalMode.php
index 76989975c..1db62f02a 100755
--- a/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/GlobalMode.php
+++ b/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/GlobalMode.php
@@ -2,26 +2,23 @@
namespace Ess\M2ePro\Block\Adminhtml\Amazon\Listing\AutoAction\Mode;
-use Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory as AmazonProductTypeCollectionFactory;
-
class GlobalMode extends \Ess\M2ePro\Block\Adminhtml\Listing\AutoAction\Mode\AbstractGlobalMode
{
/** @var \Ess\M2ePro\Helper\Module\Support */
private $supportHelper;
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory */
- private $amazonProductTypeCollectionFactory;
+ private \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $amazonTemplateProductTypeRepository;
public function __construct(
+ \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $amazonTemplateProductTypeRepository,
\Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Ess\M2ePro\Helper\Module\Support $supportHelper,
\Ess\M2ePro\Helper\Data $dataHelper,
- AmazonProductTypeCollectionFactory $amazonProductTypeCollectionFactory,
array $data = []
) {
$this->supportHelper = $supportHelper;
- $this->amazonProductTypeCollectionFactory = $amazonProductTypeCollectionFactory;
+ $this->amazonTemplateProductTypeRepository = $amazonTemplateProductTypeRepository;
parent::__construct($context, $registry, $formFactory, $dataHelper, $data);
}
@@ -156,16 +153,15 @@ protected function _prepareForm()
]
);
- $collection = $this->amazonProductTypeCollectionFactory->create();
- $collection->appendFilterMarketplaceId($this->getListing()->getMarketplaceId());
-
- $productTypesTemplates = $collection->getData();
+ $productTypesTemplates = $this->amazonTemplateProductTypeRepository->findByMarketplaceId(
+ $this->getListing()->getMarketplaceId(),
+ );
$options = [['label' => '', 'value' => '', 'attrs' => ['class' => 'empty']]];
foreach ($productTypesTemplates as $template) {
$options[] = [
- 'label' => $this->_escaper->escapeHtml($template['title']),
- 'value' => $template['id']
+ 'label' => $this->_escaper->escapeHtml($template->getTitle()),
+ 'value' => $template->getId(),
];
}
diff --git a/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Website.php b/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Website.php
index 977bb9542..97d1bec11 100755
--- a/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Website.php
+++ b/Block/Adminhtml/Amazon/Listing/AutoAction/Mode/Website.php
@@ -14,21 +14,10 @@ class Website extends \Ess\M2ePro\Block\Adminhtml\Listing\AutoAction\Mode\Abstra
{
/** @var \Ess\M2ePro\Helper\Module\Support */
private $supportHelper;
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory */
- private $amazonProductTypeCollectionFactory;
+ private \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $amazonTemplateProductTypeRepository;
- /**
- * @param \Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Framework\Data\FormFactory $formFactory
- * @param \Ess\M2ePro\Helper\Module\Support $supportHelper
- * @param \Ess\M2ePro\Helper\Data $dataHelper
- * @param \Ess\M2ePro\Helper\Data\GlobalData $globalDataHelper
- * @param \Ess\M2ePro\Helper\Magento\Store $magentoStoreHelper
- * @param AmazonProductTypeCollectionFactory $amazonProductTypeCollectionFactory
- * @param array $data
- */
public function __construct(
+ \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $amazonTemplateProductTypeRepository,
\Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
@@ -36,10 +25,10 @@ public function __construct(
\Ess\M2ePro\Helper\Data $dataHelper,
\Ess\M2ePro\Helper\Data\GlobalData $globalDataHelper,
\Ess\M2ePro\Helper\Magento\Store $magentoStoreHelper,
- AmazonProductTypeCollectionFactory $amazonProductTypeCollectionFactory,
array $data = []
) {
$this->supportHelper = $supportHelper;
+ $this->amazonTemplateProductTypeRepository = $amazonTemplateProductTypeRepository;
parent::__construct(
$context,
$registry,
@@ -49,7 +38,6 @@ public function __construct(
$magentoStoreHelper,
$data
);
- $this->amazonProductTypeCollectionFactory = $amazonProductTypeCollectionFactory;
}
protected function _prepareForm()
@@ -158,16 +146,15 @@ protected function _prepareForm()
]
);
- $collection = $this->amazonProductTypeCollectionFactory->create();
- $collection->appendFilterMarketplaceId($this->getListing()->getMarketplaceId());
-
- $productTypesTemplates = $collection->getData();
+ $productTypesTemplates = $this->amazonTemplateProductTypeRepository->findByMarketplaceId(
+ $this->getListing()->getMarketplaceId(),
+ );
$options = [['label' => '', 'value' => '', 'attrs' => ['class' => 'empty']]];
foreach ($productTypesTemplates as $template) {
$options[] = [
- 'label' => $this->_escaper->escapeHtml($template['title']),
- 'value' => $template['id']
+ 'label' => $this->_escaper->escapeHtml($template->getTitle()),
+ 'value' => $template->getId(),
];
}
diff --git a/Block/Adminhtml/Amazon/Listing/Product/Add/SearchAsin.php b/Block/Adminhtml/Amazon/Listing/Product/Add/SearchAsin.php
index f4b29ee92..1aae76ea9 100644
--- a/Block/Adminhtml/Amazon/Listing/Product/Add/SearchAsin.php
+++ b/Block/Adminhtml/Amazon/Listing/Product/Add/SearchAsin.php
@@ -157,9 +157,6 @@ protected function _toHtml()
$autoMapAsinSearchProducts = __('Search %product_title% Product(s) on Amazon.');
$autoMapAsinProgressTitle = __('Automatic Assigning ASIN/ISBN to Item(s)');
$autoMapAsinErrorMessage = __('Server is currently unavailable. Please try again later.');
- $newAsinNotAvailable = $this->__(
- 'The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.'
- );
$notSynchronizedMarketplace = __(
'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
) . ' ' . __('Press "Save And Update" Button after redirect on Marketplace Page.');
@@ -176,7 +173,6 @@ protected function _toHtml()
'sending_data_message' => $sendingDataToAmazonMessage,
- 'new_asin_not_available' => $newAsinNotAvailable,
'not_synchronized_marketplace' => $notSynchronizedMarketplace,
'enter_productSearch_query' => $enterProductSearchQueryMessage,
diff --git a/Block/Adminhtml/Amazon/Listing/Product/Template/ProductType/Grid.php b/Block/Adminhtml/Amazon/Listing/Product/Template/ProductType/Grid.php
index 6ef30104c..909275e04 100644
--- a/Block/Adminhtml/Amazon/Listing/Product/Template/ProductType/Grid.php
+++ b/Block/Adminhtml/Amazon/Listing/Product/Template/ProductType/Grid.php
@@ -24,26 +24,17 @@ class Grid extends \Ess\M2ePro\Block\Adminhtml\Magento\Grid\AbstractGrid
private $checkNewAsinAccepted;
/** @var \Ess\M2ePro\Helper\Data */
private $dataHelper;
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory */
- private $productTypeCollectionFactory;
+ private \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $amazonTemplateProductTypeRepository;
- /**
- * @param ProductTypeCollectionFactory $productTypeCollectionFactory
- * @param \Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context
- * @param \Magento\Backend\Helper\Data $backendHelper
- * @param \Ess\M2ePro\Helper\Data $dataHelper
- * @param array $data
- */
public function __construct(
- \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory $productTypeCollectionFactory,
+ \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $amazonTemplateProductTypeRepository,
\Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context,
\Magento\Backend\Helper\Data $backendHelper,
\Ess\M2ePro\Helper\Data $dataHelper,
array $data = []
) {
$this->dataHelper = $dataHelper;
- $this->productTypeCollectionFactory = $productTypeCollectionFactory;
-
+ $this->amazonTemplateProductTypeRepository = $amazonTemplateProductTypeRepository;
parent::__construct($context, $backendHelper, $data);
}
@@ -155,8 +146,9 @@ protected function _prepareCollection()
{
$this->setNoTemplatesText();
- $collection = $this->productTypeCollectionFactory->create();
- $collection->appendFilterMarketplaceId($this->getMarketplaceId());
+ $collection = $this->amazonTemplateProductTypeRepository->getCollectionForGrid();
+ $collection->getSelect()
+ ->where('adpt.marketplace_id = ?', $this->getMarketplaceId());
$this->setCollection($collection);
diff --git a/Block/Adminhtml/Amazon/Listing/Product/Variation/Manage/Tabs/Settings/Form.php b/Block/Adminhtml/Amazon/Listing/Product/Variation/Manage/Tabs/Settings/Form.php
index 4c6a148d0..91bc14e38 100644
--- a/Block/Adminhtml/Amazon/Listing/Product/Variation/Manage/Tabs/Settings/Form.php
+++ b/Block/Adminhtml/Amazon/Listing/Product/Variation/Manage/Tabs/Settings/Form.php
@@ -928,11 +928,7 @@ public function getChannelThemes()
$marketPlaceId = $this->getListingProduct()->getListing()->getMarketplaceId();
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Details $detailsModel */
- $detailsModel = $this->modelFactory->getObject('Amazon_Marketplace_Details');
- $detailsModel->setMarketplaceId($marketPlaceId);
-
- $channelThemes = $detailsModel->getVariationThemes($productTypeTemplate->getNick());
+ $channelThemes = $productTypeTemplate->getDictionary()->getVariationThemes();
$themesUsageData = $this->variationHelper->getThemesUsageData();
$usedThemes = [];
diff --git a/Block/Adminhtml/Amazon/Listing/View.php b/Block/Adminhtml/Amazon/Listing/View.php
index 57abfb096..60b83bc78 100644
--- a/Block/Adminhtml/Amazon/Listing/View.php
+++ b/Block/Adminhtml/Amazon/Listing/View.php
@@ -232,8 +232,6 @@ public function getGridHtml(): string
);
$this->jsUrl->add($this->getUrl('*/listing_mapping/remap'), 'listing_mapping/remap');
- $this->jsUrl->add($this->getUrl('*/amazon_marketplace/index'), 'marketplaceSynchUrl');
-
$this->jsUrl->add(
$this->getUrl('*/listing/saveListingAdditionalData', [
'id' => $this->listing['id'],
@@ -262,9 +260,6 @@ public function getGridHtml(): string
$this->listing->getMarketplace()->getChildObject()->getData()
)
);
- $isNewAsinAvailable = \Ess\M2ePro\Helper\Json::encode(
- $this->listing->getMarketplace()->getChildObject()->isNewAsinAvailable()
- );
$temp = $this->sessionDataHelper->getValue('products_ids_for_list', true);
$productsIdsForList = empty($temp) ? '' : $temp;
@@ -311,9 +306,6 @@ public function getGridHtml(): string
$autoMapAsinSearchProducts = $this->__('Search %product_title% Product(s) on Amazon.');
$autoMapAsinProgressTitle = $this->__('Automatic Assigning ASIN/ISBN to Item(s)');
$autoMapAsinErrorMessage = $this->__('Server is currently unavailable. Please try again later.');
- $newAsinNotAvailable = $this->__(
- 'The new ASIN/ISBN creation functionality is not available in %code% Marketplace yet.'
- );
$notSynchronizedMarketplace = $this->__(
'In order to use New ASIN/ISBN functionality, please re-synchronize Marketplace data.'
) . ' ' . $this->__('Press "Save And Update" Button after redirect on Marketplace Page.');
@@ -389,7 +381,6 @@ public function getGridHtml(): string
'automap_asin_progress_title' => $autoMapAsinProgressTitle,
'automap_error_message' => $autoMapAsinErrorMessage,
- 'new_asin_not_available' => $newAsinNotAvailable,
'not_synchronized_marketplace' => $notSynchronizedMarketplace,
'no_variations_left' => $noVariationsLeftText,
@@ -431,7 +422,6 @@ public function getGridHtml(): string
M2ePro.customData.ignoreListings = '{$ignoreListings}';
M2ePro.customData.marketplace = {$marketplace};
- M2ePro.customData.isNewAsinAvailable = {$isNewAsinAvailable};
ListingGridObj = new AmazonListingViewGrid(
'{$gridId}',
diff --git a/Block/Adminhtml/Amazon/Marketplace.php b/Block/Adminhtml/Amazon/Marketplace.php
deleted file mode 100755
index 568ab7a08..000000000
--- a/Block/Adminhtml/Amazon/Marketplace.php
+++ /dev/null
@@ -1,76 +0,0 @@
-_controller = 'adminhtml_amazon_marketplace';
- // ---------------------------------------
-
- $this->removeButton('save');
- $this->removeButton('reset');
- $this->removeButton('back');
-
- // ---------------------------------------
- $this->addButton('run_update_all', [
- 'label' => __('Update All Now'),
- 'onclick' => 'MarketplaceObj.updateAction()',
- 'class' => 'save update_all_marketplace primary',
- ]);
- // ---------------------------------------
-
- // ---------------------------------------
- $this->addButton('run_synch_now', [
- 'label' => __('Save'),
- 'onclick' => 'MarketplaceObj.saveAction();',
- 'class' => 'save save_and_update_marketplaces primary',
- ]);
- // ---------------------------------------
- }
-
- //########################################
-
- protected function _prepareLayout()
- {
- $this->appendHelpBlock([
- 'content' => __(
- 'This Page contains a list of Amazon international Marketplaces
- where you can sell your Items.
- Enable only those Marketplaces that you want to sell on.
- High number of enabled Marketplaces will take longer to process the necessary data.
'
- ),
- ]);
-
- return parent::_prepareLayout();
- }
-
- protected function _toHtml()
- {
- return
- '
' .
- '' .
- parent::_toHtml() .
- '
';
- }
-
- //########################################
-}
diff --git a/Block/Adminhtml/Amazon/Marketplace/Edit/Form.php b/Block/Adminhtml/Amazon/Marketplace/Edit/Form.php
deleted file mode 100755
index 9bf03d6ab..000000000
--- a/Block/Adminhtml/Amazon/Marketplace/Edit/Form.php
+++ /dev/null
@@ -1,228 +0,0 @@
-dataHelper = $dataHelper;
- $this->amazonHelper = $amazonHelper;
- parent::__construct($context, $registry, $formFactory, $data);
- }
-
- public function _construct()
- {
- parent::_construct();
- $this->css->addFile('marketplace/form.css');
- }
-
- protected function _prepareForm()
- {
- $this->prepareData();
-
- $form = $this->_formFactory->create(
- ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
- );
-
- foreach ($this->groups as $group) {
- $fieldset = $form->addFieldset(
- 'marketplaces_group_' . $group['id'],
- ['legend' => $this->__($group['title'])]
- );
-
- foreach ($group['marketplaces'] as $marketplace) {
- $afterElementHtml =
- 'getStatus() == \Ess\M2ePro\Model\Marketplace::STATUS_DISABLE &&
- $afterElementHtml .= ' style="display: none;"';
- $afterElementHtml .= '">';
-
- $afterElementHtml .= $this->getLayout()
- ->createBlock(\Magento\Backend\Block\Widget\Button::class)
- ->setData([
- 'label' => $this->__('Update Now'),
- 'onclick' => 'MarketplaceObj.runSingleSynchronization(this)',
- 'class' => 'run_single_button primary'
- ])->toHtml();
- $afterElementHtml .= '
';
-
- $afterElementHtml .= <<
- {$this->__('Waiting')}
-
- {$this->__('Processing')}
-
- {$this->__('Completed')}
-
- {$this->__('Error')}
-
- {$this->__('Skipped')}
-
- {$marketplace['instance']->getTitle()}
-
-
-
-HTML;
-
- $selectData = [
- 'label' => $this->__($marketplace['instance']->getData('title')),
- 'style' => 'display: inline-block;',
- 'after_element_html' => $afterElementHtml,
- ];
-
- if ($marketplace['params']['locked']) {
- $selectData['disabled'] = 'disabled';
- $selectData['values'] = [
- \Ess\M2ePro\Model\Marketplace::STATUS_ENABLE => $this->__('Enabled') . ' - ' .
- $this->__('Used in Account(s)'),
- ];
- $selectData['value'] = \Ess\M2ePro\Model\Marketplace::STATUS_ENABLE;
- } else {
- $selectData['values'] = [
- \Ess\M2ePro\Model\Marketplace::STATUS_DISABLE => $this->__('Disabled'),
- \Ess\M2ePro\Model\Marketplace::STATUS_ENABLE => $this->__('Enabled'),
- ];
- $selectData['value'] = $marketplace['instance']->getStatus();
- }
-
- $selectData['name'] = 'status_' . $marketplace['instance']->getId();
- $selectData['class'] = 'marketplace_status_select';
- $selectData['note'] = $marketplace['instance']->getUrl();
-
- $fieldset->addField(
- 'status_' . $marketplace['instance']->getId(),
- self::SELECT,
- $selectData
- )->addCustomAttribute('marketplace_id', $marketplace['instance']->getId())
- ->addCustomAttribute('component_name', \Ess\M2ePro\Helper\Component\Amazon::NICK)
- ->addCustomAttribute('component_title', $this->amazonHelper->getTitle())
- ->addCustomAttribute('onchange', 'MarketplaceObj.changeStatus(this);');
- }
- }
-
- $form->setUseContainer(true);
- $this->setForm($form);
-
- return $this;
- }
-
- protected function prepareData()
- {
- // ---------------------------------------
- /** @var \Ess\M2ePro\Model\Marketplace $tempMarketplaces */
- $tempMarketplaces = $this->parentFactory->getObject(\Ess\M2ePro\Helper\Component\Amazon::NICK, 'Marketplace')
- ->getCollection()
- ->setOrder('group_title', 'ASC')
- ->setOrder('sorder', 'ASC')
- ->setOrder('title', 'ASC')
- ->getItems();
-
- $storedStatuses = [];
- $groups = [];
- $idGroup = 1;
-
- $groupOrder = [
- 'america' => 'America',
- 'europe' => 'Europe',
- 'asia_pacific' => 'Asia / Pacific',
- ];
-
- foreach ($groupOrder as $key => $groupOrderTitle) {
- $groups[$key] = [
- 'id' => $idGroup++,
- 'title' => $groupOrderTitle,
- 'marketplaces' => [],
- ];
-
- foreach ($tempMarketplaces as $tempMarketplace) {
- if ($groupOrderTitle != $tempMarketplace->getGroupTitle()) {
- continue;
- }
-
- $isLocked = (bool)$this->parentFactory
- ->getObject(\Ess\M2ePro\Helper\Component\Amazon::NICK, 'Account')->getCollection()
- ->addFieldToFilter('marketplace_id', $tempMarketplace->getId())
- ->getSize();
-
- $storedStatuses[] = [
- 'marketplace_id' => $tempMarketplace->getId(),
- 'status' => $tempMarketplace->getStatus(),
- ];
-
- /** @var \Ess\M2ePro\Model\Marketplace $tempMarketplace */
- $marketplace = [
- 'instance' => $tempMarketplace,
- 'params' => ['locked' => $isLocked],
- ];
-
- $groups[$key]['marketplaces'][] = $marketplace;
- }
- }
-
- $this->groups = $groups;
- $this->storedStatuses = $storedStatuses;
- // ---------------------------------------
- }
-
- protected function _toHtml()
- {
- $this->jsUrl->addUrls([
- 'formSubmit' => $this->getUrl('*/amazon_marketplace/save'),
- 'logViewUrl' => $this->getUrl(
- '*/amazon_synchronization_log/index',
- ['back' => $this->dataHelper->makeBackUrlParam('*/amazon_synchronization/index')]
- ),
- 'runSynchNow' => $this->getUrl('*/amazon_marketplace/runSynchNow'),
- ]);
-
- $this->jsUrl->addUrls($this->dataHelper->getControllerActions('Amazon\Marketplace'));
-
- $storedStatuses = \Ess\M2ePro\Helper\Json::encode($this->storedStatuses);
- $this->js->addOnReadyJs(
- <<amazonHelper = $amazonHelper;
- $this->supportHelper = $supportHelper;
- parent::__construct($context, $data);
- }
-
- /**
- * @return void
- */
- public function _construct()
- {
- parent::_construct();
-
- $this->setId('amazonTemplateProductType');
- $this->_controller = 'adminhtml_amazon_template_productType';
-
- $this->buttonList->remove('back');
- $this->buttonList->remove('reset');
- $this->buttonList->remove('delete');
- $this->buttonList->remove('save');
- $this->buttonList->remove('edit');
-
- $this->buttonList->update('add', 'label', $this->__('Add Product Type'));
- $this->buttonList->update('add', 'onclick', '');
-
- $this->addButton('run_update_all', [
- 'label' => __('Refresh Amazon Data'),
- 'onclick' => 'MarketplaceObj.updateAction()',
- 'class' => 'save update_all_marketplace primary',
- ]);
- }
-
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType|\Magento\Backend\Block\Widget\Grid\Container
- */
- protected function _prepareLayout()
- {
- $content = $this->__(
- 'The page displays Amazon Product Types that are currently used in your M2E Pro Listings.
-
- Here you can add a new Product Type, edit or delete existing ones.
- Learn how to manage Amazon Product Types in
- this article .
- To ensure that you have the most up-to-date Product Type information in your M2E Pro,
- simply click the Refresh Amazon Data button.
- This will synchronize any changes made to Product Types on Amazon. Whether certain specifics have been
- added or removed, you will see the updated information after the data is refreshed.',
- $this->supportHelper->getDocumentationArticleUrl('amazon-product-type')
- );
-
- $this->appendHelpBlock(
- [
- 'content' => $content,
- ]
- );
-
- $url = $this->getUrl('*/amazon_template_productType/edit');
- $this->addButton(
- 'add',
- [
- 'label' => $this->__('Add Product Type'),
- 'onclick' => 'setLocation(\'' . $url . '\')',
- 'class' => 'action-primary',
- 'button_class' => '',
- ]
- );
-
- return parent::_prepareLayout();
- }
- public function _toHtml()
- {
- $this->jsUrl->addUrls([
- 'runSynchNow' => $this->getUrl('*/amazon_marketplace/runSynchNow'),
- 'amazon_marketplace/synchGetExecutingInfo' => $this->getUrl(
- '*/amazon_marketplace/synchGetExecutingInfo'
- ),
- 'logViewUrl' => $this->getUrl('*/amazon_synchronization_log/index'),
- ]);
-
- $storedStatuses = [];
- foreach ($this->amazonHelper->getMarketplacesListByActiveAccounts() as $marketplaceId => $marketplaceTitle) {
- $storedStatuses[] = [
- 'marketplace_id' => $marketplaceId,
- 'title' => $marketplaceTitle,
- ];
- }
- $storedStatuses = \Ess\M2ePro\Helper\Json::encode($storedStatuses);
-
- $this->js->addOnReadyJs(
- <<' .
- '' .
- parent::_toHtml() .
- '
';
- }
-}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/ActionColumn.php b/Block/Adminhtml/Amazon/Template/ProductType/ActionColumn.php
new file mode 100644
index 000000000..2f3984a06
--- /dev/null
+++ b/Block/Adminhtml/Amazon/Template/ProductType/ActionColumn.php
@@ -0,0 +1,60 @@
+url = $url;
+ }
+
+ public function prepareDataSource(array $dataSource): array
+ {
+ if (!isset($dataSource['data']['items'])) {
+ return $dataSource;
+ }
+
+ $name = $this->getData('name');
+ foreach ($dataSource['data']['items'] as &$item) {
+ $buttons = [
+ 'enable' => [
+ 'href' => $this->url->getUrl(
+ 'm2epro/amazon_template_productType/edit',
+ [
+ 'id' => $item['id'],
+ 'back' => 1,
+ ],
+ ),
+ 'label' => __('Edit'),
+ ],
+ 'delete' => [
+ 'href' => $this->url->getUrl(
+ 'm2epro/amazon_template_productType/delete',
+ [
+ 'id' => $item['id'],
+ ],
+ ),
+ 'confirm' => [
+ 'message' => 'Are you sure?',
+ ],
+ 'label' => __('Delete'),
+ ],
+ ];
+
+ $item[$name] = $buttons;
+ }
+
+ return $dataSource;
+ }
+}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Button/AddNewButton.php b/Block/Adminhtml/Amazon/Template/ProductType/Button/AddNewButton.php
new file mode 100644
index 000000000..8825f7735
--- /dev/null
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Button/AddNewButton.php
@@ -0,0 +1,28 @@
+urlBuilder = $urlBuilder;
+ }
+
+ public function getButtonData(): array
+ {
+ $url = $this->urlBuilder->getUrl('*/amazon_template_productType/edit');
+
+ return [
+ 'label' => __('Add Product Type'),
+ 'class' => 'action-primary',
+ 'on_click' => 'setLocation(\'' . $url . '\')',
+ 'sort_order' => 4,
+ ];
+ }
+}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Button/RefreshAmazonData.php b/Block/Adminhtml/Amazon/Template/ProductType/Button/RefreshAmazonData.php
new file mode 100644
index 000000000..5476e49f9
--- /dev/null
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Button/RefreshAmazonData.php
@@ -0,0 +1,45 @@
+urlBuilder = $urlBuilder;
+ }
+
+ public function getButtonData(): array
+ {
+ return [
+ 'label' => __('Refresh Amazon Data'),
+ 'class' => 'save update_all_marketplace primary',
+ 'on_click' => '',
+ 'sort_order' => 4,
+ 'data_attribute' => [
+ 'mage-init' => [
+ 'M2ePro/Amazon/Marketplace/Sync' => [
+ 'url_for_get_marketplaces' => $this->urlBuilder->getUrl(
+ '*/amazon_marketplace_sync/getMarketplaceList'
+ ),
+ 'url_for_update_marketplaces_details' => $this->urlBuilder->getUrl(
+ '*/amazon_marketplace_sync/updateDetails'
+ ),
+ 'url_for_get_product_types' => $this->urlBuilder->getUrl(
+ '*/amazon_marketplace_sync/getProductTypeList'
+ ),
+ 'url_for_update_product_type' => $this->urlBuilder->getUrl(
+ '*/amazon_marketplace_sync/updateProductType'
+ ),
+ 'progress_bar_el_id' => 'product_type_progress_bar',
+ ],
+ ],
+ ],
+ ];
+ }
+}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit.php
index ea1924dc4..334946d08 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit.php
@@ -1,97 +1,24 @@
dataHelper = $dataHelper;
- $this->globalDataHelper = $globalDataHelper;
$this->productType = $productType;
parent::__construct($context, $data);
}
- protected function _beforeToHtml()
- {
- $this->setDataObject($this->productType);
-
- $changeAttributeMappingConfirmMessage = __(
- <<New Magento attributes have been mapped to some of the Specifics.
-Do you want to save these new Attribute mappings as the default ones?
-Once confirmed, the records in Amazon > Configurations > Settings > Attribute Mapping
-will be updated accordingly.
-TEXT
- );
-
- $this->jsTranslator->addTranslations([
- 'Do not show any more' => $this->__('Do not show this message anymore'),
- 'Save Product Type Settings' => $this->__('Save Product Type Settings'),
- 'Search Product Type' => __('Search Product Type'),
- 'Change Attribute Mapping Confirm Message' => $changeAttributeMappingConfirmMessage,
- ]);
-
- $this->jsUrl->add(
- $this->_urlBuilder->getUrl('*/*/updateAttributeMapping'),
- 'update_attribute_mappings'
- );
-
- $this->jsPhp->addConstants(
- $this->dataHelper->getClassConstants(\Ess\M2ePro\Model\Amazon\Template\ProductType::class)
- );
-
- return parent::_beforeToHtml();
- }
-
- protected function getSaveConfirmationText($id = null)
- {
- $saveConfirmation = '';
-
- if ($id === null && $this->productType !== null) {
- $id = $this->productType->getId();
- }
-
- if ($id) {
- $saveConfirmation = $this->dataHelper->escapeJs(
- $this->__(
- '
-Note: All changes you have made will be automatically applied to all M2E Pro Listings where this
-Product Type is used.
- '
- )
- );
- }
-
- return $saveConfirmation;
- }
-
- public function _construct()
+ public function _construct(): void
{
parent::_construct();
@@ -115,7 +42,7 @@ public function _construct()
$this->buttonList->add(
'delete',
[
- 'label' => $this->__('Delete'),
+ 'label' => __('Delete'),
'onclick' => 'AmazonTemplateProductTypeObj.deleteClick()',
'class' => 'delete M2ePro_delete_button primary',
]
@@ -125,7 +52,7 @@ public function _construct()
if ($isSaveAndClose) {
$saveButtons = [
'id' => 'save_and_close',
- 'label' => $this->__('Save And Close'),
+ 'label' => __('Save And Close'),
'class' => 'add',
'button_class' => '',
'onclick' => 'AmazonTemplateProductTypeObj.saveAndCloseClick('
@@ -134,7 +61,7 @@ public function _construct()
'class_name' => \Ess\M2ePro\Block\Adminhtml\Magento\Button\SplitButton::class,
'options' => [
'save' => [
- 'label' => $this->__('Save And Continue Edit'),
+ 'label' => __('Save And Continue Edit'),
'onclick' => 'AmazonTemplateProductTypeObj.saveAndEditClick('
. '\'\','
. '\'' . $this->getSaveConfirmationText() . '\''
@@ -146,7 +73,7 @@ public function _construct()
} else {
$saveButtons = [
'id' => 'save_and_continue',
- 'label' => $this->__('Save And Continue Edit'),
+ 'label' => __('Save And Continue Edit'),
'class' => 'add',
'onclick' => 'AmazonTemplateProductTypeObj.saveAndEditClick('
. '\'\','
@@ -155,7 +82,7 @@ public function _construct()
'class_name' => \Ess\M2ePro\Block\Adminhtml\Magento\Button\SplitButton::class,
'options' => [
'save' => [
- 'label' => $this->__('Save And Back'),
+ 'label' => __('Save And Back'),
'onclick' => 'AmazonTemplateProductTypeObj.saveClick('
. '\'\','
. '\'' . $this->getSaveConfirmationText() . '\''
@@ -172,8 +99,54 @@ public function _construct()
$this->css->addFile('amazon/product_type.css');
}
+ protected function _beforeToHtml()
+ {
+ $this->setDataObject($this->productType);
+
+ $changeAttributeMappingConfirmMessage = __(
+ 'New Magento attributes have been mapped to some of the Specifics.
+Do you want to save these new Attribute mappings as the default ones?
+Once confirmed, the records in Amazon > Configurations > Settings > Attribute Mapping
+will be updated accordingly.
'
+ );
+
+ $this->jsTranslator->addTranslations([
+ 'Do not show any more' => __('Do not show this message anymore'),
+ 'Save Product Type Settings' => __('Save Product Type Settings'),
+ 'Search Product Type' => __('Search Product Type'),
+ 'Change Attribute Mapping Confirm Message' => $changeAttributeMappingConfirmMessage,
+ ]);
+
+ $this->jsUrl->add(
+ $this->_urlBuilder->getUrl('*/*/updateAttributeMapping'),
+ 'update_attribute_mappings'
+ );
+
+ $this->jsPhp->addConstants(
+ $this->dataHelper->getClassConstants(\Ess\M2ePro\Model\Amazon\Template\ProductType::class)
+ );
+
+ return parent::_beforeToHtml();
+ }
+
+ private function getSaveConfirmationText()
+ {
+ if (!$this->productType->isObjectNew()) {
+ return $this->dataHelper->escapeJs(
+ __(
+ '
+Note: All changes you have made will be automatically applied to all M2E Pro Listings where this
+Product Type is used.
+ '
+ )
+ );
+ }
+
+ return '';
+ }
+
private function isEditMode(): bool
{
- return (bool)$this->productType->getId();
+ return !$this->productType->isObjectNew();
}
}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Data.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Data.php
index 15f5ad8c0..6f10034ef 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Data.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Data.php
@@ -1,38 +1,22 @@
productType = $productType;
+ parent::__construct($context, $data);
}
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Data
- * @throws \Magento\Framework\Exception\LocalizedException
- */
protected function _prepareLayout(): Data
{
$this->setChild(
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit/FieldTemplates.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit/FieldTemplates.php
index 8a0b5e6fe..ace0da938 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit/FieldTemplates.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit/FieldTemplates.php
@@ -1,11 +1,5 @@
attributes;
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Form.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Form.php
index 00da4e29d..dd9abb8f0 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Form.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Form.php
@@ -1,29 +1,15 @@
setId('amazonTemplateProductTypeEditForm');
}
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Form
- * @throws \Ess\M2ePro\Model\Exception\Logic
- * @throws \Magento\Framework\Exception\LocalizedException
- */
protected function _prepareForm(): Form
{
/** @var \Ess\M2ePro\Model\Amazon\Template\ProductType $productType */
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs.php
index b92f5efb2..6516f7183 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs.php
@@ -1,28 +1,13 @@
dataHelper = $dataHelper;
$this->productType = $productType;
+ parent::__construct($context, $jsonEncoder, $authSession, $data);
}
/**
@@ -47,18 +32,13 @@ public function _construct()
$this->setDestElementId('tabs_edit_form_data');
}
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Tabs
- * @throws \Magento\Framework\Exception\LocalizedException
- * @throws \Exception
- */
protected function _prepareLayout(): Tabs
{
$this->addTab(
'general',
[
- 'label' => $this->__('General'),
- 'title' => $this->__('General'),
+ 'label' => __('General'),
+ 'title' => __('General'),
'content' => $this->getLayout()
->createBlock(
\Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Tabs\General::class,
@@ -88,10 +68,6 @@ protected function _prepareLayout(): Tabs
return parent::_prepareLayout();
}
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Tabs|\Magento\Backend\Block\Widget\Tabs
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function _beforeToHtml()
{
$this->jsUrl->addUrls($this->dataHelper->getControllerActions('Amazon_Template_ProductType'));
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General.php
index 4716dff9d..741e16983 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General.php
@@ -1,42 +1,25 @@
dataHelper = $dataHelper;
- $this->amazonHelper = $amazonHelper;
$this->productType = $productType;
$this->productTypeBuilderFactory = $productTypeBuilderFactory;
+ $this->amazonMarketplaceRepository = $amazonMarketplaceRepository;
parent::__construct($context, $registry, $formFactory, $data);
}
- /**
- * @return void
- */
- public function _construct()
+ public function _construct(): void
{
parent::_construct();
$this->setId('amazonTemplateProductTypeEditTabsGeneral');
$this->formData = $this->getFormData();
- $marketplaces = $this->amazonHelper->getMarketplacesAvailableForAsinCreation();
- $marketplaces = $marketplaces->toArray();
- $this->marketplaceData = $marketplaces['items'];
+ $this->allowedMarketplaces = $this->amazonMarketplaceRepository->findWithAccounts();
}
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Tabs\General
- * @throws \Magento\Framework\Exception\LocalizedException
- */
protected function _prepareForm(): General
{
$form = $this->_formFactory->create();
@@ -91,9 +65,9 @@ protected function _prepareForm(): General
[]
);
- $isEdit = (bool)$this->productType->getId();
- $marketplaceId = $this->productType->getMarketplaceId();
- if (!$marketplaceId) {
+ $isEdit = !$this->productType->isObjectNew();
+ $marketplaceId = $isEdit ? $this->productType->getMarketplaceId() : null;
+ if ($marketplaceId === null) {
$marketplaceId = $this->getSuggestedMarketplaceId();
}
@@ -115,8 +89,8 @@ protected function _prepareForm(): General
self::SELECT,
[
'name' => 'general[marketplace_id]',
- 'label' => $this->__('Marketplace'),
- 'title' => $this->__('Marketplace'),
+ 'label' => __('Marketplace'),
+ 'title' => __('Marketplace'),
'values' => $this->getMarketplaceDataOptions(),
'value' => $marketplaceId,
'class' => 'required-entry',
@@ -130,7 +104,7 @@ protected function _prepareForm(): General
'general_product_type_selection',
'note',
[
- 'label' => $this->__('Product Type'),
+ 'label' => __('Product Type'),
'required' => true,
'after_element_html' => $this->getProductTypeEditHtml($isEdit)
]
@@ -149,9 +123,6 @@ protected function _prepareForm(): General
return parent::_prepareForm();
}
- /**
- * @return string[]
- */
public function getFormData(): array
{
if ($this->productType->getId()) {
@@ -218,32 +189,27 @@ private function getMarketplaceDataOptions(): array
['value' => '', 'label' => '', 'attrs' => ['style' => 'display: none;']]
];
- foreach ($this->marketplaceData as $marketplace) {
+ foreach ($this->allowedMarketplaces as $marketplace) {
$optionsResult[] = [
- 'value' => $marketplace['id'],
- 'label' => $this->__($marketplace['title'])
+ 'value' => $marketplace->getId(),
+ 'label' => __($marketplace->getTitle())
];
}
return $optionsResult;
}
- /**
- * @param bool $isEdit
- *
- * @return string
- */
private function getProductTypeEditHtml(bool $isEdit): string
{
- $textNotSelected = $this->__('Not Selected');
- $textEdit = $this->__('Edit');
+ $textNotSelected = __('Not Selected');
+ $textEdit = __('Edit');
$title = $isEdit ? $this->getDictionaryTitle() : '';
$quotedTitle = $this->dataHelper->escapeHtml($title);
$displayModeNotSelected = $isEdit ? 'none' : 'inline-block';
$displayModeTitle = $isEdit ? 'inline-block' : 'none';
- $productTypeNick = $this->productType->getNick();
+ $productTypeNick = $isEdit ? $this->productType->getNick() : '';
$quotedNick = $this->dataHelper->escapeHtml($productTypeNick);
return <<getRequest()->getParam('marketplace_id', 0);
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General/SearchPopup.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General/SearchPopup.php
index 0d6b3930f..992ab537e 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General/SearchPopup.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/General/SearchPopup.php
@@ -1,11 +1,5 @@
productTypes = $productTypes;
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/Template.php b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/Template.php
index bd8ea3690..2db11c846 100644
--- a/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/Template.php
+++ b/Block/Adminhtml/Amazon/Template/ProductType/Edit/Tabs/Template.php
@@ -1,32 +1,20 @@
setId('amazonTemplateProductTypeEditTabsTemplate');
}
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Tabs\Template
- * @throws \Magento\Framework\Exception\LocalizedException
- */
protected function _prepareForm(): Template
{
$form = $this->_formFactory->create();
$this->setForm($form);
+
return parent::_prepareForm();
}
}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/Grid.php b/Block/Adminhtml/Amazon/Template/ProductType/Grid.php
deleted file mode 100644
index af0cfebd9..000000000
--- a/Block/Adminhtml/Amazon/Template/ProductType/Grid.php
+++ /dev/null
@@ -1,266 +0,0 @@
-dataHelper = $dataHelper;
- $this->productTypeCollectionFactory = $productTypeCollectionFactory;
- $this->marketplaceCollectionFactory = $marketplaceCollectionFactory;
- parent::__construct($context, $backendHelper, $data);
- }
-
- /**
- * @return void
- * @throws \Magento\Framework\Exception\FileSystemException
- */
- public function _construct()
- {
- parent::_construct();
-
- $this->setId('amazonTemplateProductTypeGrid');
- $this->setSaveParametersInSession(true);
- $this->setUseAjax(true);
- $this->css->addFile('amazon/product_type.css');
- }
-
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Grid
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- protected function _prepareCollection(): Grid
- {
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\Collection $collection */
- $collection = $this->productTypeCollectionFactory->create()
- ->appendTableDictionary()
- ->appendTableMarketplace();
-
- $this->setCollection($collection);
-
- return parent::_prepareCollection();
- }
-
- /**
- * @return \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Grid
- * @throws \Exception
- */
- protected function _prepareColumns(): Grid
- {
- $this->addColumn(
- 'title',
- [
- 'header' => $this->__('Title'),
- 'align' => 'left',
- 'type' => 'text',
- 'index' => 'title',
- 'escape' => true,
- 'filter_index' => 'main_table.title',
- 'frame_callback' => [$this, 'callbackColumnTitle'],
- ]
- );
-
- $this->addColumn(
- 'marketplace',
- [
- 'header' => $this->__('Marketplace'),
- 'align' => 'left',
- 'type' => 'options',
- 'width' => '100px',
- 'index' => 'marketplace_title',
- 'filter_condition_callback' => [$this, 'callbackFilterMarketplace'],
- 'options' => $this->getEnabledMarketplaceTitles(),
- ]
- );
-
- $this->addColumn(
- 'create_date',
- [
- 'header' => $this->__('Creation Date'),
- 'align' => 'left',
- 'width' => '150px',
- 'type' => 'datetime',
- 'filter' => \Ess\M2ePro\Block\Adminhtml\Magento\Grid\Column\Filter\Datetime::class,
- 'filter_time' => true,
- 'format' => \IntlDateFormatter::MEDIUM,
- 'index' => 'create_date',
- 'filter_index' => 'main_table.create_date',
- ]
- );
-
- $this->addColumn(
- 'update_date',
- [
- 'header' => $this->__('Update Date'),
- 'align' => 'left',
- 'width' => '150px',
- 'type' => 'datetime',
- 'filter' => \Ess\M2ePro\Block\Adminhtml\Magento\Grid\Column\Filter\Datetime::class,
- 'filter_time' => true,
- 'format' => \IntlDateFormatter::MEDIUM,
- 'index' => 'update_date',
- 'filter_index' => 'main_table.update_date',
- ]
- );
-
- $this->addColumn(
- 'actions',
- [
- 'header' => $this->__('Actions'),
- 'align' => 'left',
- 'width' => '100px',
- 'type' => 'action',
- 'index' => 'actions',
- 'filter' => false,
- 'sortable' => false,
- 'renderer' => \Ess\M2ePro\Block\Adminhtml\Magento\Grid\Column\Renderer\Action::class,
- 'getter' => 'getId',
- 'actions' => $this->getRowActions(),
- ]
- );
-
- return parent::_prepareColumns();
- }
-
- /**
- * @param \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\Collection $collection
- * @param \Ess\M2ePro\Block\Adminhtml\Widget\Grid\Column\Extended\Rewrite $column
- *
- * @return void
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- protected function callbackFilterMarketplace($collection, $column): void
- {
- $value = $column->getFilter()->getValue();
- if ($value == null) {
- return;
- }
-
- $collection->appendFilterMarketplaceId((int)$value);
- }
-
- /**
- * @return array
- */
- private function getEnabledMarketplaceTitles(): array
- {
- /** @var \Ess\M2ePro\Model\ResourceModel\Marketplace\Collection $collection */
- $collection = $this->marketplaceCollectionFactory->create()
- ->appendFilterEnabledMarketplaces(\Ess\M2ePro\Helper\Component\Amazon::NICK)
- ->setOrder('title', 'ASC');
-
- return $collection->toOptionHash();
- }
-
- /**
- * @return string
- */
- public function getGridUrl(): string
- {
- return $this->getUrl('*/*/grid', ['_current' => true]);
- }
-
- /**
- * @param $item
- *
- * @return string
- */
- public function getRowUrl($item): string
- {
- return $this->getUrl(
- '*/amazon_template_productType/edit',
- [
- 'id' => $item->getData('id'),
- 'back' => 1,
- ]
- );
- }
-
- /**
- * @return array[]
- */
- private function getRowActions(): array
- {
- return [
- [
- 'caption' => $this->__('Edit'),
- 'url' => [
- 'base' => '*/amazon_template_productType/edit',
- ],
- 'field' => 'id',
- ],
- [
- 'caption' => $this->__('Delete'),
- 'class' => 'action-default scalable add primary',
- 'url' => [
- 'base' => '*/amazon_template_productType/delete',
- ],
- 'field' => 'id',
- 'confirm' => $this->__('Are you sure?'),
- ],
- ];
- }
-
- /**
- * @param string $value
- * @param \Ess\M2ePro\Model\Amazon\Template\ProductType $row
- *
- * @return string
- */
- public function callbackColumnTitle($value, $row)
- {
- $value = $this->dataHelper->escapeHtml($value);
- $dictionary = $row->getDictionary();
- $isInvalid = $dictionary->isInvalid();
-
- if (!$value) {
- $value = $dictionary->getTitle();
- }
-
- if ($isInvalid) {
- $message = $this->__(
- 'This Product Type is no longer supported by Amazon. '
- . 'Please assign another Product Type to the products that use it.'
- );
-
- $value = <<
- $value
- {$this->getTooltipHtml($message, true)}
-
-HTML;
- }
-
- return $value;
- }
-}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/HelpBlock.php b/Block/Adminhtml/Amazon/Template/ProductType/HelpBlock.php
new file mode 100644
index 000000000..16f2b1e83
--- /dev/null
+++ b/Block/Adminhtml/Amazon/Template/ProductType/HelpBlock.php
@@ -0,0 +1,35 @@
+supportHelper = $supportHelper;
+ parent::__construct($context, $data);
+ }
+
+ public function getContent(): string
+ {
+ return (string)__(
+ 'The page displays Amazon Product Types that are currently used in your M2E Pro Listings.
+
+ Here you can add a new Product Type, edit or delete existing ones.
+ Learn how to manage Amazon Product Types in
+ this article .
+ To ensure that you have the most up-to-date Product Type information in your M2E Pro,
+ simply click the Refresh Amazon Data button.
+ This will synchronize any changes made to Product Types on Amazon. Whether certain specifics have been
+ added or removed, you will see the updated information after the data is refreshed.',
+ ['url' => $this->supportHelper->getDocumentationArticleUrl('amazon-product-type')]
+ );
+ }
+}
diff --git a/Block/Adminhtml/Amazon/Template/ProductType/RefreshAmazonDataProgressBar.php b/Block/Adminhtml/Amazon/Template/ProductType/RefreshAmazonDataProgressBar.php
new file mode 100644
index 000000000..ce802499c
--- /dev/null
+++ b/Block/Adminhtml/Amazon/Template/ProductType/RefreshAmazonDataProgressBar.php
@@ -0,0 +1,13 @@
+';
+ }
+}
diff --git a/Block/Adminhtml/General.php b/Block/Adminhtml/General.php
index 90dfa0580..3ca6ebeae 100644
--- a/Block/Adminhtml/General.php
+++ b/Block/Adminhtml/General.php
@@ -1,11 +1,5 @@
{$this->__('Confirm the Unmanaged Listings reset')}
{$this->__(
- 'This action will remove all the items from Amazon Unmanaged Listings.
+ 'This action will remove all the items from Walmart Unmanaged Listings.
It will take some time to import them again.'
)}
diff --git a/Block/Adminhtml/Wizard/MigrationToInnodb/Installation.php b/Block/Adminhtml/Wizard/MigrationToInnodb/Installation.php
index afa9e1740..bd87f26d5 100644
--- a/Block/Adminhtml/Wizard/MigrationToInnodb/Installation.php
+++ b/Block/Adminhtml/Wizard/MigrationToInnodb/Installation.php
@@ -1,11 +1,5 @@
marketplaceResource = $marketplaceResource;
$this->marketplaceFactory = $marketplaceFactory;
- $this->marketplaceUpdater = $marketplaceUpdater;
$this->helperException = $helperException;
$this->accountServerUpdate = $accountServerUpdate;
$this->accountCollectionFactory = $accountCollectionFactory;
@@ -107,7 +103,6 @@ public function execute()
(string)$params['selling_partner_id']
);
}
- $this->marketplaceUpdater->update($marketplace);
return $result;
}
diff --git a/Controller/Adminhtml/Amazon/Listing/AutoAction/GetProductTypesList.php b/Controller/Adminhtml/Amazon/Listing/AutoAction/GetProductTypesList.php
index a02b53b3b..dd9e0dd03 100644
--- a/Controller/Adminhtml/Amazon/Listing/AutoAction/GetProductTypesList.php
+++ b/Controller/Adminhtml/Amazon/Listing/AutoAction/GetProductTypesList.php
@@ -1,56 +1,39 @@
productTypeCollectionFactory = $productTypeCollectionFactory;
+ $this->amazonTemplateProductTypeRepository = $amazonTemplateProductTypeRepository;
}
- /**
- * @inheridoc
- */
public function execute()
{
$marketplaceId = $this->getRequest()->getParam('marketplace_id', '');
+ if (empty($marketplaceId)) {
+ $this->setJsonContent([]);
- $collection = $this->productTypeCollectionFactory->create();
- $collection->appendTableDictionary();
- $collection->getSelect()->reset(\Magento\Framework\DB\Select::COLUMNS);
- $collection->getSelect()->columns([
- 'id' => 'id',
- 'title' => 'adpt.title',
- ]);
+ return $this->getResult();
+ }
- if ($marketplaceId !== '') {
- $collection->appendFilterMarketplaceId((int)$marketplaceId);
+ $result = [];
+ foreach ($this->amazonTemplateProductTypeRepository->findByMarketplaceId((int)$marketplaceId) as $template) {
+ $result[] = [
+ 'id' => $template->getId(),
+ 'title' => $template->getTitle(),
+ ];
}
- $productTypeTemplates = $collection->getData();
+ $this->setJsonContent($result);
- $this->setJsonContent($productTypeTemplates);
return $this->getResult();
}
}
diff --git a/Controller/Adminhtml/Amazon/Listing/Create/Index.php b/Controller/Adminhtml/Amazon/Listing/Create/Index.php
index b021ff3a0..753b739a7 100644
--- a/Controller/Adminhtml/Amazon/Listing/Create/Index.php
+++ b/Controller/Adminhtml/Amazon/Listing/Create/Index.php
@@ -13,8 +13,10 @@ class Index extends \Ess\M2ePro\Controller\Adminhtml\Amazon\Main
/** @var \Ess\M2ePro\Helper\Data\Session */
private $helperDataSession;
private \Ess\M2ePro\Model\Amazon\Listing\OfferImagesFormService $offerImagesService;
+ private \Ess\M2ePro\Model\Amazon\Dictionary\MarketplaceService $amazonDictionaryMarketplaceService;
public function __construct(
+ \Ess\M2ePro\Model\Amazon\Dictionary\MarketplaceService $amazonDictionaryMarketplaceService,
\Ess\M2ePro\Model\Amazon\Listing\OfferImagesFormService $offerImagesService,
\Ess\M2ePro\Helper\Module\Wizard $helperWizard,
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Amazon\Factory $amazonFactory,
@@ -22,12 +24,12 @@ public function __construct(
\Ess\M2ePro\Helper\Data\Session $helperDataSession,
\Ess\M2ePro\Controller\Adminhtml\Context $context
) {
+ parent::__construct($amazonFactory, $context);
$this->helperWizard = $helperWizard;
$this->transferring = $transferring;
$this->helperDataSession = $helperDataSession;
$this->offerImagesService = $offerImagesService;
-
- parent::__construct($amazonFactory, $context);
+ $this->amazonDictionaryMarketplaceService = $amazonDictionaryMarketplaceService;
}
protected function _isAllowed()
@@ -86,6 +88,8 @@ protected function stepOne()
$this->setSessionValue('account_id', (int)$post['account_id']);
$this->setSessionValue('store_id', (int)$post['store_id']);
+ $this->activateAndPrepareDictionaryMarketplaceIfNeed((int)$post['marketplace_id']);
+
$this->_redirect('*/*/index', ['_current' => true, 'step' => 2]);
return;
@@ -302,4 +306,22 @@ private function setWizardStep($step)
$this->helperWizard->setStep(\Ess\M2ePro\Helper\View\Amazon::WIZARD_INSTALLATION_NICK, $step);
}
+
+ private function activateAndPrepareDictionaryMarketplaceIfNeed(int $marketplaceId): void
+ {
+ /** @var \Ess\M2ePro\Model\Marketplace $marketplaceObj */
+ $marketplaceObj = $this->activeRecordFactory->getObjectLoaded(
+ 'Marketplace',
+ $marketplaceId
+ );
+
+ if (!$marketplaceObj->isStatusEnabled()) {
+ $marketplaceObj->enable();
+ $marketplaceObj->save();
+ }
+
+ if (!$this->amazonDictionaryMarketplaceService->isExistForMarketplace($marketplaceObj)) {
+ $this->amazonDictionaryMarketplaceService->update($marketplaceObj);
+ }
+ }
}
diff --git a/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php b/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php
index 01dd13237..e900b9b54 100644
--- a/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php
+++ b/Controller/Adminhtml/Amazon/Listing/Product/Add/CheckSearchResults.php
@@ -15,10 +15,7 @@ public function execute()
$listingProductsIds = $this->filterProductsForNewAsin($listingProductsIds);
- if (
- empty($listingProductsIds)
- || !$this->getListing()->getMarketplace()->getChildObject()->isNewAsinAvailable()
- ) {
+ if (empty($listingProductsIds)) {
$redirectUrl = $this->getUrl('*/*/index', [
'step' => 6,
'id' => $this->getRequest()->getParam('id'),
diff --git a/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetGeneralIdOwner.php b/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetGeneralIdOwner.php
index 6c1f404d0..04bea4ba1 100644
--- a/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetGeneralIdOwner.php
+++ b/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetGeneralIdOwner.php
@@ -18,27 +18,16 @@ class SetGeneralIdOwner extends Main
private $listingProductFactory;
/** @var \Ess\M2ePro\Helper\Data\Session */
private $session;
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\DetailsFactory */
- private $amazonMarketplaceDetailsFactory;
- /**
- * @param \Ess\M2ePro\Helper\Data\Session $session
- * @param \Ess\M2ePro\Model\Listing\ProductFactory $listingProductFactory
- * @param \Ess\M2ePro\Model\Amazon\Marketplace\DetailsFactory $amazonMarketplaceDetailsFactory
- * @param \Ess\M2ePro\Model\ActiveRecord\Component\Parent\Amazon\Factory $amazonFactory
- * @param \Ess\M2ePro\Controller\Adminhtml\Context $context
- */
public function __construct(
\Ess\M2ePro\Helper\Data\Session $session,
\Ess\M2ePro\Model\Listing\ProductFactory $listingProductFactory,
- \Ess\M2ePro\Model\Amazon\Marketplace\DetailsFactory $amazonMarketplaceDetailsFactory,
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Amazon\Factory $amazonFactory,
\Ess\M2ePro\Controller\Adminhtml\Context $context
) {
parent::__construct($amazonFactory, $context);
$this->listingProductFactory = $listingProductFactory;
$this->session = $session;
- $this->amazonMarketplaceDetailsFactory = $amazonMarketplaceDetailsFactory;
}
/**
@@ -134,11 +123,7 @@ private function setGeneralIdOwner(int $productId, int $generalIdOwner)
return $data;
}
- $detailsModel = $this->amazonMarketplaceDetailsFactory->create();
- $detailsModel->setMarketplaceId($listingProduct->getListing()->getMarketplaceId());
- $themes = $detailsModel->getVariationThemes(
- $amazonListingProduct->getProductTypeTemplate()->getNick()
- );
+ $themes = $amazonListingProduct->getProductTypeTemplate()->getDictionary()->getVariationThemes();
if (empty($themes)) {
$data['success'] = false;
@@ -155,7 +140,7 @@ private function setGeneralIdOwner(int $productId, int $generalIdOwner)
$isCountEqual = false;
foreach ($themes as $theme) {
- if (count($theme['attributes']) == count($productAttributes)) {
+ if (count($theme['attributes']) === count($productAttributes)) {
$isCountEqual = true;
break;
}
@@ -169,8 +154,13 @@ private function setGeneralIdOwner(int $productId, int $generalIdOwner)
}
}
- $listingProduct->getChildObject()->setData('is_general_id_owner', $generalIdOwner)->save();
- $amazonListingProduct->getVariationManager()->getTypeModel()->getProcessor()->process();
+ $listingProduct->getChildObject()
+ ->setData('is_general_id_owner', $generalIdOwner)
+ ->save();
+ $amazonListingProduct->getVariationManager()
+ ->getTypeModel()
+ ->getProcessor()
+ ->process();
return $data;
}
diff --git a/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetVariationTheme.php b/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetVariationTheme.php
index fa19c4527..78bca9c34 100644
--- a/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetVariationTheme.php
+++ b/Controller/Adminhtml/Amazon/Listing/Product/Variation/Manage/SetVariationTheme.php
@@ -12,15 +12,12 @@
class SetVariationTheme extends Main
{
- /** @var \Ess\M2ePro\Helper\Component\Amazon\ProductType */
- private $productTypeHelper;
/** @var \Ess\M2ePro\Helper\Component\Amazon\Variation */
protected $variationHelper;
/** @var \Ess\M2ePro\Helper\Component\Amazon\Vocabulary */
protected $vocabularyHelper;
public function __construct(
- \Ess\M2ePro\Helper\Component\Amazon\ProductType $productTypeHelper,
\Ess\M2ePro\Helper\Component\Amazon\Variation $variationHelper,
\Ess\M2ePro\Helper\Component\Amazon\Vocabulary $vocabularyHelper,
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Amazon\Factory $amazonFactory,
@@ -28,7 +25,6 @@ public function __construct(
) {
parent::__construct($amazonFactory, $context);
- $this->productTypeHelper = $productTypeHelper;
$this->variationHelper = $variationHelper;
$this->vocabularyHelper = $vocabularyHelper;
}
@@ -50,21 +46,18 @@ public function execute()
$parentTypeModel = $amazonListingProduct->getVariationManager()->getTypeModel();
+ $variationThemesAttributes = $amazonListingProduct->getProductTypeTemplate()
+ ->getDictionary()
+ ->getVariationThemesAttributes($variationTheme);
+
$additionalData = $listingProduct->getAdditionalData();
if (
empty($additionalData['migrated_to_product_types'])
&& $amazonListingProduct->isGeneralIdOwner()
) {
- $productType = $amazonListingProduct->getProductTypeTemplate();
- $productTypeNick = $productType->getNick();
- $marketplaceId = $listingProduct->getListing()->getMarketplaceId();
- $dictionary = $this->productTypeHelper->getMarketplaceDictionary($marketplaceId);
- $dictionaryProductTypes = $dictionary->getProductTypes();
- if (!empty($dictionaryProductTypes[$productTypeNick]['variation_themes'][$variationTheme])) {
- $themeData = $dictionaryProductTypes[$productTypeNick]['variation_themes'][$variationTheme];
+ if (!empty($variationThemesAttributes)) {
$sets = [];
-
- foreach ($themeData['attributes'] as $attribute) {
+ foreach ($variationThemesAttributes as $attribute) {
$sets[$attribute] = [];
}
@@ -88,16 +81,10 @@ public function execute()
$this->variationHelper->increaseThemeUsageCount($variationTheme, $listingProduct->getMarketplace()->getId());
- $productDataNick = $amazonListingProduct->getProductTypeTemplate()->getNick();
-
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Details $marketplaceDetails */
- $marketplaceDetails = $this->modelFactory->getObject('Amazon_Marketplace_Details');
- $marketplaceDetails->setMarketplaceId($amazonListingProduct->getMarketplace()->getId());
-
- $themeAttributes = $marketplaceDetails->getVariationThemeAttributes($productDataNick, $variationTheme);
+ $themeAttributes = $variationThemesAttributes;
$productAttributes = $parentTypeModel->getProductAttributes();
- if (count($themeAttributes) != 1 || count($productAttributes) != 1) {
+ if (count($themeAttributes) !== 1 || count($productAttributes) !== 1) {
$parentTypeModel->getProcessor()->process();
$this->setJsonContent($result);
diff --git a/Controller/Adminhtml/Amazon/Marketplace/Index.php b/Controller/Adminhtml/Amazon/Marketplace/Index.php
deleted file mode 100755
index 32cb50d41..000000000
--- a/Controller/Adminhtml/Amazon/Marketplace/Index.php
+++ /dev/null
@@ -1,30 +0,0 @@
-addContent($this->getLayout()->createBlock(\Ess\M2ePro\Block\Adminhtml\Amazon\Marketplace::class));
- $this->getResult()->getConfig()->getTitle()->prepend($this->__('Marketplaces'));
- $this->setPageHelpLink('amazon-marketplaces');
-
- return $this->getResult();
- }
-
- //########################################
-}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/RunSynchNow.php b/Controller/Adminhtml/Amazon/Marketplace/RunSynchNow.php
deleted file mode 100755
index 9b8745008..000000000
--- a/Controller/Adminhtml/Amazon/Marketplace/RunSynchNow.php
+++ /dev/null
@@ -1,49 +0,0 @@
-marketplaceUpdater = $marketplaceUpdater;
- $this->amazonHelper = $amazonHelper;
- }
-
- public function execute()
- {
- // @codingStandardsIgnoreLine
- session_write_close();
-
- /** @var \Ess\M2ePro\Model\Marketplace $marketplace */
- $marketplace = $this->activeRecordFactory->getObjectLoaded(
- 'Marketplace',
- (int)$this->getRequest()->getParam('marketplace_id')
- );
-
- $this->setJsonContent([
- 'result' => $this->marketplaceUpdater->update($marketplace) ? 'success' : 'error'
- ]);
-
- return $this->getResult();
- }
-}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/Save.php b/Controller/Adminhtml/Amazon/Marketplace/Save.php
deleted file mode 100755
index d1fb08486..000000000
--- a/Controller/Adminhtml/Amazon/Marketplace/Save.php
+++ /dev/null
@@ -1,38 +0,0 @@
-activeRecordFactory->getObject('Marketplace')->getCollection();
-
- foreach ($marketplaces as $marketplace) {
- $newStatus = $this->getRequest()->getParam('status_' . $marketplace->getId());
-
- if ($newStatus === null) {
- continue;
- }
- if ($marketplace->getStatus() == $newStatus) {
- continue;
- }
- $marketplace->setData('status', $newStatus)->save();
- }
- }
-
- //########################################
-}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/Sync/GetMarketplaceList.php b/Controller/Adminhtml/Amazon/Marketplace/Sync/GetMarketplaceList.php
new file mode 100644
index 000000000..bfa147646
--- /dev/null
+++ b/Controller/Adminhtml/Amazon/Marketplace/Sync/GetMarketplaceList.php
@@ -0,0 +1,37 @@
+amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ $this->jsonResultFactory = $jsonResultFactory;
+ }
+
+ public function execute()
+ {
+ $result = [];
+ foreach ($this->amazonMarketplaceRepository->findWithAccounts() as $marketplace) {
+ $result[] = [
+ 'id' => (int)$marketplace->getId(),
+ 'title' => $marketplace->getTitle(),
+ ];
+ }
+
+ return $this->jsonResultFactory->create()
+ ->setData(['list' => $result]);
+ }
+}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/Sync/GetProductTypeList.php b/Controller/Adminhtml/Amazon/Marketplace/Sync/GetProductTypeList.php
new file mode 100644
index 000000000..7d834babd
--- /dev/null
+++ b/Controller/Adminhtml/Amazon/Marketplace/Sync/GetProductTypeList.php
@@ -0,0 +1,49 @@
+jsonResultFactory = $jsonResultFactory;
+ $this->dictionaryProductTypeRepository = $dictionaryProductTypeRepository;
+ $this->amazonMarketplaceLoader = $amazonMarketplaceLoader;
+ }
+
+ public function execute()
+ {
+ $marketplace = $this->amazonMarketplaceLoader->load($this->getRequest()->getParam('marketplace_id'));
+
+ $productTypes = $this->dictionaryProductTypeRepository->findValidByMarketplace($marketplace);
+
+ $result = [];
+ foreach ($productTypes as $productType) {
+ $result[] = [
+ 'id' => (int)$productType->getId(),
+ 'title' => $productType->getTitle(),
+ ];
+ }
+
+ return $this->jsonResultFactory->create()
+ ->setData([
+ 'list' => $result,
+ ]);
+ }
+}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/Sync/MarketplaceLoader.php b/Controller/Adminhtml/Amazon/Marketplace/Sync/MarketplaceLoader.php
new file mode 100644
index 000000000..b01a611ad
--- /dev/null
+++ b/Controller/Adminhtml/Amazon/Marketplace/Sync/MarketplaceLoader.php
@@ -0,0 +1,29 @@
+amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ }
+
+ public function load($marketplaceId): \Ess\M2ePro\Model\Marketplace
+ {
+ if ($marketplaceId === null) {
+ throw new \RuntimeException('Missing marketplace ID');
+ }
+
+ $marketplace = $this->amazonMarketplaceRepository->get((int)$marketplaceId);
+ if (!$marketplace->isComponentModeAmazon()) {
+ throw new \LogicException('Marketplace is not valid.');
+ }
+
+ return $marketplace;
+ }
+}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateDetails.php b/Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateDetails.php
new file mode 100644
index 000000000..762f491e5
--- /dev/null
+++ b/Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateDetails.php
@@ -0,0 +1,38 @@
+dictionaryMarketplaceService = $dictionaryMarketplaceService;
+ $this->jsonResultFactory = $jsonResultFactory;
+ $this->amazonMarketplaceLoader = $amazonMarketplaceLoader;
+ }
+
+ public function execute()
+ {
+ $marketplace = $this->amazonMarketplaceLoader->load($this->getRequest()->getParam('marketplace_id'));
+
+ $this->dictionaryMarketplaceService->update($marketplace);
+
+ return $this->jsonResultFactory->create()->setData([]);
+ }
+}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateProductType.php b/Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateProductType.php
new file mode 100644
index 000000000..f216b4b72
--- /dev/null
+++ b/Controller/Adminhtml/Amazon/Marketplace/Sync/UpdateProductType.php
@@ -0,0 +1,40 @@
+jsonResultFactory = $jsonResultFactory;
+ $this->dictionaryProductTypeRepository = $dictionaryProductTypeRepository;
+ $this->dictionaryProductTypeService = $dictionaryProductTypeService;
+ }
+
+ public function execute()
+ {
+ $productTypeId = $this->getRequest()->getParam('id');
+ if ($productTypeId === null) {
+ throw new \RuntimeException('Missing Product Type ID');
+ }
+
+ $productType = $this->dictionaryProductTypeRepository->get((int)$productTypeId);
+
+ $this->dictionaryProductTypeService->update($productType);
+
+ return $this->jsonResultFactory->create()->setData([]);
+ }
+}
diff --git a/Controller/Adminhtml/Amazon/Marketplace/SynchGetExecutingInfo.php b/Controller/Adminhtml/Amazon/Marketplace/SynchGetExecutingInfo.php
index 38cc2c1ca..3823dfbbd 100644
--- a/Controller/Adminhtml/Amazon/Marketplace/SynchGetExecutingInfo.php
+++ b/Controller/Adminhtml/Amazon/Marketplace/SynchGetExecutingInfo.php
@@ -1,47 +1,16 @@
modelFactory->getObject('Amazon_Marketplace_Synchronization');
- if (!$synchronization->isLocked()) {
- $this->setJsonContent(['mode' => 'inactive']);
-
- return $this->getResult();
- }
-
- $contentData = $synchronization->getLockItemManager()->getContentData();
- $progressData = $contentData[\Ess\M2ePro\Model\Lock\Item\Progress::CONTENT_DATA_KEY];
-
- $response = ['mode' => 'executing'];
-
- if (!empty($progressData)) {
- $response['title'] = 'Amazon Data Update';
- $response['percents'] = $progressData[key($progressData)]['percentage'];
- $response['status'] = key($progressData);
- }
-
- $this->setJsonContent($response);
+ $this->setJsonContent(['mode' => 'done']);
return $this->getResult();
}
-
- //########################################
}
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType.php b/Controller/Adminhtml/Amazon/Template/ProductType.php
index 73f9ce300..ea45fbff5 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType.php
@@ -1,18 +1,11 @@
_authorization->isAllowed('Ess_M2ePro::amazon_configuration_product_types');
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/Delete.php b/Controller/Adminhtml/Amazon/Template/ProductType/Delete.php
index 53396c0ef..69d8ade2f 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/Delete.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/Delete.php
@@ -1,64 +1,53 @@
productTypeHelper = $productTypeHelper;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
}
- /**
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function execute()
{
$ids = $this->getRequestIds();
if (count($ids) == 0) {
- $this->messageManager->addErrorMessage($this->__('Please select Item(s) to remove.'));
+ $this->messageManager->addErrorMessage(__('Please select Item(s) to remove.'));
$this->_redirect('*/*/index');
+
return;
}
$deleted = $locked = 0;
foreach ($ids as $id) {
- $template = $this->productTypeHelper->getProductTypeById((int)$id);
- if ($template->isLocked() || $this->productTypeHelper->isProductTypeUsingInProducts($id)) {
+ $template = $this->templateProductTypeRepository->get((int)$id);
+ if (
+ $template->isLocked()
+ || $this->templateProductTypeRepository->isUsed($template)
+ ) {
$locked++;
} else {
- $template->delete();
+ $this->templateProductTypeRepository->remove($template);
$deleted++;
}
}
if ($deleted) {
- $tempString = $this->__('%deleted% record(s) were deleted.', $deleted);
+ $tempString = __('%deleted record(s) were deleted.', ['deleted' => $deleted]);
$this->messageManager->addSuccessMessage($tempString);
}
if ($locked) {
- $tempString = $this->__('%locked% record(s) are used in Listing(s).', $locked) . ' ';
- $tempString .= $this->__('Product Type must not be in use to be deleted.');
+ $tempString = __('%locked record(s) are used in Listing(s).', ['locked' => $locked]) . ' ';
+ $tempString .= __('Product Type must not be in use to be deleted.');
$this->messageManager->addErrorMessage($tempString);
}
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/Edit.php b/Controller/Adminhtml/Amazon/Template/ProductType/Edit.php
index 9e9a8b396..5a593f861 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/Edit.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/Edit.php
@@ -1,10 +1,6 @@
dataHelper = $dataHelper;
- $this->amazonComponentHelper = $amazonComponentHelper;
$this->productTypeFactory = $productTypeFactory;
$this->registryManager = $registryManager;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
}
- /**
- * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|\Magento\Framework\View\Result\Page
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function execute()
{
$id = $this->getRequest()->getParam('id');
- /** @var \Ess\M2ePro\Model\Amazon\Template\ProductType $productType */
- $productType = $this->productTypeFactory->create();
- if ($id) {
- $productType->load($id);
- }
+ $productType = $this->productTypeFactory->createEmpty();
- $marketplaces = $this->amazonComponentHelper->getMarketplacesAvailableForAsinCreation();
- if ($marketplaces->getSize() <= 0) {
- $this->messageManager->addErrorMessage(
- __('Unable to create Product Type.')
- );
- return $this->_redirect('*/*/index');
+ if ($id !== null) {
+ $productType = $this->templateProductTypeRepository->get((int)$id);
}
$this->addContent(
- $this
- ->getLayout()
- ->createBlock(
- \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit::class,
- '',
- ['productType' => $productType]
- )
+ $this->getLayout()
+ ->createBlock(
+ \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit::class,
+ '',
+ ['productType' => $productType]
+ )
);
$block = $this
@@ -82,15 +64,15 @@ public function execute()
$this->addContent($block);
if ($productType->getId()) {
- $headerText = $this->__("Edit Product Type Settings");
- $headerText .= ' "' . $this->dataHelper->escapeHtml(
- $productType->getTitle()
- ) . '"';
+ $headerText = __("Edit Product Type Settings");
+ $headerText .= ' "' . $this->dataHelper->escapeHtml($productType->getTitle()) . '"';
} else {
- $headerText = $this->__("Add Product Type Settings");
+ $headerText = __("Add Product Type Settings");
}
- $this->getResultPage()->getConfig()->getTitle()->prepend($headerText);
+ $this->getResultPage()
+ ->getConfig()
+ ->getTitle()->prepend($headerText);
$this->setPageHelpLink('amazon-product-type');
return $this->getResultPage();
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/GetProductTypeInfo.php b/Controller/Adminhtml/Amazon/Template/ProductType/GetProductTypeInfo.php
index c04df70b0..edacf8612 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/GetProductTypeInfo.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/GetProductTypeInfo.php
@@ -1,38 +1,31 @@
productTypeHelper = $productTypeHelper;
+ $this->dictionaryProductTypeService = $dictionaryProductTypeService;
+ $this->amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
+ $this->productTypeAttributeMappingSuggester = $productTypeAttributeMappingSuggester;
}
- /**
- * @return \Magento\Framework\Controller\Result\Raw|\Magento\Framework\Controller\ResultInterface|\Magento\Framework\View\Result\Page
- * @throws \Ess\M2ePro\Model\Exception\Logic
- * @throws \Magento\Framework\Exception\LocalizedException
- * @throws \Exception
- */
public function execute()
{
$marketplaceId = (int)$this->getRequest()->getParam('marketplace_id');
@@ -45,8 +38,9 @@ public function execute()
return $this->getResult();
}
- $productType = (string)$this->getRequest()->getParam('product_type');
- if (!$productType) {
+ $marketplace = $this->amazonMarketplaceRepository->get($marketplaceId);
+ $productTypeNick = (string)$this->getRequest()->getParam('product_type');
+ if (!$productTypeNick) {
$this->setJsonContent([
'result' => false,
'message' => 'You should provide correct product_type.',
@@ -56,37 +50,25 @@ public function execute()
}
$onlyRequiredAttributes = (bool)$this->getRequest()->getParam('only_required_attributes');
- $scheme = $this->productTypeHelper->getProductTypeScheme(
- $marketplaceId,
- $productType,
- $onlyRequiredAttributes
- );
- $onlyForAttributes = $onlyRequiredAttributes ? $scheme : [];
- $settings = $this->productTypeHelper->getProductTypeSettings($marketplaceId, $productType);
- $groups = $this->productTypeHelper->getProductTypeGroups(
- $marketplaceId,
- $productType,
- $onlyForAttributes
- );
+
+ $productType = $this->dictionaryProductTypeService->retrieve($productTypeNick, $marketplace);
+
+ $template = $this->templateProductTypeRepository->findByDictionary($productType)[0] ?? null;
$isNewProductType = (bool)$this->getRequest()->getParam('is_new_product_type');
- $specificsDefaultSettings = $isNewProductType ? $this->productTypeHelper->getSpecificsDefaultSettings() : [];
- $timezoneShift = $this->productTypeHelper->getTimezoneShift();
- $mainImageSpecifics = $this->productTypeHelper->getMainImageSpecifics();
- $otherImagesSpecifics = $this->productTypeHelper->getOtherImagesSpecifics();
- $recommendedBrowseNodesLink = $this->productTypeHelper->getRecommendedBrowseNodesLink((int)$marketplaceId);
$this->setJsonContent([
'result' => true,
'data' => [
- 'scheme' => $scheme,
- 'settings' => $settings,
- 'groups' => $groups,
- 'timezone_shift' => $timezoneShift,
- 'specifics_default_settings' => $specificsDefaultSettings,
- 'main_image_specifics' => $mainImageSpecifics,
- 'other_images_specifics' => $otherImagesSpecifics,
- 'recommended_browse_node_link' => $recommendedBrowseNodesLink,
+ 'scheme' => $productType->getScheme(),
+ 'settings' => $template !== null ? $template->getSelfSetting() : [],
+ 'groups' => $productType->getAttributesGroups(),
+ 'timezone_shift' => ProductTypeHelper::getTimezoneShift(),
+ 'specifics_default_settings' => $isNewProductType
+ ? $this->productTypeAttributeMappingSuggester->getSuggestedAttributes() : [],
+ 'main_image_specifics' => ProductTypeHelper::getMainImageSpecifics(),
+ 'other_images_specifics' => ProductTypeHelper::getOtherImagesSpecifics(),
+ 'recommended_browse_node_link' => ProductTypeHelper::getRecommendedBrowseNodesLink($marketplaceId),
],
]);
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/Grid.php b/Controller/Adminhtml/Amazon/Template/ProductType/Grid.php
index 79ec65f9d..73079a835 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/Grid.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/Grid.php
@@ -1,24 +1,16 @@
getLayout()->createBlock(\Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Grid::class);
$this->setAjaxContent($grid->toHtml());
+
return $this->getResult();
}
}
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/Index.php b/Controller/Adminhtml/Amazon/Template/ProductType/Index.php
index 8fd4481bf..95f536564 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/Index.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/Index.php
@@ -1,24 +1,17 @@
getLayout()->createBlock(\Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType::class);
+ $this->getResultPage()
+ ->getConfig()
+ ->getTitle()->prepend('Product Types');
- $this->getResultPage()->getConfig()->getTitle()->prepend('Product Types');
- $this->addContent($content);
$this->setPageHelpLink('amazon-product-type');
return $this->getResultPage();
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/IsUniqueTitle.php b/Controller/Adminhtml/Amazon/Template/ProductType/IsUniqueTitle.php
index 7cd730325..52bc5240c 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/IsUniqueTitle.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/IsUniqueTitle.php
@@ -6,20 +6,15 @@
class IsUniqueTitle extends \Ess\M2ePro\Controller\Adminhtml\Amazon\Template\ProductType
{
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory */
- private $productTypeCollectionFactory;
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType */
- private $dictionaryProductTypeResource;
+ private \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $templateProductTypeRepository;
public function __construct(
- \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory $productTypeCollectionFactory,
- \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType $dictionaryProductTypeResource,
+ \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $templateProductTypeRepository,
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Amazon\Factory $amazonFactory,
\Ess\M2ePro\Controller\Adminhtml\Context $context
) {
parent::__construct($amazonFactory, $context);
- $this->productTypeCollectionFactory = $productTypeCollectionFactory;
- $this->dictionaryProductTypeResource = $dictionaryProductTypeResource;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
}
public function execute(): \Magento\Framework\Controller\ResultInterface
@@ -33,7 +28,7 @@ public function execute(): \Magento\Framework\Controller\ResultInterface
}
$this->setJsonContent([
- 'result' => $this->isUniqueTitle($title, (int)$marketplaceId, (int)$productTypeId)
+ 'result' => $this->isUniqueTitle($title, (int)$marketplaceId, (int)$productTypeId),
]);
return $this->getResult();
@@ -41,19 +36,12 @@ public function execute(): \Magento\Framework\Controller\ResultInterface
private function isUniqueTitle(string $title, int $marketplaceId, int $productTypeId): bool
{
- $collection = $this->productTypeCollectionFactory->create();
- $collection->joinInner(
- ['dictionary' => $this->dictionaryProductTypeResource->getMainTable()],
- 'dictionary.id = dictionary_product_type_id',
- ['marketplace_id' => 'marketplace_id']
+ $exist = $this->templateProductTypeRepository->findByTitleMarketplace(
+ $title,
+ $marketplaceId,
+ $productTypeId > 0 ? $productTypeId : null
);
- $collection->addFieldToFilter('main_table.title', ['eq' => $title]);
- $collection->addFieldToFilter('dictionary.marketplace_id', ['eq' => $marketplaceId]);
- if ($productTypeId > 0) {
- $collection->addFieldToFilter('main_table.id', ['neq' => $productTypeId]);
- }
-
- return $collection->getSize() === 0;
+ return $exist === null;
}
}
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/Save.php b/Controller/Adminhtml/Amazon/Template/ProductType/Save.php
index 07f12be4a..602aeade2 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/Save.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/Save.php
@@ -1,27 +1,16 @@
dataHelper = $dataHelper;
$this->productTypeFactory = $productTypeFactory;
$this->productTypeBuilderFactory = $productTypeBuilderFactory;
- $this->productTypeCollectionFactory = $productTypeCollectionFactory;
$this->productTypeSnapshotBuilderFactory = $productTypeSnapshotBuilderFactory;
$this->productTypeDiffFactory = $productTypeDiffFactory;
$this->productTypeAffectedProductsFactory = $productTypeAffectedProductsFactory;
$this->productTypeChangeProcessorFactory = $productTypeChangeProcessorFactory;
$this->registryManager = $registryManager;
$this->attributeMappingManagerFactory = $attributeMappingManagerFactory;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
+ $this->urlHelper = $urlHelper;
}
- /**
- * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|\Magento\Framework\View\Result\Page
- * @throws \Ess\M2ePro\Model\Exception\Logic|\Magento\Framework\Exception\LocalizedException
- */
public function execute()
{
$post = $this->getRequest()->getPostValue();
@@ -75,10 +62,12 @@ public function execute()
'status' => false,
'message' => 'Incorrect input',
]);
+
return $this->getResult();
}
$this->_forward('index');
+
return;
}
@@ -95,6 +84,7 @@ public function execute()
'status' => false,
'message' => $message,
]);
+
return $this->getResult();
}
@@ -107,7 +97,7 @@ public function execute()
}
if ($this->isTryingOverrideExistingSettings((int)$temp['marketplace_id'], (string)$temp['nick'])) {
- $message = $this->__(
+ $message = __(
'Product Type Settings were not saved: duplication of Product Type Settings'
. ' for marketplace is not allowed.'
);
@@ -117,6 +107,7 @@ public function execute()
'status' => false,
'message' => $message,
]);
+
return $this->getResult();
}
@@ -127,10 +118,11 @@ public function execute()
}
$builder = $this->productTypeBuilderFactory->create();
- $productType = $this->productTypeFactory->create();
+
+ $productType = $this->productTypeFactory->createEmpty();
if ($id) {
- $productType->load($id);
+ $productType = $this->templateProductTypeRepository->get($id);
}
$oldData = [];
@@ -139,8 +131,8 @@ public function execute()
}
$builder->build($productType, $post);
- $productType = $builder->getModel();
- $this->messageManager->addSuccessMessage($this->__('Product Type Settings were saved'));
+
+ $this->messageManager->addSuccessMessage(__('Product Type Settings were saved'));
$newData = $this->makeSnapshot($productType);
@@ -160,7 +152,7 @@ public function execute()
$attributeMappingManager = $this->attributeMappingManagerFactory->create($productType);
$attributeMappingManager->createNewMappings();
- $backUrl = $this->dataHelper->getBackUrl(
+ $backUrl = $this->urlHelper->getBackUrl(
'*/amazon_template_productType/index',
[],
['edit' => ['id' => $productType->getId()]]
@@ -198,33 +190,16 @@ public function execute()
* This code prevents attempt to create duplicate when user tries to create new product type settings.
* Situation like this possible when one user starts to create product type, another user creates the same one,
* and first user saves settings for same (marketplace_id, nick).
- *
- * @param int $marketplaceId
- * @param string $nick
- *
- * @return bool
- * @throws \Magento\Framework\Exception\LocalizedException
*/
private function isTryingOverrideExistingSettings(
int $marketplaceId,
string $nick
): bool {
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\Collection $collection */
- $collection = $this->productTypeCollectionFactory->create()
- ->appendFilterMarketplaceId($marketplaceId)
- ->appendFilterNick($nick);
+ $template = $this->templateProductTypeRepository->findByMarketplaceIdAndNick($marketplaceId, $nick);
- /** @var \Ess\M2ePro\Model\Amazon\Template\ProductType $item */
- $item = $collection->getFirstItem();
-
- return (bool)$item->getId();
+ return $template !== null;
}
- /**
- * @param \Ess\M2ePro\Model\Amazon\Template\ProductType $productType
- *
- * @return array
- */
private function makeSnapshot(
\Ess\M2ePro\Model\Amazon\Template\ProductType $productType
): array {
diff --git a/Controller/Adminhtml/Amazon/Template/ProductType/SearchProductTypePopup.php b/Controller/Adminhtml/Amazon/Template/ProductType/SearchProductTypePopup.php
index 5e190de1d..10f0023c9 100644
--- a/Controller/Adminhtml/Amazon/Template/ProductType/SearchProductTypePopup.php
+++ b/Controller/Adminhtml/Amazon/Template/ProductType/SearchProductTypePopup.php
@@ -1,36 +1,35 @@
productTypeHelper = $productTypeHelper;
+ $this->dictionaryMarketplace = $dictionaryMarketplace;
+ $this->amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
+ $this->dictionaryMarketplaceService = $dictionaryMarketplaceService;
}
public function execute()
{
$marketplaceId = $this->getRequest()->getParam('marketplace_id');
- if (!$marketplaceId) {
+ if ($marketplaceId === null) {
$this->setJsonContent([
'result' => false,
'message' => 'You should provide correct marketplace_id.',
@@ -39,7 +38,7 @@ public function execute()
return $this->getResult();
}
- $productTypes = $this->getAvailableProductTypes((int)$marketplaceId);
+ $productTypes = $this->getAvailableProductTypes($this->amazonMarketplaceRepository->get((int)$marketplaceId));
/** @var \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Edit\Tabs\General\SearchPopup $block */
$block = $this->getLayout()
@@ -52,18 +51,11 @@ public function execute()
return $this->getResult();
}
- /**
- * @param int $marketplaceId
- *
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- private function getAvailableProductTypes(int $marketplaceId): array
+ private function getAvailableProductTypes(\Ess\M2ePro\Model\Marketplace $marketplace): array
{
- $marketplaceDictionaryItem = $this->productTypeHelper->getMarketplaceDictionary($marketplaceId);
- if (!$marketplaceDictionaryItem->getId()) {
- return [];
+ $marketplaceDictionaryItem = $this->dictionaryMarketplace->findByMarketplace($marketplace);
+ if ($marketplaceDictionaryItem === null) {
+ $marketplaceDictionaryItem = $this->dictionaryMarketplaceService->update($marketplace);
}
$productTypes = $marketplaceDictionaryItem->getProductTypes();
@@ -72,7 +64,10 @@ private function getAvailableProductTypes(int $marketplaceId): array
}
$result = [];
- $alreadyUsedProductTypes = $this->productTypeHelper->getConfiguredProductTypesList($marketplaceId);
+ $alreadyUsedProductTypes = [];
+ foreach ($this->templateProductTypeRepository->findByMarketplaceId((int)$marketplace->getId()) as $template) {
+ $alreadyUsedProductTypes[$template->getDictionary()->getNick()] = (int)$template->getId();
+ }
foreach ($productTypes as $productType) {
$productTypeData = [
@@ -80,7 +75,7 @@ private function getAvailableProductTypes(int $marketplaceId): array
'title' => $productType['title'],
];
- if (!empty($alreadyUsedProductTypes[$productType['nick']])) {
+ if (isset($alreadyUsedProductTypes[$productType['nick']])) {
$productTypeData['exist_product_type_id'] = $alreadyUsedProductTypes[$productType['nick']];
}
$result[] = $productTypeData;
diff --git a/Controller/Adminhtml/General/IsMarketplaceEnabled.php b/Controller/Adminhtml/General/IsMarketplaceEnabled.php
index f19430603..26a988d7e 100644
--- a/Controller/Adminhtml/General/IsMarketplaceEnabled.php
+++ b/Controller/Adminhtml/General/IsMarketplaceEnabled.php
@@ -1,11 +1,5 @@
marketplaceCollectionFactory = $marketplaceCollectionFactory;
- $this->marketplaceSynchronizationFactory = $marketplaceSynchronizationFactory;
$this->servicingDispatcherFactory = $servicingDispatcherFactory;
+ $this->amazonDictionaryMarketplaceService = $amazonDictionaryMarketplaceService;
}
public function execute()
@@ -74,7 +67,6 @@ private function updateMarketplacesBuild(): bool
->addFieldToFilter('component_mode', \Ess\M2ePro\Helper\Component\Amazon::NICK)
->addFieldToFilter('status', 1);
- /** @var \Ess\M2ePro\Model\Marketplace $item */
foreach ($marketplaceCollection->getItems() as $item) {
if (!$this->updateMarketplaceBuild($item)) {
return false;
@@ -86,33 +78,11 @@ private function updateMarketplacesBuild(): bool
private function updateMarketplaceBuild(\Ess\M2ePro\Model\Marketplace $marketplace): bool
{
- $synchronization = $this->marketplaceSynchronizationFactory->create()
- ->setMarketplace($marketplace);
-
- if ($synchronization->isLocked()) {
- $message = $this->__(
- 'Marketplaces cannot be updated now. '
- . 'Please wait until another marketplace synchronization is completed, then try again.'
- );
-
- $synchronization->getLog()->addMessage(
- $message,
- \Ess\M2ePro\Model\Log\AbstractModel::TYPE_ERROR
- );
-
- $this->errorMessage = $message;
-
- return false;
- }
-
try {
- $synchronization->process();
- } catch (\Exception $e) {
- $synchronization->getLog()->addMessageFromException($e);
+ $this->amazonDictionaryMarketplaceService->update($marketplace);
+ } catch (\Throwable $e) {
$this->errorMessage = $e->getMessage();
- $synchronization->getLockItemManager()->remove();
-
$this->servicingDispatcherFactory->create()->processTask(
\Ess\M2ePro\Model\Servicing\Task\License::NAME
);
diff --git a/Controller/Adminhtml/Wizard/AmazonMigrationToProductTypes/Index.php b/Controller/Adminhtml/Wizard/AmazonMigrationToProductTypes/Index.php
index db8b1e0d3..112a0cb1f 100644
--- a/Controller/Adminhtml/Wizard/AmazonMigrationToProductTypes/Index.php
+++ b/Controller/Adminhtml/Wizard/AmazonMigrationToProductTypes/Index.php
@@ -1,11 +1,5 @@
amazonDictionaryMarketplaceService = $amazonDictionaryMarketplaceService;
+ }
+
public function execute()
{
- // @codingStandardsIgnoreLine
- session_write_close();
-
$component = $this->getRequest()->getParam('component');
/** @var \Ess\M2ePro\Model\Marketplace $marketplace */
$marketplace = $this->activeRecordFactory->getObjectLoaded(
@@ -24,7 +26,24 @@ public function execute()
(int)$this->getRequest()->getParam('marketplace_id')
);
+ if (strtolower($component) === 'amazon') {
+ try {
+ $this->amazonDictionaryMarketplaceService->update($marketplace);
+
+ $this->setJsonContent(['result' => 'success']);
+ } catch (\Throwable $e) {
+ $this->setJsonContent(['result' => 'error']);
+ }
+
+ return $this->getResult();
+ }
+
+ // @codingStandardsIgnoreLine
+ session_write_close();
+
$component = ucfirst(strtolower($component));
+
+ /** @var \Ess\M2ePro\Model\Ebay\Marketplace\Synchronization|\Ess\M2ePro\Model\Walmart\Marketplace\Synchronization $synchronization */
$synchronization = $this->modelFactory->getObject($component . '_Marketplace_Synchronization');
$synchronization->setMarketplace($marketplace);
@@ -44,7 +63,7 @@ public function execute()
try {
$synchronization->process();
- } catch (\Exception $e) {
+ } catch (\Throwable $e) {
$synchronization->getlog()->addMessageFromException($e);
$synchronization->getLockItemManager()->remove();
diff --git a/Helper/Component/Amazon.php b/Helper/Component/Amazon.php
index faf802c3c..297a33d07 100644
--- a/Helper/Component/Amazon.php
+++ b/Helper/Component/Amazon.php
@@ -10,8 +10,6 @@ class Amazon
{
public const NICK = 'amazon';
- public const MARKETPLACE_SYNCHRONIZATION_LOCK_ITEM_NICK = 'amazon_marketplace_synchronization';
-
public const MARKETPLACE_CA = 24;
public const MARKETPLACE_DE = 25;
public const MARKETPLACE_FR = 26;
@@ -224,14 +222,6 @@ public function getCarrierTitle($carrierCode, $title): string
return $carriers[$carrierCode] ?? $title;
}
- public function getMarketplacesAvailableForApiCreation()
- {
- return $this->amazonFactory->getObject('Marketplace')->getCollection()
- ->addFieldToFilter('component_mode', self::NICK)
- ->addFieldToFilter('status', \Ess\M2ePro\Model\Marketplace::STATUS_ENABLE)
- ->setOrder('sorder', 'ASC');
- }
-
public function getMarketplacesList()
{
$collection = $this->marketplaceCollectionFactory->create();
@@ -276,11 +266,6 @@ public function getAmazonShippingMap($amazonCode, $marketplaceId, $location)
return $collection->getFirstItem();
}
- public function getMarketplacesAvailableForAsinCreation()
- {
- return $this->getMarketplacesAvailableForApiCreation()->addFieldToFilter('is_new_asin_available', 1);
- }
-
/**
* @return \Ess\M2ePro\Model\ResourceModel\Account\Collection
*/
diff --git a/Helper/Component/Amazon/ProductType.php b/Helper/Component/Amazon/ProductType.php
index 1f0e78b47..28a1ace58 100644
--- a/Helper/Component/Amazon/ProductType.php
+++ b/Helper/Component/Amazon/ProductType.php
@@ -2,12 +2,6 @@
namespace Ess\M2ePro\Helper\Component\Amazon;
-use Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\Marketplace\CollectionFactory
- as MarketplaceDictionaryCollectionFactory;
-use Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType\CollectionFactory
- as ProductTypeDictionaryCollectionFactory;
-use Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory as ProductTypeCollectionFactory;
-
class ProductType
{
public const SPECIFIC_KEY_NAME = 'item_name#array/value';
@@ -21,412 +15,7 @@ class ProductType
public const SPECIFIC_KEY_OTHER_OFFER_IMAGE_LOCATOR = 'other_offer_image_locator_1#array/media_location';
public const SPECIFIC_KEY_BULLET_POINT = 'bullet_point#array/value';
- /** @var ProductTypeCollectionFactory */
- private $productTypeCollectionFactory;
- /** @var ProductTypeDictionaryCollectionFactory */
- private $productTypeDictionaryCollectionFactory;
- /** @var MarketplaceDictionaryCollectionFactory */
- private $marketplaceDictionaryCollectionFactory;
- /** @var \Ess\M2ePro\Model\Amazon\Template\ProductTypeFactory */
- private $productTypeFactory;
- /** @var \Ess\M2ePro\Model\MarketplaceFactory */
- private $marketplaceFactory;
- /** @var \Ess\M2ePro\Model\ResourceModel\Listing\Product\CollectionFactory */
- private $listingProductCollectionFactory;
- /** @var \Ess\M2ePro\Model\Amazon\Connector\DispatcherFactory */
- private $amazonConnectorDispatcherFactory;
- /** @var array */
- private $marketplaceDictionaryCache = [];
- /** @var array */
- private $marketplaceDictionaryProductTypeCache = [];
- /** @var \Ess\M2ePro\Model\Amazon\ProductType\AttributeMapping\Suggester */
- private $attributesSuggester;
- /** @var \Ess\M2ePro\Model\ResourceModel\Marketplace\CollectionFactory */
- private $marketplaceCollectionFactory;
-
- public function __construct(
- ProductTypeCollectionFactory $productTypeCollectionFactory,
- ProductTypeDictionaryCollectionFactory $productTypeDictionaryCollectionFactory,
- MarketplaceDictionaryCollectionFactory $marketplaceDictionaryCollectionFactory,
- \Ess\M2ePro\Model\Amazon\Template\ProductTypeFactory $productTypeFactory,
- \Ess\M2ePro\Model\MarketplaceFactory $marketplaceFactory,
- \Ess\M2ePro\Model\ResourceModel\Listing\Product\CollectionFactory $listingProductCollectionFactory,
- \Ess\M2ePro\Model\Amazon\Connector\DispatcherFactory $amazonConnectorDispatcherFactory,
- \Ess\M2ePro\Model\Amazon\ProductType\AttributeMapping\Suggester $attributesSuggester,
- \Ess\M2ePro\Model\ResourceModel\Marketplace\CollectionFactory $marketplaceCollectionFactory
- ) {
- $this->productTypeCollectionFactory = $productTypeCollectionFactory;
- $this->productTypeDictionaryCollectionFactory = $productTypeDictionaryCollectionFactory;
- $this->marketplaceDictionaryCollectionFactory = $marketplaceDictionaryCollectionFactory;
- $this->productTypeFactory = $productTypeFactory;
- $this->marketplaceFactory = $marketplaceFactory;
- $this->listingProductCollectionFactory = $listingProductCollectionFactory;
- $this->amazonConnectorDispatcherFactory = $amazonConnectorDispatcherFactory;
- $this->attributesSuggester = $attributesSuggester;
- $this->marketplaceCollectionFactory = $marketplaceCollectionFactory;
- }
-
- /**
- * @param int $id
- *
- * @return \Ess\M2ePro\Model\Amazon\Dictionary\ProductType
- */
- public function getProductTypeDictionaryById(int $id): \Ess\M2ePro\Model\Amazon\Dictionary\ProductType
- {
- $collection = $this->productTypeDictionaryCollectionFactory->create();
- $collection->getSelect()->where('id = ?', $id);
-
- /** @var \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $item */
- $item = $collection->getFirstItem();
-
- return $item;
- }
-
- /**
- * @param int $marketplaceId
- * @param string $nick
- * @param bool $allowReceive
- *
- * @return \Ess\M2ePro\Model\Amazon\Dictionary\ProductType
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function getProductTypeDictionary(
- int $marketplaceId,
- string $nick,
- bool $allowReceive = true
- ): \Ess\M2ePro\Model\Amazon\Dictionary\ProductType {
- $collection = $this->productTypeDictionaryCollectionFactory->create()
- ->appendFilterNick($nick)
- ->appendFilterMarketplaceId($marketplaceId);
-
- /** @var \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $item */
- $item = $collection->getFirstItem();
-
- if (!$item->getId() && $allowReceive) {
- $this->updateProductTypeDictionary($item, $marketplaceId, $nick);
- return $this->getProductTypeDictionary($marketplaceId, $nick, false);
- }
-
- return $item;
- }
-
- /**
- * @param int $marketplaceId
- * @param string $nick
- * @param bool $onlyRequired
- *
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function getProductTypeScheme(int $marketplaceId, string $nick, bool $onlyRequired = false): array
- {
- $item = $this->getProductTypeDictionary($marketplaceId, $nick);
- if (!$item->getId()) {
- return [];
- }
-
- if (!$onlyRequired) {
- return $item->getScheme();
- }
-
- $scheme = [];
- foreach ($item->getScheme() as $attribute) {
- if ($attribute['validation_rules']['is_required']) {
- $scheme[] = $attribute;
- }
- }
-
- return $scheme;
- }
-
- /**
- * @param int $marketplaceId
- *
- * @return \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace
- */
- public function getMarketplaceDictionary(int $marketplaceId): \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace
- {
- if (isset($this->marketplaceDictionaryCache[$marketplaceId])) {
- return $this->marketplaceDictionaryCache[$marketplaceId];
- }
-
- $collection = $this->marketplaceDictionaryCollectionFactory->create()
- ->appendFilterMarketplaceId($marketplaceId);
-
- /** @var \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace $item */
- $item = $collection->getFirstItem();
- $this->marketplaceDictionaryCache[$marketplaceId] = $item;
-
- return $item;
- }
-
- /**
- * @param int $marketplaceId
- * @param string $nick
- *
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- private function getMarketplaceDictionaryProductType(int $marketplaceId, string $nick): array
- {
- if (isset($this->marketplaceDictionaryProductTypeCache[$marketplaceId][$nick])) {
- return $this->marketplaceDictionaryProductTypeCache[$marketplaceId][$nick];
- }
-
- $marketplaceDictionary = $this->getMarketplaceDictionary($marketplaceId);
- if (!$marketplaceDictionary->getId()) {
- $this->marketplaceDictionaryProductTypeCache[$marketplaceId][$nick] = [];
- return [];
- }
-
- $productTypes = $marketplaceDictionary->getProductTypes();
- $data = !empty($productTypes[$nick]) ? $productTypes[$nick] : [];
-
- $this->marketplaceDictionaryProductTypeCache[$marketplaceId][$nick] = $data;
- return $data;
- }
-
- /**
- * @param int $marketplaceId
- * @param string $nick
- * @param array|null $onlyForAttributes
- *
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function getProductTypeGroups(int $marketplaceId, string $nick, array $onlyForAttributes = []): array
- {
- $data = $this->getMarketplaceDictionaryProductType($marketplaceId, $nick);
- if (empty($data)) {
- return [];
- }
-
- $groups = !empty($data['groups']) && is_array($data['groups']) ? $data['groups'] : [];
- if ($onlyForAttributes === []) {
- return $groups;
- }
-
- $groupNicks = array_unique(array_column($onlyForAttributes, 'group_nick'));
- $requiredGroups = [];
- foreach ($groups as $group) {
- if (in_array($group['nick'], $groupNicks)) {
- $requiredGroups[] = $group;
- }
- }
-
- return $requiredGroups;
- }
-
- /**
- * @param int $marketplaceId
- * @param string $nick
- *
- * @return string
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- private function getProductTypeTitle(int $marketplaceId, string $nick): string
- {
- $data = $this->getMarketplaceDictionaryProductType($marketplaceId, $nick);
-
- return !empty($data['title']) && is_string($data['title']) ?
- $data['title'] : 'unknown';
- }
-
- /**
- * @param int $id
- *
- * @return \Ess\M2ePro\Model\Amazon\Template\ProductType
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function getProductTypeById(int $id): \Ess\M2ePro\Model\Amazon\Template\ProductType
- {
- $productType = $this->productTypeFactory->create();
- $productType->load($id);
-
- return $productType;
- }
-
- /**
- * @param int $marketplaceId
- * @param string $nick
- *
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function getProductTypeSettings(int $marketplaceId, string $nick): array
- {
- $collection = $this->productTypeCollectionFactory->create()
- ->appendFilterNick($nick)
- ->appendFilterMarketplaceId($marketplaceId);
-
- /** @var \Ess\M2ePro\Model\Amazon\Template\ProductType $item */
- $item = $collection->getFirstItem();
- if (!$item->getId()) {
- return [];
- }
-
- return $item->getSettings('settings');
- }
-
- /**
- * @param \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productTypeDictionary
- * @param int $marketplaceId
- * @param string $nick
- *
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function updateProductTypeDictionary(
- \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productTypeDictionary,
- int $marketplaceId,
- string $nick
- ): void {
- $dispatcher = $this->amazonConnectorDispatcherFactory->create();
-
- /** @var \Ess\M2ePro\Model\Amazon\Connector\Marketplace\Get\Specifics $connector */
- $connector = $dispatcher->getConnector(
- 'marketplace',
- 'get',
- 'specifics',
- [
- 'marketplace' => $this->getMarketplaceNativeId($marketplaceId),
- 'product_type_nick' => $nick,
- ]
- );
-
- $dispatcher->process($connector);
- $responseData = $connector->getResponseData();
-
- if (!$productTypeDictionary->getId()) {
- $productTypeDictionary->setMarketplaceId($marketplaceId)
- ->setNick($nick);
- }
-
- $productTypeDictionary->setScheme($responseData['specifics'])
- ->setTitle($this->getProductTypeTitle($marketplaceId, $nick));
- $productTypeDictionary->save();
- }
-
- /**
- * @param int $marketplaceId
- * @param bool $onlyValid
- *
- * @return array
- */
- public function getProductTypesInDictionary(int $marketplaceId, bool $onlyValid = false): array
- {
- $collection = $this->productTypeDictionaryCollectionFactory->create()
- ->appendFilterMarketplaceId($marketplaceId);
-
- if ($onlyValid) {
- $collection->appendFilterInvalid(false);
- }
-
- return $collection->getItems();
- }
-
- /**
- * @param int $marketplaceId
- *
- * @return int
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- private function getMarketplaceNativeId(int $marketplaceId): int
- {
- /** @var \Ess\M2ePro\Model\Marketplace $a */
- $marketplace = $this->marketplaceFactory->create();
- $marketplace->load($marketplaceId);
-
- return $marketplace->getNativeId();
- }
-
- /**
- * @param int $marketplaceId
- *
- * @return array
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function getConfiguredProductTypesList(int $marketplaceId): array
- {
- $collection = $this->productTypeCollectionFactory->create()
- ->appendFilterMarketplaceId($marketplaceId);
-
- $result = [];
- /** @var \Ess\M2ePro\Model\Amazon\Template\ProductType $item */
- foreach ($collection->getItems() as $item) {
- $result[$item->getNick()] = (int)$item->getId();
- }
-
- return $result;
- }
-
- /**
- * @param int $templateProductTypeId
- *
- * @return bool
- */
- public function isProductTypeUsingInProducts(int $templateProductTypeId): bool
- {
- $collection = $this->listingProductCollectionFactory->create([
- 'childMode' => \Ess\M2ePro\Helper\Component\Amazon::NICK,
- ]);
-
- $collection->getSelect()->where('template_product_type_id = ?', $templateProductTypeId);
-
- return (bool)$collection->getSize();
- }
-
- /**
- * @param int $marketplaceId
- * @param array $nicks
- *
- * @return void
- */
- public function markProductTypeDictionariesInvalid(int $marketplaceId, array $nicks): void
- {
- if (empty($nicks)) {
- return;
- }
-
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType\Collection $collection */
- $collection = $this->productTypeDictionaryCollectionFactory->create()
- ->appendFilterMarketplaceId($marketplaceId)
- ->appendFilterNicks($nicks);
-
- $collection->setDataToAll('invalid', 1)
- ->save();
- }
-
- /**
- * @param int $marketplaceId
- * @param array $nicks
- *
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function removeProductTypeDictionaries(int $marketplaceId, array $nicks): void
- {
- if (empty($nicks)) {
- return;
- }
-
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType\Collection $collection */
- $collection = $this->productTypeDictionaryCollectionFactory->create()
- ->appendFilterMarketplaceId($marketplaceId)
- ->appendFilterNicks($nicks);
-
- /** @var \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $item */
- foreach ($collection->getItems() as $item) {
- $item->delete();
- }
- }
-
- /**
- * @return int
- * @throws \Exception
- */
- public function getTimezoneShift(): int
+ public static function getTimezoneShift(): int
{
$dateLocal = \Ess\M2ePro\Helper\Date::createDateInCurrentZone('2022-01-01');
$dateUTC = \Ess\M2ePro\Helper\Date::createDateGmt($dateLocal->format('Y-m-d H:i:s'));
@@ -434,12 +23,7 @@ public function getTimezoneShift(): int
return $dateUTC->getTimestamp() - $dateLocal->getTimestamp();
}
- public function getSpecificsDefaultSettings(): array
- {
- return $this->attributesSuggester->getSuggestedAttributes();
- }
-
- public function getMainImageSpecifics(): array
+ public static function getMainImageSpecifics(): array
{
return [
self::SPECIFIC_KEY_MAIN_PRODUCT_IMAGE_LOCATOR,
@@ -447,7 +31,7 @@ public function getMainImageSpecifics(): array
];
}
- public function getOtherImagesSpecifics(): array
+ public static function getOtherImagesSpecifics(): array
{
return [
'other_product_image_locator_1#array/media_location',
@@ -455,7 +39,7 @@ public function getOtherImagesSpecifics(): array
];
}
- public function getRecommendedBrowseNodesLink(int $marketplaceId): string
+ public static function getRecommendedBrowseNodesLink(int $marketplaceId): string
{
$map = [
\Ess\M2ePro\Helper\Component\Amazon::MARKETPLACE_UK
@@ -474,7 +58,7 @@ public function getRecommendedBrowseNodesLink(int $marketplaceId): string
return '';
}
- return __(
+ return (string)__(
'View latest Browse Node ID List ',
['url' => $map[$marketplaceId]]
);
diff --git a/Helper/Component/Amazon/Variation.php b/Helper/Component/Amazon/Variation.php
index 601034ddc..d7e0574b1 100644
--- a/Helper/Component/Amazon/Variation.php
+++ b/Helper/Component/Amazon/Variation.php
@@ -1,19 +1,11 @@
modelFactory = $modelFactory;
$this->activeRecordFactory = $activeRecordFactory;
$this->amazonParentFactory = $amazonParentFactory;
$this->resourceConnection = $resourceConnection;
@@ -271,9 +261,6 @@ public function filterProductsByProductType($productsIds)
public function filterParentProductsByVariationTheme($productsIds)
{
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Details $detailsModel */
- $detailsModel = $this->modelFactory->getObject('Amazon_Marketplace_Details');
-
foreach ($productsIds as $key => $productId) {
/** @var \Ess\M2ePro\Model\Listing\Product $listingProduct */
$listingProduct = $this->amazonParentFactory->getObjectLoaded('Listing\Product', $productId);
@@ -285,19 +272,15 @@ public function filterParentProductsByVariationTheme($productsIds)
continue;
}
- $detailsModel->setMarketplaceId($listingProduct->getListing()->getMarketplaceId());
-
$productType = $amazonListingProduct->getProductTypeTemplate();
if ($productType === null) {
unset($productsIds[$key]);
continue;
}
- $themes = $detailsModel->getVariationThemes(
- $productType->getNick()
- );
+ $dictionary = $productType->getDictionary();
- if (empty($themes)) {
+ if (!$dictionary->hasVariationThemes()) {
unset($productsIds[$key]);
}
}
@@ -357,6 +340,4 @@ private function removeThemeUsageDataCache()
$cacheKey = __CLASS__ . self::DATA_REGISTRY_KEY;
$this->cachePermanent->removeValue($cacheKey);
}
-
- //########################################
}
diff --git a/Helper/Component/Amazon/Vocabulary.php b/Helper/Component/Amazon/Vocabulary.php
index 70e089b16..08ea2ad28 100644
--- a/Helper/Component/Amazon/Vocabulary.php
+++ b/Helper/Component/Amazon/Vocabulary.php
@@ -148,14 +148,10 @@ public function getParentListingsProductsAffectedToAttribute($channelAttribute)
continue;
}
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Details $marketplaceDetails */
- $marketplaceDetails = $this->modelFactory->getObject('Amazon_Marketplace_Details');
- $marketplaceDetails->setMarketplaceId($newListingProduct->getListing()->getMarketplaceId());
-
- foreach ($marketplaceDetails->getVariationThemes($productTypeTemplate->getNick()) as $themeData) {
+ foreach ($productTypeTemplate->getDictionary()->getVariationThemes() as $themeData) {
$themeAttributes = $themeData['attributes'];
- if (count($themeAttributes) != count($productAttributes)) {
+ if (count($themeAttributes) !== count($productAttributes)) {
continue;
}
diff --git a/Helper/Module/Database/Structure.php b/Helper/Module/Database/Structure.php
index b9db8c17f..dc650d81f 100644
--- a/Helper/Module/Database/Structure.php
+++ b/Helper/Module/Database/Structure.php
@@ -1,11 +1,5 @@
modelFactory = $modelFactory;
}
- /**
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function addMessages(): void
{
/** @var \Ess\M2ePro\Model\Issue\Notification\Channel\Magento\Session $notificationChannel */
$notificationChannel = $this->modelFactory->getObject('Issue_Notification_Channel_Magento_Session');
$issueLocators = [
- 'Amazon_Marketplace_Issue_NotUpdated',
+ 'Amazon_Marketplace_Issue_ProductTypeOutOfDate',
'Amazon_Repricing_Issue_InvalidToken',
];
foreach ($issueLocators as $locator) {
- /** @var LocatorInterface $locatorModel */
+ /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Issue\ProductTypeOutOfDate|\Ess\M2ePro\Model\Amazon\Repricing\Issue\InvalidToken $locatorModel */
$locatorModel = $this->modelFactory->getObject($locator);
foreach ($locatorModel->getIssues() as $issue) {
diff --git a/Model/ActiveRecord/Component/Parent/AbstractModel.php b/Model/ActiveRecord/Component/Parent/AbstractModel.php
index 2e7327628..7f56f2071 100644
--- a/Model/ActiveRecord/Component/Parent/AbstractModel.php
+++ b/Model/ActiveRecord/Component/Parent/AbstractModel.php
@@ -142,9 +142,9 @@ public function isComponentModeEbay()
return $this->getComponentMode() == \Ess\M2ePro\Helper\Component\Ebay::NICK;
}
- public function isComponentModeAmazon()
+ public function isComponentModeAmazon(): bool
{
- return $this->getComponentMode() == \Ess\M2ePro\Helper\Component\Amazon::NICK;
+ return $this->getComponentMode() === \Ess\M2ePro\Helper\Component\Amazon::NICK;
}
public function isComponentModeWalmart()
diff --git a/Model/Amazon/Connector/DispatcherFactory.php b/Model/Amazon/Connector/DispatcherFactory.php
index 77d14f9e8..ec9bb483b 100644
--- a/Model/Amazon/Connector/DispatcherFactory.php
+++ b/Model/Amazon/Connector/DispatcherFactory.php
@@ -1,17 +1,12 @@
true,
+ 'marketplace' => $this->params['marketplace_id'],
+ ];
+ }
+
+ protected function validateResponse(): bool
+ {
+ $response = $this->getResponse()->getResponseData();
+
+ return isset($response['info']['details']['product_type']);
+ }
+}
diff --git a/Model/Amazon/Connector/Marketplace/Get/Specifics.php b/Model/Amazon/Connector/Marketplace/Get/Specifics.php
deleted file mode 100644
index bcd414869..000000000
--- a/Model/Amazon/Connector/Marketplace/Get/Specifics.php
+++ /dev/null
@@ -1,58 +0,0 @@
- $this->params['marketplace'],
- 'product_type_nick' => $this->params['product_type_nick'],
- ];
- }
-
- /**
- * @return array
- */
- protected function getCommand(): array
- {
- return ['marketplace', 'get', 'specifics'];
- }
-
- /**
- * @return bool
- */
- protected function validateResponse(): bool
- {
- $responseData = $this->getResponse()->getResponseData();
-
- return array_key_exists('specifics', $responseData)
- && (
- is_array($responseData['specifics'])
- || $responseData['specifics'] === null
- );
- }
-
- /**
- * @throws \Exception
- */
- protected function prepareResponseData(): void
- {
- $responseData = $this->getResponse()->getResponseData();
- if (!is_array($responseData['specifics'])) {
- $responseData['specifics'] = [];
- }
-
- $this->responseData = $responseData;
- }
-}
diff --git a/Model/Amazon/Connector/ProductType/Get/Info.php b/Model/Amazon/Connector/ProductType/Get/Info.php
new file mode 100644
index 000000000..edbf3937b
--- /dev/null
+++ b/Model/Amazon/Connector/ProductType/Get/Info.php
@@ -0,0 +1,35 @@
+ $this->params['product_type_nick'],
+ 'marketplace' => $this->params['marketplace_id'],
+ ];
+ }
+
+ protected function validateResponse(): bool
+ {
+ $response = $this->getResponse()->getResponseData();
+
+ return isset(
+ $response['nick'],
+ $response['title'],
+ $response['attributes'],
+ $response['attributes_groups'],
+ $response['variation_themes'],
+ $response['last_update']
+ );
+ }
+}
diff --git a/Model/Amazon/Connector/Protocol.php b/Model/Amazon/Connector/Protocol.php
index 79b4b1c1c..3cb484dd9 100644
--- a/Model/Amazon/Connector/Protocol.php
+++ b/Model/Amazon/Connector/Protocol.php
@@ -1,28 +1,16 @@
columns(
[
sprintf(
- 'DATE_FORMAT(purchase_update_date, "%s") AS date',
+ 'DATE_FORMAT(%s, "%s") AS date',
+ AmazonOrderResource::COLUMN_PURCHASE_CREATE_DATE,
$isHourlyInterval ? '%Y-%m-%d %H' : '%Y-%m-%d'
),
sprintf('%s AS value', $valueColumn),
@@ -99,15 +98,16 @@ private function getPointSet(string $valueColumn, DateRange $dateRange, bool $is
);
$select->where(
sprintf(
- "purchase_update_date BETWEEN '%s' AND '%s'",
+ "%s BETWEEN '%s' AND '%s'",
+ AmazonOrderResource::COLUMN_PURCHASE_CREATE_DATE,
$dateRange->getDateStart()->format('Y-m-d H:i:s'),
$dateRange->getDateEnd()->format('Y-m-d H:i:s')
)
);
if ($isHourlyInterval) {
- $select->group('HOUR(main_table.purchase_update_date)');
+ $select->group(sprintf('HOUR(main_table.%s)', AmazonOrderResource::COLUMN_PURCHASE_CREATE_DATE));
}
- $select->group('DAY(main_table.purchase_update_date)');
+ $select->group(sprintf('DAY(main_table.%s)', AmazonOrderResource::COLUMN_PURCHASE_CREATE_DATE));
$select->order('date');
$queryData = $select->query()->fetchAll();
diff --git a/Model/Amazon/Dictionary/Marketplace.php b/Model/Amazon/Dictionary/Marketplace.php
index 0c24bddd8..f196a63f6 100644
--- a/Model/Amazon/Dictionary/Marketplace.php
+++ b/Model/Amazon/Dictionary/Marketplace.php
@@ -1,83 +1,41 @@
_init(\Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\Marketplace::class);
}
- public function getId(): int
- {
- return (int)parent::getId();
- }
-
- public function getMarketplaceId(): int
- {
- return (int)$this->getData('marketplace_id');
- }
-
- public function setMarketplaceId(int $marketplaceId): self
- {
- $this->setData('marketplace_id', $marketplaceId);
+ public function create(
+ \Ess\M2ePro\Model\Marketplace $marketplace,
+ array $productTypes
+ ): self {
+ $this->setData(ResourceModel::COLUMN_MARKETPLACE_ID, $marketplace->getId())
+ ->setData(ResourceModel::COLUMN_PRODUCT_TYPES, json_encode($productTypes));
return $this;
}
- /**
- * @throws \Exception
- */
- public function getClientDetailsLastUpdateDate(): \DateTime
- {
- return \Ess\M2ePro\Helper\Date::createDateGmt($this->getData('client_details_last_update_date'));
- }
-
- public function setClientDetailsLastUpdateDate(\DateTime $value): self
- {
- $this->setData('client_details_last_update_date', $value->format('Y-m-d H:i:s'));
-
- return $this;
- }
-
- /**
- * @throws \Exception
- */
- public function getServerDetailsLastUpdateDate(): \DateTime
+ public function getId(): int
{
- return \Ess\M2ePro\Helper\Date::createDateGmt($this->getData('server_details_last_update_date'));
+ return (int)parent::getId();
}
- public function setServerDetailsLastUpdateDate(\DateTime $value): self
+ public function getMarketplaceId(): int
{
- $this->setData('server_details_last_update_date', $value->format('Y-m-d H:i:s'));
-
- return $this;
+ return (int)$this->getData(ResourceModel::COLUMN_MARKETPLACE_ID);
}
- /**
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function getProductTypes(): array
{
- return $this->getSettings('product_types');
- }
-
- /**
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function setProductTypes(array $productTypes): self
- {
- $this->setSettings('product_types', $productTypes);
-
- return $this;
+ return (array)json_decode((string)$this->getData(ResourceModel::COLUMN_PRODUCT_TYPES), true);
}
}
diff --git a/Model/Amazon/Dictionary/Marketplace/Repository.php b/Model/Amazon/Dictionary/Marketplace/Repository.php
new file mode 100644
index 000000000..4cec993d2
--- /dev/null
+++ b/Model/Amazon/Dictionary/Marketplace/Repository.php
@@ -0,0 +1,56 @@
+resource = $resource;
+ $this->collectionFactory = $collectionFactory;
+ }
+
+ public function findByMarketplace(
+ \Ess\M2ePro\Model\Marketplace $marketplace
+ ): ?\Ess\M2ePro\Model\Amazon\Dictionary\Marketplace {
+ return $this->findByMarketplaceId((int)$marketplace->getId());
+ }
+
+ public function findByMarketplaceId(int $marketplaceId): ?\Ess\M2ePro\Model\Amazon\Dictionary\Marketplace
+ {
+ $collection = $this->collectionFactory->create();
+ $collection->addFieldToFilter(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\Marketplace::COLUMN_MARKETPLACE_ID,
+ ['eq' => $marketplaceId]
+ );
+
+ $dictionary = $collection->getFirstItem();
+ if ($dictionary->isObjectNew()) {
+ return null;
+ }
+
+ return $dictionary;
+ }
+
+ public function create(\Ess\M2ePro\Model\Amazon\Dictionary\Marketplace $dictionaryMarketplace): void
+ {
+ $this->resource->save($dictionaryMarketplace);
+ }
+
+ public function removeByMarketplace(\Ess\M2ePro\Model\Marketplace $marketplace): void
+ {
+ $this->resource
+ ->getConnection()
+ ->delete(
+ $this->resource->getMainTable(),
+ ['marketplace_id = ?' => $marketplace->getId()]
+ );
+ }
+}
diff --git a/Model/Amazon/Dictionary/MarketplaceFactory.php b/Model/Amazon/Dictionary/MarketplaceFactory.php
new file mode 100644
index 000000000..ad8c0ec39
--- /dev/null
+++ b/Model/Amazon/Dictionary/MarketplaceFactory.php
@@ -0,0 +1,26 @@
+objectManager = $objectManager;
+ }
+
+ public function create(
+ \Ess\M2ePro\Model\Marketplace $marketplace,
+ array $productTypes
+ ): Marketplace {
+ /** @var Marketplace $model */
+ $model = $this->objectManager->create(Marketplace::class);
+ $model->create($marketplace, $productTypes);
+
+ return $model;
+ }
+}
diff --git a/Model/Amazon/Dictionary/MarketplaceService.php b/Model/Amazon/Dictionary/MarketplaceService.php
new file mode 100644
index 000000000..52ad7329c
--- /dev/null
+++ b/Model/Amazon/Dictionary/MarketplaceService.php
@@ -0,0 +1,127 @@
+dispatcherFactory = $dispatcherFactory;
+ $this->dictionaryMarketplaceFactory = $dictionaryMarketplaceFactory;
+ $this->dictionaryMarketplaceRepository = $dictionaryMarketplaceRepository;
+ $this->dictionaryProductTypeRepository = $dictionaryProductTypeRepository;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
+ }
+
+ public function isExistForMarketplace(\Ess\M2ePro\Model\Marketplace $marketplace): bool
+ {
+ return $this->dictionaryMarketplaceRepository->findByMarketplace($marketplace) !== null;
+ }
+
+ public function update(\Ess\M2ePro\Model\Marketplace $marketplace): \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace
+ {
+ $dispatcher = $this->dispatcherFactory->create();
+ /** @var \Ess\M2ePro\Model\Amazon\Connector\Marketplace\Get\InfoWithDetails $command */
+ $command = $dispatcher->getConnectorByClass(
+ \Ess\M2ePro\Model\Amazon\Connector\Marketplace\Get\InfoWithDetails::class,
+ ['marketplace_id' => $marketplace->getNativeId()]
+ );
+
+ $dispatcher->process($command);
+
+ $response = $command->getResponseData();
+
+ [$dictionary, $listProductTypesNicks] = $this->makeDictionary($marketplace, $response['info']);
+ $this->processRemovedProductTypes($marketplace, $listProductTypesNicks);
+ $this->restoreInvalidProductTypes($marketplace, $listProductTypesNicks);
+
+ return $dictionary;
+ }
+
+ private function makeDictionary(\Ess\M2ePro\Model\Marketplace $marketplace, array $info): array
+ {
+ [$preparedProductTypes, $listProductTypesNicks] = $this->collectProductTypes($info['details']['product_type']);
+
+ $dictionary = $this->dictionaryMarketplaceFactory->create(
+ $marketplace,
+ $preparedProductTypes,
+ );
+
+ $this->dictionaryMarketplaceRepository->removeByMarketplace($marketplace);
+ $this->dictionaryMarketplaceRepository->create($dictionary);
+
+ return [$dictionary, $listProductTypesNicks];
+ }
+
+ private function collectProductTypes(array $productTypeList): array
+ {
+ $prepared = [];
+ $list = [];
+ foreach ($productTypeList as $row) {
+ $prepared[] = [
+ 'nick' => $row['nick'],
+ 'title' => $row['title'],
+ ];
+
+ $list[] = $row['nick'];
+ }
+
+ return [$prepared, $list];
+ }
+
+ private function processRemovedProductTypes(
+ \Ess\M2ePro\Model\Marketplace $marketplace,
+ array $listProductTypesNicks
+ ): void {
+ $existProductTypesMap = array_flip($listProductTypesNicks);
+ foreach ($this->dictionaryProductTypeRepository->findByMarketplace($marketplace) as $productType) {
+ if (isset($existProductTypesMap[$productType->getNick()])) {
+ continue;
+ }
+
+ $templates = $this->templateProductTypeRepository->findByDictionary($productType);
+ if (empty($templates)) {
+ $this->dictionaryProductTypeRepository->remove($productType);
+
+ continue;
+ }
+
+ $productType->markAsInvalid();
+
+ $this->dictionaryProductTypeRepository->save($productType);
+ }
+ }
+
+ private function restoreInvalidProductTypes(
+ \Ess\M2ePro\Model\Marketplace $marketplace,
+ mixed $listProductTypesNicks
+ ): void {
+ $existProductTypesMap = array_flip($listProductTypesNicks);
+ foreach ($this->dictionaryProductTypeRepository->findByMarketplace($marketplace) as $productType) {
+ if (!$productType->isInvalid()) {
+ continue;
+ }
+
+ if (!isset($existProductTypesMap[$productType->getNick()])) {
+ continue;
+ }
+
+ $productType->markAsValid();
+
+ $this->dictionaryProductTypeRepository->save($productType);
+ }
+ }
+}
diff --git a/Model/Amazon/Dictionary/ProductType.php b/Model/Amazon/Dictionary/ProductType.php
index f1f008b5b..27309041c 100644
--- a/Model/Amazon/Dictionary/ProductType.php
+++ b/Model/Amazon/Dictionary/ProductType.php
@@ -1,166 +1,179 @@
productTypeHelper = $productTypeHelper;
- }
+ private array $flatScheme;
- /**
- * @return void
- */
- public function _construct()
+ public function _construct(): void
{
parent::_construct();
- $this->_init(\Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::class);
+ $this->_init(ProductTypeResource::class);
+ }
+
+ public function create(
+ \Ess\M2ePro\Model\Marketplace $marketplace,
+ string $nick,
+ string $title,
+ array $schema,
+ array $variationThemes,
+ array $attributesGroups,
+ \DateTime $serverUpdateDate,
+ \DateTime $clientUpdateDate
+ ): self {
+ $this->setData(ProductTypeResource::COLUMN_MARKETPLACE_ID, (int)$marketplace->getId())
+ ->setData(ProductTypeResource::COLUMN_NICK, $nick)
+ ->setData(ProductTypeResource::COLUMN_TITLE, $title)
+ ->setScheme($schema)
+ ->setVariationThemes($variationThemes)
+ ->setAttributesGroups($attributesGroups)
+ ->setClientDetailsLastUpdateDate($clientUpdateDate)
+ ->setServerDetailsLastUpdateDate($serverUpdateDate);
+
+ return $this;
}
- /**
- * @return int
- */
+ // ----------------------------------------
+
public function getMarketplaceId(): int
{
- return (int)$this->getData('marketplace_id');
+ return (int)$this->getData(
+ ProductTypeResource::COLUMN_MARKETPLACE_ID
+ );
+ }
+
+ public function getNick(): string
+ {
+ return (string)$this->getData(ProductTypeResource::COLUMN_NICK);
+ }
+
+ public function getTitle(): string
+ {
+ return (string)$this->getData(ProductTypeResource::COLUMN_TITLE);
}
- /**
- * @param int $marketplaceId
- *
- * @return $this
- */
- public function setMarketplaceId(int $marketplaceId): self
+ public function setScheme(array $schema): self
{
- $this->setData('marketplace_id', $marketplaceId);
+ $this->setData(ProductTypeResource::COLUMN_SCHEMA, json_encode($schema));
return $this;
}
- /**
- * @return string
- */
- public function getNick(): string
+ public function getScheme(): array
{
- return (string)$this->getData('nick');
+ $value = $this->getData(ProductTypeResource::COLUMN_SCHEMA);
+ if (empty($value)) {
+ return [];
+ }
+
+ return (array)json_decode($value, true);
}
- /**
- * @param string $nick
- *
- * @return $this
- */
- public function setNick(string $nick): self
+ public function setVariationThemes(array $variationThemes): self
{
- $this->setData('nick', $nick);
+ $this->setData(ProductTypeResource::COLUMN_VARIATION_THEMES, json_encode($variationThemes));
return $this;
}
- /**
- * @return string
- */
- public function getTitle(): string
+ public function hasVariationThemes(): bool
+ {
+ return !empty($this->getVariationThemes());
+ }
+
+ public function getVariationThemes(): array
{
- return (string)$this->getData('title');
+ $value = $this->getData(ProductTypeResource::COLUMN_VARIATION_THEMES);
+ if (empty($value)) {
+ return [];
+ }
+
+ return (array)json_decode($value, true);
}
- /**
- * @param string $title
- *
- * @return $this
- */
- public function setTitle(string $title): self
+ public function hasVariationTheme(string $variationTheme): bool
{
- $this->setData('title', $title);
+ return isset($this->getVariationThemes()[$variationTheme]);
+ }
+
+ public function getVariationThemesAttributes(string $variationTheme): array
+ {
+ return $this->getVariationThemes()[$variationTheme]['attributes'] ?? [];
+ }
+
+ public function setAttributesGroups(array $attributesGroups): self
+ {
+ $this->setData(ProductTypeResource::COLUMN_ATTRIBUTES_GROUPS, json_encode($attributesGroups));
return $this;
}
- /**
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function getScheme(): array
+ public function getAttributesGroups(): array
{
- $scheme = \Ess\M2ePro\Helper\Json::decode((string)$this->getData('scheme'));
+ $value = $this->getData(ProductTypeResource::COLUMN_ATTRIBUTES_GROUPS);
+ if (empty($value)) {
+ return [];
+ }
+
+ return (array)json_decode($value, true);
+ }
- return is_array($scheme) ? $scheme : [];
+ public function getClientDetailsLastUpdateDate(): \DateTime
+ {
+ return \Ess\M2ePro\Helper\Date::createDateGmt(
+ $this->getData(ProductTypeResource::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE)
+ );
}
- /**
- * @param array $scheme
- *
- * @return $this
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- public function setScheme(array $scheme): self
+ public function setClientDetailsLastUpdateDate(\DateTime $value): self
{
- $this->setData('scheme', \Ess\M2ePro\Helper\Json::encode($scheme));
+ $this->setData(ProductTypeResource::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE, $value->format('Y-m-d H:i:s'));
+
+ return $this;
+ }
+
+ public function getServerDetailsLastUpdateDate(): \DateTime
+ {
+ return \Ess\M2ePro\Helper\Date::createDateGmt(
+ $this->getData(ProductTypeResource::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE)
+ );
+ }
+
+ public function setServerDetailsLastUpdateDate(\DateTime $value): self
+ {
+ $this->setData(ProductTypeResource::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE, $value->format('Y-m-d H:i:s'));
return $this;
}
- /**
- * @return bool
- */
public function isInvalid(): bool
{
- return (bool)$this->getData('invalid');
+ return (bool)$this->getData(ProductTypeResource::COLUMN_INVALID);
}
- /**
- * @param bool $invalid
- *
- * @return $this
- */
- public function setInvalid(bool $invalid): self
+ public function markAsInvalid(): self
{
- $this->setData('invalid', $invalid);
+ $this->setData(ProductTypeResource::COLUMN_INVALID, (int)true);
return $this;
}
- /**
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
+ public function markAsValid(): self
+ {
+ $this->setData(ProductTypeResource::COLUMN_INVALID, (int)false);
+
+ return $this;
+ }
+
+ // ----------------------------------------
+
public function getValidatorByPath(string $path): ValidatorInterface
{
$flatScheme = $this->getFlatScheme();
@@ -187,7 +200,7 @@ public function findNameByProductTypeCode(string $code): string
private function getFlatScheme(): array
{
- if ($this->flatScheme === null) {
+ if (!isset($this->flatScheme)) {
$this->flatScheme = $this->convertSchemeToFlat($this->getScheme());
}
@@ -221,18 +234,6 @@ private function convertSchemeToFlat(array $array, array $parentAttributes = [])
private function getGroupTitleByNick(string $groupNick): string
{
- if ($this->groups === null) {
- $groups = $this->productTypeHelper->getProductTypeGroups(
- $this->getMarketplaceId(),
- $this->getNick()
- );
-
- $this->groups = array_combine(
- array_column($groups, 'nick'),
- array_column($groups, 'title')
- );
- }
-
- return $this->groups[$groupNick] ?? '';
+ return $this->getAttributesGroups()[$groupNick] ?? '';
}
}
diff --git a/Model/Amazon/Dictionary/ProductType/Repository.php b/Model/Amazon/Dictionary/ProductType/Repository.php
new file mode 100644
index 000000000..1ac42e0d4
--- /dev/null
+++ b/Model/Amazon/Dictionary/ProductType/Repository.php
@@ -0,0 +1,188 @@
+resource = $resource;
+ $this->collectionFactory = $collectionFactory;
+ $this->productTypeFactory = $productTypeFactory;
+ $this->marketplaceCollectionFactory = $marketplaceCollectionFactory;
+ }
+
+ public function create(\Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productType): void
+ {
+ $this->resource->save($productType);
+ }
+
+ public function get(int $id): \Ess\M2ePro\Model\Amazon\Dictionary\ProductType
+ {
+ $productType = $this->find($id);
+ if ($productType === null) {
+ throw new \LogicException("Product Type $id not found.");
+ }
+
+ return $productType;
+ }
+
+ public function find(int $id): ?\Ess\M2ePro\Model\Amazon\Dictionary\ProductType
+ {
+ if (($model = $this->tryGetFromRuntimeCache($id)) !== null) {
+ return $model;
+ }
+
+ $model = $this->productTypeFactory->createEmpty();
+ $this->resource->load($model, $id);
+ if ($model->isObjectNew()) {
+ return null;
+ }
+
+ $this->addToRuntimeCache($model);
+
+ return $model;
+ }
+
+ public function save(\Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productType): void
+ {
+ $this->resource->save($productType);
+ }
+
+ public function remove(\Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productType): void
+ {
+ $this->removeFromRuntimeCache((int)$productType->getId());
+
+ $this->resource->delete($productType);
+ }
+
+ /**
+ * @param \Ess\M2ePro\Model\Marketplace $marketplace
+ *
+ * @return \Ess\M2ePro\Model\Amazon\Dictionary\ProductType[]
+ */
+ public function findByMarketplace(
+ \Ess\M2ePro\Model\Marketplace $marketplace
+ ): array {
+ $collection = $this->collectionFactory->create();
+ $collection->addFieldToFilter(ProductTypeResource::COLUMN_MARKETPLACE_ID, ['eq' => $marketplace->getId()]);
+
+ return array_values($collection->getItems());
+ }
+
+ /**
+ * @param \Ess\M2ePro\Model\Marketplace $marketplace
+ *
+ * @return \Ess\M2ePro\Model\Amazon\Dictionary\ProductType[]
+ */
+ public function findValidByMarketplace(\Ess\M2ePro\Model\Marketplace $marketplace): array
+ {
+ $collection = $this->collectionFactory->create();
+ $collection->addFieldToFilter(ProductTypeResource::COLUMN_MARKETPLACE_ID, ['eq' => $marketplace->getId()]);
+ $collection->addFieldToFilter(ProductTypeResource::COLUMN_INVALID, ['eq' => 0]);
+
+ return array_values($collection->getItems());
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Amazon\Dictionary\ProductType[]
+ */
+ public function findValidOutOfDate(): array
+ {
+ $collection = $this->collectionFactory->create();
+ $collection->addFieldToFilter(ProductTypeResource::COLUMN_INVALID, ['eq' => 0]);
+ $collection->addFieldToFilter(
+ ProductTypeResource::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE,
+ ['gt' => new \Zend_Db_Expr(ProductTypeResource::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE)]
+ );
+ $collection->addFieldToFilter(ProductTypeResource::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE, ['notnull' => true]);
+ $collection->addFieldToFilter(ProductTypeResource::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE, ['notnull' => true]);
+
+ return array_values($collection->getItems());
+ }
+
+ public function findByMarketplaceAndNick(
+ int $marketplaceId,
+ string $nick
+ ): ?\Ess\M2ePro\Model\Amazon\Dictionary\ProductType {
+ $collection = $this->collectionFactory->create();
+ $collection->addFieldToFilter(ProductTypeResource::COLUMN_MARKETPLACE_ID, ['eq' => $marketplaceId])
+ ->addFieldToFilter(ProductTypeResource::COLUMN_NICK, ['eq' => $nick]);
+
+ $result = $collection->getFirstItem();
+ if ($result->isObjectNew()) {
+ return null;
+ }
+
+ return $result;
+ }
+
+ // ----------------------------------------
+
+ public function getValidNickMapByMarketplaceNativeId(): array
+ {
+ $marketplaceCollection = $this->marketplaceCollectionFactory->createWithAmazonChildMode();
+ $marketplaceCollection->getSelect()
+ ->joinInner(
+ ['dictionary' => $this->resource->getMainTable()],
+ sprintf(
+ 'dictionary.%s = main_table.%s',
+ ProductTypeResource::COLUMN_MARKETPLACE_ID,
+ \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_ID
+ ),
+ []
+ );
+
+ $marketplaceCollection->addFieldToFilter(
+ sprintf('dictionary.%s', ProductTypeResource::COLUMN_INVALID),
+ ['eq' => 0]
+ );
+
+ $marketplaceCollection->getSelect()->reset(\Magento\Framework\DB\Select::COLUMNS);
+ $marketplaceCollection->getSelect()->columns(
+ [
+ 'native_id' => sprintf('main_table.%s', \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_NATIVE_ID),
+ 'nick' => sprintf('dictionary.%s', ProductTypeResource::COLUMN_NICK),
+ ]
+ );
+
+ $resultMap = [];
+ foreach ($marketplaceCollection->toArray()['items'] ?? [] as $row) {
+ $resultMap[(int)$row['native_id']][] = $row['nick'];
+ }
+
+ return $resultMap;
+ }
+
+ // ----------------------------------------
+
+ private function addToRuntimeCache(\Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productType): void
+ {
+ $this->runtimeCache[(int)$productType->getId()] = $productType;
+ }
+
+ private function removeFromRuntimeCache(int $id): void
+ {
+ unset($this->runtimeCache[$id]);
+ }
+
+ private function tryGetFromRuntimeCache(int $id): ?\Ess\M2ePro\Model\Amazon\Dictionary\ProductType
+ {
+ return $this->runtimeCache[$id] ?? null;
+ }
+}
diff --git a/Model/Amazon/Dictionary/ProductTypeFactory.php b/Model/Amazon/Dictionary/ProductTypeFactory.php
new file mode 100644
index 000000000..6b2ed363e
--- /dev/null
+++ b/Model/Amazon/Dictionary/ProductTypeFactory.php
@@ -0,0 +1,45 @@
+objectManager = $objectManager;
+ }
+
+ public function create(
+ \Ess\M2ePro\Model\Marketplace $marketplace,
+ string $nick,
+ string $title,
+ array $schema,
+ array $variationThemes,
+ array $attributesGroups,
+ \DateTime $serverUpdateDate,
+ \DateTime $clientUpdateDate
+ ): ProductType {
+ $model = $this->createEmpty();
+ $model->create(
+ $marketplace,
+ $nick,
+ $title,
+ $schema,
+ $variationThemes,
+ $attributesGroups,
+ $serverUpdateDate,
+ $clientUpdateDate
+ );
+
+ return $model;
+ }
+
+ public function createEmpty(): ProductType
+ {
+ return $this->objectManager->create(ProductType::class);
+ }
+}
diff --git a/Model/Amazon/Dictionary/ProductTypeService.php b/Model/Amazon/Dictionary/ProductTypeService.php
new file mode 100644
index 000000000..4671d0263
--- /dev/null
+++ b/Model/Amazon/Dictionary/ProductTypeService.php
@@ -0,0 +1,105 @@
+dispatcherFactory = $dispatcherFactory;
+ $this->amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ $this->dictionaryProductTypeRepository = $dictionaryProductTypeRepository;
+ $this->productTypeFactory = $productTypeFactory;
+ $this->issueOutOfDateCache = $issueOutOfDateCache;
+ }
+
+ public function retrieve(
+ string $nick,
+ \Ess\M2ePro\Model\Marketplace $marketplace
+ ): \Ess\M2ePro\Model\Amazon\Dictionary\ProductType {
+ if (!$marketplace->isComponentModeAmazon()) {
+ throw new \LogicException('Marketplace is not Amazon component mode.');
+ }
+
+ $productType = $this->dictionaryProductTypeRepository->findByMarketplaceAndNick(
+ (int)$marketplace->getId(),
+ $nick
+ );
+ if ($productType !== null) {
+ return $productType;
+ }
+
+ $data = $this->getData($nick, $marketplace);
+
+ $productType = $this->productTypeFactory->create(
+ $marketplace,
+ $nick,
+ $data['title'],
+ $data['attributes'],
+ $data['variation_themes'],
+ $data['attributes_groups'],
+ \Ess\M2ePro\Helper\Date::createDateGmt($data['last_update']),
+ \Ess\M2ePro\Helper\Date::createCurrentGmt(),
+ );
+
+ $this->dictionaryProductTypeRepository->create($productType);
+
+ return $productType;
+ }
+
+ public function update(\Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productType): void
+ {
+ $marketplace = $this->amazonMarketplaceRepository->get($productType->getMarketplaceId());
+
+ $data = $this->getData($productType->getNick(), $marketplace);
+
+ $productType->setVariationThemes($data['variation_themes'])
+ ->setScheme($data['attributes'])
+ ->setAttributesGroups($data['attributes_groups'])
+ ->setServerDetailsLastUpdateDate(\Ess\M2ePro\Helper\Date::createDateGmt($data['last_update']))
+ ->setClientDetailsLastUpdateDate(\Ess\M2ePro\Helper\Date::createCurrentGmt());
+
+ $this->dictionaryProductTypeRepository->save($productType);
+
+ $this->clearCache();
+ }
+
+ private function getData(string $nick, \Ess\M2ePro\Model\Marketplace $marketplace): array
+ {
+ $dispatcher = $this->dispatcherFactory->create();
+
+ /** @var \Ess\M2ePro\Model\Amazon\Connector\ProductType\Get\Info $command */
+ $command = $dispatcher->getConnectorByClass(
+ \Ess\M2ePro\Model\Amazon\Connector\ProductType\Get\Info::class,
+ [
+ 'product_type_nick' => $nick,
+ 'marketplace_id' => $marketplace->getNativeId(),
+ ]
+ );
+
+ $dispatcher->process($command);
+
+ return $command->getResponseData();
+ }
+
+ private function clearCache(): void
+ {
+ $this->issueOutOfDateCache->clear();
+ }
+}
diff --git a/Model/Amazon/Listing/Auto/Actions/Listing.php b/Model/Amazon/Listing/Auto/Actions/Listing.php
index 98740fcc2..d34d5d911 100644
--- a/Model/Amazon/Listing/Auto/Actions/Listing.php
+++ b/Model/Amazon/Listing/Auto/Actions/Listing.php
@@ -1,35 +1,19 @@
amazonFactory = $amazonFactory;
- $this->marketplaceDetailsFactory = $marketplaceDetailsFactory;
- $this->productTypeResource = $productTypeResource;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
}
/**
@@ -250,9 +234,8 @@ protected function processAddedListingProduct(
$amazonListingProduct = $listingProduct->getChildObject();
if (!$amazonListingProduct->getVariationManager()->isRelationParentType()) {
- $amazonListingProduct->setData('template_product_type_id', $params['template_product_type_id']);
- $amazonListingProduct->setData(
- 'is_general_id_owner',
+ $amazonListingProduct->setTemplateProductTypeId($params['template_product_type_id']);
+ $amazonListingProduct->setIsGeneralIdOwner(
\Ess\M2ePro\Model\Amazon\Listing\Product::IS_GENERAL_ID_OWNER_YES
);
@@ -273,26 +256,21 @@ protected function processAddedListingProduct(
return;
}
- $detailsModel = $this->marketplaceDetailsFactory->create();
- $detailsModel->setMarketplaceId($listingProduct->getListing()->getMarketplaceId());
-
- $productTypeTemplate = $this->productTypeResource
- ->loadById((int)$params['template_product_type_id']);
+ $productTypeTemplate = $this->templateProductTypeRepository->get((int)$params['template_product_type_id']);
- $possibleThemes = $detailsModel->getVariationThemes($productTypeTemplate->getNick());
+ $possibleThemes = $productTypeTemplate->getDictionary()->getVariationThemes();
$productAttributes = $amazonListingProduct->getVariationManager()
->getTypeModel()
->getProductAttributes();
foreach ($possibleThemes as $theme) {
- if (count($theme['attributes']) != count($productAttributes)) {
+ if (count($theme['attributes']) !== count($productAttributes)) {
continue;
}
- $amazonListingProduct->setData('template_product_type_id', $params['template_product_type_id']);
- $amazonListingProduct->setData(
- 'is_general_id_owner',
+ $amazonListingProduct->setTemplateProductTypeId($params['template_product_type_id']);
+ $amazonListingProduct->setIsGeneralIdOwner(
\Ess\M2ePro\Model\Amazon\Listing\Product::IS_GENERAL_ID_OWNER_YES
);
diff --git a/Model/Amazon/Listing/Product.php b/Model/Amazon/Listing/Product.php
index 139748a75..0c5b5609a 100644
--- a/Model/Amazon/Listing/Product.php
+++ b/Model/Amazon/Listing/Product.php
@@ -2,9 +2,11 @@
namespace Ess\M2ePro\Model\Amazon\Listing;
+use Ess\M2ePro\Model\ResourceModel\Amazon\Listing\Product as AmazonProductResource;
+
/**
* @method \Ess\M2ePro\Model\Listing\Product getParentObject()
- * @method \Ess\M2ePro\Model\ResourceModel\Amazon\Listing\Product getResource()
+ * @method AmazonProductResource getResource()
*/
class Product extends \Ess\M2ePro\Model\ActiveRecord\Component\Child\Amazon\AbstractModel
{
@@ -44,8 +46,6 @@ class Product extends \Ess\M2ePro\Model\ActiveRecord\Component\Child\Amazon\Abst
public const BUSINESS_DISCOUNTS_MAX_RULES_COUNT_ALLOWED = 5;
- /** @var \Ess\M2ePro\Model\Amazon\Template\ProductTypeFactory */
- private $productTypeFactory;
/** @var \Ess\M2ePro\Model\Amazon\Listing\Product\PriceCalculatorFactory */
private $amazonPriceCalculatorFactory;
private Product\RetrieveIdentifiers $retrieveIdentifiers;
@@ -59,9 +59,10 @@ class Product extends \Ess\M2ePro\Model\ActiveRecord\Component\Child\Amazon\Abst
private $variationManager = null;
/** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Repricing|null */
private $repricingModel = null;
+ private \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $productTypeTemplateRepository;
public function __construct(
- \Ess\M2ePro\Model\Amazon\Template\ProductTypeFactory $productTypeFactory,
+ \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $productTypeTemplateRepository,
\Ess\M2ePro\Model\Amazon\Listing\Product\PriceCalculatorFactory $amazonPriceCalculatorFactory,
\Ess\M2ePro\Model\Amazon\Listing\Product\RetrieveIdentifiers $retrieveIdentifiers,
\Ess\M2ePro\Model\Amazon\Search\Dispatcher $searchDispatcher,
@@ -89,18 +90,18 @@ public function __construct(
$data
);
- $this->productTypeFactory = $productTypeFactory;
$this->amazonPriceCalculatorFactory = $amazonPriceCalculatorFactory;
$this->retrieveIdentifiers = $retrieveIdentifiers;
$this->searchDispatcher = $searchDispatcher;
$this->configuration = $configuration;
$this->helperData = $helperData;
+ $this->productTypeTemplateRepository = $productTypeTemplateRepository;
}
- public function _construct()
+ public function _construct(): void
{
parent::_construct();
- $this->_init(\Ess\M2ePro\Model\ResourceModel\Amazon\Listing\Product::class);
+ $this->_init(AmazonProductResource::class);
}
public function getListingProductId(): int
@@ -393,28 +394,18 @@ public function getProductTaxCodeTemplateSource()
// ---------------------------------------
- /**
- * @return bool
- */
public function isExistsProductTypeTemplate(): bool
{
return $this->getTemplateProductTypeId() > 0;
}
- /**
- * @return \Ess\M2ePro\Model\Amazon\Template\ProductType|null
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function getProductTypeTemplate(): ?\Ess\M2ePro\Model\Amazon\Template\ProductType
{
if (!$this->isExistsProductTypeTemplate()) {
return null;
}
- $productType = $this->productTypeFactory->create();
- $productType->load($this->getTemplateProductTypeId());
-
- return $productType;
+ return $this->productTypeTemplateRepository->get($this->getTemplateProductTypeId());
}
/**
@@ -501,7 +492,7 @@ public function getAmazonItem()
->getFirstItem();
}
- public function getVariationManager()
+ public function getVariationManager(): \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager
{
if ($this->variationManager === null) {
$this->variationManager = $this->modelFactory->getObject('Amazon_Listing_Product_Variation_Manager');
@@ -592,7 +583,7 @@ public function getSku()
*/
public function getTemplateProductTypeId(): int
{
- return (int)$this->getData('template_product_type_id');
+ return (int)$this->getData(AmazonProductResource::COLUMN_TEMPLATE_PRODUCT_TYPE_ID);
}
/**
@@ -602,7 +593,7 @@ public function getTemplateProductTypeId(): int
*/
public function setTemplateProductTypeId($productType)
{
- $this->setData('template_product_type_id', $productType);
+ $this->setData(AmazonProductResource::COLUMN_TEMPLATE_PRODUCT_TYPE_ID, $productType);
}
/**
@@ -699,7 +690,12 @@ public function isIsbnGeneralId()
*/
public function isGeneralIdOwner()
{
- return (int)$this->getData('is_general_id_owner') == self::IS_GENERAL_ID_OWNER_YES;
+ return (int)$this->getData(AmazonProductResource::COLUMN_IS_GENERAL_ID_OWNER) == self::IS_GENERAL_ID_OWNER_YES;
+ }
+
+ public function setIsGeneralIdOwner($isGeneralId): void
+ {
+ $this->setData(AmazonProductResource::COLUMN_IS_GENERAL_ID_OWNER, (int)$isGeneralId);
}
// ---------------------------------------
@@ -996,7 +992,7 @@ public function getRegularMapPrice()
public function getOnlineRegularMapPrice(): float
{
$onlineRegularMapPrice = $this->getDataByKey(
- \Ess\M2ePro\Model\ResourceModel\Amazon\Listing\Product::COLUMN_ONLINE_REGULAR_MAP_PRICE
+ AmazonProductResource::COLUMN_ONLINE_REGULAR_MAP_PRICE
);
if (empty($onlineRegularMapPrice)) {
diff --git a/Model/Amazon/Listing/Product/Action/Type/ListAction/Response.php b/Model/Amazon/Listing/Product/Action/Type/ListAction/Response.php
index d2f011701..b651d72ce 100644
--- a/Model/Amazon/Listing/Product/Action/Type/ListAction/Response.php
+++ b/Model/Amazon/Listing/Product/Action/Type/ListAction/Response.php
@@ -116,14 +116,9 @@ private function setVariationData($generalId)
$typeModel = $variationManager->getTypeModel();
if ($variationManager->isRelationParentType()) {
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Details $detailsModel */
- $detailsModel = $this->modelFactory->getObject('Amazon_Marketplace_Details');
- $detailsModel->setMarketplaceId($this->getMarketplace()->getId());
+ $dictionary = $this->getAmazonListingProduct()->getProductTypeTemplate()->getDictionary();
- $channelAttributes = $detailsModel->getVariationThemeAttributes(
- $this->getRequestData()->getProductTypeNick(),
- $typeModel->getChannelTheme()
- );
+ $channelAttributes = $dictionary->getVariationThemesAttributes((string)$typeModel->getChannelTheme());
$typeModel->setChannelAttributesSets(array_fill_keys($channelAttributes, []), false);
diff --git a/Model/Amazon/Listing/Product/Variation/Manager.php b/Model/Amazon/Listing/Product/Variation/Manager.php
index fe533c38f..f958f1735 100644
--- a/Model/Amazon/Listing/Product/Variation/Manager.php
+++ b/Model/Amazon/Listing/Product/Variation/Manager.php
@@ -1,16 +1,7 @@
variationManager = $variationManager;
$this->listingProduct = $variationManager->getListingProduct();
}
- /**
- * @return \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager
- */
- public function getVariationManager()
+ public function getVariationManager(): \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager
{
return $this->variationManager;
}
// ---------------------------------------
- /**
- * @return \Ess\M2ePro\Model\Listing\Product
- */
- public function getListingProduct()
+ public function getListingProduct(): \Ess\M2ePro\Model\Listing\Product
{
return $this->listingProduct;
}
- /**
- * @return \Ess\M2ePro\Model\Amazon\Listing\Product
- */
- public function getAmazonListingProduct()
+ public function getAmazonListingProduct(): \Ess\M2ePro\Model\Amazon\Listing\Product
{
return $this->getListingProduct()->getChildObject();
}
diff --git a/Model/Amazon/Listing/Product/Variation/Manager/Type/Individual.php b/Model/Amazon/Listing/Product/Variation/Manager/Type/Individual.php
index 04a9a77fb..8b58be5a3 100644
--- a/Model/Amazon/Listing/Product/Variation/Manager/Type/Individual.php
+++ b/Model/Amazon/Listing/Product/Variation/Manager/Type/Individual.php
@@ -1,19 +1,7 @@
modelFactory->getObject('Amazon_Marketplace_Details')
- ->setMarketplaceId($this->getListingProduct()->getMarketplace()->getId())
- ->getVariationThemeAttributes(
- $this->getAmazonListingProduct()
- ->getProductTypeTemplate()
- ->getNick(),
- $this->getChannelTheme()
- );
+ $themeAttributes = $this->getAmazonListingProduct()->getProductTypeTemplate()
+ ->getDictionary()
+ ->getVariationThemesAttributes($this->getChannelTheme());
$channelAttributes = $this->getRealChannelAttributes();
@@ -209,7 +195,7 @@ public function isActualChannelTheme()
*/
public function getChannelTheme()
{
- return $this->getListingProduct()->getSetting('additional_data', 'variation_channel_theme', null);
+ return $this->getListingProduct()->getSetting('additional_data', 'variation_channel_theme', '');
}
// ---------------------------------------
@@ -261,25 +247,18 @@ public function resetChannelTheme($save = true)
//########################################
- /**
- * @return array
- */
- public function getChannelAttributes()
+ public function getChannelAttributes(): array
{
if ($this->getAmazonListingProduct()->getGeneralId()) {
return array_keys($this->getChannelAttributesSets());
}
$productType = $this->getAmazonListingProduct()->getProductTypeTemplate();
- if ($this->hasChannelTheme() && $productType !== null) {
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Details $marketplaceDetails */
- $marketplaceDetails = $this->modelFactory->getObject('Amazon_Marketplace_Details');
- $marketplaceDetails->setMarketplaceId($this->getListingProduct()->getListing()->getMarketplaceId());
-
- return $marketplaceDetails->getVariationThemeAttributes(
- $productType->getNick(),
- $this->getChannelTheme()
- );
+ if (
+ $this->hasChannelTheme()
+ && $productType !== null
+ ) {
+ return $productType->getDictionary()->getVariationThemesAttributes($this->getChannelTheme());
}
return [];
@@ -405,7 +384,7 @@ public function setVirtualProductAttributes(array $attributes, $save = true)
$save && $this->getListingProduct()->save();
}
- public function isActualVirtualProductAttributes()
+ public function isActualVirtualProductAttributes(): bool
{
if (!$this->getVirtualProductAttributes()) {
return true;
@@ -429,14 +408,10 @@ public function isActualVirtualProductAttributes()
}
if ($this->getChannelTheme()) {
- /** @var \Ess\M2ePro\Model\Amazon\Marketplace\Details $marketplaceDetails */
- $marketplaceDetails = $this->modelFactory->getObject('Amazon_Marketplace_Details');
- $marketplaceDetails->setMarketplaceId($this->getListingProduct()->getListing()->getMarketplaceId());
-
- $themeAttributes = $marketplaceDetails->getVariationThemeAttributes(
- $this->getAmazonListingProduct()->getProductTypeTemplate()->getNick(),
- $this->getChannelTheme()
- );
+ $themeAttributes = $this->getAmazonListingProduct()
+ ->getProductTypeTemplate()
+ ->getDictionary()
+ ->getVariationThemesAttributes($this->getChannelTheme());
$virtualProductAttributes = array_keys($this->getVirtualProductAttributes());
diff --git a/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/ParentRelation/Processor.php b/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/ParentRelation/Processor.php
index 747a1355e..23cf86e59 100644
--- a/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/ParentRelation/Processor.php
+++ b/Model/Amazon/Listing/Product/Variation/Manager/Type/Relation/ParentRelation/Processor.php
@@ -109,6 +109,11 @@ private function getSortedProcessors()
];
}
+ /**
+ * @param string $processorName
+ *
+ * @return Processor\Sub\AbstractModel
+ */
private function getProcessorModel($processorName)
{
$model = $this->modelFactory->getObject(
@@ -210,10 +215,7 @@ public function getProductTypeTemplate(): ?\Ess\M2ePro\Model\Amazon\Template\Pro
//########################################
- /**
- * @return array|null
- */
- public function getPossibleThemes()
+ public function getPossibleThemes(): array
{
if ($this->possibleThemes !== null) {
return $this->possibleThemes;
@@ -226,11 +228,7 @@ public function getPossibleThemes()
return $this->possibleThemes = [];
}
- $possibleThemes = $this->modelFactory->getObject('Amazon_Marketplace_Details')
- ->setMarketplaceId($marketPlaceId)
- ->getVariationThemes(
- $productType->getNick()
- );
+ $possibleThemes = $productType->getDictionary()->getVariationThemes();
$themesUsageData = $this->variationHelper->getThemesUsageData();
$usedThemes = [];
diff --git a/Model/Amazon/Marketplace.php b/Model/Amazon/Marketplace.php
index d87832ff5..6862b08b6 100644
--- a/Model/Amazon/Marketplace.php
+++ b/Model/Amazon/Marketplace.php
@@ -53,14 +53,6 @@ public function getDefaultCurrency()
return $this->getData('default_currency');
}
- /**
- * @return bool
- */
- public function isNewAsinAvailable()
- {
- return (bool)$this->getData('is_new_asin_available');
- }
-
/**
* @return bool
*/
diff --git a/Model/Amazon/Marketplace/Details.php b/Model/Amazon/Marketplace/Details.php
deleted file mode 100644
index dfc1bc71b..000000000
--- a/Model/Amazon/Marketplace/Details.php
+++ /dev/null
@@ -1,106 +0,0 @@
-resourceConnection = $resourceConnection;
- parent::__construct($helperFactory, $modelFactory);
- }
-
- /**
- * @param $marketplaceId
- *
- * @return $this
- * @throws \Ess\M2ePro\Model\Exception
- */
- public function setMarketplaceId($marketplaceId)
- {
- if ($this->marketplaceId === $marketplaceId) {
- return $this;
- }
-
- $this->marketplaceId = $marketplaceId;
- $this->load();
-
- return $this;
- }
-
- /**
- * @return array
- */
- public function getProductTypes(): array
- {
- return $this->productTypes;
- }
-
- /**
- * @param string $productTypeNick
- *
- * @return array
- */
- public function getVariationThemes(string $productTypeNick): array
- {
- return !empty($this->productTypes[$productTypeNick]['variation_themes']) ?
- $this->productTypes[$productTypeNick]['variation_themes'] : [];
- }
-
- /**
- * @param string $productTypeNick
- * @param string $theme
- *
- * @return array
- */
- public function getVariationThemeAttributes(string $productTypeNick, string $theme): array
- {
- $themes = $this->getVariationThemes($productTypeNick);
-
- return !empty($themes[$theme]['attributes']) ? $themes[$theme]['attributes'] : [];
- }
-
- private function load()
- {
- if ($this->marketplaceId === null) {
- throw new \Ess\M2ePro\Model\Exception('Marketplace was not set.');
- }
-
- $connRead = $this->resourceConnection->getConnection();
- $table = $this->getHelper('Module_Database_Structure')
- ->getTableNameWithPrefix('m2epro_amazon_dictionary_marketplace');
-
- $data = $connRead->select()
- ->from($table)
- ->where('marketplace_id = ?', (int)$this->marketplaceId)
- ->query()
- ->fetch();
-
- if ($data === false) {
- throw new \Ess\M2ePro\Model\Exception('Marketplace not found or not synchronized');
- }
-
- $this->productTypes = \Ess\M2ePro\Helper\Json::decode($data['product_types']);
- }
-}
diff --git a/Model/Amazon/Marketplace/Issue/NotUpdated.php b/Model/Amazon/Marketplace/Issue/NotUpdated.php
deleted file mode 100644
index 1a7dd6186..000000000
--- a/Model/Amazon/Marketplace/Issue/NotUpdated.php
+++ /dev/null
@@ -1,156 +0,0 @@
-urlBuilder = $urlBuilder;
- $this->resourceConnection = $resourceConnection;
- $this->amazonViewHelper = $amazonViewHelper;
- $this->permanentCacheHelper = $permanentCacheHelper;
- $this->moduleDatabaseStructureHelper = $moduleDatabaseStructureHelper;
- $this->translationHelper = $translationHelper;
- $this->issueFactory = $issueFactory;
- $this->amazonComponentHelper = $amazonComponentHelper;
- $this->marketplaceFactory = $marketplaceFactory;
- }
-
- /**
- * @inheritDoc
- * @throws \Ess\M2ePro\Model\Exception\Logic
- * @throws \Zend_Db_Statement_Exception
- * @throws \Ess\M2ePro\Model\Exception
- */
- public function getIssues(): array
- {
- if (!$this->isNeedProcess()) {
- return [];
- }
-
- $outdatedMarketplaces = $this->permanentCacheHelper->getValue(self::CACHE_KEY);
- if (empty($outdatedMarketplaces)) {
- $tableName = $this->moduleDatabaseStructureHelper
- ->getTableNameWithPrefix('m2epro_amazon_dictionary_marketplace');
-
- $queryStmt = $this->resourceConnection
- ->getConnection()
- ->select()
- ->from(
- $tableName,
- ['marketplace_id', 'server_details_last_update_date']
- )
- ->where('client_details_last_update_date IS NOT NULL')
- ->where('server_details_last_update_date IS NOT NULL')
- ->where(
- 'client_details_last_update_date < server_details_last_update_date'
- )
- ->query();
-
- $dictionaryData = [];
- while ($row = $queryStmt->fetch()) {
- $dictionaryData[(int)$row['marketplace_id']] = $row['server_details_last_update_date'];
- }
-
- $marketplacesCollection = $this->marketplaceFactory->create()->getCollection()
- ->addFieldToFilter('status', Marketplace::STATUS_ENABLE)
- ->addFieldToFilter(
- 'id',
- ['in' => array_keys($dictionaryData)]
- )
- ->setOrder('sorder', 'ASC');
-
- $outdatedMarketplaces = [];
- foreach ($marketplacesCollection as $marketplace) {
- /** @var \Ess\M2ePro\Model\Marketplace $marketplace */
- $outdatedMarketplaces[$marketplace->getTitle()] = $dictionaryData[$marketplace->getId()];
- }
-
- $this->permanentCacheHelper->setValue(
- self::CACHE_KEY,
- $outdatedMarketplaces,
- ['amazon', 'marketplace'],
- 60 * 60 * 24
- );
- }
-
- if (empty($outdatedMarketplaces)) {
- return [];
- }
-
- $tempTitle = $this->translationHelper->__(
- 'M2E Pro requires action: Amazon marketplace data needs to be synchronized.
- Please update Amazon marketplaces.'
- );
- $textToTranslate = <<Refresh Amazon Data button in Amazon > Product Types
-and re-save the Product Types you have configured.
-TEXT;
-
- $tempMessage = __(
- $textToTranslate,
- ['url' => $this->urlBuilder->getUrl('m2epro/amazon_template_productType/index')]
- );
-
- $editHash = sha1(self::CACHE_KEY . JsonHelper::encode($outdatedMarketplaces));
- $messageUrl = $this->urlBuilder->getUrl(
- 'm2epro/amazon_template_productType/index',
- ['_query' => ['hash' => $editHash]]
- );
-
- return [
- $this->issueFactory->createNoticeDataObject($tempTitle, $tempMessage, $messageUrl),
- ];
- }
-
- /**
- * @return bool
- */
- public function isNeedProcess(): bool
- {
- return $this->amazonViewHelper->isInstallationWizardFinished() &&
- $this->amazonComponentHelper->isEnabled();
- }
-}
diff --git a/Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate.php b/Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate.php
new file mode 100644
index 000000000..25ea347c1
--- /dev/null
+++ b/Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate.php
@@ -0,0 +1,100 @@
+urlBuilder = $urlBuilder;
+ $this->amazonViewHelper = $amazonViewHelper;
+ $this->issueFactory = $issueFactory;
+ $this->amazonComponentHelper = $amazonComponentHelper;
+ $this->dictionaryProductTypeRepository = $dictionaryProductTypeRepository;
+ $this->amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ $this->cache = $cache;
+ }
+
+ public function getIssues(): array
+ {
+ if (!$this->isNeedProcess()) {
+ return [];
+ }
+
+ if (!$this->isExistOutOfDateProductTypes()) {
+ return [];
+ }
+
+ return [
+ $this->issueFactory->createNoticeDataObject(
+ __(
+ 'M2E Pro requires action: Amazon marketplace data needs to be synchronized.
+ Please update Amazon marketplaces.'
+ ),
+ __(
+ 'Data for some Product Types was changed on Amazon.
+ To avoid errors and have access to the latest updates,
+please use the Refresh Amazon Data button in Amazon > Product Types
+and re-save the Product Types you have configured.',
+ ['url' => $this->urlBuilder->getUrl('m2epro/amazon_template_productType/index')]
+ ),
+ null
+ ),
+ ];
+ }
+
+ private function isExistOutOfDateProductTypes(): bool
+ {
+ $outdatedMarketplaces = $this->cache->get();
+ if ($outdatedMarketplaces !== null) {
+ return $outdatedMarketplaces;
+ }
+
+ $activeMarketplaces = [];
+ foreach ($this->amazonMarketplaceRepository->findWithAccounts() as $marketplace) {
+ $activeMarketplaces[(int)$marketplace->getId()] = $marketplace;
+ }
+
+ $outdatedMarketplaces = [];
+ foreach ($this->dictionaryProductTypeRepository ->findValidOutOfDate() as $productType) {
+ if (!isset($activeMarketplaces[$productType->getMarketplaceId()])) {
+ continue;
+ }
+
+ if (isset($outdatedMarketplaces[$productType->getMarketplaceId()])) {
+ continue;
+ }
+
+ $outdatedMarketplaces[$productType->getMarketplaceId()] = true;
+ }
+
+ $this->cache->set($result = !empty($outdatedMarketplaces));
+
+ return $result;
+ }
+
+ public function isNeedProcess(): bool
+ {
+ return $this->amazonViewHelper->isInstallationWizardFinished() &&
+ $this->amazonComponentHelper->isEnabled();
+ }
+}
diff --git a/Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate/Cache.php b/Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate/Cache.php
new file mode 100644
index 000000000..a439d9c80
--- /dev/null
+++ b/Model/Amazon/Marketplace/Issue/ProductTypeOutOfDate/Cache.php
@@ -0,0 +1,42 @@
+permanentCache = $permanentCache;
+ }
+
+ public function set(bool $value): void
+ {
+ $this->permanentCache->setValue(
+ self::CACHE_KEY,
+ $value,
+ ['amazon', 'marketplace'],
+ 60 * 60
+ );
+ }
+
+ public function get(): ?bool
+ {
+ $value = $this->permanentCache->getValue(self::CACHE_KEY);
+ if ($value === null) {
+ return null;
+ }
+
+ return (bool)$value;
+ }
+
+ public function clear(): void
+ {
+ $this->permanentCache->removeValue(self::CACHE_KEY);
+ }
+}
diff --git a/Model/Amazon/Marketplace/Repository.php b/Model/Amazon/Marketplace/Repository.php
new file mode 100644
index 000000000..a3d44b6d6
--- /dev/null
+++ b/Model/Amazon/Marketplace/Repository.php
@@ -0,0 +1,104 @@
+collectionFactory = $collectionFactory;
+ $this->amazonAccountResource = $amazonAccountResource;
+ $this->marketplaceResource = $marketplaceResource;
+ $this->marketplaceFactory = $marketplaceFactory;
+ }
+
+ public function get(int $marketplaceId): \Ess\M2ePro\Model\Marketplace
+ {
+ $marketplace = $this->find($marketplaceId);
+ if ($marketplace === null) {
+ throw new \RuntimeException("Marketplace '$marketplaceId' not found");
+ }
+
+ return $marketplace;
+ }
+
+ public function find(int $marketplaceId): ?\Ess\M2ePro\Model\Marketplace
+ {
+ $model = $this->marketplaceFactory->create();
+ $this->marketplaceResource->load($model, $marketplaceId);
+ if ($model->isObjectNew()) {
+ return null;
+ }
+
+ if (!$model->isComponentModeAmazon()) {
+ return null;
+ }
+
+ return $model;
+ }
+
+ public function findByNativeId(int $nativeId): ?\Ess\M2ePro\Model\Marketplace
+ {
+ $collection = $this->collectionFactory->createWithAmazonChildMode();
+ $collection->addFieldToFilter(MarketplaceResource::COLUMN_NATIVE_ID, ['eq' => $nativeId]);
+
+ $marketplace = $collection->getFirstItem();
+ if ($marketplace->isObjectNew()) {
+ return null;
+ }
+
+ return $marketplace;
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Marketplace[]
+ */
+ public function findWithAccounts(): array
+ {
+ $collection = $this->collectionFactory->createWithAmazonChildMode();
+ $collection->joinInner(
+ ['account' => $this->amazonAccountResource->getMainTable()],
+ sprintf(
+ 'main_table.%s = account.%s',
+ MarketplaceResource::COLUMN_ID,
+ AmazonAccountResource::COLUMN_MARKETPLACE_ID,
+ ),
+ []
+ );
+ $collection->getSelect()->group(sprintf('main_table.%s', MarketplaceResource::COLUMN_ID));
+
+ return array_values($collection->getItems());
+ }
+
+ /**
+ * @return \Ess\M2ePro\Model\Marketplace[]
+ */
+ public function findActive(): array
+ {
+ $collection = $this->collectionFactory->createWithAmazonChildMode();
+ $collection->addFieldToFilter(
+ MarketplaceResource::COLUMN_STATUS,
+ ['eq' => \Ess\M2ePro\Model\Marketplace::STATUS_ENABLE]
+ )
+ ->setOrder(MarketplaceResource::COLUMN_SORDER, 'ASC');
+
+ return array_values($collection->getItems());
+ }
+}
diff --git a/Model/Amazon/Marketplace/Synchronization.php b/Model/Amazon/Marketplace/Synchronization.php
deleted file mode 100644
index 1bb800a02..000000000
--- a/Model/Amazon/Marketplace/Synchronization.php
+++ /dev/null
@@ -1,311 +0,0 @@
-productTypeHelper = $productTypeHelper;
- $this->activeRecordFactory = $activeRecordFactory;
- $this->resourceConnection = $resourceConnection;
- }
-
- public function setMarketplace(\Ess\M2ePro\Model\Marketplace $marketplace)
- {
- $this->marketplace = $marketplace;
-
- return $this;
- }
-
- public function isLocked()
- {
- if (!$this->getLockItemManager()->isExist()) {
- return false;
- }
-
- if ($this->getLockItemManager()->isInactiveMoreThanSeconds(self::LOCK_ITEM_MAX_ALLOWED_INACTIVE_TIME)) {
- $this->getLockItemManager()->remove();
-
- return false;
- }
-
- return true;
- }
-
- /**
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function process(): void
- {
- $this->getLockItemManager()->create();
- $this->getProgressManager()->setPercentage(0);
-
- $this->prepareExistingProductTypesNicks();
- $this->processDetails();
- $removedProductTypes = array_diff($this->existingProductTypesNicks, $this->newProductTypesNicks);
- $this->removedOldProductTypes($removedProductTypes);
-
- $specificsSteps = $this->getSpecificsStepsCount();
- $steps = 1 + $specificsSteps; // 1 step for details, other steps for specifics
- $percentsPerStep = (int)floor(100 / $steps);
-
- $this->getProgressManager()->setPercentage($percentsPerStep);
-
- for ($i = 0; $i < $specificsSteps; $i++) {
- $this->processSpecificsStep($i);
- $this->getProgressManager()->setPercentage($percentsPerStep * (2 + $i));
- }
-
- $this->getHelper('Data_Cache_Permanent')->removeTagValues('marketplace');
-
- $this->getProgressManager()->setPercentage(100);
-
- $this->getLockItemManager()->remove();
- }
-
- private function processDetails(): void
- {
- /** @var \Ess\M2ePro\Model\Amazon\Connector\Dispatcher $dispatcherObj */
- $dispatcherObj = $this->modelFactory->getObject('Amazon_Connector_Dispatcher');
- $connectorObj = $dispatcherObj->getVirtualConnector(
- 'marketplace',
- 'get',
- 'info',
- [
- 'include_details' => true,
- 'marketplace' => $this->marketplace->getNativeId(),
- ],
- 'info',
- null
- );
-
- $dispatcherObj->process($connectorObj);
- $details = $connectorObj->getResponseData();
-
- if ($details === null) {
- return;
- }
-
- $tableMarketplaces = $this->getHelper('Module_Database_Structure')
- ->getTableNameWithPrefix('m2epro_amazon_dictionary_marketplace');
-
- $this->resourceConnection->getConnection()->delete(
- $tableMarketplaces,
- ['marketplace_id = ?' => $this->marketplace->getId()]
- );
-
- // todo \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace
- $data = [
- 'marketplace_id' => $this->marketplace->getId(),
- 'client_details_last_update_date' => $details['last_update'] ?? null,
- 'server_details_last_update_date' => $details['last_update'] ?? null,
- 'product_types' => \Ess\M2ePro\Helper\Json::encode(
- $this->prepareProductTypes($details['details']['product_type'])
- ),
- ];
-
- $this->resourceConnection->getConnection()->insert($tableMarketplaces, $data);
-
- $this->prepareNewProductTypesNicks($details['details']['product_type']);
- }
-
- /**
- * @param array $productTypes
- *
- * @return array
- */
- private function prepareProductTypes(array $productTypes): array
- {
- $result = [];
-
- foreach ($productTypes as $productType) {
- $result[$productType['nick']] = $productType;
- }
-
- return $result;
- }
-
- /**
- * @return void
- */
- private function prepareExistingProductTypesNicks(): void
- {
- $productTypes = $this->productTypeHelper->getProductTypesInDictionary(
- (int)$this->marketplace->getId()
- );
-
- /** @var \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productType */
- foreach ($productTypes as $productType) {
- $this->existingProductTypesNicks[] = $productType->getNick();
- }
- }
-
- private function prepareNewProductTypesNicks(array $productTypes): void
- {
- foreach ($productTypes as $productType) {
- $this->newProductTypesNicks[] = $productType['nick'];
- }
- }
-
- /**
- * @param array $removedProductTypes
- *
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- private function removedOldProductTypes(array $removedProductTypes): void
- {
- if (empty($removedProductTypes)) {
- return;
- }
-
- $listToMarkInvalid = [];
- $listToRemove = [];
- $configuredProductTypes = $this->productTypeHelper
- ->getConfiguredProductTypesList((int)$this->marketplace->getId());
-
- foreach ($removedProductTypes as $nick) {
- if (isset($configuredProductTypes[$nick])) {
- $listToMarkInvalid[] = $nick;
- } else {
- $listToRemove[] = $nick;
- }
- }
-
- if (!empty($listToMarkInvalid)) {
- $this->productTypeHelper->markProductTypeDictionariesInvalid(
- (int)$this->marketplace->getId(),
- $listToMarkInvalid
- );
- }
-
- if (!empty($listToRemove)) {
- $this->productTypeHelper->removeProductTypeDictionaries(
- (int)$this->marketplace->getId(),
- $listToRemove
- );
- }
- }
-
- /**
- * @return int
- */
- private function getSpecificsStepsCount(): int
- {
- $this->productTypes = array_values(
- $this->productTypeHelper->getProductTypesInDictionary(
- (int)$this->marketplace->getId(),
- true
- )
- );
-
- return count($this->productTypes);
- }
-
- /**
- * @param int $step
- *
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- private function processSpecificsStep(int $step): void
- {
- if (empty($this->productTypes[$step])) {
- return;
- }
-
- /** @var \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $productTypeDictionary */
- $productTypeDictionary = $this->productTypes[$step];
-
- $this->productTypeHelper->updateProductTypeDictionary(
- $productTypeDictionary,
- $this->marketplace->getId(),
- $productTypeDictionary->getNick()
- );
- }
-
- public function getLockItemManager()
- {
- if ($this->lockItemManager !== null) {
- return $this->lockItemManager;
- }
-
- return $this->lockItemManager = $this->modelFactory->getObject('Lock_Item_Manager', [
- 'nick' => \Ess\M2ePro\Helper\Component\Amazon::MARKETPLACE_SYNCHRONIZATION_LOCK_ITEM_NICK,
- ]);
- }
-
- public function getProgressManager()
- {
- if ($this->progressManager !== null) {
- return $this->progressManager;
- }
-
- return $this->progressManager = $this->modelFactory->getObject('Lock_Item_Progress', [
- 'lockItemManager' => $this->getLockItemManager(),
- 'progressNick' => '',
- ]);
- }
-
- public function getLog()
- {
- if ($this->synchronizationLog !== null) {
- return $this->synchronizationLog;
- }
-
- $this->synchronizationLog = $this->activeRecordFactory->getObject('Synchronization\Log');
- $this->synchronizationLog->setComponentMode(\Ess\M2ePro\Helper\Component\Amazon::NICK);
- $this->synchronizationLog->setSynchronizationTask(\Ess\M2ePro\Model\Synchronization\Log::TASK_MARKETPLACES);
-
- return $this->synchronizationLog;
- }
-}
diff --git a/Model/Amazon/Marketplace/SynchronizationFactory.php b/Model/Amazon/Marketplace/SynchronizationFactory.php
deleted file mode 100644
index e49550d26..000000000
--- a/Model/Amazon/Marketplace/SynchronizationFactory.php
+++ /dev/null
@@ -1,25 +0,0 @@
-objectManager = $objectManager;
- }
-
- public function create(): Synchronization
- {
- return $this->objectManager->create(Synchronization::class);
- }
-}
diff --git a/Model/Amazon/Marketplace/Updater.php b/Model/Amazon/Marketplace/Updater.php
deleted file mode 100644
index b89e5f681..000000000
--- a/Model/Amazon/Marketplace/Updater.php
+++ /dev/null
@@ -1,50 +0,0 @@
-dispatcher = $dispatcher;
- $this->synchronization = $synchronization;
- }
-
- public function update(\Ess\M2ePro\Model\Marketplace $marketplace): bool
- {
- $synchronization = $this->synchronization;
- $synchronization->setMarketplace($marketplace);
-
- if ($synchronization->isLocked()) {
- $synchronization->getLog()->addMessage(
- 'Marketplaces cannot be updated now. '
- . 'Please wait until another marketplace synchronization is completed, then try again.',
- \Ess\M2ePro\Model\Log\AbstractModel::TYPE_ERROR
- );
- return false;
- }
-
- try {
- $synchronization->process();
- } catch (\Exception $e) {
- $synchronization->getLog()->addMessageFromException($e);
-
- $synchronization->getLockItemManager()->remove();
-
- $this->dispatcher->processTask(
- \Ess\M2ePro\Model\Servicing\Task\License::NAME
- );
-
- return false;
- }
-
- return true;
- }
-}
diff --git a/Model/Amazon/Order.php b/Model/Amazon/Order.php
index 81a8cb9a5..015277ae1 100644
--- a/Model/Amazon/Order.php
+++ b/Model/Amazon/Order.php
@@ -216,6 +216,13 @@ public function getTaxRegistrationId()
return $this->getData('tax_registration_id');
}
+ public function setTaxRegistrationId(string $taxRegistrationId): Order
+ {
+ $this->setData('tax_registration_id', $taxRegistrationId);
+
+ return $this;
+ }
+
/**
* @return bool
*/
diff --git a/Model/Amazon/ProductType/AttributesValidator.php b/Model/Amazon/ProductType/AttributesValidator.php
index 976411ee6..5d45eb966 100644
--- a/Model/Amazon/ProductType/AttributesValidator.php
+++ b/Model/Amazon/ProductType/AttributesValidator.php
@@ -6,8 +6,6 @@ class AttributesValidator
{
public const ERROR_TAG_CODE = '99001-m2e';
- /** @var \Ess\M2ePro\Helper\Component\Amazon\ProductType */
- private $productTypeHelper;
/** @var \Ess\M2ePro\Model\ResourceModel\Amazon\ProductType\Validation */
private $productTypeValidationResource;
/** @var \Ess\M2ePro\Model\Amazon\ProductType\ValidationFactory */
@@ -18,21 +16,22 @@ class AttributesValidator
private $amazonTagFactory;
/** @var \Ess\M2ePro\Model\TagFactory */
private $baseTagFactory;
+ private \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $templateProductTypeRepository;
public function __construct(
- \Ess\M2ePro\Helper\Component\Amazon\ProductType $productTypeHelper,
+ \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $templateProductTypeRepository,
\Ess\M2ePro\Model\ResourceModel\Amazon\ProductType\Validation $productTypeValidationResource,
\Ess\M2ePro\Model\Amazon\ProductType\ValidationFactory $productTypeValidationFactory,
\Ess\M2ePro\Model\Tag\ListingProduct\Buffer $tagBuffer,
\Ess\M2ePro\Model\Amazon\TagFactory $amazonTagFactory,
\Ess\M2ePro\Model\TagFactory $baseTagFactory
) {
- $this->productTypeHelper = $productTypeHelper;
$this->productTypeValidationResource = $productTypeValidationResource;
$this->productTypeValidationFactory = $productTypeValidationFactory;
$this->tagBuffer = $tagBuffer;
$this->amazonTagFactory = $amazonTagFactory;
$this->baseTagFactory = $baseTagFactory;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
}
public function validate(
@@ -55,10 +54,11 @@ public function validate(
$validationResult->setErrorMessages([]);
try {
- $productType = $this->productTypeHelper->getProductTypeById($productTypeId);
- } catch (\Ess\M2ePro\Model\Exception\Logic $exception) {
+ $productType = $this->templateProductTypeRepository->get($productTypeId);
+ } catch (\Ess\M2ePro\Model\Exception\EntityNotFound $exception) {
$validationResult->setInvalidStatus();
- $validationResult->addErrorMessage(\__('Product Type not found'));
+ $validationResult->addErrorMessage(__('Product Type not found'));
+
$resource->save($validationResult);
return;
diff --git a/Model/Amazon/ProductType/CategoryFinder/Repository.php b/Model/Amazon/ProductType/CategoryFinder/Repository.php
index 6c5e6ab06..9a36cadfc 100644
--- a/Model/Amazon/ProductType/CategoryFinder/Repository.php
+++ b/Model/Amazon/ProductType/CategoryFinder/Repository.php
@@ -4,25 +4,15 @@
class Repository
{
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\Marketplace\CollectionFactory */
- private $marketplaceDictionaryCollectionFactory;
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType\CollectionFactory */
- private $dictionaryProductTypeCollectionFactory;
- /** @var \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory */
- private $templateProductTypeCollectionFactory;
- /** @var \Ess\M2ePro\Helper\Component\Amazon\ProductType */
- private $productTypeHelper;
+ private \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace\Repository $dictionaryMarketplaceRepository;
+ private \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $templateProductTypeRepository;
public function __construct(
- \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\Marketplace\CollectionFactory $marketplaceCollectionFactory,
- \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType\CollectionFactory $productTypeCollectionFactory,
- \Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\CollectionFactory $templateTypeCollectionFactory,
- \Ess\M2ePro\Helper\Component\Amazon\ProductType $productTypeHelper
+ \Ess\M2ePro\Model\Amazon\Template\ProductType\Repository $templateProductTypeRepository,
+ \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace\Repository $dictionaryMarketplaceRepository
) {
- $this->marketplaceDictionaryCollectionFactory = $marketplaceCollectionFactory;
- $this->dictionaryProductTypeCollectionFactory = $productTypeCollectionFactory;
- $this->templateProductTypeCollectionFactory = $templateTypeCollectionFactory;
- $this->productTypeHelper = $productTypeHelper;
+ $this->dictionaryMarketplaceRepository = $dictionaryMarketplaceRepository;
+ $this->templateProductTypeRepository = $templateProductTypeRepository;
}
/**
@@ -30,52 +20,38 @@ public function __construct(
* @param array $nicks
*
* @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
*/
public function getAvailableProductTypes(int $marketplaceId, array $nicks): array
{
- $productTypes = $this->getProductTypesFromMarketplaceDictionary($marketplaceId);
- $alreadyUsedProductTypes = $this->productTypeHelper->getConfiguredProductTypesList($marketplaceId);
+ $productTypesMap = $this->getProductTypesFromMarketplaceDictionary($marketplaceId);
+ $alreadyUsedProductTypesMap = $this->getProductTypesTemplates($marketplaceId);
$availableProductTypes = [];
foreach ($nicks as $nick) {
- foreach ($productTypes as $productType) {
- if ($nick == $productType['nick']) {
- $availableProductTypes[$nick] = [
- 'nick' => $productType['nick'],
- 'title' => $productType['title'],
- 'templateId' => $alreadyUsedProductTypes[$productType['nick']] ?? null,
- ];
- }
+ if (isset($productTypesMap[$nick])) {
+ $availableProductTypes[$nick] = [
+ 'nick' => $productTypesMap[$nick]['nick'],
+ 'title' => $productTypesMap[$nick]['title'],
+ 'templateId' => $alreadyUsedProductTypesMap[$productTypesMap[$nick]['nick']] ?? null,
+ ];
}
}
return $availableProductTypes;
}
- /**
- * @param int $marketplaceId
- *
- * @return list
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
private function getProductTypesFromMarketplaceDictionary(int $marketplaceId): array
{
- $collection = $this->marketplaceDictionaryCollectionFactory->create();
- $collection->appendFilterMarketplaceId($marketplaceId);
-
- /** @var \Ess\M2ePro\Model\Amazon\Dictionary\Marketplace $marketplaceDictionaryItem */
- $marketplaceDictionaryItem = $collection->getFirstItem();
-
- if ($marketplaceDictionaryItem === null) {
+ $dictionary = $this->dictionaryMarketplaceRepository->findByMarketplaceId($marketplaceId);
+ if ($dictionary === null) {
return [];
}
- $productTypes = $marketplaceDictionaryItem->getProductTypes();
+ $productTypes = $dictionary->getProductTypes();
$result = [];
foreach ($productTypes as $productType) {
- $result[] = [
+ $result[$productType['nick']] = [
'nick' => $productType['nick'],
'title' => $productType['title'],
];
@@ -83,4 +59,14 @@ private function getProductTypesFromMarketplaceDictionary(int $marketplaceId): a
return $result;
}
+
+ private function getProductTypesTemplates(int $marketplaceId): array
+ {
+ $result = [];
+ foreach ($this->templateProductTypeRepository->findByMarketplaceId($marketplaceId) as $productType) {
+ $result[$productType->getNick()] = (int)$productType->getId();
+ }
+
+ return $result;
+ }
}
diff --git a/Model/Amazon/Template/ProductType.php b/Model/Amazon/Template/ProductType.php
index 9ce9463c0..6d1adf139 100644
--- a/Model/Amazon/Template/ProductType.php
+++ b/Model/Amazon/Template/ProductType.php
@@ -1,19 +1,9 @@
productTypeHelper = $productTypeHelper;
+ $this->dictionaryProductTypeRepository = $dictionaryProductTypeRepository;
}
- /**
- * @return void
- */
- public function _construct()
+ public function _construct(): void
{
parent::_construct();
- $this->_init(\Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType::class);
+ $this->_init(ProductTypeResource::class);
}
- /**
- * @return int
- */
public function getDictionaryProductTypeId(): int
{
- return (int)$this->getData('dictionary_product_type_id');
+ return (int)$this->getData(ProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID);
+ }
+
+ public function getDictionary(): \Ess\M2ePro\Model\Amazon\Dictionary\ProductType
+ {
+ if (!isset($this->dictionary)) {
+ $this->dictionary = $this->dictionaryProductTypeRepository->get(
+ $this->getDictionaryProductTypeId()
+ );
+ }
+
+ return $this->dictionary;
}
- /**
- * @return int
- */
public function getMarketplaceId(): int
{
return $this->getDictionary()->getMarketplaceId();
}
- /**
- * @return string
- */
public function getNick(): string
{
return $this->getDictionary()->getNick();
@@ -101,30 +76,12 @@ public function getNick(): string
public function getTitle(): ?string
{
- return $this->getData('title');
+ return $this->getData(ProductTypeResource::COLUMN_TITLE);
}
- /**
- * @return \Ess\M2ePro\Model\Amazon\Dictionary\ProductType
- */
- public function getDictionary(): \Ess\M2ePro\Model\Amazon\Dictionary\ProductType
- {
- if ($this->dictionary === null) {
- $this->dictionary = $this->productTypeHelper->getProductTypeDictionaryById(
- $this->getDictionaryProductTypeId()
- );
- }
-
- return $this->dictionary;
- }
-
- /**
- * @return array
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function getCustomAttributesName(): array
{
- $specifics = $this->getSettings('settings');
+ $specifics = $this->getSelfSetting();
$customAttributes = [];
foreach ($specifics as $values) {
foreach ($values as $value) {
@@ -162,7 +119,8 @@ public function getCustomAttributesList(): array
private function getCustomAttributes(): array
{
- $specifics = $this->getSettings('settings');
+ $specifics = $this->getSelfSetting();
+
$filterCallback = static function (array $values) {
foreach ($values as $value) {
if (!isset($value['mode'])) {
@@ -180,11 +138,21 @@ private function getCustomAttributes(): array
public function getViewMode(): int
{
- $viewMode = $this->getData('view_mode');
+ $viewMode = $this->getData(ProductTypeResource::COLUMN_VIEW_MODE);
if ($viewMode === null) {
return self::VIEW_MODE_REQUIRED_ATTRIBUTES;
}
return (int)$viewMode;
}
+
+ public function getSelfSetting(): array
+ {
+ $value = $this->getData(ProductTypeResource::COLUMN_SETTINGS);
+ if (empty($value)) {
+ return [];
+ }
+
+ return (array)json_decode($value, true);
+ }
}
diff --git a/Model/Amazon/Template/ProductType/Builder.php b/Model/Amazon/Template/ProductType/Builder.php
index 58a966f8f..49082dd86 100644
--- a/Model/Amazon/Template/ProductType/Builder.php
+++ b/Model/Amazon/Template/ProductType/Builder.php
@@ -15,31 +15,19 @@ class Builder extends \Ess\M2ePro\Model\ActiveRecord\AbstractBuilder
/** @var array */
private $otherImagesSpecifics;
- /** @var \Ess\M2ePro\Helper\Component\Amazon\ProductType */
- private $productTypeHelper;
+ private \Ess\M2ePro\Model\Amazon\Dictionary\ProductType\Repository $dictionaryProductTypeRepository;
- /**
- * @param \Ess\M2ePro\Helper\Component\Amazon\ProductType $productTypeHelper
- * @param \Ess\M2ePro\Helper\Factory $helperFactory
- * @param \Ess\M2ePro\Model\Factory $modelFactory
- * @param array $data
- */
public function __construct(
- \Ess\M2ePro\Helper\Component\Amazon\ProductType $productTypeHelper,
+ \Ess\M2ePro\Model\Amazon\Dictionary\ProductType\Repository $dictionaryProductTypeRepository,
\Ess\M2ePro\Helper\Factory $helperFactory,
\Ess\M2ePro\Model\Factory $modelFactory,
array $data = []
) {
parent::__construct($helperFactory, $modelFactory, $data);
- $this->productTypeHelper = $productTypeHelper;
- $this->otherImagesSpecifics = $productTypeHelper->getOtherImagesSpecifics();
+ $this->otherImagesSpecifics = \Ess\M2ePro\Helper\Component\Amazon\ProductType::getOtherImagesSpecifics();
+ $this->dictionaryProductTypeRepository = $dictionaryProductTypeRepository;
}
- /**
- * @return array|mixed|string[]
- * @throws \Ess\M2ePro\Model\Exception
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
protected function prepareData()
{
if ($this->model->getId()) {
@@ -59,11 +47,11 @@ protected function prepareData()
$temp[$key] = $this->rawData['general'][$key];
}
- $dictionary = $this->productTypeHelper->getProductTypeDictionary(
+ $dictionary = $this->dictionaryProductTypeRepository->findByMarketplaceAndNick(
(int)$temp['marketplace_id'],
(string)$temp['nick']
);
- if (!$dictionary->getId()) {
+ if ($dictionary === null) {
throw new \Ess\M2ePro\Model\Exception(
"Product Type data not found for provided marketplace_id and product type nick"
);
diff --git a/Model/Amazon/Template/ProductType/Repository.php b/Model/Amazon/Template/ProductType/Repository.php
new file mode 100644
index 000000000..3ebb36495
--- /dev/null
+++ b/Model/Amazon/Template/ProductType/Repository.php
@@ -0,0 +1,282 @@
+resource = $resource;
+ $this->collectionFactory = $collectionFactory;
+ $this->dictionaryProductTypeResource = $dictionaryProductTypeResource;
+ $this->productTypeFactory = $productTypeFactory;
+ $this->marketplaceResource = $marketplaceResource;
+ $this->marketplaceCollectionFactory = $marketplaceCollectionFactory;
+ $this->listingProductCollectionFactory = $listingProductCollectionFactory;
+ }
+
+ public function create(\Ess\M2ePro\Model\Amazon\Template\ProductType $productType): void
+ {
+ $this->resource->save($productType);
+ }
+
+ public function find(int $id): ?\Ess\M2ePro\Model\Amazon\Template\ProductType
+ {
+ if (($model = $this->tryGetFromRuntimeCache($id)) !== null) {
+ return $model;
+ }
+
+ $model = $this->productTypeFactory->createEmpty();
+ $this->resource->load($model, $id);
+
+ if ($model->isObjectNew()) {
+ return null;
+ }
+
+ $this->addToRuntimeCache($model);
+
+ return $model;
+ }
+
+ public function get(int $id): \Ess\M2ePro\Model\Amazon\Template\ProductType
+ {
+ $mode = $this->find($id);
+ if ($mode === null) {
+ throw new \Ess\M2ePro\Model\Exception\EntityNotFound("Product Type template $id not found.");
+ }
+
+ return $mode;
+ }
+
+ public function save(\Ess\M2ePro\Model\Amazon\Template\ProductType $productType): void
+ {
+ $this->resource->save($productType);
+ }
+
+ public function remove(\Ess\M2ePro\Model\Amazon\Template\ProductType $productType): void
+ {
+ $this->removeFromRuntimeCache((int)$productType->getId());
+
+ $this->resource->delete($productType);
+ }
+
+ // ----------------------------------------
+
+ public function findByTitleMarketplace(
+ string $title,
+ int $marketplaceId,
+ ?int $productTypeId
+ ): ?\Ess\M2ePro\Model\Amazon\Template\ProductType {
+ $collection = $this->collectionFactory->create();
+ $collection->joinInner(
+ ['dictionary' => $this->dictionaryProductTypeResource->getMainTable()],
+ sprintf('dictionary.id = %s', ProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID),
+ ['marketplace_id' => 'marketplace_id']
+ );
+
+ $collection->addFieldToFilter(sprintf('main_table.%s', ProductTypeResource::COLUMN_TITLE), ['eq' => $title]);
+ $collection->addFieldToFilter('dictionary.marketplace_id', ['eq' => $marketplaceId]);
+ if ($productTypeId !== null) {
+ $collection->addFieldToFilter('main_table.id', ['neq' => $productTypeId]);
+ }
+
+ $result = $collection->getFirstItem();
+ if ($result->isObjectNew()) {
+ return null;
+ }
+
+ return $result;
+ }
+
+ public function findByMarketplaceIdAndNick(
+ int $marketplaceId,
+ string $nick
+ ): ?\Ess\M2ePro\Model\Amazon\Template\ProductType {
+ $collection = $this->collectionFactory->create();
+ $collection->joinInner(
+ ['dictionary' => $this->dictionaryProductTypeResource->getMainTable()],
+ sprintf('dictionary.id = %s', ProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID),
+ ['marketplace_id' => 'marketplace_id']
+ );
+
+ $collection->addFieldToFilter(
+ sprintf('dictionary.%s', DictionaryProductTypeResource::COLUMN_NICK),
+ ['eq' => $nick]
+ );
+ $collection->addFieldToFilter(
+ sprintf('dictionary.%s', DictionaryProductTypeResource::COLUMN_MARKETPLACE_ID),
+ ['eq' => $marketplaceId]
+ );
+
+ $result = $collection->getFirstItem();
+ if ($result->isObjectNew()) {
+ return null;
+ }
+
+ return $result;
+ }
+
+ /**
+ * @param int $marketplaceId
+ *
+ * @return \Ess\M2ePro\Model\Amazon\Template\ProductType[]
+ */
+ public function findByMarketplaceId(int $marketplaceId): array
+ {
+ $collection = $this->collectionFactory->create();
+ $collection->joinInner(
+ ['dictionary' => $this->dictionaryProductTypeResource->getMainTable()],
+ sprintf(
+ 'main_table.%s = dictionary.%s',
+ ProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID,
+ DictionaryProductTypeResource::COLUMN_ID,
+ ),
+ [],
+ );
+ $collection->addFieldToFilter(
+ sprintf(
+ 'dictionary.%s',
+ DictionaryProductTypeResource::COLUMN_MARKETPLACE_ID,
+ ),
+ ['eq' => $marketplaceId]
+ );
+
+ return array_values($collection->getItems());
+ }
+
+ /**
+ * @param \Ess\M2ePro\Model\Amazon\Dictionary\ProductType $dictionaryProductType
+ *
+ * @return \Ess\M2ePro\Model\Amazon\Template\ProductType[]
+ */
+ public function findByDictionary(\Ess\M2ePro\Model\Amazon\Dictionary\ProductType $dictionaryProductType): array
+ {
+ $collection = $this->collectionFactory->create();
+ $collection->addFieldToFilter(
+ ProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID,
+ ['eq' => $dictionaryProductType->getId()]
+ );
+
+ return array_values($collection->getItems());
+ }
+
+ // ----------------------------------------
+
+ /**
+ * @return \Ess\M2ePro\Model\Marketplace[]
+ */
+ public function getUsingMarketplaces(): array
+ {
+ $marketplaceCollection = $this->marketplaceCollectionFactory->createWithAmazonChildMode();
+ $marketplaceCollection->getSelect()
+ ->joinInner(
+ ['dictionary' => $this->dictionaryProductTypeResource->getMainTable()],
+ sprintf(
+ 'dictionary.%s = main_table.%s',
+ DictionaryProductTypeResource::COLUMN_MARKETPLACE_ID,
+ \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_ID
+ ),
+ []
+ );
+ $marketplaceCollection->getSelect()
+ ->joinInner(
+ ['template' => $this->resource->getMainTable()],
+ sprintf(
+ 'template.%s = dictionary.%s',
+ ProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID,
+ DictionaryProductTypeResource::COLUMN_ID
+ ),
+ []
+ );
+
+ $marketplaceCollection->getSelect()
+ ->group(sprintf('main_table.%s', \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_ID));
+
+ $marketplaceCollection->setOrder(
+ sprintf('main_table.%s', \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_SORDER),
+ 'ASC'
+ );
+
+ return array_values($marketplaceCollection->getItems());
+ }
+
+ public function isUsed(\Ess\M2ePro\Model\Amazon\Template\ProductType $productType): bool
+ {
+ $collection = $this->listingProductCollectionFactory->createWithAmazonChildMode();
+
+ $collection->getSelect()
+ ->where(
+ sprintf('%s = ?', AmazonProductResource::COLUMN_TEMPLATE_PRODUCT_TYPE_ID),
+ $productType->getId()
+ )
+ ->limit(1);
+
+ $product = $collection->getFirstItem();
+
+ return !$product->isObjectNew();
+ }
+
+ // ----------------------------------------
+
+ public function getCollectionForGrid(): ProductTypeResource\Collection
+ {
+ $collection = $this->collectionFactory->create();
+ $collection->getSelect()->join(
+ ['adpt' => $this->dictionaryProductTypeResource->getMainTable()],
+ sprintf(
+ 'adpt.%s = main_table.%s',
+ DictionaryProductTypeResource::COLUMN_ID,
+ ProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID
+ ),
+ ['product_type_title' => sprintf('adpt.%s', DictionaryProductTypeResource::COLUMN_TITLE)]
+ );
+
+ $collection->getSelect()->join(
+ ['m' => $this->marketplaceResource->getMainTable()],
+ sprintf('m.id = adpt.%s', DictionaryProductTypeResource::COLUMN_MARKETPLACE_ID),
+ ['marketplace_title' => sprintf('m.%s', \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_TITLE)]
+ );
+
+ return $collection;
+ }
+
+ // ----------------------------------------
+
+ private function addToRuntimeCache(\Ess\M2ePro\Model\Amazon\Template\ProductType $productType): void
+ {
+ $this->runtimeCache[(int)$productType->getId()] = $productType;
+ }
+
+ private function removeFromRuntimeCache(int $id): void
+ {
+ unset($this->runtimeCache[$id]);
+ }
+
+ private function tryGetFromRuntimeCache(int $id): ?\Ess\M2ePro\Model\Amazon\Template\ProductType
+ {
+ return $this->runtimeCache[$id] ?? null;
+ }
+}
diff --git a/Model/Amazon/Template/ProductTypeFactory.php b/Model/Amazon/Template/ProductTypeFactory.php
index 2739008e8..b45c6129e 100644
--- a/Model/Amazon/Template/ProductTypeFactory.php
+++ b/Model/Amazon/Template/ProductTypeFactory.php
@@ -1,17 +1,12 @@
objectManager->create(ProductType::class);
}
+
+ public function createEmpty(): ProductType
+ {
+ return $this->objectManager->create(ProductType::class);
+ }
}
diff --git a/Model/Cron/Task/Amazon/Order/Receive/Details/Responser.php b/Model/Cron/Task/Amazon/Order/Receive/Details/Responser.php
index 9bbfcf2f3..1ba1dac36 100644
--- a/Model/Cron/Task/Amazon/Order/Receive/Details/Responser.php
+++ b/Model/Cron/Task/Amazon/Order/Receive/Details/Responser.php
@@ -128,7 +128,7 @@ protected function processResponseData()
continue;
}
- /** @var \Ess\M2ePro\Model\Magento\Order\Updater $magentoOrderUpdater */
+ /** @var \Ess\M2ePro\Model\Magento\Order\Updater $orderUpdater */
$orderUpdater = $this->modelFactory->getObject('Magento_Order_Updater');
$orderUpdater->setMagentoOrder($order->getMagentoOrder());
$orderUpdater->updateComments($order->getChildObject()->getProxy()->getAFNWarehouseComments());
diff --git a/Model/Cron/Task/Amazon/Order/Receive/InvoiceDataReport/Responser.php b/Model/Cron/Task/Amazon/Order/Receive/InvoiceDataReport/Responser.php
index 5869b89d2..a1cc385aa 100644
--- a/Model/Cron/Task/Amazon/Order/Receive/InvoiceDataReport/Responser.php
+++ b/Model/Cron/Task/Amazon/Order/Receive/InvoiceDataReport/Responser.php
@@ -1,29 +1,39 @@
orderUpdater = $orderUpdater;
+
+ parent::__construct(
+ $response,
+ $helperFactory,
+ $modelFactory,
+ $amazonFactory,
+ $walmartFactory,
+ $ebayFactory,
+ $activeRecordFactory,
+ $params
+ );
+ }
- //########################################
-
- /**
- * @param array $messages
- *
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- protected function processResponseMessages(array $messages = [])
+ protected function processResponseMessages(array $messages = []): void
{
parent::processResponseMessages();
@@ -36,16 +46,13 @@ protected function processResponseMessages(array $messages = [])
: \Ess\M2ePro\Model\Log\AbstractModel::TYPE_WARNING;
$this->getSynchronizationLog()->addMessage(
- $this->getHelper('Module_Translation')->__($message->getText()),
+ (string)__($message->getText()),
$logType
);
}
}
- /**
- * @return bool
- */
- protected function isNeedProcessResponse()
+ protected function isNeedProcessResponse(): bool
{
if (!parent::isNeedProcessResponse()) {
return false;
@@ -58,27 +65,17 @@ protected function isNeedProcessResponse()
return true;
}
- //########################################
-
- /**
- * @param string $messageText
- */
- public function failDetected($messageText)
+ public function failDetected($messageText): void
{
parent::failDetected($messageText);
$this->getSynchronizationLog()->addMessage(
- $this->getHelper('Module_Translation')->__($messageText),
+ (string)__($messageText),
\Ess\M2ePro\Model\Log\AbstractModel::TYPE_ERROR
);
}
- //########################################
-
- /**
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
- protected function processResponseData()
+ protected function processResponseData(): void
{
$responseData = $this->getPreparedResponseData();
$responseData = $responseData['data'];
@@ -110,6 +107,22 @@ protected function processResponseData()
continue;
}
+ $buyerVatNumber = $orderData['buyer-vat-number'] ?? null;
+
+ if (!empty($buyerVatNumber)) {
+ if (empty($order->getChildObject()->getTaxRegistrationId())) {
+ $order->getChildObject()->setTaxRegistrationId($buyerVatNumber);
+
+ $magentoOrder = $order->getMagentoOrder();
+ if ($magentoOrder !== null) {
+ $this->orderUpdater->setMagentoOrder($magentoOrder);
+ $this->orderUpdater->updateShippingAddress(['vat_id' => $buyerVatNumber]);
+ $this->orderUpdater->updateBillingAddress(['vat_id' => $buyerVatNumber]);
+ $this->orderUpdater->finishUpdate();
+ }
+ }
+ }
+
$order->getChildObject()->setSettings('invoice_data_report', $orderData);
$order->getChildObject()->save();
@@ -117,12 +130,7 @@ protected function processResponseData()
}
}
- //########################################
-
- /**
- * @return \Ess\M2ePro\Model\Synchronization\Log
- */
- protected function getSynchronizationLog()
+ protected function getSynchronizationLog(): \Ess\M2ePro\Model\Synchronization\Log
{
if ($this->synchronizationLog !== null) {
return $this->synchronizationLog;
@@ -134,6 +142,4 @@ protected function getSynchronizationLog()
return $this->synchronizationLog;
}
-
- //########################################
}
diff --git a/Model/Ebay/Connector/Item/Responser.php b/Model/Ebay/Connector/Item/Responser.php
index 03b90f6a1..65b4ac9a3 100644
--- a/Model/Ebay/Connector/Item/Responser.php
+++ b/Model/Ebay/Connector/Item/Responser.php
@@ -293,7 +293,7 @@ protected function isNewRequiredSpecificNeeded(Message $message): bool
/**
* @param Message[] $messages
*
- * @return Message|bool
+ * @return Message|false
* 21916587: The multi-variation titles have been changed and were not updated on the eBay.
* 21916626: Variations Specifics and Item Specifics entered for a Multi-SKU item should be different.
* 21916603: Variation specifics cannot be changed in restricted revise
@@ -316,6 +316,7 @@ protected function isVariationErrorAppeared(array $messages)
21916582,
21916672,
21919061,
+ 21916591, // A variation could not be found for the given SKU number {0}.
];
foreach ($messages as $message) {
diff --git a/Model/Ebay/Dashboard/Sales/Calculator.php b/Model/Ebay/Dashboard/Sales/Calculator.php
index a86b7f182..738efd654 100644
--- a/Model/Ebay/Dashboard/Sales/Calculator.php
+++ b/Model/Ebay/Dashboard/Sales/Calculator.php
@@ -4,15 +4,13 @@
use Ess\M2ePro\Model\Dashboard\Date\DateRange;
use Ess\M2ePro\Model\Dashboard\Sales\PointSet;
+use Ess\M2ePro\Model\ResourceModel\Ebay\Order as EbayOrderResource;
class Calculator implements \Ess\M2ePro\Model\Dashboard\Sales\CalculatorInterface
{
- /** @var \Ess\M2ePro\Model\Dashboard\Date\DateRangeFactory */
- private $dateRangeFactory;
- /** @var \Ess\M2ePro\Model\ResourceModel\Ebay\Order\CollectionFactory */
- private $resourceCollectionFactory;
- /** @var \Ess\M2ePro\Model\Dashboard\Sales\PointFactory */
- private $pointFactory;
+ private \Ess\M2ePro\Model\Dashboard\Date\DateRangeFactory $dateRangeFactory;
+ private \Ess\M2ePro\Model\ResourceModel\Ebay\Order\CollectionFactory $resourceCollectionFactory;
+ private \Ess\M2ePro\Model\Dashboard\Sales\PointFactory $pointFactory;
public function __construct(
\Ess\M2ePro\Model\Dashboard\Date\DateRangeFactory $dateRangeFactory,
@@ -83,7 +81,8 @@ private function getPointSet(string $valueColumn, DateRange $dateRange, bool $is
$select->columns(
[
sprintf(
- 'DATE_FORMAT(purchase_update_date, "%s") AS date',
+ 'DATE_FORMAT(%s, "%s") AS date',
+ EbayOrderResource::COLUMN_PURCHASE_CREATE_DATE,
$isHourlyInterval ? '%Y-%m-%d %H' : '%Y-%m-%d'
),
sprintf('%s AS value', $valueColumn),
@@ -99,15 +98,16 @@ private function getPointSet(string $valueColumn, DateRange $dateRange, bool $is
$select->where('cancellation_status = 0');
$select->where(
sprintf(
- "purchase_update_date BETWEEN '%s' AND '%s'",
+ "%s BETWEEN '%s' AND '%s'",
+ EbayOrderResource::COLUMN_PURCHASE_CREATE_DATE,
$dateRange->getDateStart()->format('Y-m-d H:i:s'),
$dateRange->getDateEnd()->format('Y-m-d H:i:s')
)
);
if ($isHourlyInterval) {
- $select->group('HOUR(main_table.purchase_update_date)');
+ $select->group(sprintf('HOUR(main_table.%s)', EbayOrderResource::COLUMN_PURCHASE_CREATE_DATE));
}
- $select->group('DAY(main_table.purchase_update_date)');
+ $select->group(sprintf('DAY(main_table.%s)', EbayOrderResource::COLUMN_PURCHASE_CREATE_DATE));
$select->order('date');
$queryData = $select->query()->fetchAll();
diff --git a/Model/Ebay/Listing/Product/Variation/Resolver.php b/Model/Ebay/Listing/Product/Variation/Resolver.php
index 21e8dddda..173aa33c4 100644
--- a/Model/Ebay/Listing/Product/Variation/Resolver.php
+++ b/Model/Ebay/Listing/Product/Variation/Resolver.php
@@ -70,6 +70,8 @@ public function resolve()
$this->getMessagesSet()->clearEntities();
$this->validate();
+ $this->clearVariationsThatCanNotBeDeleted();
+
$this->prepareModuleVariations();
$this->validateModuleVariations();
@@ -112,6 +114,13 @@ private function validate()
return true;
}
+ private function clearVariationsThatCanNotBeDeleted()
+ {
+ $this->listingProduct
+ ->setSetting('additional_data', 'variations_that_can_not_be_deleted', [])
+ ->save();
+ }
+
private function validateModuleVariations()
{
$skus = [];
@@ -750,7 +759,7 @@ private function getVariationHash($variation)
{
$hash = [];
- foreach ($variation['specifics'] as $name => $value) {
+ foreach ($variation['specifics'] ?? [] as $name => $value) {
$hash[] = trim($name) . '-' . trim($value);
}
diff --git a/Model/Exception/EntityNotFound.php b/Model/Exception/EntityNotFound.php
new file mode 100644
index 000000000..cc9d17b6c
--- /dev/null
+++ b/Model/Exception/EntityNotFound.php
@@ -0,0 +1,9 @@
+messageManager = $messageManager;
}
- /**
- * @inheritDoc
- * @throws Logic
- */
public function addMessage(DataObject $message): void
{
switch ($message->getType()) {
diff --git a/Model/M2ePro/Connector/Protocol.php b/Model/M2ePro/Connector/Protocol.php
index 7ab6b0891..2f6184d4a 100644
--- a/Model/M2ePro/Connector/Protocol.php
+++ b/Model/M2ePro/Connector/Protocol.php
@@ -1,28 +1,16 @@
customerFactory = $customerFactory;
$this->customerAddressFactory = $customerAddressFactory;
$this->addressFactory = $addressFactory;
- parent::__construct($helperFactory, $modelFactory);
+ $this->dataHelper = $dataHelper;
}
- //########################################
-
/**
* Set magento order for updating
- *
- * @param \Magento\Sales\Model\Order $order
- *
- * @return $this
*/
- public function setMagentoOrder(\Magento\Sales\Model\Order $order)
+ public function setMagentoOrder(\Magento\Sales\Model\Order $order): self
{
$this->magentoOrder = $order;
return $this;
}
- //########################################
-
- /**
- * @return \Magento\Customer\Model\Customer
- */
- private function getMagentoCustomer()
+ private function getMagentoCustomer(): ?\Magento\Customer\Model\Customer
{
if ($this->magentoOrder->getCustomerIsGuest()) {
return null;
@@ -79,14 +53,7 @@ private function getMagentoCustomer()
return $customer->getId() ? $customer : null;
}
- //########################################
-
- /**
- * Update shipping address
- *
- * @param array $addressInfo
- */
- public function updateShippingAddress(array $addressInfo)
+ public function updateShippingAddress(array $addressInfo): void
{
if ($this->magentoOrder->isCanceled()) {
return;
@@ -95,7 +62,6 @@ public function updateShippingAddress(array $addressInfo)
$shippingAddress = $this->magentoOrder->getShippingAddress();
if ($shippingAddress instanceof \Magento\Sales\Model\Order\Address) {
$shippingAddress->addData($addressInfo);
- $shippingAddress->save();
} else {
/** @var \Magento\Sales\Model\Order\Address $shippingAddress */
$shippingAddress = $this->addressFactory->create();
@@ -104,8 +70,8 @@ public function updateShippingAddress(array $addressInfo)
// we need to set shipping address to order before address save to init parent_id field
$this->magentoOrder->setShippingAddress($shippingAddress);
- $shippingAddress->save();
}
+ $shippingAddress->save();
// we need to save order to update data in table sales_flat_order_grid
// setData method will force magento model to save entity
@@ -113,22 +79,39 @@ public function updateShippingAddress(array $addressInfo)
$this->needSave = true;
}
- public function updateShippingDescription($shippingDescription)
+ public function updateBillingAddress(array $addressInfo): void
{
- $this->magentoOrder->setData('shipping_description', $shippingDescription);
+ if ($this->magentoOrder->isCanceled()) {
+ return;
+ }
+
+ $billingAddress = $this->magentoOrder->getBillingAddress();
+ if ($billingAddress instanceof \Magento\Sales\Model\Order\Address) {
+ $billingAddress->addData($addressInfo);
+ } else {
+ /** @var \Magento\Sales\Model\Order\Address $billingAddress */
+ $billingAddress = $this->addressFactory->create();
+ $billingAddress->setCustomerId($this->magentoOrder->getCustomerId());
+ $billingAddress->addData($addressInfo);
+
+ $this->magentoOrder->setBillingAddress($billingAddress);
+ }
+ $billingAddress->save();
+
+ $this->magentoOrder->setForceUpdateGridRecords(false);
$this->needSave = true;
}
- //########################################
+ public function updateShippingDescription($shippingDescription): void
+ {
+ $this->magentoOrder->setData('shipping_description', $shippingDescription);
+ $this->needSave = true;
+ }
/**
* Update customer email
- *
- * @param $email
- *
- * @return null
*/
- public function updateCustomerEmail($email)
+ public function updateCustomerEmail($email): void
{
if ($this->magentoOrder->isCanceled()) {
return;
@@ -160,10 +143,8 @@ public function updateCustomerEmail($email)
/**
* Update customer address
- *
- * @param array $customerAddress
*/
- public function updateCustomerAddress(array $customerAddress)
+ public function updateCustomerAddress(array $customerAddress): void
{
if ($this->magentoOrder->isCanceled()) {
return;
@@ -189,14 +170,10 @@ public function updateCustomerAddress(array $customerAddress)
$customerAddress->save();
}
- //########################################
-
/**
* Update payment data (payment method, transactions, etc)
- *
- * @param array $newPaymentData
*/
- public function updatePaymentData(array $newPaymentData)
+ public function updatePaymentData(array $newPaymentData): void
{
if ($this->magentoOrder->isCanceled()) {
return;
@@ -205,21 +182,15 @@ public function updatePaymentData(array $newPaymentData)
$payment = $this->magentoOrder->getPayment();
if ($payment instanceof \Magento\Sales\Model\Order\Payment) {
$payment->setAdditionalData(
- $this->getHelper('Data')->serialize($newPaymentData)
+ $this->dataHelper->serialize($newPaymentData)
)->save();
}
}
- //########################################
-
/**
* Add notes
- *
- * @param mixed $comments
- *
- * @return null
*/
- public function updateComments($comments)
+ public function updateComments($comments): void
{
if ($this->magentoOrder->isCanceled()) {
return;
@@ -231,23 +202,17 @@ public function updateComments($comments)
!is_array($comments) && $comments = [$comments];
- $header = '' . $this->getHelper('Module\Translation')->__('M2E Pro Notes') . ': ';
+ $header = '' . __('M2E Pro Notes') . ': ';
$comments = implode(' ', $comments);
$this->magentoOrder->addCommentToStatusHistory($header . $comments);
$this->needSave = true;
}
- //########################################
-
/**
* Update status
- *
- * @param $status
- *
- * @return null
*/
- public function updateStatus($status)
+ public function updateStatus($status): void
{
if ($this->magentoOrder->isCanceled()) {
return;
@@ -269,9 +234,7 @@ public function updateStatus($status)
$this->needSave = true;
}
- //########################################
-
- public function cancel()
+ public function cancel(): void
{
$this->magentoOrder->setActionFlag(\Magento\Sales\Model\Order::ACTION_FLAG_CANCEL, true);
$this->magentoOrder->setActionFlag(\Magento\Sales\Model\Order::ACTION_FLAG_UNHOLD, true);
@@ -279,17 +242,13 @@ public function cancel()
$this->magentoOrder->cancel()->save();
}
- //########################################
-
/**
* Save magento order only once and only if it's needed
*/
- public function finishUpdate()
+ public function finishUpdate(): void
{
if ($this->needSave) {
$this->magentoOrder->save();
}
}
-
- //########################################
}
diff --git a/Model/Marketplace.php b/Model/Marketplace.php
index 4fb5192e5..1f6d22ac9 100644
--- a/Model/Marketplace.php
+++ b/Model/Marketplace.php
@@ -73,9 +73,9 @@ public function disable(): Marketplace
// ----------------------------------------
- public function getTitle()
+ public function getTitle(): string
{
- return $this->getData('title');
+ return (string)$this->getData('title');
}
public function getCode()
diff --git a/Model/MarketplaceFactory.php b/Model/MarketplaceFactory.php
index 05a3c5041..5c279780c 100644
--- a/Model/MarketplaceFactory.php
+++ b/Model/MarketplaceFactory.php
@@ -1,19 +1,20 @@
objectManager = $objectManager;
}
- public function create(array $data = []): Marketplace
+ public function create(): Marketplace
{
- return $this->objectManager->create(Marketplace::class, $data);
+ return $this->objectManager->create(Marketplace::class);
}
}
diff --git a/Model/ResourceModel/Account/CollectionFactory.php b/Model/ResourceModel/Account/CollectionFactory.php
index a462fa1fd..454329c02 100644
--- a/Model/ResourceModel/Account/CollectionFactory.php
+++ b/Model/ResourceModel/Account/CollectionFactory.php
@@ -1,11 +1,12 @@
_init('m2epro_amazon_dictionary_marketplace', 'id');
+ $this->_init(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_DICTIONARY_MARKETPLACE, self::COLUMN_ID);
}
-
- //########################################
}
diff --git a/Model/ResourceModel/Amazon/Dictionary/Marketplace/Collection.php b/Model/ResourceModel/Amazon/Dictionary/Marketplace/Collection.php
index 0e787c41d..3ff4419cb 100644
--- a/Model/ResourceModel/Amazon/Dictionary/Marketplace/Collection.php
+++ b/Model/ResourceModel/Amazon/Dictionary/Marketplace/Collection.php
@@ -1,16 +1,16 @@
_init(
@@ -18,16 +18,4 @@ public function _construct()
\Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\Marketplace::class
);
}
-
- /**
- * @param int $marketplaceId
- *
- * @return $this
- */
- public function appendFilterMarketplaceId(int $marketplaceId): self
- {
- $this->getSelect()->where('marketplace_id = ?', $marketplaceId);
-
- return $this;
- }
}
diff --git a/Model/ResourceModel/Amazon/Dictionary/Marketplace/CollectionFactory.php b/Model/ResourceModel/Amazon/Dictionary/Marketplace/CollectionFactory.php
index 10aec3207..ac91a2d9a 100644
--- a/Model/ResourceModel/Amazon/Dictionary/Marketplace/CollectionFactory.php
+++ b/Model/ResourceModel/Amazon/Dictionary/Marketplace/CollectionFactory.php
@@ -1,11 +1,12 @@
_init('m2epro_amazon_dictionary_product_type', 'id');
+ $this->_init(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_DICTIONARY_PRODUCT_TYPE, self::COLUMN_ID);
}
}
diff --git a/Model/ResourceModel/Amazon/Dictionary/ProductType/Collection.php b/Model/ResourceModel/Amazon/Dictionary/ProductType/Collection.php
index c901c4689..2fc204a7c 100644
--- a/Model/ResourceModel/Amazon/Dictionary/ProductType/Collection.php
+++ b/Model/ResourceModel/Amazon/Dictionary/ProductType/Collection.php
@@ -1,19 +1,16 @@
_init(
@@ -21,50 +18,4 @@ public function _construct()
\Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::class
);
}
-
- /**
- * @param string $nick
- *
- * @return $this
- */
- public function appendFilterNick(string $nick): self
- {
- $this->getSelect()->where('main_table.nick = ?', $nick);
-
- return $this;
- }
-
- /**
- * @param int $marketplaceId
- *
- * @return $this
- */
- public function appendFilterMarketplaceId(int $marketplaceId): self
- {
- $this->getSelect()->where('main_table.marketplace_id = ?', $marketplaceId);
-
- return $this;
- }
-
- public function appendFilterInvalid(bool $invalid): self
- {
- $this->getSelect()->where('main_table.invalid = ?', (int)$invalid);
-
- return $this;
- }
-
- /**
- * @param array $nicks
- *
- * @return $this
- */
- public function appendFilterNicks(array $nicks): self
- {
- if (empty($nicks)) {
- return $this;
- }
-
- $this->addFieldToFilter('nick', ['in' => $nicks]);
- return $this;
- }
}
diff --git a/Model/ResourceModel/Amazon/Dictionary/ProductType/CollectionFactory.php b/Model/ResourceModel/Amazon/Dictionary/ProductType/CollectionFactory.php
index 50a4ff88c..22d3c14a5 100644
--- a/Model/ResourceModel/Amazon/Dictionary/ProductType/CollectionFactory.php
+++ b/Model/ResourceModel/Amazon/Dictionary/ProductType/CollectionFactory.php
@@ -1,11 +1,12 @@
amazonFactory = $amazonFactory;
}
- public function _construct()
+ public function _construct(): void
{
$this->_init(
\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_LISTING_PRODUCT,
diff --git a/Model/ResourceModel/Amazon/Marketplace.php b/Model/ResourceModel/Amazon/Marketplace.php
index ea168c329..473e7951e 100644
--- a/Model/ResourceModel/Amazon/Marketplace.php
+++ b/Model/ResourceModel/Amazon/Marketplace.php
@@ -6,7 +6,6 @@ class Marketplace extends \Ess\M2ePro\Model\ResourceModel\ActiveRecord\Component
{
public const COLUMN_MARKETPLACE_ID = 'marketplace_id';
public const COLUMN_DEFAULT_CURRENCY = 'default_currency';
- public const COLUMN_IS_NEW_ASIN_AVAILABLE = 'is_new_asin_available';
public const COLUMN_IS_MERCHANT_FULFILLMENT_AVAILABLE = 'is_merchant_fulfillment_available';
public const COLUMN_IS_BUSINESS_AVAILABLE = 'is_business_available';
public const COLUMN_IS_VAT_CALCULATION_SERVICE_AVAILABLE = 'is_vat_calculation_service_available';
diff --git a/Model/ResourceModel/Amazon/Template/ProductType.php b/Model/ResourceModel/Amazon/Template/ProductType.php
index 6bfb800f2..7b965763f 100644
--- a/Model/ResourceModel/Amazon/Template/ProductType.php
+++ b/Model/ResourceModel/Amazon/Template/ProductType.php
@@ -1,15 +1,19 @@
productTypeFactory = $productTypeFactory;
}
- /**
- * @return void
- */
- protected function _construct()
+ protected function _construct(): void
{
- $this->_init('m2epro_amazon_template_product_type', 'id');
- }
-
- /**
- * @param int $productTypeId
- *
- * @return \Ess\M2ePro\Model\Amazon\Template\ProductType
- */
- public function loadById(int $productTypeId): \Ess\M2ePro\Model\Amazon\Template\ProductType
- {
- $productType = $this->productTypeFactory->create();
- $this->load($productType, $productTypeId);
-
- return $productType;
+ $this->_init(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_TEMPLATE_PRODUCT_TYPE, self::COLUMN_ID);
}
}
diff --git a/Model/ResourceModel/Amazon/Template/ProductType/Collection.php b/Model/ResourceModel/Amazon/Template/ProductType/Collection.php
index 192495348..5e3cc228c 100644
--- a/Model/ResourceModel/Amazon/Template/ProductType/Collection.php
+++ b/Model/ResourceModel/Amazon/Template/ProductType/Collection.php
@@ -1,66 +1,16 @@
dictionaryResource = $dictionaryResource;
- $this->marketplaceResource = $marketplaceResource;
- }
-
- /**
- * @return void
- */
- public function _construct()
+ public function _construct(): void
{
parent::_construct();
$this->_init(
@@ -68,68 +18,4 @@ public function _construct()
\Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType::class
);
}
-
- /**
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function appendTableDictionary(): self
- {
- if ($this->isDictionaryTableAppended) {
- return $this;
- }
-
- $this->getSelect()->join(
- ['adpt' => $this->dictionaryResource->getMainTable()],
- 'adpt.id=main_table.dictionary_product_type_id',
- ['product_type_title' => 'adpt.title']
- );
-
- $this->isDictionaryTableAppended = true;
- return $this;
- }
-
- /**
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function appendTableMarketplace(): self
- {
- if ($this->isMarketplaceTableAppended) {
- return $this;
- }
-
- $this->getSelect()->join(
- ['m' => $this->marketplaceResource->getMainTable()],
- 'm.id=adpt.marketplace_id AND m.status = 1',
- ['marketplace_title' => 'm.title']
- );
-
- $this->isMarketplaceTableAppended = true;
- return $this;
- }
-
- /**
- * @param int $marketplaceId
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function appendFilterMarketplaceId(int $marketplaceId): self
- {
- $this->appendTableDictionary();
- $this->getSelect()->where('adpt.marketplace_id = ?', $marketplaceId);
- return $this;
- }
-
- /**
- * @param string $nick
- * @return $this
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function appendFilterNick(string $nick): self
- {
- $this->appendTableDictionary();
- $this->getSelect()->where('adpt.nick = ?', $nick);
- return $this;
- }
}
diff --git a/Model/ResourceModel/Amazon/Template/ProductType/CollectionFactory.php b/Model/ResourceModel/Amazon/Template/ProductType/CollectionFactory.php
index fb5095954..b5d377b1c 100644
--- a/Model/ResourceModel/Amazon/Template/ProductType/CollectionFactory.php
+++ b/Model/ResourceModel/Amazon/Template/ProductType/CollectionFactory.php
@@ -1,19 +1,20 @@
objectManager = $objectManager;
}
- public function create(array $data = []): Collection
+ public function create(): Collection
{
- return $this->objectManager->create(Collection::class, $data);
+ return $this->objectManager->create(Collection::class);
}
}
diff --git a/Model/ResourceModel/Amazon/Template/ProductType/Grid/Collection.php b/Model/ResourceModel/Amazon/Template/ProductType/Grid/Collection.php
new file mode 100644
index 000000000..1b5272ce9
--- /dev/null
+++ b/Model/ResourceModel/Amazon/Template/ProductType/Grid/Collection.php
@@ -0,0 +1,134 @@
+dictionaryProductTypeResource = $dictionaryProductTypeResource;
+ $this->marketplaceResource = $marketplaceResource;
+ $this->prepareCollection();
+ }
+
+ protected function _construct(): void
+ {
+ parent::_construct();
+ $this->_init(
+ \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
+ TemplateProductTypeResource::class,
+ );
+ }
+
+ private function prepareCollection(): void
+ {
+ $this->getSelect()->join(
+ ['adpt' => $this->dictionaryProductTypeResource->getMainTable()],
+ sprintf(
+ 'adpt.%s = main_table.%s',
+ DictionaryProductTypeResource::COLUMN_ID,
+ TemplateProductTypeResource::COLUMN_DICTIONARY_PRODUCT_TYPE_ID
+ ),
+ []
+ );
+
+ $this->getSelect()->reset(\Magento\Framework\DB\Select::COLUMNS);
+ $this->getSelect()->columns([
+ 'id' => sprintf('main_table.%s', TemplateProductTypeResource::COLUMN_ID),
+ 'template_title' => sprintf('main_table.%s', TemplateProductTypeResource::COLUMN_TITLE),
+ 'marketplace_id' => sprintf('adpt.%s', DictionaryProductTypeResource::COLUMN_MARKETPLACE_ID),
+ 'update_date' => sprintf('main_table.%s', TemplateProductTypeResource::COLUMN_UPDATE_DATE),
+ 'create_date' => sprintf('main_table.%s', TemplateProductTypeResource::COLUMN_CREATE_DATE),
+ 'invalid' => sprintf('adpt.%s', DictionaryProductTypeResource::COLUMN_INVALID),
+ 'out_of_date' => new \Magento\Framework\DB\Sql\Expression(
+ sprintf(
+ 'adpt.%s > adpt.%s',
+ DictionaryProductTypeResource::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE,
+ DictionaryProductTypeResource::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE
+ )
+ ),
+ ]);
+ }
+
+ public function setOrder($field, $direction = self::SORT_ORDER_DESC)
+ {
+ if ($field === 'marketplace') {
+ $this->joinMarketplaceTable();
+
+ $field = 'marketplace.' . \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_TITLE;
+ }
+
+ return parent::setOrder($field, $direction);
+ }
+
+ public function addFieldToFilter($field, $condition = null)
+ {
+ if ($field === 'template_title') {
+ $field = 'main_table.' . DictionaryProductTypeResource::COLUMN_TITLE;
+ }
+
+ parent::addFieldToFilter($field, $condition);
+
+ return $this;
+ }
+
+ public function getTotalCount()
+ {
+ return $this->getSize();
+ }
+
+ private function joinMarketplaceTable(): void
+ {
+ if ($this->isMarketplaceTableJoined) {
+ return;
+ }
+
+ $this->getSelect()->join(
+ ['marketplace' => $this->marketplaceResource->getMainTable()],
+ sprintf(
+ 'adpt.%s = marketplace.%s AND marketplace.%s = "%s"',
+ DictionaryProductTypeResource::COLUMN_MARKETPLACE_ID,
+ \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_ID,
+ \Ess\M2ePro\Model\ResourceModel\Marketplace::COLUMN_COMPONENT_MODE,
+ \Ess\M2ePro\Helper\Component\Amazon::NICK
+ ),
+ []
+ );
+
+ $this->isMarketplaceTableJoined = true;
+ }
+}
diff --git a/Model/ResourceModel/Marketplace.php b/Model/ResourceModel/Marketplace.php
index 6c2f05f7d..a66202e60 100644
--- a/Model/ResourceModel/Marketplace.php
+++ b/Model/ResourceModel/Marketplace.php
@@ -1,5 +1,7 @@
amazonDictionaryMarketplaceRepository = $amazonDictionaryMarketplaceRepository;
+ }
- public function _construct()
+ public function _construct(): void
{
$this->_init(
\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_MARKETPLACE,
@@ -22,21 +37,16 @@ public function _construct()
);
}
- /**
- * @param \Ess\M2ePro\Model\Marketplace $marketplace
- */
- public function isDictionaryExist($marketplace)
+ public function isDictionaryExist(\Ess\M2ePro\Model\Marketplace $marketplace): bool
{
$connection = $this->getConnection();
- $tableName = null;
switch ($marketplace->getComponentMode()) {
case \Ess\M2ePro\Helper\Component\Ebay::NICK:
$tableName = 'm2epro_ebay_dictionary_marketplace';
break;
case \Ess\M2ePro\Helper\Component\Amazon::NICK:
- $tableName = 'm2epro_amazon_dictionary_marketplace';
- break;
+ return $this->amazonDictionaryMarketplaceRepository->findByMarketplace($marketplace) !== null;
case \Ess\M2ePro\Helper\Component\Walmart::NICK:
$tableName = 'm2epro_walmart_dictionary_marketplace';
break;
diff --git a/Model/ResourceModel/Marketplace/Collection.php b/Model/ResourceModel/Marketplace/Collection.php
index ba7e3c7d0..a3abd7894 100644
--- a/Model/ResourceModel/Marketplace/Collection.php
+++ b/Model/ResourceModel/Marketplace/Collection.php
@@ -1,19 +1,14 @@
_init(
@@ -22,11 +17,6 @@ public function _construct()
);
}
- /**
- * @param string $component
- *
- * @return $this
- */
public function appendFilterEnabledMarketplaces(string $component): self
{
$this->addFieldToFilter('component_mode', $component);
diff --git a/Model/ResourceModel/Marketplace/CollectionFactory.php b/Model/ResourceModel/Marketplace/CollectionFactory.php
index f56d17d2d..d0e456662 100644
--- a/Model/ResourceModel/Marketplace/CollectionFactory.php
+++ b/Model/ResourceModel/Marketplace/CollectionFactory.php
@@ -1,34 +1,21 @@
objectManager = $objectManager;
}
- /**
- * @param array $data
- *
- * @return \Ess\M2ePro\Model\ResourceModel\Marketplace\Collection
- */
- public function create(array $data = []): Collection
+ public function create(): Collection
{
- return $this->objectManager->create(Collection::class, $data);
+ return $this->objectManager->create(Collection::class);
}
public function createWithEbayChildMode(): Collection
diff --git a/Model/ResourceModel/Ui/Grid/SearchResultTrait.php b/Model/ResourceModel/Ui/Grid/SearchResultTrait.php
new file mode 100644
index 000000000..abba63647
--- /dev/null
+++ b/Model/ResourceModel/Ui/Grid/SearchResultTrait.php
@@ -0,0 +1,41 @@
+aggregations;
+ }
+
+ public function setAggregations($aggregations)
+ {
+ $this->aggregations = $aggregations;
+ }
+
+ public function getSearchCriteria()
+ {
+ return null;
+ }
+
+ public function setSearchCriteria(SearchCriteriaInterface $searchCriteria)
+ {
+ return $this;
+ }
+
+ public function setTotalCount($totalCount): self
+ {
+ return $this;
+ }
+}
diff --git a/Model/Servicing/Task/Marketplaces.php b/Model/Servicing/Task/Marketplaces.php
index 81b051423..49f5d9603 100644
--- a/Model/Servicing/Task/Marketplaces.php
+++ b/Model/Servicing/Task/Marketplaces.php
@@ -1,19 +1,13 @@
parentFactory = $parentFactory;
$this->resource = $resource;
$this->cachePermanent = $cachePermanent;
$this->databaseStructure = $databaseStructure;
- $this->componentAmazon = $componentAmazon;
+ $this->amazonDictionaryPTRepository = $amazonDictionaryProductTypeRepository;
+ $this->amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ $this->issueOutOfDateCache = $issueOutOfDateCache;
}
// ----------------------------------------
- /**
- * @return string
- */
public function getServerTaskName(): string
{
return self::NAME;
}
- // ----------------------------------------
+ public function isAllowed(): bool
+ {
+ return true;
+ }
- /**
- * @return array
- */
public function getRequestData(): array
{
- return [];
+ return [
+ 'amazon' => $this->buildAmazonMarketplaceData(),
+ ];
}
- // ----------------------------------------
-
- /**
- * @return bool
- */
- public function isAllowed(): bool
+ private function buildAmazonMarketplaceData(): array
{
- return true;
+ $result = [];
+ $marketplacePtMap = $this->amazonDictionaryPTRepository->getValidNickMapByMarketplaceNativeId();
+ foreach ($marketplacePtMap as $nativeMarketplaceId => $productTypesNicks) {
+ $result[] = [
+ 'marketplace' => $nativeMarketplaceId,
+ 'product_types' => $productTypesNicks
+ ];
+ }
+
+ return $result;
}
// ----------------------------------------
- /**
- * @param array $data
- *
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
public function processResponseData(array $data): void
{
if (isset($data['ebay_last_update_dates']) && is_array($data['ebay_last_update_dates'])) {
$this->processEbayLastUpdateDates($data['ebay_last_update_dates']);
}
- if (isset($data['amazon_last_update_dates']) && is_array($data['amazon_last_update_dates'])) {
- $this->processAmazonLastUpdateDates($data['amazon_last_update_dates']);
+ if (isset($data['amazon']) && is_array($data['amazon'])) {
+ $this->processAmazonLastUpdateDates($data['amazon']);
}
if (isset($data['walmart_last_update_dates']) && is_array($data['walmart_last_update_dates'])) {
@@ -103,12 +92,6 @@ public function processResponseData(array $data): void
}
}
- /**
- * @param array $lastUpdateDates
- *
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
private function processEbayLastUpdateDates(array $lastUpdateDates): void
{
/** @var \Ess\M2ePro\Model\ResourceModel\Marketplace\Collection $accountCollection */
@@ -155,61 +138,36 @@ private function processEbayLastUpdateDates(array $lastUpdateDates): void
}
}
- /**
- * @param array $lastUpdateDates
- *
- * @return void
- */
- private function processAmazonLastUpdateDates(array $lastUpdateDates): void
+ private function processAmazonLastUpdateDates(array $lastUpdateDatesByProductTypes): void
{
- $enabledMarketplaces = $this->componentAmazon
- ->getMarketplacesAvailableForApiCreation();
-
- $connection = $this->resource->getConnection();
- $dictionaryTable = $this->databaseStructure
- ->getTableNameWithPrefix('m2epro_amazon_dictionary_marketplace');
+ foreach ($lastUpdateDatesByProductTypes as $row) {
+ $nativeMarketplaceId = (int)$row['marketplace'];
+ $productTypesLastUpdateByNick = [];
+ foreach ($row['product_types'] as ['name' => $productTypeNick, 'last_update' => $lastUpdateDate]) {
+ $productTypesLastUpdateByNick[$productTypeNick] = \Ess\M2ePro\Helper\Date::createDateGmt(
+ $lastUpdateDate
+ );
+ }
- /** @var \Ess\M2ePro\Model\Marketplace $marketplace */
- foreach ($enabledMarketplaces as $marketplace) {
- if (!isset($lastUpdateDates[$marketplace->getNativeId()])) {
+ $marketplace = $this->amazonMarketplaceRepository->findByNativeId($nativeMarketplaceId);
+ if ($marketplace === null) {
continue;
}
- $serverLastUpdateDate = $lastUpdateDates[$marketplace->getNativeId()];
+ foreach ($this->amazonDictionaryPTRepository->findByMarketplace($marketplace) as $productType) {
+ if (!isset($productTypesLastUpdateByNick[$productType->getNick()])) {
+ continue;
+ }
- $select = $connection->select()
- ->from($dictionaryTable, [
- 'client_details_last_update_date',
- ])
- ->where('marketplace_id = ?', $marketplace->getId());
-
- $clientLastUpdateDate = $connection->fetchOne($select);
+ $productType->setServerDetailsLastUpdateDate($productTypesLastUpdateByNick[$productType->getNick()]);
- if ($clientLastUpdateDate === null) {
- $clientLastUpdateDate = $serverLastUpdateDate;
- }
-
- if ($clientLastUpdateDate < $serverLastUpdateDate) {
- $this->needToCleanCache = true;
+ $this->amazonDictionaryPTRepository->save($productType);
}
-
- $connection->update(
- $dictionaryTable,
- [
- 'server_details_last_update_date' => $serverLastUpdateDate,
- 'client_details_last_update_date' => $clientLastUpdateDate,
- ],
- ['marketplace_id = ?' => $marketplace->getId()]
- );
}
+
+ $this->issueOutOfDateCache->clear();
}
- /**
- * @param array $lastUpdateDates
- *
- * @return void
- * @throws \Ess\M2ePro\Model\Exception\Logic
- */
private function processWalmartLastUpdateDates(array $lastUpdateDates): void
{
/** @var \Ess\M2ePro\Model\ResourceModel\Marketplace\Collection $accountCollection */
diff --git a/Model/Setup/Installer.php b/Model/Setup/Installer.php
index d16fbfe30..e5c9b471d 100644
--- a/Model/Setup/Installer.php
+++ b/Model/Setup/Installer.php
@@ -2,6 +2,8 @@
namespace Ess\M2ePro\Model\Setup;
+use Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\Marketplace as AmazonDictionaryMarketplaceResoruce;
+use Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType as AmazonDictionaryProductTypeResource;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Config\ConfigOptionsListConstants;
@@ -8479,11 +8481,12 @@ private function installAmazonSchema()
->setOption('row_format', 'dynamic');
$this->getConnection()->createTable($amazonDictionaryCategoryProductDataTable);
+ # region amazon_dictionary_marketplace
$amazonDictionaryMarketplaceTable = $this->getConnection()->newTable(
- $this->getFullTableName('amazon_dictionary_marketplace')
+ $this->getFullTableName(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_DICTIONARY_MARKETPLACE)
)
->addColumn(
- 'id',
+ AmazonDictionaryMarketplaceResoruce::COLUMN_ID,
Table::TYPE_INTEGER,
null,
[
@@ -8494,41 +8497,34 @@ private function installAmazonSchema()
]
)
->addColumn(
- 'marketplace_id',
+ AmazonDictionaryMarketplaceResoruce::COLUMN_MARKETPLACE_ID,
Table::TYPE_INTEGER,
null,
['unsigned' => true, 'nullable' => false]
)
->addColumn(
- 'client_details_last_update_date',
- Table::TYPE_DATETIME,
- null,
- ['default' => null]
- )
- ->addColumn(
- 'server_details_last_update_date',
- Table::TYPE_DATETIME,
- null,
- ['default' => null]
- )
- ->addColumn(
- 'product_types',
+ AmazonDictionaryMarketplaceResoruce::COLUMN_PRODUCT_TYPES,
Table::TYPE_TEXT,
self::LONG_COLUMN_SIZE,
['default' => null]
)
- ->addIndex('marketplace_id', 'marketplace_id')
+ ->addIndex(
+ 'marketplace_id',
+ AmazonDictionaryMarketplaceResoruce::COLUMN_MARKETPLACE_ID
+ )
->setOption('type', 'INNODB')
->setOption('charset', 'utf8')
->setOption('collate', 'utf8_general_ci')
->setOption('row_format', 'dynamic');
$this->getConnection()->createTable($amazonDictionaryMarketplaceTable);
+ # endregion
+ #region amazon_dictionary_product_type
$amazonDictionaryProductTypeTable = $this->getConnection()->newTable(
- $this->getFullTableName('amazon_dictionary_product_type')
+ $this->getFullTableName(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_DICTIONARY_PRODUCT_TYPE)
)
->addColumn(
- 'id',
+ AmazonDictionaryProductTypeResource::COLUMN_ID,
Table::TYPE_INTEGER,
null,
[
@@ -8539,31 +8535,55 @@ private function installAmazonSchema()
]
)
->addColumn(
- 'marketplace_id',
+ AmazonDictionaryProductTypeResource::COLUMN_MARKETPLACE_ID,
Table::TYPE_INTEGER,
null,
['unsigned' => true, 'nullable' => false]
)
->addColumn(
- 'nick',
+ AmazonDictionaryProductTypeResource::COLUMN_NICK,
Table::TYPE_TEXT,
255,
['nullable' => false]
)
->addColumn(
- 'title',
+ AmazonDictionaryProductTypeResource::COLUMN_TITLE,
Table::TYPE_TEXT,
255,
['nullable' => false]
)
->addColumn(
- 'scheme',
+ AmazonDictionaryProductTypeResource::COLUMN_SCHEMA,
Table::TYPE_TEXT,
self::LONG_COLUMN_SIZE,
['nullable' => false]
)
->addColumn(
- 'invalid',
+ AmazonDictionaryProductTypeResource::COLUMN_VARIATION_THEMES,
+ Table::TYPE_TEXT,
+ self::LONG_COLUMN_SIZE,
+ ['nullable' => false],
+ )
+ ->addColumn(
+ AmazonDictionaryProductTypeResource::COLUMN_ATTRIBUTES_GROUPS,
+ Table::TYPE_TEXT,
+ self::LONG_COLUMN_SIZE,
+ ['nullable' => false],
+ )
+ ->addColumn(
+ AmazonDictionaryProductTypeResource::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE,
+ Table::TYPE_DATETIME,
+ null,
+ ['nullable' => false],
+ )
+ ->addColumn(
+ AmazonDictionaryProductTypeResource::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE,
+ Table::TYPE_DATETIME,
+ null,
+ ['nullable' => false],
+ )
+ ->addColumn(
+ AmazonDictionaryProductTypeResource::COLUMN_INVALID,
Table::TYPE_SMALLINT,
null,
['unsigned' => true, 'nullable' => false, 'default' => 0]
@@ -8578,6 +8598,7 @@ private function installAmazonSchema()
->setOption('collate', 'utf8_general_ci')
->setOption('row_format', 'dynamic');
$this->getConnection()->createTable($amazonDictionaryProductTypeTable);
+ # endregion
$amazonDictionarySpecificTable = $this->getConnection()->newTable(
$this->getFullTableName('amazon_dictionary_specific')
@@ -9577,7 +9598,9 @@ private function installAmazonSchema()
->setOption('row_format', 'dynamic');
$this->getConnection()->createTable($amazonIndexerListingProductVariationParentTable);
- $amazonMarketplaceTable = $this->getConnection()->newTable($this->getFullTableName('amazon_marketplace'))
+ $amazonMarketplaceTable = $this->getConnection()->newTable(
+ $this->getFullTableName(\Ess\M2ePro\Helper\Module\Database\Tables::TABLE_AMAZON_MARKETPLACE)
+ )
->addColumn(
'marketplace_id',
Table::TYPE_INTEGER,
@@ -9590,12 +9613,6 @@ private function installAmazonSchema()
255,
['nullable' => false]
)
- ->addColumn(
- 'is_new_asin_available',
- Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => 1]
- )
->addColumn(
'is_merchant_fulfillment_available',
Table::TYPE_SMALLINT,
@@ -9620,7 +9637,6 @@ private function installAmazonSchema()
null,
['unsigned' => true, 'nullable' => false, 'default' => 0]
)
- ->addIndex('is_new_asin_available', 'is_new_asin_available')
->addIndex(
'is_merchant_fulfillment_available',
'is_merchant_fulfillment_available'
@@ -11341,7 +11357,6 @@ private function installAmazonData()
[
'marketplace_id' => 24,
'default_currency' => 'CAD',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 0,
'is_vat_calculation_service_available' => 0,
@@ -11350,7 +11365,6 @@ private function installAmazonData()
[
'marketplace_id' => 25,
'default_currency' => 'EUR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11359,7 +11373,6 @@ private function installAmazonData()
[
'marketplace_id' => 26,
'default_currency' => 'EUR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11368,7 +11381,6 @@ private function installAmazonData()
[
'marketplace_id' => 28,
'default_currency' => 'GBP',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11377,7 +11389,6 @@ private function installAmazonData()
[
'marketplace_id' => 29,
'default_currency' => 'USD',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 0,
@@ -11386,7 +11397,6 @@ private function installAmazonData()
[
'marketplace_id' => 30,
'default_currency' => 'EUR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11395,7 +11405,6 @@ private function installAmazonData()
[
'marketplace_id' => 31,
'default_currency' => 'EUR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11404,7 +11413,6 @@ private function installAmazonData()
[
'marketplace_id' => 34,
'default_currency' => 'MXN',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 0,
'is_vat_calculation_service_available' => 0,
@@ -11413,7 +11421,6 @@ private function installAmazonData()
[
'marketplace_id' => 35,
'default_currency' => 'AUD',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 0,
'is_business_available' => 0,
'is_vat_calculation_service_available' => 0,
@@ -11422,7 +11429,6 @@ private function installAmazonData()
[
'marketplace_id' => 39,
'default_currency' => 'EUR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11431,7 +11437,6 @@ private function installAmazonData()
[
'marketplace_id' => 40,
'default_currency' => 'TRY',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 0,
'is_vat_calculation_service_available' => 0,
@@ -11440,7 +11445,6 @@ private function installAmazonData()
[
'marketplace_id' => 41,
'default_currency' => 'SEK',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 0,
'is_vat_calculation_service_available' => 1,
@@ -11449,7 +11453,6 @@ private function installAmazonData()
[
'marketplace_id' => 42,
'default_currency' => 'JPY',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 0,
'is_vat_calculation_service_available' => 0,
@@ -11458,7 +11461,6 @@ private function installAmazonData()
[
'marketplace_id' => 43,
'default_currency' => 'PLN',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 0,
'is_vat_calculation_service_available' => 1,
@@ -11467,7 +11469,6 @@ private function installAmazonData()
[
'marketplace_id' => 44,
'default_currency' => 'BRL',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 0,
@@ -11476,7 +11477,6 @@ private function installAmazonData()
[
'marketplace_id' => 45,
'default_currency' => 'SGD',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 0,
@@ -11485,7 +11485,6 @@ private function installAmazonData()
[
'marketplace_id' => 46,
'default_currency' => 'INR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 0,
@@ -11494,7 +11493,6 @@ private function installAmazonData()
[
'marketplace_id' => 47,
'default_currency' => 'AED',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 0,
@@ -11503,7 +11501,6 @@ private function installAmazonData()
[
'marketplace_id' => 48,
'default_currency' => 'EUR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11512,7 +11509,6 @@ private function installAmazonData()
[
'marketplace_id' => 49,
'default_currency' => 'ZAR',
- 'is_new_asin_available' => 1,
'is_merchant_fulfillment_available' => 1,
'is_business_available' => 1,
'is_vat_calculation_service_available' => 1,
@@ -11521,7 +11517,6 @@ private function installAmazonData()
[
AmazonMarketplaceResource::COLUMN_MARKETPLACE_ID => 50,
AmazonMarketplaceResource::COLUMN_DEFAULT_CURRENCY => 'SAR',
- AmazonMarketplaceResource::COLUMN_IS_NEW_ASIN_AVAILABLE => 1,
AmazonMarketplaceResource::COLUMN_IS_MERCHANT_FULFILLMENT_AVAILABLE => 1,
AmazonMarketplaceResource::COLUMN_IS_BUSINESS_AVAILABLE => 1,
AmazonMarketplaceResource::COLUMN_IS_VAT_CALCULATION_SERVICE_AVAILABLE => 1,
diff --git a/Model/Setup/Upgrader.php b/Model/Setup/Upgrader.php
index 37803dee6..c82dc6a12 100644
--- a/Model/Setup/Upgrader.php
+++ b/Model/Setup/Upgrader.php
@@ -209,6 +209,7 @@ class Upgrader
'1.65.2' => ['1.66.0'],
'1.66.0' => ['1.66.1'],
'1.66.1' => ['1.66.2'],
+ '1.66.2' => ['1.67.0'],
];
//########################################
diff --git a/Model/Synchronization/Log.php b/Model/Synchronization/Log.php
index cb66a58cc..3b2e22c75 100644
--- a/Model/Synchronization/Log.php
+++ b/Model/Synchronization/Log.php
@@ -1,11 +1,5 @@
_init(\Ess\M2ePro\Model\ResourceModel\Synchronization\Log::class);
}
- //########################################
-
/**
* @param int $id
*/
@@ -85,11 +75,11 @@ public function setSynchronizationTask($task = self::TASK_OTHER)
$this->task = (int)$task;
}
- //########################################
+ // ----------------------------------------
- public function addMessageFromException(\Throwable $exception)
+ public function addMessageFromException(\Throwable $exception): void
{
- return $this->addMessage(
+ $this->addMessage(
$exception->getMessage(),
\Ess\M2ePro\Model\Log\AbstractModel::TYPE_ERROR,
[],
@@ -97,12 +87,17 @@ public function addMessageFromException(\Throwable $exception)
);
}
+ public function addErrorMessage(string $text): void
+ {
+ $this->addMessage($text, \Ess\M2ePro\Model\Log\AbstractModel::TYPE_ERROR);
+ }
+
public function addMessage(
$description = null,
$type = null,
array $additionalData = [],
$detailedDescription = null
- ) {
+ ): void {
$dataForAdd = [
'description' => $description,
'detailed_description' => $detailedDescription,
@@ -135,7 +130,7 @@ public function clearMessages($task = null)
$this->getResource()->clearMessages($filters);
}
- //########################################
+ // ----------------------------------------
public function setFatalErrorHandler()
{
@@ -171,6 +166,4 @@ function () use ($object) {
}
);
}
-
- //########################################
}
diff --git a/Model/Synchronization/LogFactory.php b/Model/Synchronization/LogFactory.php
new file mode 100644
index 000000000..ee5983787
--- /dev/null
+++ b/Model/Synchronization/LogFactory.php
@@ -0,0 +1,20 @@
+objectManager = $objectManager;
+ }
+
+ public function create(): Log
+ {
+ return $this->objectManager->create(Log::class);
+ }
+}
diff --git a/Model/Walmart/Dashboard/Sales/Calculator.php b/Model/Walmart/Dashboard/Sales/Calculator.php
index bb58e477c..cfadde342 100644
--- a/Model/Walmart/Dashboard/Sales/Calculator.php
+++ b/Model/Walmart/Dashboard/Sales/Calculator.php
@@ -4,15 +4,13 @@
use Ess\M2ePro\Model\Dashboard\Date\DateRange;
use Ess\M2ePro\Model\Dashboard\Sales\PointSet;
+use Ess\M2ePro\Model\ResourceModel\Walmart\Order as WalmartOrderResource;
class Calculator implements \Ess\M2ePro\Model\Dashboard\Sales\CalculatorInterface
{
- /** @var \Ess\M2ePro\Model\Dashboard\Date\DateRangeFactory */
- private $dateRangeFactory;
- /** @var \Ess\M2ePro\Model\ResourceModel\Walmart\Order\CollectionFactory */
- private $resourceCollectionFactory;
- /** @var \Ess\M2ePro\Model\Dashboard\Sales\PointFactory */
- private $pointFactory;
+ private \Ess\M2ePro\Model\Dashboard\Date\DateRangeFactory $dateRangeFactory;
+ private WalmartOrderResource\CollectionFactory $resourceCollectionFactory;
+ private \Ess\M2ePro\Model\Dashboard\Sales\PointFactory $pointFactory;
public function __construct(
\Ess\M2ePro\Model\Dashboard\Date\DateRangeFactory $dateRangeFactory,
@@ -83,7 +81,8 @@ private function getPointSet(string $valueColumn, DateRange $dateRange, bool $is
$select->columns(
[
sprintf(
- 'DATE_FORMAT(purchase_update_date, "%s") AS date',
+ 'DATE_FORMAT(%s, "%s") AS date',
+ WalmartOrderResource::COLUMN_PURCHASE_CREATE_DATE,
$isHourlyInterval ? '%Y-%m-%d %H' : '%Y-%m-%d'
),
sprintf('%s AS value', $valueColumn),
@@ -99,15 +98,16 @@ private function getPointSet(string $valueColumn, DateRange $dateRange, bool $is
);
$select->where(
sprintf(
- "purchase_update_date BETWEEN '%s' AND '%s'",
+ "%s BETWEEN '%s' AND '%s'",
+ WalmartOrderResource::COLUMN_PURCHASE_CREATE_DATE,
$dateRange->getDateStart()->format('Y-m-d H:i:s'),
$dateRange->getDateEnd()->format('Y-m-d H:i:s')
)
);
if ($isHourlyInterval) {
- $select->group('HOUR(main_table.purchase_update_date)');
+ $select->group(sprintf('HOUR(main_table.%s)', WalmartOrderResource::COLUMN_PURCHASE_CREATE_DATE));
}
- $select->group('DAY(main_table.purchase_update_date)');
+ $select->group(sprintf('DAY(main_table.%s)', WalmartOrderResource::COLUMN_PURCHASE_CREATE_DATE));
$select->order('date');
$queryData = $select->query()->fetchAll();
diff --git a/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php b/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php
index 5cdd87603..6e58c185a 100644
--- a/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php
+++ b/Setup/MigrationFromMagento1/PreconditionsChecker/AbstractModel.php
@@ -75,6 +75,7 @@ abstract class AbstractModel
'6.64.*',
'6.65.*',
'6.66.*',
+ '6.67.*',
];
/** @var \Ess\M2ePro\Model\ActiveRecord\Factory */
diff --git a/Setup/Update/Config.php b/Setup/Update/Config.php
index dee634b54..173c66d0b 100644
--- a/Setup/Update/Config.php
+++ b/Setup/Update/Config.php
@@ -376,6 +376,10 @@ public function getFeaturesList(): array
'y24_m08' => [
'AddDateOfInvoiceSendingToAmazonOrder',
'RemoveBlockingErrorsFromConfigTable',
+ 'UpdateAmazonDictionaryProductType'
+ ],
+ 'y24_m09' => [
+ 'RemoveIsNewAsinAvailableFromAmazonMarketplace'
],
];
}
@@ -438,24 +442,34 @@ public static function getFeaturesForRepeatAfterMigrationFromMagento1(): array
\Ess\M2ePro\Setup\Update\y23_m12\AddCreateShipmentFbaOrdersColumn::class,
\Ess\M2ePro\Setup\Update\y23_m12\AddTecdocKtypesIt::class,
\Ess\M2ePro\Setup\Update\y23_m12\AddAmazonInventoryFbaFieldsInAmazonAccountTable::class,
+
\Ess\M2ePro\Setup\Update\y24_m01\AddListingProductAdvancedFilterTable::class,
\Ess\M2ePro\Setup\Update\y24_m01\ImproveAutoUpdateEbayFinalFees::class,
+
\Ess\M2ePro\Setup\Update\y24_m02\AddReviseProductIdentifiersToEbaySyncTemplate::class,
\Ess\M2ePro\Setup\Update\y24_m02\DisableAmazonMarketplaceWithoutAccounts::class,
+
\Ess\M2ePro\Setup\Update\y24_m03\AddOnlineRegularMapPriceToAmazonListingProduct::class,
\Ess\M2ePro\Setup\Update\y24_m03\AddKtypesResolveAttemptColumn::class,
\Ess\M2ePro\Setup\Update\y24_m03\CreateAndFillAmazonAccountMerchantSettingTable::class,
+
\Ess\M2ePro\Setup\Update\y24_m05\AddEbayPromotion::class,
+
\Ess\M2ePro\Setup\Update\y24_m06\AddAmazonShippingPalletDelivery::class,
\Ess\M2ePro\Setup\Update\y24_m06\AddPriceLastUpdateDateColumnToEbayListingProductTable::class,
\Ess\M2ePro\Setup\Update\y24_m06\RemoveAuEpidsVisibleFromConfigTable::class,
\Ess\M2ePro\Setup\Update\y24_m06\AddAmazonMarketplaceSaudiArabia::class,
- \Ess\M2ePro\Setup\Update\y24_m07\AddProductIdentifiersSettingsForAmazonListing::class,
\Ess\M2ePro\Setup\Update\y24_m06\AddEbayBundleOptionMappingTable::class,
+
+ \Ess\M2ePro\Setup\Update\y24_m07\AddProductIdentifiersSettingsForAmazonListing::class,
\Ess\M2ePro\Setup\Update\y24_m07\AddProductIdentifiersSettingsForAmazonListing::class,
\Ess\M2ePro\Setup\Update\y24_m07\AddOfferImagesToAmazonListing::class,
\Ess\M2ePro\Setup\Update\y24_m07\AddEbayVideo::class,
+
\Ess\M2ePro\Setup\Update\y24_m08\RemoveBlockingErrorsFromConfigTable::class,
+ \Ess\M2ePro\Setup\Update\y24_m08\UpdateAmazonDictionaryProductType::class,
+
+ \Ess\M2ePro\Setup\Update\y24_m09\RemoveIsNewAsinAvailableFromAmazonMarketplace::class,
];
}
diff --git a/Setup/Update/y24_m06/AddAmazonMarketplaceSaudiArabia.php b/Setup/Update/y24_m06/AddAmazonMarketplaceSaudiArabia.php
index 8583cb08a..7ae484f2d 100644
--- a/Setup/Update/y24_m06/AddAmazonMarketplaceSaudiArabia.php
+++ b/Setup/Update/y24_m06/AddAmazonMarketplaceSaudiArabia.php
@@ -73,7 +73,7 @@ private function createAmazonMarketplace(): void
[
AmazonMarketplaceResource::COLUMN_MARKETPLACE_ID => 50,
AmazonMarketplaceResource::COLUMN_DEFAULT_CURRENCY => 'SAR',
- AmazonMarketplaceResource::COLUMN_IS_NEW_ASIN_AVAILABLE => 1,
+ 'is_new_asin_available' => 1,
AmazonMarketplaceResource::COLUMN_IS_MERCHANT_FULFILLMENT_AVAILABLE => 1,
AmazonMarketplaceResource::COLUMN_IS_BUSINESS_AVAILABLE => 1,
AmazonMarketplaceResource::COLUMN_IS_VAT_CALCULATION_SERVICE_AVAILABLE => 1,
diff --git a/Setup/Update/y24_m08/UpdateAmazonDictionaryProductType.php b/Setup/Update/y24_m08/UpdateAmazonDictionaryProductType.php
new file mode 100644
index 000000000..f74f51f88
--- /dev/null
+++ b/Setup/Update/y24_m08/UpdateAmazonDictionaryProductType.php
@@ -0,0 +1,177 @@
+addColumnForDictionaryPT();
+ $this->updateLastUpdateDate();
+ $this->updateVariationThemesGroups();
+
+ $this->removeOldColumnFromMarketplaceDictionary();
+ }
+
+ private function addColumnForDictionaryPT(): void
+ {
+ $this->getTableModifier(TablesHelper::TABLE_AMAZON_DICTIONARY_PRODUCT_TYPE)
+ ->addColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_VARIATION_THEMES,
+ 'LONGTEXT',
+ 'NULL',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_SCHEMA,
+ false,
+ false,
+ )
+ ->addColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_ATTRIBUTES_GROUPS,
+ 'LONGTEXT',
+ 'NULL',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_VARIATION_THEMES,
+ false,
+ false,
+ )
+ ->addColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE,
+ 'DATETIME',
+ 'NULL',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_ATTRIBUTES_GROUPS,
+ false,
+ false,
+ )
+ ->addColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE,
+ 'DATETIME',
+ 'NULL',
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE,
+ false,
+ false,
+ )
+ ->commit();
+ }
+
+ private function updateLastUpdateDate(): void
+ {
+ $dictionaryMarketplaceTableName = $this->getFullTableName(TablesHelper::TABLE_AMAZON_DICTIONARY_MARKETPLACE);
+ $dictionaryPTTableName = $this->getFullTableName(TablesHelper::TABLE_AMAZON_DICTIONARY_PRODUCT_TYPE);
+
+ $this->getConnection()
+ ->query(
+ <<getTableModifier(TablesHelper::TABLE_AMAZON_DICTIONARY_PRODUCT_TYPE)
+ ->changeColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_CLIENT_DETAILS_LAST_UPDATE_DATE,
+ 'DATETIME NOT NULL',
+ )
+ ->changeColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_SERVER_DETAILS_LAST_UPDATE_DATE,
+ 'DATETIME NOT NULL',
+ );
+ }
+
+ private function updateVariationThemesGroups(): void
+ {
+ $dictionaryPTTableName = $this->getFullTableName(TablesHelper::TABLE_AMAZON_DICTIONARY_PRODUCT_TYPE);
+
+ $stmt = $this->getConnection()
+ ->query(
+ <<fetch()) {
+ $ptDictionaryId = (int)$ptRow['id'];
+ $marketplaceId = (int)$ptRow['marketplace_id'];
+ $nick = $ptRow['nick'];
+
+ if (!isset($productTypeMarketplacesDictionaryData[$marketplaceId])) {
+ $productTypeMarketplacesDictionaryData[$marketplaceId] = $this->getMarketplaceDictionaryData(
+ $marketplaceId
+ );
+ }
+
+ $dictionaryPTData = $productTypeMarketplacesDictionaryData[$marketplaceId][$nick] ?? null;
+ if ($dictionaryPTData === null) {
+ continue;
+ }
+
+ $groups = $dictionaryPTData['groups'] ?? [];
+ $variationThemes = $dictionaryPTData['variation_themes'] ?? [];
+
+ //$mySqlGroups = $this->getConnection()->quote(json_encode($groups));
+ $mySqlGroups = json_encode($groups);
+ //$mySqlVariationThemes = $this->getConnection()->quote(json_encode($variationThemes));
+ $mySqlVariationThemes = json_encode($variationThemes);
+
+ $this->getConnection()
+ ->query(
+ <<getTableModifier(TablesHelper::TABLE_AMAZON_DICTIONARY_PRODUCT_TYPE)
+ ->changeColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_VARIATION_THEMES,
+ 'LONGTEXT NOT NULL',
+ null,
+ null,
+ false,
+ )
+ ->changeColumn(
+ \Ess\M2ePro\Model\ResourceModel\Amazon\Dictionary\ProductType::COLUMN_ATTRIBUTES_GROUPS,
+ 'LONGTEXT NOT NULL',
+ null,
+ null,
+ false,
+ )
+ ->commit();
+ }
+
+ private function getMarketplaceDictionaryData(int $marketplaceId): array
+ {
+ $dictionaryMarketplaceTableName = $this->getFullTableName(TablesHelper::TABLE_AMAZON_DICTIONARY_MARKETPLACE);
+
+ $ptData = $this->getConnection()
+ ->query(
+ <<fetchColumn();
+
+ return (array)json_decode($ptData ?? '[]', true);
+ }
+
+ // ----------------------------------------
+
+ private function removeOldColumnFromMarketplaceDictionary(): void
+ {
+ $this->getTableModifier(TablesHelper::TABLE_AMAZON_DICTIONARY_MARKETPLACE)
+ ->dropColumn('client_details_last_update_date', true, false)
+ ->dropColumn('server_details_last_update_date', true, false)
+ ->commit();
+ }
+}
diff --git a/Setup/Update/y24_m09/RemoveIsNewAsinAvailableFromAmazonMarketplace.php b/Setup/Update/y24_m09/RemoveIsNewAsinAvailableFromAmazonMarketplace.php
new file mode 100644
index 000000000..3d73f393a
--- /dev/null
+++ b/Setup/Update/y24_m09/RemoveIsNewAsinAvailableFromAmazonMarketplace.php
@@ -0,0 +1,16 @@
+getTableModifier(TablesHelper::TABLE_AMAZON_MARKETPLACE)
+ ->dropColumn('is_new_asin_available');
+ }
+}
diff --git a/Setup/Upgrade/v1_66_2__v1_67_0/Config.php b/Setup/Upgrade/v1_66_2__v1_67_0/Config.php
new file mode 100644
index 000000000..b242d9776
--- /dev/null
+++ b/Setup/Upgrade/v1_66_2__v1_67_0/Config.php
@@ -0,0 +1,16 @@
+data['config']['filter_url_params'])) {
+ return;
+ }
+
+ foreach ($this->data['config']['filter_url_params'] as $paramName => $paramValue) {
+ if ('*' === $paramValue) {
+ $paramValue = $this->request->getParam($paramName);
+ }
+
+ if ($paramValue !== null) {
+ $this->data['config']['update_url'] = sprintf(
+ '%s%s/%s/',
+ $this->data['config']['update_url'],
+ $paramName,
+ $paramValue
+ );
+ $this->addFilter(
+ $this->filterBuilder->setField($paramName)->setValue($paramValue)->setConditionType('eq')->create()
+ );
+ }
+ }
+ }
+}
diff --git a/Ui/Template/ProductType/Component/Listing/Column/Marketplace.php b/Ui/Template/ProductType/Component/Listing/Column/Marketplace.php
new file mode 100644
index 000000000..86eacfa03
--- /dev/null
+++ b/Ui/Template/ProductType/Component/Listing/Column/Marketplace.php
@@ -0,0 +1,41 @@
+amazonMarketplaceRepository = $amazonMarketplaceRepository;
+ }
+
+ public function prepareDataSource(array $dataSource): array
+ {
+ if (empty($dataSource['data']['items'])) {
+ return $dataSource;
+ }
+
+ foreach ($dataSource['data']['items'] as &$row) {
+ $marketplaceId = (int)$row['marketplace_id'];
+ if (!isset(self::$marketplacesRuntime[$marketplaceId])) {
+ self::$marketplacesRuntime[$marketplaceId] = $this->amazonMarketplaceRepository->get($marketplaceId);
+ }
+
+ $row['marketplace'] = self::$marketplacesRuntime[$marketplaceId]->getTitle();
+ }
+
+ return $dataSource;
+ }
+}
diff --git a/Ui/Template/ProductType/Component/Listing/Column/Title.php b/Ui/Template/ProductType/Component/Listing/Column/Title.php
new file mode 100644
index 000000000..cb5c507ba
--- /dev/null
+++ b/Ui/Template/ProductType/Component/Listing/Column/Title.php
@@ -0,0 +1,53 @@
+(Out Of Date)
+HTML;
+ }
+
+ if ($isInvalid) {
+ $message = (string)__(
+ 'This Product Type is no longer supported by Amazon. '
+ . 'Please assign another Product Type to the products that use it.',
+ );
+
+ $title = <<
+
+ $message
+
+HTML;
+ }
+
+ $row['template_title'] = $title;
+ }
+
+ return $dataSource;
+ }
+}
diff --git a/Ui/Template/ProductType/Component/Listing/Select/Marketplace.php b/Ui/Template/ProductType/Component/Listing/Select/Marketplace.php
new file mode 100644
index 000000000..e0c75c268
--- /dev/null
+++ b/Ui/Template/ProductType/Component/Listing/Select/Marketplace.php
@@ -0,0 +1,31 @@
+repository = $repository;
+ }
+
+ public function toOptionArray(): array
+ {
+ $options = [];
+
+ foreach ($this->repository->getUsingMarketplaces() as $marketplace) {
+ $options[] = [
+ 'label' => $marketplace->getTitle(),
+ 'value' => $marketplace->getId(),
+ ];
+ }
+
+ return $options;
+ }
+}
diff --git a/composer.json b/composer.json
index fa770a683..4067ae40c 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "m2e/ebay-amazon-magento2",
"description": "M2E Pro is a Magento trusted (TM), award-winning extension, which allows merchants of all sizes to fully integrate Magento based system(s) into eBay/Amazon/Walmart platforms.",
"type": "magento2-module",
- "version": "1.66.2",
+ "version": "1.67.0",
"license": "proprietary",
"keywords": ["ebay", "amazon", "walmart", "magento"],
"homepage": "https://m2epro.com/",
diff --git a/etc/di.xml b/etc/di.xml
index cd84f7056..aff01cc35 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -158,4 +158,16 @@
type="Ess\M2ePro\Model\Ebay\Api\Data\Order\OrderItem\TaxDetails" />
+
+
+
+
+
+
+ -
+ Ess\M2ePro\Model\ResourceModel\Amazon\Template\ProductType\Grid\Collection
+
+
+
+
diff --git a/etc/module.xml b/etc/module.xml
index 644b138c5..24751378a 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -3,7 +3,7 @@
-
+
diff --git a/view/adminhtml/layout/m2epro_amazon_template_producttype_index.xml b/view/adminhtml/layout/m2epro_amazon_template_producttype_index.xml
new file mode 100644
index 000000000..25d214120
--- /dev/null
+++ b/view/adminhtml/layout/m2epro_amazon_template_producttype_index.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+ Ess_M2ePro::amazon_configuration_product_types
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/view/adminhtml/layout/m2epro_general_handler.xml b/view/adminhtml/layout/m2epro_general_handler.xml
new file mode 100644
index 000000000..84c4053fe
--- /dev/null
+++ b/view/adminhtml/layout/m2epro_general_handler.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/view/adminhtml/ui_component/m2epro_amazon_template_product_type_grid.xml b/view/adminhtml/ui_component/m2epro_amazon_template_product_type_grid.xml
new file mode 100644
index 000000000..8d09e1759
--- /dev/null
+++ b/view/adminhtml/ui_component/m2epro_amazon_template_product_type_grid.xml
@@ -0,0 +1,140 @@
+
+
+
+
+ -
+
-
+ m2epro_amazon_template_product_type_grid.m2epro_amazon_template_product_type_grid_data_source
+
+ -
+ m2epro_amazon_template_product_type_grid.m2epro_amazon_template_product_type_grid_source
+
+
+ -
+
- \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Button\RefreshAmazonData
+ - \Ess\M2ePro\Block\Adminhtml\Amazon\Template\ProductType\Button\AddNewButton
+
+ - m2epro_amazon_template_product_type_grid_columns
+
+
+
+
+ \Ess\M2ePro\Ui\DataProvider
+ m2epro_amazon_template_product_type_grid_source
+ id
+ id
+
+ -
+
- Magento_Ui/js/grid/provider
+
+ -
+
- id
+
+
+
+
+
+
+
+
+ -
+
- false
+
+
+
+
+
+
+ -
+
-
+
-
+
-
+
- Magento_Ui/js/form/element/ui-select
+ - ui/grid/filters/elements/ui-select
+
+
+
+
+
+
+
+
+ Marketplace
+ marketplace_id
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+ -
+
- ID
+ - false
+
+
+
+
+
+
+ -
+
- Title
+ - ui/grid/cells/html
+ - text
+ - 10
+
+
+
+
+
+
+ -
+
- Marketplace
+ - 20
+
+
+
+
+
+
+ -
+
- Create Date
+ - dateRange
+ - 30
+
+
+
+
+
+
+ -
+
- Update Date
+ - dateRange
+ - 40
+
+
+
+
+
+
+
+
diff --git a/view/adminhtml/web/js/Amazon/Listing/Create/General.js b/view/adminhtml/web/js/Amazon/Listing/Create/General.js
index 2d082432a..bcd47b7fb 100644
--- a/view/adminhtml/web/js/Amazon/Listing/Create/General.js
+++ b/view/adminhtml/web/js/Amazon/Listing/Create/General.js
@@ -1,14 +1,10 @@
define([
'underscore',
- 'Magento_Ui/js/modal/alert',
- 'M2ePro/Amazon/Listing/Create/General/MarketplaceSynchProgress',
- 'M2ePro/Plugin/ProgressBar',
- 'M2ePro/Plugin/AreaWrapper'
-], function(_, alert) {
+ 'M2ePro/Common'
+], function(_) {
- window.AmazonListingCreateGeneral = Class.create({
+ window.AmazonListingCreateGeneral = Class.create(Common, {
- marketplaceSynchProgressObj: null,
accounts: null,
selectedAccountId: null,
@@ -17,11 +13,6 @@ define([
initialize: function() {
var self = this;
- self.marketplaceSynchProgressObj = new AmazonListingCreateGeneralMarketplaceSynchProgress(
- new ProgressBar('progress_bar'),
- new AreaWrapper('content_container')
- );
-
CommonObj.setValidationCheckRepetitionValue(
'M2ePro-listing-title',
M2ePro.translator.translate('The specified Title is already used for other Listing. Listing Title must be unique.'),
@@ -75,13 +66,9 @@ define([
var self = this;
$('save_and_next').observe('click', function() {
- if (self.marketplaceSynchProgressObj.runningNow) {
- alert({
- content: M2ePro.translator.translate('Please wait while Synchronization is finished.')
- });
- return;
+ if (jQuery('#edit_form').valid()) {
+ self.saveClick(M2ePro.url.get('amazon_listing_create/index'), true);
}
- jQuery('#edit_form').valid() && self.synchronizeMarketplace($('marketplace_id').value);
});
},
@@ -183,42 +170,6 @@ define([
});
},
- synchronizeMarketplace: function(marketplaceId) {
- var self = this;
-
- new Ajax.Request(M2ePro.url.get('general/isMarketplaceEnabled'), {
- method: 'get',
- parameters: {marketplace_id: marketplaceId},
- onSuccess: function(transport) {
-
- var result = transport.responseText.evalJSON();
- if (result.status) {
- return self.marketplaceSynchProgressObj.end();
- }
-
- var params = {};
- params['status_' + marketplaceId] = 1;
-
- new Ajax.Request(M2ePro.url.get('amazon_marketplace/save'), {
- method: 'post',
- parameters: params,
- onSuccess: function() {
-
- var title = 'Amazon ' + $('marketplace_title').innerHTML;
- $('save_and_next').disable();
-
- self.marketplaceSynchProgressObj.runTask(
- title,
- M2ePro.url.get('amazon_marketplace/runSynchNow', {marketplace_id: marketplaceId}),
- M2ePro.url.get('amazon_marketplace/synchGetExecutingInfo'),
- 'AmazonListingCreateGeneralObj.marketplaceSynchProgressObj.end()'
- );
- }
- });
- }
- });
- },
-
isAccountsEqual: function(newAccounts) {
if (!newAccounts.length && !this.accounts.length) {
return true;
@@ -232,7 +183,5 @@ define([
return _.where(newAccounts, account).length > 0;
});
}
-
- // ---------------------------------------
});
});
diff --git a/view/adminhtml/web/js/Amazon/Listing/Product/Search.js b/view/adminhtml/web/js/Amazon/Listing/Product/Search.js
index e172c5b3b..62de87567 100644
--- a/view/adminhtml/web/js/Amazon/Listing/Product/Search.js
+++ b/view/adminhtml/web/js/Amazon/Listing/Product/Search.js
@@ -293,11 +293,6 @@ define([
addNewGeneralId: function (listingProductIds) {
var self = this;
- if (!M2ePro.customData.isNewAsinAvailable) {
- self.alert(M2ePro.translator.translate('new_asin_not_available').replace('%code%', M2ePro.customData.marketplace.code));
- return;
- }
-
listingProductIds = listingProductIds || self.params.productId;
new Ajax.Request(M2ePro.url.get('amazon_listing_product/mapToNewAsin'), {
diff --git a/view/adminhtml/web/js/Amazon/Marketplace/Sync.js b/view/adminhtml/web/js/Amazon/Marketplace/Sync.js
new file mode 100644
index 000000000..c79999fe8
--- /dev/null
+++ b/view/adminhtml/web/js/Amazon/Marketplace/Sync.js
@@ -0,0 +1,172 @@
+define([
+ 'jquery',
+ 'mage/translate',
+ 'M2ePro/Plugin/ProgressBar',
+], function($, $t) {
+ 'use strict';
+
+ return function(options, button) {
+ const urlForGetMarketplaces = options.url_for_get_marketplaces;
+ const urlForUpdateMarketplacesDetails = options.url_for_update_marketplaces_details;
+ const urlForGetProductTypes = options.url_for_get_product_types;
+ const urlForUpdateProductType = options.url_for_update_product_type;
+
+ const processor = {
+ isWaiterActive: false,
+
+ progressBar: null,
+
+ totalItems: 0,
+ processedItems: 0,
+
+ async start(progressBar) {
+ this.waiterStart();
+
+ this.progressBarPrepare(progressBar);
+
+ try {
+
+ const response = await this.getMarketplaces();
+ const marketplaces = response.list.map(
+ marketplace => {
+ return {
+ 'id': marketplace.id,
+ 'title': marketplace.title,
+ };
+ },
+ );
+
+ this.progressBarChangeStatus($t('Update Marketplace details. Please wait...'), marketplaces.size());
+
+ // ----------------------------------------
+
+ const productTypes = [];
+ for (const marketplace of marketplaces) {
+ await this.updateMarketplaceDetails(marketplace.id);
+
+ const response = await this.getProductTypesForMarketplace(marketplace.id);
+ for (const productType of response.list) {
+ productTypes.push({
+ 'id': productType.id, 'title': productType.title,
+ });
+ }
+
+ this.progressBarTik();
+ }
+
+ this.progressBarChangeStatus($t('Update Product Types. Please wait...'), productTypes.size());
+
+ for (const productType of productTypes) {
+ await this.updateProductType(productType.id);
+ this.progressBarTik();
+ }
+
+ // ----------------------------------------
+ } catch (e) {
+ this.complete();
+ throw e;
+ }
+
+ this.complete();
+
+ window.location.reload();
+ },
+
+ async getMarketplaces() {
+ return $.ajax({
+ url: urlForGetMarketplaces,
+ type: 'GET',
+ });
+ },
+
+ async updateMarketplaceDetails(marketplaceId) {
+ return await $.ajax({
+ url: urlForUpdateMarketplacesDetails,
+ type: 'POST',
+ contentType: 'application/x-www-form-urlencoded',
+ data: {form_key: FORM_KEY, marketplace_id: marketplaceId},
+ });
+ },
+
+ async getProductTypesForMarketplace(marketplaceId) {
+ return $.ajax({
+ url: urlForGetProductTypes + `marketplace_id/${marketplaceId}`,
+ type: 'GET',
+ });
+ },
+
+ async updateProductType(productTypeId) {
+ return await $.ajax({
+ url: urlForUpdateProductType,
+ type: 'POST',
+ contentType: 'application/x-www-form-urlencoded',
+ data: {form_key: FORM_KEY, id: productTypeId},
+ });
+ },
+
+ // ----------------------------------------
+
+ waiterStart: function() {
+ if (this.isWaiterActive) {
+ return;
+ }
+
+ $('body').trigger('processStart');
+ this.isWaiterActive = true;
+ },
+
+ waiterStop: function() {
+ if (!this.isWaiterActive) {
+ return;
+ }
+
+ $('body').trigger('processStop');
+ this.isWaiterActive = false;
+ },
+
+ complete: function() {
+ this.ProgressBar.hide();
+ this.waiterStop();
+ },
+
+ // ----------------------------------------
+
+ progressBarPrepare: function(progressBar) {
+ this.ProgressBar = progressBar;
+
+ this.ProgressBar.reset();
+ this.ProgressBar.setTitle($t('Update Amazon Data'));
+ this.ProgressBar.show();
+
+ this.progressBarUpdate();
+ },
+
+ progressBarChangeStatus: function(title, totalItems) {
+ this.ProgressBar.setStatus(title);
+ this.totalItems = totalItems;
+ this.processedItems = 0;
+
+ this.progressBarUpdate();
+ },
+
+ progressBarTik: function() {
+ this.processedItems++;
+ this.progressBarUpdate();
+ },
+
+ progressBarUpdate: function() {
+ this.ProgressBar.setPercents(this.getProcessPercent(), 0);
+ },
+
+ getProcessPercent: function() {
+ return (this.processedItems / this.totalItems) * 100;
+ },
+ };
+
+ $(button).on('click', function(e) {
+ e.preventDefault();
+
+ processor.start(new window.ProgressBar(options.progress_bar_el_id));
+ });
+ };
+});
diff --git a/view/adminhtml/web/js/Amazon/MarketplaceUpdateSynchProgress.js b/view/adminhtml/web/js/Amazon/MarketplaceUpdateSynchProgress.js
deleted file mode 100644
index 50fced3a5..000000000
--- a/view/adminhtml/web/js/Amazon/MarketplaceUpdateSynchProgress.js
+++ /dev/null
@@ -1,34 +0,0 @@
-define([
- 'M2ePro/Plugin/Messages',
- 'M2ePro/SynchProgress'
-], function (MessageObj) {
- MarketplaceUpdateSynchProgress = Class.create(SynchProgress, {
-
- // ---------------------------------------
-
- printFinalMessage: function ()
- {
- var self = this;
-
- if (self.result == self.resultTypeError) {
- MessageObj.addError(str_replace(
- '%url%',
- M2ePro.url.get('logViewUrl'),
- M2ePro.translator.translate('Amazon Data Update was completed with errors. View Log for the details.')
- ));
- } else if (self.result == self.resultTypeWarning) {
- MessageObj.addWarning(str_replace(
- '%url%',
- M2ePro.url.get('logViewUrl'),
- M2ePro.translator.translate('Amazon Data Update was completed with warnings. View Log for the details.')
- ));
- } else {
- MessageObj.addSuccess(M2ePro.translator.translate('Amazon Data Update was completed.'));
- }
-
- self.result = null;
- },
-
- // ---------------------------------------
- });
-});
diff --git a/view/adminhtml/web/js/MarketplaceBuildUpdate.js b/view/adminhtml/web/js/MarketplaceBuildUpdate.js
deleted file mode 100755
index 0c477916e..000000000
--- a/view/adminhtml/web/js/MarketplaceBuildUpdate.js
+++ /dev/null
@@ -1,127 +0,0 @@
-define([
- 'M2ePro/Plugin/Messages',
- 'M2ePro/Common'
-], function (MessageObj) {
-
- window.AmazonMarketplacesBuildUpdate = Class.create(Common, {
-
- // ---------------------------------------
-
- initialize: function (synchProgressObj, storedStatuses)
- {
- this.synchProgressObj = synchProgressObj;
-
- this.marketplacesForUpdate = [];
- this.marketplacesForUpdateCurrentIndex = 0;
- this.storedStatuses = storedStatuses || [];
- },
-
- // ---------------------------------------
-
- getStoredStatuses: function ()
- {
- return this.storedStatuses;
- },
-
- // ---------------------------------------
-
- updateAction: function ()
- {
- MessageObj.clear();
- CommonObj.scrollPageToTop();
- this.runAllSynchronization();
- },
-
- // ---------------------------------------
-
- runAllSynchronization: function (statuses)
- {
- var statusesForSynch = statuses || this.getStoredStatuses();
-
- this.marketplacesForUpdate = [];
- this.marketplacesForUpdateCurrentIndex = 0;
-
- for (var i = 0; i < statusesForSynch.length; i++) {
-
- var marketplaceId = statusesForSynch[i].marketplace_id;
-
- if (!marketplaceId) {
- continue;
- }
- this.marketplacesForUpdate[this.marketplacesForUpdate.length] = marketplaceId;
- }
-
- if (this.marketplacesForUpdate.length == 0) {
- return false;
- }
-
- this.marketplacesForUpdateCurrentIndex = 0;
-
- this.runNextMarketplaceNow();
- return true;
- },
-
- // ---------------------------------------
-
- runNextMarketplaceNow: function ()
- {
- var self = this;
-
- if (self.synchProgressObj.result == self.synchProgressObj.resultTypeError) {
- self.completeWithError();
- return;
- }
-
- if (self.marketplacesForUpdateCurrentIndex >= self.marketplacesForUpdate.length) {
-
- self.marketplacesForUpdate = [];
- self.marketplacesForUpdateCurrentIndex = 0;
- self.marketplacesUpdateFinished = true;
-
- self.synchProgressObj.end();
- self.synchProgressObj.printFinalMessage();
-
- return;
- }
-
- var marketplaceId = self.marketplacesForUpdate[self.marketplacesForUpdateCurrentIndex];
- self.marketplacesForUpdateCurrentIndex++;
- var currentMarketplace = self.storedStatuses[self.marketplacesForUpdateCurrentIndex - 1];
-
- var titleProgressBar = currentMarketplace.title;
- var componentTitle = 'Amazon';
- var component = 'amazon';
-
- titleProgressBar = componentTitle + ' ' + titleProgressBar;
-
- self.runNextMarketplaceTask(titleProgressBar, marketplaceId, component);
- return true;
- },
-
- runNextMarketplaceTask: function(titleProgressBar, marketplaceId, component)
- {
- this.synchProgressObj.runTask(
- titleProgressBar,
- M2ePro.url.get('runSynchNow', {'marketplace_id': marketplaceId}),
- M2ePro.url.get('amazon_marketplace/synchGetExecutingInfo'),
- 'MarketplaceObj.runNextMarketplaceNow();'
- );
- },
-
- // ---------------------------------------
-
- completeWithError: function()
- {
- var self = this;
-
- self.marketplacesForUpdate = [];
- self.marketplacesForUpdateCurrentIndex = 0;
- self.marketplacesUpdateFinished = true;
-
- self.synchProgressObj.end();
- self.synchProgressObj.printFinalMessage();
- }
-
- // ---------------------------------------
- });
-});