diff --git a/Block/Adminhtml/Category/Merchandising.php b/Block/Adminhtml/Category/Merchandising.php index 2828b9a67..89357498e 100644 --- a/Block/Adminhtml/Category/Merchandising.php +++ b/Block/Adminhtml/Category/Merchandising.php @@ -6,15 +6,15 @@ use Algolia\AlgoliaSearch\Helper\Data; use Magento\Backend\Block\Template\Context; use Magento\Catalog\Model\Category; -use Magento\Framework\Registry; +use Algolia\AlgoliaSearch\Registry\CurrentCategory; class Merchandising extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'catalog/category/edit/merchandising.phtml'; - /** @var Registry */ - protected $registry; + /** @var CurrentCategory */ + protected $currentCategory; /** @var ConfigHelper */ private $configHelper; @@ -27,19 +27,19 @@ class Merchandising extends \Magento\Backend\Block\Template /** * @param Context $context - * @param Registry $registry + * @param CurrentCategory $currentCategory * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - Registry $registry, + CurrentCategory $currentCategory, ConfigHelper $configHelper, Data $coreHelper, array $data = [] ) { - $this->registry = $registry; + $this->currentCategory = $currentCategory; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; $this->storeManager = $context->getStoreManager(); @@ -50,7 +50,7 @@ public function __construct( /** @return Category | null */ public function getCategory() { - return $this->registry->registry('category'); + return $this->currentCategory->get(); } /** @return bool */ diff --git a/Block/Adminhtml/Job/View.php b/Block/Adminhtml/Job/View.php old mode 100644 new mode 100755 index a184b98b9..3459cd31e --- a/Block/Adminhtml/Job/View.php +++ b/Block/Adminhtml/Job/View.php @@ -3,28 +3,27 @@ namespace Algolia\AlgoliaSearch\Block\Adminhtml\Job; use Magento\Backend\Block\Widget\Button; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class View extends Template { - /** @var \Magento\Framework\Registry */ - protected $coreRegistry; + /** @var SessionManagerInterface */ + protected $backendSession; /** - * @param Context $context - * @param Registry $coreRegistry - * @param array $data + * @param Context $context + * @param SessionManagerInterface $backendSession + * @param array $data */ public function __construct( - Context $context, - Registry $coreRegistry, + Context $context, + SessionManagerInterface $backendSession, array $data = [] ) { parent::__construct($context, $data); - - $this->coreRegistry = $coreRegistry; + $this->backendSession = $backendSession; } /** @inheritdoc */ @@ -48,7 +47,7 @@ protected function _prepareLayout() /** @return \Algolia\AlgoliaSearch\Model\Job */ public function getCurrentJob() { - return $this->coreRegistry->registry('current_job'); + return $this->backendSession->getData('current_job'); } /** @return string */ diff --git a/Block/Adminhtml/LandingPage/SearchConfiguration.php b/Block/Adminhtml/LandingPage/SearchConfiguration.php old mode 100644 new mode 100755 index edb1584c0..0cbeb6638 --- a/Block/Adminhtml/LandingPage/SearchConfiguration.php +++ b/Block/Adminhtml/LandingPage/SearchConfiguration.php @@ -6,15 +6,15 @@ use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\LandingPage; use Magento\Backend\Block\Template\Context; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; class SearchConfiguration extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'landingpage/search-configuration.phtml'; - /** @var Registry */ - protected $registry; + /** @var SessionManagerInterface */ + protected $backendSession; /** @var ConfigHelper */ private $configHelper; @@ -27,19 +27,19 @@ class SearchConfiguration extends \Magento\Backend\Block\Template /** * @param Context $context - * @param Registry $registry + * @param SessionManagerInterface $backendSession * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - Registry $registry, + SessionManagerInterface $backendSession, ConfigHelper $configHelper, Data $coreHelper, array $data = [] ) { - $this->registry = $registry; + $this->backendSession = $backendSession; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; @@ -49,7 +49,7 @@ public function __construct( /** @return LandingPage | null */ public function getLandingPage() { - return $this->registry->registry('algoliasearch_landing_page'); + return $this->backendSession->getData('algoliasearch_landing_page'); } /** @return ConfigHelper */ diff --git a/Block/Adminhtml/Query/Merchandising.php b/Block/Adminhtml/Query/Merchandising.php old mode 100644 new mode 100755 index c4d378831..6face4425 --- a/Block/Adminhtml/Query/Merchandising.php +++ b/Block/Adminhtml/Query/Merchandising.php @@ -6,15 +6,15 @@ use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\Query; use Magento\Backend\Block\Template\Context; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; class Merchandising extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'query/edit/merchandising.phtml'; - /** @var Registry */ - protected $registry; + /** @var SessionManagerInterface */ + protected $backendSession; /** @var ConfigHelper */ private $configHelper; @@ -27,19 +27,19 @@ class Merchandising extends \Magento\Backend\Block\Template /** * @param Context $context - * @param Registry $registry + * @param SessionManagerInterface $backendSession * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - Registry $registry, + SessionManagerInterface $backendSession, ConfigHelper $configHelper, Data $coreHelper, array $data = [] ) { - $this->registry = $registry; + $this->backendSession = $backendSession; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; $this->storeManager = $context->getStoreManager(); @@ -50,7 +50,7 @@ public function __construct( /** @return Query | null */ public function getCurrentQuery() { - return $this->registry->registry('algoliasearch_query'); + return $this->backendSession->getData('algoliasearch_query'); } /** @return ConfigHelper */ diff --git a/Block/Adminhtml/QueueArchive/View.php b/Block/Adminhtml/QueueArchive/View.php old mode 100644 new mode 100755 index d52639b92..5e72f5d5e --- a/Block/Adminhtml/QueueArchive/View.php +++ b/Block/Adminhtml/QueueArchive/View.php @@ -3,28 +3,28 @@ namespace Algolia\AlgoliaSearch\Block\Adminhtml\QueueArchive; use Magento\Backend\Block\Widget\Button; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class View extends Template { - /** @var Registry */ - protected $coreRegistry; + /** @var SessionManagerInterface */ + protected $backendSession; /** - * @param Context $context - * @param Registry $coreRegistry - * @param array $data + * @param Context $context + * @param SessionManagerInterface $backendSession + * @param array $data */ public function __construct( - Context $context, - Registry $coreRegistry, + Context $context, + SessionManagerInterface $backendSession, array $data = [] ) { parent::__construct($context, $data); - $this->coreRegistry = $coreRegistry; + $this->backendSession = $backendSession; } /** @inheritdoc */ @@ -48,7 +48,7 @@ protected function _prepareLayout() /** @return \Algolia\AlgoliaSearch\Model\QueueArchive */ public function getCurrentJob() { - return $this->coreRegistry->registry('current_job'); + return $this->backendSession->getData('current_job'); } /** @return string */ diff --git a/Block/Algolia.php b/Block/Algolia.php index bc53a9224..0b349ccb6 100755 --- a/Block/Algolia.php +++ b/Block/Algolia.php @@ -20,7 +20,7 @@ use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Locale\Currency; use Magento\Framework\Locale\Format; -use Magento\Framework\Registry; +use Algolia\AlgoliaSearch\Registry\CurrentProduct; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Framework\Url\Helper\Data; use Magento\Framework\View\Element\Template; @@ -38,9 +38,9 @@ class Algolia extends Template implements CollectionDataSourceInterface */ protected $catalogSearchHelper; /** - * @var Registry + * @var CurrentProduct */ - protected $registry; + protected $currentProduct; /** * @var ProductHelper */ @@ -110,7 +110,7 @@ class Algolia extends Template implements CollectionDataSourceInterface * @param ProductHelper $productHelper * @param Currency $currency * @param Format $format - * @param Registry $registry + * @param CurrentProduct $currentProduct * @param AlgoliaHelper $algoliaHelper * @param Data $urlHelper * @param FormKey $formKey @@ -131,7 +131,7 @@ public function __construct( ProductHelper $productHelper, Currency $currency, Format $format, - Registry $registry, + CurrentProduct $currentProduct, AlgoliaHelper $algoliaHelper, Data $urlHelper, FormKey $formKey, @@ -151,7 +151,7 @@ public function __construct( $this->productHelper = $productHelper; $this->currency = $currency; $this->format = $format; - $this->registry = $registry; + $this->currentProduct = $currentProduct; $this->algoliaHelper = $algoliaHelper; $this->urlHelper = $urlHelper; $this->formKey = $formKey; @@ -267,7 +267,7 @@ public function getCurrentCategory() /** @return Product */ public function getCurrentProduct() { - return $this->registry->registry('product'); + return $this->currentProduct->get(); } /** @return Order */ diff --git a/Block/RecommendProductView.php b/Block/RecommendProductView.php index 4450651e7..ec43eecf5 100644 --- a/Block/RecommendProductView.php +++ b/Block/RecommendProductView.php @@ -8,7 +8,7 @@ use Magento\Catalog\Model\Product; use Algolia\AlgoliaSearch\Helper\ConfigHelper; -use Magento\Framework\Registry; +use Algolia\AlgoliaSearch\Registry\CurrentProduct; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; @@ -20,11 +20,9 @@ class RecommendProductView extends Template protected $product = null; /** - * Core registry - * - * @var Registry + * @var CurrentProduct */ - protected $coreRegistry = null; + protected $currentProduct; /** * @var ConfigHelper @@ -33,17 +31,17 @@ class RecommendProductView extends Template /** * @param Context $context - * @param Registry $registry + * @param CurrentProduct $currentProduct * @param ConfigHelper $configHelper * @param array $data */ public function __construct( Context $context, - Registry $registry, + CurrentProduct $currentProduct, ConfigHelper $configHelper, array $data = [] ) { - $this->coreRegistry = $registry; + $this->currentProduct = $currentProduct; $this->configHelper = $configHelper; parent::__construct($context, $data); } @@ -56,7 +54,7 @@ public function __construct( public function getProduct() { if (!$this->product) { - $this->product = $this->coreRegistry->registry('product'); + $this->product = $this->currentProduct->get(); } return $this->product; } diff --git a/CHANGELOG.md b/CHANGELOG.md index a5761b7df..afc103d4f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # CHANGE LOG +## 3.13.2 + +### Updates +- Updated code to refactor the deprecated usage of the registry in the extension +- Updated the code to prevent the creation of indexer for websites excluded in customer groups +- Removed the unused polyfill script from the extension. + +### Bug Fixes +- Fixed issue with the special price range for configurable products +- Fixed issue with tier prices +- Fixed issue causing duplicate replica errors to occur when saving the configuration. + + ## 3.13.1 ### Bug Fixes diff --git a/Controller/Adminhtml/Landingpage/AbstractAction.php b/Controller/Adminhtml/Landingpage/AbstractAction.php old mode 100644 new mode 100755 index 05d7c8559..0f61ed550 --- a/Controller/Adminhtml/Landingpage/AbstractAction.php +++ b/Controller/Adminhtml/Landingpage/AbstractAction.php @@ -5,13 +5,14 @@ use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\LandingPageFactory; use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Store\Model\StoreManagerInterface; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + + /** @var SessionManagerInterface */ + protected $backendSession; /** @var LandingPageFactory */ protected $landingPageFactory; @@ -24,21 +25,21 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param Registry $coreRegistry + * @param SessionManagerInterface $backendSession * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, - Registry $coreRegistry, + SessionManagerInterface $backendSession, LandingPageFactory $landingPageFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager ) { parent::__construct($context); - $this->coreRegistry = $coreRegistry; + $this->backendSession = $backendSession; $this->landingPageFactory = $landingPageFactory; $this->merchandisingHelper = $merchandisingHelper; $this->storeManager = $storeManager; @@ -65,7 +66,7 @@ protected function initLandingPage() } } - $this->coreRegistry->register('algoliasearch_landing_page', $landingPage); + $this->backendSession->setData('algoliasearch_landing_page', $landingPage); return $landingPage; } diff --git a/Controller/Adminhtml/Landingpage/Duplicate.php b/Controller/Adminhtml/Landingpage/Duplicate.php index 3fcd8301a..2926a9fff 100644 --- a/Controller/Adminhtml/Landingpage/Duplicate.php +++ b/Controller/Adminhtml/Landingpage/Duplicate.php @@ -35,8 +35,7 @@ public function execute() try { $newLandingPage->getResource()->save($newLandingPage); $this->copyQueryRules($landingPage->getId(), $newLandingPage->getId()); - - $this->coreRegistry->register('algoliasearch_landing_page', $newLandingPage); + $this->backendSession->setData('algoliasearch_landing_page', $newLandingPage); $this->messageManager->addSuccessMessage(__('The duplicated landing page has been saved.')); return $resultRedirect->setPath('*/*/edit', ['id' => $newLandingPage->getId()]); diff --git a/Controller/Adminhtml/Landingpage/Save.php b/Controller/Adminhtml/Landingpage/Save.php old mode 100644 new mode 100755 index d22593352..e1e2b7a68 --- a/Controller/Adminhtml/Landingpage/Save.php +++ b/Controller/Adminhtml/Landingpage/Save.php @@ -5,6 +5,7 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\LandingPageFactory; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; @@ -28,11 +29,16 @@ class Save extends AbstractAction */ protected $configHelper; + /** + * @var SessionManagerInterface + */ + protected $backendSession; + /** * PHP Constructor * * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry + * @param SessionManagerInterface $backendSession * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager @@ -42,7 +48,7 @@ class Save extends AbstractAction */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, + SessionManagerInterface $backendSession, LandingPageFactory $landingPageFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager, @@ -55,7 +61,7 @@ public function __construct( $this->configHelper = $configHelper; parent::__construct( $context, - $coreRegistry, + $backendSession, $landingPageFactory, $merchandisingHelper, $storeManager diff --git a/Controller/Adminhtml/Query/AbstractAction.php b/Controller/Adminhtml/Query/AbstractAction.php old mode 100644 new mode 100755 index 1ccba4d82..78d616b44 --- a/Controller/Adminhtml/Query/AbstractAction.php +++ b/Controller/Adminhtml/Query/AbstractAction.php @@ -5,13 +5,13 @@ use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\QueryFactory; use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Store\Model\StoreManagerInterface; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + /** @var SessionManagerInterface */ + protected $backendSession; /** @var QueryFactory */ protected $queryFactory; @@ -24,21 +24,21 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param Registry $coreRegistry + * @param SessionManagerInterface $backendSession * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, - Registry $coreRegistry, + SessionManagerInterface $backendSession, QueryFactory $queryFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager ) { parent::__construct($context); - $this->coreRegistry = $coreRegistry; + $this->backendSession = $backendSession; $this->queryFactory = $queryFactory; $this->merchandisingHelper = $merchandisingHelper; $this->storeManager = $storeManager; @@ -65,7 +65,7 @@ protected function initQuery() } } - $this->coreRegistry->register('algoliasearch_query', $query); + $this->backendSession->setData('algoliasearch_query', $query); return $query; } diff --git a/Controller/Adminhtml/Query/Save.php b/Controller/Adminhtml/Query/Save.php old mode 100644 new mode 100755 index fa3f61408..e6db407b8 --- a/Controller/Adminhtml/Query/Save.php +++ b/Controller/Adminhtml/Query/Save.php @@ -6,6 +6,7 @@ use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\ImageUploader; use Algolia\AlgoliaSearch\Model\QueryFactory; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; @@ -28,11 +29,16 @@ class Save extends AbstractAction */ protected $imageUploader; + /** + * @var SessionManagerInterface + */ + protected $backendSession; + /** * PHP Constructor * * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry + * @param SessionManagerInterface $backendSession * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager @@ -44,7 +50,7 @@ class Save extends AbstractAction */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, + SessionManagerInterface $backendSession, QueryFactory $queryFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager, @@ -58,7 +64,7 @@ public function __construct( parent::__construct( $context, - $coreRegistry, + $backendSession, $queryFactory, $merchandisingHelper, $storeManager diff --git a/Controller/Adminhtml/Queue/AbstractAction.php b/Controller/Adminhtml/Queue/AbstractAction.php old mode 100644 new mode 100755 index 3c39255e7..672ca12e3 --- a/Controller/Adminhtml/Queue/AbstractAction.php +++ b/Controller/Adminhtml/Queue/AbstractAction.php @@ -5,13 +5,13 @@ use Algolia\AlgoliaSearch\Model\JobFactory; use Algolia\AlgoliaSearch\Model\ResourceModel\Job as JobResourceModel; use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Indexer\Model\IndexerFactory; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + /** @var SessionManagerInterface */ + protected $backendSession; /** @var \Algolia\AlgoliaSearch\Model\JobFactory */ protected $jobFactory; @@ -24,21 +24,21 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param Registry $coreRegistry + * @param SessionManagerInterface $backendSession * @param JobFactory $jobFactory * @param JobResourceModel $jobResourceModel * @param IndexerFactory $indexerFactory */ public function __construct( Context $context, - Registry $coreRegistry, + SessionManagerInterface $backendSession, JobFactory $jobFactory, JobResourceModel $jobResourceModel, IndexerFactory $indexerFactory ) { parent::__construct($context); - $this->coreRegistry = $coreRegistry; + $this->backendSession = $backendSession; $this->jobFactory = $jobFactory; $this->jobResourceModel = $jobResourceModel; $this->indexerFactory = $indexerFactory; @@ -68,7 +68,7 @@ protected function initJob() } // Register model to use later in blocks - $this->coreRegistry->register('current_job', $model); + $this->backendSession->setData('current_job', $model); return $model; } diff --git a/Controller/Adminhtml/QueueArchive/AbstractAction.php b/Controller/Adminhtml/QueueArchive/AbstractAction.php old mode 100644 new mode 100755 index 2c5eaf22d..377223bb4 --- a/Controller/Adminhtml/QueueArchive/AbstractAction.php +++ b/Controller/Adminhtml/QueueArchive/AbstractAction.php @@ -5,13 +5,13 @@ use Algolia\AlgoliaSearch\Model\QueueArchiveFactory; use Algolia\AlgoliaSearch\Model\ResourceModel\QueueArchive as QueueArchiveResourceModel; use Magento\Backend\App\Action\Context; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Indexer\Model\IndexerFactory; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + /** @var SessionManagerInterface */ + protected $backendSession; /** @var \Algolia\AlgoliaSearch\Model\QueueArchiveFactory */ protected $queueArchiveFactory; @@ -24,21 +24,21 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param Registry $coreRegistry + * @param SessionManagerInterface $backendSession * @param QueueArchiveFactory $queueArchiveFactory * @param QueueArchiveResourceModel $queueArchiveResourceModel * @param IndexerFactory $indexerFactory */ public function __construct( Context $context, - Registry $coreRegistry, + SessionManagerInterface $backendSession, QueueArchiveFactory $queueArchiveFactory, QueueArchiveResourceModel $queueArchiveResourceModel, IndexerFactory $indexerFactory ) { parent::__construct($context); - $this->coreRegistry = $coreRegistry; + $this->backendSession = $backendSession; $this->queueArchiveFactory = $queueArchiveFactory; $this->queueArchiveResourceModel = $queueArchiveResourceModel; $this->indexerFactory = $indexerFactory; @@ -68,7 +68,7 @@ protected function initJob() } // Register model to use later in blocks - $this->coreRegistry->register('current_job', $model); + $this->backendSession->setData('current_job', $model); return $model; } diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php index 83bad3075..7f1039512 100755 --- a/Helper/ConfigHelper.php +++ b/Helper/ConfigHelper.php @@ -11,8 +11,10 @@ use Magento\Framework\Serialize\SerializerInterface; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface; use Magento\Cookie\Helper\Cookie as CookieHelper; + class ConfigHelper { public const ENABLE_FRONTEND = 'algoliasearch_credentials/credentials/enable_frontend'; @@ -194,6 +196,11 @@ class ConfigHelper */ protected $groupCollection; + /** + * @var GroupExcludedWebsiteRepositoryInterface + */ + protected $groupExcludedWebsiteRepository; + /** * @var CookieHelper */ @@ -210,7 +217,9 @@ class ConfigHelper * @param Magento\Framework\Event\ManagerInterface $eventManager * @param SerializerInterface $serializer * @param GroupCollection $groupCollection + * @param GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository * @param CookieHelper $cookieHelper + */ public function __construct( Magento\Framework\App\Config\ScopeConfigInterface $configInterface, @@ -223,6 +232,7 @@ public function __construct( Magento\Framework\Event\ManagerInterface $eventManager, SerializerInterface $serializer, GroupCollection $groupCollection, + GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository, CookieHelper $cookieHelper ) { $this->configInterface = $configInterface; @@ -235,6 +245,7 @@ public function __construct( $this->eventManager = $eventManager; $this->serializer = $serializer; $this->groupCollection = $groupCollection; + $this->groupExcludedWebsiteRepository = $groupExcludedWebsiteRepository; $this->cookieHelper = $cookieHelper; } @@ -999,6 +1010,7 @@ public function getAutocompleteMinimumCharacterLength($storeId = null): int * @param $currentCustomerGroupId * @param $attrs * @return array + * @throws Magento\Framework\Exception\LocalizedException * @throws Magento\Framework\Exception\NoSuchEntityException */ public function getSortingIndices($originalIndexName, $storeId = null, $currentCustomerGroupId = null, $attrs = null) @@ -1013,12 +1025,17 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC $indexName = false; $sortAttribute = false; if ($this->isCustomerGroupsEnabled($storeId) && $attr['attribute'] === 'price') { + $websiteId = (int)$this->storeManager->getStore($storeId)->getWebsiteId(); $groupCollection = $this->groupCollection; if (!is_null($currentCustomerGroupId)) { $groupCollection->addFilter('customer_group_id', $currentCustomerGroupId); } foreach ($groupCollection as $group) { $customerGroupId = (int)$group->getData('customer_group_id'); + $excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($customerGroupId); + if (in_array($websiteId, $excludedWebsites)) { + continue; + } $groupIndexNameSuffix = 'group_' . $customerGroupId; $groupIndexName = $originalIndexName . '_' . $attr['attribute'] . '_' . $groupIndexNameSuffix . '_' . $attr['sort']; diff --git a/Helper/Entity/Product/PriceManager/Configurable.php b/Helper/Entity/Product/PriceManager/Configurable.php old mode 100644 new mode 100755 index d9383392b..a55671c5a --- a/Helper/Entity/Product/PriceManager/Configurable.php +++ b/Helper/Entity/Product/PriceManager/Configurable.php @@ -9,15 +9,20 @@ class Configurable extends ProductWithChildren /** * @param $groupId * @param $product + * @param $subProducts * @return float|int|mixed */ - protected function getRulePrice($groupId, $product) + protected function getRulePrice($groupId, $product, $subProducts) { $childrenPrices = []; - /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $typeInstance */ $typeInstance = $product->getTypeInstance(); - $children = $typeInstance->getUsedProducts($product); - foreach ($children as $child) { + + if (!$typeInstance instanceof \Magento\ConfigurableProduct\Model\Product\Type\Configurable) { + $this->logger->log('Unexpected product type encountered, reverting to default price calculation. Where Product Id is ' .$product->getId(). ' and Group Id is ' .$groupId); + return parent::getRulePrice($groupId, $product, $subProducts); + } + + foreach ($subProducts as $child) { $childrenPrices[] = (float) $this->rule->getRulePrice( new DateTime(), $this->store->getWebsiteId(), diff --git a/Helper/Entity/Product/PriceManager/ProductWithChildren.php b/Helper/Entity/Product/PriceManager/ProductWithChildren.php old mode 100644 new mode 100755 index bb2fa87bf..719d8e1da --- a/Helper/Entity/Product/PriceManager/ProductWithChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithChildren.php @@ -26,9 +26,6 @@ protected function addAdditionalData($product, $withTax, $subProducts, $currency $this->handleOriginalPrice($field, $currencyCode, $min, $max, $minOriginal, $maxOriginal); if (!$this->customData[$field][$currencyCode]['default']) { $this->handleZeroDefaultPrice($field, $currencyCode, $min, $max); - # need to rehandle specialPrice - $specialPrice = $this->getSpecialPrice($product, $currencyCode, $withTax); - $this->addSpecialPrices($specialPrice, $field, $currencyCode); } if ($this->areCustomersGroupsEnabled) { $this->setFinalGroupPrices($field, $currencyCode, $min, $max, $dashedFormat, $product, $subProducts, $withTax); @@ -51,7 +48,14 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu if (count($subProducts) > 0) { /** @var Product $subProduct */ foreach ($subProducts as $subProduct) { - $price = $this->getTaxPrice($product, $subProduct->getFinalPrice(), $withTax); + $specialPrice = $this->getSpecialPrice($subProduct, $currencyCode, $withTax, $subProducts); + $tierPrice = $this->getTierPrice($subProduct, $currencyCode, $withTax); + if (!empty($tierPrice[0]) && $specialPrice[0] > $tierPrice[0]){ + $minPrice = $tierPrice[0]; + } else { + $minPrice = $specialPrice[0]; + } + $price = $minPrice ?? $this->getTaxPrice($product, $subProduct->getFinalPrice(), $withTax); $basePrice = $this->getTaxPrice($product, $subProduct->getPrice(), $withTax); $min = min($min, $price); $original = min($original, $basePrice); @@ -153,28 +157,32 @@ protected function handleZeroDefaultPrice($field, $currencyCode, $min, $max) protected function setFinalGroupPrices($field, $currencyCode, $min, $max, $dashedFormat, $product, $subproducts, $withTax) { if (count($subproducts) > 0) { - $array = []; + $groupPriceList = []; /** @var Group $group */ foreach ($this->groups as $group) { $groupId = (int) $group->getData('customer_group_id'); + $minPrice = $min; foreach ($subproducts as $subProduct) { $subProduct->setData('customer_group_id', $groupId); $subProduct->setData('website_id', $subProduct->getStore()->getWebsiteId()); + $specialPrice = $this->getSpecialPrice($subProduct, $currencyCode, $withTax, []); + $tierPrice = $this->getTierPrice($subProduct, $currencyCode, $withTax); $price = $this->getTaxPrice($product, $subProduct->getPriceModel()->getFinalPrice(1, $subProduct), $withTax); - $array[$groupId][] = $price; + if (!empty($tierPrice[$groupId]) && $specialPrice[$groupId] > $tierPrice[$groupId]){ + $minPrice = $tierPrice[$groupId]; + } + $groupPriceList[$groupId]['min'] = min($minPrice, $price); + $groupPriceList[$groupId]['max'] = max($max, $price); $subProduct->setData('customer_group_id', null); } } + $minArray = []; - foreach ($array as $key => $value) { - $minArray[$key]['price'] = min($value); - $price = min($value); - $formattedPrice = $this->formatPrice($price, $currencyCode); - $minArray[$key]['formatted'] = $formattedPrice; + foreach ($groupPriceList as $key => $value) { + $minArray[$key]['price'] = $value['min']; + $minArray[$key]['formatted'] = $this->formattedConfigPrice($value['min'], $value['max'], $currencyCode); if ($currencyCode !== $this->baseCurrencyCode) { - $min = $this->convertPrice($price, $currencyCode); - $formattedPrice = $this->formatPrice($min, $currencyCode); - $minArray[$key]['formatted'] = strval($formattedPrice); + $minArray[$key]['formatted'] = $this->formattedConfigPrice($value['min'], $value['max'], $currencyCode); } } /** @var Group $group */ @@ -200,6 +208,20 @@ protected function setFinalGroupPrices($field, $currencyCode, $min, $max, $dashe } } + /** + * @param $min + * @param $max + * @param $currencyCode + * @return mixed|string + */ + public function formattedConfigPrice($min, $max, $currencyCode) { + if ($min != $max) { + return $this->getDashedPriceFormat($min, $max, $currencyCode); + } else { + return $this->formatPrice($min, $currencyCode); + } + } + /** * @param $field * @param $currencyCode @@ -219,11 +241,13 @@ public function handleOriginalPrice($field, $currencyCode, $min, $max, $minOrigi $maxOriginal, $currencyCode ); + $this->handleGroupOrginalPriceformated($field, $currencyCode, $this->customData[$field][$currencyCode]['default_original_formated']); } else { $this->customData[$field][$currencyCode]['default_original_formated'] = $this->formatPrice( $minOriginal, $currencyCode ); + $this->handleGroupOrginalPriceformated($field, $currencyCode, $this->customData[$field][$currencyCode]['default_original_formated']); } } } else { @@ -232,6 +256,25 @@ public function handleOriginalPrice($field, $currencyCode, $min, $max, $minOrigi $minOriginal, $currencyCode ); + $this->handleGroupOrginalPriceformated($field, $currencyCode, $this->customData[$field][$currencyCode]['default_original_formated']); + } + } + + } + + /** + * @param $field + * @param $currencyCode + * @param $formatedPrice + * @return void + */ + public function handleGroupOrginalPriceformated($field, $currencyCode, $formatedPrice) { + if ($this->areCustomersGroupsEnabled) { + /** @var Group $group */ + foreach ($this->groups as $group) { + $groupId = (int)$group->getData('customer_group_id'); + $this->customData[$field][$currencyCode]['group_' . $groupId . '_original_formated'] = + $formatedPrice; } } } diff --git a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php old mode 100644 new mode 100755 index 4a1a2be83..4ea16b285 --- a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php @@ -3,6 +3,7 @@ namespace Algolia\AlgoliaSearch\Helper\Entity\Product\PriceManager; use Algolia\AlgoliaSearch\Helper\ConfigHelper; +use Algolia\AlgoliaSearch\Helper\Logger; use DateTime; use Magento\Catalog\Helper\Data as CatalogHelper; use Magento\Catalog\Model\Product; @@ -11,9 +12,11 @@ use Magento\Customer\Model\Group; use Magento\Customer\Api\Data\GroupInterface; use Magento\Customer\Model\ResourceModel\Group\CollectionFactory; +use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Tax\Helper\Data as TaxHelper; use Magento\Tax\Model\Config as TaxConfig; +use Magento\Catalog\Api\ScopedProductTierPriceManagementInterface; abstract class ProductWithoutChildren { @@ -46,6 +49,21 @@ abstract class ProductWithoutChildren */ protected $productloader; + /** + * @var GroupExcludedWebsiteRepositoryInterface + */ + protected $groupExcludedWebsiteRepository; + + /** + * @var ScopedProductTierPriceManagementInterface + */ + private $productTierPrice; + + /** + * @var Logger + */ + protected $logger; + protected $store; protected $baseCurrencyCode; protected $groups; @@ -55,28 +73,37 @@ abstract class ProductWithoutChildren /** * @param ConfigHelper $configHelper * @param CollectionFactory $customerGroupCollectionFactory + * @param GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository * @param PriceCurrencyInterface $priceCurrency * @param CatalogHelper $catalogHelper * @param TaxHelper $taxHelper * @param Rule $rule * @param ProductFactory $productloader + * @param ScopedProductTierPriceManagementInterface $productTierPrice + * @param Logger $logger */ public function __construct( ConfigHelper $configHelper, CollectionFactory $customerGroupCollectionFactory, + GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository, PriceCurrencyInterface $priceCurrency, CatalogHelper $catalogHelper, TaxHelper $taxHelper, Rule $rule, - ProductFactory $productloader + ProductFactory $productloader, + ScopedProductTierPriceManagementInterface $productTierPrice, + Logger $logger, ) { $this->configHelper = $configHelper; $this->customerGroupCollectionFactory = $customerGroupCollectionFactory; + $this->groupExcludedWebsiteRepository = $groupExcludedWebsiteRepository; $this->priceCurrency = $priceCurrency; $this->catalogHelper = $catalogHelper; $this->taxHelper = $taxHelper; $this->rule = $rule; $this->productloader = $productloader; + $this->productTierPrice = $productTierPrice; + $this->logger = $logger; } /** @@ -84,6 +111,7 @@ public function __construct( * @param Product $product * @param $subProducts * @return array + * @throws \Magento\Framework\Exception\LocalizedException */ public function addPriceData($customData, Product $product, $subProducts): array { @@ -96,6 +124,18 @@ public function addPriceData($customData, Product $product, $subProducts): array $fields = $this->getFields(); if (!$this->areCustomersGroupsEnabled) { $this->groups->addFieldToFilter('main_table.customer_group_id', 0); + } else { + $excludedGroups = array(); + foreach ($this->groups as $group) { + $groupId = (int)$group->getData('customer_group_id'); + $excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($groupId); + if (in_array($product->getStore()->getWebsiteId(), $excludedWebsites)) { + $excludedGroups[] = $groupId; + } + } + if(count($excludedGroups) > 0) { + $this->groups->addFieldToFilter('main_table.customer_group_id', ["nin" => $excludedGroups]); + } } // price/price_with_tax => true/false foreach ($fields as $field => $withTax) { @@ -110,7 +150,7 @@ public function addPriceData($customData, Product $product, $subProducts): array $price = $this->getTaxPrice($product, $price, $withTax); $this->customData[$field][$currencyCode]['default'] = $this->priceCurrency->round($price); $this->customData[$field][$currencyCode]['default_formated'] = $this->formatPrice($price, $currencyCode); - $specialPrice = $this->getSpecialPrice($product, $currencyCode, $withTax); + $specialPrice = $this->getSpecialPrice($product, $currencyCode, $withTax, $subProducts); $tierPrice = $this->getTierPrice($product, $currencyCode, $withTax); if ($this->areCustomersGroupsEnabled) { $this->addCustomerGroupsPrices($product, $currencyCode, $withTax, $field); @@ -202,16 +242,17 @@ public function getTaxPrice($product, $amount, $withTax): float * @param Product $product * @param $currencyCode * @param $withTax + * @param $subProducts * @return array */ - protected function getSpecialPrice(Product $product, $currencyCode, $withTax): array + protected function getSpecialPrice(Product $product, $currencyCode, $withTax, $subProducts): array { $specialPrice = []; /** @var Group $group */ foreach ($this->groups as $group) { $groupId = (int) $group->getData('customer_group_id'); $specialPrices[$groupId] = []; - $specialPrices[$groupId][] = $this->getRulePrice($groupId, $product); + $specialPrices[$groupId][] = $this->getRulePrice($groupId, $product, $subProducts); // The price with applied catalog rules $specialPrices[$groupId][] = $product->getFinalPrice(); // The product's special price $specialPrices[$groupId] = array_filter($specialPrices[$groupId], function ($price) { @@ -231,7 +272,7 @@ protected function getSpecialPrice(Product $product, $currencyCode, $withTax): a } return $specialPrice; } - + /** * @param Product $product * @param $currencyCode @@ -243,7 +284,7 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax) $tierPrice = []; $tierPrices = []; - if (!is_null($product->getTierPrices())) { + if (!empty($product->getTierPrices())) { $product->setData('website_id', $product->getStore()->getWebsiteId()); $productTierPrices = $product->getTierPrices(); foreach ($productTierPrices as $productTierPrice) { @@ -258,6 +299,24 @@ protected function getTierPrice(Product $product, $currencyCode, $withTax) $productTierPrice->getValue() ); } + } else { + /** @var Group $group */ + foreach ($this->groups as $group) { + $customerGroupId = (int) $group->getData('customer_group_id'); + $productTierPrices = $this->productTierPrice->getList($product->getSku(), $customerGroupId); + if(!empty($productTierPrices)) { + foreach ($productTierPrices as $productTierPrice) { + if (!isset($tierPrices[$productTierPrice->getCustomerGroupId()])) { + $tierPrices[$productTierPrice->getCustomerGroupId()] = $productTierPrice->getValue(); + continue; + } + $tierPrices[$productTierPrice->getCustomerGroupId()] = min( + $tierPrices[$productTierPrice->getCustomerGroupId()], + $productTierPrice->getValue() + ); + } + } + } } /** @var Group $group */ @@ -321,13 +380,14 @@ protected function addTierPrices($tierPrice, $field, $currencyCode) $this->formatPrice($tierPrice[0], $currencyCode); } } - + # TODO bookmarking getRulePrice function for a future refactor effort. /** * @param $groupId * @param $product + * @param $subProducts * @return float */ - protected function getRulePrice($groupId, $product) + protected function getRulePrice($groupId, $product, $subProducts) { return (float) $this->rule->getRulePrice( new DateTime(), diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index 678c685b8..be91da093 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -33,6 +33,7 @@ use Magento\Framework\Event\ManagerInterface; use Magento\Store\Model\Store; use Magento\Store\Model\StoreManagerInterface; +use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface; class ProductHelper { @@ -112,6 +113,11 @@ class ProductHelper */ protected $productAttributes; + /** + * @var GroupExcludedWebsiteRepositoryInterface + */ + protected $groupExcludedWebsiteRepository; + /** * @var string[] */ @@ -166,6 +172,7 @@ class ProductHelper * @param Type $productType * @param CollectionFactory $productCollectionFactory * @param GroupCollection $groupCollection + * @param GroupExcludedWebsiteRepositoryInterface groupExcludedWebsiteRepository * @param ImageHelper $imageHelper */ public function __construct( @@ -178,15 +185,15 @@ public function __construct( Visibility $visibility, Stock $stockHelper, StockRegistryInterface $stockRegistry, - CurrencyHelper $currencyManager, - CategoryHelper $categoryHelper, - PriceManager $priceManager, - Type $productType, - CollectionFactory $productCollectionFactory, - GroupCollection $groupCollection, - ImageHelper $imageHelper - ) - { + CurrencyHelper $currencyManager, + CategoryHelper $categoryHelper, + PriceManager $priceManager, + Type $productType, + CollectionFactory $productCollectionFactory, + GroupCollection $groupCollection, + GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository, + ImageHelper $imageHelper + ) { $this->eavConfig = $eavConfig; $this->configHelper = $configHelper; $this->algoliaHelper = $algoliaHelper; @@ -202,6 +209,7 @@ public function __construct( $this->productType = $productType; $this->productCollectionFactory = $productCollectionFactory; $this->groupCollection = $groupCollection; + $this->groupExcludedWebsiteRepository = $groupExcludedWebsiteRepository; $this->imageHelper = $imageHelper; } @@ -452,7 +460,6 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic * Handle replicas */ $sortingIndices = $this->configHelper->getSortingIndices($indexName, $storeId); - $replicas = []; if ($this->configHelper->isInstantEnabled($storeId)) { @@ -463,7 +470,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic // Managing Virtual Replica if ($this->configHelper->useVirtualReplica($storeId)) { - $replicas = $this->handleVirtualReplica($replicas, $indexName); + $replicas = $this->handleVirtualReplica($replicas); } // Merge current replicas with sorting replicas to not delete A/B testing replica indices @@ -483,7 +490,6 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic $this->logger->log('Setting replicas to "' . $indexName . '" index.'); $this->logger->log('Replicas: ' . json_encode($replicas)); $setReplicasTaskId = $this->algoliaHelper->getLastTaskId(); - if (!$this->configHelper->useVirtualReplica($storeId)) { foreach ($sortingIndices as $values) { $replicaName = $values['name']; @@ -574,7 +580,7 @@ public function getObject(Product $product) ); $defaultData = $transport->getData(); - + $visibility = $product->getVisibility(); $visibleInCatalog = $this->visibility->getVisibleInCatalogIds(); @@ -1056,7 +1062,7 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P } $attributeResource = $attributeResource->setData('store_id', $product->getStoreId()); - + $value = $product->getData($attributeName); if ($value !== null) { @@ -1302,6 +1308,8 @@ protected function getUnretrieveableAttributes($storeId = null) /** * @param $storeId * @return array + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException */ protected function getAttributesForFaceting($storeId) { @@ -1310,6 +1318,7 @@ protected function getAttributesForFaceting($storeId) $currencies = $this->currencyManager->getConfigAllowCurrencies(); $facets = $this->configHelper->getFacets($storeId); + $websiteId = (int)$this->storeManager->getStore($storeId)->getWebsiteId(); foreach ($facets as $facet) { if ($facet['attribute'] === 'price') { foreach ($currencies as $currency_code) { @@ -1317,9 +1326,12 @@ protected function getAttributesForFaceting($storeId) if ($this->configHelper->isCustomerGroupsEnabled($storeId)) { foreach ($this->groupCollection as $group) { - $group_id = (int)$group->getData('customer_group_id'); - - $attributesForFaceting[] = 'price.' . $currency_code . '.group_' . $group_id; + $groupId = (int)$group->getData('customer_group_id'); + $excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($groupId); + if (in_array($websiteId, $excludedWebsites)) { + continue; + } + $attributesForFaceting[] = 'price.' . $currency_code . '.group_' . $groupId; } } @@ -1534,7 +1546,7 @@ public function productIsInStock($product, $storeId) * @param $replica * @return array */ - public function handleVirtualReplica($replicas, $indexName) + public function handleVirtualReplica($replicas) { $virtualReplicaArray = []; foreach ($replicas as $replica) { @@ -1557,18 +1569,21 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false) $replicas = array_values(array_map(function ($sortingIndex) { return $sortingIndex['name']; }, $sortingIndices)); + try { + $replicasFormated = $this->handleVirtualReplica($replicas); + $availableReplicaMatch = array_merge($replicasFormated, $replicas); if ($this->configHelper->useVirtualReplica($storeId)) { - $replicas = $this->handleVirtualReplica($replicas, $indexName); + $replicas = $replicasFormated; } $currentSettings = $this->algoliaHelper->getSettings($indexName); if (is_array($currentSettings) && array_key_exists('replicas', $currentSettings)) { - $replicasRequired = array_values(array_diff_assoc($currentSettings['replicas'], $replicas)); + $replicasRequired = array_values(array_diff($currentSettings['replicas'], $availableReplicaMatch)); $this->algoliaHelper->setSettings($indexName, ['replicas' => $replicasRequired]); $setReplicasTaskId = $this->algoliaHelper->getLastTaskId(); $this->algoliaHelper->waitLastTask($indexName, $setReplicasTaskId); - if (count($replicas) > 0) { - foreach ($replicas as $replicaIndex) { + if (count($availableReplicaMatch) > 0) { + foreach ($availableReplicaMatch as $replicaIndex) { $this->algoliaHelper->deleteIndex($replicaIndex); } } diff --git a/Model/Backend/Sorts.php b/Model/Backend/Sorts.php index 30626968d..92d0b60ba 100644 --- a/Model/Backend/Sorts.php +++ b/Model/Backend/Sorts.php @@ -74,10 +74,12 @@ public function afterSave() if ($this->isValueChanged()) { try{ $oldValue = $this->serializer->unserialize($this->getOldValue()); + $updatedValue = $this->serializer->unserialize($this->getValue()); + $sortingAttributes = array_merge($oldValue, $updatedValue); $storeIds = array_keys($this->storeManager->getStores()); foreach ($storeIds as $storeId) { $indexName = $this->helper->getIndexName($this->productHelper->getIndexNameSuffix(), $storeId); - $this->productHelper->handlingReplica($indexName, $storeId, $oldValue); + $this->productHelper->handlingReplica($indexName, $storeId, $sortingAttributes); } } catch (AlgoliaException $e) { if ($e->getCode() !== 404) { diff --git a/Observer/RegisterCurrentProductObserver.php b/Observer/RegisterCurrentProductObserver.php new file mode 100644 index 000000000..1bb1e4947 --- /dev/null +++ b/Observer/RegisterCurrentProductObserver.php @@ -0,0 +1,44 @@ +currentProduct = $currentProduct; + } + + /** + * Trigger event + * + * @param Event $event + */ + public function execute(Event $event) + { + /** @var ProductInterface $product */ + $product = $event->getData('product'); + $this->currentProduct->set($product); + } +} diff --git a/README.md b/README.md index cab3060bd..db9d6dd18 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Algolia Search & Discovery extension for Magento 2 ================================================== -![Latest version](https://img.shields.io/badge/latest-3.13.1-green) +![Latest version](https://img.shields.io/badge/latest-3.13.2-green) ![Magento 2](https://img.shields.io/badge/Magento-2.4.x-orange) ![PHP](https://img.shields.io/badge/PHP-8.2%2C8.1%2C7.4-blue) diff --git a/Registry/CurrentProduct.php b/Registry/CurrentProduct.php new file mode 100644 index 000000000..48f06f251 --- /dev/null +++ b/Registry/CurrentProduct.php @@ -0,0 +1,66 @@ +productFactory = $productFactory; + } + + /** + * Setter + * + * @param ProductInterface $product + */ + public function set(ProductInterface $product): void + { + $this->product = $product; + } + + /** + * Getter + * + * @return ProductInterface + */ + public function get(): ProductInterface + { + return $this->product ?? $this->createProduct(); + } + + /** + * Product factory + * + * @return ProductInterface + */ + private function createProduct(): ProductInterface + { + return $this->productFactory->create(); + } +} diff --git a/ViewModel/Recommend/ProductView.php b/ViewModel/Recommend/ProductView.php index 518e738ad..914e2255b 100644 --- a/ViewModel/Recommend/ProductView.php +++ b/ViewModel/Recommend/ProductView.php @@ -4,7 +4,7 @@ use Magento\Catalog\Model\Product; use Algolia\AlgoliaSearch\Helper\ConfigHelper; -use Magento\Framework\Registry; +use Algolia\AlgoliaSearch\Registry\CurrentProduct; use Magento\Framework\View\Element\Block\ArgumentInterface; class ProductView implements ArgumentInterface @@ -15,11 +15,9 @@ class ProductView implements ArgumentInterface protected $product = null; /** - * Core registry - * - * @var Registry + * @var CurrentProduct */ - protected $coreRegistry = null; + protected $currentProduct; /** * @var ConfigHelper @@ -27,14 +25,14 @@ class ProductView implements ArgumentInterface protected $configHelper; /** - * @param Registry $registry + * @param CurrentProduct $currentProduct * @param ConfigHelper $configHelper */ public function __construct( - Registry $registry, + CurrentProduct $currentProduct, ConfigHelper $configHelper ) { - $this->coreRegistry = $registry; + $this->currentProduct = $currentProduct; $this->configHelper = $configHelper; } /** @@ -45,11 +43,22 @@ public function __construct( public function getProduct() { if (!$this->product) { - $this->product = $this->coreRegistry->registry('product'); + $this->product = $this->getCurrentProduct(); } return $this->product; } + /** + * Get product + * + * @return array + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function getCurrentProduct() + { + return $this->currentProduct->get(); + } + /** * @return array */ diff --git a/composer.json b/composer.json index e422188c3..bc18202ab 100755 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Algolia Search & Discovery extension for Magento 2", "type": "magento2-module", "license": ["MIT"], - "version": "3.13.1", + "version": "3.13.2", "require": { "magento/framework": "~102.0|~103.0", "algolia/algoliasearch-client-php": "3.3.2", diff --git a/etc/adminhtml/events.xml b/etc/adminhtml/events.xml index 62132a089..273feaedf 100755 --- a/etc/adminhtml/events.xml +++ b/etc/adminhtml/events.xml @@ -65,5 +65,7 @@ - + + + diff --git a/etc/frontend/events.xml b/etc/frontend/events.xml index 4c2434232..4e8d28591 100755 --- a/etc/frontend/events.xml +++ b/etc/frontend/events.xml @@ -32,4 +32,7 @@ + + + diff --git a/etc/module.xml b/etc/module.xml index 2da64af9f..78806a7f3 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/view/frontend/templates/internals/configuration.phtml b/view/frontend/templates/internals/configuration.phtml old mode 100644 new mode 100755 index a94fd2aab..7986b6711 --- a/view/frontend/templates/internals/configuration.phtml +++ b/view/frontend/templates/internals/configuration.phtml @@ -5,7 +5,6 @@ $configuration = $block->getConfiguration(); ?> - \ No newline at end of file +