Magento and theme

Source: Internet
Author: User
Tags php foreach

Magento development principles:

1. Do not modify magento's Core.

2. If theme is used, you can modify theme. If a plug-in is required, consider using the plug-in.

3. Standardized writing code

 

Key Points of MAGENTO and theme development

  1. Add and remove javascript and CSS
  2. Use of static Blocks
  3. Setting template
  4. New Page Layout
  5. Common layout syntax
  6. MAGENTO template syntax

 

Common layout files

Syntax rules for catalog. xml layout files

Xml is actually a description of the layout of a page. It contains multiple references (menu, header, left, right ).

Reference is equivalent to multiple core parts in a page, such as header, content, left, right, footer etc.

The reference includes multiple blocks (similar to the block structure in HTML). To ensure reusability and flexibility, the reference template is generally used.

For a block, it may also have image settings, text settings, and link settings. This requires action.

 

 

Common layout files

 

 

Common reference blocks (by default)

 

<Reference name = "root">
<Action method = "setTemplate"> <template> page/2columns-right.phtml </template> </action>
</Reference>

<Reference name = "top. menu"> </reference>

 

<Reference name = "content"> </reference>

<Reference name = "left"> </reference>

<Reference name = "right"> </reference>

<Reference name = "footer_links"> </reference>

<Reference name = "head"> </reference>

 

 

<Reference name = "product.info"> </reference>

<Reference name = "minicart"> </reference>

 

 

 

Common block formats

<Block type = "catalog/navigation" name = "catalog. topnav"
Template = "catalog/navigation/top. phtml"/>

 

 

Common default actions:

<Action method = "addJs" ifconfig = "dev/js/deprecation"> <script> prototype/deprecation. js </script> </action>

<Action method = "addCss"> <stylesheet> css/styles.css </stylesheet> </action>

 

<Action method = "setTemplate"> <template> page/2columns-right.phtml </template> </action>

 

 

<Action method = "addColumnCountLayoutDepend"> <layout> two_columns_left </layout> <count> 4 </count> </action>

<Action method = "setdefagrigridperpage"> <limit> 3 </limit> </action>
<Action method = "addPagerLimit"> <mode> list </mode> <limit> 2 </limit> </action>

 

 

<Action method = "unsetChildren"> </action>

 

 

 

<Block type = "catalog/product_list_upsell" name = "product.info. upsell" as = "upsell_products" template = "catalog/product/list/upsell. phtml">
<Action method = "setColumnCount"> <columns> 4 </columns> </action>
<Action method = "setItemLimit"> <type> upsell </type> <limit> 4 </limit> </action>
</Block>

 

<Action method = "addItem">
<Type> skin_js </type> <name> js/lightbox. js </name>
</Action>

 

<Action method = "addItem"> <type> js_css </type> <name> calendar/calendar-win2k-1.css </name> <params/> <! -- <If/> <condition> can_load_calendar_js </condition> --> </action>
<Action method = "addItem"> <type> js </type> <name> calendar/calendar. js </name> <! -- <Params/> <if/> <condition> can_load_calendar_js </condition> --> </action>
<Action method = "addItem"> <type> js </type> <name> calendar/calendar-setup.js </name> <! -- <Params/> <if/> <condition> can_load_calendar_js </condition>-> </action>

 

 

<Reference name = "seo. sitemap. links">
<Action method = "addLink" translate = "label title" module = "catalog"> <label> Categories Sitemap </label> <url helper = "catalog/map/getCategoryUrl "/> <title> Categories Sitemap </title> </action>

 

 

 

Delete a block or action

Delete A block

<Reference name = "content">

<Remove name = "right. permanent. callout_copy"/>
<Remove name = "right. permanent. callout"/>

</Reference>

 

 

Delete reference

<Reference name = "root">

<Remove name = "right"/>
<Remove name = "left"/>

</Reference>

 

 

 

 

 

Position sequence adjustment of block in the same reference

You can use the 'before' and 'after' attribute in the block tag to position the blocks.

1. before = "-" positions the block before all other blocks
2. after = "-" positions the block after all other block
3. before = "some_block" positions this block before another block with name = "some_block"
4. after = "some_block" position this block after another block with name = "some_block"

For example <block name = "this_block" before = "that_block"/>

 

 

Common APIs applied to themem

Get the home address

<A href = "<? Php echo $ this-> getUrl ('')?> "> <? Php echo $ this->__ ('home')?> </A>

Every Page and PAI in theme

$ This-> getUrl ()

$ This-> getTitle ()

$ This-> getTags ()

 

 

Variable references in CMS page

The image file is from the theme directory in skin.

 

Block: This creates a static block with specified ID.

For example: {block type = 'core/template' template = 'cms/your_page.phtml '}}

Layout: This renders an HTML layout output for the specified layout. The handle attribute expects the name of a layout handle.

For example: {layout handle = "default "}}

Media: This retrieves path of files from root/media folder.

For example: {media url = "images/logo.png "}}

Skin: This gets files from active theme in skin/frontend folder.

For example:

Store: This creates routes and custom URLs for Magento store.

For example: {store url = "contact"} wocould render the full URL for that path.

 

 

 

 

Helper assistant in MAGENTO

 

$ This-> helper ('catalogsearch ')

 

