Git Product home page Git Product logo

magento-cheat-sheet's Introduction

Magento Cheat Sheet

Frontend local.xml snippets

Change page template

<reference name="root">
    <action method="setTemplate"><template>page/template_file.phtml</template></action>
</reference>

Add/remove CSS/JS

<reference name="head">
    <action method="addItem"><type>skin_css</type><name>css/file.css</name><params/></action>
    <action method="addItem"><type>skin_js</type><name>js/file.js</name><params/></action>
    <action method="removeItem"><type>skin_css</type><name>css/file.css</name><params/></action>
    <action method="removeItem"><type>skin_js</type><name>js/file.js</name><params/></action>
</reference>

Move block position

<reference name="old_parent">
    <action method="unsetChild"><name>block_name</name></action>
</reference>
<reference name="new_parent">
    <action method="insert"><block>block_name</block></action>
</reference>

Remove block

<remove name="block_name" />

Add crumb to breadcrumbs

<reference name="breadcrumbs">
    <action method="addCrumb">
        <crumbName>Link Text</crumbName>
        <crumbInfo>
            <label>Link Text</label>
            <title>Link Text</title>
            <link>/link-url</link>
        </crumbInfo>
    </action>
</reference>

Insert CMS block - usage: $this->getChildHtml('relevant_name')

<block type="cms/block" name="relevant_name">
    <action method="setBlockId"><block_id>static_block_identifier</block_id></action>
</block>

Insert template file - usage: $this->getChildHtml('relevant_name')

<block type="core/template" name="relevant_name" template="page/html/template_file.phtml" />

Add address fields to customer signup form

<customer_account_create>
    <reference name="customer_form_register">
        <action method="setShowAddressFields"><param>true</param></action>
    </reference>
</customer_account_create>

Frontend template file snippets

Hard coded content in templates (for translations)

$text = $this->__('Content');

$float_value to currency format

$amount = Mage::helper('core')->currency($float_value, true, false);

Get URLs

$url = $this->getSkinUrl('images/file.jpg'); // Get skin asset URL
$url = Mage::helper('core/url')->getHomeUrl(); // Get home URL
$url = Mage::helper('core/url')->getCurrentUrl(); // Get current URL
$url = $this->getUrl('page.html'); // Get specific page URL

Get current category

$_category = Mage::getModel('catalog/layer')->getCurrentCategory();

Load category by ID

$_category = Mage::getModel('catalog/category')->load($category_id);

Load product by ID

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

Load product by SKU

$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku);

Load configurable product's children

$_child_products = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $_product);

Get resized product image URL (Use in catalog/product_view_media blocks only)

$this->helper('catalog/image')->init($_product, $_image_attribute_name)
    ->keepFrame(false) // Remove white border around images
    ->constrainOnly(true) // Don't enlarge further than original size
    ->keepAspectRatio(true) // Don't crop image
    ->resize($_image_width, $_image_height); // Resize to dimensions provided

Check if customer logged in

$logged_in = Mage::getSingleton('customer/session')->isLoggedIn();

Get a clean string with no symbols or spaces

$_cleaned = Mage::getModel('catalog/product_url')->formatUrlKey($_dirty);

magento-cheat-sheet's People

Contributors

dannynimmo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.