Skip to content

Commit

Permalink
Merge pull request #3432 from magento-epam/EPAM-PR-16
Browse files Browse the repository at this point in the history
[epam] MAGETWO-67269: Gift Options set to no still show up as choices on front end order page
  • Loading branch information
rganin authored Nov 9, 2018
2 parents 6481cec + 33c2552 commit 072ef37
Show file tree
Hide file tree
Showing 63 changed files with 1,409 additions and 79 deletions.
9 changes: 6 additions & 3 deletions app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ public function getSku($product)
$selectionIds = $this->serializer->unserialize($customOption->getValue());
if (!empty($selectionIds)) {
$selections = $this->getSelectionsByIds($selectionIds, $product);
foreach ($selections->getItems() as $selection) {
$skuParts[] = $selection->getSku();
foreach ($selectionIds as $selectionId) {
$entity = $selections->getItemByColumnValue('selection_id', $selectionId);
if (isset($entity) && $entity->getEntityId()) {
$skuParts[] = $entity->getSku();
}
}
}
}
Expand Down Expand Up @@ -736,7 +739,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
$price = $product->getPriceModel()
->getSelectionFinalTotalPrice($product, $selection, 0, $qty);
$attributes = [
'price' => $this->priceCurrency->convert($price),
'price' => $price,
'qty' => $qty,
'option_label' => $selection->getOption()
->getTitle(),
Expand Down
55 changes: 55 additions & 0 deletions app/code/Magento/Bundle/Plugin/UpdatePriceInQuoteItemOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Plugin;

use Magento\Quote\Model\Quote\Item as OrigQuoteItem;
use Magento\Quote\Model\Quote\Item\AbstractItem;
use Magento\Framework\Serialize\SerializerInterface;

/**
* Update prices stored in quote item options after calculating quote item's totals
*/
class UpdatePriceInQuoteItemOptions
{
/**
* @var SerializerInterface
*/
private $serializer;

/**
* @param SerializerInterface $serializer
*/
public function __construct(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}

/**
* Update price on quote item options level
*
* @param OrigQuoteItem $subject
* @param AbstractItem $result
* @return AbstractItem
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterCalcRowTotal(OrigQuoteItem $subject, AbstractItem $result)
{
$bundleAttributes = $result->getProduct()->getCustomOption('bundle_selection_attributes');
if ($bundleAttributes !== null) {
$actualPrice = $result->getPrice();
$parsedValue = $this->serializer->unserialize($bundleAttributes->getValue());
if (is_array($parsedValue) && array_key_exists('price', $parsedValue)) {
$parsedValue['price'] = $actualPrice;
}
$bundleAttributes->setValue($this->serializer->serialize($parsedValue));
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup">
<arguments>
<argument name="product"/>
<argument name="currency" type="string" defaultValue="US Dollar"/>
</arguments>
<click selector="{{StorefrontBundledSection.currencyTrigger}}" stepKey="openCurrencyTrigger"/>
<click selector="{{StorefrontBundledSection.currency(currency)}}" stepKey="chooseCurrency"/>
<click selector="{{StorefrontBundledSection.addToCart}}" stepKey="clickCustomize"/>
<waitForPageLoad stepKey="waitForBundleOpen"/>
<checkOption selector="{{StorefrontBundledSection.productInBundle(product.name)}}" stepKey="chooseProduct"/>
<click selector="{{StorefrontBundledSection.addToCartConfigured}}" stepKey="addToCartProduct"/>
<scrollToTopOfPage stepKey="scrollToTop"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
<element name="bundleProductName" type="text" selector="//*[@id='maincontent']//span[@itemprop='name']"/>
<element name="pageNotFound" type="text" selector="//h1[@class='page-title']//span[contains(., 'Whoops, our bad...')]"/>
<element name="dropDownOptionOneProducts" type="select" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//select" parameterized="true"/>
<element name="productInBundle" type="select" selector="//label//span[contains(text(), '{{productName}}')]" parameterized="true"/>
<element name="dropDownOptionOneQuantity" type="input" selector="//span[contains(text(), '{{productName}}')]/../..//input" parameterized="true"/>
<element name="radioButtonOptionTwoProducts" type="checkbox" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//div[@class='field choice'][{{productNumber}}]/input" parameterized="true"/>
<element name="radioButtonOptionTwoQuantity" type="input" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//div[@class='field qty qty-holder']//input" parameterized="true"/>
<element name="checkboxOptionThreeProducts" type="checkbox" selector="//label//span[contains(text(), '{{productName}}')]/../..//div[@class='control']//div[@class='field choice'][{{productNumber}}]/input" parameterized="true"/>
<element name="multiselectOptionFourProducts" type="multiselect" selector="//label//span[contains(text(), '{{productName}}')]/../..//select[@multiple='multiple']" parameterized="true"/>
<element name="currencyTrigger" type="select" selector="#switcher-currency-trigger" timeout="30"/>
<element name="currency" type="select" selector="//a[text()='{{arg}}']" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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="CurrencyChangingBundleProductInCartTest">
<annotations>
<features value="Bundle"/>
<stories value="Check that after changing currency price of cart is correct when the bundle product added to the cart"/>
<title value="User should be able change the currency and get right price in cart when the bundle product added to the cart"/>
<description value="User should be able change the currency and add one more product in cart and get right price in previous currency"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-94467"/>
<group value="Bundle"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="login"/>
<createData entity="SimpleProduct2" stepKey="simpleProduct1"/>
<createData entity="SimpleProduct2" stepKey="simpleProduct2"/>
</before>
<after>
<!-- Delete the bundled product -->
<actionGroup stepKey="deleteBundle" ref="deleteProductUsingProductGrid">
<argument name="product" value="BundleProduct"/>
</actionGroup>
<actionGroup ref="AdminClearFiltersActionGroup" stepKey="ClearFiltersAfter"/>
<waitForPageLoad stepKey="waitForClearFilter"/>
<!--Clear Configs-->
<amOnPage url="{{AdminLoginPage.url}}" stepKey="navigateToAdmin"/>
<waitForPageLoad stepKey="waitForAdminLoginPageLoad"/>
<amOnPage url="{{ConfigCurrencySetupPage.url}}" stepKey="navigateToConfigCurrencySetupPage"/>
<waitForPageLoad stepKey="waitForConfigCurrencySetupPageForUnselectEuroCurrency"/>
<unselectOption selector="{{CurrencySetupSection.allowCurrencies}}" userInput="Euro" stepKey="unselectEuro"/>
<scrollToTopOfPage stepKey="scrollToTopOfPage"/>
<click selector="{{CurrencySetupSection.currencyOptions}}" stepKey="closeOptions"/>
<waitForPageLoad stepKey="waitForCloseOptions"/>
<click stepKey="saveUnselectedConfigs" selector="{{AdminConfigSection.saveButton}}"/>
<amOnPage url="{{AdminLogoutPage.url}}" stepKey="logout"/>
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
</after>
<!--Go to bundle product creation page-->
<amOnPage url="{{AdminProductCreatePage.url(BundleProduct.set, BundleProduct.type)}}" stepKey="goToBundleProductCreationPage"/>
<waitForPageLoad stepKey="waitForBundleProductCreatePageToLoad"/>
<actionGroup ref="fillMainBundleProductForm" stepKey="fillMainFieldsForBundle"/>
<!-- Add Option, a "Radio Buttons" type option -->
<actionGroup ref="addBundleOptionWithTwoProducts" stepKey="addBundleOptionWithTwoProducts2">
<argument name="x" value="0"/>
<argument name="n" value="1"/>
<argument name="prodOneSku" value="$$simpleProduct1.sku$$"/>
<argument name="prodTwoSku" value="$$simpleProduct2.sku$$"/>
<argument name="optionTitle" value="Option"/>
<argument name="inputType" value="radio"/>
</actionGroup>
<checkOption selector="{{AdminProductFormBundleSection.userDefinedQuantity('0', '0')}}" stepKey="userDefinedQuantitiyOptionProduct0"/>
<checkOption selector="{{AdminProductFormBundleSection.userDefinedQuantity('0', '1')}}" stepKey="userDefinedQuantitiyOptionProduct1"/>
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
<amOnPage url="{{ConfigCurrencySetupPage.url}}" stepKey="navigateToConfigCurrencySetupPage"/>
<waitForPageLoad stepKey="waitForConfigCurrencySetupPage"/>
<conditionalClick selector="{{CurrencySetupSection.currencyOptions}}" dependentSelector="{{CurrencySetupSection.allowCurrencies}}" visible="false" stepKey="openOptions"/>
<waitForPageLoad stepKey="waitForOptions"/>
<selectOption selector="{{CurrencySetupSection.allowCurrencies}}" parameterArray="['Euro', 'US Dollar']" stepKey="selectCurrencies"/>
<click stepKey="saveConfigs" selector="{{AdminConfigSection.saveButton}}"/>
<!-- Go to storefront BundleProduct -->
<amOnPage url="{{BundleProduct.sku}}.html" stepKey="goToStorefront"/>
<waitForPageLoad stepKey="waitForStorefront"/>
<actionGroup ref="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup" stepKey="addProduct1ToCartAndChangeCurrencyToEuro">
<argument name="product" value="$$simpleProduct1$$"/>
<argument name="currency" value="EUR - Euro"/>
</actionGroup>
<actionGroup ref="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup" stepKey="addProduct2ToCartAndChangeCurrencyToUSD">
<argument name="product" value="$$simpleProduct2$$"/>
<argument name="currency" value="USD - US Dollar"/>
</actionGroup>
<click stepKey="openMiniCart" selector="{{StorefrontMinicartSection.showCart}}"/>
<waitForPageLoad stepKey="waitForMiniCart"/>
<see stepKey="seeCartSubtotal" userInput="$12,300.00"/>
</test>
</tests>
23 changes: 7 additions & 16 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,6 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('getSelectionId')
->willReturn(314);

$this->priceCurrency->expects($this->once())
->method('convert')
->willReturn(3.14);

$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
$this->assertEquals([$product, $productType], $result);
}
Expand Down Expand Up @@ -737,10 +733,6 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('prepareForCart')
->willReturn([]);

$this->priceCurrency->expects($this->once())
->method('convert')
->willReturn(3.14);

$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
$this->assertEquals('We can\'t add this item to your shopping cart right now.', $result);
}
Expand Down Expand Up @@ -961,10 +953,6 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('prepareForCart')
->willReturn('string');

$this->priceCurrency->expects($this->once())
->method('convert')
->willReturn(3.14);

$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
$this->assertEquals('string', $result);
}
Expand Down Expand Up @@ -1595,7 +1583,7 @@ public function testGetSkuWithoutType()
->disableOriginalConstructor()
->getMock();
$selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
->setMethods(['getSku', '__wakeup'])
->setMethods(['getSku', 'getEntityId', '__wakeup'])
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -1623,9 +1611,12 @@ public function testGetSkuWithoutType()
->will($this->returnValue($serializeIds));
$selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6);
$selectionMock->expects(($this->any()))
->method('getItems')
->will($this->returnValue([$selectionItemMock]));
$selectionItemMock->expects($this->any())
->method('getItemByColumnValue')
->will($this->returnValue($selectionItemMock));
$selectionItemMock->expects($this->at(0))
->method('getEntityId')
->will($this->returnValue(1));
$selectionItemMock->expects($this->once())
->method('getSku')
->will($this->returnValue($itemSku));

Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Quote\Model\Quote\Item">
<plugin name="update_price_for_bundle_in_quote_item_option" type="Magento\Bundle\Plugin\UpdatePriceInQuoteItemOptions"/>
</type>
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
<plugin name="append_bundle_data_to_order" type="Magento\Bundle\Model\Plugin\QuoteItem"/>
</type>
Expand Down
Loading

0 comments on commit 072ef37

Please sign in to comment.