Skip to content

Commit

Permalink
Merge pull request magento#4181 from magento-tsg-csl3/2.2-develop-pr28
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.2 (pr28)
  • Loading branch information
viktym authored May 8, 2019
2 parents d184fce + 1da969f commit b3cf9d1
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/
namespace Magento\Catalog\Model\Product\Attribute\Backend\TierPrice;

use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Locale\FormatInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use Magento\Customer\Api\GroupManagementInterface;
Expand Down Expand Up @@ -38,26 +39,34 @@ class UpdateHandler extends AbstractHandler
*/
private $tierPriceResource;

/**
* @var FormatInterface
*/
private $localeFormat;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
* @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice $tierPriceResource
* @param FormatInterface|null $localeFormat
*/
public function __construct(
StoreManagerInterface $storeManager,
ProductAttributeRepositoryInterface $attributeRepository,
GroupManagementInterface $groupManagement,
MetadataPool $metadataPool,
Tierprice $tierPriceResource
Tierprice $tierPriceResource,
FormatInterface $localeFormat = null
) {
parent::__construct($groupManagement);

$this->storeManager = $storeManager;
$this->attributeRepository = $attributeRepository;
$this->metadataPoll = $metadataPool;
$this->tierPriceResource = $tierPriceResource;
$this->localeFormat = $localeFormat ?: ObjectManager::getInstance()->get(FormatInterface::class);
}

/**
Expand Down Expand Up @@ -116,8 +125,9 @@ private function updateValues(array $valuesToUpdate, array $oldValues): bool
{
$isChanged = false;
foreach ($valuesToUpdate as $key => $value) {
if ((!empty($value['value']) && (float)$oldValues[$key]['price'] !== (float)$value['value'])
|| $this->getPercentage($oldValues[$key]) !== $this->getPercentage($value)
if ((!empty($value['value'])
&& (float)$oldValues[$key]['price'] !== $this->localeFormat->getNumber($value['value'])
) || $this->getPercentage($oldValues[$key]) !== $this->getPercentage($value)
) {
$price = new \Magento\Framework\DataObject(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,14 @@
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the product." stepKey="seeSaveConfirmation"/>
</actionGroup>

<actionGroup name="AdminAssignProductToCategory">
<actionGroup name="AdminAssignProductToCategory" extends="AdminProductAssignCategory">
<arguments>
<argument name="productId" type="string"/>
<argument name="categoryName" type="string"/>
</arguments>
<amOnPage url="{{AdminProductEditPage.url(productId)}}" stepKey="amOnPage"/>
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{categoryName}}]" stepKey="selectCategory"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickOnSaveButton"/>
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the product." stepKey="seeSaveProductMessage"/>
<amOnPage url="{{AdminProductEditPage.url(productId)}}" before="searchAndSelectCategory" stepKey="amOnPage"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" after="searchAndSelectCategory" stepKey="clickOnSaveButton"/>
<waitForElementVisible selector="{{AdminMessagesSection.success}}" after="clickOnSaveButton" stepKey="waitForSaveProductMessage"/>
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the product." after="waitForSaveProductMessage" stepKey="seeSaveProductMessage"/>
</actionGroup>

<actionGroup name="AdminChangeProductAttributeSet">
Expand All @@ -269,4 +268,19 @@
<waitForElementVisible selector="{{AdminProductFormSection.attributeSetFilterResultByName(attributeSet.attribute_set_name)}}" stepKey="waitForNewAttributeSetIsShown"/>
<click selector="{{AdminProductFormSection.attributeSetFilterResultByName(attributeSet.attribute_set_name)}}" stepKey="selectAttributeSet"/>
</actionGroup>

<actionGroup name="AdminProductAssignCategory">
<arguments>
<argument name="categoryName" type="string"/>
</arguments>
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{categoryName}}]" stepKey="searchAndSelectCategory"/>
</actionGroup>

<!--Navigate to created product page directly via ID-->
<actionGroup name="goToProductPageViaID">
<arguments>
<argument name="productId" type="string"/>
</arguments>
<amOnPage url="{{AdminProductEditPage.url(productId)}}" stepKey="goToProduct"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<element name="productPriceOld" type="text" selector="//span[@data-price-type='oldPrice']//span[@class='price'][contains(., '{{var1}}')]" parameterized="true"/>
<element name="productPriceLabel" type="text" selector="//span[@class='price-label'][contains(text(),'{{var1}}')]" parameterized="true"/>
<element name="productPriceLinkAfterLabel" type="text" selector="//span[@class='price-label'][contains(text(),'{{var1}}')]/following::span[contains(text(), '{{var2}}')]" parameterized="true"/>
<element name="productStockUnavailableByName" type="text" selector="//a[contains(@class, 'product-item-link') and normalize-space(text())='{{productName}}']/ancestor::div[contains(@class, 'product-item-details')]//span[contains(text(),'Out of stock')]" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="StockOptionsDisplayOutOfStockProductsEnable">
<data key="path">cataloginventory/options/show_out_of_stock</data>
<data key="scope_id">0</data>
<data key="label">Yes</data>
<data key="value">1</data>
</entity>
<entity name="StockOptionsDisplayOutOfStockProductsDisable">
<data key="path">cataloginventory/options/show_out_of_stock</data>
<data key="scope_id">0</data>
<data key="label">No</data>
<data key="value">0</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminCreateApiConfigurableProductActionGroup">
<arguments>
<argument name="productName" defaultValue="ApiConfigurableProductWithOutCategory" type="string"/>
<argument name="productName" defaultValue="{{ApiConfigurableProductWithOutCategory.name}}" type="string"/>
</arguments>

<!-- Create the configurable product based on the data in the /data folder -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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">
<!-- Check for the product link. -->
<!-- Assumes web client is on Grouped Product Page -->
<actionGroup name="AssertLinkPresenceOnGroupedProductPage">
<arguments>
<argument name="productName" type="string"/>
</arguments>
<see selector="{{StorefrontProductInfoMainSection.groupedProductsTable}}" userInput="{{productName}}" stepKey="seeFirstStagedGroupedProduct"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="StorefrontProductInfoMainSection">
<element name="groupedProductsTable" type="text" selector="#super-product-table .product-item-name"/>
</section>
</sections>
16 changes: 15 additions & 1 deletion lib/internal/Magento/Framework/Locale/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*/
class Format implements \Magento\Framework\Locale\FormatInterface
{
/**
* Japan locale code
*/
private static $japanLocaleCode = 'ja_JP';

/**
* @var \Magento\Framework\App\ScopeResolverInterface
*/
Expand Down Expand Up @@ -81,7 +86,16 @@ public function getNumber($value)
$value = str_replace(',', '', $value);
}
} elseif ($separatorComa !== false) {
$value = str_replace(',', '.', $value);
$locale = $this->_localeResolver->getLocale();
/**
* It's hard code for Japan locale.
* The comma separator uses as group separator: 4,000 saves as 4,000.00
*/
$value = str_replace(
',',
$locale === self::$japanLocaleCode ? '' : '.',
$value
);
}

