From 3f26b620c2f9ca4537634b441ce817cdc394fbfc Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Mon, 6 Feb 2023 19:08:57 +0530 Subject: [PATCH 01/25] Fixed Indexer created for websites excluded in Customer groups --- .../PriceManager/ProductWithoutChildren.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php index 40940bf3f..189d7ec56 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php @@ -10,6 +10,7 @@ use Magento\CatalogRule\Model\ResourceModel\Rule; use Magento\Customer\Model\Group; 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; @@ -45,6 +46,11 @@ abstract class ProductWithoutChildren */ protected $productloader; + /** + * @var GroupExcludedWebsiteRepositoryInterface + */ + protected $groupExcludedWebsiteRepository; + protected $store; protected $baseCurrencyCode; protected $groups; @@ -54,6 +60,7 @@ abstract class ProductWithoutChildren /** * @param ConfigHelper $configHelper * @param CollectionFactory $customerGroupCollectionFactory + * @param GroupExcludedWebsiteRepositoryInterface groupExcludedWebsiteRepository * @param PriceCurrencyInterface $priceCurrency * @param CatalogHelper $catalogHelper * @param TaxHelper $taxHelper @@ -63,6 +70,7 @@ abstract class ProductWithoutChildren public function __construct( ConfigHelper $configHelper, CollectionFactory $customerGroupCollectionFactory, + GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository, PriceCurrencyInterface $priceCurrency, CatalogHelper $catalogHelper, TaxHelper $taxHelper, @@ -71,6 +79,7 @@ public function __construct( ) { $this->configHelper = $configHelper; $this->customerGroupCollectionFactory = $customerGroupCollectionFactory; + $this->groupExcludedWebsiteRepository = $groupExcludedWebsiteRepository; $this->priceCurrency = $priceCurrency; $this->catalogHelper = $catalogHelper; $this->taxHelper = $taxHelper; @@ -95,6 +104,14 @@ public function addPriceData($customData, Product $product, $subProducts): array $fields = $this->getFields(); if (!$this->areCustomersGroupsEnabled) { $this->groups->addFieldToFilter('main_table.customer_group_id', 0); + } else { + foreach ($this->groups as $group) { + $groupId = (int)$group->getData('customer_group_id'); + $excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($groupId); + if (in_array($product->getStore()->getWebsiteId(), $excludedWebsites)) { + $group->delete(); + } + } } // price/price_with_tax => true/false foreach ($fields as $field => $withTax) { From 7611eff2db5e6144d9e805bb98bda29ee901ff27 Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Mon, 6 Feb 2023 20:28:28 +0530 Subject: [PATCH 02/25] Fix for Indexer created for websites excluded in Customer groups --- Helper/Entity/ProductHelper.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index 570c6c011..4d5368dea 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -32,6 +32,7 @@ use Magento\Framework\Event\ManagerInterface; use Magento\Store\Model\Store; use Magento\Store\Model\StoreManagerInterface; +use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface; class ProductHelper { @@ -111,6 +112,11 @@ class ProductHelper */ protected $productAttributes; + /** + * @var GroupExcludedWebsiteRepositoryInterface + */ + protected $groupExcludedWebsiteRepository; + /** * @var string[] */ @@ -164,6 +170,7 @@ class ProductHelper * @param Type $productType * @param CollectionFactory $productCollectionFactory * @param GroupCollection $groupCollection + * @param GroupExcludedWebsiteRepositoryInterface groupExcludedWebsiteRepository * @param ImageHelper $imageHelper */ public function __construct( @@ -182,6 +189,7 @@ public function __construct( Type $productType, CollectionFactory $productCollectionFactory, GroupCollection $groupCollection, + GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository, ImageHelper $imageHelper ) { $this->eavConfig = $eavConfig; @@ -199,6 +207,7 @@ public function __construct( $this->productType = $productType; $this->productCollectionFactory = $productCollectionFactory; $this->groupCollection = $groupCollection; + $this->groupExcludedWebsiteRepository = $groupExcludedWebsiteRepository; $this->imageHelper = $imageHelper; } @@ -1155,9 +1164,14 @@ protected function getAttributesForFaceting($storeId) $facet['attribute'] = 'price.' . $currency_code . '.default'; if ($this->configHelper->isCustomerGroupsEnabled($storeId)) { + $websiteId = (int)$this->storeManager->getStore($storeId)->getWebsiteId(); foreach ($this->groupCollection as $group) { $group_id = (int) $group->getData('customer_group_id'); - + $groupId = (int)$group->getData('customer_group_id'); + $excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($groupId); + if (in_array($websiteId, $excludedWebsites)) { + $group->delete(); + } $attributesForFaceting[] = 'price.' . $currency_code . '.group_' . $group_id; } } From aa32513fab525eee8ff33cc3468173a0655bbf43 Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Mon, 6 Feb 2023 20:48:56 +0530 Subject: [PATCH 03/25] Fix for Indexer created for websites excluded in Customer groups --- Helper/Entity/ProductHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index 4d5368dea..cf332b98c 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -1170,7 +1170,7 @@ protected function getAttributesForFaceting($storeId) $groupId = (int)$group->getData('customer_group_id'); $excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($groupId); if (in_array($websiteId, $excludedWebsites)) { - $group->delete(); + continue; } $attributesForFaceting[] = 'price.' . $currency_code . '.group_' . $group_id; } From 2ae64f6c0f2b81fd01074546a98b11949a4b5c85 Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Wed, 8 Feb 2023 18:24:29 +0530 Subject: [PATCH 04/25] Fix for Indexer created for websites excluded in Customer groups --- Helper/ConfigHelper.php | 16 +++++++++++++++- .../PriceManager/ProductWithoutChildren.php | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php index 003ab9a2d..980e4cc9d 100755 --- a/Helper/ConfigHelper.php +++ b/Helper/ConfigHelper.php @@ -11,6 +11,7 @@ use Magento\Framework\Serialize\SerializerInterface; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface; class ConfigHelper { @@ -175,6 +176,11 @@ class ConfigHelper */ protected $groupCollection; + /** + * @var GroupExcludedWebsiteRepositoryInterface + */ + protected $groupExcludedWebsiteRepository; + /** * @param Magento\Framework\App\Config\ScopeConfigInterface $configInterface * @param StoreManagerInterface $storeManager @@ -186,6 +192,7 @@ class ConfigHelper * @param Magento\Framework\Event\ManagerInterface $eventManager * @param SerializerInterface $serializer * @param GroupCollection $groupCollection + * @param GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository */ public function __construct( Magento\Framework\App\Config\ScopeConfigInterface $configInterface, @@ -197,7 +204,8 @@ public function __construct( Magento\Framework\App\ProductMetadataInterface $productMetadata, Magento\Framework\Event\ManagerInterface $eventManager, SerializerInterface $serializer, - GroupCollection $groupCollection + GroupCollection $groupCollection, + GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository ) { $this->configInterface = $configInterface; $this->currency = $currency; @@ -209,6 +217,7 @@ public function __construct( $this->eventManager = $eventManager; $this->serializer = $serializer; $this->groupCollection = $groupCollection; + $this->groupExcludedWebsiteRepository = $groupExcludedWebsiteRepository; } /** @@ -939,12 +948,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/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php index 189d7ec56..8987a2afa 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php @@ -105,13 +105,17 @@ public function addPriceData($customData, Product $product, $subProducts): array 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)) { - $group->delete(); + $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) { From b75ffa5292521e60cc3d12ff2027ed469b066b62 Mon Sep 17 00:00:00 2001 From: Bart Lubbersen Date: Tue, 11 Apr 2023 17:15:14 +0200 Subject: [PATCH 05/25] fix: Correctly calculate min special price for configurable products with price rules --- Helper/Entity/Product/PriceManager/Configurable.php | 11 +++++++---- .../Product/PriceManager/ProductWithChildren.php | 6 ++---- .../Product/PriceManager/ProductWithoutChildren.php | 10 ++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Helper/Entity/Product/PriceManager/Configurable.php b/Helper/Entity/Product/PriceManager/Configurable.php index d9383392b..49f93bfe1 100644 --- a/Helper/Entity/Product/PriceManager/Configurable.php +++ b/Helper/Entity/Product/PriceManager/Configurable.php @@ -9,15 +9,18 @@ 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) { + 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 index bb2fa87bf..175b344d6 100644 --- 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,8 @@ 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); + $price = $specialPrice[0] ?? $this->getTaxPrice($product, $subProduct->getFinalPrice(), $withTax); $basePrice = $this->getTaxPrice($product, $subProduct->getPrice(), $withTax); $min = min($min, $price); $original = min($original, $basePrice); diff --git a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php index 40940bf3f..dd3f4c180 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php @@ -109,7 +109,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); if ($this->areCustomersGroupsEnabled) { $this->addCustomerGroupsPrices($product, $currencyCode, $withTax, $field); } @@ -199,16 +199,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) { @@ -232,9 +233,10 @@ protected function getSpecialPrice(Product $product, $currencyCode, $withTax): a /** * @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(), From 5839fdd3f83690e69ad150ca83cf4545062c4d91 Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Wed, 27 Sep 2023 16:38:39 +0530 Subject: [PATCH 06/25] MAGE-760 Fixed Tier price issue --- .../PriceManager/ProductWithoutChildren.php | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php index 4a1a2be83..943b95344 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php @@ -14,6 +14,7 @@ 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 +47,11 @@ abstract class ProductWithoutChildren */ protected $productloader; + /** + * @var ScopedProductTierPriceManagementInterface + */ + private $productTierPrice; + protected $store; protected $baseCurrencyCode; protected $groups; @@ -60,6 +66,7 @@ abstract class ProductWithoutChildren * @param TaxHelper $taxHelper * @param Rule $rule * @param ProductFactory $productloader + * @param ScopedProductTierPriceManagementInterface $productTierPrice */ public function __construct( ConfigHelper $configHelper, @@ -68,7 +75,8 @@ public function __construct( CatalogHelper $catalogHelper, TaxHelper $taxHelper, Rule $rule, - ProductFactory $productloader + ProductFactory $productloader, + ScopedProductTierPriceManagementInterface $productTierPrice ) { $this->configHelper = $configHelper; $this->customerGroupCollectionFactory = $customerGroupCollectionFactory; @@ -77,6 +85,7 @@ public function __construct( $this->taxHelper = $taxHelper; $this->rule = $rule; $this->productloader = $productloader; + $this->productTierPrice = $productTierPrice; } /** @@ -243,7 +252,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 +267,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 */ From fb8fd2978cd0da9ca95af3e5ed60c6c2606ac7e4 Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Thu, 5 Oct 2023 15:57:33 +0530 Subject: [PATCH 07/25] Added option to select replica type per attribute --- Helper/ConfigHelper.php | 10 ++++++- Helper/Entity/ProductHelper.php | 53 ++++++++++++++++----------------- Model/Source/Sorts.php | 4 +++ 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php index 2e09902b0..65e544d82 100755 --- a/Helper/ConfigHelper.php +++ b/Helper/ConfigHelper.php @@ -989,10 +989,16 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC if (!$attrs){ $attrs = $this->getSorting($storeId); } - + $currency = $this->getCurrencyCode($storeId); $attributesToAdd = []; + $defaultVirtualReplicaEnabled = $this->useVirtualReplica($storeId); foreach ($attrs as $key => $attr) { + if ($defaultVirtualReplicaEnabled || (isset($attr['virtualReplica']) && $attr['virtualReplica'])){ + $virtualReplica = 1; + } else { + $virtualReplica = 0; + } $indexName = false; $sortAttribute = false; if ($this->isCustomerGroupsEnabled($storeId) && $attr['attribute'] === 'price') { @@ -1011,6 +1017,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC $newAttr['attribute'] = $attr['attribute']; $newAttr['sort'] = $attr['sort']; $newAttr['sortLabel'] = $attr['sortLabel']; + $newAttr['virtualReplica'] = $virtualReplica; if (!array_key_exists('label', $newAttr) && array_key_exists('sortLabel', $newAttr)) { $newAttr['label'] = $newAttr['sortLabel']; } @@ -1036,6 +1043,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC } if ($indexName && $sortAttribute) { $attrs[$key]['name'] = $indexName; + $attrs[$key]['virtualReplica'] = $virtualReplica; if (!array_key_exists('label', $attrs[$key]) && array_key_exists('sortLabel', $attrs[$key])) { $attrs[$key]['label'] = $attrs[$key]['sortLabel']; } diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index c1ce0679d..9a9e7664e 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -452,19 +452,16 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic * Handle replicas */ $sortingIndices = $this->configHelper->getSortingIndices($indexName, $storeId); - $replicas = []; if ($this->configHelper->isInstantEnabled($storeId)) { $replicas = array_values(array_map(function ($sortingIndex) { - return $sortingIndex['name']; + return [$sortingIndex['name'],$sortingIndex['virtualReplica']]; }, $sortingIndices)); } // Managing Virtual Replica - if ($this->configHelper->useVirtualReplica($storeId)) { - $replicas = $this->handleVirtualReplica($replicas, $indexName); - } + $replicas = $this->handleVirtualReplica($replicas, $indexName, $storeId); // Merge current replicas with sorting replicas to not delete A/B testing replica indices try { @@ -483,25 +480,23 @@ 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']; - $indexSettings['ranking'] = $values['ranking']; - $this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true); - $this->logger->log('Setting settings to "' . $replicaName . '" replica.'); - $this->logger->log('Settings: ' . json_encode($indexSettings)); - } - } else { - foreach ($sortingIndices as $values) { + foreach ($sortingIndices as $values) { + if ($values['virtualReplica']) { $replicaName = $values['name']; array_unshift($customRanking, $values['ranking'][0]); $replicaSetting['customRanking'] = $customRanking; $this->algoliaHelper->setSettings($replicaName, $replicaSetting, false, false); $this->logger->log('Setting settings to "' . $replicaName . '" replica.'); $this->logger->log('Settings: ' . json_encode($replicaSetting)); + } else { + $replicaName = $values['name']; + $indexSettings['ranking'] = $values['ranking']; + $this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true); + $this->logger->log('Setting settings to "' . $replicaName . '" replica.'); + $this->logger->log('Settings: ' . json_encode($indexSettings)); } } + } else { $this->algoliaHelper->setSettings($indexName, ['replicas' => []]); $this->logger->log('Removing replicas from "' . $indexName . '" index'); @@ -574,7 +569,6 @@ public function getObject(Product $product) ); $defaultData = $transport->getData(); - $visibility = $product->getVisibility(); $visibleInCatalog = $this->visibility->getVisibleInCatalogIds(); @@ -1054,7 +1048,6 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P } $attributeResource = $attributeResource->setData('store_id', $product->getStoreId()); - $value = $product->getData($attributeName); if ($value !== null) { @@ -1066,7 +1059,7 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P } $type = $product->getTypeId(); - if ($type !== 'configurable' && $type !== 'grouped' && $type !== 'bundle') { + if ($type !== 'configurable' && $type !== 'grouped' && $type !== 'bundle' && $attributeName != 'test') { continue; } @@ -1229,7 +1222,7 @@ protected function addNonNullValue( $value = $attributeResource->getFrontend()->getValue($product); } - if ($value) { + if ($value !== null) { $customData[$attribute['attribute']] = $value; } @@ -1532,13 +1525,17 @@ public function productIsInStock($product, $storeId) * @param $replica * @return array */ - public function handleVirtualReplica($replicas, $indexName) + public function handleVirtualReplica($replicas, $indexName, $storeId) { $virtualReplicaArray = []; foreach ($replicas as $replica) { - $virtualReplicaArray[] = 'virtual(' . $replica . ')'; + if ($replica[1]) { + $replicaArray[] = 'virtual(' . $replica[0] . ')'; + } else { + $replicaArray[] = $replica[0]; + } } - return $virtualReplicaArray; + return $replicaArray; } /** @@ -1553,12 +1550,12 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false) $sortingIndices = $this->configHelper->getSortingIndices($indexName, $storeId, null, $sortingAttribute); if ($this->configHelper->isInstantEnabled($storeId)) { $replicas = array_values(array_map(function ($sortingIndex) { - return $sortingIndex['name']; + return [$sortingIndex['name'],$sortingIndex['virtualReplica']]; }, $sortingIndices)); + try { - if ($this->configHelper->useVirtualReplica($storeId)) { - $replicas = $this->handleVirtualReplica($replicas, $indexName); - } + $replicas = $this->handleVirtualReplica($replicas, $indexName, $storeId); + $currentSettings = $this->algoliaHelper->getSettings($indexName); if (is_array($currentSettings) && array_key_exists('replicas', $currentSettings)) { $replicasRequired = array_values(array_diff_assoc($currentSettings['replicas'], $replicas)); @@ -1580,4 +1577,4 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false) } return true; } -} +} \ No newline at end of file diff --git a/Model/Source/Sorts.php b/Model/Source/Sorts.php index 1994c3eeb..e2b4aa38a 100755 --- a/Model/Source/Sorts.php +++ b/Model/Source/Sorts.php @@ -33,6 +33,10 @@ protected function getTableData() 'sortLabel' => [ 'label' => 'Label', ], + 'virtualReplica' => [ + 'label' => 'Enable Virtual Replica?', + 'values' => ['0' => __('No'), '1' => __('Yes')], + ], ]; } } From c3f315e7ce835768a72d0857dab0951d50e844a6 Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Thu, 5 Oct 2023 16:00:39 +0530 Subject: [PATCH 08/25] Added option to select replica type per attribute --- Helper/Entity/ProductHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index 9a9e7664e..f148d6362 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -1059,7 +1059,7 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P } $type = $product->getTypeId(); - if ($type !== 'configurable' && $type !== 'grouped' && $type !== 'bundle' && $attributeName != 'test') { + if ($type !== 'configurable' && $type !== 'grouped' && $type !== 'bundle') { continue; } @@ -1222,7 +1222,7 @@ protected function addNonNullValue( $value = $attributeResource->getFrontend()->getValue($product); } - if ($value !== null) { + if ($value) { $customData[$attribute['attribute']] = $value; } From 2e2b41b1950e2d5553d6704ded9ccdbd1590792d Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Wed, 11 Oct 2023 14:27:18 +0530 Subject: [PATCH 09/25] Added option to select replica type per attribute --- Helper/ConfigHelper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php index 65e544d82..f3d18ebda 100755 --- a/Helper/ConfigHelper.php +++ b/Helper/ConfigHelper.php @@ -134,6 +134,7 @@ class ConfigHelper public const ENHANCED_QUEUE_ARCHIVE = 'algoliasearch_advanced/queue/enhanced_archive'; public const NUMBER_OF_ELEMENT_BY_PAGE = 'algoliasearch_advanced/queue/number_of_element_by_page'; public const ARCHIVE_LOG_CLEAR_LIMIT = 'algoliasearch_advanced/queue/archive_clear_limit'; + public const MAX_VIRTUAL_REPLICA_COUNT = 50; /** * @var Magento\Framework\App\Config\ScopeConfigInterface @@ -993,8 +994,9 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC $currency = $this->getCurrencyCode($storeId); $attributesToAdd = []; $defaultVirtualReplicaEnabled = $this->useVirtualReplica($storeId); + $virtualReplicaCount = 0; foreach ($attrs as $key => $attr) { - if ($defaultVirtualReplicaEnabled || (isset($attr['virtualReplica']) && $attr['virtualReplica'])){ + if ($virtualReplicaCount < self::MAX_VIRTUAL_REPLICA_COUNT && ($defaultVirtualReplicaEnabled || (isset($attr['virtualReplica']) && $attr['virtualReplica']))){ $virtualReplica = 1; } else { $virtualReplica = 0; @@ -1033,6 +1035,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC 'custom', ]; $attributesToAdd[$newAttr['sort']][] = $newAttr; + $virtualReplicaCount++; } } elseif ($attr['attribute'] === 'price') { $indexName = $originalIndexName . '_' . $attr['attribute'] . '_' . 'default' . '_' . $attr['sort']; @@ -1058,6 +1061,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC 'exact', 'custom', ]; + $virtualReplicaCount++; } } $attrsToReturn = []; From 1fe6b15e20c05115be86b02566f839f75e1e0dc8 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:52:04 +0530 Subject: [PATCH 10/25] Fixed dashed price issue when Customer Group enable --- .../PriceManager/ProductWithChildren.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Helper/Entity/Product/PriceManager/ProductWithChildren.php b/Helper/Entity/Product/PriceManager/ProductWithChildren.php index 175b344d6..e628120ed 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithChildren.php @@ -151,7 +151,7 @@ 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'); @@ -159,20 +159,18 @@ protected function setFinalGroupPrices($field, $currencyCode, $min, $max, $dashe $subProduct->setData('customer_group_id', $groupId); $subProduct->setData('website_id', $subProduct->getStore()->getWebsiteId()); $price = $this->getTaxPrice($product, $subProduct->getPriceModel()->getFinalPrice(1, $subProduct), $withTax); - $array[$groupId][] = $price; + $groupPriceList[$groupId]['min'] = min($min, $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->getDashedPriceFormat($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->getDashedPriceFormat($value['min'], $value['max'], $currencyCode); } } /** @var Group $group */ From f80aa212cb389344293015de8d82e317e6d30af8 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:27:27 +0530 Subject: [PATCH 11/25] Fixed duplicate replica issue --- Helper/Entity/ProductHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index daced2cbe..ff5e8f674 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -1569,8 +1569,8 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false) $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); } } From 09b447d978df402705befcf7493bfde37d8d569d Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:29:29 +0530 Subject: [PATCH 12/25] Revert "Revert "Duplicate Replica Issue one set is standard and another is virtual"" --- Helper/Entity/ProductHelper.php | 10 ++++++---- Model/Backend/Sorts.php | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index 678c685b8..386a3fe45 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -463,7 +463,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 @@ -1534,7 +1534,7 @@ public function productIsInStock($product, $storeId) * @param $replica * @return array */ - public function handleVirtualReplica($replicas, $indexName) + public function handleVirtualReplica($replicas) { $virtualReplicaArray = []; foreach ($replicas as $replica) { @@ -1558,12 +1558,14 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false) 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); 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) { From 1636cd11b72ca36dbe8f16ee78bd81267384560c Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:18:30 +0530 Subject: [PATCH 13/25] Special Price range issue --- .../PriceManager/ProductWithChildren.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Helper/Entity/Product/PriceManager/ProductWithChildren.php b/Helper/Entity/Product/PriceManager/ProductWithChildren.php index e628120ed..67fd2ae1b 100644 --- a/Helper/Entity/Product/PriceManager/ProductWithChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithChildren.php @@ -215,11 +215,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 { @@ -228,6 +230,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; } } } From d3fbc0cbe217715122f560ca64c82bcfe0b4f3e8 Mon Sep 17 00:00:00 2001 From: Mohit Choudhary Date: Fri, 15 Dec 2023 16:05:42 +0530 Subject: [PATCH 14/25] Updated code for special price issue fix --- .../Product/PriceManager/ProductWithChildren.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) mode change 100644 => 100755 Helper/Entity/Product/PriceManager/ProductWithChildren.php diff --git a/Helper/Entity/Product/PriceManager/ProductWithChildren.php b/Helper/Entity/Product/PriceManager/ProductWithChildren.php old mode 100644 new mode 100755 index 67fd2ae1b..18e555527 --- a/Helper/Entity/Product/PriceManager/ProductWithChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithChildren.php @@ -49,7 +49,13 @@ protected function getMinMaxPrices(Product $product, $withTax, $subProducts, $cu /** @var Product $subProduct */ foreach ($subProducts as $subProduct) { $specialPrice = $this->getSpecialPrice($subProduct, $currencyCode, $withTax, $subProducts); - $price = $specialPrice[0] ?? $this->getTaxPrice($product, $subProduct->getFinalPrice(), $withTax); + $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); @@ -155,11 +161,17 @@ protected function setFinalGroupPrices($field, $currencyCode, $min, $max, $dashe /** @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); - $groupPriceList[$groupId]['min'] = min($min, $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); } From b7a91b337028525872c9e920d39536a82633d69b Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Tue, 2 Jan 2024 17:27:04 +0530 Subject: [PATCH 15/25] Update Config Product Price Logic --- .../PriceManager/ProductWithChildren.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Helper/Entity/Product/PriceManager/ProductWithChildren.php b/Helper/Entity/Product/PriceManager/ProductWithChildren.php index 18e555527..719d8e1da 100755 --- a/Helper/Entity/Product/PriceManager/ProductWithChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithChildren.php @@ -180,9 +180,9 @@ protected function setFinalGroupPrices($field, $currencyCode, $min, $max, $dashe $minArray = []; foreach ($groupPriceList as $key => $value) { $minArray[$key]['price'] = $value['min']; - $minArray[$key]['formatted'] = $this->getDashedPriceFormat($value['min'], $value['max'], $currencyCode); + $minArray[$key]['formatted'] = $this->formattedConfigPrice($value['min'], $value['max'], $currencyCode); if ($currencyCode !== $this->baseCurrencyCode) { - $minArray[$key]['formatted'] = $this->getDashedPriceFormat($value['min'], $value['max'], $currencyCode); + $minArray[$key]['formatted'] = $this->formattedConfigPrice($value['min'], $value['max'], $currencyCode); } } /** @var Group $group */ @@ -208,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 From 47622cc77b62446686b3b1f1597e1d14a8c9893e Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:49:40 +0530 Subject: [PATCH 16/25] Update deprecated registry for current product --- Observer/RegisterCurrentProductObserver.php | 44 ++++++++++++++ Registry/CurrentProduct.php | 66 +++++++++++++++++++++ ViewModel/Recommend/ProductView.php | 27 ++++++--- etc/frontend/events.xml | 3 + 4 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 Observer/RegisterCurrentProductObserver.php create mode 100644 Registry/CurrentProduct.php 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/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/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 @@ + + + From 155cf84d7be768afcdc958634ba1ef2afe2ec64b Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:13:10 +0530 Subject: [PATCH 17/25] MAGE-817 Updated deprecated registry code from backend --- Block/Adminhtml/Category/Merchandising.php | 14 +++++++------- .../LandingPage/SearchConfiguration.php | 14 +++++++------- Block/Adminhtml/Query/Merchandising.php | 14 +++++++------- Block/RecommendProductView.php | 16 +++++++--------- .../Adminhtml/Landingpage/AbstractAction.php | 15 ++++++++------- Controller/Adminhtml/Landingpage/Duplicate.php | 3 +-- Controller/Adminhtml/Landingpage/Save.php | 7 ++++--- Controller/Adminhtml/Query/AbstractAction.php | 14 +++++++------- Controller/Adminhtml/Query/Save.php | 7 ++++--- etc/adminhtml/events.xml | 4 +++- 10 files changed, 55 insertions(+), 53 deletions(-) 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/LandingPage/SearchConfiguration.php b/Block/Adminhtml/LandingPage/SearchConfiguration.php index edb1584c0..8a70eb710 100644 --- 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\Backend\Model\Session; class SearchConfiguration extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'landingpage/search-configuration.phtml'; - /** @var Registry */ - protected $registry; + /** @var Session */ + protected $backendSession; /** @var ConfigHelper */ private $configHelper; @@ -27,19 +27,19 @@ class SearchConfiguration extends \Magento\Backend\Block\Template /** * @param Context $context - * @param Registry $registry + * @param Session $backendSession * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - Registry $registry, + Session $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 index c4d378831..663a70e1f 100644 --- 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\Backend\Model\Session; class Merchandising extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'query/edit/merchandising.phtml'; - /** @var Registry */ - protected $registry; + /** @var Session */ + protected $backendSession; /** @var ConfigHelper */ private $configHelper; @@ -27,19 +27,19 @@ class Merchandising extends \Magento\Backend\Block\Template /** * @param Context $context - * @param Registry $registry + * @param Session $backendSession * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - Registry $registry, + Session $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/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/Controller/Adminhtml/Landingpage/AbstractAction.php b/Controller/Adminhtml/Landingpage/AbstractAction.php index 05d7c8559..359c3170d 100644 --- 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\Backend\Model\Session; use Magento\Store\Model\StoreManagerInterface; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + + /** @var Session */ + 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 Session $backendSession * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, - Registry $coreRegistry, + Session $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 index d22593352..b0879556e 100644 --- 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\Backend\Model\Session; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; @@ -32,7 +33,7 @@ class Save extends AbstractAction * PHP Constructor * * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry + * @param Session $backendSession * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager @@ -42,7 +43,7 @@ class Save extends AbstractAction */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, + Session $backendSession, LandingPageFactory $landingPageFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager, @@ -55,7 +56,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 index 1ccba4d82..5284997d6 100644 --- 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\Backend\Model\Session; use Magento\Store\Model\StoreManagerInterface; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + /** @var Session */ + 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 Session $backendSession * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, - Registry $coreRegistry, + Session $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 index fa3f61408..46f401585 100644 --- 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\Backend\Model\Session; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; @@ -32,7 +33,7 @@ class Save extends AbstractAction * PHP Constructor * * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\Registry $coreRegistry + * @param Session $backendSession * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager @@ -44,7 +45,7 @@ class Save extends AbstractAction */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\Registry $coreRegistry, + Session $backendSession, QueryFactory $queryFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager, @@ -58,7 +59,7 @@ public function __construct( parent::__construct( $context, - $coreRegistry, + $backendSession, $queryFactory, $merchandisingHelper, $storeManager 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 @@ - + + + From 835bb5e3142be539e9deee09307f3e54366d8bc9 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Mon, 15 Jan 2024 19:16:30 +0530 Subject: [PATCH 18/25] Update deprecated registry code --- Block/Adminhtml/Job/View.php | 20 +++++++++---------- Block/Adminhtml/QueueArchive/View.php | 20 +++++++++---------- Block/Algolia.php | 14 ++++++------- Controller/Adminhtml/Queue/AbstractAction.php | 14 ++++++------- .../Adminhtml/QueueArchive/AbstractAction.php | 14 ++++++------- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Block/Adminhtml/Job/View.php b/Block/Adminhtml/Job/View.php index a184b98b9..d23a72d82 100644 --- a/Block/Adminhtml/Job/View.php +++ b/Block/Adminhtml/Job/View.php @@ -3,28 +3,28 @@ namespace Algolia\AlgoliaSearch\Block\Adminhtml\Job; use Magento\Backend\Block\Widget\Button; -use Magento\Framework\Registry; +use Magento\Framework\Session\SessionManager; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class View extends Template { - /** @var \Magento\Framework\Registry */ - protected $coreRegistry; + /** @var SessionManager */ + protected $backendSession; /** - * @param Context $context - * @param Registry $coreRegistry - * @param array $data + * @param Context $context + * @param SessionManager $backendSession + * @param array $data */ public function __construct( - Context $context, - Registry $coreRegistry, + Context $context, + SessionManager $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\Job */ public function getCurrentJob() { - return $this->coreRegistry->registry('current_job'); + return $this->backendSession->getData('current_job'); } /** @return string */ diff --git a/Block/Adminhtml/QueueArchive/View.php b/Block/Adminhtml/QueueArchive/View.php index d52639b92..e0422d032 100644 --- 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\SessionManager; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class View extends Template { - /** @var Registry */ - protected $coreRegistry; + /** @var SessionManager */ + protected $backendSession; /** - * @param Context $context - * @param Registry $coreRegistry - * @param array $data + * @param Context $context + * @param SessionManager $backendSession + * @param array $data */ public function __construct( - Context $context, - Registry $coreRegistry, + Context $context, + SessionManager $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/Controller/Adminhtml/Queue/AbstractAction.php b/Controller/Adminhtml/Queue/AbstractAction.php index 3c39255e7..d91a2293e 100644 --- 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\SessionManager; use Magento\Indexer\Model\IndexerFactory; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + /** @var SessionManager */ + 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 SessionManager $backendSession * @param JobFactory $jobFactory * @param JobResourceModel $jobResourceModel * @param IndexerFactory $indexerFactory */ public function __construct( Context $context, - Registry $coreRegistry, + SessionManager $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 index 2c5eaf22d..589f342bc 100644 --- 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\SessionManager; use Magento\Indexer\Model\IndexerFactory; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Registry */ - protected $coreRegistry; + /** @var SessionManager */ + 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 SessionManager $backendSession * @param QueueArchiveFactory $queueArchiveFactory * @param QueueArchiveResourceModel $queueArchiveResourceModel * @param IndexerFactory $indexerFactory */ public function __construct( Context $context, - Registry $coreRegistry, + SessionManager $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; } From ffa34430e8819be356b6bd92d62f0f3cf408a5a2 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:31:05 +0530 Subject: [PATCH 19/25] MAGE-822 Removed polyfill script --- view/frontend/templates/internals/configuration.phtml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) mode change 100644 => 100755 view/frontend/templates/internals/configuration.phtml 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 + From 702073aa29794235b15455969621516d4b35bf43 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:03:36 +0530 Subject: [PATCH 20/25] Fixed merge conflicts --- Helper/Entity/ProductHelper.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index cae3cab64..c1a3b7c4b 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -469,9 +469,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic } // Managing Virtual Replica - if ($this->configHelper->useVirtualReplica($storeId)) { - $replicas = $this->handleVirtualReplica($replicas); - } + $replicas = $this->handleVirtualReplica($replicas); // Merge current replicas with sorting replicas to not delete A/B testing replica indices try { @@ -1599,4 +1597,4 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false) } return true; } -} \ No newline at end of file +} From 2827caf230d31042732f46b61ef3171aaa1ea372 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:09:35 +0530 Subject: [PATCH 21/25] Updated release code --- Helper/ConfigHelper.php | 14 +------------- Helper/Entity/ProductHelper.php | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php index 1caf0297b..30952b9d7 100755 --- a/Helper/ConfigHelper.php +++ b/Helper/ConfigHelper.php @@ -145,7 +145,6 @@ class ConfigHelper public const ENHANCED_QUEUE_ARCHIVE = 'algoliasearch_advanced/queue/enhanced_archive'; public const NUMBER_OF_ELEMENT_BY_PAGE = 'algoliasearch_advanced/queue/number_of_element_by_page'; public const ARCHIVE_LOG_CLEAR_LIMIT = 'algoliasearch_advanced/queue/archive_clear_limit'; - public const MAX_VIRTUAL_REPLICA_COUNT = 50; /** * @var Magento\Framework\App\Config\ScopeConfigInterface @@ -1021,14 +1020,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC $currency = $this->getCurrencyCode($storeId); $attributesToAdd = []; - $defaultVirtualReplicaEnabled = $this->useVirtualReplica($storeId); - $virtualReplicaCount = 0; foreach ($attrs as $key => $attr) { - if ($virtualReplicaCount < self::MAX_VIRTUAL_REPLICA_COUNT && ($defaultVirtualReplicaEnabled || (isset($attr['virtualReplica']) && $attr['virtualReplica']))){ - $virtualReplica = 1; - } else { - $virtualReplica = 0; - } $indexName = false; $sortAttribute = false; if ($this->isCustomerGroupsEnabled($storeId) && $attr['attribute'] === 'price') { @@ -1052,7 +1044,6 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC $newAttr['attribute'] = $attr['attribute']; $newAttr['sort'] = $attr['sort']; $newAttr['sortLabel'] = $attr['sortLabel']; - $newAttr['virtualReplica'] = $virtualReplica; if (!array_key_exists('label', $newAttr) && array_key_exists('sortLabel', $newAttr)) { $newAttr['label'] = $newAttr['sortLabel']; } @@ -1068,7 +1059,6 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC 'custom', ]; $attributesToAdd[$newAttr['sort']][] = $newAttr; - $virtualReplicaCount++; } } elseif ($attr['attribute'] === 'price') { $indexName = $originalIndexName . '_' . $attr['attribute'] . '_' . 'default' . '_' . $attr['sort']; @@ -1078,8 +1068,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC $sortAttribute = $attr['attribute']; } if ($indexName && $sortAttribute) { - $attrs[$key]['name'] = $indexName; - $attrs[$key]['virtualReplica'] = $virtualReplica; + $attrs[$key]['name'] = $indexName; if (!array_key_exists('label', $attrs[$key]) && array_key_exists('sortLabel', $attrs[$key])) { $attrs[$key]['label'] = $attrs[$key]['sortLabel']; } @@ -1094,7 +1083,6 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC 'exact', 'custom', ]; - $virtualReplicaCount++; } } $attrsToReturn = []; diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index c1a3b7c4b..ac39fc48e 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -464,7 +464,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic if ($this->configHelper->isInstantEnabled($storeId)) { $replicas = array_values(array_map(function ($sortingIndex) { - return [$sortingIndex['name'],$sortingIndex['virtualReplica']]; + return $sortingIndex['name']; }, $sortingIndices)); } @@ -488,23 +488,24 @@ 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(); - foreach ($sortingIndices as $values) { - if ($values['virtualReplica']) { + if (!$this->configHelper->useVirtualReplica($storeId)) { + foreach ($sortingIndices as $values) { + $replicaName = $values['name']; + $indexSettings['ranking'] = $values['ranking']; + $this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true); + $this->logger->log('Setting settings to "' . $replicaName . '" replica.'); + $this->logger->log('Settings: ' . json_encode($indexSettings)); + } + } else { + foreach ($sortingIndices as $values) { $replicaName = $values['name']; array_unshift($customRanking, $values['ranking'][0]); $replicaSetting['customRanking'] = $customRanking; $this->algoliaHelper->setSettings($replicaName, $replicaSetting, false, false); $this->logger->log('Setting settings to "' . $replicaName . '" replica.'); $this->logger->log('Settings: ' . json_encode($replicaSetting)); - } else { - $replicaName = $values['name']; - $indexSettings['ranking'] = $values['ranking']; - $this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true); - $this->logger->log('Setting settings to "' . $replicaName . '" replica.'); - $this->logger->log('Settings: ' . json_encode($indexSettings)); } } - } else { $this->algoliaHelper->setSettings($indexName, ['replicas' => []]); $this->logger->log('Removing replicas from "' . $indexName . '" index'); @@ -1546,13 +1547,9 @@ public function handleVirtualReplica($replicas) { $virtualReplicaArray = []; foreach ($replicas as $replica) { - if ($replica[1]) { - $replicaArray[] = 'virtual(' . $replica[0] . ')'; - } else { - $replicaArray[] = $replica[0]; - } + $virtualReplicaArray[] = 'virtual(' . $replica . ')'; } - return $replicaArray; + return $virtualReplicaArray; } /** @@ -1567,7 +1564,7 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false) $sortingIndices = $this->configHelper->getSortingIndices($indexName, $storeId, null, $sortingAttribute); if ($this->configHelper->isInstantEnabled($storeId)) { $replicas = array_values(array_map(function ($sortingIndex) { - return [$sortingIndex['name'],$sortingIndex['virtualReplica']]; + return $sortingIndex['name']; }, $sortingIndices)); try { From c805426259b6e1021a0439dbdb17fdb432fc8b0e Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:12:57 +0530 Subject: [PATCH 22/25] Update Sorts --- Model/Source/Sorts.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Model/Source/Sorts.php b/Model/Source/Sorts.php index e2b4aa38a..1994c3eeb 100755 --- a/Model/Source/Sorts.php +++ b/Model/Source/Sorts.php @@ -33,10 +33,6 @@ protected function getTableData() 'sortLabel' => [ 'label' => 'Label', ], - 'virtualReplica' => [ - 'label' => 'Enable Virtual Replica?', - 'values' => ['0' => __('No'), '1' => __('Yes')], - ], ]; } } From fe1d945c3954bfbc62c29b489c717100096d1c87 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:03:49 +0530 Subject: [PATCH 23/25] Update Code for Replica Update --- Helper/Entity/ProductHelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index ac39fc48e..8e13fac0b 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -469,7 +469,9 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic } // Managing Virtual Replica - $replicas = $this->handleVirtualReplica($replicas); + if ($this->configHelper->useVirtualReplica($storeId)) { + $replicas = $this->handleVirtualReplica($replicas); + } // Merge current replicas with sorting replicas to not delete A/B testing replica indices try { From 378497768d98699e0aac7730b1c8a93ca754e9da Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Mon, 19 Feb 2024 19:39:42 +0530 Subject: [PATCH 24/25] Updated code and add logger --- Block/Adminhtml/Job/View.php | 9 ++++----- .../LandingPage/SearchConfiguration.php | 8 ++++---- Block/Adminhtml/Query/Merchandising.php | 8 ++++---- Block/Adminhtml/QueueArchive/View.php | 8 ++++---- .../Adminhtml/Landingpage/AbstractAction.php | 8 ++++---- Controller/Adminhtml/Landingpage/Save.php | 11 +++++++--- Controller/Adminhtml/Query/AbstractAction.php | 8 ++++---- Controller/Adminhtml/Query/Save.php | 11 +++++++--- Controller/Adminhtml/Queue/AbstractAction.php | 8 ++++---- .../Adminhtml/QueueArchive/AbstractAction.php | 8 ++++---- Helper/ConfigHelper.php | 5 +++-- .../Product/PriceManager/Configurable.php | 2 ++ .../PriceManager/ProductWithoutChildren.php | 20 ++++++++++++++----- Helper/Entity/ProductHelper.php | 11 +++++----- 14 files changed, 74 insertions(+), 51 deletions(-) mode change 100644 => 100755 Block/Adminhtml/Job/View.php mode change 100644 => 100755 Block/Adminhtml/LandingPage/SearchConfiguration.php mode change 100644 => 100755 Block/Adminhtml/Query/Merchandising.php mode change 100644 => 100755 Block/Adminhtml/QueueArchive/View.php mode change 100644 => 100755 Controller/Adminhtml/Landingpage/AbstractAction.php mode change 100644 => 100755 Controller/Adminhtml/Landingpage/Save.php mode change 100644 => 100755 Controller/Adminhtml/Query/AbstractAction.php mode change 100644 => 100755 Controller/Adminhtml/Query/Save.php mode change 100644 => 100755 Controller/Adminhtml/Queue/AbstractAction.php mode change 100644 => 100755 Controller/Adminhtml/QueueArchive/AbstractAction.php mode change 100644 => 100755 Helper/Entity/Product/PriceManager/Configurable.php mode change 100644 => 100755 Helper/Entity/Product/PriceManager/ProductWithoutChildren.php diff --git a/Block/Adminhtml/Job/View.php b/Block/Adminhtml/Job/View.php old mode 100644 new mode 100755 index d23a72d82..3459cd31e --- a/Block/Adminhtml/Job/View.php +++ b/Block/Adminhtml/Job/View.php @@ -3,27 +3,26 @@ namespace Algolia\AlgoliaSearch\Block\Adminhtml\Job; use Magento\Backend\Block\Widget\Button; -use Magento\Framework\Session\SessionManager; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class View extends Template { - /** @var SessionManager */ + /** @var SessionManagerInterface */ protected $backendSession; /** * @param Context $context - * @param SessionManager $backendSession + * @param SessionManagerInterface $backendSession * @param array $data */ public function __construct( Context $context, - SessionManager $backendSession, + SessionManagerInterface $backendSession, array $data = [] ) { parent::__construct($context, $data); - $this->backendSession = $backendSession; } diff --git a/Block/Adminhtml/LandingPage/SearchConfiguration.php b/Block/Adminhtml/LandingPage/SearchConfiguration.php old mode 100644 new mode 100755 index 8a70eb710..0cbeb6638 --- a/Block/Adminhtml/LandingPage/SearchConfiguration.php +++ b/Block/Adminhtml/LandingPage/SearchConfiguration.php @@ -6,14 +6,14 @@ use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\LandingPage; use Magento\Backend\Block\Template\Context; -use Magento\Backend\Model\Session; +use Magento\Framework\Session\SessionManagerInterface; class SearchConfiguration extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'landingpage/search-configuration.phtml'; - /** @var Session */ + /** @var SessionManagerInterface */ protected $backendSession; /** @var ConfigHelper */ @@ -27,14 +27,14 @@ class SearchConfiguration extends \Magento\Backend\Block\Template /** * @param Context $context - * @param Session $backendSession + * @param SessionManagerInterface $backendSession * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - Session $backendSession, + SessionManagerInterface $backendSession, ConfigHelper $configHelper, Data $coreHelper, array $data = [] diff --git a/Block/Adminhtml/Query/Merchandising.php b/Block/Adminhtml/Query/Merchandising.php old mode 100644 new mode 100755 index 663a70e1f..6face4425 --- a/Block/Adminhtml/Query/Merchandising.php +++ b/Block/Adminhtml/Query/Merchandising.php @@ -6,14 +6,14 @@ use Algolia\AlgoliaSearch\Helper\Data; use Algolia\AlgoliaSearch\Model\Query; use Magento\Backend\Block\Template\Context; -use Magento\Backend\Model\Session; +use Magento\Framework\Session\SessionManagerInterface; class Merchandising extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'query/edit/merchandising.phtml'; - /** @var Session */ + /** @var SessionManagerInterface */ protected $backendSession; /** @var ConfigHelper */ @@ -27,14 +27,14 @@ class Merchandising extends \Magento\Backend\Block\Template /** * @param Context $context - * @param Session $backendSession + * @param SessionManagerInterface $backendSession * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - Session $backendSession, + SessionManagerInterface $backendSession, ConfigHelper $configHelper, Data $coreHelper, array $data = [] diff --git a/Block/Adminhtml/QueueArchive/View.php b/Block/Adminhtml/QueueArchive/View.php old mode 100644 new mode 100755 index e0422d032..5e72f5d5e --- a/Block/Adminhtml/QueueArchive/View.php +++ b/Block/Adminhtml/QueueArchive/View.php @@ -3,23 +3,23 @@ namespace Algolia\AlgoliaSearch\Block\Adminhtml\QueueArchive; use Magento\Backend\Block\Widget\Button; -use Magento\Framework\Session\SessionManager; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class View extends Template { - /** @var SessionManager */ + /** @var SessionManagerInterface */ protected $backendSession; /** * @param Context $context - * @param SessionManager $backendSession + * @param SessionManagerInterface $backendSession * @param array $data */ public function __construct( Context $context, - SessionManager $backendSession, + SessionManagerInterface $backendSession, array $data = [] ) { parent::__construct($context, $data); diff --git a/Controller/Adminhtml/Landingpage/AbstractAction.php b/Controller/Adminhtml/Landingpage/AbstractAction.php old mode 100644 new mode 100755 index 359c3170d..0f61ed550 --- a/Controller/Adminhtml/Landingpage/AbstractAction.php +++ b/Controller/Adminhtml/Landingpage/AbstractAction.php @@ -5,13 +5,13 @@ use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\LandingPageFactory; use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\Session; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Store\Model\StoreManagerInterface; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Session */ + /** @var SessionManagerInterface */ protected $backendSession; /** @var LandingPageFactory */ @@ -25,14 +25,14 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param Session $backendSession + * @param SessionManagerInterface $backendSession * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, - Session $backendSession, + SessionManagerInterface $backendSession, LandingPageFactory $landingPageFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager diff --git a/Controller/Adminhtml/Landingpage/Save.php b/Controller/Adminhtml/Landingpage/Save.php old mode 100644 new mode 100755 index b0879556e..e1e2b7a68 --- a/Controller/Adminhtml/Landingpage/Save.php +++ b/Controller/Adminhtml/Landingpage/Save.php @@ -5,7 +5,7 @@ use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\LandingPageFactory; -use Magento\Backend\Model\Session; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; @@ -29,11 +29,16 @@ class Save extends AbstractAction */ protected $configHelper; + /** + * @var SessionManagerInterface + */ + protected $backendSession; + /** * PHP Constructor * * @param \Magento\Backend\App\Action\Context $context - * @param Session $backendSession + * @param SessionManagerInterface $backendSession * @param LandingPageFactory $landingPageFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager @@ -43,7 +48,7 @@ class Save extends AbstractAction */ public function __construct( \Magento\Backend\App\Action\Context $context, - Session $backendSession, + SessionManagerInterface $backendSession, LandingPageFactory $landingPageFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager, diff --git a/Controller/Adminhtml/Query/AbstractAction.php b/Controller/Adminhtml/Query/AbstractAction.php old mode 100644 new mode 100755 index 5284997d6..78d616b44 --- a/Controller/Adminhtml/Query/AbstractAction.php +++ b/Controller/Adminhtml/Query/AbstractAction.php @@ -5,12 +5,12 @@ use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\QueryFactory; use Magento\Backend\App\Action\Context; -use Magento\Backend\Model\Session; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Store\Model\StoreManagerInterface; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var Session */ + /** @var SessionManagerInterface */ protected $backendSession; /** @var QueryFactory */ @@ -24,14 +24,14 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param Session $backendSession + * @param SessionManagerInterface $backendSession * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, - Session $backendSession, + SessionManagerInterface $backendSession, QueryFactory $queryFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager diff --git a/Controller/Adminhtml/Query/Save.php b/Controller/Adminhtml/Query/Save.php old mode 100644 new mode 100755 index 46f401585..e6db407b8 --- a/Controller/Adminhtml/Query/Save.php +++ b/Controller/Adminhtml/Query/Save.php @@ -6,7 +6,7 @@ use Algolia\AlgoliaSearch\Helper\MerchandisingHelper; use Algolia\AlgoliaSearch\Model\ImageUploader; use Algolia\AlgoliaSearch\Model\QueryFactory; -use Magento\Backend\Model\Session; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\LocalizedException; @@ -29,11 +29,16 @@ class Save extends AbstractAction */ protected $imageUploader; + /** + * @var SessionManagerInterface + */ + protected $backendSession; + /** * PHP Constructor * * @param \Magento\Backend\App\Action\Context $context - * @param Session $backendSession + * @param SessionManagerInterface $backendSession * @param QueryFactory $queryFactory * @param MerchandisingHelper $merchandisingHelper * @param StoreManagerInterface $storeManager @@ -45,7 +50,7 @@ class Save extends AbstractAction */ public function __construct( \Magento\Backend\App\Action\Context $context, - Session $backendSession, + SessionManagerInterface $backendSession, QueryFactory $queryFactory, MerchandisingHelper $merchandisingHelper, StoreManagerInterface $storeManager, diff --git a/Controller/Adminhtml/Queue/AbstractAction.php b/Controller/Adminhtml/Queue/AbstractAction.php old mode 100644 new mode 100755 index d91a2293e..672ca12e3 --- a/Controller/Adminhtml/Queue/AbstractAction.php +++ b/Controller/Adminhtml/Queue/AbstractAction.php @@ -5,12 +5,12 @@ use Algolia\AlgoliaSearch\Model\JobFactory; use Algolia\AlgoliaSearch\Model\ResourceModel\Job as JobResourceModel; use Magento\Backend\App\Action\Context; -use Magento\Framework\Session\SessionManager; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Indexer\Model\IndexerFactory; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var SessionManager */ + /** @var SessionManagerInterface */ protected $backendSession; /** @var \Algolia\AlgoliaSearch\Model\JobFactory */ @@ -24,14 +24,14 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param SessionManager $backendSession + * @param SessionManagerInterface $backendSession * @param JobFactory $jobFactory * @param JobResourceModel $jobResourceModel * @param IndexerFactory $indexerFactory */ public function __construct( Context $context, - SessionManager $backendSession, + SessionManagerInterface $backendSession, JobFactory $jobFactory, JobResourceModel $jobResourceModel, IndexerFactory $indexerFactory diff --git a/Controller/Adminhtml/QueueArchive/AbstractAction.php b/Controller/Adminhtml/QueueArchive/AbstractAction.php old mode 100644 new mode 100755 index 589f342bc..377223bb4 --- a/Controller/Adminhtml/QueueArchive/AbstractAction.php +++ b/Controller/Adminhtml/QueueArchive/AbstractAction.php @@ -5,12 +5,12 @@ use Algolia\AlgoliaSearch\Model\QueueArchiveFactory; use Algolia\AlgoliaSearch\Model\ResourceModel\QueueArchive as QueueArchiveResourceModel; use Magento\Backend\App\Action\Context; -use Magento\Framework\Session\SessionManager; +use Magento\Framework\Session\SessionManagerInterface; use Magento\Indexer\Model\IndexerFactory; abstract class AbstractAction extends \Magento\Backend\App\Action { - /** @var SessionManager */ + /** @var SessionManagerInterface */ protected $backendSession; /** @var \Algolia\AlgoliaSearch\Model\QueueArchiveFactory */ @@ -24,14 +24,14 @@ abstract class AbstractAction extends \Magento\Backend\App\Action /** * @param Context $context - * @param SessionManager $backendSession + * @param SessionManagerInterface $backendSession * @param QueueArchiveFactory $queueArchiveFactory * @param QueueArchiveResourceModel $queueArchiveResourceModel * @param IndexerFactory $indexerFactory */ public function __construct( Context $context, - SessionManager $backendSession, + SessionManagerInterface $backendSession, QueueArchiveFactory $queueArchiveFactory, QueueArchiveResourceModel $queueArchiveResourceModel, IndexerFactory $indexerFactory diff --git a/Helper/ConfigHelper.php b/Helper/ConfigHelper.php index 30952b9d7..7f1039512 100755 --- a/Helper/ConfigHelper.php +++ b/Helper/ConfigHelper.php @@ -200,7 +200,7 @@ class ConfigHelper * @var GroupExcludedWebsiteRepositoryInterface */ protected $groupExcludedWebsiteRepository; - + /** * @var CookieHelper */ @@ -1010,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) @@ -1068,7 +1069,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC $sortAttribute = $attr['attribute']; } if ($indexName && $sortAttribute) { - $attrs[$key]['name'] = $indexName; + $attrs[$key]['name'] = $indexName; if (!array_key_exists('label', $attrs[$key]) && array_key_exists('sortLabel', $attrs[$key])) { $attrs[$key]['label'] = $attrs[$key]['sortLabel']; } diff --git a/Helper/Entity/Product/PriceManager/Configurable.php b/Helper/Entity/Product/PriceManager/Configurable.php old mode 100644 new mode 100755 index 49f93bfe1..a55671c5a --- a/Helper/Entity/Product/PriceManager/Configurable.php +++ b/Helper/Entity/Product/PriceManager/Configurable.php @@ -16,7 +16,9 @@ protected function getRulePrice($groupId, $product, $subProducts) { $childrenPrices = []; $typeInstance = $product->getTypeInstance(); + 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); } diff --git a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php old mode 100644 new mode 100755 index f0d656f57..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; @@ -52,12 +53,17 @@ abstract class ProductWithoutChildren * @var GroupExcludedWebsiteRepositoryInterface */ protected $groupExcludedWebsiteRepository; - + /** * @var ScopedProductTierPriceManagementInterface */ private $productTierPrice; + /** + * @var Logger + */ + protected $logger; + protected $store; protected $baseCurrencyCode; protected $groups; @@ -67,13 +73,14 @@ abstract class ProductWithoutChildren /** * @param ConfigHelper $configHelper * @param CollectionFactory $customerGroupCollectionFactory - * @param GroupExcludedWebsiteRepositoryInterface groupExcludedWebsiteRepository + * @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, @@ -84,7 +91,8 @@ public function __construct( TaxHelper $taxHelper, Rule $rule, ProductFactory $productloader, - ScopedProductTierPriceManagementInterface $productTierPrice + ScopedProductTierPriceManagementInterface $productTierPrice, + Logger $logger, ) { $this->configHelper = $configHelper; $this->customerGroupCollectionFactory = $customerGroupCollectionFactory; @@ -95,6 +103,7 @@ public function __construct( $this->rule = $rule; $this->productloader = $productloader; $this->productTierPrice = $productTierPrice; + $this->logger = $logger; } /** @@ -102,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 { @@ -262,7 +272,7 @@ protected function getSpecialPrice(Product $product, $currencyCode, $withTax, $s } return $specialPrice; } - + /** * @param Product $product * @param $currencyCode @@ -370,7 +380,7 @@ protected function addTierPrices($tierPrice, $field, $currencyCode) $this->formatPrice($tierPrice[0], $currencyCode); } } - + # TODO bookmarking getRulePrice function for a future refactor effort. /** * @param $groupId * @param $product diff --git a/Helper/Entity/ProductHelper.php b/Helper/Entity/ProductHelper.php index 8e13fac0b..be91da093 100755 --- a/Helper/Entity/ProductHelper.php +++ b/Helper/Entity/ProductHelper.php @@ -471,7 +471,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic // Managing Virtual Replica if ($this->configHelper->useVirtualReplica($storeId)) { $replicas = $this->handleVirtualReplica($replicas); - } + } // Merge current replicas with sorting replicas to not delete A/B testing replica indices try { @@ -1062,7 +1062,7 @@ protected function addAdditionalAttributes($customData, $additionalAttributes, P } $attributeResource = $attributeResource->setData('store_id', $product->getStoreId()); - + $value = $product->getData($attributeName); if ($value !== null) { @@ -1308,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) { @@ -1316,21 +1318,20 @@ 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) { $facet['attribute'] = 'price.' . $currency_code . '.default'; if ($this->configHelper->isCustomerGroupsEnabled($storeId)) { - $websiteId = (int)$this->storeManager->getStore($storeId)->getWebsiteId(); foreach ($this->groupCollection as $group) { - $group_id = (int) $group->getData('customer_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_' . $group_id; + $attributesForFaceting[] = 'price.' . $currency_code . '.group_' . $groupId; } } From bbe8fd6dcf7fc0a404df00ef26a0fe5662259aa5 Mon Sep 17 00:00:00 2001 From: mohitalgolia <101385480+mohitalgolia@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:39:17 +0530 Subject: [PATCH 25/25] Updated changelog for release 3.13.2 --- CHANGELOG.md | 13 +++++++++++++ README.md | 2 +- composer.json | 2 +- etc/module.xml | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) 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/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/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/module.xml b/etc/module.xml index 2da64af9f..78806a7f3 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - +