Skip to content

Commit 072ef37

Browse files
authored
Merge pull request #3432 from magento-epam/EPAM-PR-16
[epam] MAGETWO-67269: Gift Options set to no still show up as choices on front end order page
2 parents 6481cec + 33c2552 commit 072ef37

File tree

63 files changed

+1409
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1409
-79
lines changed

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,11 @@ public function getSku($product)
308308
$selectionIds = $this->serializer->unserialize($customOption->getValue());
309309
if (!empty($selectionIds)) {
310310
$selections = $this->getSelectionsByIds($selectionIds, $product);
311-
foreach ($selections->getItems() as $selection) {
312-
$skuParts[] = $selection->getSku();
311+
foreach ($selectionIds as $selectionId) {
312+
$entity = $selections->getItemByColumnValue('selection_id', $selectionId);
313+
if (isset($entity) && $entity->getEntityId()) {
314+
$skuParts[] = $entity->getSku();
315+
}
313316
}
314317
}
315318
}
@@ -736,7 +739,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
736739
$price = $product->getPriceModel()
737740
->getSelectionFinalTotalPrice($product, $selection, 0, $qty);
738741
$attributes = [
739-
'price' => $this->priceCurrency->convert($price),
742+
'price' => $price,
740743
'qty' => $qty,
741744
'option_label' => $selection->getOption()
742745
->getTitle(),
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\Bundle\Plugin;
9+
10+
use Magento\Quote\Model\Quote\Item as OrigQuoteItem;
11+
use Magento\Quote\Model\Quote\Item\AbstractItem;
12+
use Magento\Framework\Serialize\SerializerInterface;
13+
14+
/**
15+
* Update prices stored in quote item options after calculating quote item's totals
16+
*/
17+
class UpdatePriceInQuoteItemOptions
18+
{
19+
/**
20+
* @var SerializerInterface
21+
*/
22+
private $serializer;
23+
24+
/**
25+
* @param SerializerInterface $serializer
26+
*/
27+
public function __construct(SerializerInterface $serializer)
28+
{
29+
$this->serializer = $serializer;
30+
}
31+
32+
/**
33+
* Update price on quote item options level
34+
*
35+
* @param OrigQuoteItem $subject
36+
* @param AbstractItem $result
37+
* @return AbstractItem
38+
*
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterCalcRowTotal(OrigQuoteItem $subject, AbstractItem $result)
42+
{
43+
$bundleAttributes = $result->getProduct()->getCustomOption('bundle_selection_attributes');
44+
if ($bundleAttributes !== null) {
45+
$actualPrice = $result->getPrice();
46+
$parsedValue = $this->serializer->unserialize($bundleAttributes->getValue());
47+
if (is_array($parsedValue) && array_key_exists('price', $parsedValue)) {
48+
$parsedValue['price'] = $actualPrice;
49+
}
50+
$bundleAttributes->setValue($this->serializer->serialize($parsedValue));
51+
}
52+
53+
return $result;
54+
}
55+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup">
12+
<arguments>
13+
<argument name="product"/>
14+
<argument name="currency" type="string" defaultValue="US Dollar"/>
15+
</arguments>
16+
<click selector="{{StorefrontBundledSection.currencyTrigger}}" stepKey="openCurrencyTrigger"/>
17+
<click selector="{{StorefrontBundledSection.currency(currency)}}" stepKey="chooseCurrency"/>
18+
<click selector="{{StorefrontBundledSection.addToCart}}" stepKey="clickCustomize"/>
19+
<waitForPageLoad stepKey="waitForBundleOpen"/>
20+
<checkOption selector="{{StorefrontBundledSection.productInBundle(product.name)}}" stepKey="chooseProduct"/>
21+
<click selector="{{StorefrontBundledSection.addToCartConfigured}}" stepKey="addToCartProduct"/>
22+
<scrollToTopOfPage stepKey="scrollToTop"/>
23+
</actionGroup>
24+
</actionGroups>

app/code/Magento/Bundle/Test/Mftf/Section/StorefrontBundledSection.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
<element name="bundleProductName" type="text" selector="//*[@id='maincontent']//span[@itemprop='name']"/>
2525
<element name="pageNotFound" type="text" selector="//h1[@class='page-title']//span[contains(., 'Whoops, our bad...')]"/>
2626
<element name="dropDownOptionOneProducts" type="select" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//select" parameterized="true"/>
27+
<element name="productInBundle" type="select" selector="//label//span[contains(text(), '{{productName}}')]" parameterized="true"/>
2728
<element name="dropDownOptionOneQuantity" type="input" selector="//span[contains(text(), '{{productName}}')]/../..//input" parameterized="true"/>
2829
<element name="radioButtonOptionTwoProducts" type="checkbox" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//div[@class='field choice'][{{productNumber}}]/input" parameterized="true"/>
2930
<element name="radioButtonOptionTwoQuantity" type="input" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//div[@class='field qty qty-holder']//input" parameterized="true"/>
3031
<element name="checkboxOptionThreeProducts" type="checkbox" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//div[@class='field choice'][{{productNumber}}]/input" parameterized="true"/>
3132
<element name="multiselectOptionFourProducts" type="multiselect" selector="//label//span[contains(text(), '{{productName}}')]/../..//select[@multiple='multiple']" parameterized="true"/>
33+
<element name="currencyTrigger" type="select" selector="#switcher-currency-trigger" timeout="30"/>
34+
<element name="currency" type="select" selector="//a[text()='{{arg}}']" parameterized="true"/>
3235
</section>
3336
</sections>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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="CurrencyChangingBundleProductInCartTest">
11+
<annotations>
12+
<features value="Bundle"/>
13+
<stories value="Check that after changing currency price of cart is correct when the bundle product added to the cart"/>
14+
<title value="User should be able change the currency and get right price in cart when the bundle product added to the cart"/>
15+
<description value="User should be able change the currency and add one more product in cart and get right price in previous currency"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MAGETWO-94467"/>
18+
<group value="Bundle"/>
19+
</annotations>
20+
<before>
21+
<actionGroup ref="LoginAsAdmin" stepKey="login"/>
22+
<createData entity="SimpleProduct2" stepKey="simpleProduct1"/>
23+
<createData entity="SimpleProduct2" stepKey="simpleProduct2"/>
24+
</before>
25+
<after>
26+
<!-- Delete the bundled product -->
27+
<actionGroup stepKey="deleteBundle" ref="deleteProductUsingProductGrid">
28+
<argument name="product" value="BundleProduct"/>
29+
</actionGroup>
30+
<actionGroup ref="AdminClearFiltersActionGroup" stepKey="ClearFiltersAfter"/>
31+
<waitForPageLoad stepKey="waitForClearFilter"/>
32+
<!--Clear Configs-->
33+
<amOnPage url="{{AdminLoginPage.url}}" stepKey="navigateToAdmin"/>
34+
<waitForPageLoad stepKey="waitForAdminLoginPageLoad"/>
35+
<amOnPage url="{{ConfigCurrencySetupPage.url}}" stepKey="navigateToConfigCurrencySetupPage"/>
36+
<waitForPageLoad stepKey="waitForConfigCurrencySetupPageForUnselectEuroCurrency"/>
37+
<unselectOption selector="{{CurrencySetupSection.allowCurrencies}}" userInput="Euro" stepKey="unselectEuro"/>
38+
<scrollToTopOfPage stepKey="scrollToTopOfPage"/>
39+
<click selector="{{CurrencySetupSection.currencyOptions}}" stepKey="closeOptions"/>
40+
<waitForPageLoad stepKey="waitForCloseOptions"/>
41+
<click stepKey="saveUnselectedConfigs" selector="{{AdminConfigSection.saveButton}}"/>
42+
<amOnPage url="{{AdminLogoutPage.url}}" stepKey="logout"/>
43+
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
44+
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
45+
</after>
46+
<!--Go to bundle product creation page-->
47+
<amOnPage url="{{AdminProductCreatePage.url(BundleProduct.set, BundleProduct.type)}}" stepKey="goToBundleProductCreationPage"/>
48+
<waitForPageLoad stepKey="waitForBundleProductCreatePageToLoad"/>
49+
<actionGroup ref="fillMainBundleProductForm" stepKey="fillMainFieldsForBundle"/>
50+
<!-- Add Option, a "Radio Buttons" type option -->
51+
<actionGroup ref="addBundleOptionWithTwoProducts" stepKey="addBundleOptionWithTwoProducts2">
52+
<argument name="x" value="0"/>
53+
<argument name="n" value="1"/>
54+
<argument name="prodOneSku" value="$$simpleProduct1.sku$$"/>
55+
<argument name="prodTwoSku" value="$$simpleProduct2.sku$$"/>
56+
<argument name="optionTitle" value="Option"/>
57+
<argument name="inputType" value="radio"/>
58+
</actionGroup>
59+
<checkOption selector="{{AdminProductFormBundleSection.userDefinedQuantity('0', '0')}}" stepKey="userDefinedQuantitiyOptionProduct0"/>
60+
<checkOption selector="{{AdminProductFormBundleSection.userDefinedQuantity('0', '1')}}" stepKey="userDefinedQuantitiyOptionProduct1"/>
61+
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
62+
<amOnPage url="{{ConfigCurrencySetupPage.url}}" stepKey="navigateToConfigCurrencySetupPage"/>
63+
<waitForPageLoad stepKey="waitForConfigCurrencySetupPage"/>
64+
<conditionalClick selector="{{CurrencySetupSection.currencyOptions}}" dependentSelector="{{CurrencySetupSection.allowCurrencies}}" visible="false" stepKey="openOptions"/>
65+
<waitForPageLoad stepKey="waitForOptions"/>
66+
<selectOption selector="{{CurrencySetupSection.allowCurrencies}}" parameterArray="['Euro', 'US Dollar']" stepKey="selectCurrencies"/>
67+
<click stepKey="saveConfigs" selector="{{AdminConfigSection.saveButton}}"/>
68+
<!-- Go to storefront BundleProduct -->
69+
<amOnPage url="{{BundleProduct.sku}}.html" stepKey="goToStorefront"/>
70+
<waitForPageLoad stepKey="waitForStorefront"/>
71+
<actionGroup ref="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup" stepKey="addProduct1ToCartAndChangeCurrencyToEuro">
72+
<argument name="product" value="$$simpleProduct1$$"/>
73+
<argument name="currency" value="EUR - Euro"/>
74+
</actionGroup>
75+
<actionGroup ref="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup" stepKey="addProduct2ToCartAndChangeCurrencyToUSD">
76+
<argument name="product" value="$$simpleProduct2$$"/>
77+
<argument name="currency" value="USD - US Dollar"/>
78+
</actionGroup>
79+
<click stepKey="openMiniCart" selector="{{StorefrontMinicartSection.showCart}}"/>
80+
<waitForPageLoad stepKey="waitForMiniCart"/>
81+
<see stepKey="seeCartSubtotal" userInput="$12,300.00"/>
82+
</test>
83+
</tests>

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,6 @@ function ($key) use ($optionCollection, $selectionCollection) {
513513
->method('getSelectionId')
514514
->willReturn(314);
515515

516-
$this->priceCurrency->expects($this->once())
517-
->method('convert')
518-
->willReturn(3.14);
519-
520516
$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
521517
$this->assertEquals([$product, $productType], $result);
522518
}
@@ -737,10 +733,6 @@ function ($key) use ($optionCollection, $selectionCollection) {
737733
->method('prepareForCart')
738734
->willReturn([]);
739735

740-
$this->priceCurrency->expects($this->once())
741-
->method('convert')
742-
->willReturn(3.14);
743-
744736
$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
745737
$this->assertEquals('We can\'t add this item to your shopping cart right now.', $result);
746738
}
@@ -961,10 +953,6 @@ function ($key) use ($optionCollection, $selectionCollection) {
961953
->method('prepareForCart')
962954
->willReturn('string');
963955

964-
$this->priceCurrency->expects($this->once())
965-
->method('convert')
966-
->willReturn(3.14);
967-
968956
$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
969957
$this->assertEquals('string', $result);
970958
}
@@ -1595,7 +1583,7 @@ public function testGetSkuWithoutType()
15951583
->disableOriginalConstructor()
15961584
->getMock();
15971585
$selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
1598-
->setMethods(['getSku', '__wakeup'])
1586+
->setMethods(['getSku', 'getEntityId', '__wakeup'])
15991587
->disableOriginalConstructor()
16001588
->getMock();
16011589

@@ -1623,9 +1611,12 @@ public function testGetSkuWithoutType()
16231611
->will($this->returnValue($serializeIds));
16241612
$selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6);
16251613
$selectionMock->expects(($this->any()))
1626-
->method('getItems')
1627-
->will($this->returnValue([$selectionItemMock]));
1628-
$selectionItemMock->expects($this->any())
1614+
->method('getItemByColumnValue')
1615+
->will($this->returnValue($selectionItemMock));
1616+
$selectionItemMock->expects($this->at(0))
1617+
->method('getEntityId')
1618+
->will($this->returnValue(1));
1619+
$selectionItemMock->expects($this->once())
16291620
->method('getSku')
16301621
->will($this->returnValue($itemSku));
16311622

app/code/Magento/Bundle/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
</argument>
124124
</arguments>
125125
</type>
126+
<type name="Magento\Quote\Model\Quote\Item">
127+
<plugin name="update_price_for_bundle_in_quote_item_option" type="Magento\Bundle\Plugin\UpdatePriceInQuoteItemOptions"/>
128+
</type>
126129
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
127130
<plugin name="append_bundle_data_to_order" type="Magento\Bundle\Model\Plugin\QuoteItem"/>
128131
</type>

0 commit comments

Comments
 (0)