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)

Share this post


Link to post
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)

Share this post


Link to post
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)

Share this post


Link to post
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?

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More