How to add transporteur method in CMS prestashop and virtuemart

Recently had to developer new e-commerce website, and I used Prestashop in this case

For e-commerce site the transporteur could be really pain the ass, cause this is related to client, transporteur accord between countries, carte postale, product weight or package size ( larger, wide, profondeur)

Further more, like what I did in the case, there’s also category group client with different promotion percentage, ex:

promotion 10%, promotion 20% , promotion discount transport etc

Or, if the order amount over 60 euro then the transport should be free, or get discount by total amount TTC

Bref here is not freaking out of you, cause me either I’m not code geek and I always prefer get easies way

As follow I will introduced 2 CMS which had some method to reduced those pain

Prestashop 1.7

As I start using prestashop I was get impressed how easy it is to configure any complex situation for the ecommerce store

step 1 : define your sending countries region

in Admin page, go to international, zone geographic and choise Zone

Here I define zone A, B ect for transporteur Fedex:

And then filtre the countries you would like to assign with the zone:

step 2 : define your transporteur

go to transporteur, click + to add the transporteur

Here we add Fedex for example:

go to Destination section and cost, here is the key points to set the value by price total or by product weight,
the you could configure like as follow by weight range and by the zone area you had defiend:

voila, in prestashop it has thinking about all the possible scenerio for you which could make your work pretty easy

Virtuemart 3

In virtuemart it could be more complex, but in the end there’s still solution if you need add complex logical for transporteur

what different from prestashop is, in Virtuemart you do not need to configure Zone country first, instead you configure those inside transporteur method

step 1 : define your transporteurs

By default virtuemart has VM shipment – By weight, zip and countries plugin

if you simply just define the cost by countries then this the way to add:

different from prestashop, here you add transport by weight define, in this case if you had lots weight ranges then you had to add one by one

step 2 : define your price complex by the total amount

another good part of virtuemart, you could defined really complex calculation of transport cost by add this plugin: Advanced shopping by Rules plugin

Once installed, you should be able to see this method add:

go to configure page,

you could see Rules for country zone 1, Rules for country zone 2 etc

in my case, i need to define Canada and Usa those 2 countries has 2 method:
A. For shopperGroup who has no promotion, they could get reduced transporteur price by the rate of total amount 10% off, but if reduced price get down to below 6 euro then stay in 6 euros

B. For shopperGroup has promotion, then he get the original price without promotion

here is the regle to define:

Variable=ShipReducedRate; Value=0.1*BasePrice
Name=”Shipping complex function for without TVA”;Condition=contains_only(ShopperGroups, 7);0.001<=Weight<=0.65;ShippingWithTax= Max(6, 25-ShipReducedRate)
Name=”Shipping Full Price”;0.001<=Weight<=0.65;Shipping= 25

for the define rule attribute you could fine more doc here

So there you go by this plugin you could really define lots different situation to calculate the transporte price

Method to connect ERP in E-commerce CMS

As topic, we usually build a E-commerce website by CMS, like with prestashop,  Mengento, wooCommerce or Vituemart  etc , every thing could be work easily with those powerful CMS

But it might be encounter a problem, as you might need ERP software for Logistic, gestion des stocks etc, with CMS it might  get very complicated,

Fourtunatelly, right now CMS is very powerful that even provide the module to connect with, like Prestashop my Easy ERP 

As part of ERP, most popular part is SAP, there’s also ORACLE, SAGE and so many different ERP

Most data need to be integrated :

  • Order Data
  • Shipments
  • Customers
  • Inventory
  • Product Data
  • Customer Groups
  • Invoice Data
  • Credit Memos
  • Transactions
  • Tax Rules

As those data need to be passing back and forth between CMS and ERP. There are many questions you need to ask when thinking about the integration.

Here I took example use SAP and Virtuemart


what SAP part required is usually integrated Data through xml, so the target is send orders xml files to certain file that allow trigger through FTP connection

xml sample:

As you could see those has customised tag in order to trigger order client data

those allowed SAP to get information necessary

Your site

in order to stocker those xml in the root of your site you could create file something like:



this allow FTP connection to get xml in send file for example

Admin Page ( Virtuemart)

For admin Page, you could see the order list, and insider order list page, you need to create a button in order to generate xml file of this order, some thing would be looks like this:

in Virtuemart, you could put follow code in administrator/components/com_virtuemart/views/orders/tmpl/order.php

    //generate SAP file, add submit button

    if(isset($_POST['sap_generate'])) {
        if($_POST['sap_generate'] == 'ok') {
            $SAP_handler = new Sap_xml_handler();
            echo "Le fichier a été généré.";
       <form class="sap_form" action="index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id=<?php echo $this->orderID ;?>" method="post">
        <input type="hidden" name="sap_generate" value="ok">
        <input type="submit" value="Générer fichier SAP" name="sap_form_submit">
    <?php //FIN GENERATION ?>


and do the same thing in payment plugin, here for example we had paypal :

//generate SAP file
             if($order_history['order_status'] == 'A') {

                $SAP_handler = new Sap_xml_handler();

in virtuemart, order_status == A , means order had send out

then you might wonder in those php code above, there has a class Sap_xml_handler  and  call inside class function create_SAP_xml, and inject orderID

Your site root, create a file called: sap_xml_handler.php

// Check to ensure this file is included in Joomla!
defined(‘_JEXEC’) or die(‘Restricted access’);

Then create class Sap_xml_handler with create_SAP_XML function

Class Sap_xml_handler {
  function create_SAP_XML($order_id) {

     $config = new JConfig();

     $db_sap = new PDO('mysql:host=localhost;dbname='.$config->db, $config->user, $config->password);

     // start your code to get data by sql query

As query part, you could select table from the order infos

then fetch the query

start to get order info data, for example

$order_request = $db_sap->query('SELECT virtuemart_user_id, created_on, order_tax, order_shipment, order_language, order_payment, order_total, order_status, virtuemart_shipmentmethod_id, virtuemart_paymentmethod_id
										FROM h8q2p_virtuemart_orders
										WHERE virtuemart_order_id = '.$order_id);
		$order_data = $order_request->fetch();

		//Récupération de l'utilisateur lié a la commande
		$user_id = $order_data['virtuemart_user_id'];
		$payment_id = $order_data['virtuemart_paymentmethod_id'];
		$shipping_id = $order_data['virtuemart_shipmentmethod_id'];

as you could see here we had user_id, payment_id, shipping_id

And to generate those data it is important to put those in xml content:

$XML_content.="\t\t\t\t\tPaiement : ".$payment_name." || Livraison : ".$shipping_name."\n";

After the key is try to know what the value type and data formulaire between site and SAP

if your site set name string length is maxime length to 40 but SAP only allowed 20, then this might occurred integration error once a user put his name more then 20 characters

or if you send country code with 2 code but SAP only accepte 3 code

It has complex data to bind but once done syn with CMS and SAP, this does big help for ecommerce system to charge with logistic and stock or further more works