I want to display in the related products items from the same brand in order from the latest added. I was looking for an extension that can do it and didn't find it. So I figured out that the solution for me would be to edit an already existing extension. I found this 'iWeb Auto Related Products' and installed it. It automatically creates 5 random products from the same category. I'm not good with php so here's the main question do I just need to change all 'category' to 'brand' in the code below or what changes should I do?
public function getRelatedProducts($limit = false) {
$products = $this->getData('related_products');
if (!$products) {
$product = Mage::registry('current_product');
if ($category = Mage::registry('current_category')) {
} elseif ($product) {
$ids = $product->getCategoryIds();
if (!empty($ids)) {
$category = Mage::getModel('catalog/category')->load($ids[0]);
}
}
if ($category) {
if ($limit === false) {
$limit = Mage::getStoreConfig('autorelated/general/limit');
}
$products = Mage::getResourceModel('reports/product_collection')
->addAttributeToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
))
->addAttributeToFilter('status', 1)
->addCategoryFilter($category)
->addAttributeToSelect('*')
->setPageSize($limit);
if ($product) {
$products->addAttributeToFilter('entity_id', array(
'neq' => Mage::registry('current_product')->getId())
);
}
$products->getSelect()->order(new Zend_Db_Expr('RAND()'));
Mage::getModel('cataloginventory/stock')->addInStockFilterToCollection($products);
$this->setData('related_products', $products);
} else {
return false;
}
}
return $products;
}
If you have a different idea how to make it happen please let me know
thank you