Jump to content

How to change the redirection after adding a product to the cart


Recommended Posts

Hi all,
I've a problem with the redirection after the "Add to chart" action.
I set in "Preferences-->Products" the parameter "Redirection after adding product to cart" equal to "Previous Page".

The problem is that I need a redirection to another page (the product list) that is not the previous page.
In fact when in the product list I click  on the button "order now" a pop-up is opened  (the product view) in which I choose the quantity of the product to order.
When I click on "Add to chart" the previous page is correctly the "product view" and not the product list.

So, how can I redirect to the "product list" and not to the "product view"?

Thank you

Claudio

post-330540-0-15782900-1471945199_thumb.jpg

Edited by ilclaudio (see edit history)
Link to comment
Share on other sites

Thank you electriz,

I've seen that file and I've solved in this way:

 

1) I've added the hidden field "back_to_prodlist" in the product view:

                                                <p class="hidden">
                                                        <input type="hidden" name="token" value="{$static_token}" />
                                                        <input type="hidden" name="id_product" value="{$product->id|intval}" id="product_page_product_id" />
                                                        <input type="hidden" name="add" value="1" />
                                                        <input type="hidden" name="id_product_attribute" id="idCombination" value="" />
                                                        <input type="hidden" name="back_to_prodlist" id="back_to_prodlist" value="{$smarty.server.HTTP_REFERER}" />
                                                </p>

2) I've modified the cart controller so that if the POST value "back_to_prodlist" is defined then the right redirect is done:

                // Redirect to previous page
                if (isset($_SERVER['HTTP_REFERER'])) {

                    if(isset($_POST['back_to_prodlist'])){
                        $url = preg_replace('/(\?)+content_only=1/', '', $_POST['back_to_prodlist']);
                        Tools::redirect($url);
                    } else if (isset($regs[3]) && !Configuration::get('PS_CART_REDIRECT')) {
                        $url = preg_replace('/(\?)+content_only=1/', '', $_SERVER['HTTP_REFERER']);
                        Tools::redirect($url);
                    }
                }
 

I know, as you say, I should override the method and not modify the core of Prestashop.

However this fix works.

 

Claudio

 

 

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
×
×
  • Create New...