Last active
March 27, 2022 15:14
-
-
Save kalinichenko88/03f8fdddefb685e19098 to your computer and use it in GitHub Desktop.
Получение минимальной цены товара в категории OpenCart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Получение минимальной цены товара в категории | |
* | |
* @file catalog/models/product.php | |
* @param $category_id | |
* @return int | |
*/ | |
public function getMinPriceFromCategory($category_id) | |
{ | |
$sql = 'SELECT MIN(' . DB_PREFIX . 'product.price) FROM ' . DB_PREFIX . 'product LEFT JOIN ' . | |
DB_PREFIX . 'product_to_category ON ' . DB_PREFIX . 'product.product_id = ' . | |
DB_PREFIX . 'product_to_category.product_id WHERE ' . DB_PREFIX . 'product_to_category.category_id = ' . (int)$category_id; | |
$query = $this->db->query($sql); | |
$price = $query->row['MIN(' . DB_PREFIX . 'product.price)']; | |
if ($price != null) | |
return $this->currency->format($price); else | |
return 0; | |
} | |
/* | |
И вызов в контроллере category.php | |
$this->data['categories'][] = array( | |
'min_price' => $this->model_catalog_product->getMinPriceFromCategory($result['category_id']) | |
); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment