【问题标题】:Programmatically create sales order using quote with custom shipping method in Magento在 Magento 中使用带有自定义运输方式的报价以编程方式创建销售订单
【发布时间】:2016-02-11 10:34:02
【问题描述】:

我想以编程方式使用报价和我自己的自定义运输方式、运输价格和标题来创建销售订单。

这是我的自定义运输方式模型:

<?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',
        );
    }
}

我尝试这样使用它:

// 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();
}

但它似乎不起作用。创建订单后,除了运输方式、标题和价格外,一切都是正确的。这是我在后端看到的:

到目前为止,这是我的完整代码:http://pastebin.com/jUTM0VbD

知道我在这里做错了什么吗?如何使用我自己的自定义运输方式并设置自定义价格和标题?

【问题讨论】:

    标签: php magento


    【解决方案1】:

    为以编程方式生成的订单添加运输方式非常简单,

    按照以上步骤进行

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

    【讨论】:

      猜你喜欢
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 2011-12-11
      • 2016-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多