Back to Top

How to create custom shipping in CS-Cart?

Updated 20 April 2023

Shipping is one of the major parts of an e-commerce website. To create a custom shipping method in CS-Cart, you need to write code to create a new shipping method, define its properties, and calculate the shipping rates.

Create a New Shipping Method

Folder Structure

File data
  • addon.xml“: The addon.xml file plays a crucial role in CS-Cart as it contains vital information about the add-on or modification. It is located in the root directory of the add-on and serves as a configuration file.
  • func.php“: The “func.php” file includes helper functions and logic used by the shipping method.
  • init.php“: The purpose of the “init.php” file is to register the hook used in the shipping method.
  • lang“: This file contains the language translations for the shipping method. This file serves to provide translations for the shipping method’s title, description, and other text in different languages, allowing for localization.
  • image“: This folder will contain an image icon for your addon.
  • Tygh“: The Tygh/Shippings/Services a folder is used in CS-Cart to define shipping services for different shipping methods. This folder contains PHP classes that implement the logic to calculate the shipping cost for each service that we use in the shipping method.

After creating the necessary files and folders for your custom shipping method in CS-Cart, Now you are ready for coding:

Code

Finally, we have our folder structure in place, let’s start adding some code.

Find the Best CS-Cart
Development Company
Find out More

The addon XML code represents the addon.xml a file that is typically used in CS-Cart add-ons, and it contains various metadata about the add-on, such as its name, version, author, and installation/uninstallation functions.

<?xml version="1.0"?>
<addon scheme='3.0'>
    <id>custom_shipping_method</id>
    <version>1.0</version>
    <priority>12456</priority>
    <position>45789</position>
    <status>active</status>
    <has_icon>Y</has_icon>
    <supplier>Webkul Software Pvt. Ltd</supplier>
    <supplier_link>https://store.webkul.com/CS-Cart.html</supplier_link>
    <default_language>en</default_language>
    <auto_install>MULTIVENDOR,ULTIMATE</auto_install>
    <authors>
        <author>
            <name>Webkul</name>
            <email>[email protected]</email>
            <url>https://webkul.com/</url>
            <phone>India (+91)-9650486699 </phone>
            <phone>USA (+1)-8667772047</phone>
            <phone>UK (+44)-7937415639</phone>
        </author>
    </authors>
    <functions>
        <item for="install">fn_wk_custom_shipping_install</item>
        <item for="uninstall">fn_wk_custom_shipping_uninstall</item>
    </functions>
</addon>

This is an XML file that describes an add-on for the CS-Cart e-commerce platform. The XML file outlines several pieces of metadata related to the add-on, including details about its priority and position within the installed add-ons list, along with its current status and default language.

Know more…

The func.php code shows the implementation of the installation and uninstallation functions for a custom shipping method in CS-Cart.

<?php

if (!defined('AREA')) {
    die('Access denied');
}
function fn_wk_custom_shipping_install()
{
    $service_code = array(
        'CSM' => 'Custom Shipping Method'
    );
    foreach ($service_code as $code => $description) {
        $data = array('status' => 'A', 'module' => 'custom', 'code' => $code, 'status' => 'A');
        $service_id = db_query('INSERT INTO ?:shipping_services ?e', $data);

        $data_desc = array('service_id' => $service_id, 'description' => $description, 'lang_code' => 'en');
        db_query('INSERT INTO ?:shipping_service_descriptions ?e', $data_desc);
    }
}

function fn_wk_custom_shipping_uninstall()
{
    $service_ids = db_get_fields("SELECT service_id FROM ?:shipping_services WHERE module = ?s", 'custom');
    foreach ($service_ids as $key => $service_id) {
        db_query("DELETE FROM ?:shipping_services WHERE service_id = ?i", $service_id);
        db_query("DELETE FROM ?:shipping_service_descriptions WHERE service_id = ?i", $service_id);
    }
}

The init.php code shows the initialization file for a custom shipping method in CS-Cart.

<?php

if (!defined('BOOTSTRAP')) { die('Access denied'); }

fn_register_hooks(
    'get_shipments'
);

CS-Cart uses the .po file as a translation file to present the user interface in various languages. It contains translations for all the strings that appear in the user interface, such as button labels, form fields, and error messages.

msgid ""
msgstr "Project-Id-Version: tygh\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Language-Team: English\n"
"Language: en_US"

msgctxt "Addons::name::custom_shipping_method"
msgid "Custom Shipping Method"
msgstr "Custom Shipping Method"

msgctxt "Addons::description::custom_shipping_method"
msgid "A custom shipping method in CS-Cart is a way to define a unique shipping option for your online store. This shipping method can have its own title, description, and shipping rates, and can be customized to suit your specific needs."
msgstr "A custom shipping method in CS-Cart is a way to define a unique shipping option for your online store. This shipping method can have its own title, description, and shipping rates, and can be customized to suit your specific needs."

msgctxt "Languages::carrier_custom"
msgid "Custom Carrier"
msgstr "Custom Carrier"

The Tygh/Shippings/Services the folder is used in CS-Cart to define shipping services for different shipping methods. This folder contains PHP classes that implement the logic to calculate the shipping cost for each service.

You have completed the integration of your Basic Shipping method, making it available for use by your customers. Check now how this looks like on the addon manage page.

Check how to find the addon that you create:

screenshot_1681824270248

Then find the addon that you created:

screenshot-gaurav.webkul.com-2023.04.14-13_48_22

And then go to the shipping manage page to create a new shipping method:

screenshot_1681824456167

And click on the plus button to add a new shipping method:

screenshot_1681824627951

Check the final shipping method:

screenshot-gaurav.webkul.com-2023.04.14-13_49_31

CS-Cart JNE Shipping Method : 

Integrate JNE shipping with CS-Cart and calculate shipping rates in real time with this magnificent add-on. JNE is a popular shipping service in Indonesia. People trust JNE for their accurate and prompt delivery. The speed and reliability of services consistently make JNE higher credible among customers.

Check our Cs-Cart Shipping Methods :

If you need custom Cs-Cart Development services . Then feel free to reach us. And also explore our exclusive range of Cs-Cart Addons.
!!Have a Great Day Ahead!!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home