0

I have a "New Arrival" Category. I need to show the Latest product of the top level category ( Mens->New arrival) and limit the products. I have tried to override the below category block. But not achieve that.

File Path : \\app\code\core\Mage\Catalog\Model\Category.php

if($this->getId()==463){ // New arrival Category ID
    $category = Mage::getModel('catalog/category')->load(18);   // Mens category ID            
    $collection = Mage::getResourceModel('catalog/product_collection')
        ->setStoreId($this->getStoreId())
        ->addCategoryFilter($category)->setPageSize(1,10);
}else{
    $collection = Mage::getResourceModel('catalog/product_collection')
        ->setStoreId($this->getStoreId())
        ->addCategoryFilter($this);
}

2 Answers 2

1

Try below code:

$_categoryId = 18;
$category = Mage::getModel('catalog/category')->load($_categoryId );
$productCollection = $category->getProductCollection();
$productCollection
        ->addStoreFilter()
        ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
        ->addUrlRewrite();

$productCollection->getSelect()->limit(20);
7
  • I already tried above code, but return all products for that category. Its not assigned the product collection.
    – Rat
    Apr 21, 2018 at 7:24
  • @Rat , try updated code above Apr 21, 2018 at 7:27
  • its not working. while printing the $collection get the 20 produts for above code. But not assigned the productcollection of actual magento
    – Rat
    Apr 21, 2018 at 7:32
  • @Rat , i updated code. try please. Also flat category is enabled in your site? Apr 21, 2018 at 8:30
  • Raiput , Flat category is disabled. I tried the above code, its loading long time
    – Rat
    Apr 21, 2018 at 8:55
0

Edit Your code

->setPageSize(1,10);

to

->setPageSize(10);

Your Answer

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

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