Skip to content

Commit 3208695

Browse files
committed
added UpdateHandlerPlugin for tierprice issue
1 parent 886b557 commit 3208695

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\Customer\Api\GroupManagementInterface;
1616
use Magento\Framework\EntityManager\MetadataPool;
1717
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice;
18-
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1918

2019
/**
2120
* Process tier price data for handled existing product.
@@ -85,10 +84,6 @@ public function execute($entity, $arguments = [])
8584
{
8685
$attribute = $this->attributeRepository->get('tier_price');
8786
$priceRows = $entity->getData($attribute->getName());
88-
$origPrices = $entity->getOrigData($attribute->getName());
89-
if ($entity->getTypeId() === Configurable::TYPE_CODE && null !== $origPrices) {
90-
$priceRows = [];
91-
}
9287
if (null !== $priceRows) {
9388
if (!is_array($priceRows)) {
9489
throw new \Magento\Framework\Exception\InputException(
@@ -101,6 +96,7 @@ public function execute($entity, $arguments = [])
10196
$productId = (int)$entity->getData($identifierField);
10297

10398
// prepare original data to compare
99+
$origPrices = $entity->getOrigData($attribute->getName());
104100
$old = $this->prepareOldTierPriceToCompare($origPrices);
105101
// prepare data for save
106102
$new = $this->prepareNewDataForSave($priceRows, $isGlobal);
@@ -266,4 +262,4 @@ private function prepareNewDataForSave(array $priceRows, bool $isGlobal = true):
266262

267263
return $new;
268264
}
269-
}
265+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Attribute\Backend\TierPrice;
4+
5+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
6+
use Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler;
7+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
8+
9+
class UpdateHandlerPlugin
10+
{
11+
/**
12+
* @var ProductAttributeRepositoryInterface
13+
*/
14+
private $attributeRepository;
15+
16+
/**
17+
* @param ProductAttributeRepositoryInterface $attributeRepository
18+
*/
19+
public function __construct(
20+
ProductAttributeRepositoryInterface $attributeRepository
21+
) {
22+
$this->attributeRepository = $attributeRepository;
23+
}
24+
25+
/**
26+
* @param UpdateHandler $subject
27+
* @param mixed $entity
28+
* @param array $arguments
29+
* @return array
30+
*/
31+
public function beforeExecute(UpdateHandler $subject, $entity, $arguments = [])
32+
{
33+
$attribute = $this->attributeRepository->get('tier_price');
34+
$origPrices = $entity->getOrigData($attribute->getName());
35+
36+
if ($entity->getTypeId() === Configurable::TYPE_CODE && $origPrices !== null) {
37+
$entity->setData($attribute->getName(), []);
38+
}
39+
40+
return [$entity, $arguments];
41+
}
42+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,7 @@
288288
<type name="Magento\CatalogInventory\Model\ResourceModel\Stock\Item">
289289
<plugin name="updateStockChangedAuto" type="Magento\ConfigurableProduct\Model\Plugin\UpdateStockChangedAuto" />
290290
</type>
291+
<type name="Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler">
292+
<plugin name="tier_price_update_handler_plugin" type="Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandlerPlugin" sortOrder="10" disabled="false"/>
293+
</type>
291294
</config>

0 commit comments

Comments
 (0)