检查属性是客户属性还是客户地址属性

发布于 2024-12-21 11:48:51 字数 1143 浏览 1 评论 0原文

我有以下代码,我需要检查有问题的属性是客户属性还是客户地址属性。我该如何检查?

<代码> 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

节枝 2024-12-28 11:48:51

您可以使用 magic has*() 调用扩展 Varien_Object 的每个类来检查给定属性是否存在。

此外,Varien_Object 提供了一个非魔法的 hasData('property_name') 方法。

hasData() 方法基本上做同样的事情,只是间接地 - 即通过将属性名称作为参数传递给方法,而不是将其用作方法名称的驼峰式部分。

Mage_Customer_Model_CustomerMage_Customer_Model_Address 实际上扩展了 Varien_Object,因此您可以在对象实例上调用 hasData('street')检查此类属性是否存在并将结果用于您的 if/else 场景。

您还可以神奇地调用 hasStreet(),但在您的情况下,hasData() 变体肯定会更好(因为您正在循环使用具有可变属性名称的数组) 。

请注意,hasData() 只能帮助您区分唯一的属性名称。当然,您不能使用hasData()来区分两个类中存在的同名属性(例如'entity_id')。

You can use magic has*() calls with each class extending Varien_Object to check whether a given property does, or does not exist.

Additionally, Varien_Object offers a non-magic hasData('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 and Mage_Customer_Model_Address actually do extend Varien_Object, so you could call hasData('street') on an object instance to check for the existence of such property and use the result for your if/else scenario.

You could also magically call hasStreet(), but in your case the hasData() 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 use hasData() to distinguish properties of the same name existing in both classes (e.g. 'entity_id').

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文