From 31b9e836005ee1145c3d1436faf704ac3962b9cf Mon Sep 17 00:00:00 2001 From: gapon2401 Date: Mon, 7 Dec 2020 11:23:52 +0300 Subject: [PATCH] Add hook cart_items_after Hook will help to change order items. I have plugin (Gift certificates), which changes prices of order items. One product can have different prices, depends on the amount of the certificate. For now it's imposible to edit definite item in the order. I was trying to change item price with the help of `frontend_products` hook, but I found, that skus in some cases don't contain item ids. What am I trying to achieve? I want to: - edit item price depends on certain item ID, - calculate relevant order discount Method `shopCart::discount` use function `shopCartItemsModel::getByCode` to get order items. If you add hook `cart_items_after`, I will be able to change prices of the items. What issues have users? In some places of the website users see wrong discounts and item prices. --- lib/model/shopCartItems.model.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/model/shopCartItems.model.php b/lib/model/shopCartItems.model.php index cb861cf41..0d76531f6 100644 --- a/lib/model/shopCartItems.model.php +++ b/lib/model/shopCartItems.model.php @@ -438,6 +438,10 @@ public function getByCode($code, $full_info = false, $hierarchy = true) } $items = $result; } + + wa('shop')->event('cart_items_after', ref([ + 'items' => &$items + ])); return $items; }