【问题标题】:Set & get custom CUSTOMER ATTRIBUTE in Magento Enterprise在 Magento Enterprise 中设置和获取自定义客户属性
【发布时间】:2012-12-17 23:27:05
【问题描述】:

我们在 Magento Enterprise (1.12.0.2) 中创建自定义客户属性来存储用户帐户 ID,从而使我们的 RMS 与 Magento 保持同步。

我需要手动设置 RMS id(通过 PHP),然后再获取 RMS id。自定义属性是一个文本字段,它的标签是 rms_id。我需要执行以下操作:

  1. 检查是否使用客户 ID 设置了 rms_id
  2. 如果未设置,则使用提供的值更新客户 rms_id

看起来很简单,但是我是 Magento 开发的新手,无法找到解决此问题的方法。所有搜索都会返回自定义 product 属性的结果,这与自定义 customer 属性不同。任何帮助将不胜感激。

【问题讨论】:

标签: magento


【解决方案1】:
/* @var $customer Mage_Customer_Model_Customer */    
$customer = Mage::getModel('customer/customer')->load({customer id});

if (!$customer->getRmsId()) {
    $customer->setRmsId({value});
    //the original version of this answer was wrong; need to use the resource model.
    $customer->getResource()->saveAttribute($customer,'rms_id');
} 

【讨论】:

  • 除了保存方法外,这一切都很好。显然 Magento 不喜欢 saveAttribute 并抛出了一个令人讨厌的错误,所以我用 $customer->save(); 换掉了它。它就像一个魅力。谢谢!
  • 有没有办法使用 rms id 加载单个客户?理想的解决方案是 $customer->loadByRmsId($rms_id);
  • $customer 模型中没有 saveAttribute() 方法。您应该使用 $customer->getResource()->saveAttribute($customer,'rms_id'); @尼克帕森斯
  • Mage Customer Model Customer 没有 saveAttribute 函数。尼克帕森的答案是正确的。
猜你喜欢
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-25
  • 2023-03-06
  • 1970-01-01
相关资源
最近更新 更多