Tuesday 10 December 2013

get payment method in cart magento

for handling payment method display in cart we use event handling  we use config.xml in module or in custom module

app/code/local/regitration/field/etc/config.xml

<?xml version="1.0"?>
<config>
<frontend>
<events>
    <payment_method_is_active>
        <observers>
            <Regitration_Field_Model_observer>
                <class>Regitration_Field_Model_observer</class>
                <method>payment_method_is_active</method>
            </Regitration_Field_Model_observer>
        </observers>
    </payment_method_is_active>
</events>
  </frontend>
</config>



define action in observer file


app/code/local/regitration/field/model/observer.php

<?php
class Regitration_Field_Model_observer {

public function payment_method_is_active($observer){
     $event           = $observer->getEvent();
    $method          = $event->getMethodInstance();
    $result          = $event->getResult();
    $session = Mage::getSingleton('checkout/session')->getQuote();
$shippiingcarriers =  $session->getShippingAddress()->getShippingMethod();
            if ($shippiingcarriers == 'flatrate_flatrate' ){
                    if($method->getCode() == 'cashondelivery' OR $method->getCode() == 'checkmo' OR $method->getCode() == 'paypal_standard' or $method->getCode()=='purchaseorder'){
                        $result->isAvailable = false;
                    }else{
                        $result->isAvailable = true;
                }
            }

}
}
 ?>

Wednesday 27 November 2013

get cross cell product collection magento

$cart = Mage::getModel('checkout/cart')->getQuote();
$productid = array();
$crossc = array();
foreach ($cart->getAllItems() as $item) {
    $productid[] = $item->getProduct()->getId();
foreach($item->getProduct()->getCrossSellProducts() as $crosscell){
$crossc[] = $crosscell['entity_id'];
}
}
$crossce = array_diff($crossc, $productid);
$collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
$collection->addIdFilter($crossce);
$collection->setPageSize(4);

upcell product collection magento

$pid = 2;
$product = Mage::getModel('catalog/product')->load($pid);
$collect = $this->getProduct()->getUpSellProductCollection();
$collect->getItems();

Friday 1 November 2013

custom price in cart Magento

Add event in module  etc/config.xml

<?xml version="1.0"?>
<config>
</frontend>
        <events>
            <checkout_cart_product_add_after>
                <observers>
                    <Custom_Event_Model_Observer>
                        <type>singleton</type>
                        <class>Custom_Event_Model_Observer</class>
                        <method>Mytestmethod</method>
                    </Custom_Event_Model_Observer>
                </observers>
            </checkout_cart_product_add_after>
        </events>
</frontend>
</config>




calculate your price in Custom/Event/Model/Observer.php



class Custom_Event_Model_Observer {

    public function Mytestmethod(Varien_Event_Observer $observer) {
 $item = $observer->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        $price = 66;
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);
        $item->getProduct()->setIsSuperMode(true);

    }
}





Thursday 24 October 2013

Remove product image magento

$_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load(2);
$removes[0] = a/b/aaa.png;
$removes[1] = a/c/bbb.png;
if(count($remove)>0){
 $attributes = $_product->getTypeInstance ()->getSetAttributes ();
 $gallery = $attributes ['media_gallery'];
$galleryData = $_product->getMediaGallery();
foreach($removes as $remove) {
foreach($galleryData['images'] as $image) {
if($remove==$image['file']){
$gallery->getBackend ()->removeImage( $_product, $image ['file'] );
}
}
}
$_product->save ();
}

Tuesday 8 October 2013

multi select in custom module magento

$tool_cat_Arr = array(array('value' => '1', 'label' => 'Shirt'), array('value' => '2', 'label' => 'Tshirt'), array('value' => '3', 'label' => 'Custom'));


$fieldset->addField("tool_cat", "multiselect", array(
"label" => Mage::helper("storeinfo")->__("Tool Category"),
"name" => "tool_cat",
"values" => $tool_cat_Arr

));

filter in custom module magento

$stored = 25;

$storeinfo = Mage::getModel("storeinfo/storeinfo")->getCollection()->addFilter('storeowner_id',$stored)->load();

$storeinfoid = $storeinfo->getAllIds();

$Storeinfomodel = Mage::getModel("storeinfo/storeinfo")->load($storeinfoid[0]);

Wednesday 18 September 2013

aad to cart product with custom option, super attribute magento

$cartarray = array($textaria_option => $instructions_text,
 $width_option_id => $width,
 $height_option_id => $height,
 $side_optionId => $side_optionVal,
 );
foreach($cartarray as $key=>$val){
if($val!= ''){
$arv[$key] = $val;
}
}

$productIdtoadd=$productDub->getId();
$cart = Mage::getSingelton('checkout/cart');
$cart->addProduct($productIdtoadd, array(
'qty' => $qty,
'total_price'=>$total,
'super_attribute' => array($attributeid =>$assproductColorOptionId),
'options' =>$arv
)
);

Tuesday 17 September 2013

get product custom option magento

$priductid = 82;
$product = Mage::getModel('catalog/product')->load($priductid);

foreach ($product->getOptions() as $o) {
                              $values = $o->getValues();
$optionType = $o->getType();/*********TYPE************/
  $o->getId(); /************getId*****************/

                                     /* dropdown type custom option */
if ($optionType == 'drop_down') {
                                    foreach ($values as $k => $v) {
$drpdoption = $v->getData();
                                    }
                                }
                                       /* end dropdown type custom option */

}

Friday 30 August 2013

save+Edit shipping title+name+Error Message magento

$shipmethods = Mage::getSingleton('shipping/config');

$title = "Aditya_title";
$name = "Aditya_Name";
$Errormessage= "This is shipping error Error Message";


$code = 'shipping_code';


$shipmethods->saveConfig('carriers/'.$code.'/title', "$title", 'stores');
$shipmethods->saveConfig('carriers/'.$code.'/name', "$name", 'stores');
$shipmethods->saveConfig('carriers/'.$code.'/specificerrmsg', "$Errormessage", 'stores');

magento get shipping method


$shippingmethods = Mage::getSingleton('shipping/config');
foreach($shippingmethods as $code =>$carrier){
     $shipTitle = Mage::getStoreConfig('carriers/'.$code.'/title');
     $shipName = Mage::getStoreConfig('carriers/'.$code.'/name');
     $shipErrorMsg = Mage::getStoreConfig('carriers/'.$code.'/specificerrmsg');
}

get data out side of magento

get data out side of magento

include  "app/Mage.php";
Mage::app();


$customModule = Mage::getModel('custommodule/custommodule')->getCollection()->getData();

Saturday 17 August 2013

Magento Add status field in module

open app/code/locel/Package/Module/Block/Adminhtml/Font/Grid.php



$this->addColumn("status", array(
"header" => Mage::helper("Module")->__("status"),
"index" => "status",
"type" => "options",
"options" => Package_Module_Block_Adminhtml_Font_Grid::getValuArray1(),
));


add function getValuArray1 in Grid.php



static public function getValuArray1(){
$data_array1 = Array();
$data_array1[0]='Enabled';
$data_array1[1]='Disabled';
return($data_array1);
}

Tuesday 6 August 2013

magento add event

create new module



add in magento
after that go to app/code/local/package/module/etc/config.xml


find "<frontend>" tag and put the code as given


<events>
            <event>
                <observers>
                    <Package_Module_Model_Observer>
                        <type>singleton</type>
                        <class>Package_Module_Model_Observer</class>
                        <method>Mytestmethod</method>
                    </Package_Module_Model_Observer>
                </observers>
            </event>
        </events>



then go to app/code/local/package/module/model


create a file for event like observer.php
and put the code give for event

some thing like this

