Same shipping for many vendors

For example on my contry, there is 79 states, & there 5 possible shipping method
so, i would create standard shipping rules for all vendors & applied automatically
for example:

I create 5 shipping methods for each states
when vendor from states 1 registred, the 5 shipping methods will applied automatically on his store

& always give hime possibility to add his shipping method

Any developping guide to edit the shipping template code!!

I woud create for example 79 shipping template for each state
When vendor from state 1 registred, the shipping method for state 1 will aplied automatically on his store,
Or option to set same shipping method for many sellers

@CS-Cart_team any guide to edit please or snippet code

I’m sorry, but I don’t know how to help you as I don’t understand your request. Please have a look at this section first:

I’ll simplify it for you
My goal is to prevent sellers from creating their own shipping methods
And I want it to be shipped via the marketplace
But the problem is that the sellers are from different states, and the price varies according to each state
So, through the admin panel, I want to create a shipping method for each state individually.
Now I want to modify the template, and set conditions for how shipping methods appear to customers.

For example, if the seller of the product is from the state of A, only shipping method ID 1 will appear to the customer in the interface

like addin code on
design\themes\responsive\templates\views\checkout\components\shipping_rates.tpl inside the checkout:shipping_rate hook

{foreach $product_groups as $group_key => $group}

  {$seller_state = $group.seller_state}
    
  {foreach $group.shippings as $shipping_id => $shipping}

    {hook name="checkout:shipping_rate"}
      
      {if $seller_state == 'StateA'}
        {if $shipping.shipping_id == 1}
          // Show shipping method 1 
        {/if}

      {elseif $seller_state == 'StateB'}
        {if $shipping.shipping_id == 2}
         // Show shipping method 2
        {/if}
      {/if}

    {/hook}

  {/foreach}

{/foreach}

also need to set the seller state on the product level, like:

fn_set_product_data($product_id, ['seller_state' => 'StateA'];

Thanks for clarifying!

I can recommend you to take a look at the PHP hooks shippings_get_shippings_list_conditions and shippings_get_shippings_list_post. These hooks may be used to filter out the shipping methods that are not suitable for the specific vendor.

Also you can check the full database of the hooks available:
https://helpdesk.cs-cart.com/api

1 Like

no i use this

{foreach $all_shippings.$group_key as $shipping_id => $item}
    {if $group.shippings.$shipping_id}
        {$shipping = $group.shippings.$shipping_id}
        {$shipping.service_delivery_time = $item.service_delivery_time}
        {$shipping.shipping = $item.shipping}
    {else}
        {$shipping = $item}
        {if $show_unavailable_shippings}
            {$shipping.rate_disabled = true}
        {else}
            {continue}
        {/if}
    {/if}

    {if $vendor_state == 'state1' && $shipping.rate_disabled}
        {continue}
    {/if}

    {if $vendor_state == 'state2' && $shipping.rate_disabled}
        {continue}
    {/if}
    // do it with al states
    {if $shipping.rate_disabled && $cart.chosen_shipping.$group_key == $shipping.shipping_id}
        {$group.shipping_disabled = true}
    {/if}
    
    ...
{/foreach}

now on $vendor_state i will use this php code on shipping_rates

{php}
    // Function to retrieve vendor state
    function get_vendor_state($auth)
    {
        $vendor_id = $auth['user_id']; // Assuming the vendor ID is stored in the user_id field
        $vendor_info = fn_get_vendor_data($vendor_id); // Replace with the actual function to get vendor data

        // Assuming the vendor state is stored in the 'state' field of vendor data
        $vendor_state = isset($vendor_info['state']) ? $vendor_info['state'] : '';

        return $vendor_state;
    }

    // Get vendor state for the current vendor
    $vendor_state = get_vendor_state($auth);
{/php}

Adding php code to a Smarty template isn’t a good idea. It’s better to put it in a php file and assign the results of that code to a Smarty variable.