2016-06-02 5 views
2

문제점에 대한 해결책을 찾으려고했지만 지금까지 실패했습니다.장바구니에 해당 제품의 수량이 10을 초과하면 장바구니에 담기 버튼을 비활성화하십시오.

고객이 장바구니에 제품 당 10 개가 넘는 항목을 추가하는 경우 장바구니에 추가 버튼을 사용 중지하라는 요청이 있습니다. 내가 opencart의 V 2.2.0을 사용하고

   <?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 } ?> 

을 다음과 같이

내 버튼의 코드입니다. 장바구니에 추가 버튼 코드에 한도를 정의하는 방법이 있습니까? 내가이 책에서 완전히 잃어 버렸기 때문에 어떤 제안이라도 높게 평가 될 것입니다. 나는 해결책이 거기에 있다고 확신하지만 나는 그것을 스스로 볼 수 없다. 모두에게 미리 감사드립니다.

+0

같은 자바 스크립트 문이 확실히 가능하다 할 경우 는 .. : –

+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 코드를 넣을 때 오류가 발생했습니다. "Notice : 정의되지 않은 변수 : product_qty in". 어떤 제안이라도? 고맙습니다. – Nancy

+0

$ product_qty = $ product_qty- $ cart_quantity 줄에서 주석을 대체해야합니다. –

+0

고맙습니다, 방금했습니다. 문제는 장바구니에 제품을 추가하지 않아도 장바구니에 추가 버튼이 사라졌습니다. 어떤 제안? 고맙습니다. – Nancy

0

? 그래서이

if(cartcount > 10) 
    { 
     document.getElementById("button-cart").disabled = true; 
    } else { 
     document.getElementById("button-cart").disabled = false; 
    } 
관련 문제