高级应用Magento-订单创建流程及程序代码
来源:互联网 发布:淘宝上的外卖是饿了么 编辑:程序博客网 时间:2024/06/05 22:58
出处:http://www.wemvc.com/1606.html
老规矩,直接看代码吧。下面的代码是如何通过程序创建一个完美订单。
<?phprequire_once 'app/Mage.php'; Mage::app('default');//初始化程序,设置当前店铺 $store = Mage::app()->getStore('default');//通过电子邮件获取用户,当然也可以不获取,创建guest订单$customer = Mage::getModel('customer/customer');$customer->setStore($store);$customer->loadByEmail('email_address@gmail.com'); //初始化Quote,Magento的订单是通过Quote来转化过去的$quote = Mage::getModel('sales/quote');$quote->setStore($store);$quote->assignCustomer($customer);//如果有用户则执行这个 $product1 = Mage::getModel('catalog/product')->load(166); /* HTC Touch Diamond */$buyInfo1 = array('qty' => 1); $product2 = Mage::getModel('catalog/product')->load(18); /* Sony Ericsson W810i */$buyInfo2 = array('qty' => 3);//添加商品到Quote$quote->addProduct($product1, new Varien_Object($buyInfo1));$quote->addProduct($product2, new Varien_Object($buyInfo2));//设置账单和收货品地址$billingAddress = $quote->getBillingAddress()->addData($customer->getPrimaryBillingAddress());$shippingAddress = $quote->getShippingAddress()->addData($customer->getPrimaryShippingAddress());//设置配送和支付方式$shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate') ->setPaymentMethod('checkmo'); $quote->getPayment()->importData(array('method' => 'checkmo'));//Quote计算运费$quote->collectTotals()->save();//将Quote转化为订单$service = Mage::getModel('sales/service_quote', $quote);$service->submitAll();$order = $service->getOrder();/***至此订单已经成功生成,下面是注册付款信息***/ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);$invoice->register(); $transaction = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()); $transaction->save();
- 高级应用Magento-订单创建流程及程序代码
- Magento订单流程小记
- magento 后台创建一个订单
- 51. magento 手动创建订单
- magento下订单流程以及订单数据库结构分析
- Magento通过订单id修改订单创建时间的sql
- mq-订单创建流程通知
- Magento导入excel中的信息,然后创建订单
- Magento订单状态详解(一):Magento订单基本流程 http://www.php-source.com/thread-20100-1-1.html
- Magento订单管理
- Magento 订单删除
- magento 删除订单
- Magento 订单清空
- magento删除订单
- Magento订单状态迷思
- 50.magento 订单状态
- Magento认证工程师考试及注册流程
- magento 模型及程序架构与流程
- corrupt master file table (MFT)主文件表损坏
- PHP中文件读写操作
- S3C6410 IDE硬盘接口性能测试
- 地址、内存、堆、栈总结
- sleep,interrupt和wait,notify的区别
- 高级应用Magento-订单创建流程及程序代码
- Delegate介绍
- 前言
- jquery dialog的研究
- JVM调优文献参考
- android UI Link
- 各字符集编码间的转换
- Test
- (数据结构与算法分析 五)------二叉查找树的实现( Java语言描述)