Jump to content

Afficher un produit spécifique en page d'accueil


Recommended Posts

Bonjour à tous,

 

Je sèche depuis quelques heures déjà et impossible de trouver quoi que ce soit pour avancer :

 

Je souhaite créer un module qui me permet d'afficher une fiche produit au centre de ma page d'accueil.

sur le modèle de homefeatured, je voudrais appeler product.tpl au lieu de product-list.tpl Malheureusement, il me manque les images liées au produit.

Mon module est bien installé, mon hook est correctement paramétré, le hic, c'est que je n'arrive pas à récupérer mon produit avec ses images.

 Voici la requête que j'utilise pour récupérer mon produit : 

$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, pl.`description`, pl.`description_short`, pl.`available_now`,
					pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image,
					il.`legend`, m.`name` AS manufacturer_name, cl.`name` AS category_default,
					DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
					INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
						DAY)) > 0 AS new, product_shop.price AS orderprice
				FROM `'._DB_PREFIX_.'category_product` cp
				LEFT JOIN `'._DB_PREFIX_.'product` p
					ON p.`id_product` = cp.`id_product`
				'.Shop::addSqlAssociation('product', 'p').'
				LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
				ON (p.`id_product` = pa.`id_product`)
				'.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').'
				'.Product::sqlStock('p', 'product_attribute_shop', false, $this->context->shop).'
				LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
					ON (product_shop.`id_category_default` = cl.`id_category`
					AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').')
				LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
					ON (p.`id_product` = pl.`id_product`
					AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').')
				LEFT JOIN `'._DB_PREFIX_.'image` i
					ON (i.`id_product` = p.`id_product`)'.
				Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
				LEFT JOIN `'._DB_PREFIX_.'image_lang` il
					ON (image_shop.`id_image` = il.`id_image`
					AND il.`id_lang` = '.(int)$id_lang.')
				LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
					ON m.`id_manufacturer` = p.`id_manufacturer`
				WHERE product_shop.`id_shop` = '.(int)$this->context->shop->id.'
					AND product_shop.deal_du_jour = true ORDER BY pl.date_fin_deal DESC';
			$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

 et ce que j'assigne à mon template :

$this->context->smarty->assign(
				array('product' => new Product($res[0]['id_product'], true, $this->context->language->id, $this->context->shop->id),
				'homeSize' => Image::getSize('home')
				)
			);

Je récupère beaucoup d'informations mais mes images ne sont pas liées...

 

Merci pour votre aide

 

[edit]

J'imagine qu'il faudrait que je fasse appel à initContent de ProductController.php mais je ne sais pas comment l'initialiser depuis mon module.

[/edit]

Edited by ruminez (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...