woocommerce / woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
https://woocommerce.com
9.43k stars 10.77k forks source link

The Product Attribute tab automatically tries to create a new attribute. #38547

Open Babylon1999 opened 1 year ago

Babylon1999 commented 1 year ago

Prerequisites

Describe the bug

Based on the report in zd-6321021

If you try to remove all global attributes from Products > Attributes and then create a new variable product, you'll see a "New Attribute" tab open automatically in the product attribute settings, as if you clicked the "Add" button.

Link to image: https://d.pr/i/dtwNae

When there's at least one global attribute, this doesn't happen.

I'm not sure if this is a bug, it's certainly not breaking any part of the product edit page, I just thought you know about it on the off chance it is a bug so the attribute tab doesn't break silently with a future update.

Expected behavior

/

Actual behavior

/

Steps to reproduce

  1. Go to Products > Attributes and delete all global attributes.
  2. Create a new variable product from Products > Add new

WordPress Environment

/

Isolating the problem

linux4me commented 1 year ago

If there are no global attributes, the New Attribute panel is loaded automagically via line 60 of wp-content/plugins/woocommerce/assets/js/admin/meta-boxes-product.js even if there are local attributes: $( function () { if ( ! woocommerce_admin_meta_boxes.has_local_attributes ) { $( 'button.add_attribute' ).trigger( 'click' ); } } ); It seems the intent is to open the New Attribute panel automatically by triggering the add_attribute click event only if there are no local attributes; however, if there are no global attributes, the click event is triggered even if there are local attributes, in which case the user has to click the "remove" link on the New Attribute panel in order to save changes made to existing local attributes. I believe that is the situation in which a bug exists.

Steps to reproduce the bug:

  1. Delete all global attributes if there are any.
  2. Create a variable product with at least one local attribute.
  3. Click Update to save the product.
  4. Open the Attributes tab.

Expected behavior:

Actual behavior:

druesome commented 1 year ago

Just to add more clarity on the issue. If we try to edit an existing variable product, particularly a locally created attribute of it, we are immediately met with a screen that assumes that we're creating a New attribute, rather than editing one:

image

In our example, we have the Color attribute, for which we have Blue and Red as options. But what if we want to add Green?

image

The button to save it cannot be clicked.

The current workaround is to remove the New attribute screen below it:

image

And that is only when the button can be clicked:

image

This issue does not happen if we have some Global Attributes saved in Products > Attributes. With these present, we are shown a screen that lets us edit the Attributes right away:

image
linux4me commented 1 year ago

This appears to be fixed in WooCommerce 7.8.0.