Displaying 1-20 of 104 results.

Get the current category/product/cms page

Syntax:

$currentCategory = Mage::registry('current_category');
$currentProduct = Mage::registry('current_product');
$currentCmsPage = Mage::registry('cms_page');


Check customer is logged in

Syntax:

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


Add JavaScript to page

First approach: page.xml - you can add something like

Syntax:

<action method="addJs"><script>path/to/my/file.js</script></action>


Call Static Block

Syntax:

echo $this->getLayout()->createBlock('cms/block')->setBlockId('block-name')->toHtml();


Log to custom file

Syntax:

Mage::log('Your Log Message', Zend_Log::INFO, 'your_log_file.log');


Get Configurable product's Children's (simple product) custom attributes

Syntax:

// input is $_product and result is iterating child products
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($col as $simple_product){
    var_dump($simple_product->getId());
}


Get Configurable product's Child products

Syntax:

// input is $_product and result is iterating child products
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);


Load product by id sku

Syntax:

$_product_1 = Mage::getModel('catalog/product')->load(12);
$_product_2 = Mage::getModel('catalog/product')->loadByAttribute('sku','cordoba-classic-6-String-guitar');


Load category by id

Syntax:

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


Clear cache reindex

Syntax:

// clear cache
Mage::app()->removeCache('catalog_rules_dirty');
// reindex prices
Mage::getModel('index/process')->load(2)->reindexEverything();
/*
1 = Product Attributes
2 = Product Attributes
3 = Catalog URL Rewrites
4 = Product Flat Data
5 = Category Flat Data
6 = Category Products
7 = Catalog Search Index
8 = Tag Aggregation Data
9 = Stock Status
*/


Resize A Product Image

Syntax:

Mage::helper('catalog/image')->init($product, 'image')->resize(150);


Creating a New Attribute

Syntax:

$entityTypeId = Mage::getModel('catalog/product')
                  ->getResource()
                  ->getEntityType()
                  ->getId();
 
$attributeSet = Mage::getModel('eav/entity_attribute_set')
                  ->setEntityTypeId($entityTypeId)
                  ->setAttributeSetName('test_set');
 
$attributeSet->validate();
$attributeSet->save();
 
$attributeSet->initFromSkeleton($skeletonID)->save();


CTreeView

CTreeView displays a tree view of hierarchical data. To use CTreeView, simply sets data to the data that you want to present and you are there.

Syntax:

$this->widget(
    'CTreeView',
    array('url' => array('ajaxFillTree'))
);


CTextHighlighter

CTextHighlighter does syntax highlighting for its body content.

Example:

$content = 'public function processOutput($output)
{
    $output=$this->highlight($output);
    parent::processOutput($output);
}';
 
$highlight = new CTextHighlighter;
$highlight->language = 'php';
$highlight->showLineNumbers = true;
$highlight->lineNumberStyle = 'list';
 
echo $highlight->highlight($content);


CMarkdown

CMarkdown converts the captured content from markdown syntax to HTML code.


CJuiSelectable

CJuiSelectable displays an accordion widget. CJuiSelectable encapsulates the JUI Selectable plugin.

Syntax:

$this->widget('zii.widgets.jui.CJuiSelectable',array(
    'items'=>array(
        'id1'=>'Item 1',
        'id2'=>'Item 2',
        'id3'=>'Item 3',
    ),
    // additional javascript options for the selectable plugin
    'options'=>array(
        'delay'=>'300',
    ),
));


CJuiResizable

CJuiResizable displays a resizable widget. CJuiResizable encapsulates the JUI Resizable plugin.

Syntax:

$this->beginWidget('zii.widgets.jui.CJuiResizable',array(
    // additional javascript options for the resizable plugin
    'options'=>array(
        'minHeight'=>'150',
    ),
));
    echo 'Your Resizable content here';
 
$this->endWidget();


CJui ProgressBar

CJuiProgressBar displays a progress bar widget. CJuiProgressBar encapsulates the JUI Progressbar plugin.

Syntax:

$this->widget('zii.widgets.jui.CJuiProgressBar',array(
    'value'=>75,
    // additional javascript options for the progress bar plugin
    'options'=>array(
        'change'=>new CJavaScriptExpression('function(event, ui) {...}'),
    ),
    'htmlOptions'=>array(
        'style'=>'height:20px;',
    ),
));


CJui Droppable

CJuiDroppable show a dropable widget in Yii. Yiiframework is using jQueryUI Dropable widget

Syntax:

$this->beginWidget('zii.widgets.jui.CJuiDroppable',array(
    // additional javascript options for the droppable plugin
    'options'=>array(
        'scope'=>'myScope',
    ),
));
    echo 'Your droppable content here';
 
$this->endWidget();


About us
Useful links
Menu