Skip to content

Commit 437c1c2

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-58571' into 2.1.8-develop-pr17
2 parents 8f5dd5f + cb126af commit 437c1c2

File tree

4 files changed

+178
-6
lines changed

4 files changed

+178
-6
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class Value extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
3333
*/
3434
protected $_config;
3535

36+
/**
37+
* @var \Magento\Framework\Locale\FormatInterface
38+
*/
39+
private $localeFormat;
40+
3641
/**
3742
* Class constructor
3843
*
@@ -81,7 +86,7 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
8186
}
8287

8388
/**
84-
* Save option value price data
89+
* Save option value price data.
8590
*
8691
* @param \Magento\Framework\Model\AbstractModel $object
8792
* @return void
@@ -91,8 +96,9 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
9196
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
9297
{
9398
$priceTable = $this->getTable('catalog_product_option_type_price');
99+
$formattedPrice = $this->getLocaleFormatter()->getNumber($object->getPrice());
94100

95-
$price = (double)sprintf('%F', $object->getPrice());
101+
$price = (double)sprintf('%F', $formattedPrice);
96102
$priceType = $object->getPriceType();
97103

98104
if ($object->getPrice() && $priceType) {
@@ -417,4 +423,20 @@ public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $
417423

418424
return $object;
419425
}
426+
427+
/**
428+
* Get FormatInterface to convert price from string to number format.
429+
*
430+
* @return \Magento\Framework\Locale\FormatInterface
431+
* @deprecated
432+
*/
433+
private function getLocaleFormatter()
434+
{
435+
if ($this->localeFormat === null) {
436+
$this->localeFormat = \Magento\Framework\App\ObjectManager::getInstance()
437+
->get(\Magento\Framework\Locale\FormatInterface::class);
438+
}
439+
440+
return $this->localeFormat;
441+
}
420442
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,24 @@ public function testValidateUniqueInputAttributeValue()
475475
}
476476

477477
/**
478-
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
478+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
479479
* @magentoAppIsolation enabled
480480
*/
481481
public function testGetOptions()
482482
{
483-
$this->_model = $this->productRepository->get('simple');
484-
485-
$this->assertEquals(4, count($this->_model->getOptions()));
483+
$this->_model = $this->productRepository->get('simple_with_custom_options');
484+
$options = $this->_model->getOptions();
485+
$this->assertNotEmpty($options);
486+
$expectedValue = [
487+
'3-1-select' => 3000.00,
488+
'3-2-select' => 5000.00,
489+
'4-1-radio' => 600.234,
490+
'4-2-radio' => 40000.00
491+
];
492+
foreach ($options as $option) {
493+
foreach ($option->getValues() as $value) {
494+
$this->assertEquals($expectedValue[$value->getSku()], floatval($value->getPrice()));
495+
}
496+
}
486497
}
487498
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize();
7+
8+
/** @var \Magento\TestFramework\ObjectManager $objectManager */
9+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
10+
11+
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
12+
$categoryLinkManagement = $objectManager->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
13+
14+
/** @var $product \Magento\Catalog\Model\Product */
15+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
16+
$product->isObjectNew(true);
17+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
18+
->setAttributeSetId(4)
19+
->setWebsiteIds([1])
20+
->setName('Simple Product')
21+
->setSku('simple_with_custom_options')
22+
->setPrice(10)
23+
->setWeight(1)
24+
->setShortDescription("Short description")
25+
->setTaxClassId(0)
26+
->setDescription('Description with <b>html tag</b>')
27+
->setMetaTitle('meta title')
28+
->setMetaKeyword('meta keyword')
29+
->setMetaDescription('meta description')
30+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
31+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
32+
->setStockData(
33+
[
34+
'use_config_manage_stock' => 1,
35+
'qty' => 100,
36+
'is_qty_decimal' => 0,
37+
'is_in_stock' => 1,
38+
]
39+
)->setCanSaveCustomOptions(true)
40+
->setHasOptions(true);
41+
42+
$oldOptions = [
43+
[
44+
'previous_group' => 'select',
45+
'title' => 'Test Select',
46+
'type' => 'drop_down',
47+
'is_require' => 1,
48+
'sort_order' => 0,
49+
'values' => [
50+
[
51+
'option_type_id' => null,
52+
'title' => 'Option 1',
53+
'price' => '3,000.00',
54+
'price_type' => 'fixed',
55+
'sku' => '3-1-select',
56+
],
57+
[
58+
'option_type_id' => null,
59+
'title' => 'Option 2',
60+
'price' => '5,000.00',
61+
'price_type' => 'fixed',
62+
'sku' => '3-2-select',
63+
],
64+
]
65+
],
66+
[
67+
'previous_group' => 'select',
68+
'title' => 'Test Radio',
69+
'type' => 'radio',
70+
'is_require' => 1,
71+
'sort_order' => 0,
72+
'values' => [
73+
[
74+
'option_type_id' => null,
75+
'title' => 'Option 1',
76+
'price' => '600.234',
77+
'price_type' => 'fixed',
78+
'sku' => '4-1-radio',
79+
],
80+
[
81+
'option_type_id' => null,
82+
'title' => 'Option 2',
83+
'price' => '40,000.00',
84+
'price_type' => 'fixed',
85+
'sku' => '4-2-radio',
86+
],
87+
]
88+
]
89+
];
90+
91+
$options = [];
92+
93+
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */
94+
$customOptionFactory = $objectManager->create(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class);
95+
96+
foreach ($oldOptions as $option) {
97+
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $option */
98+
$option = $customOptionFactory->create(['data' => $option]);
99+
$option->setProductSku($product->getSku());
100+
101+
$options[] = $option;
102+
}
103+
104+
$product->setOptions($options);
105+
106+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryFactory */
107+
$productRepositoryFactory = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
108+
$productRepositoryFactory->save($product);
109+
110+
$categoryLinkManagement->assignProductToCategories(
111+
$product->getSku(),
112+
[2]
113+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
use Magento\Framework\Exception\NoSuchEntityException;
7+
8+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize();
9+
10+
/** @var \Magento\Framework\Registry $registry */
11+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
12+
13+
$registry->unregister('isSecureArea');
14+
$registry->register('isSecureArea', true);
15+
16+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
17+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
18+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
19+
try {
20+
$product = $productRepository->get('simple_with_custom_options', false, null, true);
21+
$productRepository->delete($product);
22+
} catch (NoSuchEntityException $e) {
23+
24+
}
25+
$registry->unregister('isSecureArea');
26+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)