根据属性加入客户
我正在尝试通过客户属性过滤 magento API 返回的订单。我尝试了几种方法,但似乎没有任何效果。
我正在使用 Magento 1.4.1.1 atm,API 目前执行此操作:
$billingAliasName = 'billing_o_a';
$shippingAliasName = 'shipping_o_a';
$collection = Mage::getModel("sales/order")->getCollection()
->addAttributeToSelect('*')
->addAddressFields()
->addExpressionFieldToSelect(
'billing_firstname', "{{billing_firstname}}", array('billing_firstname'=>"$billingAliasName.firstname")
)
->addExpressionFieldToSelect(
'billing_lastname', "{{billing_lastname}}", array('billing_lastname'=>"$billingAliasName.lastname")
)
->addExpressionFieldToSelect(
'shipping_firstname', "{{shipping_firstname}}", array('shipping_firstname'=>"$shippingAliasName.firstname")
)
->addExpressionFieldToSelect(
'shipping_lastname', "{{shipping_lastname}}", array('shipping_lastname'=>"$shippingAliasName.lastname")
)
->addExpressionFieldToSelect(
'billing_name',
"CONCAT({{billing_firstname}}, ' ', {{billing_lastname}})",
array('billing_firstname'=>"$billingAliasName.firstname", 'billing_lastname'=>"$billingAliasName.lastname")
)
->addExpressionFieldToSelect(
'shipping_name',
'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
array('shipping_firstname'=>"$shippingAliasName.firstname", 'shipping_lastname'=>"$shippingAliasName.lastname")
);
我猜这是默认的 API 调用。现在我只想加入一个名为 update
的客户属性 - 如何实现这个简单的任务?
或者这在像 sales_flat_order
这样的平面上不可能吗?
I'm trying to filter my orders which are returned back by the magento API by a customer attribute. I tried several approaches but nothing seem to work.
I'm using Magento 1.4.1.1 atm and the api does this at the moment:
$billingAliasName = 'billing_o_a';
$shippingAliasName = 'shipping_o_a';
$collection = Mage::getModel("sales/order")->getCollection()
->addAttributeToSelect('*')
->addAddressFields()
->addExpressionFieldToSelect(
'billing_firstname', "{{billing_firstname}}", array('billing_firstname'=>"$billingAliasName.firstname")
)
->addExpressionFieldToSelect(
'billing_lastname', "{{billing_lastname}}", array('billing_lastname'=>"$billingAliasName.lastname")
)
->addExpressionFieldToSelect(
'shipping_firstname', "{{shipping_firstname}}", array('shipping_firstname'=>"$shippingAliasName.firstname")
)
->addExpressionFieldToSelect(
'shipping_lastname', "{{shipping_lastname}}", array('shipping_lastname'=>"$shippingAliasName.lastname")
)
->addExpressionFieldToSelect(
'billing_name',
"CONCAT({{billing_firstname}}, ' ', {{billing_lastname}})",
array('billing_firstname'=>"$billingAliasName.firstname", 'billing_lastname'=>"$billingAliasName.lastname")
)
->addExpressionFieldToSelect(
'shipping_name',
'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
array('shipping_firstname'=>"$shippingAliasName.firstname", 'shipping_lastname'=>"$shippingAliasName.lastname")
);
Which is the default API call I guess. Now I just want to join a customer attribute called update
- how do I achieve this simple task?
Or is this not possible on a flat table like sales_flat_order
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当我需要这样做时,我都会使用类似的东西:
将 EAV 表(带属性)连接到平面表
它没有得到很好的优化,但你应该能够挑选出你需要的部分。
附注
我想我会解释一下优化的含义,因为它很重要。该方法的核心是这样的:
如果你了解MySQL,那么你就会知道它在连接表时只会选择一个索引,越具体越好。在这种情况下,仅使用
entity_id
和attribute_id
字段,因此 MySQL 仅限于这些字段。两列都已建立索引,但基数较低。如果条件还包括实体类型,那么 MySQL 将选择使用 IDX_BASE 来按顺序索引列entity_type_id、entity_id、attribute_id、store_id(它需要处理他们从左到右)。因此,类似的事情会大大提高 EAV 性能 - 取决于“左”表上的行数,它可能会好几百或几千倍。
Whenever I need to do this I use something like:
Joining An EAV Table (With Attributes) To A Flat Table
It's not well optimised but you should be able to pick out the parts you need.
PS.
I think I'll explain what I mean by optimised since it's important. In the heart of the method is this bit:
If you know MySQL then you'll know it will only pick one index when joining a table, the more specific the better. In this case only the
entity_id
andattribute_id
fields are being used so MySQL is restricted to those. Both columns are indexed but the cardinality is low.If the condition also included the entity type then MySQL would have the choice of using
IDX_BASE
which indexes the columnsentity_type_id,entity_id,attribute_id,store_id
in that order (it needs to process them left to right). So something like this results in a much improved EAV performance - depending on how many rows on the 'left' table it could be several hundred- or thousand-fold better.