2

When I activate Auto Generated SKU's in Craft Commerce, I get the "SKU's cannot be left blank" error when I submit a new product. Isn't it the point to leave them blank so they'll auto generate based on other fields?

2
  • What is your Automatic SKU Format setting set to?
    – Brad Bell
    Oct 18 '17 at 22:10
  • I just kept it simple to see how it worked. {product.slug} Oct 19 '17 at 16:02
1

It's a little awkward, but the documentation has a note about this: https://craftcommerce.com/docs/product-types#automatic-sku-format

If a product does not have a variant, then you'd just use {slug}. If it does have a variant, then you'd use {product.slug}. This should be less awkward in the upcoming Commerce 2 as well.

5
  • Brad, would there be a way to include an asset field to help in the auto-generation of SKUs? I'd like to have a product image filename be the SKU number. I've tried {productImage.filename} and {product.productImage.filename} and came up empty. Oct 27 '17 at 14:15
  • Assets are always in array format. So if you wanted the first Asset, you'd use {productImage[0].filename} or {product.productImage[0].filename} depending on the variant situation.
    – Brad Bell
    Oct 27 '17 at 18:29
  • Worked wonderfully! Except I didn't realize the file extension was included in filename. Any way to avoid the file extension in the SKU? Oct 27 '17 at 20:27
  • I can't get this to work for variants... I have the variant SKU set to {product.slug} and the automatic SKU format for the product type set to the same... but it isn't being translated into anything on the front end. Feb 2 '18 at 13:55
  • Yes just to add that @BradBell's method does not work for variant products. By setting the value to {product.title} the SKU field does not show for any variants, and saving failed because you cant enter a unique SKU. This unfortunately makes commerce near unusable for products with large numbers of variants - you cant expect clients to sit manually entering hundreds of SKU codes that could just auto increment.
    – Sk446
    Jul 7 '20 at 8:59

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.