Question

i'm working on a website which doesn't need product sku. Is it possible to set the sku=product_id whenever a new product is created? Any side effect doing that?

thanks

Was it helpful?

Solution

It's possible but you have to take some things into account. I did something similar in my AutoSKU extension which automatically creates SKUs similar to order numbers. Probably this extension already solves your problem but I will explain the important parts:

  • set the SKU attribute to "not required" so that you can leave it empty
  • change the backend model of the SKU attribute to set a value in its _beforeSave() method if the value is not set yet.
  • if you use product import, you cannot leave the SKU blank, otherwise your import data is considered invalid and cannot be parsed. This is at least true for the Magento core import (Mage_ImportExport), any import that is based on this (like AvS_FastSimpleImport) and the Magmi importer. In the AutoSKU extension I solved this with a prefix for temporary SKUs, so you can import products as "tmp1", "tmp2", ... and after import those can be converted automatically.

Disadvantage of your approach, using the product id, is that you will have to use _afterSave() for new products and then save a second time because you don't know the ID beforehand. In the AutoSKU extension, I choose the increment backend model to generate SKUs, so this was not a problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top