Jump to content

Removing item from cart right before order placement fails


Kholja
 Share

Recommended Posts

I found a problem which might be a dealbreaker for a client. Let's say a client has two products in his cart. Right before clicking 'place order' (after typing in client date) he decides to remove one of the products. So he will navigate back to edit cart page (cart-edit.php template) and remove the product from the cart. The product is now removed from the cart, but padloper does not remove the product from the order (which is already created). The customer will find the product in the order-overview and has no chance to remove it from there.

How could this be handled? Shouldn't Padloper take care of keeping cart and order in sync until order placement is completely done?

Link to comment
Share on other sites

Hi @Kholja,

Thanks for reporting. This has now been fixed in today's update. The issue was we were only checking for quantity=0 BUT NOT 'remove item' request as well.

For information, this is how Padloper currently handles items removed/updated/added to the cart. Please note that below ONLY APPLIES to cart and order processing executed via an order checkout form (i.e., not if manually processing cart and order using the API).

  1. If at least one item is added to the cart AND the customer has started the checkout process by 'proceeding to confirmation', an order page is immediately created. The line item(s) is added to the order page. This allows for tracking abandoned carts.
  2. If an item is updated (increased quantity or decreased quantity BUT NOT ZERO quantity) in the cart: In the line item, there is nothing to do at this point.
  3. If an item is either removed OR quantity is ZERO, the item is removed from the cart but still we don't delete the corresponding line item in the order page. Instead, we hide it (it is a pending item). This caters for situations whereby the customer might decide to re-add the product to the cart after removing it completely. In such cases, we only need to unhide the line item in the order page instead of creating another page.
  4. When the order is completed, any hidden line item pages (pending items -> meaning they were not purchased) are deleted.

I am mentioning the above, especially #3 since if you are manually getting and displaying (i.e., using $pages->find()) order overview before purchase is complete, you should not use include=all or include=hidden as that would display pending items to the customer. Use check_access=0 instead, or better, $padloper->find();

Edited by kongondo
Added missing information
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Me again 🙂

The same happens when I try to remove the product programmatically:

$cartRowID = $padloper->cart->checkIfProductInCart($fontID);
$padloper->cart->removeProduct($cartRowID);

This removes the product from the cart, but not from the order. 

I have also tried setting the quantity to zero:

$padloper->cart->updateProduct($cartRowID, 0);

But that gives the same result. Do you maybe have a hint?

Link to comment
Share on other sites

17 hours ago, Jan Fromm said:

The same happens when I try to remove the product programmatically:

Hi @Jan Fromm

This is because you are manually processing the cart and order. I have updated my post above to be clear that those steps refer to instances when cart and order are being processed via a checkout form.

As stated in my post above, Padloper tries not to create order line items pages unnecessarily. When checkout is complete (if executed via checkout form), Padloper will clean up, removing any line items pages whose corresponding cart items were removed from the cart. In your case, you would have to do this manually since you are not going through the usual checkout process. I have now added a 2nd boolean parameter to PadloperCart::removeProduct that will tell it to also delete the order line item page associated with the cart item that is being removed. Hence, your solution would be:


<?php

namespace ProcessWire;

$padloper->cart->removeProduct($cartRowID,true);

I have updated the download. Please grab it from there as usual.

Thanks.

Edited by kongondo
Link to comment
Share on other sites

Hi @kongondo,

Thanks again for your quick help and customization of the module. Unfortunately I have to ask another stupid question, which probably has nothing to do with Padloper, but with my setup.

I installed your update and added the new parameter. Now the product is deleted from the cart and the order, but only when Tracy Debugger is active. When I test without Tracy Debugger, only the cart is updated, but not the order.

I have refreshed the module several times, and also cleared the cache with Cache Admin. Still, the updated code doesn’t seem to be applied in every context.

Sorry to bother you again with such small stuff.

Link to comment
Share on other sites

Hi @Jan Fromm,

Thanks for reporting this.

4 hours ago, Jan Fromm said:

Unfortunately I have to ask another stupid question, which probably has nothing to do with Padloper, but with my setup.

I installed your update and added the new parameter. Now the product is deleted from the cart and the order, but only when Tracy Debugger is active. When I test without Tracy Debugger, only the cart is updated, but not the order.

Nope. Entirely my silly mistake. Nothing to do with your setup or Tracy 😁. Forgot a 'check_access=0' in the selector to grab the line item to delete (since they are in admin). So, the reason it worked with 'Tracy enabled' is, I guess, you were logged in as a Superuser :-). Anyway, sorted for now. 

Please grab the updated files again. 

4 hours ago, Jan Fromm said:

Sorry to bother you again with such small stuff.

Not at all 🙂.

Thanks.

  • Like 1
Link to comment
Share on other sites

Thanks @kongondo for clarification and the swift update.

16 hours ago, kongondo said:

Nope. Entirely my silly mistake. Nothing to do with your setup or Tracy

I’ll print this out and put it on my wall 😉

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...