0

I have created order programatically in magento1.9, but order status inserted as "Payment accepted" by default but i need to "New - Payment Pending" and Currency also not saving.

My Code:

       public function orderCreate()
 {
    $paymentMethod = 'cashondelivery';
    $shippingMethod = 'flatrate_flatrate';      
    $productsid=array(1=>2=>1);
    $websiteId = Mage::app()->getWebsite()->getId();
    $store = Mage::app()->getStore();

    $customer = Mage::getModel('customer/customer')->setWebsiteId($websiteId)->loadByEmail($post['email']);
    $quote = Mage::getModel('sales/quote')->setStoreId($store->getId());
    //print_r($quote->getData());exit;
        //$av=  
//print_r($av->getData());exit;
    //$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();


    // Assign customer to quote
    $quote->assignCustomer($customer);

    foreach($productsid as $pids=>$qty)
    {
        $product = Mage::getModel('catalog/product')->load($pids);
        $quote->addProduct($product, new Varien_Object(array('qty' => $qty)));
    }

    $customerBillingAddress = $customer->getDefaultBillingAddress();
    $customerShippingAddress = $customer->getDefaultShippingAddress();

    $customerBillingAddress=$customerBillingAddress->getData();
    $customerShippingAddress=$customerShippingAddress->getData();


    //Add billing address to quote
    $billingAddressData = $quote->getBillingAddress()->addData($customerBillingAddress);

    //Add shipping address to quote
    $shippingAddressData = $quote->getShippingAddress()->addData($customerShippingAddress);

    //Collect shipping rates on quote
    $shippingAddressData->setCollectShippingRates(true)->collectShippingRates();

    $shippingAddressData->setShippingMethod($shippingMethod)->setPaymentMethod('payon_cashondelivery'); //Shipping is flatrate for this example

    $quote->getPayment()->importData(array('method' => 'payon_cashondelivery')); 
    $quote->setCurrency($store->getCurrentCurrencyCode());


    try {
        $quote->collectTotals();
        $quote->save();
        $service = Mage::getModel('sales/service_quote', $quote);
        $service->submitAll();
        $incrementId = $service->getOrder()->getRealOrderId();


    }
    catch (Exception $e) {

            Mage::getSingleton('customer/session')->addError($e->getMessage());
            $this->_redirect('*/*/');
            return;
        }


  }

Can anyone help me on this.

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.