Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DominicWatts/fba5340f46af47aa8fe6379f652879b5 to your computer and use it in GitHub Desktop.
Save DominicWatts/fba5340f46af47aa8fe6379f652879b5 to your computer and use it in GitHub Desktop.
Magento 2 : get configurable linked attributes #magento2

Steps to Determine the Linked Attributes

To identify the attributes linking a configurable product (e.g., product ID 123) to its child products, follow these steps:

Find the Attribute IDs for the Configurable Product:

Query the catalog_product_super_attribute table to get the attribute_id values linked to the configurable product.

SELECT cpsa.attribute_id
FROM catalog_product_super_attribute cpsa
WHERE cpsa.product_id = 123;

Map Attribute IDs to Attribute Codes:

Use the attribute_id values obtained in the previous step to find their corresponding attribute_code from the eav_attribute table.

SELECT ea.attribute_id, ea.attribute_code, ea.frontend_label
FROM eav_attribute ea
WHERE ea.attribute_id IN (
    SELECT cpsa.attribute_id
    FROM catalog_product_super_attribute cpsa
    WHERE cpsa.product_id = 123
);

This will give you the attribute codes and possibly the frontend labels for the attributes used by the configurable product.

(Optional) Retrieve Custom Labels:

If custom labels are defined for these attributes, fetch them from catalog_product_super_attribute_label.

SELECT cpsal.product_super_attribute_id, cpsal.use_default, cpsal.value
FROM catalog_product_super_attribute_label cpsal
WHERE cpsal.product_super_attribute_id IN (
    SELECT cpsa.product_super_attribute_id
    FROM catalog_product_super_attribute cpsa
    WHERE cpsa.product_id = 123
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment