I have created a event observer module that will trigger and remove any product that is out of stock from Upsell, but for some reason it is removing the products that are in stock. I have included the module code below and let me know if I am missing anything.
File name: kevz_upsellobserver.xml
<?xml version="1.0"?>
<config>
<modules>
<kevz_upsellobserver>
<codePool>local</codePool>
<active>true</active>
</kevz_upsellobserver>
</modules>
</config>
File name: config.xml
<?xml version="1.0"?>
<config>
<modules>
<kevz_upsellobserver>
<version>0.0.1</version>
</kevz_upsellobserver>
</modules>
<global>
<models>
<kevzupsellobserver>
<class>upsellobserver_Model</class>
</kevzupsellobserver>
</models>
<events>
<catalog_product_upsell>
<observers>
<kevzupsellobserver>
<type>singleton</type>
<class>Kevz_Upsellobserver_Model_Observer</class>
<method>filterUpsells</method>
</kevzupsellobserver>
</observers>
</catalog_product_upsell>
</events>
</global>
</config>
File name: Observer.php
<?php
class Kevz_Upsellobserver_Model_Observer {
public function filterUpsells($observer) {
$collection = $observer->getEvent()->getCollection();
foreach ($collection as $item) {
if (!$item->getIsSalable()) {
$collection->removeItemByKey($item->getId());
}
}
}
}
?>
if (!$item->getIsSalable()) {toif (!$item->getIsSaleable()) {? – Kevin S Mar 07 '14 at 06:59if(!$item->isSaleable()), you can try both methods though. – Moose Mar 07 '14 at 07:00if (!$item->getIsSalable()) {is working fine. P.S. Is there any way to pull static number of products in upsell unless there are less then 4 products assigned to a product as upsell? – Kevin S Mar 07 '14 at 07:03if(!$item->getIsSaleable()), you keep dropping the 'e'. I don't quite understand what you mean by pulling a static number of products in upsell, can you clarify? – Moose Mar 07 '14 at 07:04upsell.phtml) random number of products are being shown. Sometimes 1, 2 and 4 on every page refresh, but I would like to display 4 products and show less then 4 products only if less then 4 products are assigned as upsell to a product – Kevin S Mar 07 '14 at 07:08