1

I can use {product.slug} for generating Auto SKU but does anyone know how to use the Product ID

Using SKU{product.id} the create product form won't submit because no SKU is generated. I think it might be because there's an error there but I can't see anything in the logs.

Using just SKU{id} allows the form to submit but the result is just "SKU", so it isn't fetching the product id.

I've tried ID and id in both cases.

I'm sure this should work. Any ideas?

1

I'm going to guess that the id for the new product entry doesn't yet exist when the sku is being generated....it's probably created at the end of the save process once Craft is sure the save will complete.

Do you really need to use the ID in the sku?

(I don't immediately see an obvious in built way around it either, but perhaps someone cleverer than me will come along with a good idea).

4
  • I would have thought it is definitely created too late in the game - you could however listen to commerce_products.onSaveProduct, check if its new and then re-save it with a modified SKU that uses the id. Bit of a round trip but it would work. Oct 4 '16 at 9:46
  • 1
    What I'm after really is some auto-incrementation of the SKUs, and I figured the product ID would be the simplest way of doing that without buidling something new. It looks like that's no going to be the case. Thanks Jeremy and Josh. Oct 24 '16 at 9:00
  • Would like to achieve auto-incremenation for variant SKU's also... must be a way to do this? Feb 2 '18 at 14:34
  • Well that's different than using the product ID in there - start a new question with that I'd say. Feb 2 '18 at 23:10

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.