Skip to content

Commit c21a64e

Browse files
committed
Merge remote-tracking branch 'github-magento2ce/MAGETWO-98522' into EPAM-PR-51
2 parents d2b6928 + e8b34ff commit c21a64e

File tree

5 files changed

+162
-1
lines changed

5 files changed

+162
-1
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AddOutOfStockProductToCompareListTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<title value="Add out of stock product to compare list"/>
15+
<description value="Add out of stock product to compare list"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MAGETWO-98644"/>
18+
<useCaseId value="MAGETWO-98522"/>
19+
<group value="Catalog"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
23+
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 0" stepKey="displayOutOfStockNo"/>
24+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
25+
<createData entity="SimpleSubCategory" stepKey="category"/>
26+
<createData entity="SimpleProduct4" stepKey="product">
27+
<requiredEntity createDataKey="category"/>
28+
</createData>
29+
</before>
30+
<after>
31+
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 0" stepKey="displayOutOfStockNo2"/>
32+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
33+
<deleteData createDataKey="product" stepKey="deleteProduct"/>
34+
<deleteData createDataKey="category" stepKey="deleteCategory"/>
35+
<actionGroup ref="logout" stepKey="logout"/>
36+
</after>
37+
<!--Open product page-->
38+
<comment userInput="Open product page" stepKey="openProdPage"/>
39+
<amOnPage url="{{StorefrontProductPage.url($$product.name$$)}}" stepKey="goToSimpleProductPage"/>
40+
<waitForPageLoad stepKey="waitForSimpleProductPage"/>
41+
<!--'Add to compare' link is not available-->
42+
<comment userInput="'Add to compare' link is not available" stepKey="addToCompareLinkAvailability"/>
43+
<dontSeeElement selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="dontSeeAddToCompareLink"/>
44+
<!--Turn on 'out on stock' config-->
45+
<comment userInput="Turn on 'out of stock' config" stepKey="onOutOfStockConfig"/>
46+
<magentoCLI command="config:set cataloginventory/options/show_out_of_stock 1" stepKey="displayOutOfStockYes"/>
47+
<!--Clear cache and reindex-->
48+
<comment userInput="Clear cache and reindex" stepKey="cleanCache"/>
49+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
50+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
51+
<!--Open product page-->
52+
<comment userInput="Open product page" stepKey="openProductPage"/>
53+
<amOnPage url="{{StorefrontProductPage.url($$product.name$$)}}" stepKey="goToSimpleProductPage2"/>
54+
<waitForPageLoad stepKey="waitForSimpleProductPage2"/>
55+
<!--Click on 'Add to Compare' link-->
56+
<comment userInput="Click on 'Add to Compare' link" stepKey="clickOnAddToCompareLink"/>
57+
<click selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="clickOnAddToCompare"/>
58+
<waitForPageLoad stepKey="waitForProdAddToCmpList"/>
59+
<!--Assert success message-->
60+
<comment userInput="Assert success message" stepKey="assertSuccessMsg"/>
61+
<grabTextFrom selector="{{AdminProductMessagesSection.successMessage}}" stepKey="grabTextFromSuccessMessage"/>
62+
<assertEquals expected='You added product $$product.name$$ to the comparison list.' expectedType="string" actual="($grabTextFromSuccessMessage)" stepKey="assertSuccessMessage"/>
63+
<!--See product in the comparison list-->
64+
<comment userInput="See product in the comparison list" stepKey="seeProductInComparisonList"/>
65+
<amOnPage url="{{StorefrontProductComparePage.url}}" stepKey="navigateToComparePage"/>
66+
<waitForPageLoad stepKey="waitForStorefrontProductComparePageLoad"/>
67+
<seeElement selector="{{StorefrontProductCompareMainSection.ProductLinkByName($product.name$)}}" stepKey="seeProductInCompareList"/>
68+
<!--Go to Category page and delete product from comparison list-->
69+
<comment userInput="Go to Category page and delete prduct from comparison list" stepKey="deletProdFromCmpList"/>
70+
<amOnPage url="{{StorefrontCategoryPage.url($$category.name$$)}}" stepKey="onCategoryPage"/>
71+
<waitForPageLoad time="30" stepKey="waitForPageLoad1"/>
72+
<click selector="{{StorefrontComparisonSidebarSection.ClearAll}}" stepKey="clickClearAll"/>
73+
<waitForPageLoad time="30" stepKey="waitForConfirmPageLoad"/>
74+
<click selector="{{AdminDeleteRoleSection.confirm}}" stepKey="confirmProdDelate"/>
75+
<waitForPageLoad time="30" stepKey="waitForConfirmLoad"/>
76+
<!--Add product to compare list from Category page-->
77+
<comment userInput="Add product to compare list fom Category page" stepKey="addToCmpFromCategPage"/>
78+
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverOverProduct"/>
79+
<click selector="{{StorefrontProductInfoMainSection.productAddToCompare}}" stepKey="clickAddToCompare"/>
80+
<waitForPageLoad stepKey="waitProdAddingToCmpList"/>
81+
<!--Assert success message-->
82+
<comment userInput="Assert success message" stepKey="assertSuccessMsg2"/>
83+
<grabTextFrom selector="{{AdminProductMessagesSection.successMessage}}" stepKey="grabTextFromSuccessMessage2"/>
84+
<assertEquals expected='You added product $$product.name$$ to the comparison list.' expectedType="string" actual="($grabTextFromSuccessMessage)" stepKey="assertSuccessMessage2"/>
85+
<!--Check that product displays on add to compare widget-->
86+
<comment userInput="Check that product displays on add to compare widget" stepKey="checkProdNameOnWidget"/>
87+
<seeElement selector="{{StorefrontComparisonSidebarSection.ProductTitleByName($$product.name$$)}}" stepKey="seeProdNameOnCmpWidget"/>
88+
<!--See product in the compare page-->
89+
<comment userInput="See product in the compare page" stepKey="seeProductInComparePage"/>
90+
<amOnPage url="{{StorefrontProductComparePage.url}}" stepKey="navigateToComparePage2"/>
91+
<waitForPageLoad stepKey="waitForStorefrontProductComparePageLoad2"/>
92+
<seeElement selector="{{StorefrontProductCompareMainSection.ProductLinkByName($product.name$)}}" stepKey="seeProductInCompareList2"/>
93+
</test>
94+
</tests>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\ViewModel\Product\Checker;
9+
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
13+
14+
/**
15+
* Check is available add to compare.
16+
*/
17+
class AddToCompareAvailability implements ArgumentInterface
18+
{
19+
/**
20+
* @var StockConfigurationInterface
21+
*/
22+
private $stockConfiguration;
23+
24+
/**
25+
* @param StockConfigurationInterface $stockConfiguration
26+
*/
27+
public function __construct(StockConfigurationInterface $stockConfiguration)
28+
{
29+
$this->stockConfiguration = $stockConfiguration;
30+
}
31+
32+
/**
33+
* Is product available for comparison.
34+
*
35+
* @param ProductInterface $product
36+
* @return bool
37+
*/
38+
public function isAvailableForCompare(ProductInterface $product): bool
39+
{
40+
return $this->isInStock($product) || $this->stockConfiguration->isShowOutOfStock();
41+
}
42+
43+
/**
44+
* Get is in stock status.
45+
*
46+
* @param ProductInterface $product
47+
* @return bool
48+
*/
49+
private function isInStock(ProductInterface $product): bool
50+
{
51+
$quantityAndStockStatus = $product->getQuantityAndStockStatus();
52+
if (!$quantityAndStockStatus) {
53+
return $product->isSalable();
54+
}
55+
56+
return isset($quantityAndStockStatus['is_in_stock']) && $quantityAndStockStatus['is_in_stock'];
57+
}
58+
}

