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();

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();

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);

Wednesday 20 February 2013

assign new related product in bundled product magento


$param = array(
           $productid=>array(
                  'position'=>0
            ),
            $productid=>array(
                  'position'=>0
            ));



$related_product = $product->getRelatedProductCollection();




foreach($related_product as $rproduct){
$rlateproduct = Mage::getModel('catalog/product')->load($rproduct->getId());
$data[$rlateproduct->getId()] = array('position'=>0);

}



if($data != ""){
$result = $param + $data;
}
else{
$result = $param;
}




$product->setRelatedLinkData($result);
$product->save();


Tuesday 19 February 2013

get user login magento

<?php

 $isloggedin = Mage::getSingleton('customer/session')->isLoggedIn();

it will return 1;


 ?>

Monday 18 February 2013

get Order data magento


$orderid = 1;
$orderdata = Mage::getModel('sales/order')->load($orderid);
$orderdetail = $orderdata->getData();
$items = $orderdata->getAllItems();
$orderdata->getShippingAddress()->getFirstname();
$orderdata->getShippingAddress()->getLastname();
foreach ($orderdata->getShippingAddress()->getStreet() as $street)
   {
    echo $street;
   }
$orderdata->getShippingMethod();
$orderdata->getPayment()->getMethodInstance()->getTitle();





if you wan to see hole order data


echo "<pre>";
print_r($orderdata);
echo "</pre>";

add new product magento

ADITYA: add new product programetically: /* udate product */ $_product = Mage::getModel('catalog/product')->load(4); /* Add product */ $_product = Mage::getModel('catalog/pro...