Skip to content

Commit 91aa22b

Browse files
committed
Merge remote-tracking branch 'github-magento/MAGETWO-91628' into EPAM-PR-16
2 parents 672ca58 + 3370c81 commit 91aa22b

File tree

9 files changed

+197
-13
lines changed

9 files changed

+197
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
736736
$price = $product->getPriceModel()
737737
->getSelectionFinalTotalPrice($product, $selection, 0, $qty);
738738
$attributes = [
739-
'price' => $this->priceCurrency->convert($price),
739+
'price' => $price,
740740
'qty' => $qty,
741741
'option_label' => $selection->getOption()
742742
->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: 0 additions & 12 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
}

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>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
11+
<page name="ConfigCurrencySetupPage" url="admin/system_config/edit/section/currency" area="admin" module="Magento_Config">
12+
</page>
13+
</pages>
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 © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="CurrencySetupSection">
12+
<element name="allowCurrencies" type="select" selector="#currency_options_allow"/>
13+
<element name="currencyOptions" type="select" selector="#currency_options-head"/>
14+
</section>
15+
</sections>

0 commit comments

Comments
 (0)