Header Ad

Saturday, March 27, 2010

Ability to Get Products under a category in Magento

Hi,

We can use the following code to get the products under a category.



$_categories=$this->getCurrentChildCategories();

$_category = $this->getCurrentCategory();
$subs = $_category->getAllChildren(true);
$result = array();
foreach($subs as $cat_id) {
$category = new Mage_Catalog_Model_Category();
$category->load($cat_id);
$collection = $category->getProductCollection();
foreach ($collection as $product) {
$result[] = $product->getId();
}

}
shuffle($result);
?>

Monday, March 8, 2010

How to find in between value from an array in javascript

Take the following code is an simple example for finding bigger value in an array


var foo = new Array("222","323","314","431","422");
var biggest = 10;
for (x=0;xif (foo[x] > biggest) {
biggest = parseint(foo[x]); //right here
}
}
document.write(biggest);