Skip to content

Commit

Permalink
Merge pull request #4925 from magento-epam/MAGETWO-72172-v2
Browse files Browse the repository at this point in the history
- fixed Disabled variation of configurable product can be added to shopping cart via admin
  • Loading branch information
irenelagno authored Oct 28, 2019
2 parents 68d2137 + 9f4fee2 commit e90ddc6
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ public function getAllowProducts()
{
if (!$this->hasAllowProducts()) {
$products = [];
$skipSaleableCheck = $this->catalogProduct->getSkipSaleableCheck();
$allProducts = $this->getProduct()->getTypeInstance()->getUsedProducts($this->getProduct(), null);
/** @var $product \Magento\Catalog\Model\Product */
foreach ($allProducts as $product) {
if ($skipSaleableCheck || ((int) $product->getStatus()) === Status::STATUS_ENABLED) {
if ((int) $product->getStatus() === Status::STATUS_ENABLED) {
$products[] = $product;
}
}
Expand Down
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="NoOptionAvailableToConfigureDisabledProductTest">
<annotations>
<features value="ConfigurableProduct"/>
<stories value="Admin order configurable product"/>
<title value="Disabled variation of configurable product can't be added to shopping cart via admin"/>
<description value="Disabled variation of configurable product can't be added to shopping cart via admin"/>
<severity value="AVERAGE"/>
<testCaseId value="MC-17373"/>
<useCaseId value="MAGETWO-72172"/>
<group value="ConfigurableProduct"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="login"/>
<!--Create category-->
<comment userInput="Create category" stepKey="commentCreateCategory"/>
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
<!-- Create the configurable product based on the data in the data folder -->
<comment userInput="Create the configurable product based on the data in the data folder" stepKey="createConfigurableProduct"/>
<createData entity="ApiConfigurableProduct" stepKey="createConfigProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
<!-- Create the configurable product with two options based on the default attribute set -->
<comment userInput="Create the configurable product with two options based on the default attribute set" stepKey="configurableProductWithTwoOptions"/>
<createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/>
<createData entity="productAttributeOption1" stepKey="createConfigProductAttributeOption1">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</createData>
<createData entity="productAttributeOption2" stepKey="createConfigProductAttributeOption2">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</createData>
<createData entity="productAttributeOption3" stepKey="createConfigProductAttributeOption3">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</createData>
<createData entity="AddToDefaultSet" stepKey="createConfigAddToAttributeSet">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</createData>
<getData entity="ProductAttributeOptionGetter" index="1" stepKey="getConfigAttributeOption1">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</getData>
<getData entity="ProductAttributeOptionGetter" index="2" stepKey="getConfigAttributeOption2">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</getData>
<getData entity="ProductAttributeOptionGetter" index="3" stepKey="getConfigAttributeOption3">
<requiredEntity createDataKey="createConfigProductAttribute"/>
</getData>
<!-- Create the 3 children that will be a part of the configurable product -->
<comment userInput="Create the 3 children that will be a part of the configurable product" stepKey="createTwoChildrenProducts"/>
<createData entity="ApiSimpleProductWithPrice50" stepKey="createConfigChildProduct1">
<requiredEntity createDataKey="createConfigProductAttribute"/>
<requiredEntity createDataKey="getConfigAttributeOption1"/>
</createData>
<createData entity="ApiSimpleProductWithPrice60" stepKey="createConfigChildProduct2">
<requiredEntity createDataKey="createConfigProductAttribute"/>
<requiredEntity createDataKey="getConfigAttributeOption2"/>
</createData>
<createData entity="ApiSimpleProductWithPrice70" stepKey="createConfigChildProduct3">
<requiredEntity createDataKey="createConfigProductAttribute"/>
<requiredEntity createDataKey="getConfigAttributeOption3"/>
</createData>
<!-- Assign 3 products to the configurable product -->
<comment userInput="Assign 3 products to the configurable product" stepKey="assignToConfigurableProduct"/>
<createData entity="ConfigurableProductTwoOptions" stepKey="createConfigProductOption">
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigProductAttribute"/>
<requiredEntity createDataKey="getConfigAttributeOption1"/>
<requiredEntity createDataKey="getConfigAttributeOption2"/>
<requiredEntity createDataKey="getConfigAttributeOption3"/>
</createData>
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddChild1">
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigChildProduct1"/>
</createData>
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddChild2">
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigChildProduct2"/>
</createData>
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddChild3">
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigChildProduct3"/>
</createData>
<!-- Create Customer -->
<comment userInput="Create customer" stepKey="commentCreateCustomer"/>
<createData entity="Simple_US_Customer_CA" stepKey="createCustomer"/>
</before>
<after>
<!-- Delete created data -->
<comment userInput="Delete created data" stepKey="deleteData"/>
<deleteData createDataKey="createCategory" stepKey="deleteCategory2"/>
<deleteData createDataKey="createConfigProduct" stepKey="deleteConfigProduct"/>
<deleteData createDataKey="createConfigChildProduct1" stepKey="deleteConfigChildProduct1"/>
<deleteData createDataKey="createConfigChildProduct2" stepKey="deleteConfigChildProduct2"/>
<deleteData createDataKey="createConfigChildProduct3" stepKey="deleteConfigChildProduct3"/>
<deleteData createDataKey="createConfigProductAttribute" stepKey="deleteConfigProductAttribute"/>
<deleteData createDataKey="createCustomer" stepKey="deleteCreatedCustomer"/>
<actionGroup ref="logout" stepKey="logout"/>
</after>
<!-- Disable child product -->
<comment userInput="Disable child product" stepKey="disableChildProduct"/>
<amOnPage url="{{AdminProductEditPage.url($$createConfigChildProduct1.id$$)}}" stepKey="goToEditPage"/>
<waitForPageLoad stepKey="waitForChildProductPageLoad"/>
<click selector="{{AdminProductFormSection.enableProductLabel}}" stepKey="disableProduct"/>
<actionGroup ref="saveProductForm" stepKey="saveProductForm"/>
<!-- Set the second product out of stock -->
<comment userInput="Set the second product out of stock" stepKey="outOfStockChildProduct"/>
<amOnPage url="{{AdminProductEditPage.url($$createConfigChildProduct2.id$$)}}" stepKey="goToSecondProductEditPage"/>
<waitForPageLoad stepKey="waitForSecondChildProductPageLoad"/>
<selectOption selector="{{AdminProductFormSection.productStockStatus}}" userInput="Out of Stock" stepKey="outOfStockStatus"/>
<actionGroup ref="saveProductForm" stepKey="saveSecondProductForm"/>
<!-- Go to created customer page -->
<comment userInput="Go to created customer page" stepKey="goToCreatedCustomerPage"/>
<actionGroup ref="navigateToNewOrderPageExistingCustomer" stepKey="createNewOrder">
<argument name="customer" value="$$createCustomer$$"/>
</actionGroup>
<click selector="{{AdminOrderFormItemsSection.addProducts}}" stepKey="clickToAddProduct"/>
<waitForPageLoad stepKey="waitForProductsOpened"/>
<!-- Find created configurable product and click on "Configure" link -->
<comment userInput="Find created configurable product and click on Configure link" stepKey="goToConfigurableLink"/>
<click selector="{{AdminOrderFormConfigureProductSection.configure($$createConfigProduct.id$$)}}" stepKey="clickOnConfigure"/>
<!-- Click on attribute drop-down and check no option 1 is available -->
<comment userInput="Click on attribute drop-down and check no option 1 is available" stepKey="commentNoOptionIsAvailable"/>
<waitForElement selector="{{AdminOrderFormConfigureProductSection.selectOption}}" stepKey="waitForShippingSectionLoaded"/>
<click selector="{{AdminOrderFormConfigureProductSection.selectOption}}" stepKey="clickToSelectOption"/>
<dontSee userInput="$$createConfigProductAttributeOption1.option[store_labels][1][label]$$" stepKey="dontSeeOption1"/>
<!-- Go to created customer page again -->
<comment userInput="Go to created customer page again" stepKey="goToCreatedCustomerPageAgain"/>
<actionGroup ref="navigateToNewOrderPageExistingCustomer" stepKey="createNewOrderAgain">
<argument name="customer" value="$$createCustomer$$"/>
</actionGroup>
<click selector="{{AdminOrderFormItemsSection.addProducts}}" stepKey="clickToAddProductAgain"/>
<waitForPageLoad stepKey="waitForProductsOpenedAgain"/>
<fillField selector="{{AdminOrderFormItemsSection.idFilter}}" userInput="$$createConfigChildProduct2.id$$" stepKey="idFilter"/>
<click selector="{{AdminOrderFormItemsSection.search}}" stepKey="clickSearch"/>
<checkOption selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" stepKey="selectConfigurableProduct"/>
<!-- Add product to order -->
<comment userInput="Add product to order" stepKey="addProductToOrder"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
<click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickToAddProductToOrder"/>
<waitForPageLoad stepKey="waitForNewOrderPageLoad"/>
<see userInput="This product is out of stock." stepKey="seeTheErrorMessageDisplayed"/>
<!-- Select shipping method -->
<comment userInput="Select shipping method" stepKey="selectShippingMethod"/>
<click selector="{{AdminInvoicePaymentShippingSection.getShippingMethodAndRates}}" stepKey="openShippingMethod"/>
<waitForPageLoad stepKey="waitForShippingMethods"/>
<click selector="{{AdminInvoicePaymentShippingSection.shippingMethod}}" stepKey="chooseShippingMethod"/>
<waitForPageLoad stepKey="waitForShippingMethodLoad"/>
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/>
<waitForPageLoad stepKey="waitForSuccess"/>
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="You created the order." stepKey="seeSuccessMessage"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ public function cacheKeyProvider(): array
public function testGetCacheKeyInfo(array $expected, string $priceCurrency = null, string $customerGroupId = null)
{
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
->setMethods([
'getCurrentCurrency',
])
->setMethods(['getCurrentCurrency'])
->getMockForAbstractClass();
$storeMock->expects($this->any())
->method('getCode')
Expand Down Expand Up @@ -270,9 +268,7 @@ public function testGetJsonConfig()
$amountMock = $this->getAmountMock($amount);

$priceMock = $this->getMockBuilder(\Magento\Framework\Pricing\Price\PriceInterface::class)
->setMethods([
'getAmount',
])
->setMethods(['getAmount'])
->getMockForAbstractClass();
$priceMock->expects($this->any())->method('getAmount')->willReturn($amountMock);
$tierPriceMock = $this->getTierPriceMock($amountMock, $priceQty, $percentage);
Expand All @@ -287,22 +283,25 @@ public function testGetJsonConfig()
->getMock();
$priceInfoMock->expects($this->any())
->method('getPrice')
->willReturnMap([
['regular_price', $priceMock],
['final_price', $priceMock],
['tier_price', $tierPriceMock],
]);
->willReturnMap(
[
['regular_price', $priceMock],
['final_price', $priceMock],
['tier_price', $tierPriceMock],
]
);

$productMock->expects($this->any())->method('getTypeInstance')->willReturn($productTypeMock);
$productMock->expects($this->any())->method('getPriceInfo')->willReturn($priceInfoMock);
$productMock->expects($this->any())->method('isSaleable')->willReturn(true);
$productMock->expects($this->any())->method('getId')->willReturn($productId);
$productMock->expects($this->any())->method('getStatus')
->willReturn(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);

$this->helper->expects($this->any())
->method('getOptions')
->with($productMock, [$productMock])
->willReturn([]);
$this->product->expects($this->any())->method('getSkipSaleableCheck')->willReturn(true);

$attributesData = [
'attributes' => [],
Expand Down Expand Up @@ -421,9 +420,7 @@ private function getProductTypeMock(\PHPUnit_Framework_MockObject_MockObject $pr
->willReturn('%s');

$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
->setMethods([
'getCurrentCurrency',
])
->setMethods(['getCurrentCurrency'])
->getMockForAbstractClass();
$storeMock->expects($this->any())
->method('getCurrentCurrency')
Expand Down Expand Up @@ -475,10 +472,7 @@ protected function mockContextObject()
protected function getAmountMock($amount): \PHPUnit_Framework_MockObject_MockObject
{
$amountMock = $this->getMockBuilder(\Magento\Framework\Pricing\Amount\AmountInterface::class)
->setMethods([
'getValue',
'getBaseAmount',
])
->setMethods(['getValue', 'getBaseAmount'])
->getMockForAbstractClass();
$amountMock->expects($this->any())
->method('getValue')
Expand Down Expand Up @@ -506,10 +500,7 @@ protected function getTierPriceMock(\PHPUnit_Framework_MockObject_MockObject $am
];

$tierPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\TierPriceInterface::class)
->setMethods([
'getTierPriceList',
'getSavePercent',
])
->setMethods(['getTierPriceList', 'getSavePercent'])
->getMockForAbstractClass();
$tierPriceMock->expects($this->any())
->method('getTierPriceList')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

<!-- Save product -->
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>

<!-- Find downloadable product in grid -->
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminOrderFormConfigureProductSection">
<element name="configure" type="button" selector="//a[@product_id='{{productId}}']" parameterized="true"/>
<element name="optionSelect" type="select" selector="//div[contains(@class,'product-options')]//select[//label[text() = '{{option}}']]" parameterized="true"/>
<element name="optionSelectNew" type="select" selector="//label[text()='{{option1}}']/following-sibling::div/select" parameterized="true"/>
<element name="quantity" type="input" selector="#product_composite_configure_input_qty"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
<createData entity="SimpleProduct" stepKey="simpleProduct2">
<requiredEntity createDataKey="categorySecond"/>
</createData>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
<createData entity="Simple_US_Customer" stepKey="customer"/>
</before>
<after>
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
<deleteData createDataKey="categoryFirst" stepKey="deleteCategoryFirst"/>
<deleteData createDataKey="categorySecond" stepKey="deleteCategorySecond"/>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
<deleteData createDataKey="customer" stepKey="deleteCustomer"/>
</after>
<!-- Sign in as customer -->
Expand Down

0 comments on commit e90ddc6

Please sign in to comment.