Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #28011 - remove page number from query on layered navigation swatch filter #28015

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AssertStorefrontCategoryCurrentPageIsNthActionGroup">
<arguments>
<argument name="expectedPage" type="string"/>
</arguments>

<grabTextFrom selector="{{StorefrontCategoryBottomToolbarSection.currentPage}}" stepKey="currentPageText"/>
<assertEquals stepKey="assertIsPageNth">
<expectedResult type="string">{{expectedPage}}</expectedResult>
<actualResult type="variable">currentPageText</actualResult>
</assertEquals>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StorefrontNavigateCategoryNextPageActionGroup">
<annotations>
<description>Navigates storefront category next page from toolbar</description>
</annotations>
<scrollTo selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="scrollToNextButton"/>
<click selector="{{StorefrontCategoryBottomToolbarSection.nextPage}}" stepKey="clickOnNextPage"/>
<waitForPageLoad stepKey="waitForNextCategoryPageLoad"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<element name="previousPage" type="button" selector=".//*[@class='toolbar toolbar-products'][2]//a[contains(@class, 'previous')]" timeout="30"/>
<element name="pageNumber" type="text" selector="//*[@class='toolbar toolbar-products'][2]//a[contains(@class, 'page')]//span[2][contains(text() ,'{{var1}}')]" parameterized="true"/>
<element name="perPage" type="select" selector="//*[@class='toolbar toolbar-products'][2]//select[@id='limiter']"/>
<element name="currentPage" type="text" selector=".products.wrapper + .toolbar-products .pages .current span:nth-of-type(2)"/>
<element name="currentPage" type="text" selector=".//*[@class='toolbar toolbar-products'][2]//li[contains(@class, 'current')]//span[2]" timeout="30"/>
ihor-sviziev marked this conversation as resolved.
Show resolved Hide resolved
</section>
</sections>
97 changes: 75 additions & 22 deletions app/code/Magento/Swatches/Block/LayeredNavigation/RenderLayered.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
*/
namespace Magento\Swatches\Block\LayeredNavigation;

use Magento\Eav\Model\Entity\Attribute;
use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
use Magento\Catalog\Model\Layer\Filter\Item as FilterItem;
use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory;
use Magento\Framework\View\Element\Template;
use Magento\Eav\Model\Entity\Attribute;
use Magento\Eav\Model\Entity\Attribute\Option;
use Magento\Catalog\Model\Layer\Filter\Item as FilterItem;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Swatches\Helper\Data;
use Magento\Swatches\Helper\Media;
use Magento\Theme\Block\Html\Pager;

/**
* Class RenderLayered Render Swatches at Layered Navigation
Expand Down Expand Up @@ -37,7 +43,7 @@ class RenderLayered extends Template
protected $eavAttribute;

/**
* @var \Magento\Catalog\Model\Layer\Filter\AbstractFilter
* @var AbstractFilter
*/
protected $filter;

Expand All @@ -47,41 +53,52 @@ class RenderLayered extends Template
protected $layerAttribute;

/**
* @var \Magento\Swatches\Helper\Data
* @var Data
*/
protected $swatchHelper;

/**
* @var \Magento\Swatches\Helper\Media
* @var Media
*/
protected $mediaHelper;

/**
* @param Template\Context $context
* @var Pager
*/
private $htmlPagerBlock;

/**
* @param Context $context
* @param Attribute $eavAttribute
* @param AttributeFactory $layerAttribute
* @param \Magento\Swatches\Helper\Data $swatchHelper
* @param \Magento\Swatches\Helper\Media $mediaHelper
* @param Data $swatchHelper
* @param Media $mediaHelper
* @param array $data
* @param Pager|null $htmlPagerBlock
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
Context $context,
Attribute $eavAttribute,
AttributeFactory $layerAttribute,
\Magento\Swatches\Helper\Data $swatchHelper,
\Magento\Swatches\Helper\Media $mediaHelper,
array $data = []
Data $swatchHelper,
Media $mediaHelper,
array $data = [],
?Pager $htmlPagerBlock = null
) {
$this->eavAttribute = $eavAttribute;
$this->layerAttribute = $layerAttribute;
$this->swatchHelper = $swatchHelper;
$this->mediaHelper = $mediaHelper;
$this->htmlPagerBlock = $htmlPagerBlock ?? ObjectManager::getInstance()->get(Pager::class);

parent::__construct($context, $data);
}

/**
* Set filter and attribute objects
*
* @param \Magento\Catalog\Model\Layer\Filter\AbstractFilter $filter
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
Expand All @@ -94,6 +111,8 @@ public function setSwatchFilter(\Magento\Catalog\Model\Layer\Filter\AbstractFilt
}

/**
* Get attribute swatch data
*
* @return array
*/
public function getSwatchData()
Expand All @@ -114,30 +133,46 @@ public function getSwatchData()
$attributeOptionIds = array_keys($attributeOptions);
$swatches = $this->swatchHelper->getSwatchesByOptionsId($attributeOptionIds);

