Prestashop网络服务 - 获得订单的税费和运费

时间:2013-06-25 18:32:50

标签: api prestashop shipping

我希望使用prestashop API(网络服务)下订单。我到了最后但它仍然遗漏了一些关于的信息:

  • 税费
  • 运费

如果有人知道获取这些信息的路线或流程,那将非常有帮助。

2 个答案:

答案 0 :(得分:0)

我不确定,但关于运费我觉得它在功能中:

public function getOrderShippingCost($params, $shipping_cost) {
// This example returns shipping cost with overcost set in the back-office, but you can call a webservice or calculate what you want before returning the final value to the Cart
        if ($this->id_carrier == (int)(Configuration::get('MYCARRIER1_CARRIER_ID')) && Configuration::get('MYCARRIER1_OVERCOST') > 1)
            return (float)(Configuration::get('MYCARRIER1_OVERCOST'));
        if ($this->id_carrier == (int)(Configuration::get('MYCARRIER2_CARRIER_ID')) && Configuration::get('MYCARRIER2_OVERCOST') > 1)
            return (float)(Configuration::get('MYCARRIER2_OVERCOST'));

        // If the carrier is not known, you can return false, the carrier won't appear in the order process
        return false;
}

然而,它在CarrierModule中使用,你在创建什么样的模块?

答案 1 :(得分:0)

我知道这有点旧,但我设法通过webservices以这种方式获取这些信息:

编辑Cart.php核心类(有一种更优雅的方式,但这也有效)。

// added 2 attributes in class
public $my_shipping_cost;
public $my_order_total;



// added some more data to $webserviceParameters
protected $webserviceParameters = array(
    'fields' => array(
        'id_address_delivery' => array('xlink_resource' => 'addresses'),
        'id_address_invoice' => array('xlink_resource' => 'addresses'),
        'id_currency' => array('xlink_resource' => 'currencies'),
        'id_customer' => array('xlink_resource' => 'customers'),
        'id_guest' => array('xlink_resource' => 'guests'),
        'id_lang' => array('xlink_resource' => 'languages'),
        'my_shipping_cost' => array(
                            'getter' => 'getMyShippingCost',
                            'setter' => 'getMyShippingCost'
                    ),
        'my_order_total' => array(
                            'getter' => 'getMyOrderTotal',
                            'setter' => 'getMyOrderTotal',
                    ),

    ), ...

// added some methods to process the values
public function getMyShippingCost(){
    if (!isset($this->my_shipping_cost))
        $this->setMyCustomFieldsValues();
    return $this->my_shipping_cost;
}

public function getMyOrderTotal(){
    if (!isset($this->my_order_total))
                    $this->setMyCustomFieldsValues();
            return $this->my_order_total;

}

public function setMyCustomFieldsValues(){

    if (!isset($this->id))
        return;

    $currency = 1;
    $taxCalculationMethod = Group::getPriceDisplayMethod((int)Group::getCurrent()->id);
    $useTax = !($taxCalculationMethod == PS_TAX_EXC);

    $base_shipping = $this->getOrderTotal($useTax, Cart::ONLY_SHIPPING, null, $this->id_carrier, false);
    $this->my_shipping_cost = $base_shipping;
    $this->my_order_total = $this->getOrderTotal($useTax, Cart::BOTH, null, $this->id_carrier, false);

}

也许你可以改进一些代码,但这是一种方法。

最佳, Eder的。