magento / inventory

Magento Inventory Project (a.k.a MSI)
Open Software License 3.0
337 stars 248 forks source link

IsEnabledOptionSelectBuilder does not take store value into account #3410

Open aligent-lturner opened 5 months ago

aligent-lturner commented 5 months ago

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.

m2-assistant[bot] commented 5 months ago

Hi @aligent-lturner. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information. Add a comment to assign the issue: @magento I am working on this


Join Magento Community Engineering Slack and ask your questions in #github channel.