Posted by: james | January 5, 2010

Gmap links..

http://groups.google.com/group/google-maps-api/browse_thread/thread/3aacd6d5ff4d4aee?pli=1
http://groups.google.com/group/Google-Maps-API/browse_thread/thread/b4a09be5259c7493

Advertisements
Posted by: james | October 12, 2009

Render Block from Controller’s Action in Magento..

How can i render any block from controllers action..

in your action code you have to write,

$this->getLayout->createBlock(‘full_path upto that block file..’)
$this->_initAction()          ->_addContent($this->getLayout()->createBlock(‘adminhtml/catalog_product_attribute_edit’)->toHtml                             ->renderLayout();

Posted by: james | October 12, 2009

Basic technique to apply CSS to div or ul or li…

if we have one div its id is new-nav… and in that we have ul, in that li, in that a tag…
so now if we want to apply css then to apply css to ul use this

#new-nav ul { ur css…}

to apply css to li use this

#new-nav ul li { ur css…}

to apply css to a use this

#new-nav ul li a { ur css…}

if you want to apply css when anyone hove on that link then use this..

#new-nav ul li a:hover { ur css…}

now if you want to apply class to any tag..for ex you want to apply class to li.. then do this..
for ex. in our div new-nav in that ul and in that li and you want to apply class active to li…

<div id=”new-nav”>
<ul>
<li>
Now here you want to apply class active to li then in css file you can write..as under
</li>
</ul>
</div>

write in css file like this..

#new-nav ul li.active {ur css….}

thus you can apply class to any tag and then u can use that class in ur html file..

Posted by: james | October 7, 2009

For Calc…

First of all create One Product with no quantity, no price and  all that.. just give sku and name.

$dst = Mage::getBaseDir(‘media’)
so in $dst you will get Directory structure upto media so to get main remoave media from bracket and then use that in this function.

use this under url, if you get success then no prob but if you get any failure then check by default url and generate that random key, because per product its unique, so may be from that you will get it.

or use that function getAddToCartUrl and pass object of product of model class..

onClick = setLocation(‘$dst/checkout/cart/add/product/id’)
Add To Cart == window.location()

so now your product will add to cart and you will redirect to checkout page, so frontend complete…

now for admin panel

public function getAddToCartUrl($product, $additional = array())
{
$additional = array();

if ($this->getRequest()->getParam(‘wishlist_next’)){
$additional[‘wishlist_next’] = 1;
}

return $this->helper(‘checkout/cart’)->getAddUrl($product, $additional);
}
<button onclick=”setLocation(‘<?php echo $this->getAddToCartUrl($_product) ?>’)”><span><?php echo $this->__(‘Add to Cart’) ?></span></button>

Posted by: james | October 7, 2009

what is block type?

while defining block in that block type means like getBlock class call. means in type before ‘/’ its a module name and after ‘/’ it will file name and if it is with under score then there will one folder and in that file will there.

full for of SKU..

SKU (stock keeping unit)

Posted by: james | October 7, 2009

Great Feature of Magento — Inline Translation

if you want to change any text in magento then use inline translation tool. just go to admin panel and in that system–>configuration–> and in that click on developer and in that selcet store view from left and then select yes on inline translate tab.

dont forget to select store from upper left hand side.

so now you can view one book symbol and now go to particular text or string and click on that book symbol near to it and then enter new string and click on submit. and refresh page now that effect will come through over whole site for that word.

but on some page like checkout you can’t use this functionality or in tab where data come from call of AJAX, there you can’t use this functionlaity. SO to change any text at that place just go to csv file and change that. But its risky because of may be some time that value get error and through out whole site you get error.

so to solve that error go to phpmyadmin, i mean to say go to database and on that click on table core_translate.and in that pass that string with value.

For ex. we want to change Account Info to Greek languange then enter this kind of string.

insert into core_translate (string,store_id,translate,locale) values (Namespace_ModuleName::’string want to change’,your store id,locale for that).

in our example my that module store in local in that bank in that transfer and i want to change Account Info so my first argument will be like this..

first Argument : Bank_Transfer::Account Info
second Argument : My store id = 1
third Argument : ?????f???e? ???a??asµ??
foruth Argument : it will be locale name for greek: may be this (el_GR);

thus you can change any word or string using inline translation..
feel free to ask me if you have any question..

for ex. if we have table, whose name is test. and it has two fields frist and second.
and if you want to increment the first field though its not auto increment field or not primary key.
then how can do this??

so for that you have to make any field as unique key, means first of all make unique key any field of that table and then run this query, so you will get expected output.. (I hope so..)

insert into test (frist,second) values(1,2) on duplicate key update frist=frist+1;

Posted by: james | October 3, 2009

How to Create Static Block in magento

<li><a href=”<?php echo $this->getUrl(”)?>”><?php echo $this->__(‘Home1’) ?></a></li>
<li><a href=”<?php echo $this->getUrl(‘warranty/form’)?>”><?php echo $this->__(‘Warranty’) ?></a></li>

Steps to create static block in magento..

first of all go to app/design/frontend/default/default/template/form/data.phmtl

//now here create your own template i have just write code to dispaly hi.

so in data.phtml

<?php
echo “hi”; exit;

?>

now go to app/code/local/Display/Form/Block/Data.php

<?php
class Display_Form_Block_Data extends Mage_Core_Block_Template
{
public function doSomeAction()
{

}
}

now go to app/code/local/Display/Form/etc/config.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<Display_Form>
<version> 0.1.0 </version>
</Display_Form>
</modules>
<global>
<blocks>
<Display_Form>
<class> Display_Form_Block </class>
</Display_Form>
</blocks>
</global>
</config>

dont’ forget to add xml file in etc.so now go to app/etc/Display_Form.xml
<?xml version=”1.0″ encoding=”UTF-8″?>

<config>
<modules>
<Display_Form>
<active>true</active>
<codePool>local</codePool>
<version> 0.1.0 </version>
</Display_Form>
</modules>
</config>

// here your template and view block part has completed. Now its time to display that block on particular page, let’s say you want to display that block on home page, then go to admin panel.

in admin panel click on CMS–>Mange Pages, now you will get list of whole pages, in that click on home page. and in that at the last you will get content. in that at last put this code.

<div>
Example’s Output:
{{block type=”Display_Form/data” template=”form/data.phtml”}}
</div>

and now save this page and check it on home page so at last you will get output of your code..
its an easy because its a static page but if you want to add it at any other page which is coming from any xml file like checkout page or catalog page or product page or customer account page, then you have to specify this block to that particular xml. and also you can give position for that block in that xml file.

for ex.you want to display that block at product view page..

remaining– how to put that block in different pages. please check it..

while defining block in that block type means like getBlock class call. means in type before ‘/’ its a module name and after ‘/’ it will file name and if it is with under score then there will one folder and in that file will there.

Posted by: james | September 30, 2009

Design in Magento

getChildHtml, change in design of layout and block in magento, change design of

<?=$this→getChildHtml(’topLeftLinks’)?> – The getChildHtml() function is the most important function used in our

template. It calls particular block defined in XML file and renders it as HTML , then outputs it to the browser. We

can call blocks from everywhere and from corresponding XML files.

To use getChildHtml(’topLeftLinks’) we must have defined first the child “as” so take a closer look at page.xml

(layout/ folder). Here’s what you should see:

<block type=”page/html_toplinks” name=”top.left.links” as=”topLeftLinks”/>

As we see, getChildHtml(’topLeftLinks’) uses its alias “as” and calls it from the XML. The getChildHtml() function

only allows Magento to call a block if that block was defined in the corresponding XML file.

We can also override this mechanism by using another function call:

<?=$this→getLayout()→getBlock(’top.left.links’)→toHtml()?>

This structure will call the top.search block (based on its name, not its alias “as”) from anywhere in any of our

templates so we do not need to define it everywhere in our XML files. Remember to use the “name” attribute instead of

the “as” attribute with this workaround.

We must be aware that every phtml file and every function will always refer to the corresponding XML file or files.

We can identify used phtml files simply by searching for the following:

<action method=”setTemplate”><template>wishlist/sidebar.phtml</template></action>

Design in Magento, Layout and Blocks in Magento.

first of all there are 3 blocks..
first is structure template, second is content template and last is layout.

The php method getChildHtml(’right’) does not refer in any way to right.phtml. “right” is simply an identifier in

order for templates and the layout file to interact with each other in order to structure and bring content to the

page. Remember, changing the layouts of a page in Magento means no longer relying on manual XHTML inclusion in one

large structural block template such as col_right.phtml. Think of it this way:

There are now three parts to modifying page layout. One is the structural templates, two, content templates, and

three is what Magento calls “layouts”.
Structure templates are templates that simply creates the structural layout of a page – such template exists only to

designate real estate for content inclusion. A sample structural template would look something like the following:
<div><?=$this->getChildHtml(‘header’)?></div>
<div><?=$this->getChildHtml(‘left’)?></div>
<div><?=$this->getChildHtml(‘content’)?></div>
<div><?=$this->getChildHtml(‘right’)?></div>
<div><?=$this->getChildHtml(‘footer’)?></div>

You can see how the XHTML used in a skeleton template is only there to build structural.

A layout arranges the content blocks such as product tags, category listing, mini cart, mini wishlist..etc, then

delivers it to the structural block to be parsed in the assigned order.
All this in human language is basically “Grab all the mini cart, grab the compare products, grab the poll and the

grab the newsletter sign up box, and put all this inside the <div>.” The one that orders this whole

operation, is the layout. Each of the mini-cart, compare products..etc are the content blocks. The <div

class=”col-right”></div> is the structural block.

The layout only knows where to include all the content blocks via the getChildHtml() method used in the structural

template. Using the assigned identifier called “right” as in getChildHtml(’right’), the layout knows where to put all

the content blocks it gathered – inside the <div></div>

For each design theme, you have a default layout, and the subsequent layout updates. The default, is what sets the

default layout for the whole store, and the layout updates is the layout that modifies(updates) the default layout

per store page. So if the default layout says, use 3 columns, but you want your product info page to use 2 columns

only, you’d update the <catalog_product_view> “handle” inside your xml file to reflect this.

ex. if you want to remove compare product block then make comment in this code.
<block type=”core/template” name=”catalog.compare.sidebar”

template=”catalog/product/compare/sidebar.phtml”/>

2. if you want to remove newsletter subscription block then make commment in this code..
<reference name=”right”>
<block type=”newsletter/subscribe” name=”right.newsletter” template=”newsletter/subscribe.phtml”/>
</reference>

3. if you want to remove community poll block then make comment in this code.

<reference name=”right”>
<block type=”poll/activePoll” name=”right.poll”>
<action method=”setPollTemplate”><template>poll/active.phtml</template><type>poll</type></action>
<action method=”setPollTemplate”><template>poll/result.phtml</template><type>results</type></action>
</block>
</reference>

something about page.xml..

So basically your page.xml creates Data Blocks, your .phtml Outputs that data where you want it. Hence, the

names for left, right and so forth in your .phtml.

page.xml manages the layout and content blocks for all pages in your store, so all the updates you need to

make to a page layout can be done from the page.xml file.

setTemplate

Action method setTemplate allows us to change the default .phtml file used in particular block. For example by

navigating to app/design/frontend/default/default/layout/catalog/product/view.xml we can see the reference:

<reference name=”root”>
<action method=”setTemplate”><template>page/2columns-right.phtml</template></action>
</reference>

and by using another <template> value we are allowed to change default .phtml file used on our products

page.Possible values are:

1column.phtml 2columns-left.phtml 2columns-right.phtml 3columns.phtml one-column.phtml dashboard.phtml

As we see in app/design/frontend/default/default/layout/checkout/cart.xml , there also additional 2 values for empty

and non-empty cart

<action method=”setCartTemplate”><value>checkout/cart.phtml</value></action>
<action method=”setEmptyTemplate”><value>checkout/cart/noItems.phtml</value></action>
<action method=”chooseTemplate”/>

The method chooseTemplate is used to set a template (setCartTemplate / setEmptyTemplate) depending on quantity of

items in our cart. If we have more than 0 than the

<action method=”setCartTemplate”><value>checkout/cart.phtml</value></action>
is used.
If we have no items in cart then the following will be used.

<action method=”setEmptyTemplate”><value>checkout/cart/noItems.phtml</value></action>

The function provided by the Model is shown below:

public function chooseTemplate()
{
if ($this->getQuote()->hasItems()) {
$this->setTemplate($this->getCartTemplate());
} else {
$this->setTemplate($this->getEmptyTemplate());
}
}

That should clarify how we can use this particular switch. Depending on our needs we can write custom functions in

our blocks and than assign a template depending on parameters returned by a function.

addCss

This method allows us to add an additional CSS file to our page on per-page basis or globally for our template. If we

use a reference name “head” and action method addCss by using

<reference name=”head”>
<action method=”addCss”><link>style.css</link></action>
</reference>

then our page will have an additional line of code to attach the CSS file, for example:

<link rel=”stylesheet” type=”text/css” media=”all”

href=”http://www.ourstore.com/skin/frontend/default/default/css/style.css&#8221; ></link>

As we can see, the <link> path refers to the /skin/frontend/default/default/css/ folder.

addJs

The above method allows us to attach a .js script in the same way as we attached a CSS file. The script path refers

to the /js/varien/ folder but we can change it to suit our needs. FIXME How is that done?

<reference name=”head”>
<action method=”addJs”>varien/script.js</action>
</reference>

It will add a script to our page with src attribute of

<script src=”http://www.ourstore.com/js/varien/product.js&#8221; />
Adding custom CSS and JS files to a layout (part II)

There are 2 ways of adding custom js and css files to our template. The recommended way is by extending the head

section in the default XML file. But you also have the ability to add the files directly in the particular root

template file.

<script type=”text/javascript” src=”<?=$this->getJsUrl()?>varien/js.js” ></script>
<script type=”text/javascript” src=”<?=$this->getJsUrl()?>varien/form.js” ></script>
<script type=”text/javascript” src=”<?=$this->getJsUrl()?>varien/menu.js” ></script>

if you want to make any block before or after or left or right then you can do that bu just adding this keywords.
ex.
on product page community pole is at last in right bar but if you want to move that block at upper side then you

can follw this changes.

first of all go to admin panel and enable path hint, so you will get it easily that from where that side bar

come.so after that you can view that that side bar come from checkout.xml so now copy that block name.

<reference name=”right”>
<block type=”checkout/cart_sidebar” name=”cart_sidebar” template=”checkout/cart/sidebar.phtml” before=”-“>
</block>
</reference>
here copy cart_sidebar — block name and paste it in poll.xml with tag before. so now our poll.xml will look like

this..
<reference name=”right”>
<block type=”poll/activePoll” name=”right.poll” before=”cart_sidebar”>
<action method=”setPollTemplate”><template>poll/active.phtml</template><type>poll</type></action>
<action method=”setPollTemplate”><template>poll/result.phtml</template><type>results</type></action>
</block>
</reference>

here i add before in default so on every page it will look at top in side bar.

thus these are main changes for magento design.. using this keywords before,after,left,right.

if you want to display any block at first or at top of level then use before=”-” this.
if you want to display any block before some block then use before=”block_name of under”
if you want to display any block after some block then use after=”block_name of upper”
if you want to display any block in right side then use right in reference name.
for ex. <reference name=”right”>
<block type=”checkout/cart_sidebar” name=”cart_sidebar” template=”checkout/cart/sidebar.phtml”

before=”-“>
</reference>

here this block will display in right bar and also at the top. same as use left if you want to display block at left

direction.

now all the headers change can be done from header.phtml and from xml..
all the change for footer links can be done from footer.phtml. and in the footer the upper three links of About Us

and Customer Service and Mobile come from static block so to modify it go to admin panel and make changes.
and other all links come from different xml so to make changes in that go to respected xml file.

the another major part is 1-column.phtml,2-column.phtml or 3-column.phtml means there you can define layout for every

page that that page is either 1-column or 2-column or 3-column. if you want to make change in whole site then go to

page.xml and in that in deafult tag change template as you wish.

whenever you make foreign key at that time before making foreign key that key must be unique key means u have to

define that key as index or indices…

Posted by: james | September 29, 2009

Important Notes On Magento..

to add new tab in right hand side add system.xml and in that add either tab or section. and to display in that any thing you have to use group tag in xml file and also use all the fields.. please reffer any default system.xml and also check another thing from there also….

to get input type like text or dropdown use getFrontendInout() and to get simple data from any input type use getData but if you use select or multiselect then you have to use getAttributeText()..

in system tab in configuration tab all data will be stored directly in table core_config_data…

use getStoreConfig(‘path’) to get directly all the data… and then overwrite view file for product or whatever file related to your module and then apply logic and all that.. and also you can check that if you give input type yes/no then in database it will store that value as either 1 or 0….

whenever you use either backend model or something like _beforesave or aftersave method or afterload or method which has an observer.. then in that method always at the end use syntax like  return parent::_beforesave means method name and all that..please see the deafult methods….

getcollection will call method like select * from tablename..
ex.
$op1 = Mage::getModel(‘bundle/selection’);
$collection1 = $op1->getCollection();
here it will retrive all the data and now if you want to use where condition on some field then call addFieldToFilter function and in that pass column name as argument.

ex.
$op1 = Mage::getModel(‘bundle/selection’);
$collection1 = $op1->getCollection();
$collection1->addFieldToFilter(‘option_id’,$optionIds[0]);

now here option_id will be in where condition. now to see select query use getSelect method.
ex.
$op1 = Mage::getModel(‘bundle/selection’);
$collection1 = $op1->getCollection();
echo $collection1->getSelect()->where(‘option_id = ‘,8);

so now here it will print select query and in some cases this function faild to call because it might think that passed argument is attribute and it thrwos error but we pass here field so it throws error.
so to solve it we have to call directly where on select query means first of all get all cokllection and on that call getSelect function so you will get whole select query and now on that call where function.

ex.
require_once(‘C:/www/magento/app/Mage.php’);
Mage::app(‘admin’);

$op1 = Mage::getModel(‘bundle/selection’);
$collection1 = $op1->getCollection();
echo $collection1->getSelect()->where(‘option_id = ‘,8);

Older Posts »

Categories