Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error matching cart lines to order lines in MapDiscountBreakdown #1954

Closed
maurice-ellis opened this issue Sep 17, 2024 · 1 comment
Closed
Labels
bug Something isn't working unconfirmed

Comments

@maurice-ellis
Copy link
Contributor

  • Lunar version: 1.0.0-beta-2
  • Laravel Version:11.23.5
  • PHP Version: 8.3
  • Database Driver & Version:

Expected Behaviour:

To be able to create an order with no issue

Actual Behaviour:

When creating an order, I experience an "Undefined array key 2" error

Steps To Reproduce:

Add 2 of the same products without merging and create the order

It seems that the mapping to order lines can't handle when there is 2 of the same product variants in the cart

foreach ($order->lines as $orderLine) {
    $cartLine = $cart->lines->first(function ($cartLine) use ($orderLine) {
        return $cartLine->purchasable_type == $orderLine->purchasable_type &&
            $cartLine->purchasable_id == $orderLine->purchasable_id;
    });

    if ($cartLine) {
        $cartLinesMappedToOrderLines[$cartLine->id] = $orderLine;
    }
}

When it iterates through the 2nd line, the $cartline that is returned is the first one and then it overrides the same key in $cartLinesMappedToOrderLines .

This thing causes an issue when trying to reference the line later in the discountBreakdown and the key is undefined

'lines' => $discount->lines->map(function ($discountLine) use ($cartLinesMappedToOrderLines) {
    return (object) [
        'quantity' => $discountLine->quantity,
        'line' => $cartLinesMappedToOrderLines[$discountLine->line->id],
    ];
}),
@maurice-ellis maurice-ellis added bug Something isn't working unconfirmed labels Sep 17, 2024
@maurice-ellis
Copy link
Contributor Author

Fixed with #1956

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed
Projects
None yet
Development

No branches or pull requests

1 participant