0

What is the code to do it he can see three products in one category only??

<?php

$category = Mage::getModel('catalog/category')->load(68);
$product->addCategoryFilter($category);    

$collection->addStoreFilter();   

$catid = '68'; //your category id
$category = new Mage_Catalog_Model_Category();
$category->load($catid); // this is your category id!
$collection = $category->getProductCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 4;
$collection->setPage(1, $numProducts)->load();
foreach($collection as $product) {
$product = Mage::getModel('catalog/product')->load($product->getId()); /* Load Products by ID*/
echo $product->getName();
echo $product->getShortDescription();
endforeach;
?> 

1 Answer 1

0
<?php

$category = Mage::getModel('catalog/category')->load(68);
$product->addCategoryFilter($category);    

$collection->addStoreFilter();   

$catid = '68'; //your category id
$category = new Mage_Catalog_Model_Category();
$category->load($catid); // this is your category id!
$collection = $category->getProductCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 4;
$collection->setPage(1, $numProducts)->load();
foreach($collection as $product) {
$product = Mage::getModel('catalog/product')->load($product->getId()); /* Load Products by ID*/
echo $product->getName();
echo $product->getShortDescription();
endforeach;
?> 
1
  • mi serve assolutamente una mano!! grazie Commented Oct 10, 2016 at 13:27

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.