[英]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.