Skip to content

Commit 97289ca

Browse files
author
Valeriy Nayda
committed
MAGETWO-65113: [Performance] Add an opportunity to turn off swatches for category page
1 parent ac5427b commit 97289ca

File tree

10 files changed

+268
-3
lines changed

10 files changed

+268
-3
lines changed

app/code/Magento/Swatches/etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<field id="swatches_per_product" translate="label comment" type="text" sortOrder="300" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
1313
<label>Swatches per Product</label>
1414
</field>
15+
<field id="show_swatches_in_product_list" translate="label comment" type="select" sortOrder="310" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
16+
<label>Show Swatches in Product List</label>
17+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
18+
</field>
1519
</group>
1620
</section>
1721
</system>

app/code/Magento/Swatches/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<catalog>
1111
<frontend>
1212
<swatches_per_product>16</swatches_per_product>
13+
<show_swatches_in_product_list>1</show_swatches_in_product_list>
1314
</frontend>
1415
</catalog>
1516
<general>

app/code/Magento/Swatches/view/frontend/layout/catalog_category_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</head>
1212
<body>
1313
<referenceBlock name="category.product.type.details.renderers">
14-
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" />
14+
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" ifconfig="catalog/frontend/show_swatches_in_product_list" />
1515
</referenceBlock>
1616
</body>
1717
</page>

app/code/Magento/Swatches/view/frontend/layout/catalogsearch_advanced_result.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</head>
1212
<body>
1313
<referenceBlock name="category.product.type.details.renderers">
14-
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" />
14+
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" ifconfig="catalog/frontend/show_swatches_in_product_list" />
1515
</referenceBlock>
1616
</body>
1717
</page>

app/code/Magento/Swatches/view/frontend/layout/catalogsearch_result_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</head>
1212
<body>
1313
<referenceBlock name="category.product.type.details.renderers">
14-
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" />
14+
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" ifconfig="catalog/frontend/show_swatches_in_product_list"/>
1515
</referenceBlock>
1616
</body>
1717
</page>

dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ProductList/ProductItem.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class ProductItem extends CatalogProductItem
2121
*/
2222
protected $swatchSelector = 'div[option-id="%s"]';
2323

