jeffharrell / minicart

The minicart is a great way to improve your PayPal shopping cart integration.
MIT License
500 stars 209 forks source link

onCheckout event order #239

Open randykato opened 10 years ago

randykato commented 10 years ago

I've updated to v3.0.5 as it offers some additional functionality I needed, and I've got it almost all working.

I'm having an issue with cart.on('checkout'). I want to offer free shipping with a minimum order amount. I figured I should do this onCheckout rather than onAdd since quantities can be changed in the cart after the add event. I've got the checkout event function doing everything it needs to - checking subtotal and delivery zones and then changing the shipping charge to 0 if all criteria are met. I can see in the console when I view the items array that the shipping cost has indeed been changed to 0. BUT, when I'm redirected to PayPal, the shipping charge still shows up. It seems that checkout is compiling data before my function can change it, so it winds up sending the pre-altered data. If I go back, re-open the cart and checkout (without making any changes) it works with shipping = 0.

Am I understanding this properly? Or is something else going on? I would love to know if there's a way to refresh the cart data right before sending to PayPal...or if there's some other thing I'm not doing properly.

Cheers! Randy

jeffharrell commented 10 years ago

This is valid issue due to the improper way I'm currently capturing the form submission, i.e. submit button click rather than form submit.

I can publish a fix probably this week, but if you want to take a look at fixing it yourself off the top of my head you'll want to remove the submit click event here:

https://github.com/jeffharrell/minicart/blob/master/src/viewevents.js#L17

and instead unbind and rebind a submit event to this.el.querySelector('form') at:

https://github.com/jeffharrell/minicart/blob/master/src/view.js#L45

randykato commented 10 years ago

Thanks, Jeff. I'll leave that to you as it's a bit above my level.

randykato commented 10 years ago

Hoping this can be resolved.

DevGW commented 10 years ago

any update on this? I'm having a very similar problem see issue #254

jakeday commented 9 years ago

I don't think the author ever posted a fix for this, but this is what he meant. I can do a pull request if needed. This fixes the issue.

image

jakeday commented 9 years ago

Submitted the pull request.

jeffharrell commented 9 years ago

Thanks to the PR from @jakeday this should now be fixed as part of 3.0.6.

randykato commented 9 years ago

I had kind of left this behind, but now I see it's been addressed. I've updated to v3.0.6, but I'm still getting the same behavior, so I'm thinking it must be my code:

paypal.minicart.cart.on('checkout', function (evt) {
        if(paypal.minicart.cart.subtotal() >= 55) {
        alert("you get free shipping");
            paypal.minicart.cart._items[0].set('shipping',0);
        }
    }
});

I see that the shipping (which I've added only to the first item) is reset to 0 in the minicart, but it still shows up in PayPal. If I go back to the site and re-open the cart and checkout again, then the $0 shipping charge gets sent properly to PayPal.

Do I need to somehow manually force a data refresh before submitting to PayPal?

Thanks for any input.

Cheers! Randy