3

I have to modify the catalog search to only show the configurable parent product of a simple product in the search result.

It should work like this:

  • Simple Product SKU: 123.123
  • Configurable Product SKU: 123.100-X
  • Search "123.123"

Result: Product 123.100-X is displayed.

I'm pretty sure I have to override the function: prepareProductCollection in app/code/core/Mage/CatalogSearch/Model/Layer.php

But I'm stuck with this.

As a second step, I want to preselect the configurable options of the showed configurable product based on the searched simple product, if only one exact result is returned.

For this I would redirect to the product view page like described in this thread: Catalog Search: If only one result, show product view page insted of list view

And use this function to get the attribute value to select:

private function getProductUrlWithAttributes($product, $storeId) {

$url = $product->setStoreId($storeId)->getProductUrl();
$urlHash = array();
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());

if(isset($parentIds[0])) {

  $parent = Mage::getModel('catalog/product')->load($parentIds[0]);
  $url = $parent->setStoreId($storeId)->getProductUrl();
  $attrs = $parent->getTypeInstance(true)->getConfigurableAttributes($parent);

  foreach ($attrs as $attribute) {
    $productAttribute   = $attribute->getProductAttribute();
    $productAttributeId = $productAttribute->getId();

    if($attributeValue = $product->getData($productAttribute->getAttributeCode())) {
      $urlHash[$productAttributeId] = $attributeValue;
    }
  }
} 

if(count($urlHash) > 0) {
  $url .= '#'.http_build_query($urlHash, null, ',');
}

return substr($url, 0, 2000);
}

(Source: http://www.snip2code.com/Snippet/171609/gets-a-Magento-parent-product-url-with-h)

I would really appreciate any help, I don't know how to continue with this.

3

Can I suggest not touching the code to get this functionality? Perhaps you could do the following:

First up:
1. Change all simple product visibility to "Catalog" or "Not visible individually"
2. Make sure all the configurable products' visibility is set to "Catalog/Search" or "Search"

Option 1
Create a product attribute called "child_skus", make it used for quick search and add a comma separated list of the child SKUs.

Option 2
Add the child skus to the configurable product's meta keywords. Make sure the meta_keywords attribute is included in the quick search

|improve this answer|||||
  • I also thought about a way like this. But it would be necessary, that adding the child SKUs would be made automatically. Because we are talking about 1000 configurable with each 36 correponding simple products. Do you know a way how to this automatically? – Marco Feb 2 '15 at 14:56
  • 1
    You could write an event observer that listens for the catalog_product_save_before event and loops through the associated products and adds their SKUs to an attribute. – jharrison.au Feb 2 '15 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.