2

I am trying to get loaded product attributes from Layered navigation into listing page.

The below code is working fine if I print $grid_labels[]

When I am applying/selecting layered navigation filter, i am getting the following error :

You cannot define a correlation name 'manufacturer_idx' more than once

I am unable to identify why the block/attributes are loading twice.

$block = $this->getLayout()->createBlock('Catalog/Layer_View');
$_filters = $block->getFilters();
$grid_label = array();
$grid_attribute_code = array();
//echo "<pre>";
foreach ($_filters as $_filter) {
    if ($count = $_filter->getItemsCount()) {
        $attr = Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToFilter('frontend_label', $_filter->getName());
        $attcodeobj = $attr->getData();
        $attrcode = $attcodeobj[0]['attribute_code'];
        if($attrcode!=''):
        $grid_label[] = array($attrcode => $_filter->getName());
endif;
        //$grid_attribute_code[] = $_filter->getLabel();
    }
}

Can any one help me out on this issue ?

4
  • Paste your layout xml.
    – Nidheesh
    Commented Oct 4, 2016 at 5:52
  • @Nidheesh I did not override any layout file. i am in product list.phtml by theme and trying to create $block = $this->getLayout()->createBlock('Catalog/Layer_View'); Commented Oct 4, 2016 at 6:07
  • What happens if you use $block = $this->getLayout()->getBlock('catalog.leftnav'); instead of createBlock()? Commented Oct 4, 2016 at 6:45
  • Why you want to create the catalog/layer_view block in listing page?
    – Nidheesh
    Commented Oct 4, 2016 at 9:09

1 Answer 1

3
+50

Well the You cannot define a correlation name 'attribute_idx' more than once error is a well known issue.

It is caused by the fact that the catalog/layer_view block is called twice.

So depending on what you want to achieve you can either:

Remove the original Magento left layered navigation

By adding the following to your local.xml

<remove name="catalog.leftnav" />

Use the original Magento left layered navigation

Instead of creating the block so you'll have to replace:

$block = $this->getLayout()->createBlock('catalog/layer_view'); 

With:

$block = $this->getLayout()->getBlock('catalog.leftnav');
3
  • 1
    Thanks, perfect. It is working fine, but I need to call same block in Controller to filter from Ajax request. i have tried but not working. please tell me how can i call. Commented Oct 5, 2016 at 18:05
  • @krishnaijjadaati95Dev hard to do that in the comments feel free to create a new question I'll check it out Commented Oct 5, 2016 at 18:17
  • Sure , please check magento.stackexchange.com/questions/139552/… Commented Oct 5, 2016 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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