Google+

Pages

Thursday, January 12, 2017

Custom CMS field showing widget calling code in frontend in Magento

Scenario:
I added custom field for CMS pages and wanted to show its value in sidebar.

Field type: Textarea
Wysiwyg: Enabled
Field Name: content_custom

I wanted to call a widget in content of this custom field.

For reference, I added below code to call widget:

{{widget type="cms/widget_page_link" anchor_text="My Custom Link" title="My Custom Link" template="cms/widget/link/link_block.phtml" page_id="153"}}

When I tried to show field's value in frontend, it displayed content as it was inputted from cms page:

{{widget type="cms/widget_page_link" anchor_text="My Custom Link" title="My Custom Link" template="cms/widget/link/link_block.phtml" page_id="153"}}

instead of rendering its html.

Solution: To render html instead of code calling widget, use below code:

echo Mage::helper('cms')->getBlockTemplateProcessor()->filter(Mage::getBlockSingleton('cms/page')->getPage()->getContentCustom());

Please try this code and let me know if you find any problem.

Thanks for visiting.

Monday, July 4, 2016

How to add a datetime picker input field in admin module form in magento 1.x

To add a date/time input field in admin form in magento 1.x, you need to simply use code like below:

$dateFormatIso = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldset->addField(‘time_from’, ‘date’, array(
‘name’ => ‘time_from’,
‘class’ => ‘required-entry’,
‘required’ => true,
‘label’ => Mage::helper(‘event’)->__(‘Time From’),
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘input_format’ => Varien_Date::DATETIME_INTERNAL_FORMAT,
‘format’ => $dateFormatIso,
‘time’ => true, //if you don’t want time, then simply set ‘time’ => false,
));

Friday, January 1, 2016

Eliminate render-blocking JavaScript and CSS in above-the-fold content in Magento

To remove render-blocking JavaScript issue in Magento using layout xml directly simply add either <params>defer</params> or <params>defer</params> before </action> tag.

For example:

<action method="addJs"><script>prototype/prototype.js</script></action>

Replace it with following:

<action method="addJs"><script>prototype/prototype.js</script><params>defer</params></action>

or

<action method="addJs"><script>prototype/prototype.js</script><params>async</params></action>

Saturday, December 26, 2015

Delete mysql user and revoke all privileges properly in mysql

If you want to remove all the privileges and start totally from scratch do the following:

    Revoke all privileges on database level:

    REVOKE ALL PRIVILEGES ON dbname.* FROM 'username'@'hostname';

    Drop the user:

    DROP USER 'username'@'hostname';

Above procedure will entirely remove mysql user from your instance, this means you can recreate him from scratch.

Wednesday, December 16, 2015

Attribute options are not deleting in magento

It may happen due to lesser php value of max_input_variable.

To fix this problem open .htaccess file of magento's document root and write this in it:

php_value max_input_vars 2500
You can also do the same by adding/changing max_input_vars value from active php.ini of your server.
example:
max_input_vars = 2500

Thursday, September 10, 2015

Add link to category page by id from cms static block/cms page in Magento

If you want to add a link for category page from cms page or cms static block, simply use the category link widget inline link code:


{{widget type="catalog/category_widget_link" anchor_text="Displayed Text" title="Title attribute text" template="catalog/category/widget/link/link_block.phtml" id_path="category/22"}}

There is no need to add <a> tag from cms pages or static blocks.

Sunday, July 6, 2014

Magento: Set page layout on specific pages programmatically

If you want to set page layout on specific pages programmatically; for example you need to change layout from 1column.phtml to 2columns-left.phtml in some condition or so, then you need to create a simple module for it.

Steps to do so are given below:


Under app/etc/modules folder create your module's definition file (Package_Module.xml) and put this code in it:

<?xml version="1.0"?>
<config>
    <modules>
        <Package_Module>
            <codePool>local</codePool>
            <active>true</active>
        </Package_Module>
    </modules>
</config>
 
Now create config.xml file under 
app/code/local/Your/Module/etc folder and put this code in it:
 
<?xml version="1.0"?>
<config>
    <modules>
        <Package_Module>
            <version>0.1.0</version>
        </Package_Module>
    </modules> 
    <global> 
        <models>
            <module>
                <class>Package_Module_Model</class>
            </module>
        </models>
        <events> 
            <controller_action_layout_generate_blocks_after>
                <observers>
                    <any_unique_name>
                        <type>singleton</type>
                        <class>Module/Observer</class>
                        <method>controllerActionLayoutGenerateBlocksAfter</method>
                    </any_unique_name>
                </observers>
            </controller_action_layout_generate_blocks_after>
        </events>
    </global>
</config>
 
Now create Observer.php under app/code/local/Your/Module/Model folder and put this 
code in it:
 
<?php
class Package_Module_Model_Observer
{
    public function controllerActionLayoutGenerateBlocksAfter ($observer)
    {
        $controller = $observer->getAction();

        if ($controller->getFullActionName() == 'catalog_product_view') {
            $layout = $controller->getLayout();
            $rootBlock = $layout->getBlock('root');

            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                $rootBlock->setTemplate('page/1-column.html');
            } else {
                $rootBlock->setTemplate('page/2-columns.html');
            }
        }
    }
}
 
That's it. Cheers.. :)