Friday 30 August 2013

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