Updating shipping cost in the checkout page

My situation is similar to this. I have used the same steps to update the rate of the shipping cost variable and it is not doing so. I am using CS cart 4.13.x

I have to abide by some wholesaler conditions. I have edited the shipping costs as per my need using the cart function and added respective costs while doing so. My issue is that after I add those shipping costs to the front end, I now need to add that to the order total as well.

If I can update the shipping cost rates, I should be able to get the expected results. But, I am not able to do so.

 //Updating the shipping cost and recalculating it
    if (!empty($cart['shipping'])){
        foreach ($cart['shipping'] as $shipping_key => $shipping)
        {
            $cart['shipping'][$shipping_key]['rate'] = $freight;
            foreach ($shipping['rate_info']['rate_value']['C'] as $rate_key => $rate)
            {
                $cart['shipping'][$shipping_key]['rate_info']['rate_value']['C'][$rate_key]['value'] = $freight;
            }
        }
        // Recalculate cart content
    }
        fn_calculate_cart_content($cart, Tygh::$app['session']['auth'], 'E', true,'F',true);
        Registry::get('view')->assign('cart',$cart);

The cart values are getting updated but for some reason during calculation, it doesn’t work. I know I am missing something here and I need some assistance.

An update to this.

I figured out how to update the shipping cost in the database, at least temporarily. I am using CS-Cart 4.13.3.

I first tried updating the shipping cost using the fn_update_shipping() hook. This is a sample code:

$shipping_id = 1;  // The ID of the shipping method
$data = array(
    'rate_value' => array(
        'C' => array(
            array(
                'range_from_value' => 0,
                'range_to_value' => '',
                'value' => 7.50,  // Value I want to insert
                'per_unit' => 'N'
            )
        )
    )
);

//To update the shipping
fn_update_shipping($data, $shipping_id);

Then, I pulled out the shipping info only to find that it didn’t work.

$shipping = fn_get_shipping_info($shipping_id);

Then, I tried using db_query() to update the rate in the database. Although I don’t think that should be done, because I only want to update the shipping rate temporarily.

db_query(
    'UPDATE ?:shippings SET rate_value = ?s WHERE shipping_id = ?i',
    serialize($shipping_data), 
    $shipping_id  
);

Problem is, the cscart_shippings table doesn’t have a rate_value field and it isn’t updating. I have tried almost everything. Any help would be appreciated.

1 Like