Skip to content

Commit

Permalink
Merge pull request #3492 from magento-tsg/2.2-develop-pr59
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.2 (pr59) (2.2.8)
  • Loading branch information
xmav authored Nov 30, 2018
2 parents 65c9a58 + 398d1f1 commit 3dd49b7
Show file tree
Hide file tree
Showing 27 changed files with 434 additions and 54 deletions.
39 changes: 19 additions & 20 deletions app/code/Magento/Backend/Model/AdminPathConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,38 @@ public function __construct(
}

/**
* {@inheritdoc}
*
* @param \Magento\Framework\App\RequestInterface $request
* @return string
* @inheritdoc
*/
public function getCurrentSecureUrl(\Magento\Framework\App\RequestInterface $request)
{
return $this->url->getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
}

/**
* {@inheritdoc}
*
* @param string $path
* @return bool
* @inheritdoc
*/
public function shouldBeSecure($path)
{
return parse_url(
(string)$this->coreConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default'),
PHP_URL_SCHEME
) === 'https'
|| $this->backendConfig->isSetFlag(Store::XML_PATH_SECURE_IN_ADMINHTML)
&& parse_url(
(string)$this->coreConfig->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default'),
PHP_URL_SCHEME
) === 'https';
$baseUrl = (string)$this->coreConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default');
if (parse_url($baseUrl, PHP_URL_SCHEME) === 'https') {
return true;
}

if ($this->backendConfig->isSetFlag(Store::XML_PATH_SECURE_IN_ADMINHTML)) {
if ($this->backendConfig->isSetFlag('admin/url/use_custom')) {
$adminBaseUrl = (string)$this->coreConfig->getValue('admin/url/custom', 'default');
} else {
$adminBaseUrl = (string)$this->coreConfig->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default');
}

return parse_url($adminBaseUrl, PHP_URL_SCHEME) === 'https';
}

return false;
}

/**
* {@inheritdoc}
*
* @return string
* @inheritdoc
*/
public function getDefaultPath()
{
Expand Down
44 changes: 31 additions & 13 deletions app/code/Magento/Backend/Test/Unit/Model/AdminPathConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,35 @@ public function testGetCurrentSecureUrl()
* @param $unsecureBaseUrl
* @param $useSecureInAdmin
* @param $secureBaseUrl
* @param $useCustomUrl
* @param $customUrl
* @param $expected
* @dataProvider shouldBeSecureDataProvider
*/
public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected)
{
$coreConfigValueMap = [
public function testShouldBeSecure(
$unsecureBaseUrl,
$useSecureInAdmin,
$secureBaseUrl,
$useCustomUrl,
$customUrl,
$expected
) {
$coreConfigValueMap = $this->returnValueMap([
[\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl],
[\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl],
];
$this->coreConfig->expects($this->any())->method('getValue')->will($this->returnValueMap($coreConfigValueMap));
$this->backendConfig->expects($this->any())->method('isSetFlag')->willReturn($useSecureInAdmin);
['admin/url/custom', 'default', null, $customUrl],
]);
$backendConfigFlagsMap = $this->returnValueMap([
[\Magento\Store\Model\Store::XML_PATH_SECURE_IN_ADMINHTML, $useSecureInAdmin],
['admin/url/use_custom', $useCustomUrl],
]);
$this->coreConfig->expects($this->atLeast(1))->method('getValue')
->will($coreConfigValueMap);
$this->coreConfig->expects($this->atMost(2))->method('getValue')
->will($coreConfigValueMap);

$this->backendConfig->expects($this->atMost(2))->method('isSetFlag')
->will($backendConfigFlagsMap);
$this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure(''));
}

Expand All @@ -96,13 +114,13 @@ public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureB
public function shouldBeSecureDataProvider()
{
return [
['http://localhost/', false, 'default', false],
['http://localhost/', true, 'default', false],
['https://localhost/', false, 'default', true],
['https://localhost/', true, 'default', true],
['http://localhost/', false, 'https://localhost/', false],
['http://localhost/', true, 'https://localhost/', true],
['https://localhost/', true, 'https://localhost/', true],
['http://localhost/', false, 'default', false, '', false],
['http://localhost/', true, 'default', false, '', false],
['https://localhost/', false, 'default', false, '', true],
['https://localhost/', true, 'default', false, '', true],
['http://localhost/', false, 'https://localhost/', false, '', false],
['http://localhost/', true, 'https://localhost/', false, '', true],
['https://localhost/', true, 'https://localhost/', false, '', true],
];
}