app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@
9191
<container name="product.info.social" label="Product social links container" htmlTag="div" htmlClass="product-social-links">
9292
<block class="Magento\Catalog\Block\Product\View" name="product.info.addto" as="addto" template="Magento_Catalog::product/view/addto.phtml">
9393
<block class="Magento\Catalog\Block\Product\View\AddTo\Compare" name="view.addto.compare" after="view.addto.wishlist"
94-
template="Magento_Catalog::product/view/addto/compare.phtml" />
94+
template="Magento_Catalog::product/view/addto/compare.phtml" >
95+
<arguments>
96+
<argument name="addToCompareViewModel" xsi:type="object">Magento\Catalog\ViewModel\Product\Checker\AddToCompareAvailability</argument>
97+
</arguments>
98+
</block>
9599
</block>
96100
<block class="Magento\Catalog\Block\Product\View" name="product.info.mailto" template="Magento_Catalog::product/view/mailto.phtml"/>
97101
</container>

app/code/Magento/Catalog/view/frontend/templates/product/view/addto/compare.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
/** @var $block \Magento\Catalog\Block\Product\View\Addto\Compare */
1010
?>
1111

12+
<?php $viewModel = $block->getData('addToCompareViewModel'); ?>
13+
<?php if ($viewModel->isAvailableForCompare($block->getProduct())): ?>
1214
<a href="#" data-post='<?= /* @escapeNotVerified */ $block->getPostDataParams() ?>'
1315
data-role="add-to-links"
1416
class="action tocompare"><span><?= /* @escapeNotVerified */ __('Add to Compare') ?></span></a>
17+
<?php endif; ?>
18+

app/code/Magento/CatalogInventory/Test/Mftf/ActionGroup/DisplayOutOfStockProductActionGroup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<actionGroup name="noDisplayOutOfStockProduct">
2222
<amOnPage url="{{InventoryConfigurationPage.url}}" stepKey="navigateToInventoryConfigurationPage"/>
2323
<waitForPageLoad stepKey="waitForConfigPageToLoad"/>
24+
<conditionalClick stepKey="expandProductStockOptions" selector="{{InventoryConfigSection.ProductStockOptionsTab}}" dependentSelector="{{InventoryConfigSection.CheckIfProductStockOptionsTabExpanded}}" visible="true" />
2425
<uncheckOption selector="{{InventoryConfigSection.DisplayOutOfStockSystemValue}}" stepKey="uncheckUseSystemValue"/>
2526
<waitForElementVisible selector="{{InventoryConfigSection.DisplayOutOfStockDropdown}}" stepKey="waitForSwitcherDropdown" />
2627
<selectOption selector="{{InventoryConfigSection.DisplayOutOfStockDropdown}}" userInput="No" stepKey="switchToNo" />

0 commit comments

Comments
 (0)