protected function _getProductCollection() { $storeId = Mage::app()->getStore()->getId(); $product = Mage::getModel('catalog/product'); $visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG); $this->_productCollection = $product->setStoreId($storeId)->getCollection()->addAttributeToSelect(array('name', 'price', 'small_image'), 'inner')->addAttributeToSelect(array('special_price'), 'left')->setOrder('created_at', 'desc')->addFieldToFilter('type_id', 'bundle')->setPageSize($this->getProductsLimit())->addAttributeToFilter('visibility', $visibility); $checkedProducts = new Varien_Data_Collection(); foreach ($this->_productCollection as $k => $p) { $p = $p->loadParentProductIds(); $parentIds = $p->getData('parent_product_ids'); if (is_array($parentIds) && !empty($parentIds)) { if (!$checkedProducts->getItemById($parentIds[0])) { $parentProduct = Mage::getModel('catalog/product')->setStoreId($storeId)->load($parentIds[0]); if ($parentProduct->isVisibleInCatalog()) { $checkedProducts->addItem($parentProduct); } } } else { if (!$checkedProducts->getItemById($k)) { $checkedProducts->addItem($p); } } if (count($checkedProducts) >= $this->getProductsLimit()) { break; } } return $this->_productCollection; }
protected function _getProductCollection() { $page = Mage::getBlockSingleton('page/html_pager')->getCurrentPage(); date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone')); $todayDate = strftime("%Y-%m-%d", Mage::app()->getLocale()->storeTimeStamp(Mage::app()->getStore()->getId())); $storeId = Mage::app()->getStore()->getId(); $product = Mage::getModel('catalog/product'); $this->_productCollection = $product->setStoreId($storeId)->getCollection()->addAttributeToSelect(array('name', 'status', 'price', 'special_price', 'small_image', 'required_options', 'special_from_date', 'special_to_date'), 'inner')->joinField('stock_status', 'cataloginventory/stock_status', 'stock_status', 'product_id=entity_id', array('stock_status' => Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK, 'website_id' => Mage::app()->getWebsite()->getWebsiteId()))->addAttributeToFilter('special_price', array('gt' => 0), 'left')->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $todayDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')->addAttributeToSort('created_at', 'desc')->addFinalPrice()->addStoreFilter()->setPageSize($this->getProductsLimit())->setCurPage($page)->addAttributeToFilter('status', 1)->addUrlRewrite(); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection); $checkedProducts = new Varien_Data_Collection(); foreach ($this->_productCollection as $k => $p) { $p = $p->loadParentProductIds(); $parentIds = $p->getData('parent_product_ids'); if (is_array($parentIds) && !empty($parentIds)) { if (!$checkedProducts->getItemById($parentIds[0])) { $parentProduct = Mage::getModel('catalog/product')->setStoreId($storeId)->load($parentIds[0]); if ($parentProduct->isVisibleInCatalog()) { $checkedProducts->addItem($parentProduct); } } } else { if (!$checkedProducts->getItemById($k)) { $checkedProducts->addItem($p); } } if (count($checkedProducts) >= $this->getProductsLimit()) { break; } } return $this->_productCollection; }
public static function getCollection($force = false) { static $collection = null; if ($collection === null or $force === true) { $collection = new Varien_Data_Collection(); $moduleConfig = Mage::getConfig()->getModuleConfig(); foreach ($moduleConfig->children() as $moduleIdentifier => $config) { if ($collection->getItemById($moduleIdentifier) === null) { $collection->addItem(self::factory($moduleIdentifier)); } } } return $collection; }
protected function _getProductCollection() { $storeId = Mage::app()->getStore()->getId(); $product = Mage::getModel('catalog/product'); $visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG); $doc1 = new DOMDocument(); $doc1->load("topseller.xml"); $connect = $doc1->getElementsByTagName("item"); foreach ($connect as $con) { $product_ids = $con->getElementsByTagName("id"); $product_id = $product_ids->item(0)->nodeValue; // $productid_xml .= $product_id.", "; $productid_xml[] = $product_id; } $this->_productCollection = $product->setStoreId($storeId)->getCollection()->addAttributeToSelect(array('name', 'price', 'small_image'), 'inner')->addAttributeToSelect(array('special_price'), 'left')->setOrder('created_at', 'desc')->setPageSize($this->getProductsLimit())->addAttributeToFilter('visibility', $visibility)->addAttributeToFilter('entity_id', array('in' => $productid_xml)); $checkedProducts = new Varien_Data_Collection(); foreach ($this->_productCollection as $k => $p) { $p = $p->loadParentProductIds(); $parentIds = $p->getData('parent_product_ids'); if (is_array($parentIds) && !empty($parentIds)) { if (!$checkedProducts->getItemById($parentIds[0])) { $parentProduct = Mage::getModel('catalog/product')->setStoreId($storeId)->load($parentIds[0]); if ($parentProduct->isVisibleInCatalog()) { $checkedProducts->addItem($parentProduct); } } } else { if (!$checkedProducts->getItemById($k)) { $checkedProducts->addItem($p); } } if (count($checkedProducts) >= $this->getProductsLimit()) { break; } } return $this->_productCollection; }
/** * Loads all items in the grid. * @todo Use a stored procedure instead. */ protected function _prepareCollection() { $report = new Varien_Data_Collection(); $filter = $this->getDateRange(); $charities = Mage::getResourceModel('donations/charity_collection'); foreach ($charities as $charity) { // each charity is a row in the grid $collection = Mage::getResourceModel('donations/report_bymonth_collection'); /* @var $collection Lucky_Donations_Model_Mysql4_Report_Bymonth_Collection */ $collection->joinCharity()->joinOrders()->filterOrders()->setDateRange($filter['report_from'], $filter['report_to'])->addFieldToFilter('charity.charity_id', $charity->getCharityId())->setOrder('charity.is_system', 'DESC')->setOrder('charity_name', 'ASC')->groupByCharity(); foreach ($this->getMonths() as $key => $label) { $collection->addAmountByMonth($key); } $firstItem = $collection->getFirstItem(); if ($collection->count() && !$report->getItemById($firstItem->getId())) { $report->addItem($firstItem); // add the row } } $this->setCollection($report); return $this; }
/** * Function to get product collection * * This Function will return the product collection * * @return array */ public function getProductCollection() { /** Getting Store id */ $storeId = Mage::app()->getStore()->getId(); $order = (int) Mage::getStoreConfig('superdeals/slider/slide_order'); if ($order == 1) { $productCollection = $this->getProductCollectionHigher(); } elseif ($order == 2) { $productCollection = $this->getProductCollectionLower(); } elseif ($order == 3) { $productCollection = $this->getProductCollectionRandom(); } else { $productCollection = $this->getProductCollectionRandom(); } $sameProduct = array(); $checkedProducts = new Varien_Data_Collection(); foreach ($productCollection as $key => $prod) { /** Getting product Id */ $parentId = $this->getParentId($prod); if ($parentId == '') { continue; } /** Set Store Id */ $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($this->getParentId($prod)); /** * if the product is not visible or is disabled */ if (!$product->isVisibleInCatalog()) { continue; } /** * if two or more simple products of the same configurable product are ordered */ if (in_array($product->getId(), $sameProduct)) { continue; } $sameProduct[] = $product->getId(); if (!$checkedProducts->getItemById($parentId)) { $checkedProducts->addItem($product); } if (count($checkedProducts) >= $this->getProductsLimit()) { break; } } return $checkedProducts; }
public function getProductCollection() { $storeId = Mage::app()->getStore()->getId(); $productCollection = $this->getProductCollectionInitial(); //echo count($productCollection); die; $sameProduct = array(); $checkedProducts = new Varien_Data_Collection(); foreach ($productCollection as $key => $prod) { $parentId = $this->getParentId($prod); if ($parentId == '') { continue; } $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($this->getParentId($prod)); // if the product is not visible or is disabled if (!$product->isVisibleInCatalog()) { continue; } // if two or more simple products of the same configurable product are ordered if (in_array($product->getId(), $sameProduct)) { continue; } $sameProduct[] = $product->getId(); if (!$checkedProducts->getItemById($parentId)) { $checkedProducts->addItem($product); } if (count($checkedProducts) >= $this->getProductsLimit()) { break; } } $productCollection = $checkedProducts; //echo "<pre>"; print_r(count($checkedProducts)); exit; return $productCollection; }
/** * Update a single product with data from the feed. Should check for the * product to already exist in the collection and when it does, update the * product in the collection. When the product doesn't exist yet, it should * create a new product, set the extracted data on it and add it to the * collection. * * @param DOMXPath $feedXPath * @param DOMNode $itemNode * @param Varien_Data_Collection $itemCollection * @param int $storeId * @param array $cfgData * @param EbayEnterprise_Catalog_Interface_Import_Items $items * @return self */ protected function _updateItem(DOMXPath $feedXPath, DOMNode $itemNode, Varien_Data_Collection $itemCollection, $storeId, array $cfgData, EbayEnterprise_Catalog_Interface_Import_Items $items) { $extractor = Mage::getSingleton('ebayenterprise_catalog/feed_extractor'); $sku = $this->_helper->normalizeSku($extractor->extractSku($feedXPath, $itemNode, $cfgData['extractor_sku_xpath']), $this->_coreHelper->getConfigModel()->catalogId); $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId(); $item = $itemCollection->getItemById($sku); if (is_null($item)) { $item = $items->createNewItem($sku); $item->setWebsiteIds(array($websiteId)); $itemCollection->addItem($item); } elseif ($cfgData['feed_type'] === 'product') { $item->setUrlKey(false); } $item->setStoreId($storeId); $webSiteIds = array_unique(array_merge($item->getWebsiteIds(), array($websiteId))); $item->setWebsiteIds($webSiteIds); $item->addData($extractor->extractItem($feedXPath, $itemNode, $item, $cfgData)); return $this; }
/** * Function to get product collection * * This Function will return the product collection * @return array */ public function getProductCollection() { $storeId = Mage::app()->getStore()->getId(); $productCollection = $this->getProductCollectionInitial(); $count = count($productCollection); if ($count <= 0) { $productCollection = $this->getProductCollectionRandom(); } $sameProduct = array(); $checkedProducts = new Varien_Data_Collection(); foreach ($productCollection as $key => $prod) { $parentId = $this->getParentId($prod); /** * Check the parent id is not equal to empty */ if ($parentId == '') { continue; } $productDetail = Mage::getModel('catalog/product')->setStoreId($storeId)->load($this->getParentId($prod)); /** * if the product is not visible or is disabled */ if (!$productDetail->isVisibleInCatalog()) { continue; } /** * if two or more simple products of the same configurable product are ordered */ if (in_array($productDetail->getId(), $sameProduct)) { continue; } $sameProduct[] = $productDetail->getId(); if (!$checkedProducts->getItemById($parentId)) { $checkedProducts->addItem($productDetail); } if (count($checkedProducts) >= $this->getProductsLimit()) { break; } } return $checkedProducts; }