<?php
class Package_Module_Model_Observer_Observer {

public function Mytestmethod($observer) {
/*write your here code*/
//$observer->getEvent();
//$event->getProduct();

}
 ?>

Monday 5 August 2013

magento redirect on custom url after login

<?php

if (!Mage::getSingleton("customer/session")->isLoggedIn())
{
$session = Mage::getSingleton("customer/session");

 $session->setBeforeAuthUrl(Mage::helper("core/url")->getCurrentUrl());

$customerLoginURL = $this->getBaseUrl() . "customer/account/login";

Mage::app()->getFrontController()->getResponse()->setRedirect($customerLoginURL)->sendResponse();

 }
 ?>

Friday 14 June 2013

add image in custom module grid magento


create folder on given module path path
code\local\Package\Module\Block\Adminhtml\Module\Renderer

then create file in given folder Image.php

and put the code as suggested.



<?php
class Package_Module_Block_Adminhtml_Module_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
   
    public function render(Varien_Object $row)
    {
        $html = '<img width="75" height="75" ';
        $html .= 'id="' . $this->getColumn()->getId() . '" ';
        $html .= 'src="' . Mage::getBaseUrl('media').$row->getData($this->getColumn()->getIndex()) . '"';
        $html .= 'class="grid-image ' . $this->getColumn()->getInlineCss() . '"/>';
      //  $html .= '<br/><p>'.$row->getData($this->getColumn()->getIndex()).'</p>';
        return $html;
    }
}
?>

save file
then go to grid file path is given bellow

app\code\local\Package\Module\Block\Adminhtml\Module\Grid.php

and  add new column in following ways



$this->addColumn('image', array(
'header'    => Mage::helper('module')->__('image'),
'align'     =>'left',
'index'     =>'image',
'renderer' =>'module/adminhtml_module_renderer_image'
));



Tuesday 4 June 2013

get associated product configrable product magento

$productId = 3;
$product = Mage::getModel('catalog/product')->load($productId);
$configrable = $product->getTypeInstance()->getUsedProducts();
foreach($configrable as $config){
                  $config->getId();
                  $config->name;
                  }

Friday 17 May 2013

include js file in header magento

 add your js file in your magento js folder in   magento/js/myfolder

open page.xml file

put this code in page.xml

<action method="addJs"><script>myfolder/myjs.js</script></action>




add link at top link position magento


adding help page link
   open youre theam layout page xml  put this code inside header block



<block type="page/template_links" name="top.links" as="topLinks">
<action method="addLink" translate="label title"><label>Help</label><url>help</url><title>Help</title><prepare/><urlParams/><position>1</position></action>
</block>

Tuesday 30 April 2013

language changer in header magento

open your app/design/frontend/package/theam/template/page/html/header.phtml

put this code in your header.phtml
<?php echo $this->getChildHtml('store_language') ?>



open your app/design/frontend/package/theam/layout/xml/page.xml

it will already have code


<block type="page/html_header" name="header" as="header">
                <block type="page/template_links" name="top.links" as="topLinks"/>
                <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
                <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
                    <label>Navigation Bar</label>
                    <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
                </block>
                <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
                    <label>Page Header</label>
                    <action method="setElementClass"><value>top-container</value></action>
                </block>
            </block>



make sure code in bold itelic must be at the place




app/design/frontend/package/theam/template/page/switch/language.phtml
file should be on place which will contain code



