Skip to content

Commit

Permalink
[7.x] Add lineItemPriceHook hook (#1157)
Browse files Browse the repository at this point in the history
* Created price hook from a lineItem perspective

* Let's not document this for now.

* Doh! I removed the wrong bit.

* Add back the note.

* Code Style

---------

Co-authored-by: Jan Willem Rigters <jrigters@steets.nl>
Co-authored-by: Duncan McClean <duncan@doublethree.digital>
  • Loading branch information
3 people authored Sep 18, 2024
1 parent 02407fa commit 5f71d13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Orders/Calculator/LineItemCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function handle(Order $order, Closure $next)
if ($product->purchasableType() === ProductType::Product) {
if (SimpleCommerce::$productPriceHook) {
$productPrice = (SimpleCommerce::$productPriceHook)($order, $product);
} elseif (SimpleCommerce::$lineItemPriceHook) {
$productPrice = (SimpleCommerce::$lineItemPriceHook)($lineItem);
} else {
$productPrice = $product->price();
}
Expand Down
9 changes: 9 additions & 0 deletions src/SimpleCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class SimpleCommerce

public static $productVariantPriceHook;

public static $lineItemPriceHook;

public static function version(): string
{
if (app()->environment('testing')) {
Expand Down Expand Up @@ -200,4 +202,11 @@ public static function productVariantPriceHook(Closure $callback): self

return new static;
}

public static function lineItemPriceHook(Closure $callback): self
{
static::$lineItemPriceHook = $callback;

return new static;
}
}

0 comments on commit 5f71d13

Please sign in to comment.