检查属性是客户属性还是客户地址属性
我有以下代码,我需要检查相关属性是客户属性还是客户地址属性。我如何检查?检查属性是客户属性还是客户地址属性
private $custom_columns = array();
public function __construct()
{
parent::__construct();
$this->setId('customerGrid');
$this->setUseAjax(true);
$this->setDefaultSort('email');
$this->setDefaultLimit('200');
$this->setSaveParametersInSession(true);
$attributeIds = Mage::getStoreConfig('sectionname/group/field');
$this->custom_columns = array($attributeIds);
}
$attributeIds
回属性代码像街道如果我选择街道地址,性别如果我选择性别等等。现在应该提出什么条件才能知道给定的属性是客户还是地址属性。
// Prepare Collection addition to store custom fields
foreach ($this->custom_columns as $col)
{
//Some Condition if its a Customer attribute
collection->addAttributeToSelect($col);
//else some condition if its a Customer address attribute
$collection->joinAttribute($col, "customer_address/$col", 'default_billing', null, 'left');
}
$this->setCollection($collection);
return parent::_prepareCollection();
}
我只是想知道那些条件会是什么。希望这个更清楚一点
您可以使用magichas*()
调用与每个类延伸Varien_Object
来检查给定的属性是否存在。
此外,Varien_Object
提供了非魔术hasData('property_name')
方法。
hasData()
方法基本上做同样的事情,只是间接 - 即通过将属性名称作为参数传递给方法,而不是将它用作方法名称的驼峰部分。
Mage_Customer_Model_Customer
和Mage_Customer_Model_Address
其实并延长Varien_Object
,所以你可以调用hasData('street')
的对象实例来检查了这些财产的存在和使用结果为您if/else
方案。
你也可以神奇地叫hasStreet()
,但在你的情况下,hasData()
变体肯定会更好地服务(因为你正在循环通过具有可变属性名称的数组)。
请注意,hasData()
只能帮助您区分独特的属性名称。当然,您不能使用hasData()
来区分两个类中存在的同名名称的属性(例如'entity_id'
)。
感谢您的详细解释。这帮助我更好地理解事物。所以我可以使用* if(Mage :: getModel('customer/entity_attribute_collection) - > hasData($ col)){做某事...} else {别的...} * – ivn 2011-12-17 23:14:34
很难理解你在问什么。请尝试清楚您的问题,并发布您已经尝试过的代码以及您收到的任何错误消息。 – rdlowrey 2011-12-16 15:33:09