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

CheckoutSuccessPage retrieves wrong cart #92

Open
russdot opened this issue Sep 25, 2024 · 4 comments
Open

CheckoutSuccessPage retrieves wrong cart #92

russdot opened this issue Sep 25, 2024 · 4 comments

Comments

@russdot
Copy link

russdot commented Sep 25, 2024

I noticed that when submitting an order, there is no confirmation and it redirects to the main storefront (/).

After some debugging and tracing, I believe I've tracked down what's happening but I'm not sure why.

  1. CheckoutPage->checkout() redirects on successful offline payment.
  2. However, when CheckoutSuccessPage->mount() runs, the CartSession::current() retrieves an apparently new session with an ID=N+1. For example, when the payment succeeds the cart ID might be 8, but in CheckoutSuccessPage the ID will be 9.
  3. The results in the check for completedOrder to fail, and redirect to the main storefront without displaying the checkout-success.view
@russdot
Copy link
Author

russdot commented Sep 25, 2024

Continuing to investigate this for my own learning and to help out...

I've been stepping through the code to determine where the session changes and I think I've found it.

In my debug console I was running Lunar\Facades\CartSession::current()->id to check the output. I noticed it increments by +1 after updating the order within OfflinePayment->authorize()

To illustrate using excerpt from OfflinePayment, where I've added comments to indicate breakpoint locations and values for the cart ID.

public function authorize(): ?PaymentAuthorize
    {
        if (! $this->order) {
            if (! $this->order = $this->cart->draftOrder()->first()) {
                $this->order = $this->cart->createOrder();
            }
        }
        $orderMeta = array_merge(
            (array) $this->order->meta,
            $this->data['meta'] ?? []
        );

        $status = $this->data['authorized'] ?? null;

//
// (after executing line above) Lunar\Facades\CartSession::current()->id = N
//

        $this->order->update([
            'status' => $status ?? ($this->config['authorized'] ?? null),
            'meta' => $orderMeta,
            'placed_at' => now(),
        ]);

//
// (after executing line above)  Lunar\Facades\CartSession::current()->id = N + 1
// The CartSession ID increments by 1 after updating the order
//
        $response = new PaymentAuthorize(
            success: true,
            orderId: $this->order->id,
            paymentType: 'offline',
        );

        PaymentAttemptEvent::dispatch($response);

        return $response;
    }

Not sure yet why this is occurring - but wanted to capture my findings. Perhaps this is a bug with Lunar core?

@alecritson
Copy link
Contributor

I think the issue here is the Starter kit is quite outdated at this point, we're working on new starter kits for v1 and to bring this back up to speed with the latest beta.

There was a change to the way carts are retrieved from the session after a cart completed an order, so because you're trying to fetch the cart afterwards, it has a completed order and therefore returns a new cart. So, in the case of the offline payment, you would need to pass the cart id to the success page to fetch it that way instead of going through the session manager.

@alecritson
Copy link
Contributor

You can see this on this PR which is awaiting review by @glennjacobs #89

@eugenefvdm
Copy link

I think the issue here is the Starter kit is quite outdated at this point

If I may add my opinion, the Livewire Starter kit works really well except for a few minor issues.
The one issue I have is the clever way the shipping and billing details pages have been merged into one.
It makes it a bit hard to customize. For example, often a client might want to administer multiple shipping address, and sometimes a client wants the shipping address pre-populated. I feel that combining the login shipping and billing into one broke the single responsibility principle and I'm finding customization hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants