gpt4 book ai didi

php - 在非对象上调用成员函数 getFullActionName()

转载 作者:行者123 更新时间:2023-12-03 07:49:28 24 4
gpt4 key购买 nike

我正在使用 Magento 1.9.0,我正在尝试让 cron 接听一个废弃的购物车电话,但有一个异常(exception)情况不断发生。

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);
}
}
}

最佳答案

您的 getAction() 可能返回 null。
更好的方法是做

$action = Mage::app()->getRequest()->getActionName();

这将返回一个字符串。所以,在你的 if 条件下,使用,
if($action == 'checkout_cart_add' ||  $action == 'checkout_cart_updateItemOptions') {}

关于php - 在非对象上调用成员函数 getFullActionName(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45149200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com