Thursday, 25 September 2014

Magento Custom Options – Change the Option to show total price.

Sol : You need to modify Abstact.PHP file.. It is located at app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php
        $_priceInclTax = $this->getPrice($value['pricing_value'], true);
        $_priceExclTax = $this->getPrice($value['pricing_value']);

 Replace above code below code

        $_priceInclTax = $this->getPrice($value['pricing_value'], true)+$this->getProduct()->getFinalPrice();
        $_priceExclTax = $this->getPrice($value['pricing_value'])+$this->getProduct()->getFinalPrice();

Wednesday, 17 September 2014

Show third level catgories in Magento

<?php $_helper = Mage::helper('catalog/category') ?>
                <?php $_categories = $_helper->getStoreCategories() ?>
                <?php $currentCategory = Mage::registry('current_category') ?>
                <?php if (count($_categories) > 0): ?>
                 <?php foreach($_categories as $_category): ?>
              <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <span class="guitar"><?php echo $_category->getName() ?></span>
                </a>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                <?php $_subcategories = $_category->getChildrenCategories() ?>
                <?php if (count($_subcategories) > 0): ?>
                  <ul>
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <li>
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                                <?php // third level /// ?>
                                    <?php $_sub_subcategory = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>
                                    <?php $_sub_subcategories = $_sub_subcategory->getChildrenCategories() ?>
                                    <?php if (count($_sub_subcategories) > 0): ?>
                                        <ul>
                                            <?php foreach($_sub_subcategories as $_subsubcategory): ?>
                                                <li>
                                                    <a href="<?php echo $_helper->getCategoryUrl($_subsubcategory) ?>">
                                                        <?php echo $_subsubcategory->getName() ?>
                                                    </a>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>
                                    <?php endif; ?>
                                   
                                <?php /// third level //// ?>
                               
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
         <?php endif; ?>

Tuesday, 16 September 2014

Category image resize in Magento

<?php
$_file_name = $cat->getThumbnail();             
$_media_dir = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
$cache_dir = $_media_dir . 'resize' . DS;

if (file_exists($cache_dir . $_file_name)) {
$catImg =Mage::getBaseUrl('media') .  'catalog' . DS . 'category' . DS . 'resize' . DS . $_file_name;
 } elseif (file_exists($_media_dir . $_file_name)) {
if (!is_dir($cache_dir)) {
mkdir($cache_dir);
}

$_image = new Varien_Image($_media_dir . $_file_name);
$_image->constrainOnly(true);
$_image->keepAspectRatio(false);
$_image->keepFrame(false);
$_image->keepTransparency(true);
$_image->resize(224, 174); // change image height, width
$_image->save($cache_dir . $_file_name);
$catImg = Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . 'resize' . DS . $_file_name;
                         }
 echo  $catImg ; // display resize category thumbnail imagename
 ?>

<img src="<?php echo $catImg;  ?>"  />

Magento Add Payment Method to Admin invoice Grid

 protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
      
        $collection->join(array('payment'=>'sales/order_payment'),'main_table.order_id=parent_id',array('method','po_number'));
      
        $collection->getSelect()->joinLeft('sales_flat_order_address', 'main_table.order_id = sales_flat_order_address.parent_id',array('full_name'=>'CONCAT(sales_flat_order_address.firstname, " " , sales_flat_order_address.lastname)','full_address'=>'CONCAT(sales_flat_order_address.street, " ", sales_flat_order_address.city, sales_flat_order_address.postcode)','telephone','city','firstname','postcode','company','street','email' ) )->where("sales_flat_order_address.address_type =  'billing'");
      
      
          $collection->getSelect()->joinLeft('sales_flat_order', 'main_table.order_id=sales_flat_order.entity_id', array("shipping_desc"=>"shipping_description","weight"=>"weight","subtotal_incl_tax"=>"subtotal_incl_tax","base_subtotal_invoiced"=>"base_subtotal_invoiced","base_shipping_invoiced"=>"base_shipping_invoiced","base_tax_amount"=>"base_tax_amount"));
        
     
         $this->setCollection($collection);
         return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
        
    }
$payments = Mage::getModel('payment/config')->getAllMethods();
        $methods = array();
            foreach ($payments as $paymentCode=>$paymentModel)
            {
                $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
                $methods[$paymentCode] = $paymentTitle;
            }
            $this->addColumnAfter('method', array(
                'header' => Mage::helper('sales')->__('Payment Method'),
                'index' => 'method',
                'filter_index' => 'method',
                'type'  => 'options',
                'width' => '1050px',
                'options' => $methods,
            ));