Wednesday, 26 November 2014

Magento change currency format

/lib/Zend/Locale/Data/en_US.xml



<numbers>
    <currencyFormats>
        <currencyFormatLength>
            <currencyFormat>
                <pattern>¤#,##0.00(USD);(¤#,##0.00(USD))</pattern>
            </currencyFormat>
        </currencyFormatLength>
        <unitPattern count="one">{0} {1}</unitPattern>
        <unitPattern count="other">{0} {1}</unitPattern>
    </currencyFormats>
</numbers>

Monday, 22 September 2014

magento product collection with specific id


magento product collection with specific id

    $productIds = array(1,3,2);
    $products = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter('entity_id', array('in' => $productIds));

Tuesday, 2 September 2014

Magento Product Collection random in limit


 <?php
                            $c=0;
                            $category = Mage::getModel('catalog/category')->load(3);//3 is category id where we assign the products for men
                            $products = Mage::getModel('catalog/product')->getCollection()
                            ->addCategoryFilter($category);
                           
                            $products->addAttributeToSelect('*');
                           
                            $products->getSelect()->order('RAND()');
                            $products->getSelect()->limit(5);//to show only three products randomly
                           
                            $total = $products->count();
                            foreach ($products as $_product) {
                                $c++; ?>
                            <li class="item <?php if($total== $c){ echo "last"; }?>">
                                <a href="<?php echo $_product->getProductUrl() ?>">
                                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(375,281)?>" alt="" />
                                </a>
                                <?php echo $_product->getName() ?>
                               
                                <div class="price-box">
                                        <span class="regular-price" >
                                            <span class="price"><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();?> <?php echo number_format($_product->getPrice(),2);?></span>
                                        </span>
                                </div>
                               
                               
                            </li>
                            <?php } ?>

Monday, 25 August 2014

Get product attribute’s select option id/label/value in magento


$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute("color");
 echo $color_id = $attr->getSource()->getOptionId("Red");

Tuesday, 5 August 2014

Magento toolbar use in custom product calection

    $toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
       $toolbar->setCollection($_productCollection);
       $layout = Mage::getSingleton('core/layout');
       $pager = $layout->createBlock('page/html_pager');
       $toolbar->setChild('product_list_toolbar_pager', $pager);
       echo $toolbar->toHtml();
       $this->getToolbarHtml() eta comment kore ei code lagabe


Magento Get product attribute 'option label'


<?php echo $product->getResource()->getAttribute($attribute_code)->getFrontend()->getLabel($product); ?>

Friday, 11 July 2014

How to get Region Id in magento

 $customer_regionid=Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->getRegionId();

Sunday, 1 June 2014

Magento: Get Bundled Items By Bundle Product

 <?php foreach ($collection as $_product){ ?>

 $bundleIds = Mage::getResourceSingleton('bundle/selection')->getParentIdsByChild($productId);

/*************************Bundled product id*******************************/
          $parentid=$bundleIds[0];
       $_newProduct = Mage::getModel('catalog/product')->load($parentid);
 } ?>

Wednesday, 28 May 2014

Remove or rename add new save continue delete button from magento admin


If you don’t want to show the ‘Add New’ button in the Grid. The Add New button is present in top right corner of Grid Page.

Rename ‘Add New’ button

Here are the steps to rename the ‘Add New’ text to anything you required (for example, ‘Add Report’):-

- Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.php
- Add the following code in the constructor of this file:-

$this->_addButtonLabel = Mage::helper('yourmodulename')->__('Add Report');

Remove ‘Add New’ button

Here are the steps to remove the ‘Add New’ button:-

- Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.php
- Add the following code in the constructor of this file (it should be just below the call to parent constructor):-



parent::__construct();
$this->_removeButton('add');


In edit.php
parent::__construct();
$this->_removeButton('delete');
$this->_removeButton('save');
$this->_removeButton('back');

in grid.php
parent::__construct();
$this->_removeButton('add'); 

Tuesday, 20 May 2014

Server front issues

<FilesMatch "\.(ttf|otf|eot|woff)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>

LInk:-http://red-team-design.com/firefox-doesnt-allow-cross-domain-fonts-by-default/

Monday, 19 May 2014

way to display a thumbnail image in the admin grid view?

Step 1
======================================
Create Directories (if NOT there)
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/

