Вывод товара из сопутствующего бренда на странице карточки товара.
Редактируем файл:
\api\Brands.php
После функции
public function get_brand($id) { if(is_int($id)) $filter = $this->db->placehold('id = ?', $id); else $filter = $this->db->placehold('url = ?', $id); $query = "SELECT id, name, url, meta_title, meta_keywords, meta_description, description, image FROM __brands WHERE $filter ORDER BY name LIMIT 1"; $this->db->query($query); return $this->db->result(); }
вставляем:
/* * * Функция возвращает бренд по продукту id или url * (в зависимости от типа аргумента, int - id, string - url) * @param $id id или url поста * */ public function get_brand_pr($id) { if(!is_int($id)) $filter = $this->db->placehold('id = ?', $id); else $filter = $this->db->placehold('url = ?', $id); $query = "SELECT brand_id, id, url, name, position, meta_title FROM __products WHERE $filter LIMIT 1"; $this->db->query($query); return $this->db->result(); }
далее, находим в файле:
\view\ProductView.php
$this->design->assign('related_products', $related_products); }
после сразуже вставляем:
else { // генерируемые связанные товары $products->brands = $this->brands->get_brand_pr($product->id); $brandy = reset($products->brands); $related_products = array(); $after = false; $products = $this->products->get_products(array('brand_id' => $brandy, 'limit' => 100, 'in_stock'=>1, 'visible'=>1)); foreach($products as $p) { if($after && count($related_products) < 6) $related_products[$p->id] = $p; elseif($p->id == $product->id) $after = true; } if(count($related_products) < 6) foreach($products as $p) if($p->id != $product->id && count($related_products) < 6) $related_products[$p->id] = $p; else break; $related_products_images = $this->products->get_images(array('product_id'=>array_keys($related_products))); foreach($related_products_images as $related_product_image) if(isset($related_products[$related_product_image->product_id])) $related_products[$related_product_image->product_id]->images[] = $related_product_image; $related_products_variants = $this->variants->get_variants(array('product_id'=>array_keys($related_products), 'instock'=>true)); foreach($related_products_variants as $related_product_variant) { if(isset($related_products[$related_product_variant->product_id])) { $related_product_variant->price *= (100-$discount)/100; $related_products[$related_product_variant->product_id]->variants[] = $related_product_variant; } } foreach($related_products as $r) { $r->image = &$r->images[0]; $r->variant = &$r->variants[0]; } $this->design->assign('related_products', $related_products); } // end: генерируемые связанные товары
И вс,, должно вс, работать