Showing posts with label shipping. Show all posts
Showing posts with label shipping. Show all posts

Saturday 22 September 2018

How to Skip | Hide shipping address in checkout Magento 1.9

Step 1 :

Create config.xml file : app/code/local/Jaydip/Kansagra/etc/config.xml

<config>
   <global>
        <blocks>
            <jaydip_kansagra>
                <class>Jaydip_Kansagra_Block</class>
            </jaydip_kansagra>
            <!-- For Hide Shipping address-->
            <checkout>
                <rewrite>
                    <onepage>Jaydip_kansagra_Block_Kansagra_Checkout_Onepage</onepage>
                </rewrite>
            </checkout>
            <!-- For Hide Shipping address-->
       </blocks>
       ...........
       ...........
       ...........
       <!-- For Hide Shipping address-->
        <rewrite>
            <hideshippingadd> <!--This can be any unique id -->
                <from><![CDATA[#^/checkout/onepage/#]]></from>  <!-- the URL which u want to override-->
                <to>/kansagra/onepage/</to>  <!-- destination url -->
            </hideshippingadd>
        </rewrite>
        <!-- For Hide Shipping address-->
       ...........
       ...........
       ...........
   </global>
</config>


Step 2 : 

Create OnepageController.php file : app/code/local/Jaydip/Kansagra/controllers/OnepageController.php

<?php
require_once Mage::getModuleDir('controllers', "Mage_Checkout") . DS . "OnepageController.php";
class Jaydip_Kansagra_OnepageController extends Mage_Checkout_OnepageController {
    public function saveBillingAction() {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('billing', array());
            $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
            if (isset($data['email'])) {
                $data['email'] = trim($data['email']);
            }
            $result = $this->getOnepage()->saveBilling($data, $customerAddressId);
            if (!isset($result['error'])) {
                if ($this->getOnepage()->getQuote()->isVirtual()) {
                    $result['goto_section'] = 'payment';
                    $result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
                    );
                } 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()
                    );
                 
                } else {
                    $result['goto_section'] = 'shipping';
                }
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }
}

Step 3 :

Create Onepage.php file : app/code/local/Jaydip/Kansagra/Block/Kansagra/Checkout/Onepage.php

<?php
class Jaydip_Kansagra_Block_Kansagra_Checkout_Onepage extends Mage_Checkout_Block_Onepage {
    protected function _getStepCodes() {
        return array('login', 'billing', 'shipping_method', 'payment', 'review');
    }
}

Step 4 : 

And now you need to copy billing.phtml from app/design/frontend/base/default/checkout/onepage

folder into app/design/frontend/rwd/default/template/newgenray/checkout folder.

Find following code

<li class="control">
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"<?php if ($this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo Mage::helper('core')->quoteEscape($this->__('Ship to this address')) ?>" onclick="$('shipping:same_as_billing').checked = true;" class="radio" /><label for="billing:use_for_shipping_yes"><?php echo  $this->__('Ship to this address') ?></label>
</li>
<li class="control">
<input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0"<?php if (!$this->isUseBillingAddressForShipping()) {?> checked="checked"<?php }?> title="<?php echo Mage::helper('core')->quoteEscape($this->__('Ship to different address')) ?>" onclick="$('shipping:same_as_billing').checked = false;" class="radio" /><label for="billing:use_for_shipping_no"><?php echo $this->__('Ship to different address') ?></label>
</li>

and replace this by

<li class="control">
   <input type="hidden" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"  />
</li>

Friday 3 August 2018

How to add | update Shipping Price on existing order in Magento 1.9

$shippingamount = 10.00;
        try {
            $order = Mage::getModel('sales/order')->load(37881)
                    ->setShippingMethod('cstoreshipping_cstoreshipping')
                    ->setShippingAmount($shippingamount)
                    ->setBaseShippingAmount($shippingamount)
                    ->setShippingDescription('Shipping by third party');
            $order->setGrandTotal($order->getGrandTotal() + $shippingamount);
            $order->setBaseGrandTotal($order->getBaseGrandTotal() + $shippingamount);
            $order->save();
            pre($order->getData());
        } catch (Exception $e) {
            pre($e->getMessage());
        }

Thursday 15 September 2016

How to change the sort order for shipping in admin panel in magento



Step 1 : You have to copy this two files to your Theme in the adminhtml

app/design/adminhtml/default/default/template/sales/order/shipment/create/tracking.phtml
app/design/adminhtml/default/default/template/sales/order/invoice/create/tracking.phtml


Step 2 : Open : app/design/adminhtml/default/default/template/sales/order/shipment/create/tracking.phtml
(you will find this code at Line number 93)

Replace with

<select name="tracking[__index__][carrier_code]" id="trackingC__index__" class="select carrier" style="width:110px;" disabled="disabled">
    <?php foreach ($this->getCarriers() as $_code=>$_name): ?>
    <option value="<?php echo $_code ?>"><?php echo $this->escapeHtml($_name) ?></option>
    <?php endforeach; ?>
</select>

Step 3 : Open : app/design/adminhtml/default/default/template/sales/order/invoice/create/tracking.phtml
(you will find this code at Line number 93)

Replace with

<select name="tracking[__index__][carrier_code]" id="trackingC__index__" class="select carrier" style="width:110px;" disabled="disabled">
    <?php foreach ($this->getCarriers() as $_code=>$_name): ?>
    <option <?php if ($_code=="ups"): ?>selected<?php endif; ?> value="<?php echo $_code ?>"><?php echo $this->escapeHtml($_name) ?></option>
    <?php endforeach; ?>
</select>

Tuesday 26 April 2016

Create dropdown/select box in magento system.xml for payment/shipping configuration

Create drop down in system.xml and show custom values in it, rather than using default magento classes only

Directory : app/code/local/Companyname/Modulename/config/system.xml

In system.xml

<config>
  <sections>
<payment>
  <groups>
<Modulename translate="label" module="Modulename">
<label>Payment Module</label>
       <sort_order>670</sort_order>
       <show_in_default>1</show_in_default>
       <show_in_website>1</show_in_website>
       <show_in_store>0</show_in_store>
<fields>
<paymentmethod translate="label comment">
   <label>Payment method</label>
   <comment>Omni Payment method.</comment>
   <frontend_type>select</frontend_type>
   <source_model>Modulename/Modelname</source_model>
   <sort_order>30</sort_order>
   <show_in_default>1</show_in_default>
   <show_in_website>0</show_in_website>
   <show_in_store>0</show_in_store>
</paymentmethod>
</fields>
</Modulename>
            </groups>
        </payment>
    </sections>
</config>

If you want to create your custom source_Model, you need to do the following steps: Create a Pmethod.php in app/code/local/Companyname/Modulename/Model/Pmethod.php Companyname_Modulename is our module name. You need to create a function name toOptionArray() as mention below, the value and label can be anything you want to be display in dropdown

In Pmethod.php 

class Companyname_Modulename_Model_Pmethod
{
    public function toOptionArray()
    {
        return array(
            array(
                'value' => 'key1',
                'label' => 'Label 1',
            ),
            array(
                'value' => 'key2',
                'label' => 'label 2',
            )
        );
    }
}

Tuesday 1 September 2015

How to create shipping and invoice in magneto by code or API


Various merchants, various demands. Imagine you have a private on site sale or something like that, where your checkout requirements are pretty simply: create invoice / ship and complete the order all at once. For example, you are doing the checkout for bunch of people standing in front of you, paying you money right on the spot. In such scenario overload of manually creating an invoice and shipment can be too much.

Thus, having your Magento automatically invoice/ship/complete orders can be a logical request. So how do we do that?

Easy! All you need to do is to observe the sales_order_save_after event or observe the controller_action_predispatch event and target the Mage_Checkout_OnepageController::successAction() catching the Mage::getSingleton(‘checkout/session’)->getLastOrderId(). In this example I decided to demonstrate the possible (not ideal, or not even the best) “sales_order_save_after event” approach. 

And here is the code for our observer model. 

$order = $observer->getEvent()->getOrder();
 
        $orders = Mage::getModel('sales/order_invoice')->getCollection()
                        ->addAttributeToFilter('order_id', array('eq'=>$order->getId()));
        $orders->getSelect()->limit(1);  
 
        if ((int)$orders->count() !== 0) {
            return $this;
        }
 
        if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
 
            try {
                if(!$order->canInvoice()) {
                    $order->addStatusHistoryComment('Inchoo_Invoicer: Order cannot be invoiced.', false);
                    $order->save();  
                }
 
                //START Handle Invoice
                $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
 
                $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
                $invoice->register();
 
                $invoice->getOrder()->setCustomerNoteNotify(false);          
                $invoice->getOrder()->setIsInProcess(true);
                $order->addStatusHistoryComment('Automatically INVOICED by Invoicer.', false);
 
                $transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($invoice)
                    ->addObject($invoice->getOrder());
 
                $transactionSave->save();
                //END Handle Invoice
 
                //START Handle Shipment
                $shipment = $order->prepareShipment();
                $shipment->register();
 
                $order->setIsInProcess(true);
                $order->addStatusHistoryComment('Automatically SHIPPED by Invoicer.', false);
 
                $transactionSave = Mage::getModel('core/resource_transaction')
                    ->addObject($shipment)
                    ->addObject($shipment->getOrder())
                    ->save();
                //END Handle Shipment
            } catch (Exception $e) {
                $order->addStatusHistoryComment('Inchoo_Invoicer: Exception occurred during automaticallyInvoiceShipCompleteOrder action. Exception message: '.$e->getMessage(), false);
                $order->save();
            }                
        }