Opencart最低订购价格不包括一个类别 [英] Opencart minimum order price exclude one category
问题描述
我正在使用opencart,并且已成功为所有交易添加了最低订单价格. 这是我使用的代码:
I am using opencart and successfully added minimum order price for all transactions. This is the code I used:
<?php if ($this->cart->getSubtotal() >= 10) { ?>
<div id="payment"><?php echo $payment; ?></div>
<?php } else { ?>
<div class="warning">Minimum 10 Euro to checkout</div>
<?php } ?>
现在,我要排除一个类别,以便可以购买该类别中的9美元产品.
Now I want to exclude one category out of it so that $9 product from that category can be bought.
更新1: 非常感谢shadyyx的帮助
Update 1: Thank you so much for the help shadyyx
我尝试了shadyyx方法,但出现此错误:
此行中的unexpected T_BOOLEAN_OR
I tried shadyyx method but I am getting this error:
unexpected T_BOOLEAN_OR
in this line
<?php if ($this->cart->getSubtotal() >= 10 || $this->cart->productsAreInCategory(1)) { ?>
更新2:我尝试了此操作,但弹出了一个对话框,提示只是错误和确定按钮
<?php if (($this->cart->getSubtotal() >= 10) || $this->cart->productsAreInCategory(1)) { ?>
Update 2: I tried this but it gave a pop up saying just error and ok button
<?php if (($this->cart->getSubtotal() >= 10) || $this->cart->productsAreInCategory(1)) { ?>
我尝试了这个
<?php if (($this->cart->getSubtotal() >= 10) || ($this->cart->productsAreInCategory(1))) { ?>
它没有给出任何错误,并且执行相同的工作(所有订单的最低金额,与类别ID无关)
I tried this
<?php if (($this->cart->getSubtotal() >= 10) || ($this->cart->productsAreInCategory(1))) { ?>
it did not give any error and does same work (min amount for all orders regardless of category id)
推荐答案
我会这样:
扩展system/library/cart.php
并添加方法:
public function productsAreInCategory($category_id) {
$product_ids = array();
foreach($this->getProducts() as $product) {
$product_ids[] = $product['product_id'];
}
$categories = $this->db->query('SELECT category_id FROM ' . DB_PREFIX . 'product_to_category WHERE product_id IN (' . implode(',', $product_ids) . ')')->rows;
$category_ids = array();
foreach($categories as $category) {
$category_ids[] = $category['category_id'];
}
if(in_array($category_id, $category_ids) {
return true;
}
return false;
}
此方法应接受$category_id
参数进行测试,并应加载购物车中所有产品的类别.第一次匹配后,返回true,如果没有匹配,则返回false.您现在可以通过以下方式使用此方法:
This method should accept a $category_id
parameter to test against and should load categories for all products in cart. After first match a true is returned, if no match, a false is returned. You can now use this method this way:
<?php if (($this->cart->getSubtotal() >= 10) || $this->cart->productsAreInCategory(1)) { ?>
<div id="payment"><?php echo $payment; ?></div>
<?php } else { ?>
<div class="warning">Minimum 10 Euro to checkout</div>
<?php } ?>
只需用正确的ID替换$this->cart->productsAreInCategory(1)
中的类别ID.
Just replace the category ID in $this->cart->productsAreInCategory(1)
with the correct one.
这篇关于Opencart最低订购价格不包括一个类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!