24+
/**
25+
* Selector for the swatches of the product.
26+
*
27+
* @var string
28+
*/
29+
protected $swatchBlockSelector = '.swatch-attribute-options';
30+
2431
/**
2532
* Fill product options on category page.
2633
*
@@ -70,4 +77,14 @@ public function clickAddToCart()
7077
$this->_rootElement->hover();
7178
parent::clickAddToCart();
7279
}
80+
81+
/**
82+
* Check swatches visibility.
83+
*
84+
* @return bool
85+
*/
86+
public function isSwatchesBlockVisible()
87+
{
88+
return $this->_rootElement->find($this->swatchBlockSelector)->isVisible();
89+
}
7390
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Swatches\Test\Constraint;
7+
8+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
9+
use Magento\Cms\Test\Page\CmsIndex;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Mtf\Fixture\FixtureInterface;
12+
13+
/**
14+
* Assert swatches visibility in category page.
15+
*/
16+
class AssertSwatchesVisibilityInCategory extends AbstractConstraint
17+
{
18+
/**
19+
* Checking swatches in the category page.
20+
*
21+
* @param CatalogCategoryView $catalogCategoryView
22+
* @param CmsIndex $cmsIndex
23+
* @param FixtureInterface $product
24+
* @param bool $visible
25+
* @return void
26+
*/
27+
public function processAssert(
28+
CatalogCategoryView $catalogCategoryView,
29+
CmsIndex $cmsIndex,
30+
FixtureInterface $product,
31+
$visible = true
32+
) {
33+
$this->openCategoryPage($cmsIndex, $product);
34+
35+
$swatchesBlockVisible = $catalogCategoryView->getListSwatchesProductBlock()
36+
->getProductItem($product)->isSwatchesBlockVisible();
37+
38+
if ($visible) {
39+
\PHPUnit_Framework_Assert::assertTrue(
40+
$swatchesBlockVisible,
41+
'Swatches are absent on category page.'
42+
);
43+
} else {
44+
\PHPUnit_Framework_Assert::assertFalse(
45+
$swatchesBlockVisible,
46+
'Swatches are still present on category page.'
47+
);
48+
}
49+
}
50+
51+
/**
52+
* Open category view page.
53+
*
54+
* @param CmsIndex $cmsIndex
55+
* @param FixtureInterface $product
56+
* @return void
57+
*/
58+
private function openCategoryPage(
59+
CmsIndex $cmsIndex,
60+
FixtureInterface $product
61+
) {
62+
$categoryIds = $product->getCategoryIds();
63+
$categoryName = reset($categoryIds);
64+
$cmsIndex->open();
65+
$cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
66+
}
67+
68+
/**
69+
* Returns a string representation of the object.
70+
*
71+
* @return string
72+
*/
73+
public function toString()
74+
{
75+
return 'Swatches visibility is correct.';
76+
}
77+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
9+
<repository class="Magento\Config\Test\Repository\ConfigData">
10+
<dataset name="enable_swatches_visibility_in_catalog">
11+
<field name="catalog/frontend/show_swatches_in_product_list" xsi:type="array">
12+
<item name="scope" xsi:type="string">default</item>
13+
<item name="scope_id" xsi:type="number">0</item>
14+
<item name="value" xsi:type="number">1</item>
15+
</field>
16+
</dataset>
17+
<dataset name="disable_swatches_visibility_in_catalog">
18+
<field name="catalog/frontend/show_swatches_in_product_list" xsi:type="array">
19+
<item name="scope" xsi:type="string">default</item>
20+
<item name="scope_id" xsi:type="number">0</item>
21+
<item name="value" xsi:type="number">0</item>
22+
</field>
23+
</dataset>
24+
</repository>
25+
</config>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Swatches\Test\TestCase;
7+
8+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
9+
use Magento\Cms\Test\Page\CmsIndex;
10+
use Magento\Config\Test\TestStep\SetupConfigurationStep;
11+
use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct;
12+
use Magento\Mtf\Constraint\ConstraintFactory;
13+
use Magento\Mtf\TestCase\Injectable;
14+
use Magento\Mtf\TestStep\TestStepFactory;
15+
use Magento\Swatches\Test\Constraint\AssertSwatchesVisibilityInCategory;
16+
17+
/**
18+
* Test Flow:
19+
*
20+
* Preconditions:
21+
* 1. Attribute type swatch is created.
22+
* 2. Configurable product with swatch is created.
23+
* 3. Configurable product assigned to category.
24+
*
25+
* Steps:
26+
* 1. Go to Backend.
27+
* 2. Navigate to Stores > Configuration > Catalog > Catalog > Storefront.
28+
* 3. Set Show Swatches in Product List = No.
29+
* 4. Save configuration.
30+
* 5. Clean cache.
31+
* 6. Go to storefront > category with configurable product.
32+
* 7. Check swatches not visible in catalog item.
33+
* 8. Navigate to Stores > Configuration > Catalog > Catalog > Storefront.
34+
* 9. Set Show Swatches in Product List = Yes.
35+
* 10. Save configuration.
36+
* 11. Clean cache.
37+
* 12. Go to storefront > category with configurable product.
38+
* 13. Check swatches are visible in catalog item.
39+
*
40+
* @group Swatches (MX)
41+
* @ZephyrId MAGETWO-65485
42+
*/
43+
class CheckSwatchesInCategoryPageTest extends Injectable
44+
{
45+
/**
46+
* Category page.
47+
*
48+
* @var CatalogCategoryView
49+
*/
50+
protected $catalogCategoryView;
51+
52+
/**
53+
* Index page.
54+
*
55+
* @var CmsIndex
56+
*/
57+
protected $cmsIndex;
58+
59+
/**
60+
* Factory for creation SetupConfigurationStep.
61+
*
62+
* @var TestStepFactory
63+
*/
64+
protected $testStepFactory;
65+
66+
/**
67+
* Factory for creation AssertSwatchesVisibilityInCategory.
68+
*
69+
* @var ConstraintFactory
70+
*/
71+
protected $constraintFactory;
72+
73+
/**
74+
* @param CatalogCategoryView $catalogCategoryView
75+
* @param CmsIndex $cmsIndex
76+
* @param TestStepFactory $testStepFactory
77+
* @param ConstraintFactory $constraintFactory
78+
*/
79+
public function __prepare(
80+
CatalogCategoryView $catalogCategoryView,
81+
CmsIndex $cmsIndex,
82+
TestStepFactory $testStepFactory,
83+
ConstraintFactory $constraintFactory
84+
) {
85+
$this->catalogCategoryView = $catalogCategoryView;
86+
$this->cmsIndex = $cmsIndex;
87+
$this->testStepFactory = $testStepFactory;
88+
$this->constraintFactory = $constraintFactory;
89+
}
90+
91+
/**
92+
* Test check swatches on category page run.
93+
*
94+
* @param ConfigurableProduct $product
95+
* @return array
96+
*/
97+
public function test(ConfigurableProduct $product)
98+
{
99+
//Preconditions:
100+
$product->persist();
101+
102+
//Steps:
103+
$this->testStepFactory->create(
104+
SetupConfigurationStep::class,
105+
['configData' => 'disable_swatches_visibility_in_catalog']
106+
)->run();
107+
108+
/** @var AssertSwatchesVisibilityInCategory $assertSwatchesVisibility */
109+
$assertSwatchesVisibility = $this->constraintFactory->get(
110+
AssertSwatchesVisibilityInCategory::class
111+
);
112+
$assertSwatchesVisibility->processAssert(
113+
$this->catalogCategoryView,
114+
$this->cmsIndex,
115+
$product,
116+
false
117+
);
118+
119+
$this->testStepFactory->create(
120+
SetupConfigurationStep::class,
121+
['configData' => 'enable_swatches_visibility_in_catalog', 'flushCache' => true]
122+
)->run();
123+
124+
return ['product' => $product];
125+
}
126+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Swatches\Test\TestCase\CheckSwatchesInCategoryPageTest" summary="Check Swathes visibility in category page" ticketId="MAGETWO-65485">
10+
<variation name="CheckSwatchesInCategoryPageTestVariation1">
11+
<data name="product/dataset" xsi:type="string">product_with_text_swatch</data>
12+
<constraint name="Magento\Swatches\Test\Constraint\AssertSwatchesVisibilityInCategory" />
13+
</variation>
14+
</testCase>
15+
</config>

0 commit comments

Comments
 (0)