disco_ii_disco Posted November 12, 2014 Share Posted November 12, 2014 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, Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 12, 2014 Share Posted November 12, 2014 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. Quote Link to comment Share on other sites More sharing options...
Mods Index Posted November 13, 2014 Share Posted November 13, 2014 We have also developed a CC5 add to basket notification mod that shows a pop up window every time customer add an item to shopping basket. You can check it out on www.revolutionrc.com.au If you would like to use this mod please get in touch. Quote Link to comment Share on other sites More sharing options...
disco_ii_disco Posted November 14, 2014 Author Share Posted November 14, 2014 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! I commented out the redirect parts of the add() function in cart.class.php - approx. lines 421, 423, 428 and 431. I gave the buy button on the content.product.php template the name "buyproduct" 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 Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 14, 2014 Share Posted November 14, 2014 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'); Quote Link to comment Share on other sites More sharing options...
disco_ii_disco Posted November 15, 2014 Author Share Posted November 15, 2014 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! Quote Link to comment Share on other sites More sharing options...
disco_ii_disco Posted November 23, 2014 Author Share Posted November 23, 2014 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} Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 23, 2014 Share Posted November 23, 2014 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. Quote Link to comment Share on other sites More sharing options...
disco_ii_disco Posted November 25, 2014 Author Share Posted November 25, 2014 Many thanks. Wouldn't have figured that one out myself! It still won't allow the <span> part but the link was the main thing. Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 25, 2014 Share Posted November 25, 2014 I see no reason why the character sequence <span would still go missing. Having made the addition to the exempt fields list should now leave the entirety of that form element submission untouched. Quote Link to comment Share on other sites More sharing options...
disco_ii_disco Posted November 26, 2014 Author Share Posted November 26, 2014 The <span> has saved in the code snippet but doesn't get printed out in the gui message (viewed the page source and it is not there). I am not going to worry too much about that though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.