Skip to content

Commit 584242c

Browse files
authored
Merge pull request #5 from magento/2.2-develop
2.2 develop-update branch
2 parents 7c013a1 + b1e26d5 commit 584242c

File tree

128 files changed

+3159
-1422
lines changed

Some content is hidden

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

128 files changed

+3159
-1422
lines changed

app/code/Magento/Analytics/Model/Cryptographer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ private function getInitializationVector()
124124
*/
125125
private function validateCipherMethod($cipherMethod)
126126
{
127-
$methods = openssl_get_cipher_methods();
127+
$methods = array_map(
128+
'strtolower',
129+
openssl_get_cipher_methods()
130+
);
131+
$cipherMethod = strtolower($cipherMethod);
132+
128133
return (false !== array_search($cipherMethod, $methods));
129134
}
130135
}

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,11 @@ public function getSku($product)
310310
$selectionIds = $this->serializer->unserialize($customOption->getValue());
311311
if (!empty($selectionIds)) {
312312
$selections = $this->getSelectionsByIds($selectionIds, $product);
313-
foreach ($selections->getItems() as $selection) {
314-
$skuParts[] = $selection->getSku();
313+
foreach ($selectionIds as $selectionId) {
314+
$entity = $selections->getItemByColumnValue('selection_id', $selectionId);
315+
if (isset($entity) && $entity->getEntityId()) {
316+
$skuParts[] = $entity->getSku();
317+
}
315318
}
316319
}
317320
}

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ public function testGetSkuWithoutType()
15951595
->disableOriginalConstructor()
15961596
->getMock();
15971597
$selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
1598-
->setMethods(['getSku', '__wakeup'])
1598+
->setMethods(['getSku', 'getEntityId', '__wakeup'])
15991599
->disableOriginalConstructor()
16001600
->getMock();
16011601

@@ -1623,9 +1623,12 @@ public function testGetSkuWithoutType()
16231623
->will($this->returnValue($serializeIds));
16241624
$selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6);
16251625
$selectionMock->expects(($this->any()))
1626-
->method('getItems')
1627-
->will($this->returnValue([$selectionItemMock]));
1628-
$selectionItemMock->expects($this->any())
1626+
->method('getItemByColumnValue')
1627+
->will($this->returnValue($selectionItemMock));
1628+
$selectionItemMock->expects($this->at(0))
1629+
->method('getEntityId')
1630+
->will($this->returnValue(1));
1631+
$selectionItemMock->expects($this->once())
16291632
->method('getSku')
16301633
->will($this->returnValue($itemSku));
16311634

