• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Cart2 Ajax calls
PostPosted: Wed Dec 04, 2019 9:07 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Wed Feb 20, 2008 4:33 pm
Posts: 88
Location: London, England
I am trying to get the Cart2 module to perform an ajax request rather than submitting the page.

I am using javascript to display that an item is added to the basket. unfortunately the page refreshes and the javascript instance is lost.

any thoughts welcome


Thanks


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Cart2 Ajax calls
PostPosted: Wed Dec 04, 2019 9:47 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 8172
Location: Fernie British Columbia, Canada
the add to cart action is designed to redirect to a destination page after submission. Ajax won't be possible there till the action is rewritten.

_________________
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Cart2 Ajax calls
PostPosted: Wed Dec 04, 2019 11:01 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Wed Feb 20, 2008 4:33 pm
Posts: 88
Location: London, England
@calguy1000

Is there a way of the Cart2 module exposing the sku's currently held in the cart so that on load I can tell the page to scroll the sku id I have assigned to the product widget? this may be a solution I could explore to solve my issue in the short term?

Thanks


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Cart2 Ajax calls
PostPosted: Wed Dec 04, 2019 9:12 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 8172
Location: Fernie British Columbia, Canada
The view cart template has the sku (if it exists) of every item in the cart.

You may be able to repurpose a call to the viewcart action with a different template to do what you want.

_________________
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Cart2 Ajax calls
PostPosted: Thu Dec 05, 2019 6:20 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Mon Sep 29, 2014 5:38 am
Posts: 77
This code will help you add products and not refresh the page.

\$1:
<head>
<__script__ type="text/javascript" src="assets/js/jquery.min.js"></__script>
</head>



MyCart
\$1:
                    <ul id="mycart" class="navbar-mini-cart navbar-nav animate-dropdown nav flip">
                           <li class="nav-item dropdown">
                              <a href="{cms_selflink href='korzina'}" class="nav-link">
                                 <i class="ec ec-shopping-bag"></i>
                                 {strip}
                                     {if $cart_itemcount == 0}
                                         {*Пустая корзина*}
                                     {else if $cart_itemcount >= "100"}
                                     <span class="cart-items-count count">&infin; </span>
                                     {else}
                                         <span class="cart-items-count count">{$cart_itemcount}</span>
                                     {/if}
                                  {/strip}
                                 <span class="cart-items-total-price total-price">
                                 {strip}
                                 {if $cart_itemcount == 0}
                                     Корзина пуста
                                 {else}
                                     <span class="amount">
                                           {$cart_totalprice} {$currency_symbol}
                                  </span>
                                 {/if}
                                 {/strip}
                                 </span>
                              </a>
                           </li>
                        </ul>



Addtocart
\$1:
<div id="{$submitname}_cart" class="frm_cart">   
{$formstart}
{strip}
<input type="hidden" name="{$submitname}" value="1" style="display: none;" />
<div class="input-group">
<input class="form-control " type="text" value="1" name="{$quantityname}" placeholder="1" size="3" maxlength="3"/>
<span class="input-group-btn">
<button type="submit" name="{$submitname}" class="btn btn-danger btn-lg" ><i class="ec ec-add-to-cart"></i> Купить </button>
 </span>
</div>
{/strip}
{$formend}
</div>
{jsmin}
{literal}
<__script__ type="text/javascript">
function ajaxifyCartButtons_{/literal}{$submitname}{literal}() {
  $('#{/literal}{$submitname}{literal}_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_{/literal}{$submitname}{literal}();
      replaceButton_{/literal}{$submitname}{literal}();
    });
  });
}

function updateCart_{/literal}{$submitname}{literal}() {
  $("#mycart").load(
    "{/literal}{module_action_link module='Cart2' action='mycart' urlonly=1 jsfriendly=1}{literal}",
     { 'showtemplate' : 'false' },
     function() {}
  )
};
function replaceButton_{/literal}{$submitname}{literal}() {
$("button[name~='{/literal}{$submitname}{literal}']").replaceWith('<button type="submit" class="btn btn-warning ripple" disabled> <i class="fa fa-check" aria-hidden="true"></i>  Добавлено <span class="md-ripple"></span></button>');
};
ajaxifyCartButtons_{/literal}{$submitname}{literal}();
</__script>
{/literal}
{/jsmin}


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Hosting Nation - Managed CMSMS Hosting