0

I have these code on my homepage:

list_home.phtml:

$_productCollection = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToSelect('*')
                ->setVisibility(array(2,3,4))
                ->setOrder('created_at', 'desc')
                ->setPage(1, 48);

list_featured.phtml:

$preorderAttribute = 'featured';
$preorderValue = 'Yes';

$_productCollection = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter($preorderAttribute, array(
                    'eq' => Mage::getResourceModel('catalog/product')
                        ->getAttribute($preorderAttribute)
                        ->getSource()
                        ->getOptionId($preorderValue)
                ))

                ->setVisibility(array(2,3,4))
                ->setOrder('created_at', 'desc')
                ->setPage(1, 12);

Both of which are called from the 'home' CMS page with this:

<div class="category-title">
<h1>Best Sellers!</h1>
</div>
<p>{{block type="catalog/product_list" category_id="4" template="catalog/product/list_featured.phtml"}}</p>
<div class="category-title">
<h1>Newest Additions!</h1>
</div>
<p>{{block type="catalog/product_list" category_id="4" template="catalog/product/list_home.phtml"}}</p>

But after some category changes, e.g. adding some categories and moving them in order or descendence, the homepage suddenly gives nothing as you can see.

I'm totally at a loss. Thus far I tried changing category_id to other categories, refreshing the caches, etc. but nothing worked.

The template code in the .phtml files seems fine to me.

Why is this happening? How to fix this?

2 Answers 2

1

Got rid of this:

->setVisibility(array(2,3,4))

And it's all right now.

1

To filter a product collection to show only products visible in the current store, use this instead:

$_productCollection
    ->addStoreFilter()
    ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

A general recommendation: Instead of addAttributeToSelect('*') load only the attributes that you need. In product listing, the following is usually sufficient:

$_productCollection
    ->addMinimalPrice()
    ->addFinalPrice()
    ->addTaxPercents()
    ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
    ->addUrlRewrite();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.