Step 2
======================================
Create a file named “Image.php” at the following location
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/


 Step 3
======================================
Paste the following code into “Image.php” created above


class <Mycomapname>_<Mymodule>_Block_Adminhtml_Grid_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    
public function render(Varien_Object $row)
    
{
        
if($row->getData($this->getColumn()->getIndex())==""){
            
return "";
        
}
        else{
            $html 
'<img ';
            
$html .= 'id="' $this->getColumn()->getId() . '" ';
            
$html .= 'width="45" ';
            
$html .= 'height="35" ';
            
$html .= 'src="' Mage::getBaseUrl("media") . $row->getData($this->getColumn()->getIndex()) . '"';
            
$html .= 'class="grid-image ' $this->getColumn()->getInlineCss() . '"/>';
          
            return 
$html;
        
}
    }
}



 
Hi All,
You do not need to overwrite any thing at all, just follow these simple steps instead
Step 1
======================================
Create Directories (if NOT there)
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/
Step 2
======================================
Create a file named “Image.php” at the following location
app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/Grid/Renderer/
Step 3
======================================
Paste the following code into “Image.php” created above

class <Mycomapname>_<Mymodule>_Block_Adminhtml_Grid_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    
public function render(Varien_Object $row)
    
{
        
if($row->getData($this->getColumn()->getIndex())==""){
            
return "";
        
}
        else{
            $html 
'<img ';
            
$html .= 'id="' $this->getColumn()->getId() . '" ';
            
$html .= 'width="45" ';
            
$html .= 'height="35" ';
            
$html .= 'src="' Mage::getBaseUrl("media") . $row->getData($this->getColumn()->getIndex()) . '"';
            
$html .= 'class="grid-image ' $this->getColumn()->getInlineCss() . '"/>';
          
            return 
$html;
        
}
    }
}

Step 4
======================================
Open app/code/local/<Mycomapname>/<Mymodule>/Block/Adminhtml/<Mymodule>/Grid.php and paste the following code into the function protected function _prepareColumns() some where

$this->addColumn('<Tbl_Colname>', array(
            
'header'    => Mage::helper('<mycomapname>_<mymodule>')->__('Image'),
            
'align'     => 'left',
            
'width'     => '100px',
            
'index'     => '<Tbl_Colname>',
            
'type'      => 'image',
            
'escape'    => true,
            
'sortable'  => false,
            
'filter'    => false,
            
'renderer'  => new <Mycomapname>_<Mymodule>_Block_Adminhtml_Grid_Renderer_Image,
        ));



===================================================================






Wednesday, 23 April 2014

Get Option Value by ID in Magento

<?php
$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute("manufacturer");

if ($attr->usesSource()) {
    echo $color_label = $attr->getSource()->getOptionText(45);
}
?>

Note:- manufacturer (product attribute code)
            45 ==> (option value id)

Thursday, 17 April 2014

Magento Currency Symbol 404's when i go to admin

/app/code/core/Mage/CurrencySymbol/etc/config.xml

<currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol>
                                  Change to

<currencysymbol before="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol>

Wednesday, 16 April 2014

How to check is object

if(is_object(Mage::registry('current_category')))

{

$GetCurrentCatName=Mage::registry('current_category')->getName();

}

Wednesday, 2 April 2014

How to resize product/custom image in magento


$_product = Mage::getModel('catalog/product')->load($_product->getId());
 <img src="<?php echo Mage::helper('catalog/image')->init($_product ,'image')->resize(224,299) ?>" />

Friday, 28 March 2014

Magento: Resize category image and thumbnail


