From 9f82053d2ac8653e7f9598ec021b0525aec5f13d Mon Sep 17 00:00:00 2001 From: "Paolo Cunti @codencode" Date: Sat, 7 Feb 2026 12:14:05 +0000 Subject: [PATCH 1/3] Add actionUpdateDefaultCombinationAfter hook --- .../actionUpdateDefaultCombinationAfter.md | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md diff --git a/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md b/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md new file mode 100644 index 0000000000..4736dfd808 --- /dev/null +++ b/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md @@ -0,0 +1,63 @@ +--- +Title: actionUpdateDefaultCombinationAfter +hidden: true +hookTitle: 'React after a product default combination is updated' +files: + - + url: 'https://github.com/PrestaShop/PrestaShop/blob/9.1.x/src/Adapter/Product/Combination/Update/DefaultCombinationUpdater.php' + file: src/Adapter/Product/Combination/Update/DefaultCombinationUpdater.php +locations: + - 'back office' +type: action +hookAliases: +array_return: false +check_exceptions: false +chain: false +origin: core +description: 'This hook is triggered after a product default combination is set (updated in database), allowing modules to react to the new default combination.' +--- + +{{% hookDescriptor %}} + +## Purpose + +The `actionUpdateDefaultCombinationAfter` hook allows modules to **react right after** the default combination of a product has been updated. + +It is dispatched when a merchant sets a new default combination in the product page (Back Office). + +## Parameters available + +The hook receives an array of parameters: + +| Parameter | Type | Description | +|---------------------|------|-------------| +| id_product | int | The product ID. | +| id_product_attribute| int | The ID of the new default combination (product attribute ID). | + +## Example usage + +```php +public function hookActionUpdateDefaultCombinationAfter(array $params): void +{ + $productId = (int) ($params['id_product'] ?? 0); + $productAttributeId = (int) ($params['id_product_attribute'] ?? 0); + + if ($productId <= 0 || $productAttributeId <= 0) { + return; + } + + // Your custom code +} +``` + +## Call of the Hook in the origin file + +```php +$this->hookDispatcher->dispatchWithParameters( + 'actionUpdateDefaultCombinationAfter', + [ + 'id_product' => (int) $newDefaultCombination->id_product, + 'id_product_attribute' => (int) $defaultCombinationId->getValue(), + ] +); +``` From fc064024552f4a26713d8c6b0ab0f460fecc7aee Mon Sep 17 00:00:00 2001 From: "Paolo Cunti @codencode" Date: Mon, 9 Feb 2026 08:23:17 +0000 Subject: [PATCH 2/3] Refactor: add id_shop to actionUpdateDefaultCombinationAfter hook parameter --- .../list-of-hooks/actionUpdateDefaultCombinationAfter.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md b/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md index 4736dfd808..63953afdeb 100644 --- a/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md +++ b/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md @@ -30,9 +30,10 @@ It is dispatched when a merchant sets a new default combination in the product p The hook receives an array of parameters: | Parameter | Type | Description | -|---------------------|------|-------------| -| id_product | int | The product ID. | -| id_product_attribute| int | The ID of the new default combination (product attribute ID). | +|--------------------- |------|-------------| +| id_product | int | The product ID. | +| id_product_attribute | int | The ID of the new default combination (product attribute ID). | +| id_shop | int | The shop ID (current shop context). | ## Example usage @@ -41,6 +42,7 @@ public function hookActionUpdateDefaultCombinationAfter(array $params): void { $productId = (int) ($params['id_product'] ?? 0); $productAttributeId = (int) ($params['id_product_attribute'] ?? 0); + $shopId = (int) ($params['id_shop'] ?? 0); if ($productId <= 0 || $productAttributeId <= 0) { return; @@ -58,6 +60,7 @@ $this->hookDispatcher->dispatchWithParameters( [ 'id_product' => (int) $newDefaultCombination->id_product, 'id_product_attribute' => (int) $defaultCombinationId->getValue(), + 'id_shop' => $shopConstraint->getShopId()->getValue(), ] ); ``` From 492a3f5b03025aa629cf70fa57e196eb63b33964 Mon Sep 17 00:00:00 2001 From: "Paolo Cunti @codencode" Date: Mon, 9 Feb 2026 08:23:17 +0000 Subject: [PATCH 3/3] Refactor: add id_shop to actionUpdateDefaultCombinationAfter hook parameter --- .../actionUpdateDefaultCombinationAfter.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md b/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md index 63953afdeb..615d341963 100644 --- a/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md +++ b/modules/concepts/hooks/list-of-hooks/actionUpdateDefaultCombinationAfter.md @@ -29,11 +29,11 @@ It is dispatched when a merchant sets a new default combination in the product p The hook receives an array of parameters: -| Parameter | Type | Description | -|--------------------- |------|-------------| -| id_product | int | The product ID. | -| id_product_attribute | int | The ID of the new default combination (product attribute ID). | -| id_shop | int | The shop ID (current shop context). | +| Parameter | Type | Description | +|--------------------- |-----------|-------------| +| id_product | int | The product ID. | +| id_product_attribute | int | The ID of the new default combination (product attribute ID). | +| id_shop | int\|null | The shop ID when in **single shop context**, otherwise `null`. | ## Example usage @@ -42,7 +42,9 @@ public function hookActionUpdateDefaultCombinationAfter(array $params): void { $productId = (int) ($params['id_product'] ?? 0); $productAttributeId = (int) ($params['id_product_attribute'] ?? 0); - $shopId = (int) ($params['id_shop'] ?? 0); + + // id_shop can be null when not in a single shop context + $shopId = $params['id_shop'] ?? null; if ($productId <= 0 || $productAttributeId <= 0) { return; @@ -60,7 +62,9 @@ $this->hookDispatcher->dispatchWithParameters( [ 'id_product' => (int) $newDefaultCombination->id_product, 'id_product_attribute' => (int) $defaultCombinationId->getValue(), - 'id_shop' => $shopConstraint->getShopId()->getValue(), + 'id_shop' => $shopConstraint->isSingleShopContext() + ? $shopConstraint->getShopId()->getValue() + : null, ] ); ```