i'm a newbie to magento, default using $this->getItemCollection()->getItems()
(upsell.phtml) displaying all up selling products.
I'm wondering how to group these results by its category.
Example, i have 4 up sell products,
3 Products from category A,
1 Product from category B
On view i need to display like this,
Category A,
Product 1 | product 2 | Product 3
Category B,
Product 4
So far created a module, it's structure below,
local
Fugen
Accessories
etc
config.php
Model
Observer.php
My module's config.xml
<?xml version="1.0"?>
<config>
<modules>
<Fugen_Accessories>
<version>1.0</version>
</Fugen_Accessories>
</modules>
<frontend>
<events>
<catalog_product_upsell>
<observers>
<Fugen_Accessories>
<class>Fugen_Accessories/observer</class>
<method>updateUpsells</method>
</Fugen_Accessories>
</observers>
</catalog_product_upsell>
</events>
</frontend>
</config>
My Observer.php
class Fugen_Accessories
{
public function __construct()
{
// leave empty
}
public function updateUpsells(Varien_Event_Observer $oObserver)
{
$iCurrentCategory = Mage::registry('current_category')->getId();
$oUpsellCollection = $oObserver->getCollection();
foreach ($oUpsellCollection->getItems() as $key => $oUpsellProduct) {
$aCategoriesIds = $oUpsellProduct->getCategoryIds();
if (!in_array($iCurrentCategory, $aCategoriesIds)) {
$oUpsellCollection->removeItemByKey($key);
}
}
}
}