Eclipse42 Posted September 16, 2020 Share Posted September 16, 2020 (edited) Hey guys! I thought my need was very basic but I can't seem to find a way out. I just want to display a product on the home page. I don't want like the featured products with only the link to the product. I want directly the product with the add to cart button, the cover, description, everything. In order to do that, I created a module in which I can configure the product ID to display. And then, I tried to do something like that public function HookDisplayMyProduct($params) { $productId = Configuration::get('DISPLAYPRODUCT_ID'); if ($productId !== false) { $lang_id = (int) Configuration::get('PS_LANG_DEFAULT'); $product = new Product($productId, false, $lang_id); if (Validate::isLoadedObject($product)) { $this->context->smarty->assign([ 'product' => (array) $product, ]); return $this->display(__FILE__, 'my-product.tpl'); } } } The my-product.tpl is just a copy/paste from the original product.tpl And then, in my homepage, I just display the hook {block name='hook_my_product'} {hook h='displayMyProduct'} {/block} And I thought it was enough but the $product variable does not contain everything I need, I have some errors like "Undefined index: id_customization (or cover and so on)" So maybe I did something wrong here and there is an easier way to achieve that. Any input would be much appreciated ! I'm on PS 1.7 Cheers Edited September 17, 2020 by Eclipse42 (see edit history) Link to comment Share on other sites More sharing options...
idnovate.com Posted September 17, 2020 Share Posted September 17, 2020 Try this: $product = new Product($productId, true, $lang_id); Link to comment Share on other sites More sharing options...
Eclipse42 Posted September 17, 2020 Author Share Posted September 17, 2020 (edited) Hi, thanks for your answer ! I tried but it does not change the issue unfortunately ! I get the same "Notice: Undefined index: cover" from the product-cover-thumbnails.tpl which looks for $product.cover (I tried to get the cover with the getCover function but then, it complains about the 'bySize' index...) Edited September 17, 2020 by Eclipse42 (see edit history) Link to comment Share on other sites More sharing options...
Eclipse42 Posted September 30, 2020 Author Share Posted September 30, 2020 Nobody tried that before ? Link to comment Share on other sites More sharing options...
idnovate.com Posted October 4, 2020 Share Posted October 4, 2020 Call $product->assignImages(); Link to comment Share on other sites More sharing options...
Eclipse42 Posted October 4, 2020 Author Share Posted October 4, 2020 (edited) Thanks for your answer @idnovate.com but I did not find this function in the Product.php class ? (and nowhere in the project) Can you tell me where is this function located ? Edit : ok it's from prestashop 1.6 I believe. I'm on 1.7 but whatever. But it's from the productcontroller. Can you provide me a snippet to show me how to use that from a module ? Edited October 4, 2020 by Eclipse42 (see edit history) Link to comment Share on other sites More sharing options...
idnovate.com Posted October 8, 2020 Share Posted October 8, 2020 On 10/4/2020 at 7:55 PM, Eclipse42 said: Thanks for your answer @idnovate.com but I did not find this function in the Product.php class ? (and nowhere in the project) Can you tell me where is this function located ? Edit : ok it's from prestashop 1.6 I believe. I'm on 1.7 but whatever. But it's from the productcontroller. Can you provide me a snippet to show me how to use that from a module ? Yes, sorry, I didn't check it was not on PS 1.7. So let's go back. It's seems that getCover() function doesn't retrieves the cover. What did you do? Link to comment Share on other sites More sharing options...
Pack Posted October 13, 2021 Share Posted October 13, 2021 Hello, Have you managed to display a single product on homepage? I only have few products. I would like to list them all on Homepage with all of its combinations, quantity, description, add-to-cart button… (like they are display on a product Page). I am on PS 1.7. If you could help me… Thnak you very much Link to comment Share on other sites More sharing options...
pullidea-dev Posted October 20, 2021 Share Posted October 20, 2021 You need to refer the ProductController. (controllers/front/ProductController.php) Link to comment Share on other sites More sharing options...
ps8modules Posted October 21, 2021 Share Posted October 21, 2021 On 10/20/2021 at 9:28 AM, raudsepp said: You need to refer the ProductController. (controllers/front/ProductController.php) If you edit ProductController.php, the change will be global. What they advise you here will be a change in categories or subcategories. It will not be just for the Home Page. Link to comment Share on other sites More sharing options...
joseantgv Posted October 21, 2021 Share Posted October 21, 2021 En 13/10/2021 a las 5:17 PM, Pack dijo: Hello, Have you managed to display a single product on homepage? I only have few products. I would like to list them all on Homepage with all of its combinations, quantity, description, add-to-cart button… (like they are display on a product Page). I am on PS 1.7. If you could help me… Thnak you very much If you are interested in purchasing a module, with this one https://addons.prestashop.com/en/sliders-galleries/45104-products-carousel-and-slider.html you can configure multiple blocks and display them anywhere, with the products that you need. Link to comment Share on other sites More sharing options...
Yelish Posted October 25, 2021 Share Posted October 25, 2021 You just have to change the template to show only 1 product. You can specify the product in the template. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now