Jump to content

Display a single product on the homepage


Recommended Posts

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 by Eclipse42 (see edit history)
Link to comment
Share on other sites

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 by Eclipse42 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

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 by Eclipse42 (see edit history)
Link to comment
Share on other sites

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

  • 1 year later...

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

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

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...