Magento: How do I get observers to work in an external script?

Posted by Laizer on Stack Overflow See other posts from Stack Overflow or by Laizer
Published on 2010-05-12T09:29:52Z Indexed on 2010/05/12 13:34 UTC
Read the original article Hit count: 203

Filed under:

As far as I can tell, when a script is run outside of Magento, observers are not invoked when an event is fired. Why? How do I fix it?

Below is the original issue that lead me to this question. The issue is that the observer that would apply the catalog rule is never called. The event fires, but the observer doesn't pick it up.


I'm running an external script that loads up a Magento session.

Within that script, I'm loading products and grabbing a bunch of properties. The one issue is that getFinalPrice() does not apply the catalog rules that apply to the product.

I'm doing everything I know to set the session, even a bunch of stuff that I think is superfluous. Nothing seems to get these rules applied.

Here's a test script:

require_once "app/Mage.php";
umask(0);
$app = Mage::app("default");

$app->getTranslator()->init('frontend');  //Probably not needed
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton("customer/session");
$session->start();  //Probably not needed
$session->loginById(122);

$product = Mage::getModel('catalog/product')->load(1429);
echo $product->getFinalPrice();

Any insight is appreciated.

© Stack Overflow or respective owner

Related posts about magento