HTML/JavaScript

Tuesday, January 12, 2016

Get Filterable attribute by Category ID

<?php
$category_ids = $this->getCategoryid(); // HERE YOU CAN PUT THE STATIC CATEGORY ID

$layer = Mage::getModel("catalog/layer");
    $categoryid = $category_ids;
    $category = Mage::getModel("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($category);
    $attributes = $layer->getFilterableAttributes();

    foreach ($attributes as $attribute) {
        if ($attribute->getAttributeCode() != 'price') {
           
            $filterBlockName = 'catalog/layer_filter_attribute';
       
        echo '<br/>---'.$attribute->getFrontendLabel();
        echo '---<br/>';
        $result = $this->getLayout()->createBlock($filterBlockName)->setLayer($layer)
->setAttributeModel($attribute)->init();
       
        foreach($result->getItems() as $option) {
            echo $option->getLabel().'<br/>';
            echo $option->getValue();
        }
        }
}

?>

Thursday, January 7, 2016

How to override controller in magento/Override controller’s action in magento

Some times you may run into situation where you want to override the core functionality of Magento core controllers.

So in this case, The best practise is override the controller then override actions or add new actions for custom requirement.

For example you want to override OnepageController.php file and overwride indexAction.

In this example my custom module name space is “MyBlog” and i am going to overwride indexAction

Mage_Checkout_OnepageController


Base File Path : app/code/core/Mage/Checkout/controllers/OnepageController.php
To Do the same we have to follow bellow steps.

Step1: We need to create a custom module


File Path : app/etc/modules/
File Name: MyBlog_Checkout.xml
File Content:

<?xml version="1.0"?>
<config>
<modules>
<MyBlog_Checkout>
<active>true</active>
<codePool>local</codePool>
</MyBlog_Checkout>
</modules>
</config>
Step2: Now we have to create bellow files in our custom module


File Path: app/code/local/MyBlog/Checkout/etc/config.xml
Bellow is content for config.xml file

<?xml version="1.0"?>
<config>
<modules>
<MyBlog_Checkout>
<version>0.0.1</version>
</MyBlog_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<MyBlog_Checkout before="Mage_Checkout">MyBlog_Checkout</MyBlog_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
Bellow is content for OnepageController.php


File Path : app/code/local/MyBlog/Checkout/controllers/OnepageController.php

<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';

class MyBlog_Checkout_OnepageController extends Mage_Checkout_OnepageController {

public function indexAction()
{
echo "Great! You are in MyBlog checkout controller section";
exit;
}
}
?>

Wednesday, December 30, 2015

Fixing Magento Catalog Price Rules Issue

try {
Mage::getConfig()->init()->loadEventObservers('crontab');
Mage::app()->addEventArea('crontab');
Mage::dispatchEvent('default');
$observ = Mage::getModel('catalogrule/observer');
$observ->dailyCatalogUpdate("0 1 * * *");
} catch (Exception $e) {
Mage::printException($e);
}

Custom column layout

Learn how easy it is to create a custom column layout for Magento. The tutorial is based on the Magento Enterprise Edition but also applies to the Magento Community Edition. A custom column layout is helpful if you want for instance a "left" column to only appear on certain pages.

To create a new custom column layout, you need to place a new file in the Magento theme. With the Magento default theme, you could use the folder app/design/frontend/default/default/template/page, but of course - when building your own site - it is recommended to have your own theme-directory.

In the tutorial, the file 1column.phtml is copied to the file 1columnfp.phtml (where "fp" stands for the front page). To make this new page reckognizable you wll need to add a new XML-definition. In the tutorial the following code is added to the file app/code/core/Mage/Page/etc/config.xml this needs to be copied into app/code/local/Mage/Page/etc/config.xml


<one_column_fp module="page" translate="label">
    <label>1 column (frontpage)</label>
    <template>page/1columnfp.phtml</template>
    <layout_handle>page_one_column_fp</layout_handle>
</one_column_fp>

However, with a Magento upgrade this change could be gone. The same XML could also be added to your app/etc/local.xml file instead:

<config>
    <global>
        <page>
            <layouts>
                <one_column_fp module="page" translate="label">
                    <label>1 column (frontpage)</label>
                    <template>page/1columnfp.phtml</template>
                    <layout_handle>page_one_column_fp</layout_handle>
                </one_column_fp>
            </layouts>
        </page>
    </global>
</config>

Monday, December 28, 2015

Remove maintenance mode in magento 2

Removing Maintenance mode in Magento 2 is extremely simple as in previous Magento versions.

The .maintenance.flag file is located under var folder in Magento 2. Delete this file to remove the maintenance mode.

Wednesday, October 21, 2015

Add Custom Field in Registration Form and in Admin Side

Here I am add the Custom Field for the Customer Registration Form using the database,

It's very simple to add Custom Field in Registration Form and also in Manage Customer Account Information of Admin,

This is the easiest way to Create field using Database Query !!!!!

A) First, Open your Database of Magento

    Click on SQL tab of  your Database and simplly write Below Query in that

    1)  Insert into eav_attribute set      entity_type_id="1",attribute_code="occupation",
backend_type="text",frontend_input="text",
frontend_label="Occupation",is_required=0,is_user_defined=0,is_unique=0

   2) Copy the Last inserted Id of  "Eav_attribute" table

   3)  Insert into `eav_entity_attribute` set entity_type_id=1,attribute_set_id=1, attribute_group_id=1,attribute_id=134,sort_order=111

   Here, you mention that change your attribute id with the Last inserted id of Eav_attribute table.

   attribute_id = "Last Inserted Id of Eav_attribute" table

   4) insert into  `customer_eav_attribute` set attribute_id="134",is_visible=1,multiline_count=1,is_system=0,sort_order=111

  same as Point (3) change attribute_id

  5) insert into  `customer_form_attribute` set form_code="adminhtml_customer",attribute_id=134

 same as Point (3) change attribute_id

  6) insert into  `customer_form_attribute` set form_code="checkout_register",attribute_id=134

  same as Point (3) change attribute_id

 7) insert into  `customer_form_attribute` set form_code="customer_account_create",attribute_id=134

 same as Point (3) change attribute_id

8) insert into  `customer_form_attribute` set form_code="customer_account_edit",attribute_id=134

 same as Point (3) change attribute_id



B) Now, some code for Create Field to saw in Front end,

   1) open Customer/Form/registration.phtml

   simply Copy-Paste below code

 Copy this .......

   <li>
        <label for="occupation"><em></em><?php echo $this->__('Occupation') ?></label>

        <div class="input-box">

         <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />

         </div>
    </li>

   2) open Customer/Form/edit.phtml

    simply Copy-Paste below code

    Copy this .......

   <li>
        <label for="occupation"><em></em><?php echo $this->__('Occupation') ?></label>

        <div class="input-box">

         <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />

         </div>
    </li>

Thursday, October 1, 2015

Magento: How to get controller, module, action and router name?

You can easily get controller name, action name, router name and module name in any template file or class file.

IN TEMPLATE FILES

$this->getRequest() can be used in template (phtml) files.

Here is the code:

/**
 * get Controller name
 */
$this->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
$this->getRequest()->getActionName();

/**
 * get Router name
 */
$this->getRequest()->getRouteName();

/**
 * get module name
 */
$this->getRequest()->getModuleName();

/**
 * get Controller name
 */
$this->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
$this->getRequest()->getActionName();

/**
 * get Router name
 */
$this->getRequest()->getRouteName();

/**
 * get module name
 */
$this->getRequest()->getModuleName();

IN CLASS FILES

Here is the code:

/**
 * get Controller name
 */
Mage::app()->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
Mage::app()->getRequest()->getActionName();

/**
 * get Router name
 */
Mage::app()->getRequest()->getRouteName();

/**
 * get module name
 */
Mage::app()->getRequest()->getModuleName();

/**
 * get Controller name
 */
Mage::app()->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
Mage::app()->getRequest()->getActionName();

/**
 * get Router name
 */
Mage::app()->getRequest()->getRouteName();

/**
 * get module name
 */
Mage::app()->getRequest()->getModuleName();

The above functions (getControllerName, getActionName, getRouteName, getModuleName) are present in the class Mage_Core_Model_Url.

You can explore all requests with print_r.

echo "<pre>"; print_r(Mage::app()->getRequest());  
  
echo "<pre>"; print_r(Mage::app()->getRequest());