Skip to content
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
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
namespace Magento\Swatches\Block\Product\Renderer;

use Magento\Catalog\Block\Product\Context;
Expand Down Expand Up @@ -57,6 +58,11 @@ class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\
*/
const SWATCH_THUMBNAIL_NAME = 'swatchThumb';

/**
* Config path which contains number of swatches per product
*/
private const XML_PATH_SWATCHES_PER_PRODUCT = 'catalog/frontend/swatches_per_product';

/**
* @var Product
*/
Expand Down Expand Up @@ -200,7 +206,7 @@ public function getJsonSwatchConfig()
public function getNumberSwatchesPerProduct()
{
return $this->_scopeConfig->getValue(
'catalog/frontend/swatches_per_product',
self::XML_PATH_SWATCHES_PER_PRODUCT,
ScopeInterface::SCOPE_STORE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<element name="nthSwatchOptionText" type="button" selector="div.swatch-option.text:nth-of-type({{n}})" parameterized="true"/>
<element name="productSwatch" type="button" selector="//div[@class='swatch-option'][@aria-label='{{var1}}']" parameterized="true"/>
<element name="visualSwatchOption" type="button" selector=".swatch-option[option-tooltip-value='#{{visualSwatchOption}}']" parameterized="true"/>
<element name="swatchOptionTooltip" type="block" selector="div.swatch-option-tooltip"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminDisablingSwatchTooltipsTest">
<annotations>
<features value="Swatches"/>
<title value="Admin disabling swatch tooltips test."/>
<description value="Verify possibility to disable/enable swatch tooltips."/>
<severity value="AVERAGE"/>
<group value="Swatches"/>
</annotations>
<before>
<!-- Create category -->
<createData entity="ApiCategory" stepKey="createCategory"/>

<!-- Log in -->
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>
<after>
<!-- Clean up our modifications to the existing color attribute -->
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="goToProductAttributes"/>
<waitForPageLoad stepKey="waitForProductAttributes"/>
<fillField selector="{{AdminProductAttributeGridSection.FilterByAttributeCode}}" userInput="color"
stepKey="fillFilter"/>
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="clickSearch"/>
<click selector="{{AdminProductAttributeGridSection.AttributeCode('color')}}" stepKey="clickRowToEdit"/>
<click selector="{{AdminManageSwatchSection.nthDelete('1')}}" stepKey="deleteSwatch1"/>
<waitForPageLoad stepKey="waitToClickSave"/>
<click selector="{{AttributePropertiesSection.SaveAndEdit}}" stepKey="clickSaveAndEdit"/>

<!-- Log out -->
<actionGroup ref="logout" stepKey="logOut"/>

<!-- Delete category -->
<deleteData stepKey="deleteCategory" createDataKey="createCategory"/>

<!-- Enable swatch tooltips -->
<magentoCLI command="config:set catalog/frontend/show_swatch_tooltip 1" stepKey="disableTooltips"/>
<magentoCLI command="cache:flush" stepKey="flushCacheAfterEnabling"/>
</after>

<!-- Go to the edit page for the "color" attribute -->
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="goToProductAttributes"/>
<waitForPageLoad stepKey="waitForProductAttributes"/>
<fillField selector="{{AdminProductAttributeGridSection.FilterByAttributeCode}}" userInput="color"
stepKey="fillFilter"/>
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="clickSearch"/>
<click selector="{{AdminProductAttributeGridSection.AttributeCode('color')}}" stepKey="clickRowToEdit"/>

<!-- Change to visual swatches -->
<selectOption selector="{{AdminNewAttributePanel.inputType}}" userInput="swatch_visual"
stepKey="selectVisualSwatch"/>

<!-- Set swatch using the color picker -->
<click selector="{{AdminManageSwatchSection.addSwatch}}" stepKey="clickAddSwatch1"/>
<actionGroup ref="openSwatchMenuByIndex" stepKey="clickSwatch1">
<argument name="index" value="0"/>
</actionGroup>
<click selector="{{AdminManageSwatchSection.nthChooseColor('1')}}" stepKey="clickChooseColor1"/>
<actionGroup ref="setColorPickerByHex" stepKey="fillHex1">
<argument name="nthColorPicker" value="1"/>
<argument name="hexColor" value="e74c3c"/>
</actionGroup>
<fillField selector="{{AdminManageSwatchSection.adminInputByIndex('0')}}" userInput="red" stepKey="fillAdmin1"/>
<waitForPageLoad stepKey="waitToClickSave"/>

<!-- Save -->
<click selector="{{AttributePropertiesSection.SaveAndEdit}}" stepKey="clickSaveAndEdit1"/>
<waitForElementVisible selector="{{AdminProductMessagesSection.successMessage}}" stepKey="waitForSuccess"/>

<!-- Assert that the Save was successful after round trip to server -->
<actionGroup ref="assertSwatchColor" stepKey="assertSwatchAdmin">
<argument name="nthSwatch" value="1"/>
<argument name="expectedStyle" value="background: rgb(231, 77, 60);"/>
</actionGroup>

<!-- Create a configurable product to verify the storefront with -->
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="amOnProductGridPage"/>
<waitForPageLoad stepKey="waitForProductGridPage"/>
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickOnAddProductToggle"/>
<click selector="{{AdminProductGridActionSection.addConfigurableProduct}}"
stepKey="clickOnAddConfigurableProduct"/>
<fillField userInput="{{_defaultProduct.name}}" selector="{{AdminProductFormSection.productName}}"
stepKey="fillName"/>
<fillField userInput="{{_defaultProduct.sku}}" selector="{{AdminProductFormSection.productSku}}"
stepKey="fillSKU"/>
<fillField userInput="{{_defaultProduct.price}}" selector="{{AdminProductFormSection.productPrice}}"
stepKey="fillPrice"/>
<fillField userInput="{{_defaultProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}"
stepKey="fillQuantity"/>
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}"
parameterArray="[$$createCategory.name$$]" stepKey="fillCategory"/>
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/>
<fillField userInput="{{_defaultProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}"
stepKey="fillUrlKey"/>

<!-- Create configurations based on the Swatch we created earlier -->
<click selector="{{AdminProductFormConfigurationsSection.createConfigurations}}"
stepKey="clickCreateConfigurations"/>
<click selector="{{AdminCreateProductConfigurationsPanel.filters}}" stepKey="clickFilters"/>
<fillField selector="{{AdminCreateProductConfigurationsPanel.attributeCode}}" userInput="color"
stepKey="fillFilterAttributeCodeField"/>
<click selector="{{AdminCreateProductConfigurationsPanel.applyFilters}}" stepKey="clickApplyFiltersButton"/>
<click selector="{{AdminCreateProductConfigurationsPanel.firstCheckbox}}" stepKey="clickOnFirstCheckbox"/>
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton1"/>
<click selector="{{AdminCreateProductConfigurationsPanel.selectAll}}" stepKey="clickOnSelectAll"/>
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton2"/>
<click selector="{{AdminCreateProductConfigurationsPanel.applyUniquePricesByAttributeToEachSku}}"
stepKey="clickOnApplyUniquePricesByAttributeToEachSku"/>
<selectOption selector="{{AdminCreateProductConfigurationsPanel.selectAttribute}}" userInput="Color"
stepKey="selectAttributes"/>
<fillField selector="{{AdminCreateProductConfigurationsPanel.attribute1}}" userInput="10"
stepKey="fillAttributePrice1"/>
<click selector="{{AdminCreateProductConfigurationsPanel.applySingleQuantityToEachSkus}}"
stepKey="clickOnApplySingleQuantityToEachSku"/>
<fillField selector="{{AdminCreateProductConfigurationsPanel.quantity}}" userInput="99"
stepKey="enterAttributeQuantity"/>
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton3"/>
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton4"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickOnSaveButton2"/>
<conditionalClick selector="{{AdminChooseAffectedAttributeSetPopup.confirm}}"
dependentSelector="{{AdminChooseAffectedAttributeSetPopup.confirm}}" visible="true"
stepKey="clickOnConfirmInPopup"/>
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessage"/>
<seeInTitle userInput="{{_defaultProduct.name}}" stepKey="seeProductNameInTitle"/>

<!-- Go to the product page and see swatch options -->
<amOnPage url="{{_defaultProduct.urlKey}}.html" stepKey="amOnProductPage"/>
<waitForPageLoad stepKey="waitForProductPage"/>

<!-- Verify that the storefront shows the swatches too -->
<actionGroup ref="assertStorefrontSwatchColor" stepKey="assertSwatchStorefront">
<argument name="nthSwatch" value="1"/>
<argument name="expectedRgb" value="rgb(231, 77, 60)"/>
</actionGroup>

<!-- Verify swatch tooltips are visible-->
<moveMouseOver selector="{{StorefrontProductInfoMainSection.nthSwatchOption('1')}}" stepKey="hoverEnabledSwatch"/>
<wait time="1" stepKey="waitForTooltip1"/>
<seeElement selector="{{StorefrontProductInfoMainSection.swatchOptionTooltip}}" stepKey="swatchTooltipVisible"/>

<!-- Disable swatch tooltips -->
<magentoCLI command="config:set catalog/frontend/show_swatch_tooltip 0" stepKey="disableTooltips"/>
<magentoCLI command="cache:flush" stepKey="flushCacheAfterDisabling"/>

<!-- Verify swatch tooltips are not visible -->
<reloadPage stepKey="refreshPage"/>
<waitForPageLoad stepKey="waitForPageReload"/>
<moveMouseOver selector="{{StorefrontProductInfoMainSection.nthSwatchOption('1')}}" stepKey="hoverDisabledSwatch"/>
<wait time="1" stepKey="waitForTooltip2"/>
<dontSeeElement selector="{{StorefrontProductInfoMainSection.swatchOptionTooltip}}" stepKey="swatchTooltipNotVisible"/>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
namespace Magento\Swatches\ViewModel\Product\Renderer;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Store\Model\ScopeInterface;

/**
* Class Configurable
*/
class Configurable implements ArgumentInterface
{
/**
* Config path if swatch tooltips are enabled
*/
private const XML_PATH_SHOW_SWATCH_TOOLTIP = 'catalog/frontend/show_swatch_tooltip';

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* Configurable constructor.
*
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(ScopeConfigInterface $scopeConfig)
{
$this->scopeConfig = $scopeConfig;
}

/**
* Get config if swatch tooltips should be rendered.
*
* @return string
*/
public function getShowSwatchTooltip()
{
return $this->scopeConfig->getValue(
self::XML_PATH_SHOW_SWATCH_TOOLTIP,
ScopeInterface::SCOPE_STORE
);
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/Swatches/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<label>Show Swatches in Product List</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="show_swatch_tooltip" translate="label" type="select" sortOrder="320" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Show Swatch Tooltip</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Swatches/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<frontend>
<swatches_per_product>16</swatches_per_product>
<show_swatches_in_product_list>1</show_swatches_in_product_list>
<show_swatch_tooltip>1</show_swatch_tooltip>
</frontend>
</catalog>
<general>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.product.type.details.renderers">
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" name="category.product.type.details.renderers.configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" ifconfig="catalog/frontend/show_swatches_in_product_list" />
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable"
name="category.product.type.details.renderers.configurable" as="configurable"
template="Magento_Swatches::product/listing/renderer.phtml"
ifconfig="catalog/frontend/show_swatches_in_product_list">
<arguments>
<argument name="configurable_view_model"
xsi:type="object">Magento\Swatches\ViewModel\Product\Renderer\Configurable</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.options.configurable" remove="true"/>
<referenceBlock name="product.info.options.wrapper">
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-" />
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches"
as="swatch_options" before="-">
<arguments>
<argument name="configurable_view_model"
xsi:type="object">Magento\Swatches\ViewModel\Product\Renderer\Configurable</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
~ See COPYING.txt for license details.
-->

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.product.type.widget.details.renderers">
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" name="category.product.type.details.renderers.configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" ifconfig="catalog/frontend/show_swatches_in_product_list"/>
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable"
name="category.product.type.details.renderers.configurable" as="configurable"
template="Magento_Swatches::product/listing/renderer.phtml"
ifconfig="catalog/frontend/show_swatches_in_product_list">
<arguments>
<argument name="configurable_view_model"
xsi:type="object">Magento\Swatches\ViewModel\Product\Renderer\Configurable</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.product.type.details.renderers">
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" name="category.product.type.details.renderers.configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" ifconfig="catalog/frontend/show_swatches_in_product_list" />
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable"
name="category.product.type.details.renderers.configurable" as="configurable"
template="Magento_Swatches::product/listing/renderer.phtml"
ifconfig="catalog/frontend/show_swatches_in_product_list">
<arguments>
<argument name="configurable_view_model"
xsi:type="object">Magento\Swatches\ViewModel\Product\Renderer\Configurable</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Loading