Magento:按价格和更新日期对心愿单产品集合进行排序


Magento: Sorting wishlist product collection by price and updated date

我想按产品的日期和价格对心愿单产品集合进行排序。有人能帮我吗。。。这是我的代码

public function getWishlistCollection(Mage_Customer_Model_Customer $customer = null){
        if($customer):
            $wishlists = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
            if($wishlists->getItemCollection()->getSize()):
                $wishlists = $this->favorites->getItemCollection();
                $wishlists->addWishListSortOrder('added_at', 'DESC');
                $wishlists->getSelect()->limit(10, 0);
                return $wishlists;
            endif;
            return;
        endif;
        return;
    }

否项目集合不是产品集合。在这种情况下,您需要从心愿单项目集合创建产品集合。

使用以下代码:

$wishList = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer);
$wishListItemCollection = $wishList->getItemCollection();
if (count($wishListItemCollection)) {
    $arrProductIds = array();
    foreach ($wishListItemCollection as $item) {
        $arrProductIds[] = $item->getProductId();
    }
}
$productsCollection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('entity_id', array('in' => $arrProductIds))
    ->addAttributeToSort('price', 'ASC')
    ->addAttributeToSort('created_at', 'ASC');
foreach($productsCollection as $product)
{
    echo $product->getprice();
    echo $product->getCreatedAt();
}