Reputation: 71
I was looking around and couldn't find a solution.
Usually you'd set the simple product to "not visible individually" and the configurable product "catalog, search".
What I would like to do is the other way around, set the visibility of the simples to "catalog, search" and the configs to "not visible individually". Now here is the catch, when you click on the simple it should take you to the configurable parent, and if possible pre-selected with the options of the simple.
I use Magento 1.8.1
Thanks in advance.
Upvotes: 1
Views: 2836
Reputation: 286
first off all you have to set config visiblity to search or catalog because if you keep the config value to not visible individually than its give 404 error when you redirected to the config product page by clicking on variant product link.
follow the below steps to implement your requirement:
For redirecting to parent product set the parent product link on child product.Use below code in product listing foreach to get parent object and get url from parent object.
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($_product->getId());
$product = Mage::getModel('catalog/product')->load($parentIds[0]);
As we have set the config product visibility to search we need do the change in product listing collection for that rewrite the Mage_Catalog_Block_Product_List block in this block change the below function for show only variant product on listing.
protected function _getProductCollection()
{
parent::_getProductCollection();
$this->_productCollection->addAttributeToFilter('type_id','simple');
return $this->_productCollection;
}
Upvotes: 1