<?php if(count($this->getStores())>1): ?>
<div class="form-language">
    <label for="select-language"><?php echo $this->__('Your Language:') ?></label>
    <select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
    <?php foreach ($this->getStores() as $_lang): ?>
        <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
        <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($_lang->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>






currency changer in header magento

1-create local.xml file



<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="header">
            <block type="directory/currency" name="custom_currency_selector" template="currency/currency.phtml"/>
        </reference>
    </default>
</layout>

and place it in your   app/design/frontend/package/theam/layout/    folder









currency.phtml  should be in your  app/design/frontend/package/theam/template/currency/


<?php if($this->getCurrencyCount() > 1): ?>
<div class="form-language">
    <label for="custom-currency-selector"><?php echo $this->__('Your Currency:') ?></label>
    <select onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
        <option value="<?php echo $this->getSwitchCurrencyUrl($_code)?>"
            <?php if($_code == $this->getCurrentCurrencyCode()): ?>
                selected="SELECTED"
            <?php endif; ?>>
            <?php echo $_code ?>
        </option>
        <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>







header.phtml which path is       app/design/frontend/package/theam/template/page/html/      already contain code  given blow if it is not there then add it in your

<?php echo $this->getChildHtml('custom_currency_selector') ?>





and last thig go to        admin->system->configuration       select your       current configuration scope
go to      Currency Setup select your allowed currency   and make sure use default should not be checked















Sunday 21 April 2013

change store phone number magento

$Aditya = new Mage_Core_Model_Config();
$stphne = '1234567890';

$Aditya ->saveConfig('general/store_information/phone', $stphne, 'stores', 2);

$Aditya ->saveConfig('general/store_information/phone', 'value', 'scope', STORE_ID);

change store address magento


$Aditya = new Mage_Core_Model_Config();
$stnm = "b-67,okhla, phase1";
$Aditya ->saveConfig('general/store_information/address', $stnm, 'stores', 2);



$Aditya ->saveConfig('general/store_information/address', 'value', 'scope', STORE_ID);

Wednesday 10 April 2013

get order data magento

$orders = Mage::getModel('sales/order')->getCollection();
foreach ($orders as $order){
$order->getIncrementId();
       $order['customer_firstname'];
        $order['customer_lastname'];
       $order['base_subtotal'];
        $order['grand_total'];
        $order['status'];
        $order['created_at'];
        $order['updated_at'];
    }

get Invoice data magento


$orders_invoice = Mage::getModel("sales/order_invoice")->getCollection(); 
      foreach($order_invoice as $val){
           $invoice = $val->getData();
           $order = Mage::getModel('sales/order')->load($invoice["order_id"]);
           $orderdata = $order->getData();
           $totaldue = $orderdata['total_due'];
           $grandtotal = $orderdata['grand_total'];
           $status = ($totaldue == 0) ? 'Paid':'unpaid';
           $order->getStatusLabel();
           $cfirstname = $orderdata['customer_firstname'];
           $clastname = $orderdata['customer_lastname'];
           $increment_id = $orderdata['increment_id'];
    }

Monday 8 April 2013

edit cms page magento

$pageid = 2;
$currentpage = Mage::getModel('cms/page')->load($pageid);

$currentpage->setTitle('pagetitle';
$currentpage->setIdentifier('pageidentifire');
$currentpage->setContent('pagecontant');
$currentpage->setIs_active(1);
        $currentpage->save();

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

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


Tuesday 5 March 2013

review collection magento

Category children magento

magento aditya: Magento get Category children id

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*/
}
 ?>

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...

Thursday 31 January 2013

add new product magento




/* udate product */
$_product = Mage::getModel('catalog/product')->load(4);

/* Add product */
$_product = Mage::getModel('catalog/product');



$_product->setTypeId('simple');
$_product->setWebsiteIDs(array(0));
$_product->setStoreIDs(array(0));
$_product->setAttributeSetId(9);

$_product->setName('name');

$_product->setDescription(description');

$_product->setShortDescription('shortdescription');

$_product->setSku('sku');


$_product->setCategoryIds(array('2');


$_product->setWeight('1');


$_product->setStatus('1');


$_product->setUrl_key('producturl');


$_product->setPrice('20');


$_product->setStockData(array(
        'is_in_stock' => 1,
        'qty' =>1,
    ));

$_product->save();




Sunday 20 January 2013

load product magento



$product = Mage::getModel('catalog/product')->load($productId);



get product data
 ($product->getProductAttributeCode;) or ($product->get attribute method;)



product id is always get through attribute method
$product->getId();

you can see product attribute code in admin->catalog->attributes->manage attributes


$product->get attribute method                            $product->getProductAttributeCode
                 ||                                                                              ||
$product->getName();                       or                         $product->name;
$product->getThumbnail();                   or                       $product->thumbnail;
$product->getImage();                         or                       $product->image;

.....