cancel
Showing results for 
Search instead for 
Did you mean: 

Filter cross sell list by product it belongs to

Filter cross sell list by product it belongs to

Hello, 

I have extended the core cross sell functionality in order to add a custom product relation at the cart. I'm trying to output it a little differently, however, as i want to append these products to each product in the cart's table row. This means I need to modify the cart item renderer to output the relevant products (which I've done), but what seems like the tricky part to me is how to only get the cross-sells for the product currently being rendered, rather than all the cross-sells.

So in my custom block, I override the core `_getCollection` method to get my custom relation, but it just gets all cross-sells - how would I best go about getting the products only for the current cart item?

Grateful for any pointers in the right direction (a frontender trying to do some backend work Smiley Happy )

 

protected function _getCollection()
{

    var_dump(Mage::registry(('current_product'))); // is null - was wishful thinking that I could use this
    var_dump($this->getData(''));

    $collection = Mage::getModel('catalog/product_link')
        ->useCustomLinks()
        ->getProductCollection()
        ->setStoreId(Mage::app()->getStore()->getId())
        ->addStoreFilter()
        ->setPageSize(1);

    $this->_addProductAttributesAndPrices($collection);

    Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);

    return $collection;
}