我想按类别在购物车页面上分组和显示产品。我的意思是,如果我们有四种产品,那么应该如下所示:
Category 1
- product i
- product ii
Category 2
- product i
- product ii
我还想将每个类别值的总量存储在一个数组中。我正在尝试实现分类折扣。 谢谢。
编辑:- 这是我的购物车页面,我试图在其中根据产品类别显示折扣
假设,如果购物车中有两种产品,并且它们属于两个不同的类别。现在我想根据每个类别的数量来计算折扣。 我在管理部分创建了一个模块,在其中设置所有必需的值,并将其存储到数据库中的表中。
现在,根据管理员中设置的值,我尝试在购物车页面上实现折扣。但我不知道,我该怎么做?
That's why I have no code to place here.
请给我一些想法,以便我可以尝试创建一些东西。 谢谢!!
以下是我的要求--
Sale and Delivery Terms:
- for orders exceeding 600 Francs, delivery is free of charge;
- for orders less than the above, a delivery charge of 20 Francs, will apply;
Discounts and Quantities
Red Wines, White Wines:
- from 36 bottles, each of 750ml, 6% discount;
- from 60 bottles, each of 750ml, 10% discount;
- from 84 bottles, each of 750ml, 13% discount.
Fortified Wines (sweet):
- from 12 bottles, each of 750ml, 5% discount.
Discount on Pick up:
- from 24 bottles, each of 750ml, 3% discount.
Cash Payment:
- from 24 bottles, each of 750ml, 3% discount.
Cash Payment on Delivery:
- 3% discount.
最佳答案
可以通过以下方式实现。 我们可以根据类别对所有产品进行排序,然后可以轻松应用任何折扣..
首先你应该对所有产品进行排序 ---
////////////// Grouping Same category products into one array //////////////
$category_id = $this->model_discount_cdiscount->getcategory($product['product_id']);
$array_key = $category_id[0]['category_id'];
if (array_key_exists($array_key, $this->data['discount']))
{
$this->data['discount'][$array_key]['total'] = $this->data['discount'][$array_key]['total']+(preg_replace("/[^0-9.]/","",$total));
$this->data['discount'][$array_key]['quantity'] = $this->data['discount'][$array_key]['quantity']+$product['quantity'];
}
else
{
$this->data['discount'][$array_key] = array(
'category_name' => $category_id[0]['name'],
'category_id' => $array_key,
'total' => (preg_replace("/[^0-9.]/","",$total)),
'quantity' => $product['quantity'],
'length' => $product['length']
);
}
然后就可以申请了---
////////////////////// Get Discount values from Discount table //////////////////////
foreach($this->data['discount'] as $key2 => $value2)
{
$this->data['product_match'][] = $this->model_discount_cdiscount->matchDiscount($key2);
}
////////////////////// Calculate Discount //////////////////////
$total_d =0;
foreach($this->data['discount'] as $discounts)
{
foreach($this->data['product_match'] as $match)
{
if(count($match)!=0)
{
if ($discounts['category_id']==$match['category'] AND $discounts['quantity']>=$match['quantity'] AND $discounts['length']==$match['class_value'])
{
$dt = ($match['discount']/100)*$discounts['total'];
$total_d += $dt;
}
}
}
}
关于php - 如何根据opencart购物车页面上的产品类别计算折扣?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20439706/