Jump to content

Product Image URL


Recommended Posts

Dear,

 

anyone know how to get product image url in Prestashop 1.5.1 ?

since i think its change than previous version.

 

appreciate for any comment

 

<img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" height="{$homeSize.height}" width="{$homeSize.width}" alt="{$product.name|escape:html:'UTF-8'}" />

Link to comment
Share on other sites

here is some code:

module code :

 

 

$product = new Product((int)Tools::getValue('id_product'));

$images = Image::getImages((int)$id_lang, (int)$product->id);

$this->context->smarty->assign('id_image', (int)$images[0]['id_image']);

 

 

$this->context->smarty->assign('product_r', $product->link_rewrite[1]);

 

 

 

template :

{$link->getImageLink( $product_r, $id_image, 'large_default')

Link to comment
Share on other sites

$product = new Product((int)Tools::getValue('id_product'));

$images = Image::getImages((int)$id_lang, (int)$product->id);

$this->context->smarty->assign('id_image', (int)$images[0]['id_image']);

 

$this->context->smarty->assign('product_r', $product->link_rewrite[1]);

 

template :

{$link->getImageLink( $product_r, $id_image, 'large_default')

what exactly is in $product array? // {$product|print_r}

 

maybe try to pass to tpl $product variable with $product array

 

php:

$this->context->smarty->assign('product', $product);

 

tpl:

$link->getImageLink( $product.link_rewrite, $product.id_image, 'home_default') 
$_link->getImageLink( $product.link_rewrite, $product.id_image, 'large_default') 

Link to comment
Share on other sites

what exactly is in $product array? // {$product|print_r}

 

maybe try to pass to tpl $product variable with $product array

 

php:

$this->context->smarty->assign('product', $product);

 

tpl:

$link->getImageLink( $product.link_rewrite, $product.id_image, 'home_default')
$_link->getImageLink( $product.link_rewrite, $product.id_image, 'large_default')

 

when i try {$product|print_r} the content is product object ( a lot of content so i can't paste here)

Link to comment
Share on other sites

i found the workaround :

 

php:

$images = Image::getImages((int)$id_lang, (int)$product->id);
$id_image = Product::getCover($product->id);
   // get Image by id
   if (sizeof($id_image) > 0)
 {
 $image = new Image($id_image['id_image']);
 // get image full URL
 $image_url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";
 }

   $this->context->smarty->assign('image_url', $image_url);

 

tpl:

 

{$image_url}

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

hey i found this to other forum...

 

 

$id_image = Product::getCover($id_product);

// get Image by id

if (sizeof($id_image) > 0) {

$image = new Image($id_image['id_image']);

// get image full URL

$image_url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";

}

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

hey i found this to other forum...

 

 

$id_image = Product::getCover($id_product);

// get Image by id

if (sizeof($id_image) > 0) {

$image = new Image($id_image['id_image']);

// get image full URL

$image_url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";

}

 

 

Where to get the code and paste these one.

 

Thanks

Link to comment
Share on other sites

i found the workaround :

 

php:

$images = Image::getImages((int)$id_lang, (int)$product->id);
$id_image = Product::getCover($product->id);
// get Image by id
if (sizeof($id_image) > 0)
 {
 $image = new Image($id_image['id_image']);
 // get image full URL
 $image_url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";
 }

$this->context->smarty->assign('image_url', $image_url);

 

tpl:

 

{$image_url}

i found the workaround :

 

php:

$images = Image::getImages((int)$id_lang, (int)$product->id);
$id_image = Product::getCover($product->id);
// get Image by id
if (sizeof($id_image) > 0)
 {
 $image = new Image($id_image['id_image']);
 // get image full URL
 $image_url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath().".jpg";
 }

$this->context->smarty->assign('image_url', $image_url);

 

tpl:

 

{$image_url}

Link to comment
Share on other sites

i solve this by add the image name

$image_url = _PS_BASE_URL_._THEME_PROD_DIR_.$image->getExistingImgPath()."-small_default".".jpg";

 

Where to put this code on what file. Can u tell me the file name. U mean image.php or product.php file or what.

 

Do reply.

 

Thanks

Link to comment
Share on other sites

  • 2 years later...

Hey I want to do there any option in admin panel to add image for bulk uploading, like for CSV file have to enter the image url. But where to add those bulk images???, I don't want to add these images in Cpanel, because the uploading team don't know about the file and if any thing gone wrong my site down. 

If there is any module which give me option like upload the CSV file with images, or any module with bulk image uploading in admin panel???

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 7 months later...
  • 1 month later...

sorry in 1.5.6.2 i use this code section for mailalerts.php

 

$image_url = '';
$image = Product::getCover((int)$product['id_product']);
if (sizeof($image) > 0) 
{
$link_rewrite = '';
$id_image = $product['id_product'].'-'.$image['id_image'];
$image_url = __PS_BASE_URI__."img/p/{$id_image}-small_default.jpg";
$image_url = $context->link->getMediaLink($image_url);
}
 
Now, i use 1.6.1.2
but on mail I have no image. The format is like old version image
 
....img/p/1111-11111-small_default.jpg
 
but now i Use new format image like
 
...img/p/5/0/7/507.jpg
 
 
how can I change code for new image type, thanks.
Link to comment
Share on other sites

  • 6 months later...

 

sorry in 1.5.6.2 i use this code section for mailalerts.php

 

$image_url = '';
$image = Product::getCover((int)$product['id_product']);
if (sizeof($image) > 0) 
{
$link_rewrite = '';
$id_image = $product['id_product'].'-'.$image['id_image'];
$image_url = __PS_BASE_URI__."img/p/{$id_image}-small_default.jpg";
$image_url = $context->link->getMediaLink($image_url);
}
 
Now, i use 1.6.1.2
but on mail I have no image. The format is like old version image
 
....img/p/1111-11111-small_default.jpg
 
but now i Use new format image like
 
...img/p/5/0/7/507.jpg
 
 
how can I change code for new image type, thanks.

 

Did you find a solution? Im stuck trying to get the rest of the URL, only getting this "http://quartoscoimbra.pt/img/p/"

Link to comment
Share on other sites

  • 4 months later...

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