<p>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.</p>

<p>Do you really need to use the ID in the sku?  </p>

<p>(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).</p>

CC BY-SA 3.0
2016-10-04T09:46:04.793Z
I would have thought it is definitely created too late in the game - you could however listen to [`commerce_products.onSaveProduct`](https://craftcommerce.com/docs/events-reference#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.
Josh Angell
CC BY-SA 3.0
2016-10-24T09:00:04.373Z
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.
Clive Portman
CC BY-SA 3.0
2018-02-02T14:34:26.593Z
Would like to achieve auto-incremenation for variant SKU's also... must be a way to do this?
James Greig
CC BY-SA 3.0
2018-02-02T23:10:28.683Z
Well that's different than using the product ID in there - start a new question with that I'd say.
Jeremy Daalder
CC BY-SA 3.0
2016-10-04T01:16:43.230Z
2016-10-04T01:16:43.230Z
Jeremy Daalder
<p>I can use <code>{product.slug}</code> for generating Auto SKU but does anyone know how to use the Product ID</p>

<p>Using <code>SKU{product.id}</code> 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.</p>

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

<p>I've tried <code>ID</code> and <code>id</code> in both cases.</p>

<p>I'm sure this should work. Any ideas?</p>

<plugin-craftcommerce>
Craft Commerce auto SKU with product ID
# Craft Commerce auto SKU with product ID

(Asked by: username_0 on 2016-10-03)

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?

**Tags:** plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2016-10-04. Score: 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).

> **Comments:**
> **username_2**: I would have thought it is definitely created too late in the game - you could however listen to [`commerce_products.onSaveProduct`](https://craftcommerce.com/docs/events-reference#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.  
> **username_0**: 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.  
> **username_3**: Would like to achieve auto-incremenation for variant SKU's also... must be a way to do this?  
> **username_1**: Well that's different than using the product ID in there - start a new question with that I'd say.  

---

