0

We have a mass import &update module installed in our magento 1.9.3.10, but the products in the import feed do not have skus. Therefore we need a php script to enable us to generate sku when importing the new products from the feed (the module has a text box for php script as part pf the mapping)

Thanks in advance

2 Answers 2

1

As you didn't provide either your module code or the code that you've tried to generate the sku, i can provide you with a few ways how you could generate a SKU for the new products that you import through your Mass product Update Module.

  1. Create a custom module and observe either of these events

catalog_product_save_before or catalog_product_attribute_update_before

there are also other events like, which you can try and use the one suits your requirements.

catalog_product_save_after

catalog_product_save_commit_after

catalog_product_attribute_update_after
  1. Get the product(s) data from the Event Observer Model that you should create

  2. Check whether its a new product

  3. In case of new products, generate a SKU and then set the SKU and save the product.

Hope this helps !

Also read these Magento SE threads below to get the proper understanding of these events and Magento ORM

How can I differentiate between product creation and saving existing products?

https://magento.stackexchange.com/questions/120004/difference-between-catalog-product-save-after-and-catalog-product-save-commit-af

How prevent a model data save using _save_before event

Will $product->save() trigger catalog_product_save_after?

catalog_product_save_after Event for Massaction


BTW if you want to get help from others on this platform, you need to provide the code that you've tried.

0

I am not sure whether you are asking how can you add the SKU after importing the products without the SKU, in which case check Haijerome's answer + if you choose to go with the observers approach, be careful which scope are you using for your observer and validations regarding the context of this mechanism so that you grant regular admins to add products and add SKUs at will and not overwrite them.

Or if you are asking for a PHP code snippet that will allow you to create unique SKUs for your products while importing the products, in which case, I suggest you analyze the business needs as later on, these SKUs will be used as reference whenever you talk about a product, or a client or system asks for details; therefore you might want SKUs format which are specific to the business and not some random strings of chars and/ or numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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