1

How to get custom order status in frontend

We are using Marketplace in our site in that seller can able to processes order through front end. Now i added custom status as Shipment how to call this to frontend while seller click shipment order status also need to change

Same like i created a custom order status called shipment

Controller File

public function saveTrackingNumberAction(){
        try{
            if($this->getRequest()->isPost()){
                $orderid=$this->getRequest()->getParam('order_id');
                $trackingid=$this->getRequest()->getParam('tracking_id');
                $carrier=$this->getRequest()->getParam('carrier');
                $order=Mage::getModel('sales/order')->load($orderid);
                $partnerid=Mage::getSingleton('customer/session')->getCustomer()->getId();
                $items=array();
                $shippingAmount=0;
                $trackingsdata=Mage::getModel('mpshippingmanager/tracking')->getCollection()
                                                 ->addFieldToFilter('order_id',array('eq'=>$orderid))
                                                 ->addFieldToFilter('seller_id',array('eq'=>$partnerid));
                $product=Mage::getModel('catalog/product')->load($itemid);
                foreach($trackingsdata as $tracking){
                    $tracking->setTrackingNumber($trackingid);
                    $tracking->setCarrierName($carrier);
                    $tracking->save();
                    $product_name="";
                    $shippingAmount=$tracking->getShippingCharges();
                    $items=explode(',',$tracking->getItemIds());
                    foreach($order->getAllItems() as $item){
                        if(in_array($item->getId(),$items)){
                            $product_name =$product_name.$product->getName()." ,";
                        }
                    }

                    $product_name = $product->getName();
                    $to = $order->getCustomerEmail();

                    $emailTemp = Mage::getModel('core/email_template')->loadDefault('trackingnopartner');
                    $emailTempVariables = array();              
                    $adminEmail=Mage::getStoreConfig('trans_email/ident_general/email');
                    $emailTempVariables['myvar1'] = $order->getIncrementId();
                    $emailTempVariables['myvar2'] = $product_name;
                    $emailTempVariables['myvar3'] = $order->getIncrementId();
                    $emailTempVariables['myvar4'] = $trackingid;
                    $processedTemplate = $emailTemp->getProcessedTemplate($emailTempVariables);
                    $emailTemp->setSenderName('Admin');
                    $emailTemp->setSenderEmail($adminEmail);
                    $emailTemp->send($to,'Admin',$emailTempVariables);
                }

                    /**/
                $itemsarray = $this->_getItemQtys($order,$items);

                if(count($itemsarray)>0){
                    if($order->canInvoice()) { 
                        $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($itemsarray['data']);
                        $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
                        $invoice->setShippingAmount($shippingAmount);
                        $invoice->setSubtotal($itemsarray['subtotal']);
                        $invoice->setBaseSubtotal($itemsarray['baseSubtotal']);
                        $invoice->setGrandTotal($itemsarray['subtotal']+$shippingAmount);
                        $invoice->setBaseGrandTotal($itemsarray['subtotal']+$shippingAmount);
                        $invoice->register();

                        $transactionSave = Mage::getModel('core/resource_transaction')
                                    ->addObject($invoice)
                                    ->addObject($invoice->getOrder());
                        $transactionSave->save();
                        $order->sendNewOrderEmail()->addStatusHistoryComment(
                            Mage::helper('mpshippingmanager')->__('Notified customer about invoice #%s.', $invoice->getId())
                        )
                        ->setIsCustomerNotified(true)
                        ->save();
                        $seller_invoice_id = $invoice->getId();
                    }else{
                        if($order->hasInvoices()) {
                            foreach ($order->getInvoiceCollection() as $inv) { 
                                foreach ($inv->getAllItems() as $item) { 
                                    $product_id = $item->getProductId();
                                    $seller_pro_coll=Mage::getModel('marketplace/product')->getCollection()
                                                            ->addFieldToFilter('mageproductid',array('eq'=>$product_id))
                                                            ->addFieldToFilter('userid',array('eq'=>$partnerid));
                                    foreach ($seller_pro_coll as $value) {
                                        if($value->getMageproductid()){
                                            $seller_invoice_id = $inv->getId();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }


                    $shipment = false;              
                    $shipmentId = $this->getRequest()->getParam('shipment_id');         
                    $orderId = $orderid;    
                    if($shipmentId){
                        $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
                    }elseif($orderId){
                        $order  = Mage::getModel('sales/order')->load($orderId);
                        if (!$order->getId()) {
                            $this->_getSession()->addError($this->__('The order no longer exists.'));
                            return false;
                        }
                        if($order->getForcedDoShipmentWithInvoice()){
                            $this->_getSession()->addError($this->__('Cannot do shipment for the order separately from invoice.'));
                            return false;
                        }
                        if(!$order->canShip()){
                            $this->_getSession()->addError($this->__('Cannot do shipment for the order.'));
                            return false;
                        }

                        $savedQtys = $this->_getItemQtys($order,$items);
                        $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($savedQtys['data']);
                    }
                    $shipment->register();
                    $comment = '';
                    $shipment->getOrder()->setCustomerNoteNotify(1);
                    $responseAjax = new Varien_Object();
                    $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label'];
                    if ($isNeedCreateLabel && true) {
                        $responseAjax->setOk(true);
                    }
                    $shipment->getOrder()->setIsInProcess(true);
                    $transactionSave = Mage::getModel('core/resource_transaction')
                                ->addObject($shipment)->addObject($shipment->getOrder())->save();
                    /*sale list status update*/
                    $partnerid=Mage::getSingleton('customer/session')->getCustomer()->getId();
                    $collection = Mage::getModel('marketplace/saleslist')->getCollection()
                                ->addFieldToFilter('mageproownerid', array('eq' => $partnerid))
                                ->addFieldToFilter('mageorderid', array('eq' => $orderid));
                    foreach($collection as $saleproduct){
                        $saleproduct->setCpprostatus(1);
                        $saleproduct->save();
                    }
                    /*sale list status update*/
                    $shipment->sendEmail(1, $comment);
                    $shipmentCreatedMessage = $this->__('The shipment has been created.');
                    $labelCreatedMessage    = $this->__('The shipping label has been created.');
                    $this->_getSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage
                        : $shipmentCreatedMessage); 

                    $trackingcol1=Mage::getModel('mpshippingmanager/tracking')->getCollection()
                                ->addFieldtoFilter('order_id',array('eq'=>$orderid))
                                ->addFieldtoFilter('seller_id ',array('in'=>$partnerid));
                    $courrier="custom";
                    foreach($trackingcol1 as $row) {
                        if($shipment->getId() != '') { 
                            $row->setShipmentId($shipment->getId());
                            $row->setInvoiceId($seller_invoice_id)->save();
                            $track = Mage::getModel('sales/order_shipment_track')
                             ->setShipment($shipment)
                             ->setData('title',  $row->getCarrierName())
                             ->setData('number', $row->getTrackingNumber())
                             ->setData('carrier_code',  $courrier)
                             ->setData('order_id', $shipment->getData('order_id'))
                             ->save();
                        }
                    }
                }
                $trackingcol=Mage::getModel('mpshippingmanager/tracking')->getCollection()
                                ->addFieldtoFilter('order_id',array('eq'=>$orderid))
                                ->addFieldtoFilter('tracking_number',array('eq'=>''));
                if(count($trackingcol)==0){
                    $trackingcol=Mage::getModel('mpshippingmanager/tracking')->getCollection()
                                ->addFieldtoFilter('order_id',array('eq'=>$orderid))
                                ->addFieldtoFilter('tracking_number',array('eq'=>'canceled'));
                    $order = Mage::getModel('sales/order')->load($orderid);
                    if(count($trackingcol)==0){
                        $product_order_id = $order->getIncrementId();
                        $order->setStatus('test'); //**Custom Status**
                        $order->save();
                    }else{
                        $order->cancel();
                        $order->save();
                    }
                    $order->sendNewOrderEmail();
                    $historyItem = Mage::getResourceModel('sales/order_status_history_collection')
                        ->getUnnotifiedForInstance($order, Mage_Sales_Model_Order::HISTORY_ENTITY_NAME);
                    if ($historyItem) {
                        $historyItem->setIsCustomerNotified(1);
                        $historyItem->save();
                    }       
                }
                if(count($trackingsdata)==0)
                    Mage::getSingleton('core/session')->addError("This order doesn't contain Tracking Number..");
                else
                    Mage::getSingleton('core/session')->addSuccess('Tracking Number successfully Assign..');
                $this->_redirect('mpshippingmanager/shipping/invoice/id/',array('id'=>$orderid));
            }
        }catch(Exception $e){
            Mage::getSingleton('core/session')->addError($e->getMessage());
            $this->_redirect('mpshippingmanager/shipping/invoice/id/',array('id'=>$orderid));
        }
    }

.phtml file

<?php if($item_status=="Ordered"||$item_status=="Invoiced"){?>
                                                <button class="button wk_mp_btn" style="flaot:none" title="<?php echo $helper->__('Save Tracking Number') ?>" type="submit" id="save_butn" >
                                                    <span><span><?php echo $helper->__('Save Tracking Number') ?></span></span>
                                                </button>
                                            <?php } ?>

What's wrong on this?

2 Answers 2

1
<?php if($invoiceId):
?>
            <a href="<?php echo $this->getUrl('mpshippingmanager/shipping/order/',array('order_id'=>$mageorderid,'status'=>'shipment'));?>"><button class="button wk_mp_btn wk_invoiceslip" title="<?php// echo $helper->__('Shipment') ?>" id="<?php echo $mageorderid?>" style="float:right;">
        <span><span><?php echo $helper->__('Shipment') ?></span></span>
    </button></a>
        <?php endif; ?>

just add method in ShippingController.php

  public function orderAction()
  {
       echo $id = $this->getRequest()->getParam('order_id');
       echo $status = $this->getRequest()->getParam('status');
        $order = Mage::getModel('sales/order')->loadByIncrementId($id);
        $order->setData('state', $status);
     $order->setStatus($status);
     $history = $order->addStatusHistoryComment('', false);
     $history->setIsCustomerNotified(false);
     $order->save(); 
            $this->_getSession()->addSuccess(
                $this->__('The order state has been changed.')
            );
             //$this->_redirect('mpshippingmanager/shipping/index');


 }


public function testAction()
      {
           echo $id = $this->getRequest()->getParam('order_id');
           echo $status = $this->getRequest()->getParam('status');
            $order = Mage::getModel('sales/order')->loadByIncrementId($id);
            $order->setData('state', $status);
         $order->setStatus($status);
         $history = $order->addStatusHistoryComment('', false);
         $history->setIsCustomerNotified(false);
         $order->save(); 
                $this->_getSession()->addSuccess(
                    $this->__('The order state has been changed.')
                );
                 //$this->_redirect('mpshippingmanager/shipping/index');


     }
63
  • I am asking i already created custom order status Called Shipment how to call in front end to seller dashboard
    – Magento 2
    Dec 14, 2015 at 11:11
  • sorry don't understand you want the current order status or create status from frontend? Dec 14, 2015 at 11:12
  • create custom status from frontend?
    – Magento 2
    Dec 14, 2015 at 11:13
  • do you have any custom module added? Dec 14, 2015 at 11:16
  • add solution with module try that.. Dec 14, 2015 at 11:29
1

<?php $orderid=100001550; ?> <a href="<?php echo $this->getUrl('mpshippingmanager/shipping/order/',array('order_id'=>$orderid,'st‌​atus'=>'test'));?>"><button class="button wk_mp_btn wk_invoiceslip" title="<?php// echo $helper->__('Shipment') ?>" id="<?php echo $mageorderid?>" style="float:right;"> <span><span><?php echo $helper->__('test') ?></span></span> </button></a>

add it like that

<?php $orderid=100001550; ?> <a href="<?php echo $this->getUrl('mpshippingmanager/shipping/order/',array('order_id'=>$orderid,'st‌​atus'=>'somestatus'));?>"><button class="button wk_mp_btn wk_invoiceslip" title="<?php// echo $helper->__('Shipment') ?>" id="<?php echo $mageorderid?>" style="float:right;"> <span><span><?php echo $helper->__('test') ?></span></span> </button></a>

you can add unlimited status.

22
  • No it's not changeing
    – Magento 2
    Dec 15, 2015 at 6:11
  • the last code was working to change the status to rto Dec 15, 2015 at 6:18
  • Check my updated question
    – Magento 2
    Dec 15, 2015 at 6:23
  • this code is generate shipment and add the status. what you want to achieve from this code? Dec 15, 2015 at 6:25
  • yes that what i am asking
    – Magento 2
    Dec 15, 2015 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.