Skip to content

Commit 35e8e43

Browse files
Merge pull request #8287 from magento-l3/PR-2023-05-08
Pr 2023 05 08
2 parents b0c72f3 + 1e17b1e commit 35e8e43

File tree

4 files changed

+130
-46
lines changed

4 files changed

+130
-46
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,62 @@
1111
*/
1212
namespace Magento\Catalog\Model\Product\Attribute\Source;
1313

14+
use Magento\Directory\Model\CountryFactory;
1415
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
16+
use Magento\Framework\App\Cache\Type\Config;
1517
use Magento\Framework\Data\OptionSourceInterface;
18+
use Magento\Framework\Locale\ResolverInterface;
19+
use Magento\Framework\Serialize\SerializerInterface;
20+
use Magento\Store\Model\StoreManagerInterface;
1621

1722
class Countryofmanufacture extends AbstractSource implements OptionSourceInterface
1823
{
1924
/**
20-
* @var \Magento\Framework\App\Cache\Type\Config
25+
* @var Config
2126
*/
2227
protected $_configCacheType;
2328

2429
/**
25-
* Store manager
26-
*
27-
* @var \Magento\Store\Model\StoreManagerInterface
30+
* @var StoreManagerInterface
2831
*/
2932
protected $_storeManager;
3033

3134
/**
32-
* Country factory
33-
*
34-
* @var \Magento\Directory\Model\CountryFactory
35+
* @var CountryFactory
3536
*/
3637
protected $_countryFactory;
3738

3839
/**
39-
* @var \Magento\Framework\Serialize\SerializerInterface
40+
* @var SerializerInterface
4041
*/
4142
private $serializer;
4243

44+
/**
45+
* @var ResolverInterface
46+
*/
47+
private $localeResolver;
48+
4349
/**
4450
* Construct
4551
*
46-
* @param \Magento\Directory\Model\CountryFactory $countryFactory
47-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
48-
* @param \Magento\Framework\App\Cache\Type\Config $configCacheType
52+
* @param CountryFactory $countryFactory
53+
* @param StoreManagerInterface $storeManager
54+
* @param Config $configCacheType
55+
* @param ResolverInterface $localeResolver
56+
* @param SerializerInterface $serializer
4957
*/
5058
public function __construct(
51-
\Magento\Directory\Model\CountryFactory $countryFactory,
52-
\Magento\Store\Model\StoreManagerInterface $storeManager,
53-
\Magento\Framework\App\Cache\Type\Config $configCacheType
59+
CountryFactory $countryFactory,
60+
StoreManagerInterface $storeManager,
61+
Config $configCacheType,
62+
ResolverInterface $localeResolver,
63+
SerializerInterface $serializer
5464
) {
5565
$this->_countryFactory = $countryFactory;
5666
$this->_storeManager = $storeManager;
5767
$this->_configCacheType = $configCacheType;
68+
$this->localeResolver = $localeResolver;
69+
$this->serializer = $serializer;
5870
}
5971

6072
/**
@@ -64,32 +76,20 @@ public function __construct(
6476
*/
6577
public function getAllOptions()
6678
{
67-
$cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode();
79+
$storeCode = $this->_storeManager->getStore()->getCode();
80+
$locale = $this->localeResolver->getLocale();
81+
82+
$cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $storeCode . '_LOCALE_' . $locale;
6883
if ($cache = $this->_configCacheType->load($cacheKey)) {
69-
$options = $this->getSerializer()->unserialize($cache);
84+
$options = $this->serializer->unserialize($cache);
7085
} else {
7186
/** @var \Magento\Directory\Model\Country $country */
7287
$country = $this->_countryFactory->create();
7388
/** @var \Magento\Directory\Model\ResourceModel\Country\Collection $collection */
7489
$collection = $country->getResourceCollection();
7590
$options = $collection->load()->toOptionArray();
76-
$this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey);
91+
$this->_configCacheType->save($this->serializer->serialize($options), $cacheKey);
7792
}
7893
return $options;
7994
}
80-
81-
/**
82-
* Get serializer
83-
*
84-
* @return \Magento\Framework\Serialize\SerializerInterface
85-
* @deprecated 102.0.0
86-
*/
87-
private function getSerializer()
88-
{
89-
if ($this->serializer === null) {
90-
$this->serializer = \Magento\Framework\App\ObjectManager::getInstance()
91-
->get(\Magento\Framework\Serialize\SerializerInterface::class);
92-
}
93-
return $this->serializer;
94-
}
9595
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Source/CountryofmanufactureTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture;
1111
use Magento\Framework\App\Cache\Type\Config;
12+
use Magento\Framework\Locale\ResolverInterface;
1213
use Magento\Framework\Serialize\SerializerInterface;
1314
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1415
use Magento\Store\Model\Store;
@@ -46,17 +47,24 @@ class CountryofmanufactureTest extends TestCase
4647
*/
4748
private $serializerMock;
4849

