I stuck with an Opencart issue, it is old version 1.5.6.4. I want to show the lowest special price on the product page.
Firstly I created a function in the model with the SQL query:
public function getSpecialPriceMin($product_id) {
$query = $this->db->query("SELECT MIN(price) FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
return $query->row;
}
Then I tried to save the result in a variable in the product controller (without success as I am receiving an error message undefined variable):
$data['myVariable'] = $this->model_catalog_product->getSpecialPriceMin($product_id);
And then I try to echo the variable on the product page:
<?php echo $myVariable; ?>
I would appreciate any help. Thank you in advance.
CodePudding user response:
If you use OC 1.5.x.x version you should use: in model file:
public function getSpecialPriceMin($product_id) {
$query = $this->db->query("SELECT MIN(price) AS min_price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
return $query->row;
}
Controller:
$query = $this->model_catalog_product->getSpecialPriceMin($product_id);
$this->data['myVariable'] = $query['min_price'];
And then you can to echo the variable on product page:
<?php echo $myVariable; ?>