the usual procedure to create a new product via code is to call the product factory, set the new data, then save using the repository:

$data = [
 'id' =>  $id,
 'sku' => $sku,
 'type' => \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE,
 ... // a bunch of other product data
$product = $this->productInterfaceFactory->create();
$product = $this->productRepositoryInterface->save($product);

This code works but the $data['id'] that I pass is overridden and magento sets its own. Is there a way to save the product with the id that I pass?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.