Я хочу сортировать коллекцию продуктов списка желаний по дате и цене продукта. Может ли кто-нибудь помочь мне, пожалуйста... Вот мой код
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();
}