如何在打开的购物车中使用自定义价格 table
How to use custom price table in open cart
我们项目的概念是,区域产品筛选,产品可能相同或不同。如果管理员更改特定区域的产品价格,则价格应仅更改相应区域。
为此,我们创建了新的 table,就像 oc_product_to_category
一样,具有以下新字段 price,quantity,offer
。
如果新的 table 具有价格值,则意味着使用该值进行处理,否则意味着使用 oc_product
table 的默认价格值。到类别页面我们已经成功地实现了这个概念,
Category.php:
$this->load->model('mobile/product');
$price_by_category = $this->model_mobile_product->getpricebycategory($result['product_id'],$category_id);
if($price_by_category['price'] != ""){
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => "Rs.".$price_by_category['price'].".00",
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);;
}else{
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
}
在购物车中,它采用默认价格 table 值。如果我创建新功能意味着,我必须更改整个购物车操作,但我只想根据区域 ID 和产品 ID 更改价格计算。
希望有人给出解决方案
谢谢..
无需为 category.php 重复整个块。您可以在添加到数组之前简单地重新分配价格,例如 $price = $price_by_category['price'] ?: $price
.
要在 cart.php 中加载您的模型,您可以这样做。在 __contruct
块中添加:
public function __construct($registry) {
$this->registry = $registry;
然后在 getProducts()
方法中你可以加载你的模型:
$this->load->model('mobile/product');
$mobileProduct = $this->registry->get('model_mobile_product');
$price_by_category = $mobileProduct->getpricebycategory($product_id,$category_id);
当然,这里的挑战是当客户将产品添加到购物车时,您需要将类别数据添加到购物车数组,以便您稍后可以引用它。我的建议是将其编码为购物车会话中的第三个切片。通常产品看起来像这样:
product-id:serialized-option-data:profile-id
因此您可以在添加到购物车时添加另一个切片来存储类别 ID:
product-id:serialized-option-data:profile-id:category_id
然后是:
if (!empty($product[3])) {
$category_id = $product[3];
} else {
$category_id = 0;
}
您还需要将 category_id 作为 POST 数据发送到 controller/checkout/cart -> add()
然后再次通过它到 system/library/cart.php 被编码到购物车数组中。
我们项目的概念是,区域产品筛选,产品可能相同或不同。如果管理员更改特定区域的产品价格,则价格应仅更改相应区域。
为此,我们创建了新的 table,就像 oc_product_to_category
一样,具有以下新字段 price,quantity,offer
。
如果新的 table 具有价格值,则意味着使用该值进行处理,否则意味着使用 oc_product
table 的默认价格值。到类别页面我们已经成功地实现了这个概念,
Category.php:
$this->load->model('mobile/product');
$price_by_category = $this->model_mobile_product->getpricebycategory($result['product_id'],$category_id);
if($price_by_category['price'] != ""){
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => "Rs.".$price_by_category['price'].".00",
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);;
}else{
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
}
在购物车中,它采用默认价格 table 值。如果我创建新功能意味着,我必须更改整个购物车操作,但我只想根据区域 ID 和产品 ID 更改价格计算。
希望有人给出解决方案
谢谢..
无需为 category.php 重复整个块。您可以在添加到数组之前简单地重新分配价格,例如 $price = $price_by_category['price'] ?: $price
.
要在 cart.php 中加载您的模型,您可以这样做。在 __contruct
块中添加:
public function __construct($registry) {
$this->registry = $registry;
然后在 getProducts()
方法中你可以加载你的模型:
$this->load->model('mobile/product');
$mobileProduct = $this->registry->get('model_mobile_product');
$price_by_category = $mobileProduct->getpricebycategory($product_id,$category_id);
当然,这里的挑战是当客户将产品添加到购物车时,您需要将类别数据添加到购物车数组,以便您稍后可以引用它。我的建议是将其编码为购物车会话中的第三个切片。通常产品看起来像这样:
product-id:serialized-option-data:profile-id
因此您可以在添加到购物车时添加另一个切片来存储类别 ID:
product-id:serialized-option-data:profile-id:category_id
然后是:
if (!empty($product[3])) {
$category_id = $product[3];
} else {
$category_id = 0;
}
您还需要将 category_id 作为 POST 数据发送到 controller/checkout/cart -> add()
然后再次通过它到 system/library/cart.php 被编码到购物车数组中。