Tuesday, 5 March 2013
get Category children id magento
<?php
$cat = Mage::getModel('catalog/category')->load(2); /*load category*/
$subcatcollection = $cat->getChildren();
$subcatrgories = explode(",",$subcatcollection); /* it gives string , convert in array */
?>
get review collection magento
<?php
$reviewcollection = Mage::getModel('review/review')->getCollection(); /*collection */
foreach($reviewcollection as $reviwe){
print_r($reviwe); /*review*/
}
?>
$reviewcollection = Mage::getModel('review/review')->getCollection(); /*collection */
foreach($reviewcollection as $reviwe){
print_r($reviwe); /*review*/
}
?>
Sunday, 3 March 2013
marge category product collection magento
<?php
$merged_ids = array();
$categoryIdArray = array(2,6,5);
foreach(array_unique($categoryIdArray) as $categoryid)
{
$collection = Mage::getModel('catalog/category')->load($categoryid)->getProductCollection();
if($collection->getAllIds())
{
$temp = $collection->getAllIds();
for($k=0;$k<count($temp);$k++){
$merged_ids[] = $temp[$k];
}
unset($temp);
}
}
$merged_collection = Mage::getResourceModel('catalog/product_collection')
->addFieldToFilter('entity_id', $merged_ids)
->addAttributeToSelect('*');
?>
Saturday, 2 March 2013
resize product image magento
$productId = 2;
$width = 200;
$height = 200;
$product = Mage::getModel('catalog/product')->load($productId);
$resizeimage = Mage::helper('catalog/image')->init($product, 'image')->resize($width, $height);
category product collection magento
$categoryId = 3;
$categoryProductCollection = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();
$categoryProductCollection = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();
Collection Filter magento
$modulecollection = Mage::getModel("module/module")->getCollection()-addFilter($attributecode,$value);
add image to product magento
$product = Mage::getModel('catalog/product')->load($productid);
$frontImage = $imagepath/$frontImagename;
$product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
$product->addImageToMediaGallery($frontImage, array('image','small_image','thumbnail'),false,false);
$product->save();
$frontImage = $imagepath/$frontImagename;
$product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
$product->addImageToMediaGallery($frontImage, array('image','small_image','thumbnail'),false,false);
$product->save();
upload file magento
$_FILES['image']['name'];
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg','png','gif'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path.$_FILES['image']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
Subscribe to:
Posts (Atom)