Skip to content

Commit cf694a2

Browse files
author
Oleksii Korshenko
committed
Merge pull request #81 from magento-nord/develop
[NORD] Bugfixes
2 parents 658b520 + b72a3bb commit cf694a2

File tree

28 files changed

+447
-161
lines changed

28 files changed

+447
-161
lines changed

app/code/Magento/Catalog/Model/CustomOptions/CustomOptionProcessor.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class CustomOptionProcessor implements CartItemProcessorInterface
2525
/** @var CustomOptionFactory */
2626
protected $customOptionFactory;
2727

28+
/** @var \Magento\Catalog\Model\Product\Option\UrlBuilder */
29+
private $urlBuilder;
30+
2831
/**
2932
* @param DataObject\Factory $objectFactory
3033
* @param ProductOptionFactory $productOptionFactory
@@ -63,7 +66,6 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
6366
return null;
6467
}
6568

66-
6769
/**
6870
* @inheritDoc
6971
*/
@@ -117,10 +119,45 @@ protected function updateOptionsValues(array &$options)
117119
$option = $this->customOptionFactory->create();
118120
$option->setOptionId($optionId);
119121
if (is_array($optionValue)) {
122+
$optionValue = $this->processFileOptionValue($optionValue);
120123
$optionValue = implode(',', $optionValue);
121124
}
122125
$option->setOptionValue($optionValue);
123126
$optionValue = $option;
124127
}
125128
}
129+
130+
/**
131+
* Returns option value with file built URL
132+
*
133+
* @param array $optionValue
134+
* @return array
135+
*/
136+
private function processFileOptionValue(array $optionValue)
137+
{
138+
if (array_key_exists('url', $optionValue) &&
139+
array_key_exists('route', $optionValue['url']) &&
140+
array_key_exists('params', $optionValue['url'])
141+
) {
142+
$optionValue['url'] = $this->getUrlBuilder()->getUrl(
143+
$optionValue['url']['route'],
144+
$optionValue['url']['params']
145+
);
146+
}
147+
return $optionValue;
148+
}
149+
150+
/**
151+
* @return \Magento\Catalog\Model\Product\Option\UrlBuilder
152+
*
153+
* @deprecated
154+
*/
155+
private function getUrlBuilder()
156+
{
157+
if ($this->urlBuilder === null) {
158+
$this->urlBuilder = \Magento\Framework\App\ObjectManager::getInstance()
159+
->get('\Magento\Catalog\Model\Product\Option\UrlBuilder');
160+
}
161+
return $this->urlBuilder;
162+
}
126163
}

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
302302
*/
303303
protected $_productIdCached;
304304

305-
/**
306-
* @var \Magento\Framework\App\State
307-
*/
308-
private $appState;
309-
310305
/**
311306
* List of attributes in ProductInterface
312307
* @var array
@@ -931,8 +926,10 @@ public function afterSave()
931926

932927
// Resize images for catalog product and save results to image cache
933928
/** @var Product\Image\Cache $imageCache */
934-
$imageCache = $this->imageCacheFactory->create();
935-
$imageCache->generate($this);
929+
if (!$this->_appState->isAreaCodeEmulated()) {
930+
$imageCache = $this->imageCacheFactory->create();
931+
$imageCache->generate($this);
932+
}
936933

937934
return $result;
938935
}
@@ -2277,7 +2274,7 @@ public function getIdentities()
22772274
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22782275
}
22792276
}
2280-
if ($this->getAppState()->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
2277+
if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
22812278
$identities[] = self::CACHE_TAG;
22822279
}
22832280
return array_unique($identities);
@@ -2566,22 +2563,6 @@ public function setId($value)
25662563
return $this->setData('entity_id', $value);
25672564
}
25682565

2569-
/**
2570-
* Get application state
2571-
*
2572-
* @deprecated
2573-
* @return \Magento\Framework\App\State
2574-
*/
2575-
private function getAppState()
2576-
{
2577-
if (!$this->appState instanceof \Magento\Framework\App\State) {
2578-
$this->appState = \Magento\Framework\App\ObjectManager::getInstance()->get(
2579-
\Magento\Framework\App\State::class
2580-
);
2581-
}
2582-
return $this->appState;
2583-
}
2584-
25852566
/**
25862567
* @return ProductLinkRepositoryInterface
25872568
*/

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class ProductOptionProcessor implements ProductOptionProcessorInterface
2424
*/
2525
protected $customOptionFactory;
2626

