Skip to content

Commit 7ea39cd

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #1136 from magento-tsg/2.1.8-develop-pr15
[TSG] Backporting for 2.1 (pr15) (2.1.8)
2 parents ff253a7 + 19b8f08 commit 7ea39cd

File tree

66 files changed

+3303
-594
lines changed

Some content is hidden

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

66 files changed

+3303
-594
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function execute()
6868
$attributeCode = $attributeCode ?: $this->generateCode($frontendLabel[0]);
6969
$attributeId = $this->getRequest()->getParam('attribute_id');
7070
$attribute = $this->_objectManager->create(
71-
'Magento\Catalog\Model\ResourceModel\Eav\Attribute'
71+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
7272
)->loadByCode(
7373
$this->_entityTypeId,
7474
$attributeCode
@@ -87,10 +87,10 @@ public function execute()
8787
if ($this->getRequest()->has('new_attribute_set_name')) {
8888
$setName = $this->getRequest()->getParam('new_attribute_set_name');
8989
/** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
90-
$attributeSet = $this->_objectManager->create('Magento\Eav\Model\Entity\Attribute\Set');
90+
$attributeSet = $this->_objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
9191
$attributeSet->setEntityTypeId($this->_entityTypeId)->load($setName, 'attribute_set_name');
9292
if ($attributeSet->getId()) {
93-
$setName = $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($setName);
93+
$setName = $this->_objectManager->get(\Magento\Framework\Escaper::class)->escapeHtml($setName);
9494
$this->messageManager->addError(__('An attribute set named \'%1\' already exists.', $setName));
9595

9696
$layout = $this->layoutFactory->create();
@@ -149,10 +149,16 @@ private function setMessageToResponse($response, $messages)
149149
/**
150150
* @param DataObject $response
151151
* @param array|null $options
152+
*
153+
* @return void
152154
*/
153155
private function checkUniqueOption(DataObject $response, array $options = null)
154156
{
155-
if (is_array($options) && !$this->isUniqueAdminValues($options['value'], $options['delete'])) {
157+
if (is_array($options)
158+
&& !empty($options['value'])
159+
&& !empty($options['delete'])
160+
&& !$this->isUniqueAdminValues($options['value'], $options['delete'])
161+
) {
156162
$this->setMessageToResponse($response, [__('The value of Admin must be unique.')]);
157163
$response->setError(true);
158164
}

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\Catalog\Model\Indexer\Category\Product;
1010

11+
use Magento\Framework\DB\Query\Generator as QueryGenerator;
1112
use Magento\Framework\App\ResourceConnection;
1213
use Magento\Framework\EntityManager\MetadataPool;
1314

@@ -102,20 +103,29 @@ abstract class AbstractAction
102103
*/
103104
protected $tempTreeIndexTableName;
104105

106+
/**
107+
* @var QueryGenerator
108+
*/
109+
private $queryGenerator;
110+
105111
/**
106112
* @param ResourceConnection $resource
107113
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
108114
* @param \Magento\Catalog\Model\Config $config
115+
* @param QueryGenerator $queryGenerator
109116
*/
110117
public function __construct(
111118
\Magento\Framework\App\ResourceConnection $resource,
112119
\Magento\Store\Model\StoreManagerInterface $storeManager,
113-
\Magento\Catalog\Model\Config $config
120+
\Magento\Catalog\Model\Config $config,
121+
QueryGenerator $queryGenerator = null
114122
) {
115123
$this->resource = $resource;
116124
$this->connection = $resource->getConnection();
117125
$this->storeManager = $storeManager;
118126
$this->config = $config;
127+
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
128+
->get(QueryGenerator::class);
119129
}
120130

121131
/**
@@ -302,22 +312,35 @@ protected function isRangingNeeded()
302312
}
303313

304314
/**
305-
* Return selects cut by min and max
315+
* Return selects cut by min and max.
306316
*
307317
* @param \Magento\Framework\DB\Select $select
308318
* @param string $field
309319
* @param int $range
310320
* @return \Magento\Framework\DB\Select[]
311321
*/
312-
protected function prepareSelectsByRange(\Magento\Framework\DB\Select $select, $field, $range = self::RANGE_CATEGORY_STEP)
313-
{
314-
return $this->isRangingNeeded() ? $this->connection->selectsByRange(
315-
$field,
316-
$select,
317-
$range
318-
) : [
319-
$select
320-
];
322+
protected function prepareSelectsByRange(
323+
\Magento\Framework\DB\Select $select,
324+
$field,
325+
$range = self::RANGE_CATEGORY_STEP
326+
) {
327+
if ($this->isRangingNeeded()) {
328+
$iterator = $this->queryGenerator->generate(
329+
$field,
330+
$select,
331+
$range,
332+
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
333+
);
334+
335+
$queries = [];
336+
foreach ($iterator as $query) {
337+
$queries[] = $query;
338+
}
339+
340+
return $queries;
341+
}
342+
343+
return [$select];
321344
}
322345

323346
/**

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,30 @@ protected function _prepareFinalPriceData($entityIds = null)
235235
* @param string|null $type product type, all if null
236236
* @return $this
237237
* @throws \Magento\Framework\Exception\LocalizedException
238-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
239238
*/
240239
protected function prepareFinalPriceDataForType($entityIds, $type)
241240
{
242241
$this->_prepareDefaultFinalPriceTable();
242+
243+
$select = $this->getSelect($entityIds, $type);
244+
$query = $select->insertFromSelect($this->_getDefaultFinalPriceTable(), [], false);
245+
$this->getConnection()->query($query);
246+
return $this;
247+
}
248+
249+
/**
250+
* Forms Select for collecting price related data for final price index table
251+
* Next types of prices took into account: default, special, tier price
252+
* Moved to protected for possible reusing
253+
*
254+
* @param int|array $entityIds Ids for filtering output result
255+
* @param string|null $type Type for filtering output result by specified product type (all if null)
256+
* @return \Magento\Framework\DB\Select
257+
* @throws \Magento\Framework\Exception\LocalizedException
258+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
259+
*/
260+
protected function getSelect($entityIds = null, $type = null)
261+
{
243262
$metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
244263
$connection = $this->getConnection();
245264
$select = $connection->select()->from(
@@ -368,13 +387,10 @@ protected function prepareFinalPriceDataForType($entityIds, $type)
368387
'select' => $select,
369388
'entity_field' => new \Zend_Db_Expr('e.entity_id'),
370389
'website_field' => new \Zend_Db_Expr('cw.website_id'),
371-
'store_field' => new \Zend_Db_Expr('cs.store_id')
390+
'store_field' => new \Zend_Db_Expr('cs.store_id'),
372391
]
373392
);
374-
375-
$query = $select->insertFromSelect($this->_getDefaultFinalPriceTable(), [], false);
376-
$connection->query($query);
377-
return $this;
393+
return $select;
378394
}
379395

380396
/**

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,16 @@ public function testUniqueValidation(array $options, $isError)
198198
public function provideUniqueData()
199199
{
200200
return [
201-
// valid options
202-
[
201+
'no values' => [
202+
[
203+
'delete' => [
204+
"option_0" => "",
205+
"option_1" => "",
206+
"option_2" => "",
207+
]
208+
], false
209+
],
210+
'valid options' => [
203211
[
204212
'value' => [
205213
"option_0" => [1, 0],
@@ -213,8 +221,7 @@ public function provideUniqueData()
213221
]
214222
], false
215223
],
216-
//with duplicate
217-
[
224+
'duplicate options' => [
218225
[
219226
'value' => [
220227
"option_0" => [1, 0],
@@ -228,8 +235,7 @@ public function provideUniqueData()
228235
]
229236
], true
230237
],
231-
//with duplicate but deleted
232-
[
238+
'duplicate and deleted' => [
233239
[
234240
'value' => [
235241
"option_0" => [1, 0],

app/code/Magento/Catalog/etc/eav_attributes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<field code="is_searchable" locked="true" />
3131
</attribute>
3232
<attribute code="category_ids">
33+
<field code="is_global" locked="true" />
3334
<field code="is_searchable" locked="true" />
3435
<field code="used_for_sort_by" locked="true" />
3536
<field code="is_used_in_grid" locked="true" />

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ protected function collectRawData()
944944

945945
if ($storeId != Store::DEFAULT_STORE_ID
946946
&& isset($data[$itemId][Store::DEFAULT_STORE_ID][$fieldName])
947-
&& $data[$itemId][Store::DEFAULT_STORE_ID][$fieldName] == $attrValue
947+
&& $data[$itemId][Store::DEFAULT_STORE_ID][$fieldName] == htmlspecialchars_decode($attrValue)
948948
) {
949949
continue;
950950
}
@@ -983,7 +983,7 @@ protected function collectRawData()
983983
$data[$itemId][$storeId][self::COL_ATTR_SET] = $this->_attrSetIdToName[$attrSetId];
984984
$data[$itemId][$storeId][self::COL_TYPE] = $item->getTypeId();
985985
}
986-
$data[$itemId][$storeId][self::COL_SKU] = $item->getSku();
986+
$data[$itemId][$storeId][self::COL_SKU] = htmlspecialchars_decode($item->getSku());
987987
$data[$itemId][$storeId]['store_id'] = $storeId;
988988
$data[$itemId][$storeId]['product_id'] = $itemId;
989989
$data[$itemId][$storeId]['product_link_id'] = $productLinkId;

0 commit comments

Comments
 (0)