inventory icon indicating copy to clipboard operation
inventory copied to clipboard

IsEnabledOptionSelectBuilder does not take store value into account

Open aligent-lturner opened this issue 8 months ago • 1 comments

Preconditions (*)

  1. Magento Inventory 1.2.7, 1.2.7-p1

Steps to reproduce (*)

  1. Create a configurable product with colour and size as configurable options.
  2. Create simple variants for colours Red, Purple and Black, sizes XS, S, M, L and XL
  3. Disable all variants with size XS at global level
  4. Enable the same variants at the store level

Expected result (*)

  1. A graphql call returning configurable_options should include XS as a size value
query {
  products(
    search: "teton"
  ){
    items {
      sku
      ... on ConfigurableProduct {
        configurable_options {
          attribute_code
          label
          values {
            label
          }
        }
        variants {
          product {
            sku
          }
        }
      }
    }
  }
}
{
  "data": {
    "products": {
      "items": [
        {
          "sku": "MH02",
          "configurable_options": [
            {
              "attribute_code": "color",
              "label": "Color",
              "values": [
                {
                  "label": "Black"
                },
                {
                  "label": "Purple"
                },
                {
                  "label": "Red"
                }
              ]
            },
            {
              "attribute_code": "size",
              "label": "Size",
              "values": [
                {
                  "label": "XS"
                },
                {
                  "label": "S"
                },
                {
                  "label": "M"
                },
                {
                  "label": "L"
                },
                {
                  "label": "XL"
                }
              ]
            }
          ],
          "variants": [
            {
              "product": {
                "sku": "MH02-XS-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-XS-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-XS-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-S-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-S-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-S-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-M-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-M-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-M-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-L-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-L-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-L-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-XL-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-XL-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-XL-Red"
              }
            }
          ]
        }
      ]
    }

Actual result (*)

  1. XS is not returned as a size value:
{
  "data": {
    "products": {
      "items": [
        {
          "sku": "MH02",
          "configurable_options": [
            {
              "attribute_code": "color",
              "label": "Color",
              "values": [
                {
                  "label": "Black"
                },
                {
                  "label": "Purple"
                },
                {
                  "label": "Red"
                }
              ]
            },
            {
              "attribute_code": "size",
              "label": "Size",
              "values": [
                {
                  "label": "S"
                },
                {
                  "label": "M"
                },
                {
                  "label": "L"
                },
                {
                  "label": "XL"
                }
              ]
            }
          ],
          "variants": [
            {
              "product": {
                "sku": "MH02-XS-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-XS-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-XS-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-S-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-S-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-S-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-M-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-M-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-M-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-L-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-L-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-L-Red"
              }
            },
            {
              "product": {
                "sku": "MH02-XL-Black"
              }
            },
            {
              "product": {
                "sku": "MH02-XL-Purple"
              }
            },
            {
              "product": {
                "sku": "MH02-XL-Red"
              }
            }
          ]
        }
      ]
    }

The cause of the issue is the order variables are passed into the getIfNullSql function here - https://github.com/magento/inventory/blob/a032928522623b6a3df0e0299582667acf785a1a/InventoryConfigurableProduct/Plugin/Model/ResourceModel/Attribute/IsEnabledOptionSelectBuilder.php#L85

The global value is passed first, meaning that the store value is only used if the global value is null (which should never be the case). These should be swapped - the store value should be used, and if it is null, the global value should be used instead.

aligent-lturner avatar Jun 12 '24 07:06 aligent-lturner