diff --git a/Api/Data/AttributeSlugInterface.php b/Api/Data/AttributeSlugInterface.php index 18f6906b..d3fe2034 100644 --- a/Api/Data/AttributeSlugInterface.php +++ b/Api/Data/AttributeSlugInterface.php @@ -16,4 +16,10 @@ public function getAttribute(): ?string; * @return string */ public function getSlug(): string; + + /** + * @param string $slug + * @return void + */ + public function setSlug(string $slug): void; } diff --git a/Block/Checkout/Cart/Crosssell/Plugin.php b/Block/Checkout/Cart/Crosssell/Plugin.php index 45089336..f01e7cae 100644 --- a/Block/Checkout/Cart/Crosssell/Plugin.php +++ b/Block/Checkout/Cart/Crosssell/Plugin.php @@ -248,6 +248,7 @@ public function getQuote() */ protected function _getCartProducts() { + $products = []; foreach ($this->getQuote()->getAllItems() as $quoteItem) { /* @var $quoteItem \Magento\Quote\Model\Quote\Item */ $product = $quoteItem->getProduct(); @@ -277,6 +278,8 @@ private function getFeaturedItems() $collection = $this->removeCartItems($collection, $cartItems); } + $items = []; + foreach ($collection as $item) { $items[] = $item; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b5aa7ca..e7499e36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -188,3 +188,7 @@ We've added a setting in which you can define whether to use the old/existing wa - Implemented a preventive measure to avoid errors when no attribute values are present for ALP facet requests. - Resolved the issue with personal merchandising and pagination not functioning correctly when utilising the filter form. - Implemented measures to prevent a 500 error in the search when Tweakwise is inaccessible or down. + +## 5.8.3 +- Implemented prevention of duplicate attribute slug values. Previously, attribute values with variations in their representations, such as Black and Black", resulted in duplicate entries in the tweakwise_attribute_slug table. This duplication could disrupt filter functionality if the incorrect value was retrieved. This pull request addresses the issue by appending a unique identifier ("-") followed by a number to each slug, ensuring their uniqueness. Note that attributes with previously duplicated slug values will require re-saving to activate this fix. +- Resolved a notice issue pertaining to missing variables when the shopping cart is empty. Previously, certain sections of the application would trigger notices due to uninitialized variables when the cart was empty. diff --git a/Model/AttributeSlug.php b/Model/AttributeSlug.php index cc4a448f..a0c7570b 100644 --- a/Model/AttributeSlug.php +++ b/Model/AttributeSlug.php @@ -53,8 +53,9 @@ public function getSlug(): string /** * @param string $slug + * @return void */ - public function setSlug(string $slug) + public function setSlug(string $slug): void { $this->setData(self::SLUG, $slug); } diff --git a/Model/AttributeSlugRepository.php b/Model/AttributeSlugRepository.php index 811979fb..ede372fd 100644 --- a/Model/AttributeSlugRepository.php +++ b/Model/AttributeSlugRepository.php @@ -76,8 +76,31 @@ public function __construct( public function save(AttributeSlugInterface $attributeSlug): AttributeSlugInterface { try { - /** @var AttributeSlug $attributeSlug */ - $this->resource->save($attributeSlug); + //check for existing slugs with the same slug + try { + /** @var AttributeSlug $existingSlug */ + $existingSlug = $this->findBySlug($attributeSlug->getSlug()); + + //slug exists, check if it is not the current attribute saved + if ($attributeSlug->getAttribute() !== $existingSlug->getAttribute()) { + $newSlug = $attributeSlug->getSlug(); + $counter = 0; + while ($newSlug === $this->findBySlug($newSlug)->getSlug()) { + $counter++; + $newSlug = sprintf('%s-%s', $attributeSlug->getSlug(), $counter); + } + } + /** @var AttributeSlug $attributeSlug */ + $this->resource->save($attributeSlug); + + } catch (NoSuchEntityException $exception) { + //slug doesnt exist. Save value + if (isset($newSlug)) { + $attributeSlug->setSlug($newSlug); + } + /** @var AttributeSlug $attributeSlug */ + $this->resource->save($attributeSlug); + } } catch (\Exception $exception) { throw new CouldNotSaveException(__( 'Could not save the page: %1', @@ -136,4 +159,23 @@ public function findByAttribute(string $attribute): AttributeSlugInterface } return $attributeSlug; } + + + /** + * @param string $slug + * @return AttributeSlugInterface + * @throws NoSuchEntityException + */ + public function findBySlug(string $slug): AttributeSlugInterface + { + $collection = $this->collectionFactory->create() + ->addFieldToFilter('slug', $slug); + if (!$collection->getSize()) { + throw new NoSuchEntityException(__('No slug found for attribute "%1".', $slug)); + } + + /** @var AttributeSlug $attributeSlug */ + $attributeSlug = $collection->getFirstItem(); + return $attributeSlug; + } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 927beec7..c75af958 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -12,7 +12,7 @@
- Tweakwise version v5.8.2 + Tweakwise version v5.8.3 Provided by Tweakwise (8 alphanumeric characters)