I am using
Magento\Catalog\Model\Product to save products in a loop.
When i have multiple products with the same name
$product->setName($name) i get the following error:
Fatal error: Uncaught PDOException: SQLSTATE: Integrity constraint violation: 1062 Duplicate entry 'test.html-1' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID'
This is because it tries to save an url key based on the set product name. How can I resolve this issue?
- Is it possible to Magento create unique url keys automatically just as if i were to save to product from the admin panel?
- If it's not possible to auto generate it, what would be the best practice to manually do this? Is there a url key generator which I can manually use?