We need to display the product listings based on data from a 3rd party datasource. We have populated a category with all the products (700+). A customer may see a sub section of products i.e. upto 450 products, based on criteria passed to the 3rd party datasource.
We are using the SKU as point of reference in both data sources. We only want to display products that appear in both datasources.
At the momment we are looping through the loadedProductCollection in the catalog/product/list.phtml file to check if the product sku code exists in the other data source if so then display the magento product. This works but the paging is completely wrong.
I need to address this issue, but I don't know magento well enough to undertake such a major change or location of the files necessary to change.
Any help would be very much appreciated.
EDIT
I have extended the Mage_Catalog_Block_Product_List class see below:
class MyCompany_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
Mage::log( "MyCompany_Catalog_Block_Product_List _getProductCollection() called" );
if (is_null($this->_productCollection))
{
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
}
$this->_productCollection = $layer->getProductCollection();
/*
////////////////////////////////////////////////////////////////////////////////////////////////////////
Custom Code starts here
////////////////////////////////////////////////////////////////////////////////////////////////////////
*/
if (Mage::getSingleton('customer/session')->isLoggedIn())
{
$_skuArray = array();
// Call 3rd party datasource to get customer sku codes and store in array
$this->_productCollection->addAttributeToFilter('sku', array('in'=>$_skuArray));
}
/*
////////////////////////////////////////////////////////////////////////////////////////////////////////
Custom Code finishes here
////////////////////////////////////////////////////////////////////////////////////////////////////////
*/
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
}