0

I've been trying to something for days and stuck! Need help. I'm trying to manipulate the getloadedproductcollection() method called in list.phtml file in catalog/product. I want to remove the duplicate entries of a product(by name). I tried to apply filters in phtml files but with no success. When looked in the list.php file, couldn't get anything to achieve what I want. Is there any possible way to apply that filter to the product collection on category pages. I tried getSelect()->group('name') as it was mentioned on a question in stackoverflow, but it generated error. Can't do distinct() as it is having no effect. Also tried removeItemByKey(&key) inside foreach loop, it again generated error. Can anyone redirect me to right direction, as it strongly feel, it should be possible in an environment like magento.

P.S.: don't want to delete duplicate products from backend as they are necessity.

Reason for duplicate products: I'm having variations of products in weight, volume, or other units, which can't be managed with configurable products, as there is no rule for defining these values in advance, they may be ranging from 1kg to 100kg for example. Therefore, I created an attribute for their respective units and products having same name are differentiated using their respective units. That's why I'm having duplicate entries.

2
  • This seems like a bad idea to me - maybe if you explain why there are duplicate products in there I might be able to help you with a neater solution? Commented Feb 27, 2014 at 22:28
  • @jharrison.au, I updated my question to explain, why I'm having duplicate products in it, please have a look.
    – Prateek
    Commented Feb 28, 2014 at 7:59

2 Answers 2

1

Try this :

    $alias     = 'name_table';
    $attribute = Mage::getSingleton('eav/config')
        ->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'name');

    /** Adding eav attribute value */
    $collection->getSelect()->join(
        array($alias => $attribute->getBackendTable()),
        "e.entity_id = $alias.entity_id AND $alias.attribute_id={$attribute->getId()}",
        array('name' => 'value')
    );
    $collection->getSelect()->group('name_table.value');

The second problem is that in template collection is already loaded and changing select will not help.

But you can do that in Mage_Catalog_Block_Product_List::_getProductCollection() method.

Hope it will help.

3
  • Already tried that, and magento was crashed! anything else possible?
    – Prateek
    Commented Jan 28, 2014 at 12:44
  • a:5:{i:0;s:84:"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.name' in 'group statement'";i:1;s:5045:"#0 /lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array) and this is the first line of error report if it could help you further. Thanks
    – Prateek
    Commented Jan 28, 2014 at 13:00
  • I updated the answer please take a look. Commented Jan 28, 2014 at 14:32
0

I really think the problem lies in your product structure. Here are some options for dealing with your situation of product variations:

  • Consider only setting a single variation of a product to 'visible in catalog' and the others to 'not visible individually' (or search only)
  • Only include one variation in the category
  • Create a grouped product to house all the variations
  • Create a virtual product with each variation as a related item.

Keep in mind with grouped products or virtual products you can use custom design themes to display the products any way you want and you retain the flexibility you need. You might want to:

  • Display Grouped products in a way other than the default list
  • Remove add to cart and qty fields for the virtual product

I know your requirements are probably a lot more complicated that what I've assumed but I hope this helps give you a few other options.

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.