Skip to content

Instantly share code, notes, and snippets.

@AndresInSpace
Last active September 26, 2017 14:09
Show Gist options
  • Save AndresInSpace/631cd6d6419c1c1b63390eedcbbc6b88 to your computer and use it in GitHub Desktop.
Save AndresInSpace/631cd6d6419c1c1b63390eedcbbc6b88 to your computer and use it in GitHub Desktop.
Fix getCrossSellProductCollection() to stop returning ENTIRE product catalog collection in object data..
<?php $plcsCol = Mage::getModel('catalog/product_link')->getCollection()->addFieldToFilter('link_type_id',Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL)->addFieldToFilter('product_id',$_product->getId())->getData();//get crosssell product IDs attached to parent product ?>
<?php $csIDs = array_column($plcsCol,'linked_product_id');//map cs IDs to array, use array to filter collection by IDs ?>
<?php $_crossSellProducts = $_product->getCrossSellProductCollection()->addAttributeToFilter('entity_id', array('in'=>$csIDs))->addAttributeToSelect('*'); //ensures our crosssell collection is limited to ONLY attached crossells of parent.. calling getCrossSellProductCollection without filtering seems to return the ENTIRE product catalog collection..
//replace addAttributeToSelect('*') with whatever fields you need from product flat catalog..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment