PHP SOLUTIONS

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

Thursday 24 January 2013

Magento : Add custom field in registration form and in admin side

HI !!!

Here I am add the Custom Field for the Customer Registration Form using the database,

It's very simple to add Custom Field in Registration Form and also in Manage Customer Account Information of Admin,

This is the easiest way to Create field using Database Query !!!!!

A) First, Open your Database of Magento

    Click on SQL tab of  your Database and simplly write Below Query in that

    1)  Insert into eav_attribute set      entity_type_id="1",attribute_code="occupation",backend_type="text",frontend_input="text",frontend_label="Occupation",is_required=0,is_user_defined=0,is_unique=0

   2) Copy the Last inserted Id of  "Eav_attribute" table

   3)  Insert into `eav_entity_attribute` set entity_type_id=1,attribute_set_id=1, attribute_group_id=1,attribute_id=134,sort_order=111

   Here, you mention that change your attribute id with the Last inserted id of Eav_attribute table.

   attribute_id = "Last Inserted Id of Eav_attribute" table

   4) insert into  `customer_eav_attribute` set attribute_id="134",is_visible=1,multiline_count=1,is_system=0,sort_order=111

  same as Point (3) change attribute_id

  5) insert into  `customer_form_attribute` set form_code="adminhtml_customer",attribute_id=134

 same as Point (3) change attribute_id

  6) insert into  `customer_form_attribute` set form_code="checkout_register",attribute_id=134

  same as Point (3) change attribute_id

 7) insert into  `customer_form_attribute` set form_code="customer_account_create",attribute_id=134

 same as Point (3) change attribute_id

8) insert into  `customer_form_attribute` set form_code="customer_account_edit",attribute_id=134

 same as Point (3) change attribute_id



B) Now, some code for Create Field to saw in Front end,

   1) open Customer/Form/registration.phtml

   simply Copy-Paste below code

 Copy this .......

   <li>
        <label for="occupation"><em></em><?php echo $this->__('Occupation') ?></label>

        <div class="input-box">

         <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />

         </div>
    </li>

   2) open Customer/Form/edit.phtml

    simply Copy-Paste below code

    Copy this .......

   <li>
        <label for="occupation"><em></em><?php echo $this->__('Occupation') ?></label>

        <div class="input-box">

         <input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__('Occupation') ?>" class="input-text" />

         </div>
    </li>


Enjoy!!!!!

This is work for me in Magento 1.7


 

Thursday 3 January 2013

Magento : Add Fixed price to same Product for a Multiple Qty in cart

Hi,

 Actually This code for set custom price to each product in cart when it add to cart from Category Page,

That's why I found some solution for that add custom value to the Row Total of product

For that

A)  Open code\core\Mage\Sales\Model\Quote\Item\Abstract.php

     Find,  Function calcRowTotal()

  You can see this lines,  

    $total      = $this->getStore()->roundPrice($this->getCalculationPriceOriginal() * $qty;
    $baseTotal  = $this->getBaseCalculationPriceOriginal() * $qty;


    Simply, Add your custom value here

   $temp = 10;  /* Now $10 inserted in to the Row total of Product in cart */

    $total      = ($this->getStore()->roundPrice($this->getCalculationPriceOriginal()) * $qty) + $temp ;
    $baseTotal  = ($this->getBaseCalculationPriceOriginal() * $qty) + $temp;


Here the Basic idea for, Where to change for add custom value of row total of product
you can also set this dynamic as per your requirement,

Enjoy ::


   


,

Magento : Remove Shipping Method form Checkout

Hi,

  If in any case need to remove the Shipping Method from the site, then Now easily remove that by macking change in  following steps,

  For Remove Shipping Methods you need to change its function 

  This code is working for me in 1.7.0.2 but you can try this for older version also

A)  Open Mage/checkout/controllers/Onepagecontroller.php

     In this File Go to on  "function saveBillingAction() "

    Check this line in this function and change

     From

       elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
                    $result['goto_section'] = 'shipping_method';
                    $result['update_section'] = array(
                        'name' => 'shipping-method',
                        'html' => $this->_getShippingMethodsHtml()
                    );

     To

       elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
                    $result['goto_section'] = 'payment';
                    $result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
                    );

 B)  Now, In Onepagecontroller.php

   Go to on this function  "public function saveShippingAction()"

  change this function

  From

   public function saveShippingAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('shipping', array());
            $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
            $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

            if (!isset($result['error'])) {
                $result['goto_section'] = 'shipping_method';
                $result['update_section'] = array(
                    'name' => 'shipping-method',
                    'html' => $this->_getShippingMethodsHtml()
                );
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }      


To

public function saveShippingAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('shipping', array());
            $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
            $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

            if (!isset($result['error'])) {
                $result['goto_section'] = 'payment';
                $result['update_section'] = array(
                    'name' => 'payment-method',
                    'html' => $this->_getPaymentMethodsHtml()
                );
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }


C) After that Open Code/core/mage/sales/model/service/Quote.php

  Find this function " protected function _validate() "

  Here comment below code

  if ($addressValidation !== true) {
                Mage::throwException(
                    Mage::helper('sales')->__('Please check shipping address information. %s', implode(' ', $addressValidation))
                );
            }
            $method= $address->getShippingMethod();
            $rate  = $address->getShippingRateByCode($method);
            if (!$this->getQuote()->isVirtual() && (!$method || !$rate)) {
                Mage::throwException(Mage::helper('sales')->__('Please specify a shipping method.'));
            }

D) Open file code/core/mage/checkout/block/onepage/shipping/Method.php

   This is hide the Shipping Method tab from the Onepage checkout during Place the order

   Find below function

    public function isShow()
    {
        return !$this->getQuote()->isVirtual();
    }

   Change it with

    public function isShow()
    {
                return false;
    }


   Now, Finally you can check that your Shipping Method will remove from your site.

  Enjoy ::





,