/** * Return items collection * * @return Mage_Core_Model_Mysql4_Collection_Abstract */ public function getItemsCollection() { if (!$this->hasData('items_collection')) { $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($this->_getCustomer())->setStore($this->_getStore())->setSharedStoreIds($this->_getStore()->getWebsite()->getStoreIds()); if ($wishlist->getId()) { $collection = $wishlist->getProductCollection()->resetSortOrder()->addAttributeToSelect('name')->addAttributeToSelect('price'); $collection = Mage::helper('adminhtml/sales')->applySalableProductTypesFilter($collection); } else { $collection = parent::getItemsCollection(); } $this->setData('items_collection', $collection); } return $this->_getData('items_collection'); }
/** * Prepare customer wishlist product collection * * @return Mage_Adminhtml_Block_Customer_Edit_Tab_Wishlist */ public function getItemsCollection() { if (!$this->hasData('items_collection')) { $collection = Mage::getModel('reports/event')->getCollection()->addStoreFilter($this->_getStore()->getWebsite()->getStoreIds())->addRecentlyFiler(Mage_Reports_Model_Event::EVENT_PRODUCT_VIEW, $this->_getCustomer()->getId(), 0); $productIds = array(); foreach ($collection as $event) { $productIds[] = $event->getObjectId(); } $productCollection = parent::getItemsCollection(); if ($productIds) { $productCollection = Mage::getModel('catalog/product')->getCollection()->setStoreId($this->_getStore()->getId())->addStoreFilter($this->_getStore()->getId())->addAttributeToSelect('name')->addAttributeToSelect('price')->addIdFilter($productIds)->load(); $productCollection = Mage::helper('adminhtml/sales')->applySalableProductTypesFilter($productCollection); } $this->setData('items_collection', $productCollection); } return $this->_getData('items_collection'); }
/** * Prepare customer wishlist product collection * * @return Mage_Core_Model_Resource_Db_Collection_Abstract */ public function getItemsCollection() { if (!$this->hasData('items_collection')) { $collection = Mage::getModel('reports/event')->getCollection()->addStoreFilter($this->_getStore()->getWebsite()->getStoreIds())->addRecentlyFiler(Mage_Reports_Model_Event::EVENT_PRODUCT_VIEW, $this->_getCustomer()->getId(), 0); $productIds = array(); foreach ($collection as $event) { $productIds[] = $event->getObjectId(); } $productCollection = parent::getItemsCollection(); if ($productIds) { $attributes = Mage::getSingleton('catalog/config')->getProductAttributes(); $productCollection = Mage::getModel('catalog/product')->getCollection()->setStoreId($this->_getStore()->getId())->addStoreFilter($this->_getStore()->getId())->addAttributeToSelect($attributes)->addIdFilter($productIds)->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); Mage::getSingleton('cataloginventory/stock_status')->addIsInStockFilterToCollection($productCollection); $productCollection = Mage::helper('adminhtml/sales')->applySalableProductTypesFilter($productCollection); $productCollection->addOptionsToResult(); } $this->setData('items_collection', $productCollection); } return $this->_getData('items_collection'); }
/** * Prepare customer wishlist product collection * * @return Mage_Adminhtml_Block_Customer_Edit_Tab_Wishlist */ public function getItemsCollection() { if (!$this->hasData('items_collection')) { $storeIds = $this->_getStore()->getWebsite()->getStoreIds(); /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */ $collection = Mage::getResourceModel('sales/order_collection')->addAttributeToFilter('customer_id', $this->_getCustomer()->getId())->addAttributeToFilter('store_id', array('in' => $storeIds))->addAttributeToSort('created_at', 'desc')->setPage(1, 1)->load(); foreach ($collection as $order) { break; } if (isset($order)) { $collection = $order->getItemsCollection(); foreach ($collection as $item) { if ($item->getParentItem()) { $collection->removeItemByKey($item->getId()); } } } if (isset($order)) { $collection = Mage::helper('adminhtml/sales')->applySalableProductTypesFilter($collection); } $this->setData('items_collection', isset($order) ? $collection : parent::getItemsCollection()); } return $this->getData('items_collection'); }
/** * Prepare customer wishlist product collection * * @return Mage_Core_Model_Resource_Db_Collection_Abstract */ public function getItemsCollection() { if (!$this->hasData('items_collection')) { $productIds = array(); $storeIds = $this->_getStore()->getWebsite()->getStoreIds(); // Load last order of a customer /* @var $collection Mage_Core_Model_Mysql4_Collection_Abstract */ $collection = Mage::getResourceModel('sales/order_collection')->addAttributeToFilter('customer_id', $this->_getCustomer()->getId())->addAttributeToFilter('store_id', array('in' => $storeIds))->addAttributeToSort('created_at', 'desc')->setPage(1, 1)->load(); foreach ($collection as $order) { break; } // Add products to order items if (isset($order)) { $productIds = array(); $collection = $order->getItemsCollection(); foreach ($collection as $item) { if ($item->getParentItem()) { $collection->removeItemByKey($item->getId()); } else { $productIds[$item->getProductId()] = $item->getProductId(); } } if ($productIds) { // Load products collection $attributes = Mage::getSingleton('catalog/config')->getProductAttributes(); $products = Mage::getModel('catalog/product')->getCollection()->setStore($this->_getStore())->addAttributeToSelect($attributes)->addAttributeToSelect('sku')->addAttributeToFilter('type_id', array_keys(Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()))->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->addStoreFilter($this->_getStore())->addIdFilter($productIds); Mage::getSingleton('cataloginventory/stock_status')->addIsInStockFilterToCollection($products); Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($products); $products->addOptionsToResult(); // Set products to items foreach ($collection as $item) { $productId = $item->getProductId(); $product = $products->getItemById($productId); if ($product) { $item->setProduct($product); } else { $collection->removeItemByKey($item->getId()); } } } } $this->setData('items_collection', $productIds ? $collection : parent::getItemsCollection()); } return $this->getData('items_collection'); }