Author Topic: Custom add to cart and buy now fro prestashop 1.7.6.4  (Read 379 times)

Offline sundar

  • Site Manager
  • Hero Member
  • *****
  • Posts: 249
  • Total likes: 1
  • Karma: +1/-0
  • Gender: Male
  • Thirsty Knowledge...
    • View Profile
    • Can talk anything
Custom add to cart and buy now fro prestashop 1.7.6.4
« on: June 05, 2021, 07:27:43 AM »

My developer used this code to add to cart and buy now button after check availability shipping location, add to cart button working fine if its out of stock means button disabled but for buy now button its enabled even if its in out of stock,kindly some one help me to fix this one


here the html code we used


 
Code: [Select]


    <div class="add-to-cart">
          <form action="{Context::getContext()->link->getPageLink('cart')}" method="post" class="add-to-cart-or-refresh">
                     <input type="hidden" name="token" value="{Tools::getToken(false)}">
                     <input type="hidden" name="id_product" value="{$product.id}" class="product_page_product_id">
                     <input type="hidden" name="qty" value="1">
                     <button class="btn btn-primary add-to-cart" id="disabledCartAttr" data-button-action="add-to-cart" type="submit" {if $product.quantity < 1 || !$product.add_to_cart_url}disabled{/if}>
    <i class="fa fa-shopping-cart" aria-hidden="true"></i>
    <span>{l s='Add to cart' d='Shop.Theme.Actions'}</span>
    </button>
   
      {if isset($static_token)}
                        <div id="buy_now" class="buy_now" >
    <a id="buy_now_attr" class="button buy_now_button btn btn-default" href='{$link->getPageLink("cart", false, NULL, "add=1&id_product={$product->id|intval}&token={$static_token}", false)|escape:"html":"UTF-8"}' rel="nofollow" title="{l s='Buy Now'}" data-id-product="{$product->id|intval}"  onclick="this.href = this.href+ '&qty='+$('.buy_now_button').closest('form').find(document.querySelector('#quantity_wanted').value).selector + '&ipa='+  $('.buy_now_button').closest('form').find(document.querySelector('#idCombination').value).selector;" ><span>{l s='Buy Now'}</span></a>
                           
                        {else}
    <a id="buy_now_attr" class="button buy_now_button btn btn-default" href='{$link->getPageLink("cart", false, NULL, "add=1&id_product={$product->id|intval}", false)|escape:"html":"UTF-8"}' rel="nofollow" title="{l s='Buy Now'}" data-id-product="{$product->id|intval}" onclick="this.href = this.href+ '&qty='+$('.buy_now_button').closest('form').find(document.querySelector('#quantity_wanted').value).selector + '&ipa='+  $('.buy_now_button').closest('form').find(document.querySelector('#idCombination').value).selector;" ><span>{l s='Buy Now'}</span></a>                       
                    <>
                        {/if}
                    </form>
        <>
    <>


and the java script we used


   
Code: [Select]
<script>
    $(document).ready(function(){
           setTimeout(function(){
    if(document.querySelector('#disabledCartAttr').disabled) {
    $('#buy_now_attr').addClass("disabled");
    }
   
    if(document.querySelector('#disabledCartAttr').disabled) {
    $('#buy_now_attr').removeClass("disabled");
    }
            }, 1000);
    $('#check_zipcode').click(function() {
    setTimeout(function(){
    if(!document.querySelector('#disabledCartAttr').disabled) {
    $('#buy_now_attr').addClass("disabled");
    }
   
    if(!document.querySelector('#disabledCartAttr').disabled) {
    $('#buy_now_attr').removeClass("disabled");
    }
    }, 1000);
    });
   
     });
   
   
    </script>
Always TAG your threads

  • Download all the schematics here Direct download
  • Stay connected with S4talk on

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal