Fonction getThumbnail depuis module externe

  • Posts: 406
  • Thank you received: 27
  • Hikamarket Multivendor Hikashop Business
1 year 11 months ago #341710

Bonjour,

j'ai créé un module de recherche ajax qui affiche les produits avec les images. Pour une optimisation du module, il me faut afficher des miniatures, je tente donc d'utiliser la fonction getThumbnail depuis mon module, mais lors du var_dump($imageHelper) je m'aperçois que uploadFolder_url est faussé, au lieu d'avoir la valeur "/images/com_hikashop/upload/", il a la valeur "/modules/mod_hika_search/images/com_hikashop/upload/"

Comment puis-je utiliser cette fonction depuis un fichier externe svp ? (tout le reste de mon code fonctionne bien)

if(!@include_once(JPATH_BASE.'administrator/components/com_hikashop/helpers/helper.php')){ var_dump('fail'); return false; }
$HimageHelper	= hikashop_get('helper.image');
$Hconfig		= hikashop_config();
$image_options	= array('default' => true,'forcesize'=>$Hconfig->get('image_force_size',true),'scale'=>$Hconfig->get('image_scale_mode','inside'));
$img = $HimageHelper->getThumbnail($product_img->file_path, array('width' => 50, 'height' => 50), $image_options, JPATH_BASE);

Dans mon code on peut voir que j'ai tenté d'ajouter le paramètre relativePath, ce qui m'a value un true pour la clé success du retour en var_dump($img) au lieu de false (un petit plus)

voici mes retours de var_dump($HimageHelper);
object(hikashopImageHelper)#441 (11) {
  ["thumbnail"]=>
  int(1)
  ["uploadFolder_url"]=>
  string(52) "/modules/mod_hika_search/images/com_hikashop/upload/"
  ["uploadFolder"]=>
  string(34) "../..//images/com_hikashop/upload/"
  ["thumbnail_x"]=>
  int(250)
  ["thumbnail_y"]=>
  int(250)
  ["main_uploadFolder_url"]=>
  string(52) "/modules/mod_hika_search/images/com_hikashop/upload/"
  ["main_uploadFolder"]=>
  string(34) "../..//images/com_hikashop/upload/"
  ["main_thumbnail_x"]=>
  int(250)
  ["main_thumbnail_y"]=>
  int(250)
  ["override"]=>
  bool(false)
  ["image_mode":protected]=>
  string(2) "GD"
}

et de var_dump($img);
object(stdClass)#453 (15) {
  ["success"]=>
  bool(true)
  ["external"]=>
  bool(false)
  ["path"]=>
  string(31) "thumbnails/50x50fsO/barcode.png"
  ["height"]=>
  int(50)
  ["width"]=>
  int(50)
  ["req_height"]=>
  int(50)
  ["req_width"]=>
  int(50)
  ["url"]=>
  string(83) "/modules/mod_hika_search/images/com_hikashop/upload/thumbnails/50x50fsO/barcode.png"
  ["origin_url"]=>
  string(62) "/modules/mod_hika_search/media/com_hikashop/images/barcode.png"
  ["default_image"]=>
  bool(true)
  ["ext"]=>
  string(3) "png"
  ["orig_height"]=>
  int(100)
  ["orig_width"]=>
  int(100)
  ["filename"]=>
  string(11) "barcode.png"
  ["webpurl"]=>
  string(84) "/modules/mod_hika_search/images/com_hikashop/upload/thumbnails/50x50fsO/barcode.webp"
}

Merci d'avance, je tourne en rond

Last edit: 1 year 11 months ago by Minie.

Please Log in or Create an account to join the conversation.

  • Posts: 81566
  • Thank you received: 13075
  • MODERATOR
1 year 11 months ago #341712

Bonjour,

Vous pouvez faire comme ceci:

if(!@include_once(JPATH_BASE.'administrator/components/com_hikashop/helpers/helper.php')){ var_dump('fail'); return false; }
$HimageHelper	= hikashop_get('helper.image');
$Hconfig		= hikashop_config();
$HimageHelper->main_uploadFolder = '/images/com_hikashop/upload/';
$HimageHelper->main_uploadFolder_url = '/images/com_hikashop/upload/';
$HimageHelper->uploadFolder = '/images/com_hikashop/upload/';
$HimageHelper->uploadFolder_url = '/images/com_hikashop/upload/';
$image_options	= array('default' => true,'forcesize'=>$Hconfig->get('image_force_size',true),'scale'=>$Hconfig->get('image_scale_mode','inside'));
$img = $HimageHelper->getThumbnail($product_img->file_path, array('width' => 50, 'height' => 50), $image_options);
That way, you override the folders there before calling getThumbnail()

