drjmrg8766 2014-07-11 21:49
浏览 61
已采纳

以编程方式更新magento客户

I'm trying to modify existing customers data on magento programmatically, but i have errors, hope someone can help me with this.

require_once('../app/Mage.php');
ini_set("error_reporting",E_ALL);
ini_set("display_errors",true);
umask (0);
Mage::app('admin');

$email = $_REQUEST['email'];
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
$newEmail = $_REQUEST['newEmail'];
$method = $_REQUEST['method'];
$user_id = $_REQUEST['user_id'];


$customer = Mage::getModel('customer/customer');
        $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
        $customer->loadByEmail($email);
        $customer->setFirstname = $firstname; 
        $customer->setLastname = $lastname; 
        $customer->setEmail = $newEmail; 
        $customer->save();  

Here is the error message

Fatal error: Uncaught exception 'Mage_Customer_Exception' with message 'Customer email is required' in /home/insateck/www/zzWEBS/MAGENTO/ZZpruebasEXPRIMENET/app/Mage.php:580 Stack trace: #0 /home/insateck/www/zzWEBS/MAGENTO/ZZpruebasEXPRIMENET/app/code/core/Mage/Customer/Model/Resource/Customer.php(76): Mage::exception('Mage_Customer', 'Customer email ...') 
#1 /home/insateck/www/zzWEBS/MAGENTO/ZZpruebasEXPRIMENET/app/code/core/Mage/Eav/Model/Entity/Abstract.php(1122): Mage_Customer_Model_Resource_Customer->_beforeSave(Object(Mage_Customer_Model_Customer)) 
#2 /home/insateck/www/zzWEBS/MAGENTO/ZZpruebasEXPRIMENET/app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Eav_Model_Entity_Abstract->save(Object(Mage_Customer_Model_Customer))
#3 /home/insateck/www/zzWEBS/MAGENTO/ZZpruebasEXPRIMENET/syncadaptax/update_client_methods.php(33): Mage_Core_Model_Abstract->save() 
#4 {main} thrown in /home/insateck/www/zzWEBS/MAGENTO/ZZpruebasEXPRIMENET/app/Mage.php on line 580
  • 写回答

2条回答 默认 最新

  • dt246813579 2014-07-12 08:17
    关注

    You can modify the condition for saving the new email as:

    $customer = Mage::getModel('customer/customer');
    $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
    $customer->loadByEmail($email);
    if($customer->getId()>1){
         $customer2 = Mage::getModel('customer/customer');
         $customer2->setWebsiteId(Mage::app()->getWebsite()->getId());
         $customer2->loadByEmail($newEmail);
         if($customer2->getId()<1){
            $customer->setEmail($newEmail); 
         }
         $customer->setFirstname($firstname); 
         $customer->setLastname ($lastname); 
         $customer->save();
     }
    

    The updated condition will avoid the fatal error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