如何在打开的购物车中使用自定义价格表

时间:2015-08-17 11:07:19

标签: opencart cart

我们项目的概念是,区域明智的产品过滤,产品可能相同或不同。如果管理员更改特定区域的产品价格,则价格应仅更改相应区域。 为此,我们创建了新表格oc_product_to_category,其中包含以下新字段price,quantity,offer。      如果新表具有价格值,则表示该过程使用该值,否则表示使用oc_product表中的默认价格值。 Upto类别页面我们已经成功实现了这个概念,

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)
            );
    }

在购物车中,它采用默认价格表值。如果我创建新功能手段,我必须更改整个购物车操作,但我只想更改价格计算,根据区域ID和产品ID。

我希望有人能给出解决方案。

谢谢..

1 个答案:

答案 0 :(得分:1)

没有必要为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 ,以便编码到购物车数组中。

相关问题