Magento module Easy Topsellers (FREE) and Flat Catalog
subscribe
Magento

Magento module Easy Topsellers (FREE) and Flat Catalog

For anyone experiencing problems using the Easy Topsellers module in combination with the Flat Catalog, simply rewrite the _beforeToHtml() function as follows:

        protected function _beforeToHtml() {

		$storeId = Mage::app()->getStore()->getId();
                $sellDate=$this->getModel()->getSellDate($this->getModel()->getHomepageDaysLimit());
		$collection = Mage::getResourceModel('reports/product_sold_collection')
                                ->setStoreId($storeId)
                                ->addStoreFilter($storeId)
                                ->addUrlRewrite()
								->addOrderedQty()
								->setDateRange($sellDate['startdate'], $sellDate['todaydate'])
								;
		
		if ($collection->isEnabledFlat())
		{
			$collection->getSelect()
						->joinLeft(
							array('cpl' => $collection->getResource()->getFlatTableName()),
								"e.entity_id = cpl.entity_id"
						)
						->where("cpl.visibility IN (?)", 
							array(
								Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, 
								Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH
							)
						);		
		}
		else
		{
			$collection->addAttributeToFilter('cpl.visibility', 
						array(
							'in' => array(
								Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, 
								Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH
							)
						)
			);
		}
		
		$collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
                                ->setOrder('ordered_qty', 'desc')
                                ->setPageSize($this->getModel()->getHomepageProductsLimit())
                                ->setCurPage(1)
				->setOrder('ordered_qty', 'desc');
				

                $catId=$this->getModel()->getHomepageCatID();
                if ($catId>0) {
                    $category = $this->getModel()->getCategory($catId);
                    $collection->addCategoryFilter($category); 
                }

		$this->setProductCollection($collection);
		return parent::_beforeToHtml();
	}

This function resides in app/code/community/Magazento/Easytopsell/Block/Home.php.

I would appreciate your feedback.

Good luck,
Michael.

7 Comments

  1. Good Repair!!!Thank you! Homepage is ok,but how to repair Catalog page?

    • Hi, perhaps you mean Category page? Please be more specific, perhaps also supply a url so I can see the problem. Cheers, Michael.

  2. Hi,thank you for your reply. This function resides in app/code/community/Magazento/Easytopsell/Block/Home.php. In this directory,There have other documents:Category.php Based on your repair,I try to modify this document,it is work. protected function _beforeToHtml() { $storeId = Mage::app()->getStore()->getId(); $sellDate=$this->getModel()->getSellDate($this->getModel()->getCatDaysLimit()); $collection = Mage::getResourceModel(‘reports/product_sold_collection’) ->setStoreId($storeId) ->addStoreFilter($storeId) ->addUrlRewrite() ->addOrderedQty() ->setDateRange($sellDate[‘startdate’], $sellDate[‘todaydate’]) ; if ($collection->isEnabledFlat()) { $collection->getSelect() ->joinLeft( array(‘cpl’ => $collection->getResource()->getFlatTableName()), “e.entity_id = cpl.entity_id” ) ->where(“cpl.visibility IN (?)”, array( Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH ) ); } else { $collection->addAttributeToFilter(‘cpl.visibility’, array( ‘in’ => array( Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH ) ) ); } $collection->addAttributeToFilter(‘status’, Mage_Catalog_Model_Product_Status::STATUS_ENABLED) ->setOrder(‘ordered_qty’, ‘desc’) ->setPageSize($this->getModel()->getCatProductsLimit()) ->setCurPage(1) ->setOrder(‘ordered_qty’, ‘desc’); $c = Mage::registry(“current_category”); $catId = $c->getData(‘entity_id’); if ($catId>0) { $category = $this->getModel()->getCategory($catId); $collection->addCategoryFilter($category); } $this->setProductCollection($collection); return parent::_beforeToHtml(); } This function resides in app/code/community/Magazento/Easytopsell/Block/Category.php.

  3. http://www.magentocommerce.com/magento-connect/magento-mostviewed-mostpopular-products-free-7566.html Could you fix this extension on flat catalog? They are magazento’s expansion. Structure and code are very similar. Thank you !

    • I can give it a shot when I have some free time. I’ll post my findings if I have any news. Cheers, Michael.

  4. http://www.magentocommerce.com/magento-connect/bnm-best-selling-products-new-products-and-most-viewed-products.html this expansion is very good,Could you fix this extension on flat catalog too?

Leave a Reply

You must be logged in to post a comment.

Curs Valutar

26 April 2024
Curs oferit de Banca Națională a României
EUR
4.9765 RON
USD
4.6373 RON
GBP
5.8018 RON