Skip to content

Commit 5c1eaff

Browse files
Oleksii Korshenkokandy
authored andcommitted
MAGETWO-54682: [Customer] Fast load of product options
- fixed backward incompatible changes
1 parent 593f137 commit 5c1eaff

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,14 @@ class Configurable extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4141
/**
4242
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
4343
* @param \Magento\Catalog\Model\ResourceModel\Product\Relation $catalogProductRelation
44-
* @param ScopeResolverInterface $scopeResolver
4544
* @param string $connectionName
4645
*/
4746
public function __construct(
4847
\Magento\Framework\Model\ResourceModel\Db\Context $context,
4948
\Magento\Catalog\Model\ResourceModel\Product\Relation $catalogProductRelation,
50-
ScopeResolverInterface $scopeResolver = null,
5149
$connectionName = null
5250
) {
5351
$this->catalogProductRelation = $catalogProductRelation;
54-
$this->scopeResolver = $scopeResolver;
5552
parent::__construct($context, $connectionName);
5653
}
5754

@@ -252,7 +249,7 @@ public function getAttributeOptions($superAttribute, $productId)
252249
'entity_value.attribute_id = super_attribute.attribute_id',
253250
'entity_value.store_id = 0',
254251
"entity_value.{$this->getProductEntityLinkField()} = "
255-
. "entity.{$this->getProductEntityLinkField()}"
252+
. "entity.{$this->getProductEntityLinkField()}",
256253
]
257254
),
258255
[]
@@ -262,7 +259,7 @@ public function getAttributeOptions($superAttribute, $productId)
262259
' AND ',
263260
[
264261
'option_value.option_id = entity_value.value',
265-
'option_value.store_id = ' . $scope->getId()
262+
'option_value.store_id = ' . $scope->getId(),
266263
]
267264
),
268265
[]
@@ -272,7 +269,7 @@ public function getAttributeOptions($superAttribute, $productId)
272269
' AND ',
273270
[
274271
'default_option_value.option_id = entity_value.value',
275-
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID
272+
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
276273
]
277274
),
278275
[]
@@ -289,6 +286,7 @@ public function getAttributeOptions($superAttribute, $productId)
289286

