根据属性加入客户

发布于 2024-10-30 23:11:44 字数 1742 浏览 0 评论 0原文

我正在尝试通过客户属性过滤 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 技术交流群。

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

发布评论

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

评论(1

农村范ル 2024-11-06 23:11:44

每当我需要这样做时,我都会使用类似的东西:
将 EAV 表(带属性)连接到平面表

它没有得到很好的优化,但你应该能够挑选出你需要的部分。

附注
我想我会解释一下优化的含义,因为它很重要。该方法的核心是这样的:

->joinLeft(array($alias => $table),
    'main_table.'.$mainTableForeignKey.' = '.$alias.'.entity_id and '.$alias.'.attribute_id = '.$attribute->getAttributeId(),
    array($attribute->getAttributeCode() => $field)
);

如果你了解MySQL,那么你就会知道它在连接表时只会选择一个索引,越具体越好。在这种情况下,仅使用 entity_idattribute_id 字段,因此 MySQL 仅限于这些字段。两列都已建立索引,但基数较低。

如果条件还包括实体类型,那么 MySQL 将选择使用 IDX_BASE 来按顺序索引列entity_type_id、entity_id、attribute_id、store_id(它需要处理他们从左到右)。因此,类似的事情会大大提高 EAV 性能 - 取决于“左”表上的行数,它可能会好几百或几千倍。

$alias.'.entity_type_id='.$entityType->getId().' AND main_table.'.$mainTableForeignKey.' = '.$alias.'.entity_id AND '.$alias.'.attribute_id = '.$attribute->getAttributeId().' AND '.$alias.'.store_id=0'

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:

->joinLeft(array($alias => $table),
    'main_table.'.$mainTableForeignKey.' = '.$alias.'.entity_id and '.$alias.'.attribute_id = '.$attribute->getAttributeId(),
    array($attribute->getAttributeCode() => $field)
);

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 and attribute_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 columns entity_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.

$alias.'.entity_type_id='.$entityType->getId().' AND main_table.'.$mainTableForeignKey.' = '.$alias.'.entity_id AND '.$alias.'.attribute_id = '.$attribute->getAttributeId().' AND '.$alias.'.store_id=0'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文