Saturday 23 March 2013

magento get current currency code


 $storeid = 1;
 $currencyCode = Mage::app()->getStore($storeId)->getCurrentCurrencyCode(); /* Currncy Code*/

magento get current currency symbol



 $storeid = 1;
 $currencyCode = Mage::app()->getStore($storeId)->getCurrentCurrencyCode(); /* Currncy Code*/
$currencySymbol = Mage::app()->getLocale()->currency($currencyCode)->getSymbol(); /* Currency Symbol */

magento generate invoice order



$orderId = 2;
$order = Mage::getModel('sales/order')->load($orderId);

$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(false);
$invoice->getOrder()->setIsInProcess(true);
$order->addStatusHistoryComment('invoice by Aditya.', false);
$transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($invoice)
                    ->addObject($invoice->getOrder());
                $transactionSave->save();

magento ship order



$orderId = 2;
$order = Mage::getModel('sales/order')->load($orderId);

$shipment = $order->prepareShipment();
 $shipment->register();
 $order->setIsInProcess(true);
 $order->addStatusHistoryComment('ship by aditya.', false);
 $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)      
  ->addObject($shipment->getOrder())
   ->save();

Saturday 16 March 2013

create and download zip


<?php

$image = $_REQUEST['img'];
$source = $_SERVER['DOCUMENT_ROOT']."/sourcefolder/".$image
$orderid = $_REQUEST['orderid'];

$zip = new ZipArchive();
$DestFilePath=$orderid.".zip";
$destinat  = Mage::getBaseDir().'/zip/'.$DelFilePath;
$destinat = $_SERVER['DOCUMENT_ROOT']."/destination/".$DestFilePath;
if(file_exists($destinat)) {
    unlink ($destinat);
}
if ($zip->open($destinat, ZIPARCHIVE::CREATE) != TRUE) {
        die ("Could not open archive");
}
$zip->addFromString(basename($source), file_get_contents($source));
$zip->close();

/**************************  Download file ********************************/
$file = $orderid.'.zip';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));
header( "Content-Description: File Transfer");
@nl2br(readfile($file));
/**************************  end Download file ********************************/
?>

Sunday 10 March 2013

change customer password magento


<?php
$customer = Mage::getModel('customer/customer')->load($_REQUEST['custid']);
$oldpassword = $_REQUEST['oldpassword']
$passwordhash = $customer['password_hash'];
$phasharray = explode(":",$passwordhash);
$passpostfix = $phasharray[1];
$completeOldPassword = $oldpassword.":".$passpostfix;
if($completeOldPassword==$passwordhash){
$customer->setPassword($_REQUEST['newpass']);
$customer->save();
}
?>

duplicate entry error in saving product magento

you are triying to save product again with same information
$product->save();

save product once when you update same product use
$product->getResource()->save($product);

hope it will be helpfull


Friday 8 March 2013

Cannot complete this operation from non-admin area magento


Mage::register('isSecureArea', true); /* set secure admin area*/
 Mage::getModel('review/review')->load($review)->delete(); /* Your operation */
  Mage::unregister('isSecureArea'); /* un set secure admin area*/

get customer data magento

$id = 3;
$customer = Mage::getModel('customer/customer')->load($id);

$customer->getFirstname();
$customer->getMiddlename();
$customer->getLastname();
$customer->getEmail();