Skip to content

Commit 0df8184

Browse files
committed
MAGETWO-56018: [GitHub] Fail to import custom options #5573
2 parents 91bd544 + 5db8443 commit 0df8184

File tree

76 files changed

+3739
-860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3739
-860
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
<resource>Magento_Config::config_general</resource>
199199
<group id="country" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
200200
<label>Country Options</label>
201-
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
201+
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
202202
<label>Allow Countries</label>
203203
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
204204
<can_be_empty>1</can_be_empty>

app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ define(
2626
},
2727
initialize: function() {
2828
this._super();
29-
captchaConfig = window[this.configSource]['captcha'];
3029

31-
if (captchaConfig) {
30+
if (window[this.configSource] && window[this.configSource]['captcha']) {
31+
captchaConfig = window[this.configSource]['captcha'];
3232
$.each(captchaConfig, function(formId, captchaData) {
3333
captchaData.formId = formId;
3434
captchaList.add(Captcha(captchaData));

app/code/Magento/Catalog/Block/Adminhtml/Product/Grid.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ protected function _getStore()
114114
*/
115115
protected function _prepareCollection()
116116
{
117-
parent::_prepareCollection();
118-
119117
$store = $this->_getStore();
120118
$collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect(
121119
'sku'
@@ -184,6 +182,9 @@ protected function _prepareCollection()
184182
$this->setCollection($collection);
185183

186184
$this->getCollection()->addWebsiteNamesToResult();
185+
186+
parent::_prepareCollection();
187+
187188
return $this;
188189
}
189190

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,12 +2090,13 @@ public function addTierPriceData()
20902090
if ($this->getFlag('tier_price_added')) {
20912091
return $this;
20922092
}
2093+
$linkField = $this->getConnection()->getAutoIncrementField($this->getTable('catalog_product_entity'));
20932094

20942095
$tierPrices = [];
20952096
$productIds = [];
20962097
foreach ($this->getItems() as $item) {
2097-
$productIds[] = $item->getId();
2098-
$tierPrices[$item->getId()] = [];
2098+
$productIds[] = $item->getData($linkField);
2099+
$tierPrices[$item->getData($linkField)] = [];
20992100
}
21002101
if (!$productIds) {
21012102
return $this;
@@ -2108,7 +2109,6 @@ public function addTierPriceData()
21082109
$websiteId = $this->_storeManager->getStore($this->getStoreId())->getWebsiteId();
21092110
}
21102111

2111-
$linkField = $this->getConnection()->getAutoIncrementField($this->getTable('catalog_product_entity'));
21122112
$connection = $this->getConnection();
21132113
$columns = [
21142114
'price_id' => 'value_id',
@@ -2149,7 +2149,7 @@ public function addTierPriceData()
21492149
$backend = $attribute->getBackend();
21502150

21512151
foreach ($this->getItems() as $item) {
2152-
$data = $tierPrices[$item->getId()];
2152+
$data = $tierPrices[$item->getData($linkField)];
21532153
if (!empty($data) && $websiteId) {
21542154
$data = $backend->preparePriceData($data, $item->getTypeId(), $websiteId);
21552155
}

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories;
99
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1010
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
11+
use Magento\Framework\App\CacheInterface;
1112
use Magento\Framework\DB\Helper as DbHelper;
1213
use Magento\Framework\UrlInterface;
1314
use Magento\Store\Model\Store;
@@ -112,4 +113,38 @@ public function testModifyMeta()
112113

113114
$this->assertArrayHasKey($groupCode, $this->getModel()->modifyMeta($meta));
114115
}
116+
117+
public function testModifyMetaWithCaching()
118+
{
119+
$this->arrayManagerMock->expects($this->exactly(2))
120+
->method('findPath')
121+
->willReturn(true);
122+
$cacheManager = $this->getMockBuilder(CacheInterface::class)
123+
->getMockForAbstractClass();
124+
$cacheManager->expects($this->once())
125+
->method('load')
126+
->with(Categories::CATEGORY_TREE_ID . '_');
127+
$cacheManager->expects($this->once())
128+
->method('save');
129+
130+
$modifier = $this->createModel();
131+
$cacheContextProperty = new \ReflectionProperty(
132+
Categories::class,
133+
'cacheManager'
134+
);
135+
$cacheContextProperty->setAccessible(true);
136+
$cacheContextProperty->setValue($modifier, $cacheManager);
137+
138+
$groupCode = 'test_group_code';
139+
$meta = [
140+
$groupCode => [
141+
'children' => [
142+
'category_ids' => [
143+
'sortOrder' => 10,
144+
],
145+
],
146+
],
147+
];
148+
$modifier->modifyMeta($meta);
149+
}
115150
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@
77

88
use Magento\Catalog\Model\Locator\LocatorInterface;
99
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\App\CacheInterface;
1012
use Magento\Framework\DB\Helper as DbHelper;
1113
use Magento\Catalog\Model\Category as CategoryModel;
1214
use Magento\Framework\UrlInterface;
1315
use Magento\Framework\Stdlib\ArrayManager;
1416

1517
/**
1618
* Data provider for categories field of product page
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1720
*/
1821
class Categories extends AbstractModifier
1922
{
23+
/**#@+
24+
* Category tree cache id
25+
*/
26+
const CATEGORY_TREE_ID = 'CATALOG_PRODUCT_CATEGORY_TREE';
27+
/**#@-*/
28+
2029
/**
2130
* @var CategoryCollectionFactory
2231
*/
@@ -29,6 +38,7 @@ class Categories extends AbstractModifier
2938

3039
/**
3140
* @var array
41+
* @deprecated
3242
*/
3343
protected $categoriesTrees = [];
3444

@@ -47,6 +57,11 @@ class Categories extends AbstractModifier
4757
*/
4858
protected $arrayManager;
4959

60+
/**
61+
* @var CacheInterface
62+
*/
63+
private $cacheManager;
64+
5065
/**
5166
* @param LocatorInterface $locator
5267
* @param CategoryCollectionFactory $categoryCollectionFactory
@@ -68,6 +83,21 @@ public function __construct(
6883
$this->arrayManager = $arrayManager;
6984
}
7085

86+
/**
87+
* Retrieve cache interface
88+
*
89+
* @return CacheInterface
90+
* @deprecated
91+
*/
92+
private function getCacheManager()
93+
{
94+
if (!$this->cacheManager) {
95+
$this->cacheManager = ObjectManager::getInstance()
96+
->get(CacheInterface::class);
97+
}
98+
return $this->cacheManager;
99+
}
100+
71101
/**
72102
* {@inheritdoc}
73103
*/
@@ -254,8 +284,9 @@ protected function customizeCategoriesField(array $meta)
254284
*/
255285
protected function getCategoriesTree($filter = null)
256286
{
257-
if (isset($this->categoriesTrees[$filter])) {
258-
return $this->categoriesTrees[$filter];
287+
$categoryTree = $this->getCacheManager()->load(self::CATEGORY_TREE_ID . '_' . $filter);
288+
if ($categoryTree) {
289+
return unserialize($categoryTree);
259290
}
260291

261292
$storeId = $this->locator->getStore()->getId();
@@ -307,9 +338,16 @@ protected function getCategoriesTree($filter = null)
307338
$categoryById[$category->getId()]['label'] = $category->getName();
308339
$categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];
309340
}
341+
342+
$this->getCacheManager()->save(
343+
serialize($categoryById[CategoryModel::TREE_ROOT_ID]['optgroup']),
344+
self::CATEGORY_TREE_ID . '_' . $filter,
345+
[
346+
\Magento\Catalog\Model\Category::CACHE_TAG,
347+
\Magento\Framework\App\Cache\Type\Block::CACHE_TAG
348+
]
349+
);
310350

311-
$this->categoriesTrees[$filter] = $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
312-
313-
return $this->categoriesTrees[$filter];
351+
return $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
314352
}
315353
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/ConfigurableTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ public function testGetUsedProducts()
369369
'addFilterByRequiredOptions',
370370
'setStoreId',
371371
'addPriceData',
372+
'addTierPriceData',
372373
'getIterator',
373374
'load',
374375
]
@@ -378,6 +379,7 @@ public function testGetUsedProducts()
378379
$productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf());
379380
$productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf());
380381
$productCollection->expects($this->any())->method('addPriceData')->will($this->returnSelf());
382+
$productCollection->expects($this->any())->method('addTierPriceData')->will($this->returnSelf());
381383
$productCollection->expects($this->any())->method('addFilterByRequiredOptions')->will($this->returnSelf());
382384
$productCollection->expects($this->any())->method('setStoreId')->with(5)->will($this->returnValue([]));
383385
$productCollection->expects($this->any())->method('getIterator')->willReturn(

app/code/Magento/Customer/Model/Customer/DataProvider.php

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Customer\Model\Customer;
77

8+
use Magento\Customer\Api\Data\AddressInterface;
9+
use Magento\Customer\Api\Data\CustomerInterface;
10+
use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites;
811
use Magento\Eav\Api\Data\AttributeInterface;
912
use Magento\Eav\Model\Config;
1013
use Magento\Eav\Model\Entity\Type;
@@ -44,6 +47,16 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
4447
*/
4548
protected $loadedData;
4649

50+
/**
51+
* @var CountryWithWebsites
52+
*/
53+
private $countryByWebsiteSource;
54+
55+
/**
56+
* @var \Magento\Customer\Model\Config\Share
57+
*/
58+
private $shareConfig;
59+
4760
/**
4861
* EAV attribute properties to fetch from meta storage
4962
* @var array
@@ -195,7 +208,12 @@ protected function getAttributesMeta(Type $entityType)
195208
}
196209

197210
if ($attribute->usesSource()) {
198-
$meta[$code]['arguments']['data']['config']['options'] = $attribute->getSource()->getAllOptions();
211+
if ($code == AddressInterface::COUNTRY_ID) {
212+
$meta[$code]['arguments']['data']['config']['options'] = $this->getCountryByWebsiteSource()
213+
->getAllOptions();
214+
} else {
215+
$meta[$code]['arguments']['data']['config']['options'] = $attribute->getSource()->getAllOptions();
216+
}
199217
}
200218

201219
$rules = $this->eavValidationRules->build($attribute, $meta[$code]['arguments']['data']['config']);
@@ -204,9 +222,57 @@ protected function getAttributesMeta(Type $entityType)
204222
}
205223
$meta[$code]['arguments']['data']['config']['componentType'] = Field::NAME;
206224
}
225+
226+
$this->processWebsiteMeta($meta);
207227
return $meta;
208228
}
209229

230+
/**
231+
* Retrieve Country With Website options Source
232+
* @deprecated
233+
* @return CountryWithWebsites
234+
*/
235+
private function getCountryByWebsiteSource()
236+
{
237+
if (!$this->countryByWebsiteSource) {
238+
$this->countryByWebsiteSource = ObjectManager::getInstance()->get(CountryWithWebsites::class);
239+
}
240+
241+
return $this->countryByWebsiteSource;
242+
}
243+
244+
/**
245+
* Retrieve Customer Share Config
246+
* @deprecated
247+
* @return \Magento\Customer\Model\Config\Share
248+
*/
249+
private function getShareConfig()
250+
{
251+
if (!$this->shareConfig) {
252+
$this->shareConfig = ObjectManager::getInstance()->get(\Magento\Customer\Model\Config\Share::class);
253+
}
254+
255+
return $this->shareConfig;
256+
}
257+
258+
/**
259+
* @param array $meta
260+
* @return void
261+
*/
262+
private function processWebsiteMeta(&$meta)
263+
{
264+
if (isset($meta[CustomerInterface::WEBSITE_ID]) && $this->getShareConfig()->isGlobalScope()) {
265+
$meta[CustomerInterface::WEBSITE_ID]['arguments']['data']['config']['isGlobalScope'] = 1;
266+
}
267+
268+
if (isset($meta[AddressInterface::COUNTRY_ID]) && !$this->getShareConfig()->isGlobalScope()) {
269+
$meta[AddressInterface::COUNTRY_ID]['arguments']['data']['config']['filterBy'] = [
270+
'target' => '${ $.provider }:data.customer.website_id',
271+
'field' => 'website_ids'
272+
];
273+
}
274+
}
275+
210276
/**
211277
* Process attributes by frontend input type
212278
*

0 commit comments

Comments
 (0)