Skip to content

Instantly share code, notes, and snippets.

@nympheastudio
Created October 12, 2022 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nympheastudio/1ae85e4821c593a16cfacc2344ba6a54 to your computer and use it in GitHub Desktop.
Save nympheastudio/1ae85e4821c593a16cfacc2344ba6a54 to your computer and use it in GitHub Desktop.
prestashop get image url or productName url by id product
public function getImgId(){
$id = Tools::getValue('id');
$action = Tools::getValue('action');
if($action=='getImgId'){
$id_product = $id; // set your product ID here
$image = Image::getCover($id_product);
$product = new Product($id_product, false, Context::getContext()->language->id);
$link = new Link; // because getImageLink is not static function
$imagePath = $link->getImageLink($product->link_rewrite, $image['id_image'], 'home_default');
echo 'https://'.$imagePath;
exit;
}
}
public function getProductName(){
$id = Tools::getValue('id');
$action = Tools::getValue('action');
if($action=='getProductName'){
$id_product = $id; // set your product ID here
$product = new Product($id_product, false, Context::getContext()->language->id);
echo $product->name;
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment