Jump to content

Changing Functionality of 'Add to Basket' Button


Recommended Posts

Hello,

This may be above my pay grade, but I'm trying to figure out how to change the Add to Basket button a bit.  Instead of simply popping up the box.basket.content window at the top of the screen and leaving the user on the same page, I would like it to add the item to basket and then return the user to the category or home page that they came from.  Doing this will update the static box.basket.content that I put where featured products used to be, sort of a forced refresh.

If this is possible, I would then remove the shopping cart from the top of the nav bar, so the only place the basket content would appear is the one spot.

Is this overly complicated or possible?

Thanks,

John

Link to comment
Share on other sites

Create a code snippet using the hook `class.cart.add.preredirect` and add the following code:

<?php
$category_id = $GLOBALS['db']->select('CubeCart_category_index','cat_id',array('product_id'=>$product_id,'primary'=>1));
if ($category_id) {
    $redirect_url = $GLOBALS['seo']->buildURL('cat', $category_id[0]);
    if ($redirect_url) {
       httpredir($redirect_url); 
    }
}
?>

This will cause the page to redirect to the main category of the product any time a user adds it to the basket and avoids entirely the JS-powered auto-display of the side basket (though this basket can still be displayed if the user specifically clicks on it).

Do note, however, that the script above does not elegantly handle the case where the user adds a product from any page other than the product page, for example if they added a product to their basket from the home page. Should be enough to get you started, though.

Link to comment
Share on other sites

  • 2 weeks later...
On 6/5/2017 at 2:31 PM, bsandall said:

Create a code snippet using the hook `class.cart.add.preredirect` and add the following code:


<?php
$category_id = $GLOBALS['db']->select('CubeCart_category_index','cat_id',array('product_id'=>$product_id,'primary'=>1));
if ($category_id) {
    $redirect_url = $GLOBALS['seo']->buildURL('cat', $category_id[0]);
    if ($redirect_url) {
       httpredir($redirect_url); 
    }
}
?>

This will cause the page to redirect to the main category of the product any time a user adds it to the basket and avoids entirely the JS-powered auto-display of the side basket (though this basket can still be displayed if the user specifically clicks on it).

Do note, however, that the script above does not elegantly handle the case where the user adds a product from any page other than the product page, for example if they added a product to their basket from the home page. Should be enough to get you started, though.

Thanks so much!  I will give this a try today.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...