Add 'Shipped' Status and make customer confirm receipt goods

1. Fist, Add a shipped status in backend


Add 'Shipped' Status and make customer confirm receipt goods_第1张图片
 

2.rewrite Mage_Adminhtml_Sales_Order_ShipmentController

<config>  
 <admin>
          <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Bysoft_Mysales before="Mage_Adminhtml">Bysoft_Mysales</Bysoft_Mysales>
                    </modules>
                </args>
            </adminhtml>
          </routers>
      </admin>

 

<?php
include_once("Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php");
class Bysoft_Mysales_Sales_Order_ShipmentController extends Mage_Adminhtml_Sales_Order_ShipmentController {
	protected function _saveShipment($shipment)
	{
		$shipment->getOrder()->setIsInProcess(true);
	
		$order = $shipment->getOrder();
	
		$order = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());
		$state = 'processing';
		$status = 'shipped';
		$comment = 'Changing state to Processing and status to shipped Status';
		$isCustomerNotified = false;
		$order->setState($state, $status, $comment, $isCustomerNotified);
		$order->save();
	
		$transactionSave = Mage::getModel('core/resource_transaction')
		->addObject($shipment)
		->save();
	
		return $this;
	}
}

 3. add a confirm controller for frontend , make cusotmer to confirm the order

<config>
   <frontend>
        <routers>
            <mysales>
                <use>standard</use>
                <args>
                    <module>Bysoft_Mysales</module>
                    <frontName>mysales</frontName>
                </args>
            </mysales>
        </routers>  
    </frontend>

 

<?php
class Bysoft_Mysales_ConfirmController extends Mage_Core_Controller_Front_Action {
	public function saveAction() {
		$order_id = Mage::app()->getRequest()->getParam('order_id');
		if(Mage::getSingleton('customer/session')->isLoggedIn()) {
			$customerData = Mage::getSingleton('customer/session')->getCustomer();
			$customer_id = $customerData->getId();
			$order = Mage::getModel('sales/order')->load($order_id);
			if ( $order->getCustomerId() == $customer_id) {
				$order->setData('state', "complete");
				$order->setStatus("complete");
				$history = $order->addStatusHistoryComment('Order status to complete by customer confirm.', false);
				$history->setIsCustomerNotified(false);
				$order->save();
				$message = $this->__('You have confirmed the order.');
				Mage::getSingleton('core/session')->addSuccess($message);
				$this->_redirectReferer();
			} else {
				return ;
			}
		} else {
			return ;
		}				
	}
}

 

你可能感兴趣的:(PHP)