1.9.2.4 Modification in OrderController.php to preserve HTML tag in order comment

May 28th, 2016 No comments

In Magento 1.9.2.4, the HTML tags in order comment will be stripped which results in no HTML format in transnational emails sent from order page. In fact, comments sent from invoice, shipment and creditmemo are not affected.

Edit file:

app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php

Replace:

$comment = trim(strip_tags($data['comment']));

with:

$comment = trim($data['comment']);

Make Transactional emails to be sent instantly

May 26th, 2016 No comments

Magento 1.9.2.x stores Transactional emails in queue waiting for cron to send them out.
A modification I used to get magento send Transactional emails instantly.

Copy:

 app/code/core/Mage/Sales/Model/Order.php

to:

app/code/local/Mage/Sales/Model/Order.php

Replace:

$mailer->setQueue($emailQueue)->send(); 

with:

$mailer->send();

How to restrict Region States from DropDown list with Magento

April 21st, 2016 No comments

The Old method I used to achieve this is by add code to:
app/code/core/Mage/Directory/Helper/Data.php

Now with Magento 1.9.x, it’s a better approach by adding code to:
app/code/core/Mage/Directory/Model/Resource/Region/Collection.php

Step1:

cp app/code/core/Mage/Directory/Model/Resource/Region/Collection.php app/code/local/Mage/Directory/Model/Resource/Region/Collection.php

Step2:
In line 75 (just right after “$locale = Mage::app()->getLocale()->getLocaleCode();”) add following code:

$excludeRegions = array ('AS','AK','AA','AC','AE','AK','AM','AP','FM','GU','HI','MH','MP','PW','PR','VI','AF');
$this->getSelect()->where('code NOT IN (?)', $excludeRegions);

Magento Porto Theme with Lesti FPC

April 1st, 2016 No comments

If your magento is running with Porto Theme along with Lesti FPC, some blocks you need to add to the Dynamic Blocks of Lesti FPC in the configuration.

Dynamic Blocks: messages, global_messages, global_notices, right.reports.product.viewed, minicart

Fix Memory Exhausted issue when Add to Cart with Configuratble product

September 29th, 2015 No comments

Issue: “Fatal error: Allowed memory size of xxx bytes exhausted (tried to allocate xxx bytes) …Profiler.php on line xxx” when you add a configurable product to cart.
Version: 1.9.2.1

Replace code in the file app/code/core/Mage/SalesRule/Model/Rule/Condition/Product/Subselect.php:
Replace following line:

if (parent::validate($item)) {

with:

if (Mage_Rule_Model_Condition_Combine::validate($item)) {

How to restrict shipping with lower 48 states(Exclude certain states from region list)

September 17th, 2014 No comments

Tested with CE 1.9.0.1

Step 1: Copy files from Source to Target
Source: app/code/core/Mage/Directory/Helper/Data.php
Target: app/code/core/Mage/Directory/Helper/Data.php

Step 2: Edit app/code/core/Mage/Directory/Helper/Data.php
Find: protected function _getRegions($storeId)
Replace code with following:

 protected function _getRegions($storeId)
    {
/** Inserted Part 1 by xlulu -START */
$exclude_regions = array ('AK','VI','AS','HI','PR','RI');    	
/** Inserted Part 1 by xlulu -END */
        $countryIds = array();

        $countryCollection = $this->getCountryCollection()->loadByStore($storeId);
        foreach ($countryCollection as $country) {
            $countryIds[] = $country->getCountryId();
        }

        /** @var $regionModel Mage_Directory_Model_Region */
        $regionModel = $this->_factory->getModel('directory/region');
        /** @var $collection Mage_Directory_Model_Resource_Region_Collection */
        $collection = $regionModel->getResourceCollection()
            ->addCountryFilter($countryIds)
            ->load();

        $regions = array(
            'config' => array(
                'show_all_regions' => $this->getShowNonRequiredState(),
                'regions_required' => $this->getCountriesWithStatesRequired()
            )
        );
        foreach ($collection as $region) {
/** Inserted Part 2 by xlulu -START */
$rg = $region->getCode();
//if ($rg!='AL'){
if(!in_array($rg, $exclude_regions)) {        	
/** Inserted Part 2 by xlulu -END */
            if (!$region->getRegionId()) {
                continue;
            }
            $regions[$region->getCountryId()][$region->getRegionId()] = array(
                'code' => $region->getCode(),
                'name' => $this->__($region->getName())
            );
/** Inserted Part 3 by xlulu -START */
}            
/** Inserted Part 3 by xlulu -END */
        }
        return $regions;
    }

Step 3: Flush Magento Cache

duplicate header ‘Content-Type’ error with API working with php-fpm

April 22nd, 2014 1 comment

File to hack:app/code/core/Mage/Core/Controller/Response/Http.php
Find public function sendHeaders() and replace with following code.

 public function sendHeaders()
    {
        if (!$this->canSendHeaders()) {
            Mage::log('HEADERS ALREADY SENT: '.mageDebugBacktrace(true, true, true));
            return $this;
        }
        if (in_array(substr(php_sapi_name(), 0, 3), array('cgi', 'fpm')))
        {
            // remove duplicate headers
            $remove = array('status', 'content-type');
 
            // already sent headers
            $sent = array();
            foreach (headers_list() as $header)
            {
                // parse name
                if (!$pos = strpos($header, ':'))
                        continue;
                $sent[strtolower(substr($header, 0, $pos))] = true;
            }
 
            // raw headers
            $headersRaw = array();
            foreach ($this->_headersRaw as $i=>$header)
            {
                // parse name
                if (!$pos = strpos($header, ':'))
                        continue;
                $name = strtolower(substr($header, 0, $pos));
 
                if (in_array($name, $remove))
                {
                        // check sent headers
                        if ($sent[$name])
                        {
                            unset($this->_headersRaw[$i]);
                            continue;
                        }
 
                        // check header
                        if (!is_null($existing = $headers[$name]))
                        {
                            $this->_headersRaw[$existing] = $header;
                            unset($this->_headersRaw[$i]);
                        }
                        else
                            $headersRaw[$name] = $i;
                }
            }
 
            // object headers
            $headers = array();
            foreach ($this->_headers as $i=>$header)
            {
                $name = strtolower($header['name']);
                if (in_array($name, $remove))
                {
                        // check sent headers
                        if ($sent[$name])
                        {
                            unset($this->_headers[$i]);
                            continue;
                        }
 
                        // check header
                        if (!is_null($existing = $headers[$name]))
                        {
                            $this->_headers[$existing] = $header;
                            unset($this->_headers[$i]);
                        }
                        else
                            $headers[$name] = $i;
 
                        // check raw headers
                        if (!is_null($existing = $headersRaw[$name]))
                            unset($this->_headersRaw[$existing]);
                }
            }
        }
 
        parent::sendHeaders();
    } 

Tested with CE 1.7.0.2

Display Static Block in template page(phtml file)

May 31st, 2013 No comments

To display static block in your template page, just add following code to the page where you like.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('StaticBlockId')->toHtml(); ?>

Ext: Category sidebar navigation – Show Category Navigation on the top of sidebar

May 31st, 2013 No comments

Show Category Navigation on the top of sidebar

Edit:app/code/community/Magebuzz/Catsidebarnav/Block/Catsidebarnav.php

Chagne two identical lines:

$block->insert($sidebarBlock,'', true, 'cat-sidebar');

to

$block->insert($sidebarBlock,'', false, 'cat-sidebar');

HTC Glacier How to change the button’s actions

May 22nd, 2013 No comments

In app Root Explorer:
System>usr>keylayout >glacier-keypad.kl