Skip to content

Commit 7a73fb6

Browse files
committed
Merge branch 'MC-22856' of https://github.com/magento-mpi/magento2ce into PR-2019-12-02
2 parents 7ddca4b + 9fc4086 commit 7a73fb6

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StorefrontCheckoutDisabledBundleProductTest">
11+
<annotations>
12+
<features value="Checkout"/>
13+
<stories value="Disabled bundle product is preventing customer to checkout for the first attempt"/>
14+
<title value="Customer should be able to checkout if there is at least one available product in the cart"/>
15+
<description value="Customer should be able to checkout if there is at least one available product in the cart"/>
16+
<severity value="MINOR"/>
17+
<testCaseId value="MC-29105"/>
18+
<group value="checkout"/>
19+
</annotations>
20+
21+
<before>
22+
<!-- Create category and simple product -->
23+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
24+
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
25+
<requiredEntity createDataKey="createCategory"/>
26+
</createData>
27+
<!-- Create bundle product -->
28+
<createData entity="ApiBundleProductPriceViewRange" stepKey="createBundleDynamicProduct">
29+
<requiredEntity createDataKey="createCategory"/>
30+
</createData>
31+
<createData entity="DropDownBundleOption" stepKey="bundleOption">
32+
<requiredEntity createDataKey="createBundleDynamicProduct"/>
33+
</createData>
34+
<createData entity="ApiBundleLink" stepKey="createNewBundleLink">
35+
<requiredEntity createDataKey="createBundleDynamicProduct"/>
36+
<requiredEntity createDataKey="bundleOption"/>
37+
<requiredEntity createDataKey="createSimpleProduct"/>
38+
</createData>
39+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
40+
<magentoCLI command="cache:flush" stepKey="cacheFlush"/>
41+
</before>
42+
<after>
43+
<!-- Delete category -->
44+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
45+
<!-- Delete bundle product data -->
46+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
47+
<deleteData createDataKey="createBundleDynamicProduct" stepKey="deleteBundleProduct"/>
48+
</after>
49+
<!-- Add simple product to the cart -->
50+
<actionGroup ref="AddSimpleProductToCart" stepKey="cartAddSimpleProductToCart">
51+
<argument name="product" value="$$createSimpleProduct$$"/>
52+
<argument name="productCount" value="1"/>
53+
</actionGroup>
54+
<!-- Go to bundle product page -->
55+
<amOnPage url="{{StorefrontProductPage.url($$createBundleDynamicProduct.custom_attributes[url_key]$$)}}" stepKey="navigateToProductPage"/>
56+
<waitForPageLoad stepKey="waitForPageLoad"/>
57+
<!-- Add bundle product to the cart -->
58+
<click selector="{{StorefrontBundleProductActionSection.customizeAndAddToCartButton}}" stepKey="clickCustomizeAndAddToCart"/>
59+
<actionGroup ref="addToCartFromStorefrontProductPage" stepKey="addProductToCart">
60+
<argument name="productName" value="$$createBundleDynamicProduct.name$$"/>
61+
</actionGroup>
62+
<!-- Login to admin panel -->
63+
<openNewTab stepKey="openNewTab"/>
64+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
65+
<!-- Find the first simple product that we just created using the product grid and go to its page-->
66+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/>
67+
<!-- Disabled bundle product from grid -->
68+
<actionGroup ref="ChangeStatusProductUsingProductGridActionGroup" stepKey="disabledProductFromGrid">
69+
<argument name="product" value="$$createBundleDynamicProduct$$"/>
70+
<argument name="status" value="Disable"/>
71+
</actionGroup>
72+
<closeTab stepKey="closeTab"/>
73+
<!-- Go to cart page-->
74+
<actionGroup ref="StorefrontOpenCartPageActionGroup" stepKey="openCartPage"/>
75+
<!-- Assert checkout button exists on the page-->
76+
<seeElement selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="seeCheckoutButton"/>
77+
<!-- Assert no error message is not shown on the page-->
78+
<dontSee userInput="Some of the products are out of stock." stepKey="seeNoItemsInShoppingCart"/>
79+
</test>
80+
</tests>

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
1212
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
13+
use Magento\Framework\Exception\NoSuchEntityException;
1314
use Magento\Quote\Model\Quote;
1415
use Magento\Quote\Model\Quote\Item as QuoteItem;
1516
use Magento\Quote\Model\ResourceModel\Quote\Item as ResourceQuoteItem;
@@ -256,8 +257,17 @@ protected function _assignProducts(): self
256257
foreach ($this as $item) {
257258
/** @var ProductInterface $product */
258259
$product = $productCollection->getItemById($item->getProductId());
260+
try {
261+
/** @var QuoteItem $item */
262+
$parentItem = $item->getParentItem();
263+
$parentProduct = $parentItem ? $parentItem->getProduct() : null;
264+
} catch (NoSuchEntityException $exception) {
265+
$parentItem = null;
266+
$parentProduct = null;
267+
$this->_logger->error($exception);
268+
}
259269
$qtyOptions = [];
260-
if ($product && $this->isValidProduct($product)) {
270+
if ($this->isValidProduct($product) && (!$parentItem || $this->isValidProduct($parentProduct))) {
261271
$product->setCustomOptions([]);
262272
$optionProductIds = $this->getOptionProductIds($item, $product, $productCollection);
263273
foreach ($optionProductIds as $optionProductId) {
@@ -327,7 +337,7 @@ private function getOptionProductIds(
327337
* @param ProductInterface $product
328338
* @return bool
329339
*/
330-
private function isValidProduct(ProductInterface $product): bool
340+
private function isValidProduct(?ProductInterface $product): bool
331341
{
332342
$result = ($product && (int)$product->getStatus() !== ProductStatus::STATUS_DISABLED);
333343

0 commit comments

Comments
 (0)