How to set discount price for all products globally in opencart

此生再无相见时 提交于 2019-12-25 02:22:19

问题


I need a discount price in all products in store to -5%. It has to show in product detail page and also product listing page like the individual discount price (strike-through). I want to apply the discount to all products in store globally. As i have tried, we have option to set discount price in the option tab while adding products but adding discount for each product seems to be long process. So i want to apply it globally. Any help or ideas will be greatly appreciated.

I checked some extensions but all show the global discount in the checkout page. I want to show it in the product details page based on the product price.


回答1:


in product controller

$this->load->model('catalog/product');
$products = $this->model_catalog_product->getProducts();
foreach ($products as $product) {
$this->model_catalog_product->setdiscount($product['product_id'],$product['price']);
}

in model

public function getProducts()
{
$query = $this->db->query("SELECT product_id, price FROM oc_product");
return $query->rows; 
}
    public function setdiscount($id,$price)
{

    $price=($price*95)/100;
    $query = $this->db->query("INSERT INTO oc_product_discount (product_id,customer_group_id,quantity,priority,price,date_start,date_end) VALUES ('".$id."','1','1','1','".$price."','xxx','yyy')");
}

xxx and yyy of your choice. and do change the customer_group_id,quantity,priority as per your req.

i have provided you the flow, do changes wherever you want.




回答2:


Open catalog/model/catalog/product.php

Find the line of code around line 40 that ends

=> $query->row['special'],

change it to

=> $query->row['price'] * 0.95,

And save. Note that if you have any discounts on the product, they will not appear with an additional 5% off the discount price. If you want that too, instead change the special line to end

($query->row['discount'] ? $query->row['discount'] : $query->row['price']) * 0.95,


来源:https://stackoverflow.com/questions/20992883/how-to-set-discount-price-for-all-products-globally-in-opencart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!