Nwazet Commerce - Checkout Return

Topics: Customizing Orchard
Aug 9, 2013 at 10:46 PM
Hi Bertrand,

I'm sorry if there's a better place to ask questions about your module...BitBucket only has an "issues" area and I only have a question, I didn't want to create an issue on your project site for it.

I've got the module working with 1.7 and I installed the PayPal extension module and modified it to work with 1.7 as well since Google Checkout is gone. The PayPal configuration is looking for a return URL once the payment has been completed on the PayPal site.

I couldn't seem to find in the Routes or Controllers what the destination would be after a successful payment has been received. Is there a "Checkout Complete" route that I can send the user to after payment that is part of the module, or should I just create a page in Orchard that reflects the transaction was complete and direct them there?

Thanks for the info...love the simplicity of the module btw.
Coordinator
Aug 9, 2013 at 11:44 PM
That's because that type of workflow is not yet supported. If the PayPal module/extension is not providing it, Nwazet.Commerce isn't either.
Aug 12, 2013 at 9:26 PM
Thanks Bertrand...I figured out part of it was the PayPal module code needing a bit of "correcting", so I was able to add a "Cancel Url" and a "Return Url".

I set the Cancel Url to return the user to the cart and I set the Return Url to return the user to a Confirmation page that I created (it's a Page item).

I was wondering if you knew of an easy way to clear the cart contents when I return the user to the Confirmation page. Is there an easy way to clear the session storage for the cart via JavaScript?

Thanks!
Coordinator
Aug 12, 2013 at 9:35 PM
localStorage.removeItem("nwazet.cart")
Aug 12, 2013 at 9:44 PM
Awesome...thanks. It doesn't seem to work on localhost, so I'll wait for when I push it up to the live site to test. Chrome doesn't show any Local Storage items whatsoever on the cart page using the local web server (IIS Express). There's no way I would have found the name without your help. Thanks again!
Coordinator
Aug 12, 2013 at 9:50 PM
That's weird. I can see them just fine.
Aug 12, 2013 at 10:59 PM
I don't see it on the live site either in Chrome and the localStorage.removeItem doesn't work.

I'm not horribly familiar with using localStorage. Might you know of a troubleshooting method to get more information? The cart works great...items add to the cart and I can click around on the site and come back and the item is still in the cart.

Here's the URL of the product if you're interested in seeing what it's doing: http://allaboutharley.com/gear/survivor-wristband

Thanks again for the help
Coordinator
Aug 12, 2013 at 11:33 PM
I think you need to remove it from both local storage and from the session. The session item to clear on the server side is ShoppingCart. But you can do all that cleanly from the client-side by setting all quantities to zero $("input.quantity").val(0) and then submitting the form.
Aug 13, 2013 at 11:30 PM
Ahhh...I see. Took me a minute, but I see that you have a getcart route that returns the cart items in a JSON format. I should be able to put together a javascript that uses the results to change the quantities to 0 and submits the form.

Awesome...thanks!
Aug 14, 2013 at 2:22 AM
Edited Aug 14, 2013 at 2:25 AM
I had to create a View to do it since I I have to pass the anti-forgery token with the post, but a little simple JavaScript took care of it. I was trying to do it in a Page Content Item for simplicity, but this way works better. I may even try to extend it a bit at some point and add order tracking from within the Admin.
@using (Script.Foot()) {
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: 'GET',
                url: '/getcart',
                cache: false,
                datatype: 'json',
                success: function (result) {
                    result = result.items;
                    if (result.length != 0) {
                        $.each(result, function (index) {
                            $('#cartClear').append('<input name="items[' + index + '].ProductId" type="hidden" value="' + result[index].id + '">');
                            $('#cartClear').append('<input name="items[' + index + '].Quantity" type="text" class="quantity" value="0">');
                        });

                        localStorage.removeItem('nwazet.cart')

                        $('#cartClear').submit();
                    }
                },
                error: function (req, status, error) {
                }
            });
        });
    </script>
}

<p>Thank you for your order. Please allow us 24 hours to process orders for in-stock items.</p>

<div style="display: none;">
    @using (Html.BeginFormAntiForgeryPost(Url.Action("Update", "ShoppingCart", new { area = "Nwazet.Commerce" }), FormMethod.Post, new { id = "cartClear" })) {
    }
</div>
Thanks for the help Bertrand!