Current SKU is just a regular text field which forces a user to add this manually. Not all kinds of online stores are particular about importance of this field. Some of them will be happy if the SKU value were added automatically or were hidden at all. Also, as noted by some of commerce guys the auto SKU might be useful for creating tests. Obviously, the SKU may have a lot of requirements to satisfy all the user needs but at least we have to start from something.

CommentFileSizeAuthor
#4 hide_auto_sku.png170.51 KBdrugan
#4 2829487-4.patch9.08 KBdrugan
#2 2829487-2.patch5.89 KBdrugan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drugan created an issue. See original summary.

drugan’s picture

Status: Active » Needs review
FileSize
5.89 KB

This patch is a part of the more complex feature request and posted here just to start a discussion on the issue.

The solution is based on PHP uniqid() and can be configured for the SKU length and therefore uniqueness. Also, the SKU prefix and suffix might be set up by the widget. All the settings are optional and valid per a variation type. If you'd like to see how it works apply this patch from the PR above. Read more here.

The new PR on this issue.

klagler’s picture

Hi drugan,

I'm building a small marketplace store where the store owners only have 10 to 20 products and don't care about any SKU so this patch would be great for my site.
I tried it with the latest dev version of commerce 2.0 but it doesn't seem to work or rather it is not allowed to left the sku field empty.
It would also be great to allow Token replacement for the prefix and suffix fields.

drugan’s picture

FileSize
9.08 KB
170.51 KB

Actually, this patch is a generic one and has to be implemented by some external code in order to see the effect. For now it is implemented in the #2755529: Product variant bulk creation and the most latest version of the patch for this service will always might be found here.

But, if for some reasons you don't need the service then you could apply the patch posted on the current comment. Just do not forget to revert #2 patch before and flush plugins cache after applying the patch. It is a quick and dirty implementation of the configurable auto SKU widget.

As for the notice that your client does not need SKU at all and wish do not see it all - I am agree with you that this will be quite often required feature and must be available in the drupalcommerce. I know some clients who are totally annoyed by the obligation to add SKUs and call them "stupid" :).

The current patch resolves this issue. Just go to the Commerce Auto SKU widget settings and check Hide SKU checkbox. From now your client will never see it but at the same time have valid SKUs added at the background. Note that in this case the unique Auto SKU setting still must be enabled.

hide auto sku

Also, if you don't want SKUs to be prepopulated automatically or just want prefix or suffix of it or even empty field at all, then go to the widget and make appropriate settings. All the settings are optional.

As for the Token replacement support for the auto SKU - it's a long standing thought and tokens have to be added to the widget as soon as possible.

klagler’s picture

Thank you very much for the new patch, I'm always overwhelmed how helpful the community behind drupal is.

Thats exactly the resolution I was looking for.
I also think it would be important to have this functionality in the final release of commerce.
Store owners of smaller stores want a clean and simple UI for adding products and don't care about an SKU field.

niko-’s picture

Sinan Erdem’s picture

Hello @niko

I tried the version from github. It gives an error, which I already created an issue for. Also I couldnt see any settings for widget under "manage form display" of product variation type.

niko-’s picture

Hi,

Can't understand "Also I couldnt see any settings for widget under "manage form display" which widget ?
Configuration of autosku is under product variation type (seperate tab there) direct link:
admin/commerce/config/product-variation-types/default/auto-sku

Sinan Erdem’s picture

Hi Niko,

I was referring to Drugan's screenshot. SKU prefix etc.

zenimagine’s picture

Can we fill the sku starting with the ID of the shop?
For example for a shop with an ID 8, the sky would be:
8-021
The 8 would be filled automatically and the 021 is filled by the user.

niko-’s picture

Token CommerceAutoSkuGenerator included in module. It works with commerce variation and global tokens.
store_id is not the property\field for product variation.

You could make you project specific CommerceAutoSkuGenerator plugin in this case. See src/Plugin/CommerceAutoSkuGenerator/Token.php as example.

bojanz’s picture

Status: Needs review » Closed (won't fix)

Closing. Let's have a good commerce_autosku contrib for now.