return (float)$value;
Expand Down
17 changes: 14 additions & 3 deletions lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Magento\Framework\Locale\Test\Unit;

/**
* Tests class for Number locale format
*/
class FormatTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down Expand Up @@ -84,25 +87,31 @@ public function testGetPriceFormat($localeCode, $expectedResult)
*/
public function getPriceFormatDataProvider()
{
$swissGroupSymbol = INTL_ICU_VERSION >= 59.1 ? '' : '\'';
return [
['en_US', ['decimalSymbol' => '.', 'groupSymbol' => ',']],
['de_DE', ['decimalSymbol' => ',', 'groupSymbol' => '.']],
['de_CH', ['decimalSymbol' => '.', 'groupSymbol' => '\'']],
['de_CH', ['decimalSymbol' => '.', 'groupSymbol' => $swissGroupSymbol]],
['uk_UA', ['decimalSymbol' => ',', 'groupSymbol' => ' ']]
];
}

/**
* @param float | null $expected
* @param string|float|int $value
* @param float | null $expected
* @param string $locale
* @dataProvider provideNumbers
*/
public function testGetNumber($value, $expected)
public function testGetNumber(string $value, float $expected, string $locale = null)
{
if ($locale !== null) {
$this->localeResolver->method('getLocale')->willReturn($locale);
}
$this->assertEquals($expected, $this->formatModel->getNumber($value));
}

/**
*
* @return array
*/
public function provideNumbers(): array
Expand All @@ -118,6 +127,8 @@ public function provideNumbers(): array
['2 054.52', 2054.52],
['2,46 GB', 2.46],
['2,054.00', 2054],
['4,000', 4000.0, 'ja_JP'],
['4,000', 4.0, 'en_US'],
];
}
}
2 changes: 1 addition & 1 deletion lib/web/mage/requirejs/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define([
* @return {Boolean}
*/
function isRejected(module) {
return registry[module.id] && registry[module.id].error;
return registry[module.id] && (registry[module.id].inited || registry[module.id].error);
}

/**
Expand Down

0 comments on commit b3cf9d1

Please sign in to comment.