2012-12-17 70 views
2

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

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

  1. 检查rms_id使用客户ID
  2. 如果没有设置设置,更新客户rms_id与所提供的价值

看起来非常简单,但我Magento开发新手,无法找到解决此问题的方法。所有搜索返回的结果为自定义产品属性,这不属于定制的客户属性。任何帮助将非常感激。

+0

魔术方法应该仍然适用于客户属性。 '$ _cutomer-> getRmsId()' - 如果不是,请确保该属性是集合/模型对象的一部分。这可能是有用的:http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento – pspahn

回答

3
/* @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'); 
} 
+0

这与保存方法的例外完美。显然Magento不喜欢saveAttribute并抛出一个令人讨厌的错误,所以我用$ customer-> save()替换掉了它。它就像一个魅力。谢谢! –

+0

有没有办法使用rms id加载单个客户?理想的解决方案就像$ customer-> loadByRmsId($ rms_id); –

+1

$ customer模型中没有saveAttribute()方法。您应该使用 $ customer-> getResource() - > saveAttribute($ customer,'rms_id'); @NickParsons –

相关问题