Remove a value from an attribute (as in admin/commerce/product-attributes/manage/size for ex., remove a value there)

Try to edit a product which has a variation containing this attribute, and using this value. (it doesn't matter whether you have taken care of editing the product before to remove the variation with the attribute value to be removed, or not. I tried it both ways)

Get the error above

Comments

jpdaut created an issue. See original summary.

jpdaut’s picture

Title: Fatal error: Call to a member function label() on null in /home/site2/super/web/modules/contrib/commerce/modules/product/src/Form/ProductVariationInlineForm.php on line 72 » Fatal error: Call to a member function label() on null in ProductVariationInlineForm.php on line 72
jpdaut’s picture

Category: Bug report » Support request

Perhaps that was not permitted, what I did, and I'm not using the data model correctly? It's really not clear to me right now. I was just reading this comment in https://www.drupal.org/node/2683605#comment-10946699: "Currently when creating a product type, you select the variation type to use for it. Once created, it is locked forever (or until deleted). If you need a new variation, you are forced to create a new product type to house that variation."

I'm also changing this to Support request as I'm not sure of my claim here.

bojanz’s picture

Title: Fatal error: Call to a member function label() on null in ProductVariationInlineForm.php on line 72 » Attribute values that are in use can be deleted
Category: Support request » Bug report

The bug is that Commerce allowed you to delete an attribute that's in use.
Once an entity is referenced, it mustn't be deleted, because Drupal generally handles that poorly.
We don't have an API for preventing deletions yet.

czigor’s picture

Status: Active » Needs review
StatusFileSize
new719 bytes

Until that happens, here's a patch that gives sites a chance to fix things after removing an attribute in use.

(Coming here from #2826006: Product variation referencing a missing product attribute value..)

pavelculacov’s picture

Tested, worked, thanks

bojanz’s picture

We need to forbid deletion in this case. We also need to make the add to cart form non-crashy, cause this will always be a possibility (if a custom reference field was used, for example).

bojanz’s picture

Title: Attribute values that are in use can be deleted » Forbid deletion of attribute values that are in use
Status: Needs review » Needs work
drugan’s picture

StatusFileSize
new1.78 KB

Encountered this issue today again. Might be this at least temporarily fixed? ..before something will appear on the #2898215: [meta] Handle deletion of Commerce entities that are in use

upchuk’s picture

Status: Needs work » Needs review

The last submitted patch, 5: commerce-2815513-5-removed-attribute.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: 2815513-9.patch, failed testing. View results

bojanz’s picture

We need to decide what the UX is going to be. The exploration in #10 disables the Remove button, but that doesn't tell the user why the button is disabled, or how to resolve it. One option would be to show a message as a validation error when the Remove button is clicked. The other option would be to show a message instead of the Remove button (probably a different, shorter message than the validation error one).

We need to brainstorm both versions of the message.

I'll raise this with others on the team.

tonytheferg’s picture

nevermind.

bamberjp’s picture

StatusFileSize
new3.69 KB

Building on the above idea, patch included (#15) adds a conditionGroup to query a count of product variations referencing the attribute value and caches the result for performance.