Jump to content

Product information from module


Recommended Posts

Hi, could anyone advise me on what would be the best way to get product info such as price and description and display it on a module in the left/right column on the product page.

 

Can a module access the smarty vars that are assigned to the product tpl?

 

or would I need to create a module that calls the information?

 

My programming skills are not very good but from looking at the existing modules would code like the following work:

 

public function hookRightColumn($params)
{
 global $smarty;

 $id_product = (int)(Tools::getValue('id_product'));
 $product = new Product((int)($id_product));
 if (!$product)
  return;
 $smarty->assign(array('product' => $product));
 return $this->display(__FILE__, 'blockproductinfo.tpl');
}

 

Many thanks

Link to comment
Share on other sites

I have managed to get a little further with this but I am stuck on a problem and can't see what I am doing wrong. Here is my code:

 

public function hookRightColumn($params)
{
 global $smarty;

 $id_product = (int)(Tools::getValue('id_product'));
 if (!$id_product)
  return;
 $product = new Product((int)($id_product), false, (int)($params['cookie']->id_lang));
 $smarty->assign('product', $product);
 //$smarty->assign('productname', $product->name);

 return $this->display(__FILE__, 'prodinfo.tpl');
}

 

When I try to access the $product array in the template using {$product.name|escape:html:'UTF-8'} my page does not load.

 

If i uncomment //$smarty->assign('productname', $product->name); then I can get at the product name by using {$productname|escape:html:'UTF-8'}

 

Can anyone see why I get an error when trying to get at the $product array ?

 

Thanks

Link to comment
Share on other sites

OK I have figured this one out now, here is my code:

 

public function hookRightColumn($params)
{
 global $smarty;

 $id_product = (int)(Tools::getValue('id_product'));
 if (!$product = new Product((int)($id_product), false, (int)($params['cookie']->id_lang)))
  return;
 $smarty->assign('product', $product);

 return $this->display(__FILE__, 'prodinfo.tpl');
}

 

and to access the $product vars in a template I use: {$product->name|escape:'htmlall':'UTF-8'}

 

I have a question though, is this the best way to achieve this? It just seems a little wasteful having to call the product class twice in one page to access information that may already be available. How would this effect performance on a site with a large product database and high usage?

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