[英]Magento : Fatal error: Call to a member function getMethodInstance() on a non-object
[英]Magento Fatal error: Call to a member function save() on a non-object
我是magento的新手,想由注冊用戶創建產品廣告表格。 如果用戶尚未添加帳單/送貨地址信息,我只想通過選中復選框將電話號碼僅添加到用戶地址字段中。 但是,當用戶選中電話復選框以將電話號碼添加到默認帳單/送貨地址(如果尚未添加電話號碼)時,它將返回錯誤。
Fatal error: Call to a member function save() on a non-object
貝婁是我的代碼;
if (isset($_POST['phone_check'])) { //save phone no to customer's address
$customerAddressId = $customer->getDefaultBilling();
if ($customerAddressId) {
$customAddress = Mage::getModel('customer/address')->load($customerAddressId);
$customAddress->setTelephone($params['phone']);
}
try {
$customAddress->save(); //**Error occurred this line.**
} catch (Exception $ex) {
Zend_Debug::dump($ex->getMessage());
}
}
注意:當用戶要在添加用戶的帳單/送貨地址字段之前對產品進行廣告宣傳時,會發生此問題。 因此,我只想在地址字段中添加電話號碼。 我檢查了在尚未在“ sales_flat_quote_address”或“ sales_flat_order_address”表中添加賬單/送貨地址的用戶下,address_id,customer_id或customer_address_id中是否沒有數據。
請建議我該怎么做。
客戶地址中的客戶地址沒有價值。 使用以下代碼添加客戶地址。
if (isset($_POST['phone_check'])) { //save phone no to customer's address
$_custom_address = array ( 'telephone' => $params['phone']);
$customAddress = Mage::getModel('customer/address');
$customAddress->setData($_custom_address)
->setCustomerId($customer->getId())
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
try {
$customAddress->save();
}
catch (Exception $ex) {
Zend_Debug::dump($ex->getMessage());
}
}
$customerAddressId = $customer->getDefaultBilling();
if ($customerAddressId) {
$customAddress = Mage::getModel('customer/address')->load($customerAddressId);
$customAddress->setTelephone($params['phone']);
}
如果未定義$ customerAddressId,則以后再也不會擁有$ customAddress模型
我的猜測是您的代碼沒有在if
語句中包含它。 您僅在此處定義$customAddress
。 您需要某種else語句,否則,您需要save
不存在的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.