Magento:getCustomer->getAddresses() 的排序顺序



我正在尝试更改Magento Checkout Platvown中使用的地址集合的排序顺序(SELECT)用于运输地址。

我想更改以"公司名称"为"公司名称"的排序订单,而不是由id的默认值。

foreach ($this->getCustomer()->getAddresses() as $address) {
                $options[] = array(
                    'value' => $address->getId(),
                    'label' => $address->format('oneline')
                );
            }

我尝试对此进行调整:

foreach ($this->getCustomer()->getAddresses()->addAttributeToSort('company', 'ASC') as $address) {

,但这会导致错误。

有什么建议?

谢谢。

如果调用getAddresses(),则加载了集合,并且无法再应用您的排序。您必须在加载该集合之前访问该集合。

以这种方式尝试:

$addressCollection = $this->getCustomer()->getAddressesCollection()->addAttributeToSort('company', 'ASC');
$addresses = $addressCollection->getItems();
foreach ($addresses as $address){
 //...do whatever you need
}

最新更新