Please Log in or Create an account to join the conversation.

  • Posts: 406
  • Thank you received: 27
  • Hikamarket Multivendor Hikashop Business
1 year 11 months ago #341729

Bonjour,

merci beaucoup pour votre réponse rapide, j'ai donc effectué les modifications, bon à savoir pour l'overide des classes :)

Par contre j'ai toujours le barecode en résultat :'(

Voici le résultat du var_dump($HimageHelper), cette fois il est ok

object(hikashopImageHelper)#441 (11) {
  ["thumbnail"]=>
  int(1)
  ["uploadFolder_url"]=>
  string(28) "/images/com_hikashop/upload/"
  ["uploadFolder"]=>
  string(28) "/images/com_hikashop/upload/"
  ["thumbnail_x"]=>
  int(250)
  ["thumbnail_y"]=>
  int(250)
  ["main_uploadFolder_url"]=>
  string(28) "/images/com_hikashop/upload/"
  ["main_uploadFolder"]=>
  string(28) "/images/com_hikashop/upload/"
  ["main_thumbnail_x"]=>
  int(250)
  ["main_thumbnail_y"]=>
  int(250)
  ["override"]=>
  bool(false)
  ["image_mode":protected]=>
  string(2) "GD"
}

Le résultat du $product_img->file_path, est ok aussi
string(37) "8-vase-deco-facette-aspect-argent.jpg"
Je précise que l'image est bien à sa place sur le serveur : thival.gixia.fr/images/com_hikashop/upload/8-vase-deco-facette-aspect-argent.jpg

Et pourtant, le résultat du var_dump($img) n'est pas ok
object(stdClass)#453 (12) {
  ["success"]=>
  bool(false)
  ["external"]=>
  bool(false)
  ["path"]=>
  string(11) "barcode.png"
  ["height"]=>
  int(0)
  ["width"]=>
  int(0)
  ["req_height"]=>
  int(50)
  ["req_width"]=>
  int(50)
  ["origin_url"]=>
  string(62) "/modules/mod_hika_search/media/com_hikashop/images/barcode.png"
  ["default_image"]=>
  bool(true)
  ["ext"]=>
  string(3) "png"
  ["orig_height"]=>
  int(100)
  ["orig_width"]=>
  int(100)
}

Je ne comprends pas, tout parait pourtant ok, sauf le résultat

Please Log in or Create an account to join the conversation.

  • Posts: 81566
  • Thank you received: 13075
  • MODERATOR
1 year 11 months ago #341731

Bonour,

Essayez comme cela alors:

if(!@include_once(JPATH_BASE.'administrator/components/com_hikashop/helpers/helper.php')){ var_dump('fail'); return false; }
$HimageHelper	= hikashop_get('helper.image');
$Hconfig		= hikashop_config();
$HimageHelper->main_uploadFolder =JPATH_ROOT. '/images/com_hikashop/upload/';
$HimageHelper->main_uploadFolder_url = '/images/com_hikashop/upload/';
$HimageHelper->uploadFolder = JPATH_ROOT. '/images/com_hikashop/upload/';
$HimageHelper->uploadFolder_url = '/images/com_hikashop/upload/';
$image_options	= array('default' => true,'forcesize'=>$Hconfig->get('image_force_size',true),'scale'=>$Hconfig->get('image_scale_mode','inside'));
$img = $HimageHelper->getThumbnail($product_img->file_path, array('width' => 50, 'height' => 50), $image_options);

Please Log in or Create an account to join the conversation.

  • Posts: 406
  • Thank you received: 27
  • Hikamarket Multivendor Hikashop Business
1 year 11 months ago #341760

Bonjour,

merci pour votre réponse, voici le résultat des 3 var_dump dans le même ordre (HimageHelper / file_path / $img)

