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'];
    }