Mirko
Mirko

Reputation: 41

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'

Upvotes: 0

Views: 2282

Answers (1)

Mirko
Mirko

Reputation: 41

I've read the AdminImportController.php, the solution is simple:

return $object->id;

Upvotes: 2

Related Questions