Skip to content

Commit 0755399

Browse files
author
Volodymyr Kublytskyi
committed
Merge remote-tracking branch 'mainline/2.3-develop'
2 parents 717c368 + f57c0bc commit 0755399

File tree

6 files changed

+92
-21
lines changed

6 files changed

+92
-21
lines changed

app/code/Magento/Catalog/Model/Category.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
9797
*/
9898
protected $_url;
9999

100+
/**
101+
* @var ResourceModel\Category
102+
*/
103+
protected $_resource;
104+
100105
/**
101106
* URL rewrite model
102107
*
@@ -313,6 +318,16 @@ protected function getCustomAttributesCodes()
313318
return $this->getCustomAttributeCodes->execute($this->metadataService);
314319
}
315320

321+
/**
322+
* @throws \Magento\Framework\Exception\LocalizedException
323+
* @return \Magento\Catalog\Model\ResourceModel\Category
324+
* @deprecated because resource models should be used directly
325+
*/
326+
protected function _getResource()
327+
{
328+
return parent::_getResource();
329+
}
330+
316331
/**
317332
* Get flat resource model flag
318333
*

app/code/Magento/Catalog/Model/Product.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
120120
*/
121121
protected $_urlModel = null;
122122

123+
/**
124+
* @var ResourceModel\Product
125+
*/
126+
protected $_resource;
127+
123128
/**
124129
* @var string
125130
*/
@@ -475,6 +480,18 @@ protected function _construct()
475480
$this->_init(\Magento\Catalog\Model\ResourceModel\Product::class);
476481
}
477482

483+
/**
484+
* Get resource instance
485+
*
486+
* @throws \Magento\Framework\Exception\LocalizedException
487+
* @return \Magento\Catalog\Model\ResourceModel\Product
488+
* @deprecated because resource models should be used directly
489+
*/
490+
protected function _getResource()
491+
{
492+
return parent::_getResource();
493+
}
494+
478495
/**
479496
* {@inheritdoc}
480497
*/

app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -441,33 +441,39 @@ public function testReindexFlatDisabled(
441441

442442
public function testGetCustomAttributes()
443443
{
444-
$nameAttributeCode = 'name';
445-
$descriptionAttributeCode = 'description';
444+
$interfaceAttributeCode = 'name';
445+
$customAttributeCode = 'description';
446+
$initialCustomAttributeValue = 'initial description';
447+
$newCustomAttributeValue = 'new description';
448+
446449
$this->getCustomAttributeCodes->expects($this->exactly(3))
447450
->method('execute')
448-
->willReturn([$descriptionAttributeCode]);
449-
$this->category->setData($nameAttributeCode, "sub");
451+
->willReturn([$customAttributeCode]);
452+
$this->category->setData($interfaceAttributeCode, "sub");
450453

451454
//The description attribute is not set, expect empty custom attribute array
452455
$this->assertEquals([], $this->category->getCustomAttributes());
453456

454457
//Set the description attribute;
455-
$this->category->setData($descriptionAttributeCode, "description");
458+
$this->category->setData($customAttributeCode, $initialCustomAttributeValue);
456459
$attributeValue = new \Magento\Framework\Api\AttributeValue();
457460
$attributeValue2 = new \Magento\Framework\Api\AttributeValue();
458461
$this->attributeValueFactory->expects($this->exactly(2))->method('create')
459462
->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2);
460463
$this->assertEquals(1, count($this->category->getCustomAttributes()));
461-
$this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
462-
$this->assertEquals("description", $this->category->getCustomAttribute($descriptionAttributeCode)->getValue());
464+
$this->assertNotNull($this->category->getCustomAttribute($customAttributeCode));
465+
$this->assertEquals(
466+
$initialCustomAttributeValue,
467+
$this->category->getCustomAttribute($customAttributeCode)->getValue()
468+
);
463469

464470
//Change the attribute value, should reflect in getCustomAttribute
465-
$this->category->setData($descriptionAttributeCode, "new description");
471+
$this->category->setData($customAttributeCode, $newCustomAttributeValue);
466472
$this->assertEquals(1, count($this->category->getCustomAttributes()));
467-
$this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
473+
$this->assertNotNull($this->category->getCustomAttribute($customAttributeCode));
468474
$this->assertEquals(
469-
"new description",
470-
$this->category->getCustomAttribute($descriptionAttributeCode)->getValue()
475+
$newCustomAttributeValue,
476+
$this->category->getCustomAttribute($customAttributeCode)->getValue()
471477
);
472478
}
473479

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,31 +1278,40 @@ public function testGetMediaGalleryImagesMerging()
12781278