<?php
$mediaPath=Mage::getBaseDir('media')."/catalog/category/resized/";
                        if(!is_dir($mediaPath)) mkdir($mediaPath,0777);
 foreach($collections as $subcate){

                                 
                                    $_curCat_sub = Mage::getModel('catalog/category')->load($subcate->getId());
                                    $count_sub = $_curCat_sub->getProductCount();
                                    $_subimage=$subcate->getThumbnail();
                                    if($_subimage!=''){
                                 
                                    $_imageUrl=Mage::getBaseDir('media')."/catalog/category/".$subcate->getThumbnail(); //Real path
                                 
                                 
                                    $_imageUrl=Mage::getBaseDir('media')."/catalog/category/".$subcate->getThumbnail();
                                 
                                    $imageResized=Mage::getBaseDir('media')."/catalog/category/resized/".$subcate->getThumbnail();
                                    $imageObj = new Varien_Image($_imageUrl);
                                    $imageObj->constrainOnly(TRUE);
                                    $imageObj->keepAspectRatio(TRUE);
                                    $imageObj->keepFrame(FALSE);
                                    $imageObj->resize(null,300);
                                    $imageObj->save($imageResized);
                                    $mediaurl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
                                    $imageResized = $mediaurl."/catalog/category/resized/".$subcate->getThumbnail();
?>
<img src="<?php echo $imageResized;?>"/>
<?php } ?>

Tuesday, 25 March 2014

How to detect the width of a web browser using jQuery


<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(window).resize(function(){

         var current_width = jQuery(window).width();
   
   
            if(current_width < 400){
           
           
            }
});
  });
</script>

Monday, 10 March 2014

Magento cart update on key up

<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" /> 

Magento Product Attribute value


<?php
                   $attributeInterests = Mage::getModel('eav/config')->getAttribute('catalog_product', 'brand');
                   $InterestsSize=$attributeInterests->getSource()->getAllOptions(true, true);
                   $InterestsSizeCount = count($InterestsSize);
                   $InterestsColumnCount = 6;
                   $ii=0;?>
                    <ul>
                   <?php
                   foreach ($attributeInterests->getSource()->getAllOptions(true, true) as $option){ ?>
                   <?php if($option['value'] > 0) { ?>
                 
                 
                 
                           <li><a href="<?php echo $this->getUrl();?>catalogsearch/advanced/result/?flag=adv&description=&brand=<?php echo  $option['value']; ?>"><span><?php echo $option['label']; ?></span> <img src="<?php echo $this->getSkinUrl();?>images/bg.png" alt="bg" width="188" height="28" /></a></li>
                         
                 
                   <?php  }  } ?>
                    </ul>

Tuesday, 18 February 2014

How to get child category in magento

$collections= Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('is_active',1)->addAttributeToFilter('parent_id',5)->addOrderField('position');

How to get all category in magento


<?php $category_model = Mage::getModel('catalog/category')->load($categoryid);
       $all_child_categories = $category_model->getResource()->getAllChildren($category_model );
   
 foreach ($all_child_categories as $child_id){
}

//===============OR=====================

$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addIsActiveFilter();
     foreach($categories as $ubcat){
 
 
   $catId=$ubcat->getId();
 
     }
     ?>

How to get product images on magento


<?$_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();?>
<?if($_images){?>   
   <?$i=0; foreach($_images as $_image){ $i++;?>
      <a href="#"><img src="<?=$this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(200, 130); ?>" width="200" height="130" alt="<?=$this->htmlEscape($_image->getLabel());?>" title="<?=$this->htmlEscape($_image->getLabel());?>" /></a>    
   <?}?>
<?}?>

Wednesday, 12 February 2014

Create category attribute select option



<?php  require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'int',
'label'=> 'Featured Category',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => 0,
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'featured_category', $attribute);
$installer->endSetup();
?>

Thursday, 30 January 2014

IP track location city


<?php
   $key='4aa3d8dd845debd79b15b3d55449dbeddbf00645e0acdd2b943a99f298b9c089';
   /*include('ip2locationlite.class.php');
   $ipLite = new ip2location_lite;
   $ipLite->setKey('4aa3d8dd845debd79b15b3d55449dbeddbf00645e0acdd2b943a99f298b9c089');
 
   echo "<br>RA : ".$_SERVER['REMOTE_ADDR'];
 
   $tags = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
   $errors = $ipLite->getError();
 
   echo "<pre>"; print_r($errors); echo "</pre>";*/
 
   //http://api.ipinfodb.com/v3/ip-country/?key=4aa3d8dd845debd79b15b3d55449dbeddbf00645e0acdd2b943a99f298b9c089&ip=122.163.43.151
 
   echo "<br>U : ".$url='http://api.ipinfodb.com/v3/ip-country/?key='.$key.'&ip='.$_SERVER['REMOTE_ADDR'];
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $data = curl_exec($ch);
   curl_close($ch);
 
   $dataArr=explode(";",$data);
 
   echo "<pre>"; print_r($dataArr); echo "</pre>";
?>


Link:- http://www.ipinfodb.com/ip_location_api.php