Добрый день, уважаемые гуру sql. Помогите, пожалуйста, изменить запрос так, что бы при наличии аукционной цены на товар бралась именно она, а не базовая. Сейчас функция выглядит так:
public function getProductsByCategoryId($category_id,$stock) {
if($stock){
$stock = "p.quantity > 0 AND ";
} else {
$stock = "";
}
$query = $this->db->query("SELECT DISTINCT p.product_id,p.model,p.price,p.image,pd.name,pd.description,p2c.category_id,cd.name AS category_name FROM " . DB_PREFIX . "product p
LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)
LEFT JOIN " . DB_PREFIX . "category_description cd ON (p2c.category_id = cd.category_id) WHERE " . $stock . "pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY pd.name ASC");
return $query->rows;
}
Решил вопрос самостоятельно, изменив запрос на
$query = $this->db->query("SELECT DISTINCT p.product_id,p.model,p.price,p.image,pd.name,pd.description,p2c.category_id,cd.name AS category_name, ps.price AS special
FROM " . DB_PREFIX . "product p
LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)
LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id AND ps.customer_group_id = '3' AND ps.date_start < NOW() AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())/* AND ps.priority = 0 */)
LEFT JOIN " . DB_PREFIX . "category_description cd ON (p2c.category_id = cd.category_id) WHERE " . $stock . "pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY pd.name ASC");