2016-06-02 7 views
2

Ich habe versucht, eine Lösung für mein Problem zu finden, aber bisher gescheitert.Deaktivieren Sie das Produkt zum Warenkorb hinzufügen, wenn die Menge dieses Produkts 10 auf dem Warenkorb überschreitet

Ich habe eine Anfrage, die Schaltfläche In den Warenkorb zu deaktivieren, wenn der Kunde mehr als 10 Artikel pro Produkt in den Warenkorb legt.

Der Code für meine Taste ist wie folgt:

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

ich OpenCart v 2.2.0 verwenden. Gibt es eine Möglichkeit, das Limit in der Schaltfläche "Add to cart" zu definieren? Jeder Vorschlag würde sehr geschätzt werden, da ich auf diesem einen völlig verloren bin. Ich bin mir sicher, dass die Lösung da ist, aber ich kann es selbst nicht sehen. Vielen Dank im Voraus.

+0

Dies ist durchaus möglich .. :) –

+0

@AliZia Können Sie mir sagen, wie es zu tun, bitte? Danke. – Nancy

Antwort

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

Hallo, @Samir Karmacharya Vielen Dank für Ihren Vorschlag. Ich habe es geschafft, Code in product.php zu setzen, aber wenn ich Code für product.tpl setze, bekomme ich Fehler: "Nachricht: Undefinierte Variable: product_qty in". Irgendwelche Vorschläge, bitte? Vielen Dank. – Nancy

+0

Sie müssen den Kommentar aus der Zeile ersetzen $ product_qty = $ product_qty- $ cart_quantity; –

+0

Danke, das habe ich gerade gemacht, aber das Problem ist, dass meine Add to cart-Taste jetzt weg ist, obwohl ich noch kein Produkt in meinen Warenkorb gelegt habe. Irgendwelche Vorschläge? Vielen Dank. – Nancy

0

ich Sie schon annehmen wissen, wie die Artikel im Warenkorb zählen? wenn so eine JavaScript-Anweisung wie diese

machen
if(cartcount > 10) 
    { 
     document.getElementById("button-cart").disabled = true; 
    } else { 
     document.getElementById("button-cart").disabled = false; 
    } 
Verwandte Themen