Skip to content

Commit

Permalink
Fix line fetching in order creation
Browse files Browse the repository at this point in the history
  • Loading branch information
maurice-ellis committed Sep 17, 2024
1 parent c4381dc commit 3cc6722
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/core/src/Pipelines/Order/Creation/CreateOrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Lunar\Models\Order;
use Lunar\Models\OrderLine;
use Lunar\Utils\Arr;

class CreateOrderLines
{
Expand All @@ -23,8 +24,13 @@ public function handle(Order $order, Closure $next)

foreach ($cart->lines as $cartLine) {
$orderLine = $order->lines->first(function ($line) use ($cartLine) {
return $line->purchasable_id == $cartLine->purchasable_id &&
$line->purchasable_type == $cartLine->purchasable_type;
$diff = Arr::diff($line->meta, $cartLine->meta);

return empty($diff->new) &&
empty($diff->edited) &&
empty($diff->removed) &&
$line->purchasable_type == $cartLine->purchasable_type &&
$line->purchasable_id == $cartLine->purchasable_id;
}) ?: new OrderLine;

$orderLine->fill([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Lunar\Models\Order;
use Lunar\Utils\Arr;

class MapDiscountBreakdown
{
Expand All @@ -18,7 +19,12 @@ public function handle(Order $order, Closure $next)

foreach ($order->lines as $orderLine) {
$cartLine = $cart->lines->first(function ($cartLine) use ($orderLine) {
return $cartLine->purchasable_type == $orderLine->purchasable_type &&
$diff = Arr::diff($cartLine->meta, $orderLine->meta);

return empty($diff->new) &&
empty($diff->edited) &&
empty($diff->removed) &&
$cartLine->purchasable_type == $orderLine->purchasable_type &&
$cartLine->purchasable_id == $orderLine->purchasable_id;
});

Expand Down

0 comments on commit 3cc6722

Please sign in to comment.