27+
/**
28+
* @var \Magento\Catalog\Model\Product\Option\UrlBuilder
29+
*/
30+
private $urlBuilder;
31+
2732
/**
2833
* @param DataObjectFactory $objectFactory
2934
* @param CustomOptionFactory $customOptionFactory
@@ -84,6 +89,7 @@ public function convertToProductOption(DataObject $request)
8489
$data = [];
8590
foreach ($options as $optionId => $optionValue) {
8691
if (is_array($optionValue)) {
92+
$optionValue = $this->processFileOptionValue($optionValue);
8793
$optionValue = implode(',', $optionValue);
8894
}
8995

@@ -98,4 +104,38 @@ public function convertToProductOption(DataObject $request)
98104

99105
return [];
100106
}
107+
108+
/**
109+
* Returns option value with file built URL
110+
*
111+
* @param array $optionValue
112+
* @return array
113+
*/
114+
private function processFileOptionValue(array $optionValue)
115+
{
116+
if (array_key_exists('url', $optionValue) &&
117+
array_key_exists('route', $optionValue['url']) &&
118+
array_key_exists('params', $optionValue['url'])
119+
) {
120+
$optionValue['url'] = $this->getUrlBuilder()->getUrl(
121+
$optionValue['url']['route'],
122+
$optionValue['url']['params']
123+
);
124+
}
125+
return $optionValue;
126+
}
127+
128+
/**
129+
* @return \Magento\Catalog\Model\Product\Option\UrlBuilder
130+
*
131+
* @deprecated
132+
*/
133+
private function getUrlBuilder()
134+
{
135+
if ($this->urlBuilder === null) {
136+
$this->urlBuilder = \Magento\Framework\App\ObjectManager::getInstance()
137+
->get('\Magento\Catalog\Model\Product\Option\UrlBuilder');
138+
}
139+
return $this->urlBuilder;
140+
}
101141
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu
270270
)->where(
271271
'pvd.attribute_id IN(?)',
272272
$attrIds
273+
)->where(
274+
'cpe.entity_id IS NOT NULL'
273275
);
274276

275277
$statusCond = $connection->quoteInto('=?', ProductStatus::STATUS_ENABLED);

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ protected function setUp()
7878
$this->dataObjectFactory,
7979
$this->customOptionFactory
8080
);
81+
82+
$urlBuilder = $this->getMockBuilder('\Magento\Catalog\Model\Product\Option\UrlBuilder')
83+
->disableOriginalConstructor()
84+
->setMethods(['getUrl'])
85+
->getMock();
86+
$urlBuilder->expects($this->any())->method('getUrl')->willReturn('http://built.url/string/');
87+
88+
$reflection = new \ReflectionClass(get_class($this->processor));
89+
$reflectionProperty = $reflection->getProperty('urlBuilder');
90+
$reflectionProperty->setAccessible(true);
91+
$reflectionProperty->setValue($this->processor, $urlBuilder);
8192
}
8293

8394
/**
@@ -186,7 +197,14 @@ public function dataProviderConvertToProductOption()
186197
[
187198
'options' => [
188199
1 => 'value',
189-
2 => [1, 2],
200+
2 => [
201+
1,
202+
2,
203+
'url' => [
204+
'route' => 'route',
205+
'params' => ['id' => 20, 'key' => '8175c7c36ef69432347e']
206+
]
207+
],
190208
],
191209
'expected' => 'custom_options',
192210
],

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,14 @@ protected function setUp()
213213
false
214214
);
215215

216-
$stateMock = $this->getMock('Magento\FrameworkApp\State', ['getAreaCode'], [], '', false);
217-
$stateMock->expects($this->any())
216+
$this->appStateMock = $this->getMock(
217+
'Magento\Framework\App\State',
218+
['getAreaCode', 'isAreaCodeEmulated'],
219+
[],
220+
'',
221+
false
222+
);
223+
$this->appStateMock->expects($this->any())
218224
->method('getAreaCode')
219225
->will($this->returnValue(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE));
220226

@@ -233,7 +239,7 @@ protected function setUp()
233239
'\Magento\Framework\Model\Context',
234240
['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'], [], '', false
235241
);
236-
$contextMock->expects($this->any())->method('getAppState')->will($this->returnValue($stateMock));
242+
$contextMock->expects($this->any())->method('getAppState')->will($this->returnValue($this->appStateMock));
237243
$contextMock->expects($this->any())
238244
->method('getEventDispatcher')
239245
->will($this->returnValue($this->eventManagerMock));
@@ -370,15 +376,6 @@ protected function setUp()
370376
'data' => ['id' => 1]
371377
]
372378
);
373-
374-
$this->appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class)
375-
->disableOriginalConstructor()
376-
->setMethods([])
377-
->getMock();
378-
$modelReflection = new \ReflectionClass(get_class($this->model));
379-
$appStateReflection = $modelReflection->getProperty('appState');
380-
$appStateReflection->setAccessible(true);
381-
$appStateReflection->setValue($this->model, $this->appStateMock);
382379
}
383380

384381
public function testGetAttributes()
@@ -800,6 +797,20 @@ public function testSave()
800797
$this->model->afterSave();
801798
}
802799

800+
/**
801+
* Image cache generation would not be performed if area was emulated
802+
*/
803+
public function testSaveIfAreaEmulated()
804+
{
805+
$this->appStateMock->expects($this->any())->method('isAreaCodeEmulated')->willReturn(true);
806+
$this->imageCache->expects($this->never())
807+
->method('generate')
808+
->with($this->model);
809+
$this->configureSaveTest();
810+
$this->model->beforeSave();
811+
$this->model->afterSave();
812+
}
813+
803814
/**
804815
* Test for `save` method for duplicated product
805816
*/

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ColumnFactory
1818
protected $jsComponentMap = [
1919
'text' => 'Magento_Ui/js/grid/columns/column',
2020
'select' => 'Magento_Ui/js/grid/columns/select',
21+
'multiselect' => 'Magento_Ui/js/grid/columns/select',
2122
'date' => 'Magento_Ui/js/grid/columns/date',
2223
];
2324

@@ -29,7 +30,7 @@ class ColumnFactory
2930
'text' => 'text',
3031
'boolean' => 'select',
3132
'select' => 'select',
32-
'multiselect' => 'select',
33+
'multiselect' => 'multiselect',
3334
'date' => 'date',
3435
];
3536

0 commit comments

Comments
 (0)