I have configurable products in my system consisting of color and size. I've written the following code to get the data but it is far too slow. Before adding this bit of code the page load time is below 2 seconds and after adding it jumps to 15 seconds. Surely there is faster way to get this information (I have 2 super attributes with about 10 options each)
My code:
$productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
foreach ($productAttribute['values'] as $attribute) {
$attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
}
}
The operation getConfigurableAttributesAsArray is very slow. This is because it performs a load on the attribute collection.
Best way to fix this is using a custom query which only fetches the data you need. Something like this:
This will fetch all attribute codes. You can change the query so that will fetch the data you need.