Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-devel…
Browse files Browse the repository at this point in the history
…op expedited

Accepted Community Pull Requests:
 - #28547: 'Ship Here' in CamelCase as that's how it is written elsewhere (by @woutk88)
 - #28222: [Wishlist] Giving the possibility to set/update item description on item update (by @eduard13)
 - #28015: Fix #28011 - remove page number from query on layered navigation swatch filter (by @Bartlomiejsz)


Fixed GitHub Issues:
 - #28261: [Issue] [Wishlist] Giving the possibility to set/update item description on item update (reported by @m2-backlog[bot]) has been fixed in #28222 by @eduard13 in 2.4-develop branch
   Related commits:
     1. a41e384
     2. 1d799ab

 - #28011: ElasticSearch When applying the extra filter to the product listing, Magento keeps the same page number (reported by @santosh-gaggle) has been fixed in #28015 by @Bartlomiejsz in 2.4-develop branch
   Related commits:
     1. 92b29c6
     2. 475be33
     3. 7630cb0
     4. 0de77c8
     5. ee4acff
  • Loading branch information
magento-engcom-team authored Jun 9, 2020
2 parents bb176b8 + 249ce6d commit 8513dfd
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 68 deletions.
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"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<item name="trigger" xsi:type="string">opc-new-shipping-address</item>
<item name="buttons" xsi:type="array">
<item name="save" xsi:type="array">
<item name="text" xsi:type="string" translate="true">Ship here</item>
<item name="text" xsi:type="string" translate="true">Ship Here</item>
<item name="class" xsi:type="string">action primary action-save-address</item>
</item>
<item name="cancel" xsi:type="array">
Expand Down
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());
}

/**
* 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

0 comments on commit 8513dfd

Please sign in to comment.