This is a pretty important UX problem, as I've found that users entering products want to be able to see the existing product with the same SKU in case they have to fix the problem over there.

Adding a link to the message would be a nice thing to do, but not as simple as it sounds, as the actual checking is wrapped up in a helper function which just returns TRUE or FALSE.

    // Ensure the proposed SKU is unique.
    if (!commerce_product_validate_sku_unique($sku, $product->product_id)) {
      form_set_error('sku', t('This SKU is already in use and must be unique. Please supply another value.'));

Hence where the message is produced we don't have the ID of the existing product.

commerce_product_validate_sku_unique() is only used here, but it's not marked as private so we can't really change it.

I would suggest we use commerce_product_load_by_sku() for the validation instead (and the check becomes if ($product_existing = commerce_product_load_by_sku()), and leave commerce_product_validate_sku_unique() in case contrib modules are making use of it.

Does this sound ok to the maintainers?

#2 1791276.commerce.sku-in-use-ui-link.patch1.56 KBjoachim
PASSED: [[SimpleTest]]: [MySQL] 3,589 pass(es).
[ View ]


Title:"This SKU is already in use and must be unique" message should link to the existing productLink the "This SKU is already in use and must be unique" validation message to the existing product
Category:bug» feature

That sounds fine to me; I'd consider it a feature request, but I'm happy to add it in a minor release, as the validation functionality is the same. Not sure why we didn't just use that function to begin with, but I guess maybe commerce_product_load_by_sku() didn't exist yet. : ?

You have time to take care of it?

Status:Active» Needs review
new1.56 KB
PASSED: [[SimpleTest]]: [MySQL] 3,589 pass(es).
[ View ]


(I'd filed it as a bug because it's causing my users to have to go round the houses when they hit this, because they're using numeric SKUs and they have to figure out whether it's the new product or the existing one that's 'wrong'.)

Here's the patch. I've added a note to commerce_product_validate_sku_unique() explainining why it's still there, to prevent future head-scratching :)

Status:Needs review» Fixed

Easy enough. Committed. : )

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.