php - 根据属性加入客户

标签 php zend-framework magento

我正在尝试通过客户属性过滤由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 这样的平面上不可能吗?

最佳答案

每当我需要这样做时,我都会使用类似的东西:
Joining An EAV Table (With Attributes) To A Flat Table

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

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

->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'

关于php - 根据属性加入客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5579393/

相关文章:

php - Codeigniter XSS 过滤器删除 Ajax 数据后的内联样式

php - Symfony 2 链接到当前页面

php - Zend 框架 "under maintenance"页面

php - Magento TopLinks 作为悬停时的下拉菜单

magento - PayPal 订单在付款前自动取消?

Php Curl 403 禁止错误

php - 我的php表单未检查在表单中输入的电子邮件是否有效

php - 使用 Zend_Http_Client 进行身份验证

zend-framework - IMAP "Invalid Credentials"通过 GMail XOAUTH

forms - 如何在 magento 2 结帐、街道地址字段上添加工具提示?