0

we are using marketplace extension so seller can able to generate invoice their Dashboard

so we are using this code for generate invoice

 $shipment->getOrder()->setIsInProcess(true);
                        $transactionSave = Mage::getModel('core/resource_transaction')
                                    ->addObject($shipment)->addObject($shipment->getOrder())->save();

But after that it automatically order status Complete. So that i change in this way

$shipment->getOrder()->setState('invoice');


                        $transactionSave = Mage::getModel('core/resource_transaction')
                                    ->addObject($shipment)->addObject($shipment->getOrder())->save();

After that i add some custom order status like Shipement when i click it automatically change complete instaed of shipement

Shipment controller

public function shipementorderAction(){
                $id = $this->getRequest()->getParam('id');

                $order = Mage::getModel('sales/order')->load($id);
                $order->setData('state', 'shipement');
                $order->setStatus('shipement');
                $history = $order->addStatusHistoryComment('', false);
                $history->setIsCustomerNotified(false);
                $order->save(); 

                $order->sendOrderUpdateEmail(true, null);

                $this->_getSession()->addSuccess(
                    $this->__('The order state has been changed.')
                );
                //$this->_redirect('mpshippingmanager/shipping/index');
                Mage::getSingleton('core/session') ->addSuccess('Order Updated Successfully'); $this->_redirectReferer();


                }

enter image description here

i don't know what is the problem?

15
  • If you create invoice & shipping to order all qty then order status must completed and it is magento default functionality
    – Abdul
    Dec 24, 2015 at 10:13
  • how to change that
    – Magento 2
    Dec 24, 2015 at 10:14
  • is it automatically change complete status after create shipment right?
    – Abdul
    Dec 24, 2015 at 10:21
  • once create invoice that state change invoiced after i click shipment it shows complete
    – Magento 2
    Dec 24, 2015 at 10:23
  • after i click shipment it shows invoice right
    – Abdul
    Dec 24, 2015 at 10:28

2 Answers 2

0

Below are the status's you can use

const STATE_NEW             = 'new';
const STATE_PENDING_PAYMENT = 'pending_payment';
const STATE_PROCESSING      = 'processing';
const STATE_CLOSED          = 'closed';
const STATE_CANCELED        = 'canceled';
const STATE_HOLDED          = 'holded';
const STATE_PAYMENT_REVIEW  = 'payment_review';

Code for updating the status.

$order = Mage::getModel('sales/order')->load($orderid, 'increment_id');
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
$order->save();

Above code will update all the status's except COMPLETE Status. As Order becomes complete only when invoice and shipment is created. Once invoice and shipment is created order will automatically changed to Complete.

so for that you can use below code.

Create Invoice

$invoice = $order->prepareInvoice()
                 ->setTransactionId($order->getId())
                 ->addComment($comment)
                 ->register()
                 ->pay();

$transaction_save = Mage::getModel('core/resource_transaction')
                 ->addObject($invoice)
                 ->addObject($invoice->getOrder());
$transaction_save->save();

I hope this will help you.

1
0

Follow this:

Override order model file app/code/core/Mage/Sales/Model/Order.php in local or community

OR

copy core Order.php file in local folder app/code/local/Mage/Sales/Model

After replace code in function _checkState() from

protected function _checkState()
{
    if (!$this->getId()) {
        return $this;
    }

    $userNotification = $this->hasCustomerNoteNotify() ? $this->getCustomerNoteNotify() : null;

    if (!$this->isCanceled()
        && !$this->canUnhold()
        && !$this->canInvoice()
        && !$this->canShip()) {
        if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
            if ($this->getState() !== self::STATE_COMPLETE) {
                $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
            }
        }
        /**
         * Order can be closed just in case when we have refunded amount.
         * In case of "0" grand total order checking ForcedCanCreditmemo flag
         */
        elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded()
            && $this->hasForcedCanCreditmemo())
        ) {
            if ($this->getState() !== self::STATE_CLOSED) {
                $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
            }
        }
    }

    if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) {
        $this->setState(self::STATE_PROCESSING, true, '', $userNotification);
    }
    return $this;
}

To

protected function _checkState()
{
    if (!$this->getId()) {
        return $this;
    }

    $userNotification = $this->hasCustomerNoteNotify() ? $this->getCustomerNoteNotify() : null;

    if (!$this->isCanceled()
        && !$this->canUnhold()
        && !$this->canInvoice()
        && !$this->canShip()) {
        if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
            if ($this->getState() == 'invoice') {
                $this->_setState('shipment', true, '', $userNotification);
            }
            elseif ($this->getState() == 'shipment') {
                $this->_setState('shipment', true, '', $userNotification);
            }
            elseif ($this->getState() == 'Shipment') {
                $this->_setState('Shipment', true, '', $userNotification);
            }elseif($this->getState() !== self::STATE_COMPLETE) {
                $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
            }

        }
        /**
         * Order can be closed just in case when we have refunded amount.
         * In case of "0" grand total order checking ForcedCanCreditmemo flag
         */
        elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded()
            && $this->hasForcedCanCreditmemo())
        ) {
            if ($this->getState() !== self::STATE_CLOSED) {
                $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
            }
        }
    }

    if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) {
        $this->setState(self::STATE_PROCESSING, true, '', $userNotification);
    }
    return $this;
}
4
  • No change same thing only invoice status also not showing
    – Magento 2
    Dec 24, 2015 at 12:19
  • invoice status changed but if i click shipment it automatically complete
    – Magento 2
    Dec 24, 2015 at 12:57
  • comment code : $this->_setState(self::STATE_COMPLETE, true, '', $userNotification) and try again for testing
    – Abdul
    Dec 24, 2015 at 13:14
  • After click shipment status not showing
    – Magento 2
    Dec 24, 2015 at 13:50

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.