Skip to content

Commit

Permalink
Merge master back to beta branch (#165)
Browse files Browse the repository at this point in the history
* Prevent duplicate slug values (#159)

Prevent duplicate slug values

* Fix notice missing variables (#157)

* Bump version

* chore: Added semantic release (#158)

* chore: Added semantic release

* chore: Added develop branch to semantic release

* chore: Set beta branch as prerelease branch

* chore: Only trigger release workflow for master and beta branch (#160)

* chore: Updated README for semantic release

---------

Co-authored-by: Tjeu Jansen <[email protected]>
Co-authored-by: tjeujansen <[email protected]>
  • Loading branch information
3 people authored Mar 15, 2024
1 parent 5720a7f commit 32a83f5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Api/Data/AttributeSlugInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions Block/Checkout/Cart/Crosssell/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -277,6 +278,8 @@ private function getFeaturedItems()
$collection = $this->removeCartItems($collection, $cartItems);
}

$items = [];

foreach ($collection as $item) {
$items[] = $item;
}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion Model/AttributeSlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
46 changes: 44 additions & 2 deletions Model/AttributeSlugRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<section id="tweakwise">
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<comment>Tweakwise version v5.8.2</comment>
<comment>Tweakwise version v5.8.3</comment>
<field id="authentication_key" translate="label,comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Authentication key</label>
<comment>Provided by Tweakwise (8 alphanumeric characters)</comment>
Expand Down

0 comments on commit 32a83f5

Please sign in to comment.