Skip to content

Commit d5a3db7

Browse files
authored
Merge pull request PrestaShop#34625 from M0rgan01/fix/34358
Add hook "actionUpdateQuantity" in product v2
2 parents 2ee8ac1 + 77c2476 commit d5a3db7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Adapter/Product/Combination/Update/CombinationStockUpdater.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\ValueObject\StockModification;
4040
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
4141
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopId;
42+
use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
4243
use PrestaShop\PrestaShop\Core\Stock\StockManager;
4344
use StockAvailable;
4445

@@ -72,18 +73,25 @@ class CombinationStockUpdater
7273
*/
7374
private $configuration;
7475

76+
/**
77+
* @var HookDispatcherInterface
78+
*/
79+
private $hookDispatcher;
80+
7581
public function __construct(
7682
StockAvailableRepository $stockAvailableRepository,
7783
CombinationRepository $combinationRepository,
7884
MovementReasonRepository $movementReasonRepository,
7985
StockManager $stockManager,
80-
ShopConfigurationInterface $configuration
86+
ShopConfigurationInterface $configuration,
87+
HookDispatcherInterface $hookDispatcher
8188
) {
8289
$this->stockAvailableRepository = $stockAvailableRepository;
8390
$this->combinationRepository = $combinationRepository;
8491
$this->stockManager = $stockManager;
8592
$this->configuration = $configuration;
8693
$this->movementReasonRepository = $movementReasonRepository;
94+
$this->hookDispatcher = $hookDispatcher;
8795
}
8896

8997
/**
@@ -131,7 +139,6 @@ private function updateStockAvailable(StockAvailable $stockAvailable, Combinatio
131139

132140
$fallbackShopId = $this->stockAvailableRepository->getFallbackShopId($stockAvailable);
133141
$this->stockAvailableRepository->update($stockAvailable, $fallbackShopId);
134-
135142
// save movement only after stockAvailable has been updated
136143
if ($stockModification) {
137144
$this->saveMovement($stockAvailable, $stockModification, $previousQuantity, $fallbackShopId->getValue());
@@ -165,6 +172,15 @@ private function saveMovement(StockAvailable $stockAvailable, StockModification
165172
'id_shop' => (int) $affectedShopId,
166173
]
167174
);
175+
176+
$this->hookDispatcher->dispatchWithParameters('actionUpdateQuantity',
177+
[
178+
'id_product' => $stockAvailable->id_product,
179+
'id_product_attribute' => $stockAvailable->id_product_attribute,
180+
'quantity' => $stockAvailable->quantity,
181+
'delta_quantity' => $deltaQuantity,
182+
'id_shop' => $stockAvailable->id_shop,
183+
]);
168184
}
169185

170186
private function updateStockByShopConstraint(

src/PrestaShopBundle/Resources/config/services/adapter/product/_combination.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ services:
6363
- '@PrestaShop\PrestaShop\Adapter\Product\Stock\Repository\MovementReasonRepository'
6464
- '@PrestaShop\PrestaShop\Core\Stock\StockManager'
6565
- '@PrestaShop\PrestaShop\Core\Domain\Configuration\ShopConfigurationInterface'
66+
- '@prestashop.core.hook.dispatcher'
6667

6768
PrestaShop\PrestaShop\Adapter\Product\Combination\Create\CombinationCreator:
6869
autowire: true

0 commit comments

Comments
 (0)