Reputation: 2265
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.
Upvotes: 0
Views: 6419
Reputation: 1
I have 18,000 products and needed to allow a discount to a particular customer group. I did NOT want to play with php!
I did it in mysql, operating on the opencart database. 0product_discount is the table you need to operate on. It will be empty until you create discount entries for a particular customer group against a product_id.
# open your opencart database in mysql
# first create a file listing the product_id's you want the discount applied to: you can restrict the 'select' as desired.
# This selects all products. Or you can edit the file
select product_id into outfile '/home/junkfile' from 0product;
# outside mysql in a console run the following as a script file (this is for linux console should work in windows(???) idk
# read each product_id line from the file and creates an insert line with the proper data
while read line; do
echo "TRUNCATE TABLE 0product_discount;" >> testxx.sql
echo "" >> testxx.sql
# third item "3" is the customer_group_id
# quantity 1, priority 1 and price $1.0000
#OR you can use a percent discount
# dates are zeros for unlimited time frame
echo "INSERT INTO 0product_discount ( product_discount_id, product_id, customer_group_id, quantity, priority, price, date_start, date_end) VALUES ( '"${id}"','"${id}"', '3', '1', '1', '1.0000', '0000-00-00', '0000-00-00');" >> testxx.sql
done < /home/junkfile
#This creates a form of mysqldump text file
## now use mysql -u [user] -p < testxx.sql to load the 0product_discount table
### note that the 'truncate line, clears out your failures ready for your next try!!
Not sure whether the discounted price will show up on the product page, but it does show up on checkout. Just add the customer to the proper group.
Upvotes: 0
Reputation: 15151
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,
Upvotes: 3
Reputation: 1467
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.
Upvotes: 0