290287
/**
291288
* @return ScopeResolverInterface
289+
* @deprecated
292290
*/
293291
private function getScopeResolver()
294292
{

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable/Attribute/Collection.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*/
88
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
99

10+
use Magento\Catalog\Api\Data\ProductInterface;
1011
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
11-
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
1212
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable as ConfigurableResource;
13+
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute;
1314
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1415
use Magento\Framework\App\ObjectManager;
1516
use Magento\Framework\EntityManager\MetadataPool;
16-
use Magento\Catalog\Api\Data\ProductInterface;
1717

1818
/**
1919
* @SuppressWarnings(PHPMD.LongVariable)
@@ -73,7 +73,6 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
7373
* @param Configurable $catalogProductTypeConfigurable
7474
* @param \Magento\Catalog\Helper\Data $catalogData
7575
* @param Attribute $resource
76-
* @param ConfigurableResource $configurableResource
7776
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
7877
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7978
*/
@@ -86,13 +85,11 @@ public function __construct(
8685
Configurable $catalogProductTypeConfigurable,
8786
\Magento\Catalog\Helper\Data $catalogData,
8887
Attribute $resource,
89-
ConfigurableResource $configurableResource = null,
9088
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
9189
) {
9290
$this->_storeManager = $storeManager;
9391
$this->_productTypeConfigurable = $catalogProductTypeConfigurable;
9492
$this->_catalogData = $catalogData;
95-
$this->configurableResource = $configurableResource;
9693
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
9794
}
9895

@@ -276,7 +273,7 @@ protected function loadOptions()
276273
'product_super_attribute_id' => $itemId,
277274
'default_label' => $option['default_title'],
278275
'store_label' => $option['default_title'],
279-
'use_default_value' => true
276+
'use_default_value' => true,
280277
];
281278
}
282279
$values = array_values($values);
@@ -359,6 +356,7 @@ private function getMetadataPool()
359356
* Get Configurable Resource
360357
*
361358
* @return ConfigurableResource
359+
* @deprecated
362360
*/
363361
private function getConfigurableResource()
364362
{

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

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable;
10-
use Magento\Framework\Model\ResourceModel\Db\Context;
11-
use Magento\Framework\DB\Select;
1210
use Magento\Framework\App\ScopeResolverInterface;
11+
use Magento\Framework\DB\Select;
12+
use Magento\Framework\Model\ResourceModel\Db\Context;
1313
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1414

1515
/**
@@ -74,13 +74,18 @@ protected function setUp()
7474
->method('getMetadata')
7575
->with(ProductInterface::class)
7676
->willReturn($this->metadataMock);
77+
7778
$this->objectManagerHelper = new ObjectManagerHelper($this);
79+
$context = $this->getMockBuilder(Context::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
$context->expects($this->any())->method('getResources')->willReturn($this->resource);
83+
7884
$this->configurable = $this->objectManagerHelper->getObject(
7985
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class,
8086
[
81-
'resource' => $this->resource,
87+
'context' => $context,
8288
'catalogProductRelation' => $this->relation,
83-
'scopeResolver' => $this->getMockForAbstractClass(\Magento\Framework\App\ScopeResolverInterface::class)
8489
]
8590
);
8691
$reflection = new \ReflectionClass(
@@ -89,6 +94,13 @@ protected function setUp()
8994
$reflectionProperty = $reflection->getProperty('metadataPool');
9095
$reflectionProperty->setAccessible(true);
9196
$reflectionProperty->setValue($this->configurable, $this->metadataPoolMock);
97+
98+
$reflectionProperty = $reflection->getProperty('scopeResolver');
99+
$reflectionProperty->setAccessible(true);
100+
$reflectionProperty->setValue(
101+
$this->configurable,
102+
$this->getMockForAbstractClass(\Magento\Framework\App\ScopeResolverInterface::class)
103+
);
92104
}
93105

94106
public function testSaveProducts()
@@ -98,11 +110,11 @@ public function testSaveProducts()
98110
->setMethods(['__sleep', '__wakeup', 'getData'])
99111
->disableOriginalConstructor()
100112
->getMock();
101-
102-
$this->metadataMock->expects($this->once())
113+
114+
$this->metadataMock->expects($this->once())
103115
->method('getLinkField')
104116
->willReturn('link');
105-
$mainProduct->expects($this->once())
117+
$mainProduct->expects($this->once())
106118
->method('getData')
107119
->with('link')
108120
->willReturn(3);
@@ -140,14 +152,15 @@ public function testGetConfigurableOptions()
140152
[
141153
$this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(),
142154
$this->relation,
143-
$scopeResolver
144155
],
145156
'',
146157
true
147158
);
148-
$context = $this->getMockBuilder(Context::class)
149-
->disableOriginalConstructor()
150-
->getMock();
159+
160+
$reflection = new \ReflectionClass('Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable');
161+
$reflectionProperty = $reflection->getProperty('scopeResolver');
162+
$reflectionProperty->setAccessible(true);
163+
$reflectionProperty->setValue($configurable, $scopeResolver);
151164

152165
$reflection = new \ReflectionClass(Configurable::class);
153166
$reflectionProperty = $reflection->getProperty('metadataPool');
@@ -183,7 +196,7 @@ public function testGetConfigurableOptions()
183196
['eav_attribute', 'eav_attribute value'],
184197
['catalog_product_entity', 'catalog_product_entity value'],
185198
['eav_attribute_option_value', 'eav_attribute_option_value value'],
186-
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value']
199+
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value'],
187200
]
188201
)
189202
);
@@ -240,22 +253,22 @@ public function testGetConfigurableOptions()
240253
[
241254
['product_entity' => 'catalog_product_entity value'],
242255
'product_entity.link = super_attribute.product_id',
243-
[]
256+
[],
244257
],
245258
[
246259
['product_link' => 'catalog_product_super_link value'],
247260
'product_link.parent_id = super_attribute.product_id',
248-
[]
261+
[],
249262
],
250263
[
251264
['attribute' => 'eav_attribute value'],
252265
'attribute.attribute_id = super_attribute.attribute_id',
253-
[]
266+
[],
254267
],
255268
[
256269
['entity' => 'catalog_product_entity value'],
257270
'entity.entity_id = product_link.product_id',
258-
[]
271+
[],
259272
],
260273
[
261274
['entity_value' => 'getBackendTable value'],
@@ -264,10 +277,10 @@ public function testGetConfigurableOptions()
264277
[
265278
'entity_value.attribute_id = super_attribute.attribute_id',
266279
'entity_value.store_id = 0',
267-
'entity_value.link = entity.link'
280+
'entity_value.link = entity.link',
268281
]
269282
),
270-
[]
283+
[],
271284
]
272285
);
273286
$select->expects($this->exactly(2))
@@ -280,21 +293,21 @@ public function testGetConfigurableOptions()
280293
' AND ',
281294
[
282295
'option_value.option_id = entity_value.value',
283-
'option_value.store_id = ' . 123
296+
'option_value.store_id = ' . 123,
284297
]
285298
),
286-
[]
299+
[],
287300
],
288301
[
289302
['default_option_value' => 'eav_attribute_option_value value'],
290303
implode(
291304
' AND ',
292305
[
293306
'default_option_value.option_id = entity_value.value',
294-
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID
307+
'default_option_value.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
295308
]
296309
),
297-
[]
310+
[],
298311
]
299312
);
300313
$select->expects($this->exactly(2))
@@ -303,11 +316,11 @@ public function testGetConfigurableOptions()
303316
->withConsecutive(
304317
[
305318
'super_attribute.product_id = ?',
306-
'getId value'
319+
'getId value',
307320
],
308321
[
309322
'attribute.attribute_id = ?',
310-
'getAttributeId value'
323+
'getAttributeId value',
311324
]
312325
);
313326

0 commit comments

Comments
 (0)