PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 16, 2022

[FIXED] How to set discount price for all products globally in opencart

 October 16, 2022     e-commerce, mysql, opencart, php     No comments   

Issue

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.


Solution

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.



Answered By - Karan Thakkar
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing