Showing posts with label invoice. Show all posts
Showing posts with label invoice. Show all posts

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>

Thursday 19 May 2016

How to enable / disable edit qty create invoice in magento

How to enable / disable edit qty create invoice in magento.



You can change enable/disable edit qty when create new invoice in magento.

Open you payment method model file.

Ex. You want to enable/disable edit qty when use "Cash On Delivery"

Open file:
/var/www/html/magentostore/app/code/core/Mage/Payment/Model/Method/Cashondelivery.php

class Mage_Payment_Model_Method_Cashondelivery extends Mage_Payment_Model_Method_Abstract
{
    /**
     * Payment method code
     *
     * @var string
     */
    protected $_code  = 'cashondelivery';
    protected $_canCapture = true;
    protected $_canCapturePartial = true;
    .....
    .....
    .....
}

Add  protected $_canCapturePartial = true; in this file.

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();
            }                
        }