0

I have a problem, my shop allows users to buy products with "Manage Stock = No and Qty = 0".

It's work fine, but when the order is created, if the customer buys the product with qty > 0 then order status = complete, but qty < 0, order status is not complete.

How to set default order status is complete when the order is created.

Thanks all.

My code

protected function _getOrderCreateModel() {
        return Mage::getSingleton('adminhtml/sales_order_create');
}

public function createOrder($object) {

        $this->init($object);
        $methodInstance = $this->_getOrderCreateModel()->getQuote()->getPayment()->getMethodInstance();
        $methodInstance->getInfoInstance()->setQuote($this->_getOrderCreateModel()->getQuote());
        $methodInstance->validate();
        $this->_getOrderCreateModel()->getQuote()->setStoreToQuoteRate(1);
        $this->_getOrderCreateModel()->getQuote()->setBaseToGlobalRate(1);
        $this->_getOrderCreateModel()->getQuote()->setStoreToBaseRate(1);
        $this->_getOrderCreateModel()->getQuote()->setBaseToQuoteRate(1);
        if ($this->checkRewardPointModule()):
            $amt = (-1) * Mage::helper("posrewardpoints")->creditsToMoney($object['pos_credits_credits_used']);
            $this->_getOrderCreateModel()->getQuote()->setPosCreditsApplied($object['pos_credits_applied']);
            $this->_getOrderCreateModel()->getQuote()->setPosCreditsCreditsUsed($object['pos_credits_credits_used']);
            $this->_getOrderCreateModel()->getQuote()->setPosCreditsMoneyUsed($amt);
        endif;
        $this->_getOrderCreateModel()->saveQuote();
        $this->_getOrderCreateModel()->getQuote()->setTotalsCollectedFlag(true);

        $order = $this->_getOrderCreateModel()->createOrder();
        $order->setData('pos_user_id', $object['pos_user_id']);
        if ($object['comments'] != '') {
            $order->addStatusToHistory($order->getStatus(), $object['comments'], false);
            $order->save();
        }
        if ($object['order_collected_by'] != '') {
            $state = $order->getState();
            $status = 'order_collected_by';
            $isNotified = false;
            $order->setState($state);
            $order->setStatus($status);
            $order->addStatusToHistory($order->getStatus(), $object['order_collected_by'],$isNotified);
            $order->save();
        }
        $couponCode = $this->_getOrderCreateModel()->getQuote()->getCouponCode();
        if (!empty($couponCode)) {
            Mage::helper('PointOfSales/Discount')->deleteCoupon();
        }
        $this->_getOrderCreateModel()->getQuote()->setIsActive(false)->save();

        $this->affectWarehouse($order);

        return $order;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.