检查属性是客户属性还是客户地址属性
我有以下代码,我需要检查有问题的属性是客户属性还是客户地址属性。我该如何检查?
<代码> 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();
}
我只是想知道这些条件是什么。希望这更清楚一点
I have the following code where I need to check whether the attribute in question is a customer attribute or customer address attribute. How do I check that?
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
return attribute codes like street if I select Street Address, gender if I select Gender and so on. Now what condition should be put in order to know whether a given attribute is customer or address attribute.
// 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(); }
I just want to know what those conditions would be. Hope this is a little clearer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 magic
has*() 调用扩展
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'
)。You can use magic
has*()
calls with each class extendingVarien_Object
to check whether a given property does, or does not exist.Additionally,
Varien_Object
offers a non-magichasData('property_name')
method.The
hasData()
method basically does the same thing, just indirectly - i.e. by passing the property name as argument to the method, instead of using it as camel-cased part of the methods name.Mage_Customer_Model_Customer
andMage_Customer_Model_Address
actually do extendVarien_Object
, so you could callhasData('street')
on an object instance to check for the existence of such property and use the result for yourif/else
scenario.You could also magically call
hasStreet()
, but in your case thehasData()
variant will definitely serve better (as you're looping thru an array with variable property names).Note that
hasData()
can only help you distinguish unique property names. Of course you cannot usehasData()
to distinguish properties of the same name existing in both classes (e.g.'entity_id'
).