Tuesday 25 June 2013

Magento - Enable template path hint in admin pages


 - We can do it by changing the database directly. If we have something like phpMyAdmin that is a good way to gain access. Enter this SQL.
INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`)
       VALUES ('websites', '0', 'dev/debug/template_hints', '1');
 - When we are done with path hints just delete the matching record from core_config_data Or update the value field to 0 instead of deleting the whole record, it will probably be the last one since you've just added it.

( OR ELSE )

 - We can enable template and block path hints in every store (including the admin store) by setting them in the Magento configuration. To do this, simply edit your module's configuration file config.xml(which gets injected into Magento's global configuration).
To enable template and block path hints in the admin area add this to ourconfig.xml file
<config>

    ...

    <stores>
        <admin>
            <dev>
                <debug>
                    <template_hints>1</template_hints>
                    <template_hints_blocks>1</template_hints_blocks>
                </debug>
            </dev>
        </admin>
    </stores>

</config>
To disable path hints simply change to 0, or delete the node.

YII - How to Use Highcharts in your Yii Projects

Many times, you will come across situations, where you have to include or display simple charts like pie, graph, bar-graph, columns and lines to represent information on your website like growth, progress, attendance etc.

There are many tools that are available to include charting functionality but choosing a right charting tool that fulfills your current needs as well as future requirements is difficult. One has to carefully analyze all the factors and choose the best suited tool.

Here we are going to discuss one of the most popular charting tools ("HIGHCHARTS") and how to implement them in your Yii PHP development. It is a powerful tool that can help you outline and enhance your data visualization of the data you want to display within your website in form of charts.

What is HIGHCHART?

Highcharts is a JavaScript library which is used to incorporate interactive charts in your application through a simple & easy approach. Highcharts offer various types of charts like column, line, bar, pie, spline, scatter, etc.

To use any of the charts provided by Highcharts in your Yii application, follow the below steps:

Step1: Download the appropriate version of highcharts extension from:

http://www.yiiframework.com/extension/highcharts/ .

Step2: Unpack it to the protected/extensions folder under your Yii installation.

Step3: This extension can then be used in the form of a widget(PHP) or through java-script in your website. I am using the PHP widget(as below) which is just placed in the view file:

$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'Student Count in Universities'),
'xAxis' => array(
'categories' => array('Uni-A', 'Uni-B', 'Uni-C', 'Uni-D')
),
'yAxis' => array(
'title' => array('text' => 'Number of students')
),
'series' => array(
array('name' => 'Alpha', 'data' => array(10, 0, 44, 52),
array('name' => 'Beta', 'data' => array(54, 47, 30, 87) ,
array('name' => 'Gamma', 'data' => array(52, 76, 63, 12))
)
)
));


Step4: Now your chart is displayed on your site & you can see it by typing the appropriate URL for that view in your browser.

References:

The official website for the Highcharts is http://www.highcharts.com .

Tip: The "Edit in jsFiddle" available in every highchart demo at http://www.highcharts.com/demo/ is an excellent tool for exploring different options for each chart instantly.

Magento - Page Redirection From Module

- If we need to redirect from module we have to using the following code,

- It will used to redirect to the desired page or another module action


Mage::app()->getResponse()->setRedirect(Mage::getUrl('Desired path/URL'));



Magento - How to add button to order view page in admin


 - How could we add button to the top of order view page in admin?   (behind back, edit, cancel, hold, invoice, ship).



 We will either have to override the mage block or edit the core.  But to add you can do something like this:
app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
Mage_Adminhtml_Block_Sales_Order_View
Add the following to the constructor:

 $this->_addButton('order_reorder', array(
            
            'label'     => Mage::helper('sales')->__('Print'),
            
            'onclick'   => 'setLocation(\'' . $this->getUrl('ssireports/index/invoice') . '\')',
        ));
        ));

Saturday 22 June 2013

Magento - Create a Drop-Down of Countries

When I first needed to access a collection of countries in Magento I assumed it would work like all other data collections but was shocked to find that this wasn't the case. Rather than store country data in the database, Magento stores country data in an XML file and loads it in on each request. Fortunately though, there are some simple functions that we can use to access country names and codes in Magento.

Get An Array of Country Names/Codes in Magento

?
1
2
3
4
5
6
7
8
9
<?php
    $countryList = Mage::getResourceModel('directory/country_collection')
                    ->loadData()
                    ->toOptionArray(false);
     
    echo '<pre>';
    print_r( $countryList);
    exit('
'); ?>
The above code will print out an array containing every country code and country name known to Magento.

Drop Downs and Country Information

The most common reason developers access country names in Magento is to create a drop down. There are several ways to accomplish this and they differ depending on whether you're in the admin or the frontend.

Create a Country Drop Down in the Frontend of Magento

Add the following code to any template file in the frontend of Magento and you will get a drop down box using the country name as the label and the country code as the value.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php $_countries = Mage::getResourceModel('directory/country_collection')
                                    ->loadData()
                                    ->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
    <select name="country" id="country">
        <option value="">-- Please Select --</option>
        <?php foreach($_countries as $_country): ?>
            <option value="<?php echo $_country['value'] ?>">
                <?php echo $_country['label'] ?>
            </option>
        <?php endforeach; ?>
    </select>
<?php endif; ?>

Create a Country Drop Down in the Magento Admin

When creating forms in the Magento Admin area, it is very rare that we use actual HTML. The reason for this is that forms are generally built using pre-built functions. The benefit of this is that each Admin page looks uniform and helps to keep Magento looking like one whole application rather than having loads of bits stuck onto it. As our method of adding HTML changes, so must our method of creating our country drop down.
?
1
2
3
4
5
6
7
8
9
<?php
    $fieldset->addField('country', 'select', array(
        'name'  => 'country',
        'label'     => 'Country',
        'values'    => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),
    ));
?>