如果购物车上的产品数量超过 10,则禁用产品添加到购物车按钮
Disable product add to cart button if quantity of that product exceeds 10 on cart
我一直在尝试为我的问题寻找解决方案,但到目前为止都失败了。
如果客户将每个产品的 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。有没有办法在添加到购物车按钮代码中定义限制?任何建议将不胜感激,因为我完全迷失了这一点。我确信解决方案就在那里,但我自己似乎看不到。提前谢谢大家。
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
我想您已经知道如何计算购物车中的商品了?
如果是这样,请做出这样的 javascript 声明
if(cartcount > 10)
{
document.getElementById("button-cart").disabled = true;
} else {
document.getElementById("button-cart").disabled = false;
}
我一直在尝试为我的问题寻找解决方案,但到目前为止都失败了。
如果客户将每个产品的 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。有没有办法在添加到购物车按钮代码中定义限制?任何建议将不胜感激,因为我完全迷失了这一点。我确信解决方案就在那里,但我自己似乎看不到。提前谢谢大家。
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
我想您已经知道如何计算购物车中的商品了? 如果是这样,请做出这样的 javascript 声明
if(cartcount > 10)
{
document.getElementById("button-cart").disabled = true;
} else {
document.getElementById("button-cart").disabled = false;
}