I ran into a problem somehow where a product that is in stock and has a quantity of over 400000 is saying it is not salable. Or rather isSalable is not returning a value.
I pulled up the function to take a look and I noticed something odd.
Here is the function:
public function isSalable(){
Mage::dispatchEvent('catalog_product_is_salable_before', array(
'product' => $this
));
$salable = $this->isAvailable();
$object = new Varien_Object(array(
'product' => $this,
'is_salable' => $salable
));
Mage::dispatchEvent('catalog_product_is_salable_after', array(
'product' => $this,
'salable' => $object
));
// echo "variable: ".$salable."<br />object: ".$object->getIsSalable();
return $object->getIsSalable();
}
The commented echo was to see the value before it was put into the object and the value retrieved from the object. On the problem product I get:
variable: 1
object:
On other products they both come back as 1.
Does anyone know what would cause this to happen?
—EDIT—
Sorry, the function returns $object->getIsSalable(), not $salable.
This is on Magento Enterprise 1.12
I realize now that the object call is returning false. The effects of posting this at the end of the day.
I moved the echo to before the event dispatch and both came back as 1 so i looked into the event and tracked down where it is setting it to false.
I tracked it to this function in Enterprise/CatalogEvent:
public function applyIsSalableToProduct(Varien_Event_Observer $observer){
$event = $observer->getEvent()->getProduct()->getEvent();
echo "<br />".$event->getStatus()."<br />";
if ($event && in_array($event->getStatus(), array(
Enterprise_CatalogEvent_Model_Event::STATUS_CLOSED,
Enterprise_CatalogEvent_Model_Event::STATUS_UPCOMING
))) {
$observer->getEvent()->getSalable()->setIsSalable(false);
}
return $this;
}
If I echo $event->getStatus() outside the if, the problem product gives a status of closed, and other products throw an error because $event doesn’t exist.
What is causing the difference?
—EDIT 2—
I’ve found that the closed is coming from the product event.
$event = $observer->getEvent()->getProduct()->getEvent();
I went back to isSalable() and added print_r($this->getEvent()->getData()); after the object creation and got this:
Array([event_id] => 3 [category_id] => 12 [date_start] => 2012-11-28 09:54:00 [date_end] => 2012-11-29 09:54:00 [display_state] => [sort_order] => [status] => closed)
Again, normal products come back with an error because there is no event on the product.
Where does this event come from?
I’ll keep updating as I make progress.
Figured it out. There was a catalog event set that was setting the status to close. Deleted the event and all was well.