Skip to content

Instantly share code, notes, and snippets.

@kalinichenko88
Last active March 27, 2022 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save kalinichenko88/03f8fdddefb685e19098 to your computer and use it in GitHub Desktop.
Save kalinichenko88/03f8fdddefb685e19098 to your computer and use it in GitHub Desktop.
Получение минимальной цены товара в категории OpenCart
/**
* Получение минимальной цены товара в категории
*
* @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