EMDI can download orders, customers and products and update stock on multiple e-shops at once through one shared multishop bridge. EMDI talks to a single bridge URL; that script fans out each request to every shop bridge.
Open-source script: emdi_multishop_bridge.php.
Steps
- Install and test the normal shop bridge on each e-shop alone (WooCommerce, OpenCart, etc.) until it works with EMDI by itself.
- Upload emdi_multishop_bridge.php to a reachable folder (often on the main shop or shared hosting) and set inside it:
$passkey— same key you will enter in EMDI- each shop bridge URL (including its own
key=) - a unique
order_prefixfor every extra shop (e.g.EM)
- In EMDI Settings → Internet / bridge, set the domain to the multishop script URL and the key to
$passkey— same as a normal bridge. Apply the links sobridge.inigetsaction=orders,order,customers,products,updatestock, etc.
Important
- Use a different customer code prefix per e-shop.
- If products are shared, keep the same product codes across shops.
- Each e-shop must use a different order number prefix so the multishop bridge can route
order/confirmorder/cancelorderto the right shop.
On the second (and every extra) shop bridge, define the order prefix, e.g.:
|
1 |
$order_id_prefix='EM'; |
Just before if ($action == 'deletetmp'), strip the prefix from the incoming $orderid:
|
1 2 |
$orderid=str_ireplace($order_id_prefix,'',$orderid); if ($action == 'deletetmp') { ... |
In action=orders, when you echo the order line, prepend the prefix to the id:
|
1 |
echo $order_id_prefix.$id.';' ... |
The multishop bridge merges lists (orders / customers / products), drops the duplicate header row from the 2nd shop, then when EMDI opens or confirms an order it picks the shop from the prefix and forwards orderid without that prefix.
Full sample (edit URLs, keys and prefixes):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
<?php /*------------------------------------------------------------------------ # EMDI - multishop bridge by SBZ systems - Solon Zenetzis - version 2 # ------------------------------------------------------------------------ # Aggregates two (or more) shop bridges into one endpoint for EMDI. # EMDI Settings → Internet links: point domain/key at THIS script like a normal bridge. # ------------------------------------------------------------------------ # author SBZ systems - Solon Zenetzis # copyright Copyright (C) 2020-2026 sbzsystems.com. All Rights Reserved. # @license - https://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # Websites: https://www.sbzsystems.com -------------------------------------------------------------------------*/ header('Cache-Control: no-cache, must-revalidate'); header('Content-Type: text/html; charset=UTF-8'); error_reporting(0); // --- configure --- $passkey = 'CHANGE_ME'; // must match the key=… EMDI sends // Each shop: full bridge URL including its own key= (without action) $eshops = array( array( 'url' => 'https://eshop1.gr/emdi_wp_woo_bridge.php?company=ike&key=12245325', 'order_prefix' => '', // main shop: no order-id prefix ), array( 'url' => 'https://eshop2.com/emdi_open2_bridge.php?key=235232354235', 'order_prefix' => 'EM', // unique prefix; also set in that shop bridge when echoing order ids ), ); // --- request --- $productid = isset($_REQUEST['productid']) ? $_REQUEST['productid'] : ''; if ($productid !== '' && function_exists('mb_check_encoding') && !mb_check_encoding($productid, 'UTF-8')) { $productid = @iconv('ISO-8859-7', 'UTF-8//IGNORE', $productid); } $stock = isset($_REQUEST['stock']) ? $_REQUEST['stock'] : ''; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $orderid = isset($_REQUEST['orderid']) ? $_REQUEST['orderid'] : ''; $key = isset($_REQUEST['key']) ? $_REQUEST['key'] : ''; $shipcomp = isset($_REQUEST['shipcomp']) ? $_REQUEST['shipcomp'] : ''; $voucherno = isset($_REQUEST['voucherno']) ? $_REQUEST['voucherno'] : ''; $docid = isset($_REQUEST['docid']) ? $_REQUEST['docid'] : ''; if ($key !== $passkey) { exit; } function emdi_ms_fetch($url) { $ctx = stream_context_create(array( 'http' => array('timeout' => 60, 'ignore_errors' => true), 'ssl' => array('verify_peer' => true, 'verify_peer_name' => true), )); $out = @file_get_contents($url, false, $ctx); return ($out === false) ? '' : $out; } function emdi_ms_shop_url($base, $query) { $sep = (strpos($base, '?') === false) ? '?' : '&'; return $base . $sep . 'rndval=' . rand(10000000, 90000000) . '&' . $query; } function emdi_ms_strip_header_row($csv) { return preg_replace('/^.+(\r\n|\n|\r)/', '', $csv, 1); } function emdi_ms_find_shop($eshops, $orderid) { // Longest matching prefix wins (empty prefix = fallback / main shop) $best = null; $bestLen = -1; foreach ($eshops as $shop) { $p = isset($shop['order_prefix']) ? (string)$shop['order_prefix'] : ''; if ($p === '') { if ($best === null) { $best = $shop; $bestLen = 0; } continue; } if (mb_stripos($orderid, $p) === 0 && mb_strlen($p) > $bestLen) { $best = $shop; $bestLen = mb_strlen($p); } } return $best; } function emdi_ms_orderid_for_shop($orderid, $shop) { $p = isset($shop['order_prefix']) ? (string)$shop['order_prefix'] : ''; if ($p === '') { return $orderid; } if (mb_stripos($orderid, $p) === 0) { return mb_substr($orderid, mb_strlen($p)); } return str_ireplace($p, '', $orderid); } if ($action === 'deletetmp' || $action === 'customersok' || $action === 'productsok' || $action === 'updatestock') { foreach ($eshops as $shop) { $q = 'action=' . rawurlencode($action); if ($action === 'updatestock') { $q .= '&productid=' . rawurlencode($productid) . '&stock=' . rawurlencode($stock); } echo emdi_ms_fetch(emdi_ms_shop_url($shop['url'], $q)); } exit; } if ($action === 'customers' || $action === 'products' || $action === 'orders') { $first = true; foreach ($eshops as $shop) { $raw = emdi_ms_fetch(emdi_ms_shop_url($shop['url'], 'action=' . rawurlencode($action))); if ($first) { echo $raw; $first = false; } else { echo emdi_ms_strip_header_row($raw); } } exit; } if ($action === 'order' || $action === 'confirmorder' || $action === 'cancelorder') { $shop = emdi_ms_find_shop($eshops, $orderid); if ($shop === null) { exit; } $oid = emdi_ms_orderid_for_shop($orderid, $shop); $q = 'action=' . rawurlencode($action) . '&orderid=' . rawurlencode($oid); if ($action === 'confirmorder') { $q .= '&docid=' . rawurlencode($docid) . '&shipcomp=' . rawurlencode($shipcomp) . '&voucherno=' . rawurlencode($voucherno); } echo emdi_ms_fetch(emdi_ms_shop_url($shop['url'], $q)); exit; } ?> |
Source: https://github.com/sbzsystems/emdi-eshop-bridges-connectors/blob/gh-pages/emdi_multishop_bridge.php
