如何添加定制货件 CS-Cart

How to add custom shipment CS-Cart

我需要在结帐页面添加动态发货选项,发货的价格、持续时间和名称来自其他 API。

我尝试了这些挂钩,其中 none 个在结帐期间被调用。

    'get_available_shippings',
    'get_shipping_methods',
    'get_shipping_methods_post',
    'get_shipments_info_post'

试图勾搭shipping_methods_list.pre.tpl

{assign var="s" value=$all_shippings[0][1]}
{$s["shipping_id"] = '2'}
{$all_shippings[0][2] = $s}

我正在使用 cs-cart 4.14

正确的挂钩是 shippings_get_shippings_list_post,因为它没有添加到数据库中,看来您需要在 backend 上挂钩 orders:shipping_info 以进一步自定义。

function fn_example_addons_shippings_get_shippings_list_post(&$group, &$lang, &$area, &$shippings_info)
{
    $package_info = $group['package_info'];
    $fromZipcode = $package_info['origination']['zipcode'];
    $toZipcode = $package_info['location']['zipcode'];
    $weight = (int)round(ceil($package_info["W"]));
    $item_price = (int)round(ceil($package_info["C"]));
    $shipments = fn_example_addons_getRates($fromZipcode, $toZipcode, $weight, $item_price);
    foreach ($shipments as $key => $shipment) {
        $shippings_info[$key] = $shipment;
    }
}

货件

            $shipments["SHIPMENT_ID"] = array(
                "shipping_id" => "SHIPMENT_ID",
                "shipping" => "Example Shipment"
                "delivery_time" => "2-3 days",
                "description" => "",
                "rate_calculation" => "M",
                "service_params" => array(),
                "destination" => "I",
                "min_weight" => "0.0",
                "max_weight" => "0.0",
                "service_id" => "0",
                "free_shipping" => "N",
                "module" => null,
                "service_code" => null,
                "is_address_required" => "Y",
                "rate_info" => array(
                    "rate_id" => "0",
                    "shipping_id" => "0",
                    "rate_value" => array(
                        "C" => array(
                            array(
                                "range_from_value" => 0,
                                "range_to_value" => "",
                                "value" => $price_in_point
                            )
                        )
                    ),
                    "destination_id" => "1",
                    "base_rate" => "0.0"
                ),
                "disable_payments_ids" => array()
            );