I'm developing an import products cron. In my code I have:
if ($supplier = Supplier::getIdByName(trim($prodotto['Supplier']['Name']))) {
$product->id_supplier = (int)$supplier;
} else {
$supplier = new Supplier();
$supplier->name = $prodotto['Supplier']['Name'];
$supplier->active = true;
$supplier->add();
$product->id_supplier = (int)$supplier->id;
$supplier->associateTo($product->id_shop_list);
}
The result is:
- product created
- supplier created
- product without supplier
Where am I wrong?
You have to add also a new
ProductSupplier
, after you saved te new product use this snippet of code (obviously, adapt it to your needs :)):