2016-06-02 3 views
2

私の問題の解決方法を探していますが、これまでには失敗しました。カートの商品数量がカートで10個を超えた場合、カートに追加ボタンを無効にします

お客様がカートごとに10個以上の商品を追加した場合、カートに追加ボタンを無効にするリクエストがあります。次のように

私のボタンのコードは次のとおりです。

   <?php if($logged) { ?><button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg"><?php echo $button_cart; ?></button><?php } ?> 

私はopencartのV 2.2.0を使用しています。カートに追加ボタンのコードに制限を定義する方法はありますか?私は完全にこの1つに失われたので、任意の提案は高く評価されるだろう。私は解決策はそこにあると確信していますが、私はそれを自分で見ることはできません。あらかじめありがとうございます。

+0

のようなJavaScriptの文を作る場合、これはかなり可能..です:) –

+0

@AliZiaあなたは、それを行う方法を私にしてください教えてください。 〜 – Nancy

答えて

2

If you need to check individual product to check whether the product is qty is 10 on cat or not. as below code

controller/product.php

$cart_product_detail=$this->cart->getProducts(); 
      //print_r($cart_product_detail); 
      $data['cart_product_info']=array(); 
      foreach($cart_product_detail as $cart_info){ 
       //print_r($cart_info); 
       $data['cart_product_info'][] = array(
        'cart_product_id' => $cart_info['product_id'], 
        'cart_product_qty' => $cart_info['quantity'] 
       ); 

on product.tpl

<?php //print_r($cart_product_info); 
        $current_product=$product_id; 
        $cart_quantity=0; 
        foreach($cart_product_info as $cart_prod): 
         if($current_product==$cart_prod['cart_product_id']){ 
          $cart_quantity=$cart_prod['cart_product_qty']; 
         }else{ 
         $cart_quantity=0; 
         } 
        endforeach; 
        //$product_qty=$product_qty-$cart_quantity; 
       ?> 
       <?php if($cart_quantity<10):?> 
       <button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block"><?php echo $button_cart; ?></button> 
       <?php endif;?> 

if you need to check total quantity of car no mather the which prodcuct then

product.php 
    $data['total_product_cart']=$this->cart->countProducts(); 

product.tpl 
<?php if($total_product_cart>10):?> 
        <button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block"><?php echo $button_cart; ?></button> 
<?php else:?> 
<button type="button" ><?php echo $button_cart; ?></button> 
        <?php endif;?> 

or you can use in any page where you like to disable the add to cart button. once you get the total product in cart you can disable add to cart button in various way

yous on product.php and where you need then you will get total product and make the decision

+0

こんにちは、 @Samir Karmacharyaご清聴ありがとうございます。私はproduct.phpにコードを書き込むことができましたが、product.tplのコードを記述するとエラーが発生します。 "通知:未定義の変数:product_qty in"。何か提案してください。ありがとうございました。 – Nancy

+0

$ product_qty = $ product_qty- $ cart_quantity行のコメントを置き換える必要があります。 –

+0

Thanx、ちょうどやったけど、ショッピングカートに追加するボタンは、カートに商品を追加しなくても消えてしまうという問題があります。助言がありますか?ありがとうございました。 – Nancy

0

私はあなたがすでにあなたのカート内の項目をカウントする方法を知っていると仮定? ので、この

if(cartcount > 10) 
    { 
     document.getElementById("button-cart").disabled = true; 
    } else { 
     document.getElementById("button-cart").disabled = false; 
    } 
関連する問題