我想按产品的日期和价格对wishlist产品系列进行排序。 请有人帮帮我... 这是我的代码
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;
}
答案 0 :(得分:1)
项目集合不是产品集合。在这种情况下,您需要从心愿单项目集合中创建产品集合。
使用以下代码:
$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();
}