Skip to content

Commit c9d1923

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-73140' into 2.2-develop-pr58
2 parents 0cae940 + bc904a2 commit c9d1923

File tree

84 files changed

+2351
-639
lines changed

Some content is hidden

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

84 files changed

+2351
-639
lines changed

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+
}

app/code/Magento/Catalog/Model/Product/Attribute/Backend/TierPrice/SaveHandler.php

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Process tier price data for handled new product
1818
*/
19-
class SaveHandler implements ExtensionInterface
19+
class SaveHandler extends AbstractHandler
2020
{
2121
/**
2222
* @var \Magento\Store\Model\StoreManagerInterface
@@ -28,11 +28,6 @@ class SaveHandler implements ExtensionInterface
2828
*/
2929
private $attributeRepository;
3030

31-
/**
32-
* @var \Magento\Customer\Api\GroupManagementInterface
33-
*/
34-
private $groupManagement;
35-
3631
/**
3732
* @var \Magento\Framework\EntityManager\MetadataPool
3833
*/
@@ -57,9 +52,10 @@ public function __construct(
5752
MetadataPool $metadataPool,
5853
Tierprice $tierPriceResource
5954
) {
55+
parent::__construct($groupManagement);
56+
6057
$this->storeManager = $storeManager;
6158
$this->attributeRepository = $attributeRepository;
62-
$this->groupManagement = $groupManagement;
6359
$this->metadataPoll = $metadataPool;
6460
$this->tierPriceResource = $tierPriceResource;
6561
}
@@ -70,8 +66,6 @@ public function __construct(
7066
* @param \Magento\Catalog\Api\Data\ProductInterface|object $entity
7167
* @param array $arguments
7268
* @return \Magento\Catalog\Api\Data\ProductInterface|object
73-
* @throws \Magento\Framework\Exception\NoSuchEntityException
74-
* @throws \Magento\Framework\Exception\LocalizedException
7569
* @throws \Magento\Framework\Exception\InputException
7670
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7771
*/
@@ -113,56 +107,4 @@ public function execute($entity, $arguments = [])
113107

114108
return $entity;
115109
}
116-
117-
/**
118-
* Get additional tier price fields
119-
*
120-
* @return array
121-
*/
122-
private function getAdditionalFields(array $objectArray): array
123-
{
124-
$percentageValue = $this->getPercentage($objectArray);
125-
return [
126-
'value' => $percentageValue ? null : $objectArray['price'],
127-
'percentage_value' => $percentageValue ?: null,
128-
];
129-
}
130-
131-
/**
132-
* Check whether price has percentage value.
133-
*
134-
* @param array $priceRow
135-
* @return integer|null
136-
*/
137-
private function getPercentage(array $priceRow)
138-
{
139-
return isset($priceRow['percentage_value']) && is_numeric($priceRow['percentage_value'])
140-
? (int)$priceRow['percentage_value']
141-
: null;
142-
}
143-
144-
/**
145-
* Prepare tier price data by provided price row data
146-
*
147-
* @param array $data
148-
* @return array
149-
* @throws \Magento\Framework\Exception\LocalizedException
150-
*/
151-
private function prepareTierPrice(array $data): array
152-
{
153-
$useForAllGroups = (int)$data['cust_group'] === $this->groupManagement->getAllCustomersGroup()->getId();
154-
$customerGroupId = $useForAllGroups ? 0 : $data['cust_group'];
155-
$tierPrice = array_merge(
156-
$this->getAdditionalFields($data),
157-
[
158-
'website_id' => $data['website_id'],
159-
'all_groups' => (int)$useForAllGroups,
160-
'customer_group_id' => $customerGroupId,
161-
'value' => $data['price'] ?? null,
162-
'qty' => (int)$data['price_qty']
163-
]
164-
);
165-
166-
return $tierPrice;
167-
}
168110
}

0 commit comments

Comments
 (0)