50+
/**
51+
* @var ResolverInterface
52+
*/
53+
private $localeResolverMock;
54+
4955
protected function setUp(): void
5056
{
5157
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
5258
$this->storeMock = $this->createMock(Store::class);
5359
$this->cacheConfig = $this->createMock(Config::class);
60+
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
5461
$this->objectManagerHelper = new ObjectManager($this);
5562
$this->countryOfManufacture = $this->objectManagerHelper->getObject(
5663
Countryofmanufacture::class,
5764
[
5865
'storeManager' => $this->storeManagerMock,
5966
'configCacheType' => $this->cacheConfig,
67+
'localeResolver' => $this->localeResolverMock,
6068
]
6169
);
6270

@@ -80,9 +88,10 @@ public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl)
8088
{
8189
$this->storeMock->expects($this->once())->method('getCode')->willReturn('store_code');
8290
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
91+
$this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US');
8392
$this->cacheConfig->expects($this->once())
8493
->method('load')
85-
->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code'))
94+
->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code_LOCALE_en_US'))
8695
->willReturn($cachedDataSrl);
8796
$this->serializerMock->expects($this->once())
8897
->method('unserialize')

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/steps/summary.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,8 @@ define([
135135
if (productId && !images.file) {
136136
images = product.images;
137137
}
138-
productDataFromGrid = _.pick(
139-
productDataFromGrid,
140-
'sku',
141-
'name',
142-
'weight',
143-
'status',
144-
'price',
145-
'qty'
146-
);
138+
productDataFromGrid = this.prepareProductDataFromGrid(productDataFromGrid);
147139

148-
if (productDataFromGrid.hasOwnProperty('qty')) {
149-
productDataFromGrid[this.quantityFieldName] = productDataFromGrid.qty;
150-
}
151-
delete productDataFromGrid.qty;
152140
product = _.pick(
153141
product || {},
154142
'sku',
@@ -288,6 +276,32 @@ define([
288276
* Back.
289277
*/
290278
back: function () {
279+
},
280+
281+
/**
282+
* Prepare product data from grid to have all the current fields values
283+
*
284+
* @param {Object} productDataFromGrid
285+
* @return {Object}
286+
*/
287+
prepareProductDataFromGrid: function (productDataFromGrid) {
288+
productDataFromGrid = _.pick(
289+
productDataFromGrid,
290+
'sku',
291+
'name',
292+
'weight',
293+
'status',
294+
'price',
295+
'qty'
296+
);
297+
298+
if (productDataFromGrid.hasOwnProperty('qty')) {
299+
productDataFromGrid[this.quantityFieldName] = productDataFromGrid.qty;
300+
}
301+
302+
delete productDataFromGrid.qty;
303+
304+
return productDataFromGrid;
291305
}
292306
});
293307
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
7+
/* eslint max-nested-callbacks: 0 */
8+
/* jscs:disable jsDoc*/
9+
10+
define([
11+
'Magento_ConfigurableProduct/js/variations/steps/summary'
12+
], function (Summary) {
13+
'use strict';
14+
15+
describe('Magento_ConfigurableProduct/js/variations/steps/summary', function () {
16+
let model, quantityFieldName, productDataFromGrid, productDataFromGridExpected;
17+
18+
beforeEach(function () {
19+
quantityFieldName = 'quantity123';
20+
model = new Summary({quantityFieldName: quantityFieldName});
21+
22+
productDataFromGrid = {
23+
sku: 'testSku',
24+
name: 'test name',
25+
weight: 12.12312,
26+
status: 1,
27+
price: 333.333,
28+
someField: 'someValue',
29+
quantity: 10
30+
};
31+
32+
productDataFromGrid[quantityFieldName] = 12;
33+
34+
productDataFromGridExpected = {
35+
sku: 'testSku',
36+
name: 'test name',
37+
weight: 12.12312,
38+
status: 1,
39+
price: 333.333
40+
};
41+
});
42+
43+
describe('Check prepareProductDataFromGrid', function () {
44+
45+
it('Check call to prepareProductDataFromGrid method with qty', function () {
46+
productDataFromGrid.qty = 3;
47+
productDataFromGridExpected[quantityFieldName] = 3;
48+
const result = model.prepareProductDataFromGrid(productDataFromGrid);
49+
50+
expect(result).toEqual(productDataFromGridExpected);
51+
});
52+
53+
54+
it('Check call to prepareProductDataFromGrid method without qty', function () {
55+
const result = model.prepareProductDataFromGrid(productDataFromGrid);
56+
57+
expect(result).toEqual(productDataFromGridExpected);
58+
});
59+
});
60+
});
61+
});

0 commit comments

Comments
 (0)