简体   繁体   中英

Get Product ID after add in PHP Prestashop Module

I've writed a function like this:

public function addProduct($data){
    $object = new Product();
    foreach($data as $k=>$v){
        $object->{$k} = $v;
    }
    //$object->updateCategories($data['category'], true);
    if($object->save()){
        return $object->add();
    }else{
        return false;
    }
}

It work fine, but I need to return the Product ID.
I've tried with:

Db::getInstance()->Insert_ID();

But it return '0'

我已经阅读了AdminImportController.php,解决方案很简单:

return $object->id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM