我正在使用Magento 1.9.0,我正试图让cron接听一个废弃的购物车电话,但有一个例外情况一直在发生。
TRIGGER: shutdown function
Last error:
Array
(
[type] => 1
[message] => Call to a member function getFullActionName() on a non-object
[file] => /chroot/home/abc/URL.com/html/store/app/code/local/Mnwebco/Personalize/Model/Observer.php
[line] => 9
)
根据AOEscheduler,基本上它在那时失败并且没有前进。
以下是本地模块的代码。
class Mnwebco_Personalize_Model_Observer
{
public function catalogProductLoadAfter(Varien_Event_Observer $observer)
{
// set the additional options on the product
$action = Mage::app()->getFrontController()->getAction();
if ($action->getFullActionName() == 'checkout_cart_add' || $action->getFullActionName() == 'checkout_cart_updateItemOptions') {
// assuming you are posting your custom form values in an array called extra_options...
//if ($options = $action->getRequest()->getParam('extra_options'))
//Mage::log('req parms '.$action->getRequest()->getParam('custommessage'));
if ($action->getRequest()->getParam('custommessage')!='') {
$personvalue = $action->getRequest()->getParam('custommessage');
$product = $observer->getProduct();
// add to the additional options array
$additionalOptions = array();
if ($additionalOption = $product->getCustomOption('additional_options')) {
$additionalOptions = (array) unserialize($additionalOption->getValue());
}
$additionalOptions[] = array(
'label' => 'Message to add',
'value' => $personvalue,
);
// add the additional options array with the option code additional_options
$observer->getProduct()
->addCustomOption('additional_options', serialize($additionalOptions));
} elseif ($action->getRequest()->getParam('customsigmessage')!='') {
$personvalue = $action->getRequest()->getParam('customsigmessage');
$product = $observer->getProduct();
// add to the additional options array
$additionalOptions = array();
if ($additionalOption = $product->getCustomOption('additional_options')) {
$additionalOptions = (array) unserialize($additionalOption->getValue());
}
$additionalOptions[] = array(
'label' => 'Message to add with signature',
'value' => $personvalue,
);
// add the additional options array with the option code additional_options
$observer->getProduct()
->addCustomOption('additional_options', serialize($additionalOptions));
} elseif ($action->getRequest()->getParam('bridesname')!='') {
$bride = $action->getRequest()->getParam('bridesname');
$groom = $action->getRequest()->getParam('groomsname');
$wedding = $action->getRequest()->getParam('weddingdate');
$product = $observer->getProduct();
// add to the additional options array
$additionalOptions = array();
if ($additionalOption = $product->getCustomOption('additional_options')) {
$additionalOptions = (array) unserialize($additionalOption->getValue());
}
$additionalOptions[] = array(
'label' => 'Personalized Information',
'value' => 'Bride: '.$bride.', Groom: '.$groom.', Date: '.$wedding,
);
/*
$additionalOptions[] = array(
'label' => 'bridesname',
'value' => $bride,
);
$additionalOptions[] = array(
'label' => 'groomsname',
'value' => $groom,
);
$additionalOptions[] = array(
'label' => 'weddingdate',
'value' => $wedding,
);
*/
// add the additional options array with the option code additional_options
$observer->getProduct()
->addCustomOption('additional_options', serialize($additionalOptions));
}
}
}
public function checkoutCartUpdateItemsBefore (Varien_Event_Observer $observer)
{
// set the additional options on the product
$action = Mage::app()->getFrontController()->getAction();
//Mage::log('!imp '.$action->getFullActionName());
if ($action->getFullActionName() == 'checkout_cart_updateItemOptions') {
// assuming you are posting your custom form values in an array called extra_options...
//if ($options = $action->getRequest()->getParam('extra_options'))
//Mage::log('req parms '.$action->getRequest()->getParam('custommessage'));
if ($action->getRequest()->getParam('custommessage')!='') {
$personvalue = $action->getRequest()->getParam('custommessage');
$product = $observer->getItem()->getProduct();
// add to the additional options array
$additionalOptions = array();
if ($additionalOption = $product->getCustomOption('additional_options')) {
$additionalOptions = (array) unserialize($additionalOption->getValue());
}
$additionalOptions[] = array(
'label' => 'Message to add',
'value' => $personvalue,
);
// add the additional options array with the option code additional_options
$observer->getItem()->getProduct()
->addCustomOption('additional_options', serialize($additionalOptions));
} elseif ($action->getRequest()->getParam('customsigmessage')!='') {
$personvalue = $action->getRequest()->getParam('customsigmessage');
$product = $observer->getItem()->getProduct();
// add to the additional options array
$additionalOptions = array();
if ($additionalOption = $product->getCustomOption('additional_options')) {
$additionalOptions = (array) unserialize($additionalOption->getValue());
}
$additionalOptions[] = array(
'label' => 'Message to add with signature',
'value' => $personvalue,
);
// add the additional options array with the option code additional_options
$observer->getItem()->getProduct()
->addCustomOption('additional_options', serialize($additionalOptions));
} elseif ($action->getRequest()->getParam('bridesname')!='') {
$bride = $action->getRequest()->getParam('bridesname');
$groom = $action->getRequest()->getParam('groomsname');
$wedding = $action->getRequest()->getParam('weddingdate');
$product = $observer->getItem()->getProduct();
// add to the additional options array
$additionalOptions = array();
if ($additionalOption = $product->getCustomOption('additional_options')) {
$additionalOptions = (array) unserialize($additionalOption->getValue());
}
$additionalOptions[] = array(
'label' => 'Personalized Information',
'value' => 'Bride: '.$bride.', Groom: '.$groom.', Date: '.$wedding,
);
// add the additional options array with the option code additional_options
$observer->getItem()->getProduct()
->addCustomOption('additional_options', serialize($additionalOptions));
}
}
}
public function salesConvertQuoteItemToOrderItem (Varien_Event_Observer $observer)
{
$quoteItem = $observer->getItem();
if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) {
$orderItem = $observer->getOrderItem();
$options = $orderItem->getProductOptions();
$options['additional_options'] = unserialize($additionalOptions->getValue());
$orderItem->setProductOptions($options);
}
}
}
答案 0 :(得分:2)
你的getAction()可能返回null。 更好的方法是做
$action = Mage::app()->getRequest()->getActionName();
这将返回一个字符串。所以,在你的if条件中,使用,
if($action == 'checkout_cart_add' || $action == 'checkout_cart_updateItemOptions') {}