Здравствуйте!
По каким причинам могут теряться часть данных из массива при выборке из базы?
Проблема в том, что в корзине не выводяться наименования части товаров и тп.
В массиве есть данные о картинках и вариантах товара, а вот id,name и тп выпадают, а для других позиций эти данные есть.
Вот функция отвечающая за выборку, но для категорий работает нормально.
public function get_products($filter = array())
{
// По умолчанию
$limit = 100;
$page = 1;
$category_id_filter = '';
$brand_id_filter = '';
$product_id_filter = '';
$features_filter = '';
$keyword_filter = '';
$visible_filter = '';
$visible_filter = '';
$is_featured_filter = '';
$discounted_filter = '';
$in_stock_filter = '';
$group_by = '';
$order = 'p.position DESC';
/*Ajax-фильтр*/
$price_filter_join = '';
$price_filter_where = '';
/*EVD Ajax-фильтр*/
if(isset($filter['limit']))
$limit = max(1, intval($filter['limit']));
if(isset($filter['page']))
$page = max(1, intval($filter['page']));
$sql_limit = $this->db->placehold(' LIMIT ?, ? ', ($page-1)*$limit, $limit);
if(!empty($filter['id']))
$product_id_filter = $this->db->placehold('AND p.id in(?@)', (array)$filter['id']);
if(!empty($filter['category_id']))
{
$category_id_filter = $this->db->placehold('INNER JOIN __products_categories pc ON pc.product_id = p.id AND pc.category_id in(?@)', (array)$filter['category_id']);
$group_by = "GROUP BY p.id";
}
if(!empty($filter['brand_id']))
$brand_id_filter = $this->db->placehold('AND p.brand_id in(?@)', (array)$filter['brand_id']);
if(!empty($filter['featured'])):
$is_featured_filter = $this->db->placehold('AND p.featured=?', intval($filter['featured']));
$order = "RAND()";
endif;
if(!empty($filter['discounted'])):
$discounted_filter = $this->db->placehold('AND (SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.compare_price>0 LIMIT 1) = ?', intval($filter['discounted']));
$order = "RAND()";
endif;
if(!empty($filter['in_stock']))
$in_stock_filter = $this->db->placehold('AND (SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.price>0 AND (pv.stock IS NULL OR pv.stock>0) LIMIT 1) = ?', intval($filter['in_stock']));
if(!empty($filter['visible']))
$visible_filter = $this->db->placehold('AND p.visible=?', intval($filter['visible']));
/*Ajax-фильтр*/
if(!empty($filter['price_first']))
{
$price_filter_join = $this->db->placehold('LEFT JOIN __variants pv ON pv.product_id = p.id');
$price_filter_where .= $this->db->placehold(' AND (pv.price = NULL OR pv.price >= ?) ', (int)$filter['price_first']);
}
if(!empty($filter['price_last']))
{
$price_filter_join = $this->db->placehold('LEFT JOIN __variants pv ON pv.product_id = p.id');
$price_filter_where .= $this->db->placehold(' AND (pv.price = NULL OR pv.price <= ?) ', (int)$filter['price_last']);
}
/*END Ajax-фильтр*/
if(!empty($filter['sort']))
switch ($filter['sort'])
{
case 'position':
//$order = 'p.position DESC';
$order = 'p.position DESC';
//$order = '(SELECT pv.position FROM __variants pv WHERE (pv.stock IS NULL OR pv.stock>0) AND p.id = pv.product_id LIMIT 1) DESC';
break;
case 'name':
$order = 'p.name';
break;
case 'created':
$order = 'p.created DESC';
break;
case 'price':
//$order = 'pv.price IS NULL, pv.price=0, pv.price';
$order = '(SELECT -pv.price FROM __variants pv WHERE (pv.stock IS NULL OR pv.stock>0) AND p.id = pv.product_id AND pv.position=(SELECT MIN(position) FROM __variants WHERE (stock>0 OR stock IS NULL) AND product_id=p.id LIMIT 1) LIMIT 1) DESC';
break;
}
if(!empty($filter['keyword']))
{
$keywords = explode(' ', $filter['keyword']);
foreach($keywords as $keyword)
$keyword_filter .= $this->db->placehold('AND (p.name LIKE "%'.$this->db->escape(trim($keyword)).'%" OR p.meta_keywords LIKE "%'.$this->db->escape(trim($keyword)).'%" OR v.sku LIKE "%'.$this->db->escape(trim($keyword)).'%")');
}
/*Ajax-фильтр*/
/*if(!empty($filter['features']) && !empty($filter['features']))
foreach($filter['features'] as $feature=>$value)
$features_filter .= $this->db->placehold('AND p.id in (SELECT product_id FROM __options WHERE feature_id=? AND value=? ) ', $feature, $value);
*/
if(!empty($filter['features']) && !empty($filter['features']))
foreach($filter['features'] as $feature=>$value)
$features_filter .= $this->db->placehold('AND p.id in (SELECT product_id FROM __options WHERE feature_id=? AND value in (?@) ) ', $feature, $value);
/*END Ajax-фильтр*/
$query = "SELECT
p.id,
p.url,
p.brand_id,
p.name,
p.annotation,
p.body,
p.position,
p.created as created,
p.visible,
p.featured,
p.meta_title,
p.meta_keywords,
p.meta_description,
b.name as brand,
b.url as brand_url
FROM __products p
$category_id_filter
LEFT JOIN __brands b ON p.brand_id = b.id
LEFT JOIN __variants v ON p.id = v.product_id
/*Ajax-фильтр*/$price_filter_join/*END Ajax-фильтр*/
WHERE
1
$product_id_filter
$brand_id_filter
$features_filter
$keyword_filter
$is_featured_filter
$discounted_filter
/*Ajax-фильтр*/$price_filter_where/*END Ajax-фильтр*/
$in_stock_filter
$visible_filter
$group_by
ORDER BY $order
$sql_limit";
//echo $query;
//exit;
$query = $this->db->placehold($query);
$this->db->query($query);
return $this->db->results();
}