PHP SOLUTIONS

This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Wednesday 28 November 2012

Magento : Remove TAX / VAT from grand total in checkout


Here, We can Remove Tax from Grand Total.

If we want to removed tax for all customer we simply remove Tax class from the produc's then It will remove automatically.

But If you want to remove Tax for specific customer you can do using below steps.

Here Example for Remove Tax for that Customer Who have their Business VAT Numbers.

1) Goto " app/code/core/mage/tax/model/calculation.php  "

2) Find this Function "  public function getRateRequest() "

3) You can get this at the end of the function

    $request = new Varien_Object();
        $request
            ->setCountryId($address->getCountryId())
            ->setRegionId($address->getRegionId())
            ->setPostcode($address->getPostcode())
            ->setStore($store);
            ->setCustomerClassId($customerTaxClass);

4) Now Here for who have VAT/TAX numbers, no apply Tax in Grand Total

    $eutax = $customer['taxvat'];

    if($eutax != '')
   {
            //Who have to insert their VAT Number then remove TAX from Grand Total
            $request = new Varien_Object();
            $request
                       ->setCountryId($address->getCountryId())
                       ->setRegionId($address->getRegionId())
                       ->setPostcode($address->getPostcode())
                       ->setStore($store);                      
    }
    else
    {
           //Who have to not insertd their VAT Number then add TAX in Grand Total
           $request = new Varien_Object();
           $request
                      ->setCountryId($address->getCountryId())
                      ->setRegionId($address->getRegionId())
                      ->setPostcode($address->getPostcode())
                      ->setStore($store);
                      ->setCustomerClassId($customerTaxClass);


    }

5) Now check Tax is Remove from Grand Total in checkout.


Saturday 24 November 2012

Magento : Upgrade Magento version



You can do this for Upgrade Magento 1.4 to 1.7

Do this in your Local Machine because when you Upgrade Do not reload page before complete all steps

1) Backup your current Site files and Database

2) Download Newer version from http://www.magentocommerce.com/download
    then Extract that zip in Directory

3) Upload or Override newer version files on your current site files

4) your database upgrade automatically so don't do any thing with that

5) After Complete override then remove site cache and index from admin

6) Now, Reload your site, you can see Upgraded version 1.7 in footer


Saturday 17 November 2012

Magento : Add JavaScript / CSS



There is Two way for add external Javascript in magento

1) Using Page.xml
2) Using Head.phtml


1) Using Page.xml :::\\//

<action method="addJs"><script>directoryname/javascript_name.js</script></action>


2) Using Head.phtml :::\\//

<script type="text/javascript" src="<?php echo $this->getSkinUrl('directoryname/javascript_name.js') ?>"></script>

<link href='<?php echo $this->getSkinUrl('directoryname/css_name.css')  ?>' rel='stylesheet' type='text/css' />

Magento : Get popular tags list for any page


Here, I get Popular Tags List on Any page,

Using this can get HTML Layout of the Phtml page

Simply, Copy and Paste below code


<?php echo $this->getLayout()->createBlock('tag/popular')->setTemplate('tag/popular.phtml')->toHtml(); ?>


If you want another page html then change block directory and type,

also replace template name of phtml file.

Friday 2 November 2012

Magento : Get Product Ids, Sku, Category Id in Custom Module Field set




A) Open your Form.php File  "app\code\local\[Namespace]\[Module Name]\Block\Adminhtml\[Modele Name]\Edit\Tab\Form.php"




/* Three functions for call Category list, Product_ids and Product Skus */

 <?php

              class Addon_Beautygirl_Block_Adminhtml_Beautygirl_Edit_Tab_Form extends            Mage_Adminhtml_Block_Widget_Form

  {

        public function buildCategoriesMultiselectValues(Varien_Data_Tree_Node $node, $values, $level = 0)
       {
               $level++;
               //-----new start for only 3 level category
               if($level>3)
               {
                         return $values;
                         // print_r($values);
                }
                //-----new close
                $values[$node->getId()]['value'] =  $node->getId();
                $values[$node->getId()]['label'] = str_repeat("---", $level) . $node->getName();

                foreach ($node->getChildren() as $child)
                {
                       $values = $this->buildCategoriesMultiselectValues($child, $values, $level);
                 }
                 return $values;
       }

       public function load_tree()
      {
                $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
                $store = 1;
                $parentId = 1;
                $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
                $root = $tree->getNodeById($parentId);
                 if($root && $root->getId() == 1)
                 {
                         $root->setName(Mage::helper('catalog')->__('Root'));
                  }
                  $collection = Mage::getModel('catalog/category')->getCollection()
                                       ->setStoreId($store)
                                       ->addAttributeToSelect('name')
                                       ->addAttributeToSelect('is_active');
                  $tree->addCollectionData($collection, true);
                  return $this->buildCategoriesMultiselectValues($root, array());
         }

         function getProductCollection()
         {
                 $model = Mage::getModel('catalog/product'); //getting product model
                 $collection = $model->getCollection(); //products collection
                 $count = 0;
                 foreach ($collection as $product) //loop for getting products
                {
                        $a = $count++;
                        $values[$a]['label'] = $product->getId();
                        $values[$a]['value'] = $product->getId();
                        //$pids[] = $product->getId();
                        //return $product->getSku();
                  }
                  //print_r($pids);
                  return $values;
           }

        function getProductCollectionskus()
       {
                 $model = Mage::getModel('catalog/product'); //getting product model
                 $collection = $model->getCollection(); //products collection
                 $count = 0;
                 foreach ($collection as $product) //loop for getting products
                 {
                         $a = $count++;
                         $values[$a]['label'] = $product->getSku();
                         $values[$a]['value'] = $product->getSku();
                 }
                 //print_r($pids);
                 return $values;
        }




  protected function _prepareForm()
  {
      $form = new Varien_Data_Form();
      $this->setForm($form);
      $fieldset = $form->addFieldset('beautygirl_form', array('legend'=>Mage::helper('beautygirl')->__('Item information')));
   
      $fieldset->addField('title', 'text', array(
          'label'     => Mage::helper('beautygirl')->__('Title'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
      ));

 $fieldset->addField('status', 'select', array(
          'label'     => Mage::helper('beautygirl')->__('Status'),
          'name'      => 'status',
          'values'    => array(
                              array(
                              'value'     => 1,
                              'label'      => Mage::helper('beautygirl')->__('Enabled'),
                               ),
                             array(
                             'value'     => 2,
                             'label'     => Mage::helper('beautygirl')->__('Disabled'),
                              ),
                              ),
         ));

    $fieldset->addField('filename', 'file', array(
          'label'     => Mage::helper('beautygirl')->__('File'),
          'required'  => true,
          'name'      => 'filename',
 ));

/* This Variable's Contain that Function's Values */

 $pids = $this->getProductCollection();
 $skus = $this->getProductCollectionskus();
 $categories_values = $this->load_tree();

 $field set->addField('girloneproductid', 'multiselect', array(
                'name' => 'girloneproductid',
                'label' => Mage::helper('beautygirl')->__('Select Product ID'), 
                'required' => true ,
                'values' => $pids,
));

 $fieldset->addField('girloneproductsku', 'multiselect', array(
                'name' => 'girloneproductsku',
                'label' => Mage::helper('beautygirl')->__('Select Product SKU'), 
                'required' => false ,
                'values' => $skus,
));

$fieldset->addField('girlonecategoryid', 'multiselect', array(
                'name' => 'girlonecategoryid',
                'label' => Mage::helper('beautygirl')->__('Select Category'), 
                'required' => false ,
                'values' => $categories_values,
));