object(hikashopImageHelper)#440 (11) {
  ["thumbnail"]=>
  int(1)
  ["uploadFolder_url"]=>
  string(28) "/images/com_hikashop/upload/"
  ["uploadFolder"]=>
  string(34) "../..//images/com_hikashop/upload/"
  ["thumbnail_x"]=>
  int(250)
  ["thumbnail_y"]=>
  int(250)
  ["main_uploadFolder_url"]=>
  string(28) "/images/com_hikashop/upload/"
  ["main_uploadFolder"]=>
  string(34) "../..//images/com_hikashop/upload/"
  ["main_thumbnail_x"]=>
  int(250)
  ["main_thumbnail_y"]=>
  int(250)
  ["override"]=>
  bool(false)
  ["image_mode":protected]=>
  string(2) "GD"
}
string(37) "8-vase-deco-facette-aspect-argent.jpg"
object(stdClass)#452 (7) {
  ["success"]=>
  bool(false)
  ["external"]=>
  bool(false)
  ["path"]=>
  string(37) "8-vase-deco-facette-aspect-argent.jpg"
  ["height"]=>
  int(0)
  ["width"]=>
  int(0)
  ["req_height"]=>
  int(0)
  ["req_width"]=>
  int(0)
}

Le même code essayé dans la vue listing fonctionne très bien :(

Ci dessous le var_dump de HimageHelper dans la vue listing
object(hikashopImageHelper)#1384 (11) {
  ["thumbnail"]=>
  int(1)
  ["uploadFolder_url"]=>
  string(28) "/images/com_hikashop/upload/"
  ["uploadFolder"]=>
  string(68) "/var/www/vhosts/gixia.fr/thival.gixia.fr/images/com_hikashop/upload/"
  ["thumbnail_x"]=>
  int(250)
  ["thumbnail_y"]=>
  int(250)
  ["main_uploadFolder_url"]=>
  string(28) "/images/com_hikashop/upload/"
  ["main_uploadFolder"]=>
  string(68) "/var/www/vhosts/gixia.fr/thival.gixia.fr/images/com_hikashop/upload/"
  ["main_thumbnail_x"]=>
  int(250)
  ["main_thumbnail_y"]=>
  int(250)
  ["override"]=>
  bool(false)
  ["image_mode":protected]=>
  string(2) "GD"
}

même en mettant "/var/www/vhosts/gixia.fr/thival.gixia.fr/images/com_hikashop/upload/" à l'arrache comme ceci (ci dessous) la réponse du var_dump($img) est la même, pourtant les var_dump($HimageHelper) sont identiques
$HimageHelper->main_uploadFolder	= '/thival.gixia.fr/images/com_hikashop/upload/';
$HimageHelper->main_uploadFolder_url	= '/images/com_hikashop/upload/';
$HimageHelper->uploadFolder		= '/thival.gixia.fr/images/com_hikashop/upload/';
$HimageHelper->uploadFolder_url		= '/images/com_hikashop/upload/';

Last edit: 1 year 11 months ago by Minie.

Please Log in or Create an account to join the conversation.

  • Posts: 406
  • Thank you received: 27
  • Hikamarket Multivendor Hikashop Business
1 year 11 months ago #341766

Je ne vais pas vus embêter plus que ca, j'aurais aimé faire propre, mais je crois que je vais faire une fonction getThumbnail dans le helper de mon module et puis voilà

Please Log in or Create an account to join the conversation.

  • Posts: 81566
  • Thank you received: 13075
  • MODERATOR
1 year 11 months ago #341761

Bonjour,

Il vous manque "/var/www/vhosts".
Mettez directement le dossier complet alors et cela fonctionnera:

if(!@include_once(JPATH_BASE.'administrator/components/com_hikashop/helpers/helper.php')){ var_dump('fail'); return false; }
$HimageHelper	= hikashop_get('helper.image');
$Hconfig		= hikashop_config();
$HimageHelper->main_uploadFolder ='/var/www/vhosts/gixia.fr/thival.gixia.fr/images/com_hikashop/upload/';
$HimageHelper->main_uploadFolder_url = '/images/com_hikashop/upload/';
$HimageHelper->uploadFolder = '/var/www/vhosts/gixia.fr/thival.gixia.fr/images/com_hikashop/upload/';
$HimageHelper->uploadFolder_url = '/images/com_hikashop/upload/';
$image_options	= array('default' => true,'forcesize'=>$Hconfig->get('image_force_size',true),'scale'=>$Hconfig->get('image_scale_mode','inside'));
$img = $HimageHelper->getThumbnail($product_img->file_path, array('width' => 50, 'height' => 50), $image_options);

Last edit: 1 year 11 months ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 406
  • Thank you received: 27
  • Hikamarket Multivendor Hikashop Business
1 year 11 months ago #341770

oui pardon j'avais testé autre chose avant de copier mon code, je pensais être revenue à cette version avant de copier coller pour le post, mais le résultat était le même :'(

Please Log in or Create an account to join the conversation.

Time to create page: 0.073 seconds
Powered by Kunena Forum