简体   繁体   English

在Magento中使用报价和自定义送货方式以编程方式创建销售订单

[英]Programmatically create sales order using quote with custom shipping method in Magento

I would like to create sales orders programmatically using quotes with my own custom shipping method, shipping price & title. 我想使用报价和自己的自定义送货方式,送货价格和标题以编程方式创建销售订单。

This is my custom shipping method model: 这是我的自定义送货方式模型:

<?php

class Mycompany_Mymodule_Model_Carrier
    extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
{
    protected $_code = 'icw_shipping';

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        if (!Mage::registry($this->_code)) {
            return false;
        }

        $info = Mage::registry($this->_code);
        $method = Mage::getModel('shipping/rate_result_method');
        $method->setCarrier($this->_code);
        $method->setMethod($this->_code);
        $method->setCarrierTitle($info['shippingCarrier']);
        $method->setMethodTitle($info['shippingTitle']);
        $method->setPrice($info['shippingPrice']);
        $method->setCost($info['shippingPrice']);
        $result = Mage::getModel('shipping/rate_result');
        $result->append($method);
        Mage::unregister($this->_code);
        return $result;
    }

    public function getAllowedMethods()
    {
        return array(
            $this->_code => 'ICW Shipping',
        );
    }
}

I try to use it like this: 我尝试像这样使用它:

// Method to save sales order quote
private function saveSalesOrderQuote()
{
    Mage::register($this->_settings['ShippingMethod'], array(
        'shippingCarrier' => 'Custom',
        'shippingTitle'   => $this->_orderData->ShippingMethod,
        'shippingPrice'   => $this->_orderData->ShippingAmount
    ));
    $this->_quote->getShippingAddress()->setShippingMethod(
        $this->_settings['ShippingMethod']
    );
    $this->_quote->getShippingAddress()->setCollectShippingRates(
        true
    );
    $this->_quote->getShippingAddress()->collectShippingRates();
    $this->_quote->collectTotals();
    $this->_quote->reserveOrderId();
    $this->_quote->save();
}

But it does not appear to be working. 但是它似乎没有用。 When the order is created, everything is correct expect for the shipping method, title & price. 创建订单后,所有关于运输方式,标题和价格的信息均正确无误。 This is what I see in the backend: 这是我在后端看到的:

在此处输入图片说明

Here's my full code so far: http://pastebin.com/jUTM0VbD 到目前为止,这是我的完整代码: http : //pastebin.com/jUTM0VbD

Any idea what I am doing wrong here? 知道我在这里做错了吗? How do I use my own custom shipping method and set custom price and title? 如何使用自己的自定义送货方式并设置自定义价格和标题?

Its very simple to add shipping method for order generated programmatically, 添加以编程方式生成的订单的运输方式非常简单,

Follow above steps 遵循以上步骤

$shippingAddress =$_quote->getShippingAddress()->addData($ShippingAddress);
                    $shippingAddress->setShippingMethod('methodname_methodname')->setCollectShippingRates(true)->collectShippingRates()->setPaymentMethod('methodcode'); //

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Magento 1.使用“ sales / service_quote”以编程方式创建订单将返回空订单 - Magento 1. Create order programmaticaly using 'sales/service_quote' returns empty order Magento 2.4.3-p1 在以编程方式创建订单期间使用自定义送货方式 - Magento 2.4.3-p1 Use custom shipping method during order creation programmatically 以编程方式将产品添加到magento的销售报价中 - Add products to sales quote in magento admin programmatically 在Infusionsoft中为运输报价创建订单 - Create Order for a shipping quote in Infusionsoft 无法在Magento订单创建脚本中设置Shipping Method - Unable to set Shipping Method in Magento order create script Magento-客户地址中的自定义属性,在结帐时未复制到sales_flat_order_address和sales_flat_quote_address - Magento - Custom attribute in customer address, not copied to sales_flat_order_address and sales_flat_quote_address on checkout 如何在类Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Method_Form中获取订单ID? - How to get order Id in class Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Method_Form? magento以编程方式从订单中获得运费税 - magento programmatically get the shipping tax from an order 如何以编程方式将magento销售规则应用于报价项目 - How to programmatically apply a magento sales rule to an quote item Magento以编程方式创建sales / quote_address对象 - Magento programmatically creating a sales/quote_address object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM