Jump to content

How to update Cart-block using AJAX


Recommended Posts

Hi! This is my first post here and before I go into my issue, I just want to say that I've been on the search for a shopping cart solution for over a year now. I've been using Zen Cart until I finally came across PrestaShop. Great product!

Now, to my question (hope someone can help me with this)... Basically, what I'm trying to do is add functionality for a user to be able to use their order history to reorder the same products again.

So, on the order detail page I have added following:

{$product.product_name|escape:'htmlall':'UTF-8'}



This is inside the ordered products loop and is basically a link to cart.php, and passes the product ID, quantity that was previsouly ordered and token.

This works fine and the browser is redirected to order.php and the cart gets updated successfully.

What I want to be able to do is update the cart without redirecting the browser - so that the order detail page stays open and just the Cart-block module box is updated. My problem is that I cannot figure out which AJAX function to call to do this.

A workaround would be to make my own javascript function which sends the parameters to my JavaScript, which then sends them via AJAX to cart.php. But if I do this I still need to figure out a way how to update the cart on the screen afterwards.

I hope this makes sense. Any help would be greatly appreciated.

Link to comment
Share on other sites

Ok, I finally got it (after hours and hours of going through the code to figure this out)!!

I kept getting thrown off by a JS error - "Error: elementToTransfert is null".

This is the code I needed to get this working:

{$product.product_name|escape:'htmlall':'UTF-8'}



This code basically allows your customers to reorder from their Order History --> Order Detail page.

I'm guessing there's still some tweaking to be done to get the product attributes right, but if anyone is interested in this and would like me to elaborate on anything just let me know.

Thanks for looking...

Link to comment
Share on other sites

  • 3 months later...
  • 2 months later...
  • 10 months later...

Sure! What you do is open up the template order-detail.tpl inside your theme directory - e.g.

themes/prestashop/order-detail.tpl

Then, you replace the following code with the code below:

{else}
   {$product.product_name|escape:'htmlall':'UTF-8'}
{/if}



{else}
{$product.product_name|escape:'htmlall':'UTF-8'}

Reorder
{/if}



In my version, this snippet starts in line 179.

That's about all you need to do. It doesn't allow you to reorder your entire order, but you can reorder line by line with the same quantity. So, for example, if you had one line with 12x Pair of Red Socks, then clicking the reorder button on that line would put 12x Pair Red Socks into your cart. Hope that makes sense.

Link to comment
Share on other sites

  • 6 months later...
  • 5 months later...

php and the cart gets updated successfully. My problem is that I cannot figure out which AJAX function to call to do this. But if I do this I still need to figure out a way how to update the cart on the screen afterwards. Any help would be greatly appreciated. It would be nice if you can shed some light on what you have done. Could anyone find a solution I would be very grateful.The web-based printing marketplace is, it should be mentioned, also a casualty of economic decline and has undergone substantial economic problems. Then again, there are ways in which internet printing producers have dealt with the recession with no need for becoming lax on product standards. With clients hoping to reduce expense, printing companies need to find progressive ways to attract end users to them. In periods of market recession, it is wise to lessen on printplace credit codes spending, with the exception of marketing costs. Enhancing marketing expenses in these monetarily sluggish conditions helps to retain and persuade future customers, and online printing is no exemption to this guideline. Producers must consider efficient procedures for spending their capital and maximizing the return on their ventures. Also, it may be observed that , taking a long term view, economic reports from previous recessions have showed that strong marketing expenditure during the phase of poorest economic growth consistently improves overall performance in the following three months by approximately three quarters.

Link to comment
Share on other sites

×
×
  • Create New...