|
39 | 39 | use PrestaShop\PrestaShop\Core\Domain\Product\Stock\ValueObject\StockModification;
|
40 | 40 | use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
|
41 | 41 | use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopId;
|
| 42 | +use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface; |
42 | 43 | use PrestaShop\PrestaShop\Core\Stock\StockManager;
|
43 | 44 | use StockAvailable;
|
44 | 45 |
|
@@ -72,18 +73,25 @@ class CombinationStockUpdater
|
72 | 73 | */
|
73 | 74 | private $configuration;
|
74 | 75 |
|
| 76 | + /** |
| 77 | + * @var HookDispatcherInterface |
| 78 | + */ |
| 79 | + private $hookDispatcher; |
| 80 | + |
75 | 81 | public function __construct(
|
76 | 82 | StockAvailableRepository $stockAvailableRepository,
|
77 | 83 | CombinationRepository $combinationRepository,
|
78 | 84 | MovementReasonRepository $movementReasonRepository,
|
79 | 85 | StockManager $stockManager,
|
80 |
| - ShopConfigurationInterface $configuration |
| 86 | + ShopConfigurationInterface $configuration, |
| 87 | + HookDispatcherInterface $hookDispatcher |
81 | 88 | ) {
|
82 | 89 | $this->stockAvailableRepository = $stockAvailableRepository;
|
83 | 90 | $this->combinationRepository = $combinationRepository;
|
84 | 91 | $this->stockManager = $stockManager;
|
85 | 92 | $this->configuration = $configuration;
|
86 | 93 | $this->movementReasonRepository = $movementReasonRepository;
|
| 94 | + $this->hookDispatcher = $hookDispatcher; |
87 | 95 | }
|
88 | 96 |
|
89 | 97 | /**
|
@@ -131,7 +139,6 @@ private function updateStockAvailable(StockAvailable $stockAvailable, Combinatio
|
131 | 139 |
|
132 | 140 | $fallbackShopId = $this->stockAvailableRepository->getFallbackShopId($stockAvailable);
|
133 | 141 | $this->stockAvailableRepository->update($stockAvailable, $fallbackShopId);
|
134 |
| - |
135 | 142 | // save movement only after stockAvailable has been updated
|
136 | 143 | if ($stockModification) {
|
137 | 144 | $this->saveMovement($stockAvailable, $stockModification, $previousQuantity, $fallbackShopId->getValue());
|
@@ -165,6 +172,15 @@ private function saveMovement(StockAvailable $stockAvailable, StockModification
|
165 | 172 | 'id_shop' => (int) $affectedShopId,
|
166 | 173 | ]
|
167 | 174 | );
|
| 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 | + ]); |
168 | 184 | }
|
169 | 185 |
|
170 | 186 | private function updateStockByShopConstraint(
|
|
0 commit comments