12791279
public function testGetCustomAttributes()
12801280
{
1281-
$priceCode = 'price';
1282-
$colorAttributeCode = 'color';
1281+
$interfaceAttributeCode = 'price';
1282+
$customAttributeCode = 'color';
1283+
$initialCustomAttributeValue = 'red';
1284+
$newCustomAttributeValue = 'blue';
1285+
12831286
$this->getCustomAttributeCodes->expects($this->exactly(3))
12841287
->method('execute')
1285-
->willReturn([$colorAttributeCode]);
1286-
$this->model->setData($priceCode, 10);
1288+
->willReturn([$customAttributeCode]);
1289+
$this->model->setData($interfaceAttributeCode, 10);
12871290

12881291
//The color attribute is not set, expect empty custom attribute array
12891292
$this->assertEquals([], $this->model->getCustomAttributes());
12901293

12911294
//Set the color attribute;
1292-
$this->model->setData($colorAttributeCode, "red");
1295+
$this->model->setData($customAttributeCode, $initialCustomAttributeValue);
12931296
$attributeValue = new \Magento\Framework\Api\AttributeValue();
12941297
$attributeValue2 = new \Magento\Framework\Api\AttributeValue();
12951298
$this->attributeValueFactory->expects($this->exactly(2))->method('create')
12961299
->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2);
12971300
$this->assertEquals(1, count($this->model->getCustomAttributes()));
1298-
$this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
1299-
$this->assertEquals("red", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
1301+
$this->assertNotNull($this->model->getCustomAttribute($customAttributeCode));
1302+
$this->assertEquals(
1303+
$initialCustomAttributeValue,
1304+
$this->model->getCustomAttribute($customAttributeCode)->getValue()
1305+
);
13001306

13011307
//Change the attribute value, should reflect in getCustomAttribute
1302-
$this->model->setData($colorAttributeCode, "blue");
1308+
$this->model->setData($customAttributeCode, $newCustomAttributeValue);
13031309
$this->assertEquals(1, count($this->model->getCustomAttributes()));
1304-
$this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
1305-
$this->assertEquals("blue", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
1310+
$this->assertNotNull($this->model->getCustomAttribute($customAttributeCode));
1311+
$this->assertEquals(
1312+
$newCustomAttributeValue,
1313+
$this->model->getCustomAttribute($customAttributeCode)->getValue()
1314+
);
13061315
}
13071316

13081317
/**

lib/internal/Magento/Framework/Setup/Lists.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ class Lists
2121
*/
2222
protected $allowedLocales;
2323

24+
/**
25+
* List of allowed currencies
26+
*
27+
* @var array
28+
*/
29+
private $allowedCurrencies;
30+
2431
/**
2532
* @param ConfigInterface $localeConfig
2633
*/
2734
public function __construct(ConfigInterface $localeConfig)
2835
{
2936
$this->allowedLocales = $localeConfig->getAllowedLocales();
37+
$this->allowedCurrencies = $localeConfig->getAllowedCurrencies();
3038
}
3139

3240
/**
@@ -64,6 +72,10 @@ public function getCurrencyList()
6472
$currencies = (new CurrencyBundle())->get(Resolver::DEFAULT_LOCALE)['Currencies'];
6573
$list = [];
6674
foreach ($currencies as $code => $data) {
75+
$isAllowedCurrency = array_search($code, $this->allowedCurrencies) !== false;
76+
if (!$isAllowedCurrency) {
77+
continue;
78+
}
6779
$list[$code] = $data[1] . ' (' . $code . ')';
6880
}
6981
asort($list);

lib/internal/Magento/Framework/Setup/Test/Unit/ListsTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ protected function setUp()
5858
$this->mockConfig->expects($this->any())
5959
->method('getAllowedLocales')
6060
->willReturn($this->expectedLocales);
61+
$this->mockConfig->expects($this->any())
62+
->method('getAllowedCurrencies')
63+
->willReturn($this->expectedCurrencies);
6164

6265
$this->lists = new Lists($this->mockConfig);
6366
}
@@ -73,4 +76,13 @@ public function testGetLocaleList()
7376
$locales = array_intersect($this->expectedLocales, array_keys($this->lists->getLocaleList()));
7477
$this->assertEquals($this->expectedLocales, $locales);
7578
}
79+
80+
/**
81+
* Test Lists:getCurrencyList() considering allowed currencies config values.
82+
*/
83+
public function testGetCurrencyList()
84+
{
85+
$currencies = array_intersect($this->expectedCurrencies, array_keys($this->lists->getCurrencyList()));
86+
$this->assertEquals($this->expectedCurrencies, $currencies);
87+
}
7688
}

0 commit comments

Comments
 (0)