$data = [
return [
'attribute_id' => $this->eavAttribute->getId(),
'attribute_code' => $this->eavAttribute->getAttributeCode(),
'attribute_label' => $this->eavAttribute->getStoreLabel(),
'options' => $attributeOptions,
'swatches' => $swatches,
];

return $data;
}

/**
* Build filter option url
*
* @param string $attributeCode
* @param int $optionId
*
* @return string
*/
public function buildUrl($attributeCode, $optionId)
{
$query = [$attributeCode => $optionId];
return $this->_urlBuilder->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
$query = [
$attributeCode => $optionId,
// exclude current page from urls
$this->htmlPagerBlock->getPageVarName() => null
];

return $this->_urlBuilder->getUrl(
'*/*/*',
[
'_current' => true,
'_use_rewrite' => true,
'_query' => $query
]
);
}

/**
* Get view data for option with no results
*
* @param Option $swatchOption
*
* @return array
*/
protected function getUnusedOption(Option $swatchOption)
Expand All @@ -150,8 +185,11 @@ protected function getUnusedOption(Option $swatchOption)
}

/**
* Get option data if visible
*
* @param FilterItem[] $filterItems
* @param Option $swatchOption
*
* @return array
*/
protected function getFilterOption(array $filterItems, Option $swatchOption)
Expand All @@ -166,8 +204,11 @@ protected function getFilterOption(array $filterItems, Option $swatchOption)
}

/**
* Get view data for option
*
* @param FilterItem $filterItem
* @param Option $swatchOption
*
* @return array
*/
protected function getOptionViewData(FilterItem $filterItem, Option $swatchOption)
Expand All @@ -187,15 +228,20 @@ protected function getOptionViewData(FilterItem $filterItem, Option $swatchOptio
}

/**
* Check if option should be visible
*
* @param FilterItem $filterItem
*
* @return bool
*/
protected function isOptionVisible(FilterItem $filterItem)
{
return $this->isOptionDisabled($filterItem) && $this->isShowEmptyResults() ? false : true;
return !($this->isOptionDisabled($filterItem) && $this->isShowEmptyResults());
ihor-sviziev marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Check if attribute values should be visible with no results
*
* @return bool
*/
protected function isShowEmptyResults()
Expand All @@ -204,7 +250,10 @@ protected function isShowEmptyResults()
}

/**
* Check if option should be disabled
*
* @param FilterItem $filterItem
*
* @return bool
*/
protected function isOptionDisabled(FilterItem $filterItem)
Expand All @@ -213,8 +262,11 @@ protected function isOptionDisabled(FilterItem $filterItem)
}

/**
* Retrieve filter item by id
*
* @param FilterItem[] $filterItems
* @param integer $id
*
* @return bool|FilterItem
*/
protected function getFilterItemById(array $filterItems, $id)
Expand All @@ -228,14 +280,15 @@ protected function getFilterItemById(array $filterItems, $id)
}

/**
* Get swatch image path
*
* @param string $type
* @param string $filename
*
* @return string
*/
public function getSwatchPath($type, $filename)
{
$imagePath = $this->mediaHelper->getSwatchAttributeImage($type, $filename);

return $imagePath;
return $this->mediaHelper->getSwatchAttributeImage($type, $filename);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<argument name="option2" defaultValue="textSwatchOption2" type="string"/>
<argument name="option3" defaultValue="textSwatchOption3" type="string"/>
<argument name="usedInProductListing" defaultValue="No" type="string"/>
<argument name="usedInLayeredNavigation" defaultValue="No" type="string"/>
</arguments>

<amOnPage url="{{ProductAttributePage.url}}" stepKey="goToNewProductAttributePage"/>
Expand All @@ -41,6 +42,7 @@
<click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="clickStorefrontPropertiesTab"/>
<waitForElementVisible selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" stepKey="waitForTabSwitch"/>
<selectOption selector="{{AdvancedAttributePropertiesSection.UseInProductListing}}" userInput="{{usedInProductListing}}" stepKey="useInProductListing"/>
<selectOption selector="{{AttributePropertiesSection.useInLayeredNavigation}}" userInput="{{usedInLayeredNavigation}}" stepKey="useInLayeredNavigation"/>
<click selector="{{AttributePropertiesSection.SaveAndEdit}}" stepKey="clickSave"/>
</actionGroup>
</actionGroups>
Loading