Expand Down
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\Model\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): AbstractItem
{
$bundleAttributes = $result->getProduct()->getCustomOption('bundle_selection_attributes');
if ($bundleAttributes !== null) {
$actualAmount = $result->getPrice() * $result->getQty();
$parsedValue = $this->serializer->unserialize($bundleAttributes->getValue());
if (is_array($parsedValue) && array_key_exists('price', $parsedValue)) {
$parsedValue['price'] = $actualAmount;
}
$bundleAttributes->setValue($this->serializer->serialize($parsedValue));
}

return $result;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,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
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
<click selector="{{AdminProductGridActionSection.addBundleProduct}}" stepKey="goToNewBundleProductPage"/>
</actionGroup>

<actionGroup name="CreateBundleProductForTwoSimpleProductsWithRadioTypeOptions" extends="CreateBundleProductForTwoSimpleProducts">
<selectOption selector="{{AdminProductFormBundleSection.bundleOptionXInputType('0')}}" userInput="Radio Buttons" after="fillOptionTitle" stepKey="selectInputType"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,20 @@
<waitForText userInput="{{quantity}}" selector="{{StorefrontMinicartSection.productCount}}" time="30" stepKey="assertProductCount"/>
<see userInput="You added {{product.name}} to your shopping cart." selector="{{StorefrontMessagesSection.success}}" stepKey="seeSuccessMessage"/>
</actionGroup>
<!-- Add Bundle Product to Cart with specified currency -->
<actionGroup name="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup">
<arguments>
<argument name="product"/>
<argument name="currency" type="string" defaultValue="US Dollar"/>
</arguments>
<click selector="{{StorefrontHeaderCurrencySwitcherSection.currencyTrigger}}" stepKey="openCurrencyTrigger"/>
<click selector="{{StorefrontHeaderCurrencySwitcherSection.currency(currency)}}" stepKey="chooseCurrency"/>
<waitForPageLoad stepKey="waitForCurrencyChange"/>
<click selector="{{StorefrontBundledSection.addToCart}}" stepKey="clickCustomize"/>
<waitForPageLoad stepKey="waitForBundleOpen"/>
<checkOption selector="{{StorefrontBundledSection.bundleOptionByName(product.name)}}" stepKey="chooseProduct"/>
<click selector="{{StorefrontBundledSection.addToCartConfigured}}" stepKey="addToCartProduct"/>
<waitForAjaxLoad stepKey="waitForLoad"/>
<scrollToTopOfPage stepKey="scrollToTop"/>
</actionGroup>
</actionGroups>
2 changes: 2 additions & 0 deletions app/code/Magento/Bundle/Test/Mftf/Data/BundleProductData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<data key="name" unique="suffix">BundleProduct</data>
<data key="sku" unique="suffix">BundleProduct</data>
<data key="status">1</data>
<data key="set">4</data>
<data key="type">bundle</data>
<data key="urlKey" unique="suffix">bundleproduct</data>
<data key="visibility">4</data>
<data key="option_title" unique="suffix">TestOption</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
<section name="StorefrontBundledSection">
<element name="bundleOption" type="input" selector=".option:nth-of-type({{numOption}}) .choice:nth-of-type({{numOptionSelect}}) input" parameterized="true"/>
<element name="bundleOptionByName" type="input" selector="//div[@class='field choice']//span[@class='product-name'][contains(text(),'{{name}}')]/../../../input" parameterized="true"/>
<element name="addToCart" type="button" selector="#bundle-slide" timeout="30"/>
<element name="addToCartConfigured" type="button" selector="#product-addtocart-button" timeout="30"/>
<element name="updateCart" type="button" selector="#product-updatecart-button" timeout="30"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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="MAGETWO-90381: Bundle product price doubled when switching currency"/>
<title value="Work of currency changing with a 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-96305"/>
<group value="Bundle"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="login" />
<createData entity="CurrencySettingWithEuroAndUSD" stepKey="configureCurrencyOptions"/>
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
<createData entity="SimpleProduct" stepKey="createPreReqSimpleProduct1">
<requiredEntity createDataKey="createPreReqCategory"/>
</createData>
<createData entity="SimpleProduct2" stepKey="createPreReqSimpleProduct2">
<requiredEntity createDataKey="createPreReqCategory"/>
</createData>
</before>
<after>
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
<deleteData createDataKey="createPreReqSimpleProduct1" stepKey="deletePreReqSimpleProduct1"/>
<deleteData createDataKey="createPreReqSimpleProduct2" stepKey="deletePreReqSimpleProduct2"/>
<createData entity="DefaultCurrencySetting" stepKey="restoreCurrencyOptions"/>
<!-- Delete the bundled product -->
<actionGroup ref="deleteProductUsingProductGrid" stepKey="deleteProductOnProductsGridPageByName">
<argument name="product" value="BundleProduct"/>
</actionGroup>
<!--Clear Configs-->
<actionGroup ref="logout" stepKey="logout"/>
</after>
<!-- Navigate to the Products>Inventory>Catalog -->
<!-- Click on "+" dropdown and select Bundle Product type -->
<actionGroup ref="OpenNewBundleProductPage" stepKey="openNewBundleProductPage"/>
<!-- Add Option, a "Radio Buttons" type option -->
<actionGroup ref="CreateBundleProductForTwoSimpleProductsWithRadioTypeOptions" stepKey="addBundleOptionWithTwoProducts2">
<argument name="bundleProduct" value="BundleProduct"/>
<argument name="simpleProductFirst" value="$$createPreReqSimpleProduct1$$"/>
<argument name="simpleProductSecond" value="$$createPreReqSimpleProduct2$$"/>
</actionGroup>
<!-- Save product -->
<actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProductOnProductPageOnAdmin"/>
<!-- Go to storefront BundleProduct -->
<amOnPage url="{{StorefrontProductPage.url(BundleProduct.name)}}" stepKey="goToStorefrontProductPage"/>
<waitForPageLoad stepKey="waitForStorefrontProductPage"/>
<actionGroup ref="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup" stepKey="addProduct1ToCartAndChangeCurrencyToEuro">
<argument name="product" value="$$createPreReqSimpleProduct1$$"/>
<argument name="currency" value="EUR - Euro"/>
</actionGroup>
<actionGroup ref="StoreFrontAddProductToCartFromBundleWithCurrencyActionGroup" stepKey="addProduct2ToCartAndChangeCurrencyToUSD">
<argument name="product" value="$$createPreReqSimpleProduct1$$"/>
<argument name="currency" value="USD - US Dollar"/>
</actionGroup>
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="openMiniCart"/>
<waitForPageLoad stepKey="waitForMiniCart"/>
<see selector="{{StorefrontMinicartSection.miniCartSubtotalField}}" userInput="$4,000.00" stepKey="seeCartSubtotal"/>
</test>
</tests>
Loading

0 comments on commit 3dd49b7

Please sign in to comment.