Trying to import orders to magento from other platform. I have almost done except import products with attribute stock_data is_in_stock set to 0. If I set manually the value to 1 imports correctly. I've tried it setting the value temporally to 1 and once is imported set it to 0 when needed, but i think is not the best way. Is there any other way to do it? any help will be appreciated.

function _order_create($data){
        if(is_array($data) and !empty($data['product'])){
            $quote = Mage::getModel('sales/quote')

            $customer = Mage::getModel('customer/customer')

            // add product(s)

             foreach ($data['product'] as $id => $pdata) {

                $product = Mage::getModel('catalog/product')->load($pdata['id']);
                $buyInfo = array('qty' =>$pdata['qty']);
//****************** here set is_in_stock to 1
                $quote->addProduct($product, new Varien_Object($buyInfo));
                $quote->save(); // without saving the quote here I get error

                $quoteItem = $quote->getItemByProduct($product);
// ****************** here set is_in_stock to 0

            foreach ($data['address']['shipping'] as $key => $value) {
                $addressDataShipping[$key] = $value;

            foreach ($data['address']['billing'] as $key => $value) {
                $addressDataBilling[$key] = $value;

            $billingAddress = $quote->getBillingAddress()->addData($addressDataBilling);
            $shippingAddress = $quote->getShippingAddress()->addData($addressDataShipping);

            $quote->getPayment()->importData(array('method' => $data['methods']['payment']));

            $service = Mage::getModel('sales/service_quote', $quote);

            $order = $service->getOrder();
            $order->setData('state', $data['order']['status']);

            //printf("Created order %s\n", $order->getIncrementId());

This is the method im using

Thanks for reading!

EDIT: the easiest way is before start adding products set manage_stock to 0 and once finished set it back to 1


Are you using the manage stock feature? You could turn this off whilst the import runs? Or configure backorders? Even just temporarily for the product you are importing. Or use your approach. Your approach is the simplest I can think of.

  • Thanks @dominic-xigen disabling manage_stock and enable it after the import is the easiest way to do it. Otherwise i need to know the previous 'is_in_stock' value to set it back. – rekobeko May 24 '19 at 8:52

Your Answer

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

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