Php 在属性上加入客户
我正在尝试筛选MagentoAPI通过customer属性返回的订单。我尝试了几种方法,但似乎都不管用 我使用的是Magento 1.4.1.1 atm,api目前正在这样做:Php 在属性上加入客户,php,zend-framework,magento,Php,Zend Framework,Magento,我正在尝试筛选MagentoAPI通过customer属性返回的订单。我尝试了几种方法,但似乎都不管用 我使用的是Magento 1.4.1.1 atm,api目前正在这样做: $billingAliasName = 'billing_o_a'; $shippingAliasName = 'shipping_o_a'; $collection = Mage::getModel("sales/order")->getCollection() ->addAtt
$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\u flat\u order
这样的平桌上不可能做到这一点吗?每当我需要这样做时,我都会使用类似于:它没有得到很好的优化,但你应该能够挑选出你需要的部件 PS.
我想我会解释什么是优化,因为它很重要。该方法的核心是此位:
->joinLeft(array($alias => $table),
'main_table.'.$mainTableForeignKey.' = '.$alias.'.entity_id and '.$alias.'.attribute_id = '.$attribute->getAttributeId(),
array($attribute->getAttributeCode() => $field)
);
如果您了解MySQL,那么您就会知道它在加入表时只会选择一个索引,越具体越好。在这种情况下,仅使用实体\u id
和属性\u id
字段,因此MySQL仅限于这些字段。这两列都已编制索引,但基数较低
如果该条件还包括实体类型,那么MySQL可以选择使用IDX\u BASE
,按该顺序索引列entity\u type\u id、entity\u id、attribute\u id、store\u 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'
+1对于
AddExpressionFieldToSelection
,我通常看不到正确使用该选项。