Рекомендуемые статьи и товары

This commit is contained in:
Konstantin
2026-05-31 11:48:41 +03:00
parent 5a677f7db7
commit 15446a6402
14 changed files with 275 additions and 50 deletions
+29
View File
@@ -398,6 +398,35 @@ class ModelCatalogProduct extends Model
return $product_data;
}
public function getRandomProductsFromSameCategories($product_id, $limit = 4)
{
$product_data = array();
$cache = 'product.related.random.' . (int) $this->config->get('config_store_id') . '.' . (int) $product_id . '.' . (int) $limit;
$product_ids = $this->cache->get($cache);
if (!$product_ids) {
$product_ids = array();
$query = $this->db->query('SELECT DISTINCT p.product_id FROM ' . DB_PREFIX . 'product_to_category source_p2c INNER JOIN ' . DB_PREFIX . 'product_to_category related_p2c ON (source_p2c.category_id = related_p2c.category_id) INNER JOIN ' . DB_PREFIX . 'product p ON (related_p2c.product_id = p.product_id) INNER JOIN ' . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE source_p2c.product_id = '" . (int) $product_id . "' AND p.product_id != '" . (int) $product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int) $this->config->get('config_store_id') . "' ORDER BY RAND() LIMIT " . (int) $limit);
foreach ($query->rows as $result) {
$product_ids[] = $result['product_id'];
}
$this->cache->set($cache, $product_ids);
}
foreach ($product_ids as $related_id) {
$product = $this->getProduct($related_id);
if ($product) {
$product_data[$related_id] = $product;
}
}
return $product_data;
}
public function getProductLayoutId($product_id)
{
$query = $this->db->query('SELECT * FROM ' . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int) $product_id . "' AND store_id = '" . (int) $this->config->get('config_store_id') . "'");