Monday, April 8, 2013

magento admin redirect to same url after post

 Put the below code at the end of the action:

$this->_redirectReferer($this->getRequest()->getServer('HTTP_REFERER'));
        return;

Sunday, February 10, 2013

GET QUOTE ITEMS PRODUCT COUNT BY ATTRIBUTE


This code is for counting the total number to products in the cart having specific attribute code.

$items =Mage::getModel('checkout/cart')->getQuote()->getAllItems();
  $attriubtecnt=0;
 
   foreach($items as $item)
    {
$_product = Mage::getModel('catalog/product')->load($item->getProductId());
$att_value= $_product->getAttributeText('attributecode');

if(trim($att_value)=='lining')
{
                      $liningcnt +=$item->getTotalQty();
                 }

}

Wednesday, November 21, 2012

MAGENTO CHANGE CAPTCHA BACKGROUND LINES AND DOTS DENSITY

I had to reduce the density of dots and lines in captcha because it was un readable sometimes.

so here what i did.

Go to:

lib/Zend/Captcha/Image.php

protected $_dotNoiseLevel = 10;
protected $_lineNoiseLevel = 0;



magento:IP SPECIFIC LANGUAGE

 First download currency switcher from   
 http://www.magentocommerce.com/magento-connect/auto-currency-switcher-8671.html  
 //CODE TO DISPLAY LANGUAGE ACCORDING TO IP ADDRESS  
  if(Mage::getConfig()->getModuleConfig('Chapagain_AutoCurrency')->is('active', 'true'))  
  {   
                $geoIp = Mage::helper('autocurrency')->loadGeoIp();  
                $ipAddress = Mage::helper('autocurrency')->getIpAddress();  
                // get country code from ip address  
                 $countryCode = geoip_country_code_by_addr($geoIp, $ipAddress);   
                 $germancountries=array('CH','DE');  
                if(!isset($_COOKIE['frontstoreloc']))   
                {   
                 //$siteurl= $this->getUrl();  
                 $siteurl= "http://".$_SERVER['SERVER_NAME'];  
                      setcookie("frontstoreloc",session_id(),time()+60*60*24,"/","");  
                     switch(trim($countryCode))  
                     {  
                           case 'CH':  
                                    $url = $siteurl . '?___store=german';  
                                    header( 'Location:' . $url);die;  
                           break;  
                           case 'DE':  
                                         $url = $siteurl . '?___store=german';  
                                         header( 'Location:' . $url);die;  
                           break;  
                           case 'IN':  
                                     $url = $siteurl . '?___store=english';  
                                     header( 'Location:' . $url);die;  
                           break;  
                           default:  
                           $url = $siteurl . '?___store=usa';  
                                     header( 'Location:' . $url);die;  
                           break;  
                     }  
                 }  
            }  

MAGENTO GET STORE SPECIFIC ATTRIBUTE LABEL:

 <?php echo $_product->getResource()->getAttribute($_attribute->getAttributeId())->getStoreLabel();?>  

Magento error :Mage registry key "_singleton/core/resource" already exists

Magento invoice pdf : display custom options in one line



open default.php
at path:

app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice

//REPLACE THE LINES  one that starts with if ($options) {
        //foreach ($options as $option) { with the followin lines.

       
       $options = $this->getItemOptions();
    if ($options) {
        foreach ($options as $option) {
            if ($option['value']) {
                $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
                $values = explode(', ', $_printValue);
                foreach ($values as $value) {
                    $optlabel= Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true);
                    $optval = Mage::helper('core/string')->str_split($value, 50, true, true);
                    $lines[][] = array(
                        'text' => htmlspecialchars_decode ($optlabel[0]." : ".$optval[0]),
                        'feed' =>35
                    );
                }
            }
        }
    }