Magento Fishpig Attribute Splash Pages and Flat Catalog
subscribe
Magento

Magento Fishpig Attribute Splash Pages and Flat Catalog

UPDATE: The file needing modifying is app/code/community/Fishpig/AttributeSplash/Model/Mysql4/Page.php.

It would seem the flat catalog problem keeps rearing it’s ugly head in many Magento extensions. In this case the fix is quite simple. Replace the getProductCollection(), with the modified version below:

	public function getProductCollection(Fishpig_AttributeSplash_Model_Page $page)
	{
		$storeId = Mage::app()->getStore()->getId(); // new line added
		$collection = Mage::getResourceModel('catalog/product_collection')
			//->setStoreId($page->getStoreId())
			->setStoreId($storeId);

		/**
		 * Adds the splash page filter
		 * This uses the EAV index so ensure indexes are always up to date
		 */
		$alias = $page->getAttributeCode().'_idx';
		$read = Mage::getSingleton('core/resource')->getConnection('read');
		$storeId = ($page->getStoreId() == 0) ? Mage::app()->getStore()->getId() : $page->getStoreId();
		$collection->getSelect()
			->join(
				array($alias => $this->getTable('catalog/product_index_eav')),
				"`{$alias}`.`entity_id` = `e`.`entity_id`"
				. $read->quoteInto(" AND `{$alias}`.`attribute_id` = ? ", $page->getAttributeId())
				. $read->quoteInto(" AND `{$alias}`.`store_id` = ? ", $storeId)
				. $read->quoteInto(" AND `{$alias}`.`value` = ?", $page->getOptionId()),
				''
			);

		/* Refactored for Flat Catalog */
		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('visibility',
						array(
							'in' => array(
								Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG,
								Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH
							)
						)
			);
		}
		//$collection->addAttributeToFilter('visibility', array('in' => array(2, 4)));
		$collection->addAttributeToFilter('status', 1);
		/* Refactored for Flat Catalog */

		if (Mage::getStoreConfigFlag('attributeSplash/product/hide_out_of_stock', $page->getStoreId())) {
			Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
		}

		if (Mage::getStoreConfigFlag('attributeSplash/product/hide_no_image', $page->getStoreId())) {
			$imageAttributeCode = Mage::getStoreConfig('attributeSplash/product/image_attribute_code', $page->getStoreId());

			if ($imageAttributeCode) {
				$collection->addAttributeToFilter($imageAttributeCode, array(
					'notnull' => '',
					'nteq' => ''
				));
			}
		}

		return $collection;
	}

I modified just two bits, and I am sure you can easily spot them. Good luck and let me know if this fix worked for ya.

Cheers,
Michael.

5 Comments

  1. Thanks for that Michael – fixed our issue perfectly.

  2. Very good.Thank you very much

  3. Very good.Thank you very much

  4. Perfect…what file do I edit? I can’t wait to try it. Thanks.

    • Hi, The file you need to modify is app/code/community/Fishpig/AttributeSplash/Model/Mysql4/Page.php. Cheers, Michael.

Leave a Reply

You must be logged in to post a comment.

Curs Valutar

25 April 2024
Curs oferit de Banca Națională a României
EUR
4.9761 RON
USD
4.6567 RON
GBP
5.7878 RON