Jump to content

Added To Basket message/notifcation


disco_ii_disco

Recommended Posts

Hi all,

 

Just upgrading from Cubecart 4 to Cubecart 5.

 

On my old store I have an added to basket message which displays when "added=1" is present in the url e.g. product/jockey-wheel-clamp-34mm/4599?added=1

 

My old code was:

if (isset($_GET['added'])) {
 $view_prod->assign("TXT_ADDED_TO_BASKET", "<div class='txtAdded'><h3>Thank you for adding the ".validHTML($prodArray[0]['name'])." to your <a href='/index.php?_g=co&_a=cart'>basket</a>.</h3></div>");
}

My new code is:

{php}
  	
$GLOBALS['smarty']->assign('ADDED', "Product added to basket");

{/php}

Which trigger should I use to action the new version of this code?

 

I have tried class.cart.add.save, class.cart.add.update and others to no avail so far.

 

Any help would be greatly appreciated.

 

Chris,

Link to comment
Share on other sites

Allow me to ask: where are you displaying "Product added to basket"? Is this a custom skin?

 

In Kurouto, there is a javascript-powered "basket shake". Some have complained that if the shopping basket sidebox has scrolled off the page, this effect is not seen when the customer clicks the "Add to Basket" button.

 

It would be interesting to try to use this "basket shake" to instead show a javascript alert box of some sort.

 

CC5 has two approaches when an item is added into the shopping basket: when javascript has not crashed, and when javascript has crashed or is disabled by the browser.

 

With javascript: a POST is made via an ajax call. CubeCart detects this and sends back only the HTML of the shopping basket template, box.basket.php, to the calling ajax function. The ajax function updates only the sidebox. You could add a hidden <div id="product_added">{true|false}</div> to this template, and then add some code to the ajax call, such as looking at $('product_added').txt(), and if "true", then show some phrase somewhere on the HTML document.

 

Without javascript: the form is POSTed normally. CubeCart will understand this is a normal page request and will render an entirely new, complete web page.

 

Assuming CubeCart permitted the item to be added to the shopping basket at Cart->add(), the next step is CubeCart->loadPage(). If there is an ajaxadd, we get the basket sidebox and echo that out. Then CubeCart is finished. If no ajaxadd, the current page is re-delivered.

 

Probably the easiest hook to use is 'controller_index'. This called at the end of processing, but before -- if nothing goes wrong! -- rendering the templates.

Link to comment
Share on other sites

Cheers Bsmither for the clarification.

 

The skin is a custom one I am building for my own shop. In my old store, the add to basket message appeared at the top of the central column (when a product is added to basket on the product or category pages).

 

In my new store - built on Bootstrap - I will either have a pop-up modal box (like ModsIndex has done) or a dismissable alert across the top of the page.

 

Had a quick play around tonight and got it to work instantly!

  1. I commented out the redirect parts of the add() function in cart.class.php - approx. lines 421, 423, 428 and 431.
  2. I gave the buy button on the content.product.php template the name "buyproduct"
  3. I created this small code snippet (with class.cubecart.display_product as the trigger): 
{php}

if (isset($_POST['buyproduct'])){
  	
$GLOBALS['smarty']->assign('ADDED', "Product added to basket");

}
{/php}

4. Then in product template:

{if isset($ADDED)}
    <p>{$ADDED}</p>
  {/if}
//will improve on this once working!

Do you see any issues with removing the re-directs? Everything appears to work from my end!

 

Cheers,

 

Chris

Link to comment
Share on other sites

You may have destroyed the CubeCart feature of having the customer be taken to the View Basket page or the current page when the product was added to the basket -- an administrative store setting.

 

CC5 also has a Notice/Warning banner that shows when necessary (I'm sure you have seen it).

$GLOBALS['gui']->setError('phrase');

$GLOBALS['gui']->setNotify('phrase');

Link to comment
Share on other sites

Thank you. I just added this snippet (with the trigger: class.cart.add.preredirect):

{php}

$message ="Product added to your basket.";

$GLOBALS['gui']->setNotify($message);

{/php}

All works and means no modifcation of the Cubecart code either, which is good.

 

Another job ticked off my list. Lots to go though!

Link to comment
Share on other sites

  • 2 weeks later...

Sorry, still on this subject, does anyone know if (or how) you can include html in the setNotify message?

 

Everytime I include html in the code snippet it get's stripped back out.

 

e.g. (this is want I would like):

{php}

if (isset($_POST['buyproduct'])){
  	
$GLOBALS['smarty']->assign('ADDED', "Product added to <a href='basket'>basket <span class='glyphicon glyphicon-cart'></span></a>");

}
{/php}
Link to comment
Share on other sites

This has been mentioned to Devellion to get fixed, but nothing has come of it as yet.

 

There are two approaches: a hard-coded fix, and using a snippet to affect a fix. Let's hard code the fix.

 

In the file /classes/sanitize.class.php, near the top, there is an array $exempt. Add a comma and 'php_code' to the end of the list.

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...