app/code/Magento/Bundle/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
</argument>
141141
</arguments>
142142
</type>
143+
<type name="Magento\Sales\Model\Order\ProductOption">
144+
<arguments>
145+
<argument name="processorPool" xsi:type="array">
146+
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
147+
</argument>
148+
</arguments>
149+
</type>
143150
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
144151
<arguments>
145152
<argument name="excludeAdjustments" xsi:type="array">

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,19 @@ private function getCategoryLinksPositions($entity)
106106
*/
107107
private function mergeCategoryLinks($newCategoryPositions, $oldCategoryPositions)
108108
{
109-
$result = [];
110109
if (empty($newCategoryPositions)) {
111-
return $result;
110+
return [];
112111
}
113112

113+
$categoryPositions = array_combine(array_column($oldCategoryPositions, 'category_id'), $oldCategoryPositions);
114114
foreach ($newCategoryPositions as $newCategoryPosition) {
115-
$key = array_search(
116-
$newCategoryPosition['category_id'],
117-
array_column($oldCategoryPositions, 'category_id')
118-
);
119-
120-
if ($key === false) {
121-
$result[] = $newCategoryPosition;
122-
} elseif (isset($oldCategoryPositions[$key])
123-
&& $oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']
124-
) {
125-
$result[] = $newCategoryPositions[$key];
126-
unset($oldCategoryPositions[$key]);
115+
$categoryId = $newCategoryPosition['category_id'];
116+
if (!isset($categoryPositions[$categoryId])) {
117+
$categoryPositions[$categoryId] = ['category_id' => $categoryId];
127118
}
119+
$categoryPositions[$categoryId]['position'] = $newCategoryPosition['position'];
128120
}
129-
$result = array_merge($result, $oldCategoryPositions);
121+
$result = array_values($categoryPositions);
130122

131123
return $result;
132124
}

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

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ abstract class AbstractAction
126126
*/
127127
private $queryGenerator;
128128

129+
/**
130+
* Current store id.
131+
* @var int
132+
*/
133+
private $currentStoreId = 0;
134+
129135
/**
130136
* @param ResourceConnection $resource
131137
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -167,6 +173,7 @@ protected function reindex()
167173
{
168174
foreach ($this->storeManager->getStores() as $store) {
169175
if ($this->getPathFromCategoryId($store->getRootCategoryId())) {
176+
$this->currentStoreId = $store->getId();
170177
$this->reindexRootCategory($store);
171178
$this->reindexAnchorCategories($store);
172179
$this->reindexNonAnchorCategories($store);
@@ -594,7 +601,7 @@ protected function getTemporaryTreeIndexTableName()
594601
if (empty($this->tempTreeIndexTableName)) {
595602
$this->tempTreeIndexTableName = $this->connection->getTableName('temp_catalog_category_tree_index')
596603
. '_'
597-
. substr(md5(time() . random_int(0, 999999999)), 0, 8);
604+
. substr(sha1(time() . random_int(0, 999999999)), 0, 8);
598605
}
599606

600607
return $this->tempTreeIndexTableName;
@@ -649,30 +656,47 @@ protected function makeTempCategoryTreeIndex()
649656
}
650657

651658
/**
652-
* Populate the temporary category tree index table
659+
* Populate the temporary category tree index table.
653660
*
654661
* @param string $temporaryName
662+
* @return void
655663
* @since 101.0.0
656664
*/
657665
protected function fillTempCategoryTreeIndex($temporaryName)
658666
{
659-
$offset = 0;
660-
$limit = 500;
661-
662-
$categoryTable = $this->getTable('catalog_category_entity');
663-
664-
$categoriesSelect = $this->connection->select()
665-
->from(
666-
['c' => $categoryTable],
667-
['entity_id', 'path']
668-
)->limit($limit, $offset);
669-
670-
$categories = $this->connection->fetchAll($categoriesSelect);
667+
$isActiveAttributeId = $this->config->getAttribute(
668+
\Magento\Catalog\Model\Category::ENTITY,
669+
'is_active'
670+
)->getId();
671+
$categoryMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class);
672+
$categoryLinkField = $categoryMetadata->getLinkField();
673+
$selects = $this->prepareSelectsByRange(
674+
$this->connection->select()
675+
->from(
676+
['c' => $this->getTable('catalog_category_entity')],
677+
['entity_id', 'path']
678+
)->joinInner(
679+
['ccacd' => $this->getTable('catalog_category_entity_int')],
680+
'ccacd.' . $categoryLinkField . ' = c.' . $categoryLinkField
681+
. ' AND ccacd.store_id = 0' . ' AND ccacd.attribute_id = ' . $isActiveAttributeId,
682+
[]
683+
)->joinLeft(
684+
['ccacs' => $this->getTable('catalog_category_entity_int')],
685+
'ccacs.' . $categoryLinkField . ' = c.' . $categoryLinkField
686+
. ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = '
687+
. $this->currentStoreId,
688+
[]
689+
)->where(
690+
$this->connection->getIfNullSql('ccacs.value', 'ccacd.value') . ' = ?',
691+
1
692+
),
693+
'entity_id'
694+
);
671695

672-
while ($categories) {
696+
foreach ($selects as $select) {
673697
$values = [];
674698

675-
foreach ($categories as $category) {
699+
foreach ($this->connection->fetchAll($select) as $category) {
676700
foreach (explode('/', $category['path']) as $parentId) {
677701
if ($parentId !== $category['entity_id']) {
678702
$values[] = [$parentId, $category['entity_id']];
@@ -683,15 +707,6 @@ protected function fillTempCategoryTreeIndex($temporaryName)
683707
if (count($values) > 0) {
684708
$this->connection->insertArray($temporaryName, ['parent_id', 'child_id'], $values);
685709
}
686-
687-
$offset += $limit;
688-
$categoriesSelect = $this->connection->select()
689-
->from(
690-
['c' => $categoryTable],
691-
['entity_id', 'path']
692-
)->limit($limit, $offset);
693-
694-
$categories = $this->connection->fetchAll($categoriesSelect);
695710
}
696711
}
697712

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Product\Attribute\Backend\TierPrice;
7+
8+
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
9+
use Magento\Store\Model\StoreManagerInterface;
10+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Customer\Api\GroupManagementInterface;
13+
use Magento\Framework\EntityManager\MetadataPool;
14+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice;
15+
16+
/**
17+
* Tier price data abstract handler.
18+
*/
19+
abstract class AbstractHandler implements ExtensionInterface
20+
{
21+
/**
22+
* @var \Magento\Customer\Api\GroupManagementInterface
23+
*/
24+
protected $groupManagement;
25+
26+
/**
27+
* @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
28+
*/
29+
public function __construct(
30+
GroupManagementInterface $groupManagement
31+
) {
32+
$this->groupManagement = $groupManagement;
33+
}
34+
35+
/**
36+
* Get additional tier price fields.
37+
*
38+
* @return array
39+
*/
40+
protected function getAdditionalFields(array $objectArray): array
41+
{
42+
$percentageValue = $this->getPercentage($objectArray);
43+
44+
return [
45+
'value' => $percentageValue ? null : $objectArray['price'],
46+
'percentage_value' => $percentageValue ?: null,
47+
];
48+
}
49+
50+
/**
51+
* Check whether price has percentage value.
52+
*
53+
* @param array $priceRow
54+
* @return integer|null
55+
*/
56+
protected function getPercentage(array $priceRow)
57+
{
58+
return isset($priceRow['percentage_value']) && is_numeric($priceRow['percentage_value'])
59+
? (int)$priceRow['percentage_value']
60+
: null;
61+
}
62+
63+
/**
64+
* Prepare tier price data by provided price row data.
65+
*
66+
* @param array $data
67+
* @return array
68+
*/
69+
protected function prepareTierPrice(array $data): array
70+
{
71+
$useForAllGroups = (int)$data['cust_group'] === $this->groupManagement->getAllCustomersGroup()->getId();
72+
$customerGroupId = $useForAllGroups ? 0 : $data['cust_group'];
73+
$tierPrice = array_merge(
74+
$this->getAdditionalFields($data),
75+
[
76+
'website_id' => $data['website_id'],
77+
'all_groups' => (int)$useForAllGroups,
78+
'customer_group_id' => $customerGroupId,
79+
'value' => $data['price'] ?? null,
80+
'qty' => $this->parseQty($data['price_qty']),
81+
]
82+
);
83+
84+
return $tierPrice;
85+
}
86+
87+
/**
88+
* Parse quantity value into float.
89+
*
90+
* @param mixed $value
91+
* @return float|int
92+
*/
93+
protected function parseQty($value)
94+
{
95+
return $value * 1;
96+
}
97+
}

0 commit comments

Comments
 (0)