Don’t access the magento session object while you’re hooking the controller_front_init_before event, as it’ll be set up incorrectly and give you a cookie error. You probably wanted to hook a pre or post dispatch event instead.
The script mentioned previously is here:
It’ll tell you whether your configurable attributes are set sensibly based on how many values there are. Note it assumes size and color as attributes you care about – you can change that on line 38 if you want.
So I was writing a script to check the integrity of configurable products on a couple of sites – it appeared that the attributes on some products didn’t match the actual set of child products available, so you had weird results like dropdowns with 1 color available.
It worked okay on a site with 250 active configurable products, but ran out of memory quickly on a site with 1000. What was going on?
It turns out that this line:
$attributes = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
consumed 0.5-2MB of memory for each product – what’s happening is that the Configurable type singleton is storing the configurable attribute data on the $product that we pass into that method, in order to reuse it later. If we’re not planning on doing anything else with that product (eg it’s from a collection we’re looping through), this is just wasted.
To remove all the stuff the above method adds to the product,
$product->setData('_cache_instance_used_product_attribute_ids', false); $product->setData('_cache_instance_used_product_attributes', false); $product->setData('_cache_instance_used_attributes', false); $product->setData('_cache_instance_configurable_attributes', false); $product->setData('_cache_instance_product_ids', false); $product->setData('_cache_instance_products', false);
The obligatory first post! It’ll be a mix of:
– software, particularly php, magento, and wordpress
– games in all their variety