34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Cart\Pipelines;
|
|
|
|
use Closure;
|
|
use Lunar\DataTypes\Price;
|
|
use Lunar\Models\Contracts\CartLine as CartLineContract;
|
|
|
|
/**
|
|
* Runs in config('lunar.cart.pipelines.cart_lines'), after GetUnitPrice —
|
|
* zeroes out unitPrice/unitPriceInclTax for any line flagged
|
|
* meta.saved_for_later, BEFORE Lunar's own CalculateLines pipeline step reads
|
|
* unitPrice to compute subTotal/total. A saved-for-later item is deliberately
|
|
* parked, not pending purchase, so it shouldn't inflate Cart::total — and
|
|
* since CalculateLines sums every CartLine unconditionally with no meta-based
|
|
* exclusion of its own, zeroing the price here (rather than patching subTotal
|
|
* after the fact) is what makes every downstream total naturally correct
|
|
* without a second pass.
|
|
*/
|
|
class ZeroSavedForLaterPrice
|
|
{
|
|
public function handle(CartLineContract $cartLine, Closure $next): mixed
|
|
{
|
|
if ($cartLine->meta['saved_for_later'] ?? false) {
|
|
$currency = $cartLine->cart->currency;
|
|
|
|
$cartLine->unitPrice = new Price(0, $currency, 1);
|
|
$cartLine->unitPriceInclTax = new Price(0, $currency, 1);
|
|
}
|
|
|
|
return $next($cartLine);
|
|
}
|
|
}
|