$ This-> helper ('catalogsearch')-> getResultUrl ()

$ This-> helper ('catalogsearch')-> getQueryParamName ()

$ This-> helper ('catalogsearch')-> getEscapedQueryText ()

 

 

Mage: helper ('Directory ')

Mage: helper ('directory')-> currencyConvert ()

 

Image

$ This-> helper ('catalog/image ')

$ This-> helper ('catalog/image')-> init ($ this-> getProduct (), 'image', $ _ image-> getFile ()) -> resize (640,480);?> "

 

 

JS and web frontend

APIs in shopping cart

 

Load javascript or CSS in the template

Var BLANK_IMG = '<? Php echo $ this-> helper ('Core/js')-> getJsUrl('spacer.gif ')?> ';

Var SKIN_URL = '<? Php echo $ this-> helper ('Core/js')-> getJsSkinUrl ('')?> ';

 

 

URL helper

$ This-> helper ("core/url")-> getCurrentUrl ()

Mage::Helper('Core/Url')->GetHomeUrl())

 

 

 

 

 

Magento and common getModel ()

Mage: getModel ('catalog/product ');

 

 

 

 

Static Mage Method

Mage: getUrl ('checkout/cart/add', array ('product' => $ id ))

 

 

 

 

 

CMS APIs

Mage: getSingleton ('cms/page ')

 

Is_home ()

 

$ Checkhome = true;
$ Page = Mage: app ()-> getFrontController ()-
> GetRequest ()-> getRouteName ();
If ($ page = 'cms '){
$ Checkhome = (Mage: getSingleton ('cms/page ')-
> GetIdentifier () = 'home ')? False: true;
}

 

 

Product and API

$ Cat_id = "35 ";

 

Obtain the store ID.

$ StoreId = Mage: app ()-> getStore ()-> getId ();

$ _ ProductCollection = Mage: getResourceModel ('catalog/product _
Collection ')
-> AddAttributeToSelect (array ('name', 'price', 'small _ image', 'short _ description'), 'inner ')
-> AddCategoryFilter (Mage: getModel ('catalog/category ')

> SetStoreId ($ storeId)

> AddStoreFilter ($ storeId)

-> Load ($ cat_id ));

If (! $ _ ProductCollection-> count ()){
Echo $ this->__ ('no products in the homepage category .');
} Else {

Foreach ($ _ productCollection as $ _ product ){

$ _ Product-> getName ()

}

}

 

Get product images

$ This-> getGalleryImages ()

 

<? Php foreach ($ this-> getGalleryImages () as $ _ image):?>
<Li>
<A href = "<? Php echo $ this-> helper ('catalog/image')-> init ($ this-> getProduct (), 'image', $ _ image-> getFile ()) -> resize (640,480);?> "

Rel = "lightbox [rotation]" title = "<? Php echo $ _ product-> getName () ;?> ">

 

helper ('catalog/image')-> init ($ this-> getProduct (), 'thumbnail ', $ _ image-> getFile ()) -> resize (68, 68);?> "Width =" 68 "height =" 68 "alt =" "/>
</A>
</Li>
<? Php endforeach;?>

For standalone image:

$ This-> getImageLabel ();

 

 

Price

$ Price =$ _ product-> getFinalPrice ();
$ Base_currency_code = Mage: app ()-> getStore ()-> getBaseCurrencyCode ();
$ Current_currency_code = Mage: app ()-> getStore ()-> getCurrentCurrencyCode ();
$ Conversion = Mage: helper ('directory')-> currencyConvert ($ price, $ base_currency_code, $ current_currency_code );

Echo Mage: helper ('core')-> currency ($ conversion );

 

 

 

 

Store and API

 

Mage: app ()-> getStore () Various attribute values in the current store

 

$ Store = Mage: app ()-> getStore ();

 

$ Store_id = $ store-> getId ();

$ Store_name = $ store-> getName ();

 

$ BaseCurrencyCode = $ store-> getBaseCurrencyCode ();

 

Getting the base currency:
Mage: app ()-> getStore ()-> getBaseCurrencyCode ();

 

Getting the current currency:
Mage: app ()-> getStore ()-> getCurrentCurrencyCode ();

 

Getting store URL (getUrl ---> identifier in CMS/Page)

Mage: app ()-> getStore ()-> getUrl ("about-us-german ");

 

 

Mage: getStoreConfig ()

Mage: getStoreConfig ('Design/head/title_prefix ')

 

Mage: getStoreConfig ('Design/head/title_suffix ')

 

 

 

Mage object

Mage: getBaseUrl () returns the current URL (the URL value mapped by Document Root)

="<? Php echo Mage: getBaseUrl () ;?> /Skin/frontend/default/rafael/img_products/dont_miss_our_offers.jpg "/> </a>

 

 

 

 

Obtaining front-end files such as images, JS files, and CSS files

 

For template images in skin

Get the image in the skin directory in phtml.

= "<? Php echo Mage: getBaseUrl () ;?> /Skin/frontend/default/rafael/img_products/dont_miss_our_offers.jpg "/> </a>

Another way to get Image URL

getSkinUrl ('images/payment_logos/masterCard.png ');?> "Alt =" master card "/>

 

Tips: the start directory of getSkinUrl is skin.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.