1

I've created a command which saves a number of products using

// \Magento\Catalog\Api\Data\ProductInterface
$product->save()

or

// \Magento\Catalog\Api\ProductRepositoryInterface
$productRespository->save($product)

Is there a way of telling the magento 2 api to only save if the product doesn't exist? I have almost 500,000 products which I don't want to re-import each time.

Just checking this is the correct way to do it too - because its SUPER slow.

0

Try to use this code below:

if (!$productRespository->get($product->getSku())) {
     $productRepository->save($product);
}

This code will check the product which has the SKU. Hope it help!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.