Skip to content

Commit e6fee77

Browse files
author
Alexander Akimov
authored
Merge pull request #3448 from magento-tsg/2.2-develop-pr57
[TSG] Backporting for 2.2 (pr57) (2.2.8)
2 parents e673c83 + 48e1b11 commit e6fee77

File tree

82 files changed

+2268
-592
lines changed

Some content is hidden

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

82 files changed

+2268
-592
lines changed
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
}

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

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice;
1515

1616
/**
17-
* Process tier price data for handled existing product
17+
* Process tier price data for handled existing product.
1818
*/
19-
class UpdateHandler implements ExtensionInterface
19+
class UpdateHandler extends AbstractHandler
2020
{
2121
/**
2222
* @var \Magento\Store\Model\StoreManagerInterface
@@ -28,11 +28,6 @@ class UpdateHandler 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
}
@@ -68,8 +64,7 @@ public function __construct(
6864
* @param \Magento\Catalog\Api\Data\ProductInterface|object $entity
6965
* @param array $arguments
7066
* @return \Magento\Catalog\Api\Data\ProductInterface|object
71-
* @throws \Magento\Framework\Exception\NoSuchEntityException
72-
* @throws \Magento\Framework\Exception\LocalizedException
67+
* @throws \Magento\Framework\Exception\InputException
7368
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7469
*/
7570
public function execute($entity, $arguments = [])
@@ -110,34 +105,6 @@ public function execute($entity, $arguments = [])
110105
return $entity;
111106
}
112107

113-
/**
114-
* Get additional tier price fields
115-
*
116-
* @param array $objectArray
117-
* @return array
118-
*/
119-
private function getAdditionalFields(array $objectArray): array
120-
{
121-
$percentageValue = $this->getPercentage($objectArray);
122-
return [
123-
'value' => $percentageValue ? null : $objectArray['price'],
124-
'percentage_value' => $percentageValue ?: null,
125-
];
126-
}
127-
128-
/**
129-
* Check whether price has percentage value.
130-
*
131-
* @param array $priceRow
132-
* @return integer|null
133-
*/
134-
private function getPercentage(array $priceRow)
135-
{
136-
return isset($priceRow['percentage_value']) && is_numeric($priceRow['percentage_value'])
137-
? (int)$priceRow['percentage_value']
138-
: null;
139-
}
140-
141108
/**
142109
* Update existing tier prices for processed product
143110
*
@@ -168,7 +135,7 @@ private function updateValues(array $valuesToUpdate, array $oldValues): bool
168135
}
169136

170137
/**
171-
* Insert new tier prices for processed product
138+
* Insert new tier prices for processed product.
172139
*
173140
* @param int $productId
174141
* @param array $valuesToInsert
@@ -192,7 +159,7 @@ private function insertValues(int $productId, array $valuesToInsert): bool
192159
}
193160

194161
/**
195-
* Delete tier price values for processed product
162+
* Delete tier price values for processed product.
196163
*
197164
* @param int $productId
198165
* @param array $valuesToDelete
@@ -210,48 +177,24 @@ private function deleteValues(int $productId, array $valuesToDelete): bool
210177
}
211178

212179
/**
213-
* Get generated price key based on price data
180+
* Get generated price key based on price data.
214181
*
215182
* @param array $priceData
216183
* @return string
217184
*/
218185
private function getPriceKey(array $priceData): string
219186
{
187+
$qty = $this->parseQty($priceData['price_qty']);
220188
$key = implode(
221189
'-',
222-
array_merge([$priceData['website_id'], $priceData['cust_group']], [(int)$priceData['price_qty']])
190+
array_merge([$priceData['website_id'], $priceData['cust_group']], [$qty])
223191
);
224192

225193
return $key;
226194
}
227195

228196
/**
229-
* Prepare tier price data by provided price row data
230-
*
231-
* @param array $data
232-
* @return array
233-
* @throws \Magento\Framework\Exception\LocalizedException
234-
*/
235-
private function prepareTierPrice(array $data): array
236-
{
237-
$useForAllGroups = (int)$data['cust_group'] === $this->groupManagement->getAllCustomersGroup()->getId();
238-
$customerGroupId = $useForAllGroups ? 0 : $data['cust_group'];
239-
$tierPrice = array_merge(
240-
$this->getAdditionalFields($data),
241-
[
242-
'website_id' => $data['website_id'],
243-
'all_groups' => (int)$useForAllGroups,
244-
'customer_group_id' => $customerGroupId,
245-
'value' => $data['price'] ?? null,
246-
'qty' => (int)$data['price_qty']
247-
]
248-
);
249-
250-
return $tierPrice;
251-
}
252-
253-
/**
254-
* Check by id is website global
197+
* Check by id is website global.
255198
*
256199
* @param int $websiteId
257200
* @return bool
@@ -281,6 +224,8 @@ private function prepareOldTierPriceToCompare($origPrices): array
281224
}
282225

283226
/**
227+
* Prepare new data for save.
228+
*
284229
* @param array $priceRows
285230
* @param bool $isGlobal
286231
* @return array

app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ public function loadProductCount($items, $countRegular = true, $countAnchor = tr
265265
'main_table.category_id=e.entity_id',
266266
[]
267267
)->where(
268-
'e.entity_id = :entity_id'
269-
)->orWhere(
270-
'e.path LIKE :c_path'
268+
'(e.entity_id = :entity_id OR e.path LIKE :c_path)'
271269
);
272270
if ($websiteId) {
273271
$select->join(

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AdminProductAttributeActionGroup.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@
2525
<click selector="{{AttributePropertiesSection.save}}" stepKey="saveAttribute"/>
2626
<see selector="{{AdminMessagesSection.successMessage}}" userInput="You saved the product attribute." stepKey="successMessage"/>
2727
</actionGroup>
28+
<actionGroup name="navigateToProductAttributeByCode">
29+
<arguments>
30+
<argument name="attributeCode" type="string"/>
31+
</arguments>
32+
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="goToProductAttributesPage"/>
33+
<conditionalClick selector="{{AdminDataGridHeaderSection.clearFilters}}" dependentSelector="{{AdminDataGridHeaderSection.clearFilters}}" visible="true" stepKey="clickClearFilters"/>
34+
<fillField selector="{{AdminProductAttributeGridSection.filterByAttributeCode}}" userInput="{{attributeCode}}" stepKey="fillFilter"/>
35+
<click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickSearch"/>
36+
<click selector="{{AdminProductAttributeGridSection.attributeCode(attributeCode)}}" stepKey="clickRowToEdit"/>
37+
<waitForPageLoad stepKey="waitForColorAttributePageLoad"/>
38+
</actionGroup>
2839
</actionGroups>

0 commit comments

Comments
 (0)