get image on onAfterProductCreate

  • Posts: 120
  • Thank you received: 2
9 years 1 month ago #247593

-- HikaShop version -- : 2.6.3
-- Joomla version -- : 3.x.x

Hi dear
How can get product image on onAfterProductCreate plugin event?
I use this custom method by retun empty

public static function getImage($id){
        $db = JFactory::getDbo();
        $sql = 'SELECT file_path FROM '.hikashop_table('file').' WHERE file_type="product" AND file_ref_id='.$id.' LIMIT 0,1';
        $db->setQuery($sql);
        return $db->loadResult();
         
    }
thank you

Last edit: 9 years 1 month ago by kaya.

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

  • Posts: 26275
  • Thank you received: 4045
  • MODERATOR
9 years 1 month ago #247598

Hi,

During the trigger "onAfterProductCreate", the image are not already saved in the database.
You can perform a "var_dump" of the product $element and see his full content.
And you will find the images under :

$element->images
But, like I just wrote, the images won't be yet in the database, that process will be done just after the trigger.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 120
  • Thank you received: 2
9 years 1 month ago #247629

Thank you
I used var_dump before and see $element->images is only database id.
I need get product image in this trigger. No way do it?

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

  • Posts: 26275
  • Thank you received: 4045
  • MODERATOR
9 years 1 month ago #247632

Hi,

So you can directly get the images details in the hikashop_file table.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 120
  • Thank you received: 2
9 years 1 month ago #247676

when I get directly images details from hikashop_file table return empty
My code

/// $id = $element->product_id;
public static function getImage($id){
        $db = JFactory::getDbo();
        $sql = 'SELECT file_path FROM '.hikashop_table('file').' WHERE file_type="product" AND file_ref_id='.$id.' LIMIT 0,1';
        $db->setQuery($sql);
        return $db->loadResult();
         

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

  • Posts: 26275
  • Thank you received: 4045
  • MODERATOR
9 years 1 month ago #247677

Hi,

file_ref_id is for the product id.
You're dealing directly with the file_id.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum