通过CSV导入Magento中的订单 [英] Import Orders in Magento through CSV

查看:245
本文介绍了通过CSV导入Magento中的订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码put是简单的产品和单一的产品。



以编程方式为所有类型的产品创建订单我已经添加产品到购物车后,我添加了所有参数订单像装运,付款方法和计费和运输方法相应。但当我添加选项产品我生成空白产品订单。



但是



http://pragneshkaria.com/programmatically-create-order-in-magento/



请建议我们如何以编程方式创建订单。

解决方案

 你必须创建模块

/ *为注册客户创建订单* /

$ id = 12; // get Customer Id
$ customer = Mage :: getModel('customer / customer') - > load($ id);
// print_r($ customer-> getData()); exit;
$ transaction = Mage :: getModel('core / resource_transaction');
$ storeId = $ customer-> getStoreId();
$ reservedOrderId = Mage :: getSingleton('eav / config') - > getEntityType('order') - > fetchNewIncrementId(1); // exit
$ order = Mage :: getModel('sales / order')
- > setIncrementId($ reservedOrderId)
- > setStoreId($ storeId)
- > setQuoteId (0)
- > setGlobal_currency_code('USD')
- > setBase_currency_code('USD')
- > setStore_currency_code('USD')
- > setOrder_currency_code ('美元');
//设置商店货币USD或任何其他

//设置客户数据
$ order-> setCustomer_email($ customer-> getEmail())
- > setCustomerFirstname($ customer-> getFirstname())
- > setCustomerLastname($ customer-> getLastname())
- > setCustomerGroupId($ customer-> getGroupId )
- > setCustomer_is_guest(0)
- > setCustomer($ customer);

//设置结算地址
$ billing = $ customer-> getDefaultBillingAddress();
$ billingAddress = Mage :: getModel('sales / order_address')
- > setStoreId($ storeId)
- > setAddressType(Mage_Sales_Model_Quote_Address :: TYPE_BILLING)
- > ; setCustomerId($ customer-> getId())
- > setCustomerAddressId($ customer-> getDefaultBilling())
- > setCustomer_address_id($ billing-> getEntityId())
- > setPrefix($ billing-> getPrefix())
- > setFirstname($ billing-> getFirstname())
- > setMiddlename($ billing-> getMiddlename )
- > setLastname($ billing-> getLastname())
- > setSuffix($ billing-> getSuffix())
- > setCompany($ billing- > getCompany())
- > setStreet($ billing-> getStreet())
- > setCity($ billing-> getCity())
- > setCountry_id ($ billing-> getCountryId())
- > setRegion($ billing-> getRegion())
- > setRegion_id($ billing-> getRegionId())
- > setPostcode($ billing-> getPostcode())
- > setTelephone($ billing-> getTelephone())
- > setFax($ billing-> getFax ;
$ order-> setBillingAddress($ billingAddress);

$ shipping = $ customer-> getDefaultShippingAddress();
$ shippingAddress = Mage :: getModel('sales / order_address')
- > setStoreId($ storeId)
- > setAddressType(Mage_Sales_Model_Quote_Address :: TYPE_SHIPPING)
- > ; setCustomerId($ customer-> getId())
- > setCustomerAddressId($ customer-> getDefaultShipping())
- > setCustomer_address_id($ shipping-> getEntityId $ b - > setPrefix($ shipping-> getPrefix())
- > setFirstname($ shipping-> getFirstname())
- > setMiddlename($ shipping-> getMiddlename )
- > setLastname($ shipping-> getLastname())
- > setSuffix($ shipping-> getSuffix())
- > setCompany($ shipping- > getCompany())
- > setStreet($ shipping-> getStreet())
- > setCity($ shipping-> getCity())
- > setCountry_id ($ shipping-> getCountryId())
- > setRegion($ shipping-> getRegion())
- > setRegion_id($ shipping-> getRegionId())
- > setPostcode($ shipping-> getPostcode())
- > setTelephone($ shipping-> getTelephone())
- > setFax($ shipping-> getFax ;

$ order-> setShippingAddress($ shippingAddress)
- > setShipping_method('flatrate_flatrate');
/ * - > setShippingDescription($ this-> getCarrierName('flatrate')); * /
/ *一些错误我得到这里需要进一步解决* /

//您可以根据需要在这里设置您的付款方式名称
$ orderPayment = Mage :: getModel('sales / order_payment')
- > setStoreId($ storeId)
- > setCustomerPaymentId(0)
- > setMethod('purchaseorder')
- > setPo_number('â'''');
$ order-> setPayment($ orderPayment);

//说,我们有2个产品
//检查您的产品是否存在
//需要为可配置产品添加代码
$ subTotal = 0;
$ products = array(
'7088'=> array(
'qty'=> 2
),
'7089'=&
'qty'=> 1

);

foreach($ products as $ productId => $ product){
$ _product = Mage :: getModel('catalog / product') - > load($ productId);
$ rowTotal = $ _product-> getPrice()* $ product ['qty'];
$ orderItem = Mage :: getModel('sales / order_item')
- > setStoreId($ storeId)
- > setQuoteItemId(0)
- > setQuoteParentItemId NULL)
- > setProductId($ productId)
- > setProductType($ _ product-> getTypeId())
- > setQtyBackordered(NULL)
- > setTotalQtyOrdered($ product ['rqty'])
- > setQtyOrdered($ product ['qty'])
- > setName($ _ product-> getName())
- > setSku($ _ product-> getSku())
- > setPrice($ _ product-> getPrice())
- > setBasePrice($ _ product-> getPrice b $ b - > setOriginalPrice($ _ product-> getPrice())
- > setRowTotal($ rowTotal)
- > setBaseRowTotal($ rowTotal)

$ subTotal + = $ rowTotal;
$ order-> addItem($ orderItem);
}

$ order-> setSubtotal($ subTotal)
- > setBaseSubtotal($ subTotal)
- > setGrandTotal($ subTotal)
- > setBaseGrandTotal($ subTotal);

$ transaction-> addObject($ order);
$ transaction-> addCommitCallback(array($ order,'place'));
$ transaction-> addCommitCallback(array($ order,'save'));
$ transaction-> save();

/ *为客户创建订单* /

$ quote = Mage :: getModel('sales / quote')
- > setStoreId(Mage: :app() - > getStore('default') - > getId());

$ lsit_od_id = array('7125','7088','7089');
foreach($ lsit_od_id as $ key => $ value){
$ product = Mage :: getModel('catalog / product') - > load / * 6 =>一些产品ID * /
$ buyInfo = array('qty'=> 1);
$ quote-> addProduct($ product,new Varien_Object($ buyInfo));
}


$ billingAddress = array(
'firstname'=>'abc',
'lastname'=>'ccc'
'company'=>'hhhh',
'email'=>'manoj@gmail.com',
'street'=& Street Line_1',
'Sample Street Line_2'
),
'city'=>'City',
'region_id'=>'',
'region'=>'State / Province',
'postcode'=>'12345',
'country_id'=>'NL',
'telephone'=& '1234567890',
'fax'=>'123456987',
'customer_password'=>'',
'confirm_password'=>'',
'save_in_address_book '=>'0',
'use_for_shipping'=>'1',
);

$ quote-> getBillingAddress()
- > addData($ billingAddress);

$ quote-> getShippingAddress()
- > addData($ billingAddress)
- > setShippingMethod('tablerate_bestway')
- > setPaymentMethod 'checkmo')
- > setCollectShippingRates(true)
- > collectTotals();

$ quote-> setCheckoutMethod('guest')
- > setCustomerId(null)
- > setCustomerEmail($ quote-> getBillingAddress getEmail())
- > setCustomerIsGuest(true)
- > setCustomerGroupId(Mage_Customer_Model_Group :: NOT_LOGGED_IN_ID);

$ quote-> getPayment() - > importData(array('method'=>'checkmo'));

$ quote-> save();

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


I have used below code put is it is working on simple product and single product.

creating order programmatically for all types of product first i have added product into the cart after i have add all parameter to order like shipment,payment method and billing and shipping method accordingly.But when i add option to product i generate blank product order.

But is not working for other product type.

I used below script also

http://pragneshkaria.com/programmatically-create-order-in-magento/

Please suggest how we can create order programmatically.

解决方案

you have to create module for that 

/* create order for registered customer */

    $id=12; // get Customer Id
    $customer = Mage::getModel('customer/customer')->load($id);
    // print_r($customer->getData());exit;
    $transaction = Mage::getModel('core/resource_transaction');
    $storeId = $customer->getStoreId();
    $reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId(1);//exit();
    $order = Mage::getModel('sales/order')
    ->setIncrementId($reservedOrderId)
    ->setStoreId($storeId)
    ->setQuoteId(0)
    ->setGlobal_currency_code('USD')
    ->setBase_currency_code('USD')
    ->setStore_currency_code('USD')
    ->setOrder_currency_code('USD');
    //Set your store currency USD or any other

    // set Customer data
    $order->setCustomer_email($customer->getEmail())
    ->setCustomerFirstname($customer->getFirstname())
    ->setCustomerLastname($customer->getLastname())
    ->setCustomerGroupId($customer->getGroupId())
    ->setCustomer_is_guest(0)
    ->setCustomer($customer);

    // set Billing Address
    $billing = $customer->getDefaultBillingAddress();
    $billingAddress = Mage::getModel('sales/order_address')
    ->setStoreId($storeId)
    ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
    ->setCustomerId($customer->getId())
    ->setCustomerAddressId($customer->getDefaultBilling())
    ->setCustomer_address_id($billing->getEntityId())
    ->setPrefix($billing->getPrefix())
    ->setFirstname($billing->getFirstname())
    ->setMiddlename($billing->getMiddlename())
    ->setLastname($billing->getLastname())
    ->setSuffix($billing->getSuffix())
    ->setCompany($billing->getCompany())
    ->setStreet($billing->getStreet())
    ->setCity($billing->getCity())
    ->setCountry_id($billing->getCountryId())
    ->setRegion($billing->getRegion())
    ->setRegion_id($billing->getRegionId())
    ->setPostcode($billing->getPostcode())
    ->setTelephone($billing->getTelephone())
    ->setFax($billing->getFax());
    $order->setBillingAddress($billingAddress);

    $shipping = $customer->getDefaultShippingAddress();
    $shippingAddress = Mage::getModel('sales/order_address')
    ->setStoreId($storeId)
    ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
    ->setCustomerId($customer->getId())
    ->setCustomerAddressId($customer->getDefaultShipping())
    ->setCustomer_address_id($shipping->getEntityId())
    ->setPrefix($shipping->getPrefix())
    ->setFirstname($shipping->getFirstname())
    ->setMiddlename($shipping->getMiddlename())
    ->setLastname($shipping->getLastname())
    ->setSuffix($shipping->getSuffix())
    ->setCompany($shipping->getCompany())
    ->setStreet($shipping->getStreet())
    ->setCity($shipping->getCity())
    ->setCountry_id($shipping->getCountryId())
    ->setRegion($shipping->getRegion())
    ->setRegion_id($shipping->getRegionId())
    ->setPostcode($shipping->getPostcode())
    ->setTelephone($shipping->getTelephone())
    ->setFax($shipping->getFax());

    $order->setShippingAddress($shippingAddress)
    ->setShipping_method('flatrate_flatrate');
    /*->setShippingDescription($this->getCarrierName('flatrate'));*/
    /*some error i am getting here need to solve further*/

    //you can set your payment method name here as per your need
    $orderPayment = Mage::getModel('sales/order_payment')
    ->setStoreId($storeId)
    ->setCustomerPaymentId(0)
    ->setMethod('purchaseorder')
    ->setPo_number(' â€" ');
    $order->setPayment($orderPayment);

    // let say, we have 2 products
    //check that your products exists
    //need to add code for configurable products if any
    $subTotal = 0;
    $products = array(
        '7088' => array(
        'qty' => 2
        ),
        '7089' => array(
        'qty' => 1
        )
    );

    foreach ($products as $productId=>$product) {
    $_product = Mage::getModel('catalog/product')->load($productId);
    $rowTotal = $_product->getPrice() * $product['qty'];
    $orderItem = Mage::getModel('sales/order_item')
    ->setStoreId($storeId)
    ->setQuoteItemId(0)
    ->setQuoteParentItemId(NULL)
    ->setProductId($productId)
    ->setProductType($_product->getTypeId())
    ->setQtyBackordered(NULL)
    ->setTotalQtyOrdered($product['rqty'])
    ->setQtyOrdered($product['qty'])
    ->setName($_product->getName())
    ->setSku($_product->getSku())
    ->setPrice($_product->getPrice())
    ->setBasePrice($_product->getPrice())
    ->setOriginalPrice($_product->getPrice())
    ->setRowTotal($rowTotal)
    ->setBaseRowTotal($rowTotal);

    $subTotal += $rowTotal;
    $order->addItem($orderItem);
    }

    $order->setSubtotal($subTotal)
    ->setBaseSubtotal($subTotal)
    ->setGrandTotal($subTotal)
    ->setBaseGrandTotal($subTotal);

    $transaction->addObject($order);
    $transaction->addCommitCallback(array($order, 'place'));
    $transaction->addCommitCallback(array($order, 'save'));
    $transaction->save();

    /* create order for guest customer */

    $quote = Mage::getModel('sales/quote')
            ->setStoreId(Mage::app()->getStore('default')->getId());

    $lsit_od_id = array('7125','7088','7089');
    foreach ($lsit_od_id as $key => $value) {
        $product = Mage::getModel('catalog/product')->load($value); /* 6 => Some product ID */
        $buyInfo = array('qty' => 1);
        $quote->addProduct($product, new Varien_Object($buyInfo));
    }


    $billingAddress = array(
        'firstname' => 'abc',
        'lastname' => 'ccc',
        'company' => 'hhhh',
        'email' =>  'manoj@gmail.com',
        'street' => array(
            'Sample Street Line_1',
            'Sample Street Line_2'
        ),
        'city' => 'City',
        'region_id' => '',
        'region' => 'State/Province',
        'postcode' => '12345',
        'country_id' => 'NL',
        'telephone' =>  '1234567890',
        'fax' => '123456987',
        'customer_password' => '',
        'confirm_password' =>  '',
        'save_in_address_book' => '0',
        'use_for_shipping' => '1',
    );

    $quote->getBillingAddress()
            ->addData($billingAddress);

    $quote->getShippingAddress()
            ->addData($billingAddress)
            ->setShippingMethod('tablerate_bestway')
            ->setPaymentMethod('checkmo')
            ->setCollectShippingRates(true)
            ->collectTotals();

    $quote->setCheckoutMethod('guest')
                ->setCustomerId(null)
                ->setCustomerEmail($quote->getBillingAddress()->getEmail())
                ->setCustomerIsGuest(true)
                ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);

    $quote->getPayment()->importData( array('method' => 'checkmo'));

    $quote->save();

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

这篇关于通过CSV导入Magento中的订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