Notifying successful add-to-cart (Calguys Commerce)

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Dramatic

Notifying successful add-to-cart (Calguys Commerce)

Post by Dramatic »

I have tried looking in the module API, but it's pretty much Greek to me.
Is there a system such that a message set by a module will be displayed at the top of the next page that is loaded?

I.e. Customer clicks "Add to Cart" on a product detail page, and gets taken back to the main products page and sees a highlighted message that says "Foo was added to your cart".

Yes, there is a my-cart box on the page, but the client gets the impression that if there isn't a message displayed, the adding has failed. They don't want the add-to cart page to go to the full cart view, as they want the customer to select more products without having to "contunue shopping".

Also, where is the best place to set such a message?
Maintainability suggests somewhere in-database-and-not-overwritten-by upgrades (i.e. a template), but logic suggests it needs to be based on the success of the add to cart action?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Notifying successful add-to-cart (Calguys Commerce)

Post by Dr.CSS »

You can use the My Cart call and have it show: 0 items in your cart and if item added it will show how many, this can be a small thing in top of site or wherever you want it, I use this method a lot the time...
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Notifying successful add-to-cart (Calguys Commerce)

Post by velden »

I've once made the cart submission 'ajaxified'. Then you can show whatever you like before/after/during submission to the cart.

Unfortunatelly the Cart part is not public (only registered dealers) can use it.

In this case I used a kind of (ugly) animation of the product moving into the cart at the top of the page. The Cart also updates after submission and the page will NOT reload, so easy for the visitor to continue shopping.
10010110
Translator
Translator
Posts: 224
Joined: Tue Jan 22, 2008 9:57 am

Re: Notifying successful add-to-cart (Calguys Commerce)

Post by 10010110 »

Velden, it would be awesome if you could set up a stripped down demo of that implementation somewhere public so others can learn from it. As you might remember I was wondering about the same thing before.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Notifying successful add-to-cart (Calguys Commerce)

Post by velden »

Hi, I do have a demo version (temporary though) which I'll be happy to provide a temporary customer account for. Please send a PM if interested.

Below I'll post some relevant code from the template. There might be an obsolete function in it but don't have time to look at that now (don't fix what's not broken did remove some :) ).

Code: Select all

{* update contents of div where cart is shown *}
function updateCart() {
  $("#mycart").load(
    "{module_action_link module='Cart2' action='mycart' urlonly=1 jsfriendly=1}", 
     { 'showtemplate' : 'false' }, 
     function() {  }
  )
};

{* Ajaxify pagination links *}
function ajaxifyPaginationLinks() {
  $(".pagination a").click(
    function(event) {
      event.preventDefault();
      var url = $(this).attr("href");
      showItems(url);
    }
  )
};

{* buttons of cart should be ajaxified. For logged in customers only *}
{cc_protect group='Customers' nocache}
function ajaxifyCartButtons() {  
  $('.frm_cart form').on( "submit", function( event ) {
    event.preventDefault();
    var posturl = $(this).attr("action") + "?showtemplate=false";  
    var postdata = $(this).serialize();
    /* ajax */
    $.post(posturl,postdata,function() { 
      //we don't display returned data
      // but update cart
      updateCart(); 
    }); 
  }); 
}
{/cc_protect}

{* display Products items *}
{* filter items based on checkboxes *}
function showItems(url) {
  //disabled filter checkboxes
   $("#filter input").attr("disabled",true)
  $('#filter').addClass('disabled'); 
  //show loading gif
  $('span#loader').addClass('loading'); 

  //array of to be excluded categories/brands
  var excats = [];
 
  //put UNchecked brands to array
  $('.cb-filter:not(:checked)').each(function() {
   excats.push($(this).val());
  });
  
  var data = { 'showtemplate' : 'false' };
  var url2 = '{module_action_link module='Products' action='default' urlonly=1 jsfriendly=1}';
  if (typeof(url) !== 'undefined') { url2 = url }
  {* get productActionId from url, needed for extra parameter excludecats *}
  var productActionId = url2.match(/Products,([^,]+),/)[1];
  data[productActionId + 'excludecat'] =  excats.toString();

  $("#shopen-products").load(url2, data, function(){ 
     {cc_protect group='Customers' nocache}ajaxifyCartButtons();{/cc_protect}
     ajaxifyPaginationLinks(); 
     $("#shopen-products").foundation();
     $("#filter input").removeAttr("disabled")
     $('span#loader').removeClass('loading');
     $('#filter').removeClass('disabled');
   } );
} ;

Locked

Return to “Modules/Add-Ons”