Хочу добавить связанные товары в галерею
Ставлю в контроллер галереи:
if (isset($this->request->post['product_related'])) {
$products = $this->request->post['product_related'];
} elseif (isset($gallery_info)) {
$products = $this->model_extension_module_gallery->getProductRelated($this->request->get['gallery_id']);
} else {
$products = array();
}
$data['product_relateds'] = array();
$this->load->model('catalog/product');
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$data['product_relateds'][] = array(
'product_id' => $product_info['product_id'],
'name' => $product_info['name']
);
}
}
а в модель прописываю:
$this->db->query("DELETE FROM " . DB_PREFIX . "gallery_related_product WHERE gallery_id = '" . (int)$gallery_id . "'");
if (isset($data['product_related'])) {
foreach ($data['product_related'] as $related_id) {
$this->db->query("DELETE FROM " . DB_PREFIX . "gallery_related_product WHERE gallery_id = '" . (int)$gallery_id . "' AND product_id = '" . (int)$related_id . "'");
$this->db->query("INSERT INTO " . DB_PREFIX . "gallery_related_product SET gallery_id = '" . (int)$gallery_id . "', product_id = '" . (int)$related_id . "'");
}
}
и там же
public function getProductRelated($gallery_id) {
$uni_gallery_related_product = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "gallery_related_product WHERE gallery_id = '" . (int)$gallery_id . "'");
foreach ($query->rows as $result) {
$gallery_related_product[] = $result['product_id'];
}
return $gallery_related_product;
}
Но добавления товаров в админке модуля галереи не получилось, хоте в твиге все прописал