gpt4 book ai didi

php - 如何根据opencart中的类别对购物车页面上的产品进行分组?

转载 作者:行者123 更新时间:2023-11-29 02:26:43 25 4
gpt4 key购买 nike

我们想根据类别在购物车页面中获取数据,以根据编号对总金额应用折扣。相同类别的产品。

在模型文件中

public function getCategory($data)
{
$sql = "SELECT category_id FROM " . DB_PREFIX . "Product_to_category where product_id='".$data."'";
$query = $this->db->query($sql);
foreach($query as $key=>$value)
{
//print_r($key); echo "=>"; print_r($value);
foreach($value as $k=>$v)
{
//echo $k."=>".$v;
return $k."=".$v;
}
}
}

在 Controller 文件/catalog/controller/checkout/cart.php

$r[]=$this->model_discount_cdiscount->getCategory($product['product_id']);

最佳答案

////////////// 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']
);
}

-

关于php - 如何根据opencart中的类别对购物车页面上的产品进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20440393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com