Monday 25 March 2013

upload file in magento


           if($_FILES['productimage']['name'] != ''){    
                $uploader = new Varien_File_Uploader('productimage');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
                $productimage = $_FILES['productimage']['name'];
$path = Mage::getBaseDir() . DS . 'directoryname1' . DS . 'directoryname2' . DS;
                $uploader->save($path, $productimage);
          }

add field in custom module magento admin

go to   app\code\local\package\module\block\adminhtml\module\edit\tab

open file form.php  add custom field


                                                $fieldset->addField("lastname", "text", array(
"label" => Mage::helper("storeowner")->__("Last Name"),
"name" => "lastname",
));


$fieldset->addField("email", "text", array(
"label" => Mage::helper("storeowner")->__("email"),
"name" => "email",
));


in prepareForm function
here are  2 field has been added in this example

Saturday 23 March 2013

magento order get shipping cost


$orderid = 3;
$order = Mage::getModel('sales/order')->load($orderid);

$order->getShippingAmount();

magento order get shipping

$orderid = 3;
$order = Mage::getModel('sales/order')->load($orderid);
$order->getShippingDescription();

get order payment method magento

$payment_title = $order->getPayment()->getMethodInstance()->getTitle();

get customer billing address magento


$customerid = 1;
$visitorData = Mage::getModel('customer/customer')->load($customerid);
$billingaddress = Mage::getModel('customer/address')->load($visitorData->default_billing);
$addressdata = $billingaddress ->getData();
$addressdata['street'];
$addressdata['city'];
$addressdata['postcode'];
$addressdata['region'];
$addressdata['telephone'];

get customer group name magento


$customerid = 1;
$visitorData = Mage::getModel('customer/customer')->load($customerid);
$group = Mage::getModel('customer/group')->load($visitorData->getGroup_id());
$custgroup = $group->customer_group_code;

get customer group name magento


$customerid = 1;
$visitorData = Mage::getModel('customer/customer')->load($customerid);
$group = Mage::getModel('customer/group')->load($visitorData->getGroup_id());
$custgroup = $group->customer_group_code;

change date format in magento


$invoiceid = 3;
$invoice = Mage::getModel("sales/order_invoice")->load($invoiceid);
$orderid = $orderdata['increment_id'];
$time = explode(" ",$invoice['created_at']);
$datearr = explode("-",$time[0]);
$month = strpos($datearr[1], "0");
$mnthnub = ($month == 0) ? substr($datearr[1],1):$datearr[1];
$monthName = date("F", mktime(0, 0, 0, $mnthnub, 10));
$etime = date("g:i a", strtotime($time[1]));
$fineldate = $datearr[2].", ".$monthName.", ".$datearr[0].", ".$etime;
$orderid = $orderdata['increment_id'];
$time = explode(" ",$invoice['created_at']);
$datearr = explode("-",$time[0]);
$month = strpos($datearr[1], "0");
$mnthnub = ($month == 0) ? substr($datearr[1],1):$datearr[1];
$monthName = date("F", mktime(0, 0, 0, $mnthnub, 10));
$etime = date("g:i a", strtotime($time[1]));
$fineldate = $datearr[2].", ".$monthName.", ".$datearr[0].", ".$etime;

magento order item collection



$orderid = 3;
$order = Mage::getModel('sales/order')->load($orderid);

$order_item_collection = $order->getItemsCollection();;
foreach($order_item_collection as $item){
$item->getName();
$item->getSku();
..
..
}