Jump to content

cannot access smarty variables in prestashop product controller


Recommended Posts

In the product page of prestashop 1.5.0.17, the thumbnails are not showing because the image width and the image height are showing up blank after the page is rendered. However, when I go to the productcontroller page, it is showing that there are definitions for them. I don't want to manually adjust the size of the thumbnails. It should be dynamic based on the mediumSize.

 

Can someone please let me know if they encounter this problem before and how they manage to fix it?

 

product.tpl

<li id="thumbnail_{$image.id_image}">

<a href="{$link->getImageLink($product->link_rewrite, $imageIds, 'thickbox')}" rel="other-views" class="thickbox {if $smarty.foreach.thumbnails.first}shown{/if}" title="{$image.legend|htmlspecialchars}">

<img id="thumb_{$image.id_image}" src="{$link->getImageLink($product->link_rewrite, $imageIds, 'medium')}" alt="{$image.legend|htmlspecialchars}" height="{$mediumSize.height}" width="{$mediumSize.width}" />

</a>

</li>

 

 

 

ProductController.php

public function initContent()

{

parent::initContent();

 

// Assign template vars related to the images

$this->assignImages();

}

 

 

 

 

protected function assignImages()
{
 $images = $this->product->getImages((int)$this->context->cookie->id_lang);
 $product_images = array();
 foreach ($images as $k => $image)
 {
  if ($image['cover'])
  {
   $this->context->smarty->assign('mainImage', $images[0]);
   $cover = $image;
   $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$image['id_image']) : $image['id_image']);
   $cover['id_image_only'] = (int)$image['id_image'];
  }
  $product_images[(int)$image['id_image']] = $image;
 }
 if (!isset($cover))
  $cover = array('id_image' => $this->context->language->iso_code.'-default', 'legend' => 'No picture', 'title' => 'No picture');

 $size = Image::getSize('large');
 $this->context->smarty->assign(array(
  'have_image' => Product::getCover((int)Tools::getValue('id_product')),
  'cover' => $cover,
  'imgWidth' => (int)$size['width'],
  'mediumSize' => Image::getSize('medium'),
  'largeSize' => Image::getSize('large'),
  'homeSize' => Image::getSize('home'),
  'col_img_dir' => _PS_COL_IMG_DIR_));
 if (count($product_images))
  $this->context->smarty->assign('images', $product_images);
}

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